2 //=============================================================================
3 // File : SALOME_Session_i.cxx
4 // Created : mar jun 19 14:02:45 CEST 2001
5 // Author : Paul RASCLE, EDF
7 // Copyright : EDF 2001
9 //=============================================================================
11 #include "utilities.h"
13 #include "SALOME_Session_i.hxx"
14 #include "SALOME_NamingService.hxx"
15 #include "SALOME_Session_QThread.hxx"
17 #include "QAD_Application.h"
18 #include "QAD_Desktop.h"
19 #include <qapplication.h>
21 // Open CASCADE Includes
22 #include <OSD_SharedLibrary.hxx>
23 #include <OSD_LoadMode.hxx>
24 #include <OSD_Function.hxx>
26 //=============================================================================
30 //=============================================================================
32 SALOME_Session_i::SALOME_Session_i(int argc, char ** argv, CORBA::ORB_ptr orb, PortableServer::POA_ptr poa)
36 _IAPPThread = new SALOME_Session_QThread(_argc, _argv) ;
39 _orb = CORBA::ORB::_duplicate(orb) ;
40 _poa = PortableServer::POA::_duplicate(poa) ;
41 MESSAGE("constructor end");
44 //***//VISU::VISU_Gen_ptr SALOME_Session_i::GetVisuGen(){
45 //***// typedef VISU::VISU_Gen_ptr VisuGen(CORBA::ORB_var,PortableServer::POA_var,QMutex*);
46 //***// MESSAGE("SALOME_Session_i::GetVisuGen");
47 //***// OSD_SharedLibrary visuSharedLibrary("libVisuEngine.so");
48 //***// if(visuSharedLibrary.DlOpen(OSD_RTLD_LAZY))
49 //***// if(OSD_Function osdFun = visuSharedLibrary.DlSymb("GetVisuGen"))
50 //***// return ((VisuGen (*)) osdFun)(_orb,_poa,&_GUIMutex);
51 //***// return VISU::VISU_Gen::_nil();
54 Engines::Component_ptr SALOME_Session_i::GetVisuComponent() {
55 MESSAGE("SALOME_Session_i::GetVisuGen");
56 typedef Engines::Component_ptr VisuGen(CORBA::ORB_ptr,PortableServer::POA_ptr,QMutex*);
57 OSD_SharedLibrary visuSharedLibrary("libVISUEngine.so");
58 if(visuSharedLibrary.DlOpen(OSD_RTLD_LAZY))
59 if(OSD_Function osdFun = visuSharedLibrary.DlSymb("GetVisuGen"))
60 return ((VisuGen (*)) osdFun)(_orb,_poa,&_GUIMutex);
61 return Engines::Component::_nil();
64 //=============================================================================
68 //=============================================================================
70 SALOME_Session_i::~SALOME_Session_i()
72 MESSAGE("destructor end");
75 //=============================================================================
77 * tries to find the Corba Naming Service and to register the session,
78 * gives naming service interface to _IAPPThread
80 //=============================================================================
82 void SALOME_Session_i::NSregister()
84 SALOME::Session_ptr pSession = SALOME::Session::_narrow(_this());
87 _NS = new SALOME_NamingService(_orb);
88 _NS->Register(pSession, "/Kernel/Session");
89 _IAPPThread->setNamingService(_NS);
91 catch (ServiceUnreachable&)
93 INFOS("Caught exception: Naming Service Unreachable");
98 INFOS("Caught unknown exception from Naming Service");
100 MESSAGE("NSregister end");
103 //=============================================================================
105 * Launches the GUI if there is none.
106 * The Corba method is oneway (corba client does'nt wait for GUI completion)
108 //=============================================================================
110 void SALOME_Session_i::GetInterface()
112 _GUIMutex.lock() ; // get access to boolean _isGUI
113 _isGUI = _IAPPThread->running();
116 _IAPPThread->start() ;
118 _GUIMutex.unlock() ; // release access to boolean _isGUI
121 //=============================================================================
123 * Kills the session if there are no active studies nore GUI
125 //=============================================================================
127 void SALOME_Session_i::StopSession()
130 QAD_Application::getDesktop()->closeDesktop( true );
133 _GUIMutex.lock(); // get access to boolean _isGUI
134 if ((! _isGUI) && (! _runningStudies))
136 MESSAGE("Ask for Session Kill, OK");
141 _GUIMutex.unlock() ; // release access to boolean _isGUI
142 MESSAGE("Ask for Session Kill, NOK");
143 if (_isGUI) throw SALOME::Session::GUIActive();
144 if (_runningStudies) throw SALOME::Session::RunningStudies();
149 //=============================================================================
151 * Send a SALOME::StatSession structure (see idl) to the client
152 * (number of running studies and presence of GUI)
154 //=============================================================================
156 SALOME::StatSession SALOME_Session_i::GetStatSession()
158 // update Session state
160 _isGUI = _IAPPThread->running();
164 if ( QAD_Application::getDesktop() && QAD_Application::getDesktop()->getActiveApp() )
165 _runningStudies = QAD_Application::getDesktop()->getActiveApp()->getStudies().count();
170 SALOME::StatSession_var myStats = new SALOME::StatSession ;
172 myStats->state = SALOME::running ;
174 myStats->state = SALOME::asleep ;
175 myStats->runningStudies = _runningStudies ;
176 myStats->activeGUI = _isGUI ;
177 return myStats._retn() ;