1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/
23 #include "ObjRef_omniORB4.hh"
30 using namespace CORBA ;
34 static void DynInvoke( ObjRef_omniORB4::ObjRef_ptr objComponent ,
36 CORBA::Any * inParams , int nInParams ,
37 CORBA::Any * outParams , int nOutParams ) {
39 Request_var req = objComponent->_request( method ) ;
44 NVList_ptr arguments = req->arguments() ;
46 for ( i = 0 ; i < nInParams ; i++ ) {
47 CORBA::Any & data = inParams[i] ;
49 Type = data.type()->kind() ;
50 cout << "DynInvoke CORBA::ARG_IN" << i << " Type " << Type << endl ;
51 arguments->add_value( ArgName , data , CORBA::ARG_IN ) ;
53 //Check ObjectReference in ArgInput1
54 CORBA::Object_ptr myObjRefFromAny ;
55 //The folowing line runs with omniORB3 but not with omniORB4 :
56 // inParams[0] >>= myObjRefFromAny ;
57 //The folowing line runs with omniORB4 !!!...
58 inParams[0] >>= (CORBA::Any::to_object ) myObjRefFromAny ;
59 CORBA::String_var myObjRefIORFromAny ;
60 myObjRefIORFromAny = _ORB->object_to_string( myObjRefFromAny ) ;
61 if ( CORBA::is_nil( myObjRefFromAny ) ) {
62 cout << "The object reference from the Any is a nil reference in DynInvoke "
63 << myObjRefIORFromAny << endl ;
66 cout << "The object reference from the Any in DynInvoke is "
67 << myObjRefIORFromAny << endl ;
71 for ( i = 0 ; i < nOutParams ; i++ ) {
72 CORBA::Any & data = outParams[i] ;
74 Type = data.type()->kind() ;
75 cout << "DynInvoke CORBA::ARG_IN" << i << " Type " << Type << endl ;
76 arguments->add_value( ArgName , data , CORBA::ARG_OUT ) ;
81 if( req->env()->exception() ) {
82 req->env()->exception()->_raise() ;
83 return ; // pas utile ?
86 for ( i = 0 ; i < nOutParams ; i++ ) {
87 outParams[i] = *( arguments->item( i + nInParams )->value() ) ;
94 int main( int argc , char ** argv ) {
98 cout << "Usage : SuperV_Client_omniORB4 IOR" << endl ;
101 CORBA::ORB_var orb = CORBA::ORB_init( argc , argv , "omniORB4" ) ;
103 CORBA::Object_var obj = orb->string_to_object( argv[1] ) ;
104 ObjRef_omniORB4::ObjRef_var myObjRef = ObjRef_omniORB4::ObjRef::_narrow( obj ) ;
105 if ( CORBA::is_nil( myObjRef ) ) {
106 cout << "Cannot narrow the object reference or it was a nil reference" << endl ;
111 CORBA::Any myAnyObjRef ;
112 myAnyObjRef <<= myObjRef ;
113 //Check ObjectReference in ArgInput1
114 CORBA::Object_ptr myObjRefFromAny ;
115 //The folowing line runs with omniORB3 but not with omniORB4 :
116 // myAnyObjRef >>= myObjRefFromAny ;
117 //The folowing line runs with omniORB4 !!!...
118 myAnyObjRef >>= (CORBA::Any::to_object ) myObjRefFromAny ;
119 CORBA::String_var myObjRefIORFromAny ;
120 myObjRefIORFromAny = orb->object_to_string( myObjRefFromAny ) ;
121 if ( CORBA::is_nil( myObjRefFromAny ) ) {
122 cout << "The object reference from the Any is a nil reference before DynInvoke "
123 << myObjRefIORFromAny << endl ;
126 cout << "The object reference from the Any before DynInvoke is "
127 << myObjRefIORFromAny << endl ;
131 CORBA::Any myAnygetObjRef ;
132 myAnygetObjRef <<= ObjRef_omniORB4::ObjRef::_nil() ;
135 DynInvoke( myObjRef , "getObjRef" , &myAnyObjRef , 1 , &myAnygetObjRef , 1 ) ;
137 //Check ObjectReference in ArgInput1
138 if ( CORBA::is_nil( myObjRefFromAny ) ) {
139 cout << "The object reference from the Any is a nil reference after DynInvoke "
140 << myObjRefIORFromAny << endl ;
143 cout << "The object reference from the Any after DynInvoke is "
144 << myObjRefIORFromAny << endl ;
148 CORBA::Object_ptr mygetObjRef ;
149 myAnygetObjRef >>= mygetObjRef ;
150 CORBA::String_var mygetObjRefIOR = orb->object_to_string( mygetObjRef ) ;
151 if ( CORBA::is_nil( mygetObjRef ) ) {
152 cout << "The returned object reference is a nil reference "
153 << (char * ) mygetObjRefIOR << endl ;
156 cout << "The returned object reference is " << mygetObjRefIOR << endl ;
157 ObjRef_omniORB4::ObjRef_var mygetObjRefnarrowed ;
158 mygetObjRefnarrowed = ObjRef_omniORB4::ObjRef::_narrow( mygetObjRef ) ;
159 if ( CORBA::is_nil( mygetObjRef ) ) {
160 cout << "The returned narrowed object reference is a nil reference "
161 << mygetObjRefIOR << endl ;
165 mygetObjRefnarrowed->ping() ;
169 catch(CORBA::COMM_FAILURE & ex ) {
170 cout << "Caught CORBA::COMM_FAILURE" << endl ;
172 catch(CORBA::SystemException & ) {
173 cout << "Caught CORBA::SystemException" << endl ;
175 catch(CORBA::Exception & ) {
176 cout << "Caught CORBA::Exception" << endl ;
178 catch(omniORB::fatalException & fe ) {
179 cout << "Caught omniORB::fatalException" << endl ;
180 cout << " file " << fe.file() << endl ;
181 cout << " line " << fe.line() << endl ;
182 cout << " errmsg " << fe.errmsg() << endl ;
185 cout << "Caught unknown exception" << endl ;