2 #include "tao/IFR_Client/IFR_BasicC.h"
3 #include "tao/IFR_Client/IFR_Client_Adapter_Impl.h"
4 #include "tao/AnyTypeCode/NVList.h"
6 #include "ace/OS_NS_string.h"
8 int ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
14 ACE_DEBUG((LM_DEBUG
, "Start of Client\n"));
17 CORBA::ORB_var orb
= CORBA::ORB_init(argc
, argv
);
19 // Find the Interface Repository.
21 ACE_DEBUG((LM_DEBUG
, ". Find IFR\n"));
22 CORBA::Object_var ifr_obj
=
23 orb
->resolve_initial_references( "InterfaceRepository");
25 ACE_DEBUG((LM_DEBUG
, ". Narrow IFR\n"));
26 CORBA::Repository_var ifr
= CORBA::Repository::_narrow( ifr_obj
.in());
28 if( CORBA::is_nil( ifr
.in() ) )
30 ACE_DEBUG((LM_DEBUG
, "Nil IFR reference\n"));
34 ACE_DEBUG((LM_DEBUG
, ". Construct interface\n"));
35 // Add an interface to the repository.
37 CORBA::InterfaceDefSeq
baseInterfaces(1) ;
38 baseInterfaces
.length(0) ;
39 CORBA::InterfaceDef_var intface
=
40 ifr
->create_interface( "IDL:interface865:1.0",
45 // Add an operation to the interface.
46 // First get some useful things.
48 ACE_DEBUG((LM_DEBUG
, ". Get primitive ()\n"));
49 CORBA::PrimitiveDef_var voidPrimitive
=
50 ifr
->get_primitive( CORBA::pk_void
) ;
51 ACE_DEBUG((LM_DEBUG
, ". Get primitive (char)\n"));
52 CORBA::PrimitiveDef_var charPrimitive
=
53 ifr
->get_primitive( CORBA::pk_char
) ;
54 ACE_DEBUG((LM_DEBUG
, ". Get primitive (long)\n"));
55 CORBA::PrimitiveDef_var longPrimitive
=
56 ifr
->get_primitive( CORBA::pk_long
) ;
57 ACE_DEBUG((LM_DEBUG
, ". Get primitive (short)\n"));
58 CORBA::PrimitiveDef_var shortPrimitive
=
59 ifr
->get_primitive( CORBA::pk_short
) ;
61 ACE_DEBUG((LM_DEBUG
, ". create 3 parameters\n"));
62 // The operation has three parameters...
64 CORBA::ULong numParams
= 3 ;
65 CORBA::ParDescriptionSeq
parameters( numParams
) ;
66 parameters
.length( numParams
) ;
68 // ... which are: in char p1...
70 parameters
[0].name
= CORBA::string_dup("p1") ;
71 parameters
[0].type_def
=
72 CORBA::PrimitiveDef::_duplicate( charPrimitive
.in() ) ;
73 parameters
[0].type
= charPrimitive
->type() ;
74 parameters
[0].mode
= CORBA::PARAM_IN
;
78 parameters
[1].name
= CORBA::string_dup("p2") ;
79 parameters
[1].type_def
=
80 CORBA::PrimitiveDef::_duplicate( longPrimitive
.in() ) ;
81 parameters
[1].type
= longPrimitive
->type() ;
82 parameters
[1].mode
= CORBA::PARAM_OUT
;
84 // ...and inout short p3
86 parameters
[2].name
= CORBA::string_dup("p3") ;
87 parameters
[2].type_def
=
88 CORBA::PrimitiveDef::_duplicate( shortPrimitive
.in() ) ;
89 parameters
[2].type
= shortPrimitive
->type() ;
90 parameters
[2].mode
= CORBA::PARAM_INOUT
;
92 // ...and no exceptions...
94 ACE_DEBUG((LM_DEBUG
, ". create 0 excepts\n"));
95 CORBA::ExceptionDefSeq
exceptions( 1 ) ;
96 exceptions
.length( 0 ) ;
98 // ...and no context ids
100 ACE_DEBUG((LM_DEBUG
, ". create 0 cids\n"));
101 CORBA::ContextIdSeq
contextIds( 1 ) ;
102 contextIds
.length( 0 ) ;
104 // Create the operation, called "f".
106 ACE_DEBUG((LM_DEBUG
, ". create_operation\n"));
107 CORBA::OperationDef_var operation
=
108 intface
->create_operation( "IDL:interface865/f:1.0",
118 // Create operation list.
120 CORBA::NVList_var opList
;
122 ACE_DEBUG((LM_DEBUG
, "About to call create_operation_list\n"));
123 orb
->create_operation_list(operation
.in (),
126 ACE_DEBUG((LM_DEBUG
, "Call to create_operation_list succeeded\n"));
127 CORBA::ULong count
= opList
->count() ;
129 if( count
!= numParams
)
131 ACE_DEBUG((LM_DEBUG
, "Test failed - wrong number of elements n list\n")) ;
135 CORBA::NamedValue_ptr nv
= opList
->item( 0 ) ;
136 if(ACE_OS::strcmp( nv
->name(), "p1") != 0 )
138 ACE_DEBUG((LM_DEBUG
, "Test failed: param 1 wrong name\n"));
142 CORBA::Boolean
const eq_char
=
143 nv
->value()->type()->equal (CORBA::_tc_char
);
147 ACE_DEBUG((LM_DEBUG
, "Test failed: param 1 wrong type\n"));
150 if( nv
->flags() != CORBA::ARG_IN
)
152 ACE_DEBUG((LM_DEBUG
, "Test failed: param 1 wrong mode\n"));
156 nv
= opList
->item( 1 ) ;
157 if(ACE_OS::strcmp( nv
->name(), "p2") != 0 )
159 ACE_DEBUG((LM_DEBUG
, "Test failed: param 2 wrong name\n"));
163 CORBA::Boolean
const eq_long
=
164 nv
->value()->type()->equal (CORBA::_tc_long
);
168 ACE_DEBUG((LM_DEBUG
, "Test failed: param 2 wrong type\n"));
171 if( nv
->flags() != CORBA::ARG_OUT
)
173 ACE_DEBUG((LM_DEBUG
, "Test failed: param 2 wrong mode\n"));
177 nv
= opList
->item( 2 ) ;
178 if(ACE_OS::strcmp( nv
->name(), "p3") != 0 )
180 ACE_DEBUG((LM_DEBUG
, "Test failed: param 3 wrong name\n"));
184 CORBA::Boolean
const eq_short
=
185 nv
->value()->type()->equal (CORBA::_tc_short
);
189 ACE_DEBUG((LM_DEBUG
, "Test failed: param 3 wrong type\n"));
192 if( nv
->flags() != CORBA::ARG_INOUT
)
194 ACE_DEBUG((LM_DEBUG
, "Test failed: param 3 wrong mode\n"));
199 //operation->destroy();
201 // Finally destroy the interface.
211 ACE_DEBUG((LM_DEBUG
, ". seems OK\n"));
213 catch (const CORBA::Exception
& ex
)
215 ex
._tao_print_exception ("Exception - test failed:\n");
220 ACE_DEBUG((LM_DEBUG
, "An unknown exception occurred - test failed\n"));