]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
PR: colocalisation prototype 3
authorprascle <prascle>
Tue, 6 Apr 2004 14:05:34 +0000 (14:05 +0000)
committerprascle <prascle>
Tue, 6 Apr 2004 14:05:34 +0000 (14:05 +0000)
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 d72a954d548a6e81c4a83b4415523d6b90ae398e..a2397fc6b5e970835fa0ce5f1801034de80dc85d 100644 (file)
@@ -104,14 +104,21 @@ int main(int argc, char **argv)
       // CORBA Servant Launcher
 
       QMutex _GUIMutex ;
+      QWaitCondition _ServerLaunch;
+      _GUIMutex.lock();     // to block Launch server thread until wait(mutex)
 
       Session_ServerLauncher* myServerLauncher
-       = new Session_ServerLauncher(argc, argv, orb, poa, &_GUIMutex);
-      myServerLauncher->Init();
+       = new Session_ServerLauncher(argc, argv, orb, poa, &_GUIMutex, &_ServerLaunch);
+      myServerLauncher->start();
+
+      MESSAGE("waiting wakeAll()");
+      _ServerLaunch.wait(&_GUIMutex); // to be reseased by Launch server thread when ready:
+      // atomic operation lock - unlock on mutex
+      // unlock mutex: serverThread runs, calls  _ServerLaunch->wakeAll()
+      // this thread wakes up, and lock mutex
 
       INFOS("Session activated, Launch IAPP...");
 
-      _GUIMutex.lock();
       int qappArgc = 1;
       QApplication *_qappl = new QApplication(qappArgc, argv );
       INFOS("creation QApplication");
index 54d852aa65f492b39617142e4e4cc4a43e63ec2b..54cf11cba2f76ec5f17ba2b140c9cc71a8a67096 100644 (file)
@@ -52,13 +52,15 @@ Session_ServerLauncher::Session_ServerLauncher(int argc,
                                               char ** argv, 
                                               CORBA::ORB_ptr orb, 
                                               PortableServer::POA_ptr poa,
-                                              QMutex *GUIMutex)
+                                              QMutex *GUIMutex,
+                                              QWaitCondition *ServerLaunch)
 {
   _argc = argc;
   _argv = argv;
   _orb = CORBA::ORB::_duplicate(orb);
   _root_poa = PortableServer::POA::_duplicate(poa);
   _GUIMutex = GUIMutex;
+  _ServerLaunch = ServerLaunch;
 }
 
 //=============================================================================
@@ -77,10 +79,18 @@ Session_ServerLauncher::~Session_ServerLauncher()
  */
 //=============================================================================
 
-void Session_ServerLauncher::Init()
+void Session_ServerLauncher::run()
 {
+  MESSAGE("Session_ServerLauncher::run");
+  _GUIMutex->lock(); // lock released by calling thread when ready: wait(mutex)
+   MESSAGE("Server Launcher thread free to go...");
+   _GUIMutex->unlock();
+
   CheckArgs();
   ActivateAll();
+
+  _ServerLaunch->wakeAll();
+  _orb->run();       // this thread wait, during omniORB process events
 }
 
 //=============================================================================
@@ -171,8 +181,6 @@ void Session_ServerLauncher::CheckArgs()
 
 void Session_ServerLauncher::ActivateAll()
 {
-  _GUIMutex->lock();             // to block server threads until wait(mutex)
-
   list<ServArg>::iterator itServ;
   for (itServ = _argServToLaunch.begin(); itServ !=_argServToLaunch.end(); itServ++)
     {
@@ -188,15 +196,10 @@ void Session_ServerLauncher::ActivateAll()
            argv[i+1] = _argv[(*itServ)._firstArg + i];
        }
       Session_ServerThread* aServerThread
-       = new Session_ServerThread(argc, argv, _orb,_root_poa,_GUIMutex,&_ServerLaunch);
+       = new Session_ServerThread(argc, argv, _orb,_root_poa,_GUIMutex);
       _serverThreads.push_back(aServerThread);
 
-      aServerThread->start();
-      MESSAGE("waiting wakeAll()");
-      _ServerLaunch.wait(_GUIMutex); // to be reseased by serverThread when ready:
-      // atomic operation lock - unlock on mutex
-      // unlock mutex: serverThread runs, calls  _ServerLaunch->wakeAll()
-      // this thread wakes up, and lock mutex
+      aServerThread->Init();
     }
 
   // Always launch Session Server
@@ -205,15 +208,9 @@ void Session_ServerLauncher::ActivateAll()
   char** argv = new char*[argc];
   argv[0] = "Session";
   Session_ServerThread* aServerThread
-    = new Session_ServerThread(argc, argv, _orb,_root_poa,_GUIMutex,&_ServerLaunch);
+    = new Session_ServerThread(argc, argv, _orb,_root_poa,_GUIMutex);
   _serverThreads.push_back(aServerThread);
 
-  aServerThread->start();
-  _ServerLaunch.wait(_GUIMutex); // to be reseased by serverThread when ready
-  // atomic operation lock - unlock on mutex
-  // unlock mutex: serverThread runs, calls  _ServerLaunch->wakeAll()
-  // this thread wakes up, and lock mutex
-
-  _GUIMutex->unlock();           // release mutex for Qt main Thread
+  aServerThread->Init();
 }
 
index 186a2f61630b2d42e59986800cd159d67062fe10..893754ac06142604c0d9407eb6d698b2f8fa6723 100644 (file)
@@ -35,6 +35,7 @@
 #include <list>
 #include <vector>
 #include <string>
+#include <qthread.h>
 #include <qwaitcondition.h>
 
 using namespace std;
@@ -52,7 +53,7 @@ inline ServArg::ServArg(int servType, int firstArg, int lastArg):
   _servType(servType),_firstArg(firstArg),_lastArg(lastArg)
 {}
 
-class Session_ServerLauncher
+class Session_ServerLauncher: public QThread
 {
 public:
   Session_ServerLauncher();
@@ -60,9 +61,10 @@ public:
                         char ** argv, 
                         CORBA::ORB_ptr orb, 
                         PortableServer::POA_ptr poa,
-                        QMutex *GUIMutex);
-  virtual ~Session_ServerLauncher();;
-  void Init();
+                        QMutex *GUIMutex,
+                        QWaitCondition *ServerLaunch);
+  virtual ~Session_ServerLauncher();
+  void run();
 protected:
 
   void CheckArgs();
@@ -76,7 +78,7 @@ private:
   CORBA::ORB_var _orb;
   PortableServer::POA_var _root_poa;
   QMutex* _GUIMutex;
-  QWaitCondition _ServerLaunch;
+  QWaitCondition *_ServerLaunch;
   list<ServArg> _argServToLaunch;
   vector<string> _argCopy;
   list<Session_ServerThread*> _serverThreads;
index 6783d4a29b5a78293fd309d10582c6729926eb81..1cf8ca856a8f2165dc7731cc9d1744edf7f1f0cc 100644 (file)
@@ -135,8 +135,7 @@ Session_ServerThread::Session_ServerThread(int argc,
                                           char ** argv, 
                                           CORBA::ORB_ptr orb, 
                                           PortableServer::POA_ptr poa,
-                                          QMutex *GUIMutex,
-                                          QWaitCondition *ServerLaunch)
+                                          QMutex *GUIMutex)
 {
   MESSAGE("Session_ServerThread Constructor " << argv[0]);
   _argc = argc;
@@ -144,7 +143,6 @@ Session_ServerThread::Session_ServerThread(int argc,
   _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
@@ -168,13 +166,9 @@ Session_ServerThread::~Session_ServerThread()
  */
 //=============================================================================
 
-void Session_ServerThread::run()
+void Session_ServerThread::Init()
 {
-  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();
+  MESSAGE("Session_ServerThread::Init "<< _argv[0]); 
 
   for (int i=0; i<_argc; i++) SCRUTE(_argv[i]);
   for (int i=0; i<NB_SRV_TYP; i++)
@@ -253,8 +247,6 @@ void Session_ServerThread::ActivateModuleCatalog(int argc,
       MESSAGE("---");
       _NS->Register(myCata ,"/Kernel/ModulCatalog");
       MESSAGE("---");
-      _ServerLaunch->wakeAll();
-      _orb->run();   // this thread wait, during process events
     }
   catch(CORBA::SystemException&)
     {
@@ -303,9 +295,6 @@ void Session_ServerThread::ActivateSALOMEDS(int argc,
        = _root_poa->activate_object(myStudyManager_i);
 
       myStudyManager_i->register_name("/myStudyManager");
-       
-      _ServerLaunch->wakeAll();
-      _orb->run();   // this thread wait, during process events
     }
   catch(CORBA::SystemException&)
     {
@@ -382,16 +371,6 @@ void Session_ServerThread::ActivateRegistry(int argc,
       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 )
     {
@@ -473,9 +452,6 @@ void Session_ServerThread::ActivateContainer(int argc,
       
       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&)
     {
@@ -521,13 +497,7 @@ void Session_ServerThread::ActivateSession(int argc,
        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.");
index 3c2249b0ca2c9c587972af0bf31e31e0e49920c1..3c12b138e8955e9b8b1402a26555818ebe75fb45 100644 (file)
 #ifndef _SESSION_SERVERTHREAD_HXX_
 #define _SESSION_SERVERTHREAD_HXX_
 
-#include <qthread.h>
 #include <CORBA.h> 
+#include <string>
 
 #include "SALOME_NamingService.hxx"
-
-#include <qwaitcondition.h>
-#include <string>
+#include <qthread.h>
 
 using namespace std;
 
 void WaitForServerReadiness(string serverName);
 
 
-class Session_ServerThread: public QThread
+class Session_ServerThread
 {
 public:
   static const int NB_SRV_TYP;
@@ -53,10 +51,9 @@ public:
                       char ** argv, 
                       CORBA::ORB_ptr orb, 
                       PortableServer::POA_ptr poa,
-                      QMutex *GUIMutex,
-                      QWaitCondition *ServerLaunch);
+                      QMutex *GUIMutex);
   virtual ~Session_ServerThread();
-  void run();
+  void Init();
 protected:
   void ActivateModuleCatalog(int argc,
                             char ** argv);
@@ -76,7 +73,6 @@ private:
   CORBA::ORB_var _orb;
   PortableServer::POA_var _root_poa;
   QMutex* _GUIMutex;
-  QWaitCondition *_ServerLaunch;
   SALOME_NamingService *_NS;
 };