From 18ac854bdef328a61bec809405d640ecdc4f0bb9 Mon Sep 17 00:00:00 2001 From: rahuel Date: Wed, 26 Oct 2005 12:56:42 +0000 Subject: [PATCH] Tests omniORB Client and Server --- src/Supervision/Makefile.in | 11 +- src/Supervision/SuperV_Client_omniORB4.cxx | 169 +++++++++++++++++++++ src/Supervision/SuperV_Server_omniORB4.cxx | 69 +++++++++ 3 files changed, 246 insertions(+), 3 deletions(-) create mode 100644 src/Supervision/SuperV_Client_omniORB4.cxx create mode 100644 src/Supervision/SuperV_Server_omniORB4.cxx diff --git a/src/Supervision/Makefile.in b/src/Supervision/Makefile.in index 1573c67..6f212ff 100755 --- a/src/Supervision/Makefile.in +++ b/src/Supervision/Makefile.in @@ -79,22 +79,27 @@ LIB_CLIENT_IDL = SALOME_ModuleCatalog.idl \ SALOMEDS.idl \ SUPERV.idl \ SALOME_Exception.idl \ - SALOME_GenericObj.idl + SALOME_GenericObj.idl \ + ObjRef_omniORB4.idl # Executables targets -#BIN = SuperV_CheckOfUndefined +BIN = SuperV_Server_omniORB4 \ + SuperV_Client_omniORB4 BIN_SRC = BIN_SERVER_IDL = CPPFLAGS+= $(PYTHON_INCLUDES) $(QT_MT_INCLUDES) $(VTK_INCLUDES) $(OGL_INCLUDES) $(OCC_INCLUDES) $(BOOST_CPPFLAGS)\ -I${KERNEL_ROOT_DIR}/include/salome CXXFLAGS += -g -D__x86__ -D__linux__ -ftemplate-depth-42 -Wall \ - -I${KERNEL_ROOT_DIR}/include/salome + -I${KERNEL_ROOT_DIR}/include/salome -L${SUPERV_ROOT_DIR}/lib/salome LDFLAGS+= -lSalomeSuperVisionEditor -lSalomeSuperVisionExecutor -lSalomeSuperVisionBase \ -lSalomeContainer -lSalomeNotification -lSalomeNS -lSalomeLifeCycleCORBA \ -lOpUtil -lRegistry -lTOOLSDS -lSALOMELocalTrace \ $(QT_MT_LIBS) -L${KERNEL_ROOT_DIR}/lib/salome #LIBS += -Xlinker -export-dynamic $(PYTHON_LIBS) +LDFLAGSFORBIN= -L${SUPERV_ROOT_DIR}/lib/salome +LIBSFORBIN=$(LIBS) + @CONCLUDE@ diff --git a/src/Supervision/SuperV_Client_omniORB4.cxx b/src/Supervision/SuperV_Client_omniORB4.cxx new file mode 100644 index 0000000..15c468f --- /dev/null +++ b/src/Supervision/SuperV_Client_omniORB4.cxx @@ -0,0 +1,169 @@ + +#include +#include +#include "ObjRef_omniORB4.hh" + +#include +#include + +using namespace std; + +using namespace CORBA ; + +CORBA::ORB_var _ORB ; + +static void DynInvoke( ObjRef_omniORB4::ObjRef_ptr objComponent , + const char *method , + CORBA::Any * inParams , int nInParams , + CORBA::Any * outParams , int nOutParams ) { + + Request_var req = objComponent->_request( method ) ; + const char *ArgName ; + int Type ; + int i ; + + NVList_ptr arguments = req->arguments() ; + + for ( i = 0 ; i < nInParams ; i++ ) { + CORBA::Any & data = inParams[i] ; + ArgName = "" ; + Type = data.type()->kind() ; + cout << "DynInvoke CORBA::ARG_IN" << i << " Type " << Type << endl ; + arguments->add_value( ArgName , data , CORBA::ARG_IN ) ; + } +//Check ObjectReference in ArgInput1 + CORBA::Object_ptr myObjRefFromAny ; +//The folowing line runs with omniORB3 but not with omniORB4 : +// inParams[0] >>= myObjRefFromAny ; +//The folowing line runs with omniORB4 !!!... + inParams[0] >>= (CORBA::Any::to_object ) myObjRefFromAny ; + CORBA::String_var myObjRefIORFromAny ; + myObjRefIORFromAny = _ORB->object_to_string( myObjRefFromAny ) ; + if ( CORBA::is_nil( myObjRefFromAny ) ) { + cout << "The object reference from the Any is a nil reference in DynInvoke " + << myObjRefIORFromAny << endl ; + } + else { + cout << "The object reference from the Any in DynInvoke is " + << myObjRefIORFromAny << endl ; + } + + + for ( i = 0 ; i < nOutParams ; i++ ) { + CORBA::Any & data = outParams[i] ; + ArgName = "" ; + Type = data.type()->kind() ; + cout << "DynInvoke CORBA::ARG_IN" << i << " Type " << Type << endl ; + arguments->add_value( ArgName , data , CORBA::ARG_OUT ) ; + } + + req->invoke(); + + if( req->env()->exception() ) { + req->env()->exception()->_raise() ; + return ; // pas utile ? + } + + for ( i = 0 ; i < nOutParams ; i++ ) { + outParams[i] = *( arguments->item( i + nInParams )->value() ) ; + } + + return; + +} + +int main( int argc , char ** argv ) { + + try { + if ( argc != 2 ) { + cout << "Usage : SuperV_Client_omniORB4 IOR" << endl ; + return 1 ; + } + CORBA::ORB_var orb = CORBA::ORB_init( argc , argv , "omniORB4" ) ; + _ORB = orb ; + CORBA::Object_var obj = orb->string_to_object( argv[1] ) ; + ObjRef_omniORB4::ObjRef_var myObjRef = ObjRef_omniORB4::ObjRef::_narrow( obj ) ; + if ( CORBA::is_nil( myObjRef ) ) { + cout << "Cannot narrow the object reference or it was a nil reference" << endl ; + return 1 ; + } + +//ArgInput1 : + CORBA::Any myAnyObjRef ; + myAnyObjRef <<= myObjRef ; +//Check ObjectReference in ArgInput1 + CORBA::Object_ptr myObjRefFromAny ; +//The folowing line runs with omniORB3 but not with omniORB4 : +// myAnyObjRef >>= myObjRefFromAny ; +//The folowing line runs with omniORB4 !!!... + myAnyObjRef >>= (CORBA::Any::to_object ) myObjRefFromAny ; + CORBA::String_var myObjRefIORFromAny ; + myObjRefIORFromAny = orb->object_to_string( myObjRefFromAny ) ; + if ( CORBA::is_nil( myObjRefFromAny ) ) { + cout << "The object reference from the Any is a nil reference before DynInvoke " + << myObjRefIORFromAny << endl ; + } + else { + cout << "The object reference from the Any before DynInvoke is " + << myObjRefIORFromAny << endl ; + } + +//ArgOutput1 : + CORBA::Any myAnygetObjRef ; + myAnygetObjRef <<= ObjRef_omniORB4::ObjRef::_nil() ; + +//Dynamic invocation + DynInvoke( myObjRef , "getObjRef" , &myAnyObjRef , 1 , &myAnygetObjRef , 1 ) ; + +//Check ObjectReference in ArgInput1 + if ( CORBA::is_nil( myObjRefFromAny ) ) { + cout << "The object reference from the Any is a nil reference after DynInvoke " + << myObjRefIORFromAny << endl ; + } + else { + cout << "The object reference from the Any after DynInvoke is " + << myObjRefIORFromAny << endl ; + } + +//ArgOutput1 : + CORBA::Object_ptr mygetObjRef ; + myAnygetObjRef >>= mygetObjRef ; + CORBA::String_var mygetObjRefIOR = orb->object_to_string( mygetObjRef ) ; + if ( CORBA::is_nil( mygetObjRef ) ) { + cout << "The returned object reference is a nil reference " + << (char * ) mygetObjRefIOR << endl ; + return 1 ; + } + cout << "The returned object reference is " << mygetObjRefIOR << endl ; + ObjRef_omniORB4::ObjRef_var mygetObjRefnarrowed ; + mygetObjRefnarrowed = ObjRef_omniORB4::ObjRef::_narrow( mygetObjRef ) ; + if ( CORBA::is_nil( mygetObjRef ) ) { + cout << "The returned narrowed object reference is a nil reference " + << mygetObjRefIOR << endl ; + return 1 ; + } + + mygetObjRefnarrowed->ping() ; + + orb->destroy() ; + } + catch(CORBA::COMM_FAILURE & ex ) { + cout << "Caught CORBA::COMM_FAILURE" << endl ; + } + catch(CORBA::SystemException & ) { + cout << "Caught CORBA::SystemException" << endl ; + } + catch(CORBA::Exception & ) { + cout << "Caught CORBA::Exception" << endl ; + } + catch(omniORB::fatalException & fe ) { + cout << "Caught omniORB::fatalException" << endl ; + cout << " file " << fe.file() << endl ; + cout << " line " << fe.line() << endl ; + cout << " errmsg " << fe.errmsg() << endl ; + } + catch( ... ) { + cout << "Caught unknown exception" << endl ; + } + return 0 ; +} diff --git a/src/Supervision/SuperV_Server_omniORB4.cxx b/src/Supervision/SuperV_Server_omniORB4.cxx new file mode 100644 index 0000000..afd0577 --- /dev/null +++ b/src/Supervision/SuperV_Server_omniORB4.cxx @@ -0,0 +1,69 @@ + +#include +#include +#include "ObjRef_omniORB4.hh" + +using namespace std; + +class ObjRef_i : public POA_ObjRef_omniORB4::ObjRef { + +public: + +ObjRef_i() {} ; +virtual ~ObjRef_i() {} ; + +virtual ObjRef_omniORB4::ObjRef_ptr getObjRef( const ObjRef_omniORB4::ObjRef_ptr anObjRef ) ; + +virtual bool ping() ; + +} ; + + +ObjRef_omniORB4::ObjRef_ptr ObjRef_i::getObjRef( const ObjRef_omniORB4::ObjRef_ptr anObjRef ) { + + cout << "ObjRef_i::getObjRef" << endl ; + anObjRef->ping() ; + cout << "ObjRef_i::getObjRef will return the same object reference" << endl ; + return ObjRef_omniORB4::ObjRef::_duplicate( anObjRef ) ; + +} ; + +bool ObjRef_i::ping() { + cout << "ping" << endl ; + return true ; +} + +int main( int argc , char ** argv ) { + + try { + CORBA::ORB_var orb = CORBA::ORB_init( argc , argv , "omniORB4" ) ; + CORBA::Object_var obj = orb->resolve_initial_references( "RootPOA" ) ; + PortableServer::POA_var poa = PortableServer::POA::_narrow( obj ) ; + ObjRef_i * myObjRef = new ObjRef_i() ; + PortableServer::ObjectId_var myObjectId = poa->activate_object( myObjRef ) ; + obj = myObjRef->_this() ; + CORBA::String_var myIOR = orb->object_to_string( obj ) ; + cout << "myIOR : '" << (char * ) myIOR << "'" << endl ; + myObjRef->_remove_ref() ; + PortableServer::POAManager_var pman = poa->the_POAManager() ; + pman->activate() ; + orb->run() ; + orb->destroy() ; + } + catch(CORBA::SystemException & ) { + cout << "Caught CORBA::SystemException" << endl ; + } + catch(CORBA::Exception & ) { + cout << "Caught CORBA::Exception" << endl ; + } + catch(omniORB::fatalException & fe ) { + cout << "Caught omniORB::fatalException" << endl ; + cout << " file " << fe.file() << endl ; + cout << " line " << fe.line() << endl ; + cout << " errmsg " << fe.errmsg() << endl ; + } + catch( ... ) { + cout << "Caught unknown exception" << endl ; + } + return 0 ; +} -- 2.39.2