env_ld_library_path=['env', 'LD_LIBRARY_PATH='+ os.getenv("LD_LIBRARY_PATH")]
args = self.ARGS+ env_ld_library_path + self.CMD
args = self.ARGS+self.CMD
- #print "args = ", args
+ print "args = ", args
pid = os.spawnvp(os.P_NOWAIT, args[0], args)
process_id[pid]=self.CMD
CMD=CMD+['GUI']
class SessionServer(Server):
- CMD=['SALOME_Session_Server']
+ SCMD1=['SALOME_Session_Server',
+ '--with','Registry','(','--salome_session','theSession',')',
+ '--with','ModuleCatalog','(','-common']
+ SCMD2=['-personal','${HOME}/Salome/resources/CatalogModulePersonnel.xml',')',
+ '--with','SALOMEDS','(',')',
+ '--with','Container','(','FactoryServer','-ORBInitRef','NameService=corbaname::localhost',')',
+ '--with','Container','(','SuperVisionContainer','-ORBInitRef','NameService=corbaname::localhost',')']
+ def setpath(self,liste_modules):
+ cata_path=[]
+ for module in liste_modules:
+ module_root_dir=modules_root_dir[module]
+ module_cata=module+"Catalog.xml"
+ print " ", module_cata
+ cata_path.extend(glob.glob(os.path.join(module_root_dir,"share","salome","resources",module_cata)))
+ self.CMD=self.SCMD1 + [string.join(cata_path,':')] + self.SCMD2
class NotifyServer(Server):
CMD=['notifd','-c','${KERNEL_ROOT_DIR}/share/salome/resources/channel.cfg -DFactoryIORFileName=/tmp/${LOGNAME}_rdifact.ior -DChannelIORFileName=/tmp/${LOGNAME}_rdichan.ior']
# Lancement Registry Server
#
- RegistryServer().run()
+ # RegistryServer().run()
#
# Attente de la disponibilité du Registry dans le Naming Service
#
- clt.waitNS("/Registry")
+ # clt.waitNS("/Registry")
#
# Lancement Catalog Server
#
- cataServer=CatalogServer()
- cataServer.setpath(liste_modules)
- cataServer.run()
+ # cataServer=CatalogServer()
+ # cataServer.setpath(liste_modules)
+ # cataServer.run()
#
# Attente de la disponibilité du Catalog Server dans le Naming Service
#
- import SALOME_ModuleCatalog
- clt.waitNS("/Kernel/ModulCatalog",SALOME_ModuleCatalog.ModuleCatalog)
+ # import SALOME_ModuleCatalog
+ # clt.waitNS("/Kernel/ModulCatalog",SALOME_ModuleCatalog.ModuleCatalog)
#
# Lancement SalomeDS Server
os.environ["CSF_PluginDefaults"]=os.path.join(kernel_root_dir,"share","salome","resources")
os.environ["CSF_SALOMEDS_ResourcesDefaults"]=os.path.join(kernel_root_dir,"share","salome","resources")
- SalomeDSServer().run()
+ # SalomeDSServer().run()
if "GEOM" in liste_modules:
print "GEOM OCAF Resources"
# Attente de la disponibilité du SalomeDS dans le Naming Service
#
- clt.waitNS("/myStudyManager")
+ # clt.waitNS("/myStudyManager")
#
# Lancement Session Server
#
- SessionServer().run()
+ mySessionServ=SessionServer()
+ mySessionServ.setpath(liste_modules)
+ mySessionServ.run()
+ #SessionServer().run()
#
# Attente de la disponibilité du Session Server dans le Naming Service
#
- import SALOME
- session=clt.waitNS("/Kernel/Session",SALOME.Session)
+ #import SALOME
+ #session=clt.waitNS("/Kernel/Session",SALOME.Session)
if os.getenv("HOSTNAME") == None:
if os.getenv("HOST") == None:
#
# Lancement Container C++ local
#
- if with_container_cpp:
- ContainerCPPServer().run()
+ #if with_container_cpp:
+ #ContainerCPPServer().run()
#
# Attente de la disponibilité du Container C++ local dans le Naming Service
#
- clt.waitNS("/Containers/" + theComputer + "/FactoryServer")
+ #clt.waitNS("/Containers/" + theComputer + "/FactoryServer")
#
# Lancement Container Python local
#
- if with_container_python:
- ContainerPYServer().run()
+ #if with_container_python:
+ #ContainerPYServer().run()
#
# Attente de la disponibilité du Container Python local dans le Naming Service
#
- clt.waitNS("/Containers/" + theComputer + "/FactoryServerPy")
+ #clt.waitNS("/Containers/" + theComputer + "/FactoryServerPy")
- if with_container_superv:
+ #if with_container_superv:
#
# Lancement Container Supervision local
#
- ContainerSUPERVServer().run()
+ #ContainerSUPERVServer().run()
#
# Attente de la disponibilité du Container Supervision local dans le Naming Service
#
- clt.waitNS("/Containers/" + theComputer + "/SuperVisionContainer")
+ #clt.waitNS("/Containers/" + theComputer + "/SuperVisionContainer")
#
EXPORT_PYSCRIPTS =
EXPORT_HEADERS = \
- RegistryConnexion.hxx
+ RegistryConnexion.hxx \
+ RegistryService.hxx
# Libraries targets
LIB = libRegistry.la
-LIB_SRC = RegistryConnexion.cxx
+LIB_SRC = \
+ RegistryConnexion.cxx \
+ RegistryService.cxx
LIB_CLIENT_IDL = SALOME_Registry.idl
# Executables targets
BIN = SALOME_Registry_Server
-BIN_SRC = RegistryService.cxx
+BIN_SRC =
BIN_SERVER_IDL = SALOME_Registry.idl
LDFLAGS+= -lSalomeNS -lOpUtil -lSALOMELocalTrace
@COMMENCE@
+EXPORT_HEADERS= \
+ SALOMEDS_StudyManager_i.hxx \
+ SALOMEDS_OCAFApplication.hxx \
+ Handle_SALOMEDS_OCAFApplication.hxx
# Libraries targets
# Libraries targets
LIB = libSalomeSession.la
LIB_SRC=\
- SALOME_Session_i.cxx
+ SALOME_Session_i.cxx \
+ Session_ServerThread.cxx \
+ Session_ServerLauncher.cxx
# Executables targets
BIN = SALOME_Session_Server
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
-CPPFLAGS+=$(QT_MT_INCLUDES) $(OCC_INCLUDES) $(PYTHON_INCLUDES)
+CPPFLAGS+=$(QT_MT_INCLUDES) $(OCC_INCLUDES) $(PYTHON_INCLUDES) $(HDF5_INCLUDES)
CXXFLAGS+=$(OCC_CXXFLAGS)
-LDFLAGS+=$(QT_MT_LIBS) -lSalomeNS -lSalomeGUI -lSalomeObject -lSalomeLifeCycleCORBA -lqsplitterP -lOpUtil -lPlot2d -lSalomeVTKFilter -lSALOMELocalTrace
+LDFLAGS+=$(QT_MT_LIBS) $(HDF5_LIBS) -lSalomeHDFPersist -lSalomeNS -lSalomeGUI -lSalomeObject -lSalomeLifeCycleCORBA -lqsplitterP -lOpUtil -lPlot2d -lSalomeVTKFilter -lSALOMELocalTrace -lSalomeContainer -lRegistry -lSalomeNotification -lSalomeDS -lTOOLSDS -lSalomeGenericObj -lSalomeCatalog
@CONCLUDE@
#include <qthread.h>
#include <qapplication.h>
#include <qlabel.h>
+#include <qwaitcondition.h>
#include "SALOMEGUI_Application.h"
#include "QAD.h"
#include "SALOME_Session_i.hxx"
+#include "Session_ServerLauncher.hxx"
+
+/*! - read arguments, define list of server to launch with their arguments.
+ * - wait for naming service
+ * - create and run a thread for launch of all servers
+ *
+ */
+
// ----------------------------------------------------------------------------
-class SERVANT_Launcher: public QThread
-{
- int _argc;
- char**_argv;
- CORBA::ORB_var _orb;
- PortableServer::POA_var _poa;
- QMutex* _GUIMutex;
-public:
- SERVANT_Launcher(int argc, char ** argv, CORBA::ORB_ptr orb, PortableServer::POA_ptr poa, QMutex *GUIMutex)
- {
- _argc=argc;
- _argv=argv;
- _orb=CORBA::ORB::_duplicate(orb);
- _poa=PortableServer::POA::_duplicate(poa);
- _GUIMutex=GUIMutex;
- };
- void run()
- {
- try
- {
- INFOS("SERVANT_Launcher thread started");
- SALOME_Session_i * mySALOME_Session = new SALOME_Session_i(_argc, _argv, _orb, _poa, _GUIMutex) ;
- PortableServer::ObjectId_var mySALOME_Sessionid = _poa->activate_object(mySALOME_Session) ;
- INFOS("poa->activate_object(mySALOME_Session)");
-
- CORBA::Object_var 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() ;
- pman->activate() ;
- INFOS("pman->activate()");
-
- _orb->run() ;
- _orb->destroy() ;
- }
- catch (CORBA::SystemException&)
- {
- INFOS("Caught CORBA::SystemException.");
- }
- catch (CORBA::Exception&)
- {
- INFOS("Caught CORBA::Exception.");
- }
- catch (...)
- {
- INFOS("Caught unknown exception.");
- }
- }
-};
// ----------------------------------------------------------------------------
{
ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()) ;
- CORBA::ORB_var &orb = init( argc , argv ) ;
+ int orbArgc = 1;
+ CORBA::ORB_var &orb = init( orbArgc , argv ) ;
- long TIMESleep = 250000000;
- int NumberOfTries = 40;
- int a;
- timespec ts_req;
- ts_req.tv_nsec=TIMESleep;
- ts_req.tv_sec=0;
- timespec ts_rem;
- ts_rem.tv_nsec=0;
- ts_rem.tv_sec=0;
- CosNaming::NamingContext_var inc;
- PortableServer::POA_var poa;
- CORBA::Object_var theObj;
- CORBA::Object_var obj;
- CORBA::Object_var object;
- SALOME_NamingService *_NS = SINGLETON_<SALOME_NamingService>::Instance();
- _NS->init_orb(orb);
+ CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
+ PortableServer::POA_var poa = PortableServer::POA::_narrow(obj);
+
+ PortableServer::POAManager_var pman = poa->the_POAManager() ;
+ pman->activate() ;
+ INFOS("pman->activate()");
+
+ SALOME_NamingService *_NS = new SALOME_NamingService(orb);
- int SESSION=0;
- const char * Env = getenv("USE_LOGGER");
- int EnvL =0;
- if ((Env!=NULL) && (strlen(Env)))
- EnvL=1;
- CosNaming::Name name;
- name.length(1);
- name[0].id=CORBA::string_dup("Logger");
- PortableServer::POAManager_var pman;
- for (int i = 1; i<=NumberOfTries; i++)
- {
- if (i!=1)
- a=nanosleep(&ts_req,&ts_rem);
- try
- {
- obj = orb->resolve_initial_references("RootPOA");
- if(!CORBA::is_nil(obj))
- poa = PortableServer::POA::_narrow(obj);
- if(!CORBA::is_nil(poa))
- pman = poa->the_POAManager();
- if(!CORBA::is_nil(orb))
- theObj = orb->resolve_initial_references("NameService");
- if (!CORBA::is_nil(theObj))
- inc = CosNaming::NamingContext::_narrow(theObj);
- }
- catch( CORBA::COMM_FAILURE& )
- {
- MESSAGE( "Session Server: CORBA::COMM_FAILURE: Unable to contact the Naming Service" );
- }
- if(!CORBA::is_nil(inc))
- {
- MESSAGE( "Session Server: Naming Service was found" );
- if(EnvL==1)
- {
- for(int j=1; j<=NumberOfTries; j++)
- {
- if (j!=1)
- a=nanosleep(&ts_req, &ts_rem);
- try
- {
- object = inc->resolve(name);
- }
- catch(CosNaming::NamingContext::NotFound)
- {
- MESSAGE( "Session Server: Logger Server wasn't found" );
- }
- catch(...)
- {
- MESSAGE( "Session Server: Unknown exception" );
- }
- if (!CORBA::is_nil(object))
- {
- MESSAGE( "Session Server: Loger Server was found" );
- SESSION=1;
- break;
- }
- }
- }
- }
- if ((SESSION==1)||((EnvL==0)&&(!CORBA::is_nil(inc))))
- break;
- }
// CORBA Servant Launcher
+
QMutex _GUIMutex ;
- SERVANT_Launcher * mySERVANT_Launcher = new SERVANT_Launcher(argc, argv, orb, poa, &_GUIMutex);
- mySERVANT_Launcher->start();
-
- // QApplication
+ Session_ServerLauncher* myServerLauncher
+ = new Session_ServerLauncher(argc, argv, orb, poa, &_GUIMutex);
+ myServerLauncher->Init();
+
+ INFOS("Session activated, Launch IAPP...");
- QApplication *_qappl = new QApplication(argc, argv );
+ _GUIMutex.lock();
+ int qappArgc = 1;
+ QApplication *_qappl = new QApplication(qappArgc, argv );
INFOS("creation QApplication");
+ _GUIMutex.unlock();
QAD_ASSERT ( QObject::connect(_qappl, SIGNAL(lastWindowClosed()), _qappl, SLOT(quit()) ) );
SALOMEGUI_Application* _mw = new SALOMEGUI_Application ( "MDTV-Standard", "HDF", "hdf" );
{
INFOS("Caught unknown exception from Naming Service");
}
- MESSAGE("NSregister end");
+ MESSAGE("Session registered in Naming Service");
}
//=============================================================================
--- /dev/null
+// SALOME Session : implementation of Session_ServerLauncher.cxx
+//
+// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
+//
+//
+//
+// File : Session_ServerLauncher.xx
+// Author : Paul RASCLE, EDF
+// Module : SALOME
+// $Header$
+
+#include "Session_ServerLauncher.hxx"
+
+#include "Utils_SALOME_Exception.hxx"
+#include "utilities.h"
+
+//=============================================================================
+/*!
+ * default constructor not for use
+ */
+//=============================================================================
+
+Session_ServerLauncher::Session_ServerLauncher()
+{
+ ASSERT(0); // must not be called
+}
+
+//=============================================================================
+/*!
+ * constructor
+ */
+//=============================================================================
+
+Session_ServerLauncher::Session_ServerLauncher(int argc,
+ char ** argv,
+ CORBA::ORB_ptr orb,
+ PortableServer::POA_ptr poa,
+ QMutex *GUIMutex)
+{
+ _argc = argc;
+ _argv = argv;
+ _orb = CORBA::ORB::_duplicate(orb);
+ _root_poa = PortableServer::POA::_duplicate(poa);
+ _GUIMutex = GUIMutex;
+}
+
+//=============================================================================
+/*!
+ * destructor
+ */
+//=============================================================================
+
+Session_ServerLauncher::~Session_ServerLauncher()
+{
+}
+
+//=============================================================================
+/*!
+ * Check args and activate servers
+ */
+//=============================================================================
+
+void Session_ServerLauncher::Init()
+{
+ CheckArgs();
+ ActivateAll();
+}
+
+//=============================================================================
+/*!
+ * controls and dispatchs arguments given with command
+ */
+//=============================================================================
+
+void Session_ServerLauncher::CheckArgs()
+{
+ int argState = 0;
+ ServArg aServArg(0,0,0);
+ _argCopy.reserve(_argc);
+ for (int iarg=0; iarg <_argc; iarg++)
+ {
+ SCRUTE(iarg);
+ SCRUTE(_argv[iarg]);
+ _argCopy.push_back(_argv[iarg]);
+ switch (argState)
+ {
+ case 0: // looking for "--with"
+ {
+ if (strcmp(_argv[iarg],"--with")==0)
+ argState = 1;
+ break;
+ }
+ case 1: // looking for server type
+ {
+ for (int i=0; i<Session_ServerThread::NB_SRV_TYP; i++)
+ if (strcmp(_argv[iarg],Session_ServerThread::_serverTypes[i])==0)
+ {
+ aServArg._servType = i;
+ argState = 2;
+ break;
+ }
+ break;
+ }
+ case 2: // looking for "("
+ {
+ if (strcmp(_argv[iarg],"(")!=0)
+ {
+ INFOS("parenthesis '(' is required here...");
+ for (int i=0; i<iarg; i++)
+ cerr << _argv[i] << " ";
+ cerr << endl;
+ throw SALOME_Exception(LOCALIZED("Error in command arguments, missing prenthesis"));
+ }
+ else
+ {
+ aServArg._firstArg=iarg+1; // arg after '('
+ argState = 3;
+ }
+ break;
+ }
+ case 3: // looking for arguments
+ {
+ if (strcmp(_argv[iarg],")")==0) // end of arguments = ')'
+ {
+ aServArg._lastArg=iarg-1; // arg before ')'
+ MESSAGE("server : "<< Session_ServerThread::_serverTypes[aServArg._servType]);
+ for (int i=aServArg._firstArg; i<=aServArg._lastArg; i++)
+ MESSAGE(" arg : " << _argCopy[i]);
+ _argServToLaunch.push_back(aServArg);
+ argState = 0;
+ }
+ break;
+ }
+ default:
+ {
+ ASSERT(0);
+ break;
+ }
+ }
+ }
+ if (argState == 1)
+ throw SALOME_Exception(LOCALIZED("Error in command arguments, missing server type"));
+ if (argState == 2)
+ throw SALOME_Exception(LOCALIZED("Error in command arguments, missing parenthesis '('"));
+ if (argState == 3)
+ throw SALOME_Exception(LOCALIZED("Error in command arguments, missing parenthesis ')'"));
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+
+void Session_ServerLauncher::ActivateAll()
+{
+ list<ServArg>::iterator itServ;
+ for (itServ = _argServToLaunch.begin(); itServ !=_argServToLaunch.end(); itServ++)
+ {
+ int argc = 2 + (*itServ)._lastArg - (*itServ)._firstArg;
+ char** argv = new char*[argc+1];
+ argv[argc]=0; // for Engines_Container_i constructor...
+ int servType = (*itServ)._servType;
+ argv[0]=strdup(Session_ServerThread::_serverTypes[servType]);
+ if (argc>1)
+ {
+ for (int i=0; i<argc-1; i++)
+ //argv[i+1] = _argCopy[(*itServ)._firstArg + i].c_str();
+ argv[i+1] = _argv[(*itServ)._firstArg + i];
+ }
+ Session_ServerThread* aServerThread
+ = new Session_ServerThread(argc, argv, _orb,_root_poa,_GUIMutex,&_ServerLaunch);
+ _serverThreads.push_back(aServerThread);
+
+ //_GUIMutex->lock(); // to block server threads until wait(mutex)
+ aServerThread->start();
+ MESSAGE("waiting wakeAll()");
+ _ServerLaunch.wait(); // to be reseased by serverThread when ready
+ //_ServerLaunch.wait(_GUIMutex); // to be reseased by serverThread when ready
+ }
+
+ // Always launch Session Server
+
+ int argc=1;
+ char** argv = new char*[argc];
+ argv[0] = "Session";
+ Session_ServerThread* aServerThread
+ = new Session_ServerThread(argc, argv, _orb,_root_poa,_GUIMutex,&_ServerLaunch);
+ _serverThreads.push_back(aServerThread);
+
+ //_GUIMutex->lock(); // to block server threads until wait(mutex)
+ aServerThread->start();
+ _ServerLaunch.wait(); // to be reseased by serverThread when ready
+}
+
--- /dev/null
+// SALOME Session : implementation of Session_ServerLauncher.hxx
+//
+// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
+//
+//
+//
+// File : Session_ServerLauncher.hxx
+// Author : Paul RASCLE, EDF
+// Module : SALOME
+// $Header$
+
+#ifndef _SESSION_SERVERLAUNCHER_HXX_
+#define _SESSION_SERVERLAUNCHER_HXX_
+
+#include "Session_ServerThread.hxx"
+
+#include <CORBA.h>
+#include <list>
+#include <vector>
+#include <string>
+#include <qwaitcondition.h>
+
+using namespace std;
+
+class ServArg
+ {
+ public:
+ int _servType;
+ int _firstArg;
+ int _lastArg;
+ inline ServArg(int servType=0, int firstArg=0, int lastArg=0);
+};
+
+inline ServArg::ServArg(int servType, int firstArg, int lastArg):
+ _servType(servType),_firstArg(firstArg),_lastArg(lastArg)
+{}
+
+class Session_ServerLauncher
+{
+public:
+ Session_ServerLauncher();
+ Session_ServerLauncher(int argc,
+ char ** argv,
+ CORBA::ORB_ptr orb,
+ PortableServer::POA_ptr poa,
+ QMutex *GUIMutex);
+ virtual ~Session_ServerLauncher();;
+ void Init();
+protected:
+
+ void CheckArgs();
+
+ void ActivateAll();
+
+private:
+
+ int _argc;
+ char ** _argv;
+ CORBA::ORB_var _orb;
+ PortableServer::POA_var _root_poa;
+ QMutex* _GUIMutex;
+ QWaitCondition _ServerLaunch;
+ list<ServArg> _argServToLaunch;
+ vector<string> _argCopy;
+ list<Session_ServerThread*> _serverThreads;
+};
+
+#endif
+
--- /dev/null
+// SALOME Session : implementation of Session_ServerThread.cxx
+//
+// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
+//
+//
+//
+// File : Session_ServerThread.cxx
+// Author : Paul RASCLE, EDF
+// Module : SALOME
+// $Header$
+
+// #include <SALOMEconfig.h>
+// #include CORBA_SERVER_HEADER(SALOME_Session)
+// #include CORBA_SERVER_HEADER(SALOMEDS)
+
+#include "Session_ServerThread.hxx"
+
+#include "SALOME_Container_i.hxx"
+#include "SALOMEDS_StudyManager_i.hxx"
+#include "SALOME_ModuleCatalog_impl.hxx"
+#include "RegistryService.hxx"
+#include "SALOME_Session_i.hxx"
+
+#include "Utils_ORB_INIT.hxx"
+#include "Utils_SINGLETON.hxx"
+#include "Utils_SALOME_Exception.hxx"
+#include "OpUtil.hxx"
+#include "utilities.h"
+
+#include <cstdlib>
+#include <ctime>
+
+using namespace std;
+
+const int Session_ServerThread::NB_SRV_TYP = 5;
+const char* Session_ServerThread::_serverTypes[NB_SRV_TYP] = {"Container",
+ "ModuleCatalog",
+ "Registry",
+ "SALOMEDS",
+ "Session"};
+
+//=============================================================================
+/*!
+ * Wait until the given server is ready i.e. is name is found in namingService.
+ * Try 40 times, with 250 ms sleep between each try.
+ * If Logger is used for traces, it must be ready before this call, because
+ * SALOME_NamingService client uses SALOME traces. So, Logger readiness must be
+ * checked in Launch script before execution of WaitForServerReadiness.
+ */
+//=============================================================================
+
+void WaitForServerReadiness(SALOME_NamingService* NS, string serverName)
+{
+ long TIMESleep = 250000000; // 250 ms.
+ int NumberOfTries = 40; // total wait = 10 s.
+ int found = 0;
+
+ timespec ts_req;
+ ts_req.tv_nsec=TIMESleep;
+ ts_req.tv_sec=0;
+ timespec ts_rem;
+ ts_rem.tv_nsec=0;
+ ts_rem.tv_sec=0;
+
+ for (int itry=0; itry < NumberOfTries; itry++)
+ {
+ try
+ {
+ if (serverName.length() == 0)
+ {
+ string curdir = NS->Current_Directory(); // to wait for naming service
+ found = 1;
+ break; // naming service found
+ }
+ else
+ {
+ CORBA::Object_ptr obj = NS->Resolve(serverName.c_str());
+ if (! CORBA::is_nil(obj))
+ {
+ found =1;
+ break; // server found, no more try to do
+ }
+ MESSAGE("Server "<< serverName <<" not yet ready, waiting...");
+ int a = nanosleep(&ts_req,&ts_rem); // wait before retry
+ }
+ }
+ catch( ServiceUnreachable& )
+ {
+ MESSAGE("CORBA::COMM_FAILURE: Naming Service not yet ready, waiting...");
+ int a = nanosleep(&ts_req,&ts_rem); // wait before retry
+ }
+ }
+ if (!found)
+ {
+ INFOS("Server "<< serverName <<" not found, abort...");
+ exit(EXIT_FAILURE);
+ }
+}
+
+//=============================================================================
+/*!
+ * default constructor not for use
+ */
+//=============================================================================
+
+Session_ServerThread::Session_ServerThread()
+{
+ ASSERT(0); // must not be called
+}
+
+//=============================================================================
+/*!
+ * constructor
+ */
+//=============================================================================
+
+Session_ServerThread::Session_ServerThread(int argc,
+ char ** argv,
+ CORBA::ORB_ptr orb,
+ PortableServer::POA_ptr poa,
+ QMutex *GUIMutex,
+ QWaitCondition *ServerLaunch)
+{
+ MESSAGE("Session_ServerThread Constructor " << argv[0]);
+ _argc = argc;
+ _argv = argv;
+ _orb = CORBA::ORB::_duplicate(orb);
+ _root_poa = PortableServer::POA::_duplicate(poa);
+ _GUIMutex = GUIMutex;
+ _ServerLaunch = ServerLaunch;
+ _servType =-1;
+ _NS = new SALOME_NamingService(_orb); // one instance per server to limit
+ // multi thread coherence problems
+}
+
+//=============================================================================
+/*!
+ * destructor
+ */
+//=============================================================================
+
+Session_ServerThread::~Session_ServerThread()
+{
+ MESSAGE("~Session_ServerThread "<< _argv[0]);
+}
+
+//=============================================================================
+/*!
+ * run the thread : activate one servant, the servant type is given by
+ * argument _argv[0]
+ */
+//=============================================================================
+
+void Session_ServerThread::run()
+{
+ MESSAGE("Session_ServerThread::run "<< _argv[0]);
+
+// _GUIMutex->lock(); // lock released by calling thread when ready: wait(mutex)
+// MESSAGE("Server thread " << _argv[0] << " free to go...");
+// _GUIMutex->unlock();
+
+ for (int i=0; i<_argc; i++) SCRUTE(_argv[i]);
+ for (int i=0; i<NB_SRV_TYP; i++)
+ if (strcmp(_argv[0],_serverTypes[i])==0)
+ {
+ _servType = i;
+ MESSAGE("Server Thread type : "<<_serverTypes[i]);
+ switch (_servType)
+ {
+ case 0: // Container
+ {
+ WaitForServerReadiness(_NS,"/Registry");
+ ActivateContainer(_argc, _argv);
+ break;
+ }
+ case 1: // ModuleCatalog
+ {
+ WaitForServerReadiness(_NS,"/Registry");
+ ActivateModuleCatalog(_argc, _argv);
+ break;
+ }
+ case 2: // Registry
+ {
+ WaitForServerReadiness(_NS,"");
+ ActivateRegistry(_argc, _argv);
+ break;
+ }
+ case 3: // SALOMEDS
+ {
+ WaitForServerReadiness(_NS,"/Kernel/ModulCatalog");
+ ActivateSALOMEDS(_argc, _argv);
+ break;
+ }
+ case 4: // Session
+ {
+ WaitForServerReadiness(_NS,"/myStudyManager");
+ string containerName = "/Containers/";
+ containerName = containerName + GetHostname();
+ containerName = containerName + "/FactoryServer";
+ WaitForServerReadiness(_NS,containerName);
+ ActivateSession(_argc, _argv);
+ break;
+ }
+ default:
+ {
+ ASSERT(0);
+ break;
+ }
+ }
+ }
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+
+void Session_ServerThread::ActivateModuleCatalog(int argc,
+ char ** argv)
+{
+ try
+ {
+ INFOS("ModuleCatalog thread started");
+ // allocation on heap to allow destruction by POA
+
+ SALOME_ModuleCatalogImpl* Catalogue_i
+ = new SALOME_ModuleCatalogImpl(argc, argv);
+ MESSAGE("---");
+ // Tell the POA that the objects are ready to accept requests.
+
+ _root_poa->activate_object (Catalogue_i);
+ MESSAGE("---");
+
+ CORBA::Object_ptr myCata = Catalogue_i->_this();
+ MESSAGE("---");
+ _NS->Register(myCata ,"/Kernel/ModulCatalog");
+ MESSAGE("---");
+ _ServerLaunch->wakeAll();
+ _orb->run(); // this thread wait, during process events
+ }
+ catch(CORBA::SystemException&)
+ {
+ INFOS( "Caught CORBA::SystemException." );
+ }
+ catch(CORBA::Exception&)
+ {
+ INFOS( "Caught CORBA::Exception." );
+ }
+ catch(omniORB::fatalException& fe)
+ {
+ INFOS( "Caught omniORB::fatalException:" );
+ INFOS( " file: " << fe.file() );
+ INFOS( " line: " << fe.line() );
+ INFOS( " mesg: " << fe.errmsg() );
+ }
+ catch(...)
+ {
+ INFOS( "Caught unknown exception." );
+ }
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+
+void Session_ServerThread::ActivateSALOMEDS(int argc,
+ char ** argv)
+{
+ try
+ {
+ INFOS("SALOMEDS thread started");
+ // We allocate the objects on the heap. Since these are reference
+ // counted objects, they will be deleted by the POA when they are no
+ // longer needed.
+
+ SALOMEDS_StudyManager_i * myStudyManager_i
+ = new SALOMEDS_StudyManager_i(_orb);
+
+ // Activate the objects. This tells the POA that the objects are
+ // ready to accept requests.
+
+ PortableServer::ObjectId_var myStudyManager_iid
+ = _root_poa->activate_object(myStudyManager_i);
+
+ myStudyManager_i->register_name("/myStudyManager");
+
+ _ServerLaunch->wakeAll();
+ _orb->run(); // this thread wait, during process events
+ }
+ catch(CORBA::SystemException&)
+ {
+ INFOS( "Caught CORBA::SystemException." );
+ }
+ catch(CORBA::Exception&)
+ {
+ INFOS( "Caught CORBA::Exception." );
+ }
+ catch(omniORB::fatalException& fe)
+ {
+ INFOS( "Caught omniORB::fatalException:" );
+ INFOS( " file: " << fe.file() );
+ INFOS( " line: " << fe.line() );
+ INFOS( " mesg: " << fe.errmsg() );
+ }
+ catch(...)
+ {
+ INFOS( "Caught unknown exception." );
+ }
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+
+void Session_ServerThread::ActivateRegistry(int argc,
+ char ** argv)
+{
+ INFOS("Registry thread started");
+ SCRUTE(argc);
+ if( argc<3 )
+ {
+ INFOS("you must provide the Salome session name when you call SALOME_Registry_Server");
+ throw CommException("you must provide the Salome session name when you call SALOME_Registry_Server");
+ }
+ const char *ptrSessionName=0;
+
+ int k=0 ;
+ for ( k=1 ; k<argc ; k++ )
+ {
+ if( strcmp(argv[k],"--salome_session")==0 )
+ {
+ ptrSessionName=argv[k+1];
+ break;
+ }
+ }
+ ASSERT(ptrSessionName) ;
+ ASSERT(strlen( ptrSessionName )>0);
+ const char *registryName = "Registry";
+ Registry::Components_var varComponents;
+ try
+ {
+ RegistryService *ptrRegistry = SINGLETON_<RegistryService>::Instance();
+ ptrRegistry->SessionName( ptrSessionName );
+ varComponents = ptrRegistry->_this();
+ // The RegistryService must not already exist.
+
+ try
+ {
+ CORBA::Object_var pipo = _NS->Resolve( registryName );
+ if (CORBA::is_nil(pipo) ) throw ServiceUnreachable();
+ INFOS("RegistryService servant already existing" );
+ ASSERT(0);
+ }
+ catch( const ServiceUnreachable &ex )
+ {
+ }
+ catch( const CORBA::Exception &exx )
+ {
+ }
+ string absoluteName = string("/") + registryName;
+ _NS->Register( varComponents , absoluteName.c_str() );
+ MESSAGE("On attend les requetes des clients");
+ try
+ {
+ _ServerLaunch->wakeAll();
+ _orb->run();
+ }
+ catch( const CORBA::Exception &ex )
+ {
+ INFOS("Erreur systeme");
+ ASSERT(0);
+ }
+ }
+ catch( const SALOME_Exception &ex )
+ {
+ INFOS( "Communication Error : " << ex.what() );
+ ASSERT(0);
+ }
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+
+void Session_ServerThread::ActivateContainer(int argc,
+ char ** argv)
+{
+ try
+ {
+ INFOS("Container thread started");
+
+ // get or create the child POA
+
+ PortableServer::POA_var factory_poa;
+ try
+ {
+ factory_poa = _root_poa->find_POA("factory_poa",0);
+ // 0 = no activation (already done if exists)
+ }
+ catch (PortableServer::POA::AdapterNonExistent&)
+ {
+ INFOS("factory_poa does not exists, create...");
+ // define policy objects
+ PortableServer::ImplicitActivationPolicy_var implicitActivation =
+ _root_poa->create_implicit_activation_policy(
+ PortableServer::NO_IMPLICIT_ACTIVATION);
+ MESSAGE("---");
+ // 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
+ MESSAGE("---");
+
+ // create policy list
+ CORBA::PolicyList policyList;
+ policyList.length(2);
+ policyList[0] = PortableServer::ImplicitActivationPolicy::
+ _duplicate(implicitActivation);
+ policyList[1] = PortableServer::ThreadPolicy::
+ _duplicate(threadPolicy);
+ MESSAGE("---");
+
+ PortableServer::POAManager_var nil_mgr
+ = PortableServer::POAManager::_nil();
+ 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
+ MESSAGE("---");
+
+ // destroy policy objects
+ implicitActivation->destroy();
+ threadPolicy->destroy();
+ MESSAGE("---");
+
+ // obtain the factory poa manager
+ PortableServer::POAManager_var pmanfac = factory_poa->the_POAManager();
+ pmanfac->activate();
+ MESSAGE("pmanfac->activate()");
+ }
+
+ MESSAGE("---");
+ char *containerName = "";
+ if (argc >1)
+ {
+ containerName = argv[1];
+ }
+
+ Engines_Container_i * myContainer
+ = new Engines_Container_i(_orb, factory_poa, containerName , argc , argv );
+ MESSAGE("---");
+ _ServerLaunch->wakeAll();
+ _orb->run(); // this thread wait, during process events
+ }
+ catch(CORBA::SystemException&)
+ {
+ INFOS("Caught CORBA::SystemException.");
+ }
+ catch(PortableServer::POA::WrongPolicy&)
+ {
+ INFOS("Caught CORBA::WrongPolicyException.");
+ }
+ catch(PortableServer::POA::ServantAlreadyActive&)
+ {
+ INFOS("Caught CORBA::ServantAlreadyActiveException");
+ }
+ catch(CORBA::Exception&)
+ {
+ INFOS("Caught CORBA::Exception.");
+ }
+ catch(...)
+ {
+ INFOS("Caught unknown exception.");
+ }
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+
+void Session_ServerThread::ActivateSession(int argc,
+ char ** argv)
+{
+ try
+ {
+ INFOS("Session thread started");
+ SALOME_Session_i * mySALOME_Session
+ = new SALOME_Session_i(argc, argv, _orb, _root_poa, _GUIMutex) ;
+ PortableServer::ObjectId_var mySALOME_Sessionid
+ = _root_poa->activate_object(mySALOME_Session);
+ INFOS("poa->activate_object(mySALOME_Session)");
+
+ CORBA::Object_var obj = mySALOME_Session->_this();
+ CORBA::String_var sior(_orb->object_to_string(obj));
+
+ mySALOME_Session->NSregister();
+
+ mySALOME_Session->_remove_ref();
+
+ _ServerLaunch->wakeAll();
+ MESSAGE("---");
+ _orb->run() ; // this thread wait, during process events
+ }
+ catch (CORBA::SystemException&)
+ {
+ INFOS("Caught CORBA::SystemException.");
+ }
+ catch (CORBA::Exception&)
+ {
+ INFOS("Caught CORBA::Exception.");
+ }
+ catch (...)
+ {
+ INFOS("Caught unknown exception.");
+ }
+}
--- /dev/null
+// SALOME Session : implementation of Session_ServerThread.hxx
+//
+// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
+//
+//
+//
+// File : Session_ServerThread.hxx
+// Author : Paul RASCLE, EDF
+// Module : SALOME
+// $Header$
+
+#ifndef _SESSION_SERVERTHREAD_HXX_
+#define _SESSION_SERVERTHREAD_HXX_
+
+#include <qthread.h>
+#include <CORBA.h>
+
+#include "SALOME_NamingService.hxx"
+
+#include <qwaitcondition.h>
+#include <string>
+
+using namespace std;
+
+void WaitForServerReadiness(string serverName);
+
+
+class Session_ServerThread: public QThread
+{
+public:
+ static const int NB_SRV_TYP;
+ static const char* _serverTypes[];
+
+ Session_ServerThread();
+ Session_ServerThread(int argc,
+ char ** argv,
+ CORBA::ORB_ptr orb,
+ PortableServer::POA_ptr poa,
+ QMutex *GUIMutex,
+ QWaitCondition *ServerLaunch);
+ virtual ~Session_ServerThread();
+ void run();
+protected:
+ void ActivateModuleCatalog(int argc,
+ char ** argv);
+ void ActivateSALOMEDS(int argc,
+ char ** argv);
+ void ActivateRegistry(int argc,
+ char ** argv);
+ void ActivateContainer(int argc,
+ char ** argv);
+ void ActivateSession(int argc,
+ char ** argv);
+
+private:
+ int _argc;
+ char ** _argv;
+ int _servType;
+ CORBA::ORB_var _orb;
+ PortableServer::POA_var _root_poa;
+ QMutex* _GUIMutex;
+ QWaitCondition *_ServerLaunch;
+ SALOME_NamingService *_NS;
+};
+
+#endif
+