Пример #1
0
// Creates DynUnion using typecodes generated through IDL compiler.
int runStatic(CORBA::ORB_ptr orb)
{
  try
    {
        CORBA::Object_var obj =
          orb->resolve_initial_references("DynAnyFactory");

        DynamicAny::DynAnyFactory_var dfact =
          DynamicAny::DynAnyFactory::_narrow(obj.in ());

        if (CORBA::is_nil (dfact.in ()))
          {
            ACE_ERROR_RETURN ((LM_ERROR,
                               "Nil dynamic any factory after narrow\n"),
                              -1);
          }

        DynamicAny::DynAny_var dany =
           dfact->create_dyn_any_from_type_code(DynAnyTest::_tc_EventData);

        DynamicAny::DynUnion_var dunion =
          DynamicAny::DynUnion::_narrow(dany.in ());

        DynamicAny::DynAny_var disc = dunion->get_discriminator();

        DynamicAny::DynEnum_var denum =
          DynamicAny::DynEnum::_narrow(disc.in ());

        if (CORBA::is_nil (denum.in ()))
          {
            ACE_ERROR_RETURN ((LM_ERROR,
                               "Nil dynamic enum after narrow\n"),
                              -1);
          }

        ACE_DEBUG ((LM_DEBUG, "Static Test Passed\n"));
    }
  catch (const CORBA::Exception & ex)
    {
      ex._tao_print_exception ("runStatic");
      return -1;
    }

  return 0;
}
  virtual void push_structured_event(CosNotification::StructuredEvent const& event)
    throw(CosEventComm::Disconnected)
  {
    cout << "domain_name: " << event.header.fixed_header.event_type.domain_name
	 << "  type_name: " << event.header.fixed_header.event_type.type_name << " " << flush;

    if (false) {
    Miro::Client client;
    DynamicAny::DynAnyFactory_var daf =
      client.resolveInit<DynamicAny::DynAnyFactory>("DynAnyFactory");
    DynamicAny::DynAny_var da = daf->create_dyn_any(event.remainder_of_body);
    
    CORBA::TypeCode_var tc = da->type();

    if (tc->kind() == CORBA::tk_struct) {
      CORBA::String_var name = tc->name();
      CORBA::String_var id = tc->id();

      DynamicAny::DynStruct_var ds =
	DynamicAny::DynStruct::_narrow(da);

      for (CORBA::ULong i = 0; i < ds->component_count(); ++i) {
	DynamicAny::DynAny_var member = ds->current_component();
	CORBA::String_var name = ds->current_member_name();
	if (std::string("timestamp") == name.in()) {
	  long long int i =  member->get_ulonglong();
	  ACE_Time_Value t;
	  ORBSVCS_Time::Absolute_TimeT_to_Time_Value(t, i);
	  cout << "latency: " << ACE_OS::gettimeofday() - t << endl;
	  break;
	}
	ds->next();
      }
    }
    else {
      cerr << "unknown event layout" << endl;
    }
    }
    ACE_Time_Value t;
    t.set(time_out);
    ACE_OS::sleep(t);

    cout << "waking up after sleep" << endl;
  }
Пример #3
0
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  int result= 0;
  ACE_DEBUG (( LM_DEBUG, "Start\n" ));

  try
    {
      // init orb
      CORBA::ORB_var the_orb =
        CORBA::ORB_init (argc, argv);

      if (parse_args (argc, argv) == -1)
          return -1;

      ACE_DEBUG (( LM_DEBUG, "Get IFR\n" ));
      CORBA::Object_var objref =
        the_orb->string_to_object (ifr_ior_file);
      if (objref.in () == 0)
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                              "The received objref is nil\n"),
                            -1);
        }

      ACE_DEBUG (( LM_DEBUG, "Narrow IFR\n" ));
      CORBA::ComponentIR::Repository_var the_repo_ref;
      the_repo_ref = CORBA::ComponentIR::Repository::_narrow (objref.in ());

      ACE_DEBUG (( LM_DEBUG, "Obtaining DynamicAny\n" ));
      CORBA::Object_var factory_obj =
        the_orb->resolve_initial_references ("DynAnyFactory");
      DynamicAny::DynAnyFactory_var dynanyfactory =
        DynamicAny::DynAnyFactory::_narrow (factory_obj.in ());

      ACE_DEBUG (( LM_DEBUG, "\nLook up c2\n" ));
      CORBA::Contained_var c2 =
        the_repo_ref->lookup_id ("IDL:m1/c2:1.0");
      if (CORBA::is_nil (c2.in ()))
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                              "Can't look up the const m1/c2\n"),
                            -1);
        }
      CORBA::ConstantDef_var c2_def = CORBA::ConstantDef::_narrow (c2.in ());
      CORBA::String_var c2_name= c2_def->absolute_name ();
      CORBA::TypeCode_var c2_tc = c2_def->type ();
      CORBA::String_var c2_id = c2_tc->id ();
      ACE_DEBUG (( LM_DEBUG, "constant \"%C\" is type \"%C\"", c2_name.in (), c2_id.in () ));
      CORBA::TCKind c2_tckind = c2_tc->kind ();
      ACE_DEBUG (( LM_DEBUG, ", tkkind %d", c2_tckind ));
      if (CORBA::tk_enum == c2_tckind)
        {
          ACE_DEBUG (( LM_DEBUG, " (CORBA::tk_enum)\n" ));
          CORBA::Any_var the_value = c2_def->value ();

          DynamicAny::DynAny_var dany =
            dynanyfactory->create_dyn_any (the_value.in ());
          DynamicAny::DynEnum_var denum =
            DynamicAny::DynEnum::_narrow (dany.in ());
          CORBA::String_var the_strValue = denum->get_as_string ();
          CORBA::ULong the_intValue = denum->get_as_ulong ();

          ACE_DEBUG ((LM_DEBUG, "Whose value is \"%C\" which has an integer value of %d\n",
                     the_strValue.in (), the_intValue ));

          if (0 == ACE_OS::strcmp( "e1_2", the_strValue.in () ))
            {
              ACE_DEBUG ((LM_DEBUG, "The string value is correct\n" ));
            }
          else
            {
              ACE_DEBUG ((LM_DEBUG, "ERROR: The string value should be \"e1_2\"\n" ));
              result = -1;
            }
          if (1 == the_intValue )
            {
              ACE_DEBUG ((LM_DEBUG, "The corresponding integer value is correct\n" ));
            }
          else
            {
              ACE_DEBUG ((LM_DEBUG, "ERROR: The corresponding integer value should be 1\n" ));
              result = -1;
            }
        }
      else
        {
          ACE_DEBUG ((LM_DEBUG, "\nERROR: Wrong tkkind for m1::c2, should be %d\n", CORBA::tk_enum));
          result= -1;
        }
    }
  catch (CORBA::Exception &ex)
    {
      ex._tao_print_exception ("ERROR: CORBA Exception");
      result= -1;
    }
  catch (...)
    {
      ACE_DEBUG ((LM_DEBUG, "ERROR: UNKNOWN Excetion\n"));
      result= -1;
    }

  ACE_DEBUG (( LM_DEBUG, "\nDone\n" ));
  return result;
}
Пример #4
0
int runDynamic(CORBA::ORB_ptr orb)
{
  try
    {
        // Create typecode for EventKind.

        CORBA::EnumMemberSeq eseq;

        eseq.length(2);

        eseq[0] = CORBA::string_dup("ALARM_EVENT");
        eseq[1] = CORBA::string_dup("LOG_EVENT");

        CORBA::TypeCode_var eventKindTc;

        eventKindTc = orb->create_enum_tc("IDL:DynAnyTest/EventKind:1.0",
                                          "EventKind",
                                          eseq);

        // Create typecode for EventData. EventKind tc is used.

        CORBA::Any label;
        CORBA::UnionMemberSeq useq;

        useq.length(2);

        label <<= DynAnyTest::ALARM_EVENT;
        useq[0].name = CORBA::string_dup("ev_data");
        useq[0].label = label;
        useq[0].type = CORBA::TypeCode::_duplicate(CORBA::_tc_any);
        useq[0].type_def = CORBA::IDLType::_nil ();

        label <<= DynAnyTest::LOG_EVENT;
        useq[1].name = CORBA::string_dup("ev_desc");
        useq[1].label = label;
        useq[1].type = CORBA::TypeCode::_duplicate(CORBA::_tc_string);
        useq[1].type_def = CORBA::IDLType::_nil ();

        CORBA::TypeCode_var eventDataTc;

        eventDataTc = orb->create_union_tc("IDL:DynAnyTest/EventData:1.0",
                                           "EventData",
                                           eventKindTc.in (),
                                           useq);

        // Now create DynUnion

        CORBA::Object_var obj = orb->resolve_initial_references("DynAnyFactory");

        DynamicAny::DynAnyFactory_var dfact =
                    DynamicAny::DynAnyFactory::_narrow(obj.in ());

        if (CORBA::is_nil (dfact.in ()))
          {
            ACE_ERROR_RETURN ((LM_ERROR,
                               "Nil dynamic any factory after narrow\n"),
                              -1);
          }

        DynamicAny::DynAny_var dany =
                    dfact->create_dyn_any_from_type_code(eventDataTc.in ());

        DynamicAny::DynUnion_var dunion =
          DynamicAny::DynUnion::_narrow(dany.in ());

        DynamicAny::DynAny_var disc = dunion->get_discriminator();

        DynamicAny::DynEnum_var denum =
          DynamicAny::DynEnum::_narrow(disc.in ());

        // This fails. The type of discriminator is ulong
        if (CORBA::is_nil (denum.in ()))
          {
            ACE_ERROR_RETURN ((LM_ERROR,
                               "Nil dynamic enum after narrow\n"),
                              -1);
          }

        ACE_DEBUG ((LM_DEBUG, "Dynamic Test Passed\n"));

        denum->destroy();
        dunion->destroy();
    }
  catch (const CORBA::Exception & ex)
    {
      ex._tao_print_exception ("Dynamic Test Failed with exception");
    }
  return 0;
}