From a96ba23b888bd76592b1071632a19989b0469163 Mon Sep 17 00:00:00 2001 From: prascle Date: Mon, 15 Sep 2003 09:12:08 +0000 Subject: [PATCH 1/1] PR : Embedded C++ Container in Session Server (Engines and Clients in a single process) --- first stage of development --- bin/runSalome | 2 +- bin/runSalome.py | 21 +++--- src/Session/Makefile.in | 6 +- src/Session/SALOME_Session_Server.cxx | 102 ++++++++++++++++++++++---- 4 files changed, 103 insertions(+), 28 deletions(-) diff --git a/bin/runSalome b/bin/runSalome index 0c88c8c98..a41903406 100755 --- a/bin/runSalome +++ b/bin/runSalome @@ -8,7 +8,7 @@ export SMESH_ROOT_DIR=/Salome2/SMESH_install export SUPERV_ROOT_DIR=/Salome2/SUPERV_install export VISU_ROOT_DIR=/Salome2/VISU_install -python -i runSalome.py --gui --modules=GEOM,SMESH,VISU,SUPERV,MED --xterm --containers=cpp,python --killall +python -i runSalome.py --gui --modules=GEOM,SMESH,VISU,SUPERV,MED --xterm --containers=python --killall #python -i runSalome.py --gui --modules=GEOM,SMESH,VISU,SUPERV,MED --logger --xterm #python -i runSalome.py --modules=GEOM,SMESH,VISU,SUPERV,MED #python -i runSalome.py --help diff --git a/bin/runSalome.py b/bin/runSalome.py index cc3a72b16..67cacf59d 100755 --- a/bin/runSalome.py +++ b/bin/runSalome.py @@ -203,7 +203,7 @@ class SessionLoader(Server): CMD=CMD+['GUI'] class SessionServer(Server): - CMD=['SALOME_Session_Server'] + CMD=['SALOME_Session_Server','FactoryServer','-ORBInitRef','NameService=corbaname::localhost'] class NotifyServer(Server): CMD=['notifd','-c','${KERNEL_ROOT_DIR}/share/salome/resources/channel.cfg -DFactoryIORFileName=/tmp/${LOGNAME}_rdifact.ior -DChannelIORFileName=/tmp/${LOGNAME}_rdichan.ior'] @@ -374,6 +374,10 @@ def startSalome(): import SALOME session=clt.waitNS("/Kernel/Session",SALOME.Session) + + theComputer = os.getenv("HOSTNAME") + computerSplitName = theComputer.split('.') + theComputer = computerSplitName[0] # # Lancement Container C++ local @@ -385,10 +389,6 @@ def startSalome(): # Attente de la disponibilité du Container C++ local dans le Naming Service # - theComputer = os.getenv("HOSTNAME") - computerSplitName = theComputer.split('.') - theComputer = computerSplitName[0] - clt.waitNS("/Containers/" + theComputer + "/FactoryServer") # @@ -404,12 +404,11 @@ def startSalome(): clt.waitNS("/Containers/" + theComputer + "/FactoryServerPy") - if with_container_superv: - - # - # Lancement Container Supervision local - # + # + # Lancement Container Supervision local + # + if with_container_superv: ContainerSUPERVServer().run() # @@ -426,7 +425,7 @@ def startSalome(): #session.GetInterface() end_time = os.times() - print + print "Start SALOME, elpased time : %5.1f seconds"% (end_time[4] - init_time[4]) return clt diff --git a/src/Session/Makefile.in b/src/Session/Makefile.in index cfeaf5945..a9f96cf63 100644 --- a/src/Session/Makefile.in +++ b/src/Session/Makefile.in @@ -46,12 +46,12 @@ LIB_SRC=\ # Executables targets BIN = SALOME_Session_Server BIN_SRC = -BIN_SERVER_IDL = SALOME_Session.idl -BIN_CLIENT_IDL = SALOMEDS.idl SALOMEDS_Attributes.idl SALOME_Component.idl SALOME_Registry.idl SALOME_ModuleCatalog.idl SALOME_Exception.idl +BIN_SERVER_IDL = SALOME_Session.idl SALOME_Component.idl +BIN_CLIENT_IDL = SALOMEDS.idl SALOMEDS_Attributes.idl SALOME_Registry.idl SALOME_ModuleCatalog.idl SALOME_Exception.idl CPPFLAGS+=$(QT_MT_INCLUDES) $(OCC_INCLUDES) $(PYTHON_INCLUDES) CXXFLAGS+=$(OCC_CXXFLAGS) -LDFLAGS+=$(QT_MT_LIBS) $(OCC_KERNEL_LIBS) $(OCC_OCAF_LIBS) $(OCC_VIEWER_LIBS) $(OCC_MODELER_LIBS) -lSalomeNS -lSalomeGUI -lSalomeObject -lSalomeLifeCycleCORBA -lqsplitterP -lOpUtil -lSalomeLoggerServer -lPlot2d +LDFLAGS+=$(QT_MT_LIBS) $(OCC_KERNEL_LIBS) $(OCC_OCAF_LIBS) $(OCC_VIEWER_LIBS) $(OCC_MODELER_LIBS) -lSalomeContainer -lSalomeNS -lSalomeGUI -lSalomeObject -lSalomeLifeCycleCORBA -lqsplitterP -lRegistry -lSalomeNotification -lOpUtil -lSalomeLoggerServer -lPlot2d @CONCLUDE@ diff --git a/src/Session/SALOME_Session_Server.cxx b/src/Session/SALOME_Session_Server.cxx index a53193848..36af98b64 100644 --- a/src/Session/SALOME_Session_Server.cxx +++ b/src/Session/SALOME_Session_Server.cxx @@ -29,6 +29,7 @@ # include "Utils_ORB_INIT.hxx" # include "Utils_SINGLETON.hxx" +#include "SALOME_Container_i.hxx" #include #include using namespace std; @@ -40,6 +41,12 @@ using namespace std; #include "SALOME_Session_i.hxx" +#include +static PyMethodDef MethodPyVoidMethod[] = { + { NULL, NULL } +}; + + //! CORBA server for SALOME Session /*! * SALOME_Session Server launches a SALOME session servant. @@ -55,45 +62,114 @@ using namespace std; int main(int argc, char **argv) { + Py_Initialize() ; + PySys_SetArgv( argc , argv ) ; + Py_InitModule( "InitPyRunMethod" , MethodPyVoidMethod ) ; + + try { + // Initialise the ORB. ORB_INIT &init = *SINGLETON_::Instance() ; ASSERT(SINGLETON_::IsAlreadyExisting()) ; CORBA::ORB_var &orb = init( argc , argv ) ; + // Obtain a reference to the root POA. CORBA::Object_var obj =orb->resolve_initial_references("RootPOA") ; - PortableServer::POA_var poa = PortableServer::POA::_narrow(obj) ; + PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj) ; + + // ------------------------------------------------------------------------------- + // ---- container + + // define policy objects + PortableServer::ImplicitActivationPolicy_var implicitActivation = + root_poa->create_implicit_activation_policy(PortableServer::NO_IMPLICIT_ACTIVATION) ; + + // default = NO_IMPLICIT_ACTIVATION + PortableServer::ThreadPolicy_var threadPolicy = + root_poa->create_thread_policy(PortableServer::ORB_CTRL_MODEL) ; + // default = ORB_CTRL_MODEL, other choice SINGLE_THREAD_MODEL + + // create policy list + CORBA::PolicyList policyList; + policyList.length(2); + policyList[0] = PortableServer::ImplicitActivationPolicy::_duplicate(implicitActivation) ; + policyList[1] = PortableServer::ThreadPolicy::_duplicate(threadPolicy) ; + + // create the child POA + PortableServer::POAManager_var nil_mgr = PortableServer::POAManager::_nil() ; + // PortableServer::POA_var factory_poa = + // root_poa->create_POA("factory_poa", pman, policyList) ; + PortableServer::POA_var factory_poa = + root_poa->create_POA("factory_poa", nil_mgr, policyList) ; + //with nil_mgr instead of pman, a new POA manager is created with the new POA + + // destroy policy objects + implicitActivation->destroy() ; + threadPolicy->destroy() ; + + // servant : container + + char *containerName = ""; + if (argc >1) + { + containerName = argv[1] ; + } - // servant - SALOME_Session_i * mySALOME_Session = new SALOME_Session_i(argc, argv, orb, poa) ; - PortableServer::ObjectId_var mySALOME_Sessionid = poa->activate_object(mySALOME_Session) ; - MESSAGE("poa->activate_object(mySALOME_Session)") + Engines_Container_i * myContainer + = new Engines_Container_i(orb, factory_poa, containerName , argc , argv ); + + //PortableServer::ObjectId_var mySALOME_Containerid = factory_poa->activate_object(myContainer) ; + //MESSAGE("poa->activate_object(myContainer)"); + + // obtain the factory poa manager + PortableServer::POAManager_var pmanfac = factory_poa->the_POAManager(); + pmanfac->activate() ; + MESSAGE("pmanfac->activate()") + + + // ------------------------------------------------------------------------------- + // servant : session + + //SALOME_Session_i * mySALOME_Session = new SALOME_Session_i(argc, argv, orb, factory_poa) ; + //PortableServer::ObjectId_var mySALOME_Sessionid = factory_poa->activate_object(mySALOME_Session) ; + + SALOME_Session_i * mySALOME_Session = new SALOME_Session_i(argc, argv, orb, root_poa) ; + PortableServer::ObjectId_var mySALOME_Sessionid = root_poa->activate_object(mySALOME_Session) ; + MESSAGE("poa->activate_object(mySALOME_Session)"); obj = mySALOME_Session->_this() ; CORBA::String_var sior(orb->object_to_string(obj)) ; - mySALOME_Session->NSregister(); - mySALOME_Session->_remove_ref() ; - PortableServer::POAManager_var pman = poa->the_POAManager() ; + // obtain the root poa manager + PortableServer::POAManager_var pman = root_poa->the_POAManager(); pman->activate() ; MESSAGE("pman->activate()") orb->run() ; orb->destroy() ; } - catch (CORBA::SystemException&) + catch (CORBA::SystemException&) + { + INFOS("Caught CORBA::SystemException."); + } + catch(PortableServer::POA::WrongPolicy&) + { + INFOS("Caught CORBA::WrongPolicyException."); + } + catch(PortableServer::POA::ServantAlreadyActive&) { - INFOS("Caught CORBA::SystemException.") + INFOS("Caught CORBA::ServantAlreadyActiveException"); } - catch (CORBA::Exception&) + catch (CORBA::Exception&) { - INFOS("Caught CORBA::Exception.") + INFOS("Caught CORBA::Exception."); } catch (...) { - INFOS("Caught unknown exception.") + INFOS("Caught unknown exception."); } return 0 ; } -- 2.39.2