4 #include "ObjRef_omniORB4.hh"
11 using namespace CORBA ;
15 static void DynInvoke( ObjRef_omniORB4::ObjRef_ptr objComponent ,
17 CORBA::Any * inParams , int nInParams ,
18 CORBA::Any * outParams , int nOutParams ) {
20 Request_var req = objComponent->_request( method ) ;
25 NVList_ptr arguments = req->arguments() ;
27 for ( i = 0 ; i < nInParams ; i++ ) {
28 CORBA::Any & data = inParams[i] ;
30 Type = data.type()->kind() ;
31 cout << "DynInvoke CORBA::ARG_IN" << i << " Type " << Type << endl ;
32 arguments->add_value( ArgName , data , CORBA::ARG_IN ) ;
34 //Check ObjectReference in ArgInput1
35 CORBA::Object_ptr myObjRefFromAny ;
36 //The folowing line runs with omniORB3 but not with omniORB4 :
37 // inParams[0] >>= myObjRefFromAny ;
38 //The folowing line runs with omniORB4 !!!...
39 inParams[0] >>= (CORBA::Any::to_object ) myObjRefFromAny ;
40 CORBA::String_var myObjRefIORFromAny ;
41 myObjRefIORFromAny = _ORB->object_to_string( myObjRefFromAny ) ;
42 if ( CORBA::is_nil( myObjRefFromAny ) ) {
43 cout << "The object reference from the Any is a nil reference in DynInvoke "
44 << myObjRefIORFromAny << endl ;
47 cout << "The object reference from the Any in DynInvoke is "
48 << myObjRefIORFromAny << endl ;
52 for ( i = 0 ; i < nOutParams ; i++ ) {
53 CORBA::Any & data = outParams[i] ;
55 Type = data.type()->kind() ;
56 cout << "DynInvoke CORBA::ARG_IN" << i << " Type " << Type << endl ;
57 arguments->add_value( ArgName , data , CORBA::ARG_OUT ) ;
62 if( req->env()->exception() ) {
63 req->env()->exception()->_raise() ;
64 return ; // pas utile ?
67 for ( i = 0 ; i < nOutParams ; i++ ) {
68 outParams[i] = *( arguments->item( i + nInParams )->value() ) ;
75 int main( int argc , char ** argv ) {
79 cout << "Usage : SuperV_Client_omniORB4 IOR" << endl ;
82 CORBA::ORB_var orb = CORBA::ORB_init( argc , argv , "omniORB4" ) ;
84 CORBA::Object_var obj = orb->string_to_object( argv[1] ) ;
85 ObjRef_omniORB4::ObjRef_var myObjRef = ObjRef_omniORB4::ObjRef::_narrow( obj ) ;
86 if ( CORBA::is_nil( myObjRef ) ) {
87 cout << "Cannot narrow the object reference or it was a nil reference" << endl ;
92 CORBA::Any myAnyObjRef ;
93 myAnyObjRef <<= myObjRef ;
94 //Check ObjectReference in ArgInput1
95 CORBA::Object_ptr myObjRefFromAny ;
96 //The folowing line runs with omniORB3 but not with omniORB4 :
97 // myAnyObjRef >>= myObjRefFromAny ;
98 //The folowing line runs with omniORB4 !!!...
99 myAnyObjRef >>= (CORBA::Any::to_object ) myObjRefFromAny ;
100 CORBA::String_var myObjRefIORFromAny ;
101 myObjRefIORFromAny = orb->object_to_string( myObjRefFromAny ) ;
102 if ( CORBA::is_nil( myObjRefFromAny ) ) {
103 cout << "The object reference from the Any is a nil reference before DynInvoke "
104 << myObjRefIORFromAny << endl ;
107 cout << "The object reference from the Any before DynInvoke is "
108 << myObjRefIORFromAny << endl ;
112 CORBA::Any myAnygetObjRef ;
113 myAnygetObjRef <<= ObjRef_omniORB4::ObjRef::_nil() ;
116 DynInvoke( myObjRef , "getObjRef" , &myAnyObjRef , 1 , &myAnygetObjRef , 1 ) ;
118 //Check ObjectReference in ArgInput1
119 if ( CORBA::is_nil( myObjRefFromAny ) ) {
120 cout << "The object reference from the Any is a nil reference after DynInvoke "
121 << myObjRefIORFromAny << endl ;
124 cout << "The object reference from the Any after DynInvoke is "
125 << myObjRefIORFromAny << endl ;
129 CORBA::Object_ptr mygetObjRef ;
130 myAnygetObjRef >>= mygetObjRef ;
131 CORBA::String_var mygetObjRefIOR = orb->object_to_string( mygetObjRef ) ;
132 if ( CORBA::is_nil( mygetObjRef ) ) {
133 cout << "The returned object reference is a nil reference "
134 << (char * ) mygetObjRefIOR << endl ;
137 cout << "The returned object reference is " << mygetObjRefIOR << endl ;
138 ObjRef_omniORB4::ObjRef_var mygetObjRefnarrowed ;
139 mygetObjRefnarrowed = ObjRef_omniORB4::ObjRef::_narrow( mygetObjRef ) ;
140 if ( CORBA::is_nil( mygetObjRef ) ) {
141 cout << "The returned narrowed object reference is a nil reference "
142 << mygetObjRefIOR << endl ;
146 mygetObjRefnarrowed->ping() ;
150 catch(CORBA::COMM_FAILURE & ex ) {
151 cout << "Caught CORBA::COMM_FAILURE" << endl ;
153 catch(CORBA::SystemException & ) {
154 cout << "Caught CORBA::SystemException" << endl ;
156 catch(CORBA::Exception & ) {
157 cout << "Caught CORBA::Exception" << endl ;
159 catch(omniORB::fatalException & fe ) {
160 cout << "Caught omniORB::fatalException" << endl ;
161 cout << " file " << fe.file() << endl ;
162 cout << " line " << fe.line() << endl ;
163 cout << " errmsg " << fe.errmsg() << endl ;
166 cout << "Caught unknown exception" << endl ;