]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
PR: Prototype for Qt in main thread QT_THREAD_20040326
authorprascle <prascle>
Tue, 23 Mar 2004 07:08:02 +0000 (07:08 +0000)
committerprascle <prascle>
Tue, 23 Mar 2004 07:08:02 +0000 (07:08 +0000)
src/Session/Makefile.in
src/Session/SALOME_Session_Server.cxx
src/Session/SALOME_Session_i.cxx
src/Session/SALOME_Session_i.hxx

index 36ba65ddefbc20d6d1a9c185bf2f56d881192498..b5d95081508806752a8338c116c64cfc7bfddecf 100644 (file)
@@ -40,7 +40,6 @@ EXPORT_HEADERS= SALOME_Session_i.hxx
 # Libraries targets
 LIB = libSalomeSession.la
 LIB_SRC=\
-       SALOME_Session_QThread.cxx \
        SALOME_Session_i.cxx
 
 # Executables targets
index 2b00367c27fd2e68b62b9e2b4aed275d87a00817..efc0685b546e910f2025f59e69080516eec4e936 100644 (file)
 #include <unistd.h>
 using namespace std;
 
+#include <qthread.h> 
+#include <qapplication.h>
+#include <qlabel.h>
+
+#include "SALOMEGUI_Application.h"
+#include "QAD.h"
+#include "QAD_MessageBox.h"
+#include "QAD_Application.h"
+#include "QAD_Settings.h"
+#include "QAD_Config.h"
+#include "QAD_Tools.h"
+#include "QAD_ResourceMgr.h"
+
+
 #include <SALOMEconfig.h>
 #include CORBA_SERVER_HEADER(SALOME_Session)
+#include CORBA_SERVER_HEADER(SALOMEDS)
 
 #include "utilities.h"
 
 #include "SALOME_Session_i.hxx"
 
+// ----------------------------------------------------------------------------
+
+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.");
+      }  
+  }
+};
+
+// ----------------------------------------------------------------------------
+
 //! CORBA server for SALOME Session
 /*!
  *  SALOME_Session Server launches a SALOME session servant.
@@ -54,14 +128,12 @@ using namespace std;
 
 int main(int argc, char **argv)
 {
-
   try
     {
       ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
       ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()) ;
       CORBA::ORB_var &orb = init( argc , argv ) ;
 
-      //
       long TIMESleep = 250000000;
       int NumberOfTries = 40;
       int a;
@@ -76,7 +148,9 @@ int main(int argc, char **argv)
       CORBA::Object_var theObj;
       CORBA::Object_var obj;
       CORBA::Object_var object;
-      SALOME_NamingService &naming = *SINGLETON_<SALOME_NamingService>::Instance() ;
+      SALOME_NamingService *_NS = SINGLETON_<SALOME_NamingService>::Instance();
+      _NS->init_orb(orb);
+
       int SESSION=0;
       const char * Env = getenv("USE_LOGGER"); 
       int EnvL =0;
@@ -86,76 +160,132 @@ int main(int argc, char **argv)
       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;
-      }
-   
-      // 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)")
+      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
 
-       obj = mySALOME_Session->_this() ;
-      CORBA::String_var sior(orb->object_to_string(obj)) ;
+      QApplication *_qappl = new QApplication(argc, argv );
+      INFOS("creation QApplication");
 
-      mySALOME_Session->NSregister();
+      QAD_ASSERT ( QObject::connect(_qappl, SIGNAL(lastWindowClosed()), _qappl, SLOT(quit()) ) );
+      SALOMEGUI_Application* _mw = new SALOMEGUI_Application ( "MDTV-Standard", "HDF", "hdf" );
+      INFOS("creation SALOMEGUI_Application");
+      
+      SCRUTE(_NS);
+      if ( !SALOMEGUI_Application::addToDesktop ( _mw, _NS ) )
+       {
+         QAD_MessageBox::error1 ( 0,
+                                  QObject::tr("ERR_ERROR"), 
+                                  QObject::tr("ERR_APP_INITFAILED"),
+                                  QObject::tr("BUT_OK") );
+       }
+      else
+       {
+         
+         QFileInfo prgInfo(argv[0]);
+         QDir prgDir(prgInfo.dirPath(true));
+         QAD_CONFIG->setPrgDir(prgDir);        // CWD is program directory
+         QAD_CONFIG->createConfigFile(false);  // Create config file
+                                               // ~/.tr(MEN_APPNAME)/tr(MEN_APPNAME).conf if there's none
+         QAD_CONFIG->readConfigFile();         // Read config file
+         
+         _qappl->setPalette( QAD_Application::getPalette() ); 
 
-      mySALOME_Session->_remove_ref() ;
+         /* Run 'SALOMEGUI' application */
+         QAD_Application::run();
 
-      //DECOMMENT PortableServer::POAManager_var pman = poa->the_POAManager() ;
-      pman->activate() ;
-      MESSAGE("pman->activate()")
+         // T2.12 - catch exceptions thrown on attempts to modified a locked study
+         while (1) 
+           {
+             try 
+               {
+                 MESSAGE("run(): starting the main event loop");
+                 int _ret = _qappl->exec();
+                 break;
+               }
+             catch(SALOMEDS::StudyBuilder::LockProtection&)
+               {
+                 MESSAGE("run(): An attempt to modify a locked study has not been handled by QAD_Operation");
+                 QApplication::restoreOverrideCursor();
+                 QAD_MessageBox::warn1 ( (QWidget*)QAD_Application::getDesktop(),
+                                         QObject::tr("WRN_WARNING"), 
+                                         QObject::tr("WRN_STUDY_LOCKED"),
+                                         QObject::tr("BUT_OK") );
+               }
+             catch(...)
+               {
+                 MESSAGE("run(): An exception has been caught");
+                 QApplication::restoreOverrideCursor();
+                 QAD_MessageBox::error1 ( (QWidget*)QAD_Application::getDesktop(),
+                                          QObject::tr("ERR_ERROR"), 
+                                          QObject::tr("ERR_APP_EXCEPTION"),
+                                          QObject::tr("BUT_OK") );
+               }
+           }
 
-       orb->run() ;
-      orb->destroy() ;
+         QString confMsg = "Settings create $HOME/." 
+           + QObject::tr("MEN_APPNAME") + "/" + QObject::tr("MEN_APPNAME") + ".conf";
+         MESSAGE (confMsg );
+         QAD_CONFIG->createConfigFile(true);
+       }
     }
   catch (CORBA::SystemException&)
     {
index dc16fae7deceae32874412b7906e3a3f963d2b5d..3d2828e69528b72eef010a7242c9bc0aa3514f2e 100644 (file)
@@ -48,15 +48,15 @@ using namespace std;
  */ 
 //=============================================================================
 
-SALOME_Session_i::SALOME_Session_i(int argc, char ** argv, CORBA::ORB_ptr orb, PortableServer::POA_ptr poa)
+SALOME_Session_i::SALOME_Session_i(int argc, char ** argv, CORBA::ORB_ptr orb, PortableServer::POA_ptr poa, QMutex* GUIMutex)
 {
   _argc = argc ;
   _argv = argv ;
-  _IAPPThread = SALOME_Session_QThread::Instance(_argc, _argv);
   _isGUI = FALSE ;
   _runningStudies= 0 ;
   _orb = CORBA::ORB::_duplicate(orb) ;
   _poa = PortableServer::POA::_duplicate(poa) ;
+  _GUIMutex = GUIMutex;
   MESSAGE("constructor end");
 }
 
@@ -66,14 +66,16 @@ SALOME_Session_i::SALOME_Session_i(int argc, char ** argv, CORBA::ORB_ptr orb, P
  */ 
 //=============================================================================
 
-Engines::Component_ptr SALOME_Session_i::GetVisuComponent() {
+Engines::Component_ptr SALOME_Session_i::GetVisuComponent()
+{
   MESSAGE("SALOME_Session_i::GetVisuGen");
-  typedef Engines::Component_ptr VisuGen(CORBA::ORB_ptr,PortableServer::POA_ptr,
+  typedef Engines::Component_ptr VisuGen(CORBA::ORB_ptr,
+                                        PortableServer::POA_ptr,
                                         SALOME_NamingService*,QMutex*);
   OSD_SharedLibrary  visuSharedLibrary("libVISUEngine.so");
   if(visuSharedLibrary.DlOpen(OSD_RTLD_LAZY))
     if(OSD_Function osdFun = visuSharedLibrary.DlSymb("GetVisuGen"))
-      return ((VisuGen (*)) osdFun)(_orb,_poa,_NS,&_GUIMutex);
+      return ((VisuGen (*)) osdFun)(_orb,_poa,_NS,_GUIMutex);
   return Engines::Component::_nil();
 }
 
@@ -102,7 +104,6 @@ void SALOME_Session_i::NSregister()
     {
       _NS = new SALOME_NamingService(_orb);
       _NS->Register(pSession, "/Kernel/Session");
-      _IAPPThread->setNamingService(_NS);
     }
   catch (ServiceUnreachable&)
     {
@@ -125,13 +126,14 @@ void SALOME_Session_i::NSregister()
 
 void SALOME_Session_i::GetInterface()
 {
-  _GUIMutex.lock() ;       // get access to boolean _isGUI
-  _isGUI = _IAPPThread->running();
-  if(!_isGUI){
-    _isGUI = TRUE ; 
-    _IAPPThread->start() ;
-  }
-  _GUIMutex.unlock() ; // release access to boolean _isGUI 
+  _GUIMutex->lock() ;       // get access to boolean _isGUI
+  //_isGUI = _IAPPThread->running();
+  if(!_isGUI)
+    {
+      _isGUI = TRUE ; 
+      //_IAPPThread->start() ;
+    }
+  _GUIMutex->unlock() ; // release access to boolean _isGUI 
 }
 
 //=============================================================================
@@ -145,21 +147,6 @@ void SALOME_Session_i::StopSession()
   qApp->lock();
   QAD_Application::getDesktop()->closeDesktop( true );
   qApp->unlock();
-/*
-  _GUIMutex.lock();         // get access to boolean _isGUI
-  if ((! _isGUI) && (! _runningStudies))
-    {
-      MESSAGE("Ask for Session Kill, OK");
-      exit(0);
-    }
-  else
-    {
-      _GUIMutex.unlock() ;  // release access to boolean _isGUI
-      MESSAGE("Ask for Session Kill, NOK");
-      if (_isGUI) throw SALOME::Session::GUIActive();   
-      if (_runningStudies) throw SALOME::Session::RunningStudies();
-    }
-*/
 }
  
 //=============================================================================
@@ -173,16 +160,18 @@ SALOME::StatSession SALOME_Session_i::GetStatSession()
 {
   // update Session state
   //qApp->lock(); // rollback bug 
-  _GUIMutex.lock();    
-  _isGUI = _IAPPThread->running();
+  _GUIMutex->lock();    
+  //_isGUI = _IAPPThread->running();
+  _isGUI = 1;
   _runningStudies = 0;
-  if (_isGUI) {
-    qApp->lock();
-    if ( QAD_Application::getDesktop() && QAD_Application::getDesktop()->getActiveApp() )
-      _runningStudies = QAD_Application::getDesktop()->getActiveApp()->getStudies().count();
-    qApp->unlock();
-  }
-  _GUIMutex.unlock();
+  if (_isGUI)
+    {
+      qApp->lock();
+      if ( QAD_Application::getDesktop() && QAD_Application::getDesktop()->getActiveApp() )
+       _runningStudies = QAD_Application::getDesktop()->getActiveApp()->getStudies().count();
+      qApp->unlock();
+    }
+  _GUIMutex->unlock();
   //qApp->unlock();
   // getting stat info
   SALOME::StatSession_var myStats = new SALOME::StatSession ;
index 0d52f118eb04ff5a452fed0ce0943b08e6a6465b..438b93f62aeb2c105f35bb9eeca361ac9980e4a2 100644 (file)
@@ -41,8 +41,8 @@ class SALOME_Session_i:  public virtual POA_SALOME::Session,
                         public virtual PortableServer::RefCountServantBase
 {
 public:
-  SALOME_Session_i(int argc, char ** argv, CORBA::ORB_ptr orb, PortableServer::POA_ptr poa;
-  ~SALOME_Session_i() ;
+  SALOME_Session_i(int argc, char ** argv, CORBA::ORB_ptr orb, PortableServer::POA_ptr poa, QMutex* GUIMutex);
+  ~SALOME_Session_i();
 
   //! Launch Graphical User Interface
   void GetInterface();
@@ -62,8 +62,6 @@ public:
   void ping(){};
 
 protected:
-  //! A QT Thread for the GUI
-  SALOME_Session_QThread *_IAPPThread ;
 
   //! Naming service interface
   SALOME_NamingService *_NS;
@@ -71,7 +69,7 @@ protected:
   int _argc ;
   char **_argv;
   CORBA::Boolean _isGUI ;
-  QMutex _GUIMutex ;
+  QMutex* _GUIMutex ;
   int _runningStudies ;
   CORBA::ORB_var _orb;
   PortableServer::POA_var _poa;