// Module : SALOME
// $Header$
-using namespace std;
#include "utilities.h"
#include "SALOME_Session_i.hxx"
#include "SALOME_NamingService.hxx"
-#include "SALOME_Session_QThread.hxx"
+#include "SALOME_Event.hxx"
#include "QAD_Application.h"
#include "QAD_Desktop.h"
#include <OSD_SharedLibrary.hxx>
#include <OSD_LoadMode.hxx>
#include <OSD_Function.hxx>
+using namespace std;
//=============================================================================
/*! SALOME_Session_i
*/
//=============================================================================
-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,
+ QWaitCondition* GUILauncher)
{
_argc = argc ;
_argv = argv ;
- _IAPPThread = new SALOME_Session_QThread(_argc, _argv) ;
_isGUI = FALSE ;
_runningStudies= 0 ;
_orb = CORBA::ORB::_duplicate(orb) ;
_poa = PortableServer::POA::_duplicate(poa) ;
- MESSAGE("constructor end");
+ _GUIMutex = GUIMutex;
+ _GUILauncher = GUILauncher;
+ //MESSAGE("constructor end");
}
-
-Engines::Component_ptr SALOME_Session_i::GetVisuGen(){
- typedef Engines::Component_ptr VisuGen(CORBA::ORB_ptr, PortableServer::POA_ptr,
- SALOME_NamingService*, QMutex*);
- MESSAGE("SALOME_Session_i::GetVisuGen");
- 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);
+
+//=============================================================================
+/*! GetVisuComponent
+ * returns Visu component
+ */
+//=============================================================================
+
+Engines::Component_ptr SALOME_Session_i::GetVisuComponent()
+{
+ //MESSAGE("SALOME_Session_i::GetVisuGen");
+ typedef Engines::Component_ptr TGetImpl(CORBA::ORB_ptr,
+ PortableServer::POA_ptr,
+ SALOME_NamingService*,QMutex*);
+ OSD_SharedLibrary aSharedLibrary("libVISUEngineImpl.so");
+ if(aSharedLibrary.DlOpen(OSD_RTLD_LAZY))
+ if(OSD_Function anOSDFun = aSharedLibrary.DlSymb("GetImpl"))
+ return ((TGetImpl (*)) anOSDFun)(_orb,_poa,_NS,_GUIMutex);
return Engines::Component::_nil();
}
SALOME_Session_i::~SALOME_Session_i()
{
- MESSAGE("destructor end");
+ //MESSAGE("destructor end");
}
//=============================================================================
{
_NS = new SALOME_NamingService(_orb);
_NS->Register(pSession, "/Kernel/Session");
- _IAPPThread->setNamingService(_NS);
}
catch (ServiceUnreachable&)
{
{
INFOS("Caught unknown exception from Naming Service");
}
- MESSAGE("NSregister end");
+ //MESSAGE("Session registered in Naming Service");
}
//=============================================================================
void SALOME_Session_i::GetInterface()
{
- _GUIMutex.lock() ; // get access to boolean _isGUI
- _isGUI = _IAPPThread->running();
- if(!_isGUI){
- _isGUI = TRUE ;
- _IAPPThread->start() ;
+ if( !QAD_Application::getDesktop() ) {
+ _GUILauncher->wakeAll();
+ MESSAGE("SALOME_Session_i::GetInterface() called, starting GUI...")
}
- _GUIMutex.unlock() ; // release access to boolean _isGUI
}
//=============================================================================
* Kills the session if there are no active studies nore GUI
*/
//=============================================================================
+class CloseEvent : public SALOME_Event
+{
+public:
+ virtual void Execute() {
+ if ( QAD_Application::getDesktop() )
+ QAD_Application::getDesktop()->closeDesktop( true );
+ }
+};
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();
- }
-*/
+ ProcessVoidEvent( new CloseEvent() );
}
//=============================================================================
*/
//=============================================================================
+class QtLock
+{
+public:
+ QtLock() { if ( qApp ) qApp->lock(); }
+ ~QtLock() { if ( qApp ) qApp->unlock(); }
+};
+
+
SALOME::StatSession SALOME_Session_i::GetStatSession()
{
// update Session state
- _GUIMutex.lock();
- _isGUI = _IAPPThread->running();
+ _GUIMutex->lock();
+
_runningStudies = 0;
- if (_isGUI) {
- qApp->lock();
- if ( QAD_Application::getDesktop() && QAD_Application::getDesktop()->getActiveApp() )
+ {
+ QtLock lock;
+ _isGUI = QAD_Application::getDesktop();
+ if ( _isGUI && QAD_Application::getDesktop()->getActiveApp() )
_runningStudies = QAD_Application::getDesktop()->getActiveApp()->getStudies().count();
- qApp->unlock();
}
- _GUIMutex.unlock();
+
+ _GUIMutex->unlock();
+
// getting stat info
SALOME::StatSession_var myStats = new SALOME::StatSession ;
if (_runningStudies)
return myStats._retn() ;
}
+CORBA::Long SALOME_Session_i::GetActiveStudyId()
+{
+ long aStudyId=-1;
+ if( QAD_Application::getDesktop() && QAD_Application::getDesktop()->getActiveStudy()) {
+ aStudyId = QAD_Application::getDesktop()->getActiveStudy()->getStudyId();
+ }
+ return aStudyId;
+}