]> SALOME platform Git repositories - modules/kernel.git/blob - src/Session/SALOME_Session_i.cxx
Salome HOME
NRI : VISU dependence.
[modules/kernel.git] / src / Session / SALOME_Session_i.cxx
1 using namespace std;
2 //=============================================================================
3 // File      : SALOME_Session_i.cxx
4 // Created   : mar jun 19 14:02:45 CEST 2001
5 // Author    : Paul RASCLE, EDF
6 // Project   : SALOME
7 // Copyright : EDF 2001
8 // $Header$
9 //=============================================================================
10
11 #include "utilities.h"
12
13 #include "SALOME_Session_i.hxx"
14 #include "SALOME_NamingService.hxx"
15 #include "SALOME_Session_QThread.hxx"
16
17 #include "QAD_Application.h"
18 #include "QAD_Desktop.h"
19 #include <qapplication.h>
20
21 // Open CASCADE Includes
22 #include <OSD_SharedLibrary.hxx>
23 #include <OSD_LoadMode.hxx>
24 #include <OSD_Function.hxx>
25
26 //=============================================================================
27 /*! SALOME_Session_i
28  *  constructor
29  */ 
30 //=============================================================================
31
32 SALOME_Session_i::SALOME_Session_i(int argc, char ** argv, CORBA::ORB_ptr orb, PortableServer::POA_ptr poa)
33 {
34   _argc = argc ;
35   _argv = argv ;
36   _IAPPThread = new SALOME_Session_QThread(_argc, _argv) ;
37   _isGUI = FALSE ;
38   _runningStudies= 0 ;
39   _orb = CORBA::ORB::_duplicate(orb) ;
40   _poa = PortableServer::POA::_duplicate(poa) ;
41   MESSAGE("constructor end");
42 }
43   
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();
52 //***//} 
53
54 typedef Engines::Component_ptr VisuGen(CORBA::ORB_var,PortableServer::POA_ptr,QMutex*);
55 Engines::Component_ptr SALOME_Session_i::GetVisuComponent() {
56   MESSAGE("SALOME_Session_i::GetVisuGen");
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
62   MESSAGE ( "nil" )
63   return Engines::Component::_nil();
64 }
65
66 //=============================================================================
67 /*! ~SALOME_Session_i
68  *  destructor
69  */ 
70 //=============================================================================
71
72 SALOME_Session_i::~SALOME_Session_i()
73 {
74   MESSAGE("destructor end"); 
75 }
76
77 //=============================================================================
78 /*! NSregister
79  *  tries to find the Corba Naming Service and to register the session,
80  *  gives naming service interface to _IAPPThread
81  */ 
82 //=============================================================================
83
84 void SALOME_Session_i::NSregister()
85 {
86   SALOME::Session_ptr pSession = SALOME::Session::_narrow(_this());
87   try
88     {
89       _NS = new SALOME_NamingService(_orb);
90       _NS->Register(pSession, "/Kernel/Session");
91       _IAPPThread->setNamingService(_NS);
92     }
93   catch (ServiceUnreachable&)
94     {
95       INFOS("Caught exception: Naming Service Unreachable");
96       exit(1) ;
97     }
98   catch (...)
99     {
100       INFOS("Caught unknown exception from Naming Service");
101     }
102   MESSAGE("NSregister end"); 
103 }
104
105 //=============================================================================
106 /*! GetInterface
107  *  Launches the GUI if there is none.
108  *  The Corba method is oneway (corba client does'nt wait for GUI completion)
109  */ 
110 //=============================================================================
111
112 void SALOME_Session_i::GetInterface()
113 {
114   _GUIMutex.lock() ;       // get access to boolean _isGUI
115   _isGUI = _IAPPThread->running();
116   if(!_isGUI){
117     _isGUI = TRUE ; 
118     _IAPPThread->start() ;
119   }
120   _GUIMutex.unlock() ; // release access to boolean _isGUI 
121 }
122
123 //=============================================================================
124 /*! StopSession
125  *  Kills the session if there are no active studies nore GUI
126  */ 
127 //=============================================================================
128
129 void SALOME_Session_i::StopSession()
130 {
131   qApp->lock();
132   QAD_Application::getDesktop()->closeDesktop( true );
133   qApp->unlock();
134 /*
135   _GUIMutex.lock();         // get access to boolean _isGUI
136   if ((! _isGUI) && (! _runningStudies))
137     {
138       MESSAGE("Ask for Session Kill, OK");
139       exit(0);
140     }
141   else
142     {
143       _GUIMutex.unlock() ;  // release access to boolean _isGUI
144       MESSAGE("Ask for Session Kill, NOK");
145       if (_isGUI) throw SALOME::Session::GUIActive();   
146       if (_runningStudies) throw SALOME::Session::RunningStudies();
147     }
148 */
149 }
150  
151 //=============================================================================
152 /*! StatSession
153  *  Send a SALOME::StatSession structure (see idl) to the client
154  *  (number of running studies and presence of GUI)
155  */ 
156 //=============================================================================
157
158 SALOME::StatSession SALOME_Session_i::GetStatSession()
159 {
160   // update Session state
161   _GUIMutex.lock();    
162   _isGUI = _IAPPThread->running();
163   _runningStudies = 0;
164   if (_isGUI) {
165     qApp->lock();
166     if ( QAD_Application::getDesktop() && QAD_Application::getDesktop()->getActiveApp() )
167       _runningStudies = QAD_Application::getDesktop()->getActiveApp()->getStudies().count();
168     qApp->unlock();
169   }
170   _GUIMutex.unlock();
171   // getting stat info
172   SALOME::StatSession_var myStats = new SALOME::StatSession ;
173   if (_runningStudies)
174     myStats->state = SALOME::running ;
175   else
176     myStats->state = SALOME::asleep ;
177   myStats->runningStudies = _runningStudies ;
178   myStats->activeGUI = _isGUI ;
179   return myStats._retn() ;
180 }
181