]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
WIP
authorAnthony Geay <anthony.geay@edf.fr>
Thu, 18 Feb 2021 13:26:31 +0000 (14:26 +0100)
committerAnthony Geay <anthony.geay@edf.fr>
Thu, 18 Feb 2021 13:26:31 +0000 (14:26 +0100)
src/Session/SALOME_Session_Server.cxx
src/Session/Session_ServerLauncher.cxx
src/Session/Session_ServerLauncher.hxx
src/Session/Session_ServerThread.cxx
src/Session/Session_ServerThread.hxx

index 67fa2103bf59c2a4406432788326a99516e05b7c..b73e8f180475ff11a30e2825084606b8e45e0ac2 100644 (file)
@@ -549,7 +549,7 @@ int AbstractGUIApp::main(int argc, char **argv)
 
   SUIT_Session *aGUISession = 0;
   GetInterfaceThread *guiThread = 0;
-  Session_ServerLauncher *myServerLauncher = 0;
+  Session_ServerLauncher<SALOME_NamingService> *myServerLauncher = nullptr;
 
 #if defined(WIN32) && defined(UNICODE)
   char **new_argv = NULL;
@@ -627,9 +627,9 @@ int AbstractGUIApp::main(int argc, char **argv)
     }
     // Free memory allocated for CommandLineToArgvW arguments.
     LocalFree(szArglist);
-    myServerLauncher = new Session_ServerLauncher(nArgs, new_argv, orb, poa, &_GUIMutex, &_ServerLaunch, &_SessionMutex, &_SessionStarted);
+    myServerLauncher = new Session_ServerLauncher<SALOME_NamingService>(nArgs, new_argv, orb, poa, &_GUIMutex, &_ServerLaunch, &_SessionMutex, &_SessionStarted);
 #else
-    myServerLauncher = new Session_ServerLauncher(argc, argv, orb, poa, &_GUIMutex, &_ServerLaunch, &_SessionMutex, &_SessionStarted);
+    myServerLauncher = new Session_ServerLauncher<SALOME_NamingService>(argc, argv, orb, poa, &_GUIMutex, &_ServerLaunch, &_SessionMutex, &_SessionStarted);
 #endif
     // ...block this thread until launcher is ready
     _ServerLaunch.wait(&_GUIMutex);
index 6471c26bcd08121b6300f8f0e90d256f41849bcc..f85a1b2c0736686cafe7b1cec73bf5cf636a7bdd 100644 (file)
@@ -36,7 +36,8 @@
 /*! 
    default constructor not for use
  */
-Session_ServerLauncher::Session_ServerLauncher()
+template<class MY_NS>
+Session_ServerLauncher<MY_NS>::Session_ServerLauncher()
 {
   ASSERT(0); // must not be called
 }
@@ -44,14 +45,15 @@ Session_ServerLauncher::Session_ServerLauncher()
 /*! 
   constructor
 */
-Session_ServerLauncher::Session_ServerLauncher(int argc,
-                                               char ** argv, 
-                                               CORBA::ORB_ptr orb, 
-                                               PortableServer::POA_ptr poa,
-                                               QMutex *GUIMutex,
-                                               QWaitCondition *ServerLaunch,
-                                               QMutex *SessionMutex,
-                                               QWaitCondition *SessionStarted)
+template<class MY_NS>
+Session_ServerLauncher<MY_NS>::Session_ServerLauncher(int argc,
+                                                      char ** argv, 
+                                                      CORBA::ORB_ptr orb, 
+                                                      PortableServer::POA_ptr poa,
+                                                      QMutex *GUIMutex,
+                                                      QWaitCondition *ServerLaunch,
+                                                      QMutex *SessionMutex,
+                                                      QWaitCondition *SessionStarted)
 {
   _argc = argc;
   _argv = argv;
@@ -69,14 +71,16 @@ Session_ServerLauncher::Session_ServerLauncher(int argc,
 /*! 
   destructor
 */
-Session_ServerLauncher::~Session_ServerLauncher()
+template<class MY_NS>
+Session_ServerLauncher<MY_NS>::~Session_ServerLauncher()
 {
 }
 
 /*! 
   Check args and activate servers
 */
-void Session_ServerLauncher::run()
+template<class MY_NS>
+void Session_ServerLauncher<MY_NS>::run()
 {
   // wait until main thread is ready
   _GUIMutex->lock();          // ... lock mutex (it is unlocked my calling thread 
@@ -104,7 +108,8 @@ void Session_ServerLauncher::run()
 /*! 
   controls and dispatchs arguments given with command
 */
-void Session_ServerLauncher::CheckArgs()
+template<class MY_NS>
+void Session_ServerLauncher<MY_NS>::CheckArgs()
 {
   int argState = 0;
   ServArg aServArg(0,0,0);
@@ -135,8 +140,8 @@ void Session_ServerLauncher::CheckArgs()
             }
             // Temporary solution
 
-            for (int i=0; i<Session_ServerThread::NB_SRV_TYP; i++)
-                if (strcmp(_argv[iarg],Session_ServerThread::_serverTypes[i])==0)
+            for (int i=0; i<Session_ServerThread<MY_NS>::NB_SRV_TYP; i++)
+                if (strcmp(_argv[iarg],Session_ServerThread<MY_NS>::_serverTypes[i])==0)
                   {
                     aServArg._servType = i;
                     argState = 2;
@@ -166,7 +171,7 @@ void Session_ServerLauncher::CheckArgs()
             if (strcmp(_argv[iarg],")")==0)   // end of arguments = ')'
               {
                 aServArg._lastArg=iarg-1;     // arg before ')'
-                MESSAGE("server : "<< Session_ServerThread::_serverTypes[aServArg._servType]);
+                MESSAGE("server : "<< Session_ServerThread<MY_NS>::_serverTypes[aServArg._servType]);
                 for (int i=aServArg._firstArg; i<=aServArg._lastArg; i++)
                   MESSAGE("  arg : " << _argCopy[i]);
                 _argServToLaunch.push_back(aServArg);
@@ -189,7 +194,8 @@ void Session_ServerLauncher::CheckArgs()
     throw SALOME_Exception(LOCALIZED("Error in command arguments, missing parenthesis ')'"));
 }
 
-void Session_ServerLauncher::ActivateAll()
+template<class MY_NS>
+void Session_ServerLauncher<MY_NS>::ActivateAll()
 {
   std::list<ServArg>::iterator itServ;
   for (itServ = _argServToLaunch.begin(); itServ !=_argServToLaunch.end(); itServ++)
@@ -198,7 +204,7 @@ void Session_ServerLauncher::ActivateAll()
     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]);
+    argv[0]=strdup(Session_ServerThread<MY_NS>::_serverTypes[servType]);
     if (argc>1)
     {
       for (int i=0; i<argc-1; i++)
@@ -208,8 +214,7 @@ void Session_ServerLauncher::ActivateAll()
 
     MESSAGE("*** activating [" << argc << "] : " << argv[0]);
 
-    Session_ServerThread* aServerThread
-      = new Session_ServerThread(argc, argv, _orb,_root_poa);
+    Session_ServerThread<MY_NS>* aServerThread = new Session_ServerThread<MY_NS>(argc, argv, _orb,_root_poa);
     _serverThreads.push_front(aServerThread);
     
     aServerThread->Init();
@@ -223,17 +228,19 @@ void Session_ServerLauncher::ActivateAll()
   int argc=1;
   char** argv = new char*[argc];
   argv[0] = (char*)"Session";
-  Session_SessionThread* aServerThread
-    = new Session_SessionThread(argc, argv, _orb,_root_poa,_SessionMutex,_SessionStarted);
+  Session_SessionThread<MY_NS>* aServerThread
+    = new Session_SessionThread<MY_NS>(argc, argv, _orb,_root_poa,_SessionMutex,_SessionStarted);
   _serverThreads.push_front(aServerThread);
   aServerThread->Init();
   delete[] argv;
 }
 
-void Session_ServerLauncher::ShutdownAll()
+template <class MY_NS>
+void Session_ServerLauncher<MY_NS>::ShutdownAll()
 {
   MESSAGE("Session_ServerLauncher::ShutdownAll()");
-  std::list<Session_ServerThread*>::reverse_iterator itServ;
+  using Session_ServerThreadT = Session_ServerThread<MY_NS>;
+  typename std::list<Session_ServerThreadT*>::reverse_iterator itServ;
   for (itServ = _serverThreads.rbegin(); itServ !=_serverThreads.rend(); itServ++)
   {
     (*itServ)->Shutdown();
@@ -243,10 +250,12 @@ void Session_ServerLauncher::ShutdownAll()
 /*! 
   Destruction des classes serveur dans l'ordre inverse de creation
 */
-void Session_ServerLauncher::KillAll()
+template <class MY_NS>
+void Session_ServerLauncher<MY_NS>::KillAll()
 {
   MESSAGE("Session_ServerLauncher::KillAll()");
-  std::list<Session_ServerThread*>::reverse_iterator itServ;
+  using Session_ServerThreadT = Session_ServerThread<MY_NS>;
+  typename std::list<Session_ServerThreadT*>::reverse_iterator itServ;
   for (itServ = _serverThreads.rbegin(); itServ !=_serverThreads.rend(); itServ++)
   {
     delete (*itServ);
index 33e8187a68907ae7592fc651965889dcf914f023..719157e4002e85ff9b35f24c2bbe2372bf22a0c7 100644 (file)
@@ -48,12 +48,14 @@ inline ServArg::ServArg(int servType, int firstArg, int lastArg):
   _servType(servType),_firstArg(firstArg),_lastArg(lastArg)
 {}
 
+template <class MY_NS>
 class Session_ServerThread;
 
 class QMutex;
 class QWaitCondition;
 
-class SESSION_EXPORT Session_ServerLauncher: public QThread
+template<class MY_NS>
+class SESSION_EXPORT Session_ServerLauncher : public QThread
 {
 public:
   Session_ServerLauncher();
@@ -85,7 +87,7 @@ private:
   QWaitCondition*                  _SessionStarted;
   std::list<ServArg>               _argServToLaunch;
   std::vector<std::string>         _argCopy;
-  std::list<Session_ServerThread*> _serverThreads;
+  std::list< Session_ServerThread<MY_NS>* > _serverThreads;
 };
 
 #endif
index d9f28bd011d38792a1a5d5db7711a33df5ff4277..8cc0a339f29f8688e605e59ba04585ff2b843230 100644 (file)
 #include <QMutex>
 #include <QWaitCondition>
 
-const int Session_ServerThread::NB_SRV_TYP = 6;
-const char* Session_ServerThread::_serverTypes[NB_SRV_TYP] = {"Container",
-                                                              "ModuleCatalog",
-                                                              "Registry",
-                                                              "SALOMEDS",
-                                                              "Session",
-                                                              "ContainerManager"};
+template<class MY_NS>
+const int Session_ServerThread<MY_NS>::NB_SRV_TYP = 6;
+
+template<class MY_NS>
+const char* Session_ServerThread<MY_NS>::_serverTypes[NB_SRV_TYP] = {"Container",
+                                                                      "ModuleCatalog",
+                                                                      "Registry",
+                                                                      "SALOMEDS",
+                                                                      "Session",
+                                                                      "ContainerManager"};
 
 /*! 
   default constructor not for use
 */
-Session_ServerThread::Session_ServerThread()
+template<class MY_NS>
+Session_ServerThread<MY_NS>::Session_ServerThread()
 {
   ASSERT(0); // must not be called
 }
@@ -68,7 +72,8 @@ Session_ServerThread::Session_ServerThread()
 /*! 
   constructor
 */
-Session_ServerThread::Session_ServerThread(int argc,
+template<class MY_NS>
+Session_ServerThread<MY_NS>::Session_ServerThread(int argc,
                                            char ** argv, 
                                            CORBA::ORB_ptr orb, 
                                            PortableServer::POA_ptr poa)
@@ -91,7 +96,8 @@ Session_ServerThread::Session_ServerThread(int argc,
 /*! 
   destructor 
 */
-Session_ServerThread::~Session_ServerThread()
+template<class MY_NS>
+Session_ServerThread<MY_NS>::~Session_ServerThread()
 {
   for (int i = 0; i <_argc ; i++ )
     free( _argv[i] );
@@ -102,7 +108,8 @@ Session_ServerThread::~Session_ServerThread()
   run the thread : activate one servant, the servant type is given by
   argument _argv[0]
 */
-void Session_ServerThread::Init()
+template<class MY_NS>
+void Session_ServerThread<MY_NS>::Init()
 {
   MESSAGE("Session_ServerThread::Init "<< _argv[0]); 
 
@@ -165,12 +172,14 @@ void Session_ServerThread::Init()
   }
 }
 
-void Session_ServerThread::Shutdown()
+template<class MY_NS>
+void Session_ServerThread<MY_NS>::Shutdown()
 {
   if ( _container ) _container->Shutdown();
 }
 
-void Session_ServerThread::ActivateModuleCatalog(int argc,
+template<class MY_NS>
+void Session_ServerThread<MY_NS>::ActivateModuleCatalog(int argc,
                                                  char ** argv)
 {
   try {
@@ -205,7 +214,8 @@ void Session_ServerThread::ActivateModuleCatalog(int argc,
   }
 }
 
-void Session_ServerThread::ActivateSALOMEDS(int /*argc*/, char** /*argv*/)
+template<class MY_NS>
+void Session_ServerThread<MY_NS>::ActivateSALOMEDS(int /*argc*/, char** /*argv*/)
 {
   try {
     MESSAGE("SALOMEDS thread started");
@@ -232,7 +242,8 @@ void Session_ServerThread::ActivateSALOMEDS(int /*argc*/, char** /*argv*/)
   }
 }
 
-void Session_ServerThread::ActivateRegistry(int argc, char ** argv)
+template<class MY_NS>
+void Session_ServerThread<MY_NS>::ActivateRegistry(int argc, char ** argv)
 {
   MESSAGE("Registry thread started");
   SCRUTE(argc); 
@@ -290,7 +301,8 @@ void Session_ServerThread::ActivateRegistry(int argc, char ** argv)
   }
 }
 
-void Session_ServerThread::ActivateContainerManager(int /*argc*/, char** /*argv*/)
+template<class MY_NS>
+void Session_ServerThread<MY_NS>::ActivateContainerManager(int /*argc*/, char** /*argv*/)
 {
   try {
     PortableServer::POA_var root_poa=PortableServer::POA::_the_root_poa();
@@ -314,7 +326,8 @@ void Session_ServerThread::ActivateContainerManager(int /*argc*/, char** /*argv*
   }
 }
 
-void Session_ServerThread::ActivateContainer(int argc, char** argv)
+template<class MY_NS>
+void Session_ServerThread<MY_NS>::ActivateContainer(int argc, char** argv)
 {
   try {
     MESSAGE("Container thread started");
@@ -386,47 +399,45 @@ void Session_ServerThread::ActivateContainer(int argc, char** argv)
   }
 }
 
-void Session_ServerThread::ActivateSession(int /*argc*/, char** /*argv*/)
+template<class MY_NS>
+void Session_ServerThread<MY_NS>::ActivateSession(int /*argc*/, char** /*argv*/)
 {
   MESSAGE("Session_ServerThread::ActivateSession() not implemented!");
 }
 
-/*! 
-  constructor 
-*/
-Session_SessionThread::Session_SessionThread(int argc,
+template<class MY_NS>
+Session_SessionThread<MY_NS>::Session_SessionThread(int argc,
                                              char** argv, 
                                              CORBA::ORB_ptr orb, 
                                              PortableServer::POA_ptr poa,
                                              QMutex* GUIMutex,
                                              QWaitCondition* GUILauncher)
-: Session_ServerThread(argc, argv, orb, poa),
+: Session_ServerThread<MY_NS>(argc, argv, orb, poa),
   _GUIMutex( GUIMutex ),
   _GUILauncher( GUILauncher )
 {
 }
 
-/*! 
-  destructor 
-*/
-Session_SessionThread::~Session_SessionThread()
+template<class MY_NS>
+Session_SessionThread<MY_NS>::~Session_SessionThread()
 {
 }
 
-void Session_SessionThread::ActivateSession(int argc, char ** argv)
+template<class MY_NS>
+void Session_SessionThread<MY_NS>::ActivateSession(int argc, char ** argv)
 {
   try {
     MESSAGE("Session thread started");
     SALOME_Session_i * mySALOME_Session
-      = new SALOME_Session_i(argc, argv, _orb, _root_poa, _GUIMutex, _GUILauncher) ;
+      = new SALOME_Session_i(argc, argv, this->_orb, this->_root_poa, _GUIMutex, _GUILauncher) ;
     PortableServer::ObjectId_var mySALOME_Sessionid
-      = _root_poa->activate_object(mySALOME_Session);
+      = this->_root_poa->activate_object(mySALOME_Session);
     MESSAGE("poa->activate_object(mySALOME_Session)");
     
     CORBA::Object_var obj = mySALOME_Session->_this();
     SALOME::Session_var objC = SALOME::Session::_narrow(obj);
     GetSessionRefSingleton()->set_value(objC);
-    CORBA::String_var sior(_orb->object_to_string(obj));
+    CORBA::String_var sior(this->_orb->object_to_string(obj));
     mySALOME_Session->_remove_ref();
     
     mySALOME_Session->NSregister();
index 03296bf826a8c795c0e984b8011795dca65184ee..1df729038ba6e5cd2931cb4e6e56cb84fc9c5079 100644 (file)
@@ -38,6 +38,7 @@ void WaitForServerReadiness(std::string serverName);
 class SALOME_NamingService;
 class Engines_Container_i;
 
+template<class MY_NS>
 class SESSION_EXPORT Session_ServerThread
 {
 public:
@@ -66,14 +67,15 @@ protected:
   int                     _servType;
   CORBA::ORB_var          _orb;
   PortableServer::POA_var _root_poa;
-  std::unique_ptr<SALOME_NamingService> _NS;
+  std::unique_ptr<MY_NS> _NS;
   Engines_Container_i*    _container;
 };
 
 class QMutex;
 class QWaitCondition;
 
-class SESSION_EXPORT Session_SessionThread : public Session_ServerThread
+template<class MY_NS>
+class SESSION_EXPORT Session_SessionThread : public Session_ServerThread<MY_NS>
 {
 public:
   Session_SessionThread() {}
@@ -93,4 +95,3 @@ private:
 };
 
 #endif
-