From: prascle Date: Tue, 23 Mar 2004 07:08:02 +0000 (+0000) Subject: PR: Prototype for Qt in main thread X-Git-Tag: QT_THREAD_20040326 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=7a3d44037c38c2b6f73c4d65cd9836aeabbcf640;p=modules%2Fkernel.git PR: Prototype for Qt in main thread --- diff --git a/src/Session/Makefile.in b/src/Session/Makefile.in index 36ba65dde..b5d950815 100644 --- a/src/Session/Makefile.in +++ b/src/Session/Makefile.in @@ -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 diff --git a/src/Session/SALOME_Session_Server.cxx b/src/Session/SALOME_Session_Server.cxx index 2b00367c2..efc0685b5 100644 --- a/src/Session/SALOME_Session_Server.cxx +++ b/src/Session/SALOME_Session_Server.cxx @@ -33,13 +33,87 @@ #include using namespace std; +#include +#include +#include + +#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 #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_::Instance() ; ASSERT(SINGLETON_::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_::Instance() ; + SALOME_NamingService *_NS = SINGLETON_::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&) { diff --git a/src/Session/SALOME_Session_i.cxx b/src/Session/SALOME_Session_i.cxx index dc16fae7d..3d2828e69 100644 --- a/src/Session/SALOME_Session_i.cxx +++ b/src/Session/SALOME_Session_i.cxx @@ -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 ; diff --git a/src/Session/SALOME_Session_i.hxx b/src/Session/SALOME_Session_i.hxx index 0d52f118e..438b93f62 100644 --- a/src/Session/SALOME_Session_i.hxx +++ b/src/Session/SALOME_Session_i.hxx @@ -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;