1 #include "ace/Get_Opt.h"
2 #include "ace/OS_NS_string.h"
3 #include "tao/DynamicAny/DynamicAny.h"
5 #include "tao/IFR_Client/IFR_ComponentsC.h"
9 const ACE_TCHAR
*ifr_ior_file
= 0;
13 parse_args (int argc
, ACE_TCHAR
*argv
[])
15 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("i:s:"));
16 const unsigned char full_success
= 0x01;
17 unsigned char success
= 0;
22 if (success
== full_success
)
29 ACE_ERROR_RETURN ((LM_ERROR
,
40 ifr_ior_file
= get_opts
.opt_arg ();
46 // Indicates successful parsing of the command line
50 // ----------------------------------------------------------------------
52 int ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
55 ACE_DEBUG (( LM_DEBUG
, "Start\n" ));
60 CORBA::ORB_var the_orb
=
61 CORBA::ORB_init (argc
, argv
);
63 if (parse_args (argc
, argv
) == -1)
66 ACE_DEBUG (( LM_DEBUG
, "Get IFR\n" ));
67 CORBA::Object_var objref
=
68 the_orb
->string_to_object (ifr_ior_file
);
69 if (objref
.in () == 0)
71 ACE_ERROR_RETURN ((LM_ERROR
,
72 "The received objref is nil\n"),
76 ACE_DEBUG (( LM_DEBUG
, "Narrow IFR\n" ));
77 CORBA::ComponentIR::Repository_var the_repo_ref
;
78 the_repo_ref
= CORBA::ComponentIR::Repository::_narrow (objref
.in ());
80 ACE_DEBUG (( LM_DEBUG
, "Obtaining DynamicAny\n" ));
81 CORBA::Object_var factory_obj
=
82 the_orb
->resolve_initial_references ("DynAnyFactory");
83 DynamicAny::DynAnyFactory_var dynanyfactory
=
84 DynamicAny::DynAnyFactory::_narrow (factory_obj
.in ());
86 ACE_DEBUG (( LM_DEBUG
, "\nLook up c2\n" ));
87 CORBA::Contained_var c2
=
88 the_repo_ref
->lookup_id ("IDL:m1/c2:1.0");
89 if (CORBA::is_nil (c2
.in ()))
91 ACE_ERROR_RETURN ((LM_ERROR
,
92 "Can't look up the const m1/c2\n"),
95 CORBA::ConstantDef_var c2_def
= CORBA::ConstantDef::_narrow (c2
.in ());
96 CORBA::String_var c2_name
= c2_def
->absolute_name ();
97 CORBA::TypeCode_var c2_tc
= c2_def
->type ();
98 CORBA::String_var c2_id
= c2_tc
->id ();
99 ACE_DEBUG (( LM_DEBUG
, "constant \"%C\" is type \"%C\"", c2_name
.in (), c2_id
.in () ));
100 CORBA::TCKind c2_tckind
= c2_tc
->kind ();
101 ACE_DEBUG (( LM_DEBUG
, ", tkkind %d", c2_tckind
));
102 if (CORBA::tk_enum
== c2_tckind
)
104 ACE_DEBUG (( LM_DEBUG
, " (CORBA::tk_enum)\n" ));
105 CORBA::Any_var the_value
= c2_def
->value ();
107 DynamicAny::DynAny_var dany
=
108 dynanyfactory
->create_dyn_any (the_value
.in ());
109 DynamicAny::DynEnum_var denum
=
110 DynamicAny::DynEnum::_narrow (dany
.in ());
111 CORBA::String_var the_strValue
= denum
->get_as_string ();
112 CORBA::ULong the_intValue
= denum
->get_as_ulong ();
114 ACE_DEBUG ((LM_DEBUG
, "Whose value is \"%C\" which has an integer value of %d\n",
115 the_strValue
.in (), the_intValue
));
117 if (0 == ACE_OS::strcmp( "e1_2", the_strValue
.in () ))
119 ACE_DEBUG ((LM_DEBUG
, "The string value is correct\n" ));
123 ACE_DEBUG ((LM_DEBUG
, "ERROR: The string value should be \"e1_2\"\n" ));
126 if (1 == the_intValue
)
128 ACE_DEBUG ((LM_DEBUG
, "The corresponding integer value is correct\n" ));
132 ACE_DEBUG ((LM_DEBUG
, "ERROR: The corresponding integer value should be 1\n" ));
138 ACE_DEBUG ((LM_DEBUG
, "\nERROR: Wrong tkkind for m1::c2, should be %d\n", CORBA::tk_enum
));
142 catch (const CORBA::Exception
&ex
)
144 ex
._tao_print_exception ("ERROR: CORBA Exception");
149 ACE_DEBUG ((LM_DEBUG
, "ERROR: UNKNOWN Excetion\n"));
153 ACE_DEBUG (( LM_DEBUG
, "\nDone\n" ));