#include "SALOME_NamingService.hxx"
#include <iostream>
#include <unistd.h>
-using namespace std;
#include <qthread.h>
#include <qapplication.h>
#include "QAD_Config.h"
#include "QAD_Tools.h"
#include "QAD_ResourceMgr.h"
-#include "Utils_CatchSignals.h"
#include "Utils_SALOME_Exception.hxx"
#include "Utils_CorbaException.hxx"
#include "SALOMEGUI_QtCatchCorbaException.hxx"
-
+#include "SALOME_Event.hxx"
#include <SALOMEconfig.h>
#include CORBA_SERVER_HEADER(SALOME_Session)
#include "Session_ServerLauncher.hxx"
+extern "C" int HandleSignals(QApplication *theQApplication);
+
/*! - 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
*
*/
-// ----------------------------------------------------------------------------
-
-
-
-// ----------------------------------------------------------------------------
-
//! CORBA server for SALOME Session
/*!
* SALOME_Session Server launches a SALOME session servant.
* - get session state
*/
+using namespace std;
+
+#ifdef _DEBUG_
+static int MYDEBUG = 0;
+#else
+static int MYDEBUG = 0;
+#endif
+
int main(int argc, char **argv)
{
try
{
+ SALOME_Event::GetSessionThread();
+
ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()) ;
int orbArgc = 1;
SALOME_NamingService *_NS = new SALOME_NamingService(orb);
- Utils_CatchSignals aCatch;
- aCatch.Activate();
-
// CORBA Servant Launcher
-
QMutex _GUIMutex ;
QWaitCondition _ServerLaunch;
_GUIMutex.lock(); // to block Launch server thread until wait(mutex)
= 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
+ QApplication *_qappl = 0;
+
+ // Allow multiple activation/deactivation of GUI
+ while ( 1 ) {
+ 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...");
- INFOS("Session activated, Launch IAPP...");
+ int qappArgc = 1;
+ if ( !_qappl )
+ _qappl = new QApplication(qappArgc, argv );
- int qappArgc = 1;
- QApplication *_qappl = new QApplication(qappArgc, argv );
- INFOS("creation QApplication");
- _GUIMutex.unlock();
+ 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("creation SALOMEGUI_Application");
-
- SCRUTE(_NS);
- if ( !SALOMEGUI_Application::addToDesktop ( _mw, _NS ) )
- {
+ 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
- {
-
+ else {
QFileInfo prgInfo(argv[0]);
QDir prgDir(prgInfo.dirPath(true));
QAD_CONFIG->setPrgDir(prgDir); // CWD is program directory
_qappl->setPalette( QAD_Application::getPalette() );
- //Utils_CatchSignals aCatch;
- //aCatch.Activate();
-
/* Run 'SALOMEGUI' application */
QAD_Application::run();
// 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 (SALOME::SALOME_Exception& e)
- {
- QtCatchCorbaException(e);
- }
- catch(SALOMEDS::StudyBuilder::LockProtection&)
- {
- INFOS("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 (const CORBA::Exception& e)
- {
- CORBA::Any tmp;
- tmp<<= e;
- CORBA::TypeCode_var tc = tmp.type();
- const char *p = tc->name();
- INFOS ("run(): CORBA exception of the kind : "<<p<< " is caught");
+ while (1) {
+ try
+ {
+ MESSAGE("run(): starting the main event loop");
+ int _ret = HandleSignals(_qappl);
+ break;
+ }
+ catch (SALOME::SALOME_Exception& e)
+ {
+ QtCatchCorbaException(e);
+ }
+ catch(SALOMEDS::StudyBuilder::LockProtection&)
+ {
+ INFOS("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 (const CORBA::Exception& e)
+ {
+ CORBA::Any tmp;
+ tmp<<= e;
+ CORBA::TypeCode_var tc = tmp.type();
+ const char *p = tc->name();
+ INFOS ("run(): CORBA exception of the kind : "<<p<< " is caught");
- QApplication::restoreOverrideCursor();
- QAD_MessageBox::error1 ( (QWidget*)QAD_Application::getDesktop(),
- QObject::tr("ERR_ERROR"),
- QObject::tr("ERR_APP_EXCEPTION")
- + QObject::tr(" CORBA exception ") + QObject::tr(p),
- QObject::tr("BUT_OK") );
- }
- catch(std::exception& e)
- {
- INFOS("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(e.what()),
- QObject::tr("BUT_OK") );
- }
- catch(...)
- {
- INFOS("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") );
- }
- }
- //aCatch.Deactivate();
+ QApplication::restoreOverrideCursor();
+ QAD_MessageBox::error1 ( (QWidget*)QAD_Application::getDesktop(),
+ QObject::tr("ERR_ERROR"),
+ QObject::tr("ERR_APP_EXCEPTION")
+ + QObject::tr(" CORBA exception ") + QObject::tr(p),
+ QObject::tr("BUT_OK") );
+ }
+ catch(std::exception& e)
+ {
+ INFOS("run(): An exception has been caught");
+ QApplication::restoreOverrideCursor();
+ QAD_MessageBox::error1 ( (QWidget*)QAD_Application::getDesktop(),
+ QObject::tr("ERR_ERROR"),
+ QObject::tr("ERR_APP_EXCEPTION")+ "\n" +QObject::tr(e.what()),
+ QObject::tr("BUT_OK") );
+ }
+ catch(...)
+ {
+ INFOS("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") );
+ }
+ }
QString confMsg = "Settings create "
+ QAD_CONFIG->getConfigDir().absPath() + "/" + QObject::tr("MEN_APPNAME") + ".conf";
MESSAGE (confMsg);
QAD_CONFIG->createConfigFile(true);
}
+
+ // Prepare _GUIMutex for a new GUI activation
+ _GUIMutex.lock();
+ }
+
//orb->shutdown(0);
myServerLauncher->KillAll();
- aCatch.Deactivate();
}
catch (SALOME_Exception& e)
{
{
INFOS("Caught unknown exception.");
}
- MESSAGE("End of SALOME_Session_Server");
return 0 ;
}