#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.
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;
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;
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&)
{
*/
//=============================================================================
-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");
}
*/
//=============================================================================
-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();
}
{
_NS = new SALOME_NamingService(_orb);
_NS->Register(pSession, "/Kernel/Session");
- _IAPPThread->setNamingService(_NS);
}
catch (ServiceUnreachable&)
{
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
}
//=============================================================================
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();
- }
-*/
}
//=============================================================================
{
// 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 ;