1 // SALOME Session : implementation of Session.idl
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SALOME_Session_i.cxx
25 // Author : Paul RASCLE, EDF
30 #include "utilities.h"
32 #include "SALOME_Session_i.hxx"
33 #include "SALOME_NamingService.hxx"
34 #include "SALOME_Session_QThread.hxx"
36 #include "QAD_Application.h"
37 #include "QAD_Desktop.h"
38 #include <qapplication.h>
40 // Open CASCADE Includes
41 #include <OSD_SharedLibrary.hxx>
42 #include <OSD_LoadMode.hxx>
43 #include <OSD_Function.hxx>
45 //=============================================================================
49 //=============================================================================
51 SALOME_Session_i::SALOME_Session_i(int argc, char ** argv, CORBA::ORB_ptr orb, PortableServer::POA_ptr poa)
55 _IAPPThread = new SALOME_Session_QThread(_argc, _argv) ;
58 _orb = CORBA::ORB::_duplicate(orb) ;
59 _poa = PortableServer::POA::_duplicate(poa) ;
60 MESSAGE("constructor end");
63 //=============================================================================
65 * returns Visu component
67 //=============================================================================
69 Engines::Component_ptr SALOME_Session_i::GetVisuComponent() {
70 MESSAGE("SALOME_Session_i::GetVisuGen");
71 typedef Engines::Component_ptr VisuGen(CORBA::ORB_ptr,PortableServer::POA_ptr,
72 SALOME_NamingService*,QMutex*);
73 OSD_SharedLibrary visuSharedLibrary("libVISUEngine.so");
74 if(visuSharedLibrary.DlOpen(OSD_RTLD_LAZY))
75 if(OSD_Function osdFun = visuSharedLibrary.DlSymb("GetVisuGen"))
76 return ((VisuGen (*)) osdFun)(_orb,_poa,_NS,&_GUIMutex);
77 return Engines::Component::_nil();
80 //=============================================================================
84 //=============================================================================
86 SALOME_Session_i::~SALOME_Session_i()
88 MESSAGE("destructor end");
91 //=============================================================================
93 * tries to find the Corba Naming Service and to register the session,
94 * gives naming service interface to _IAPPThread
96 //=============================================================================
98 void SALOME_Session_i::NSregister()
100 SALOME::Session_ptr pSession = SALOME::Session::_narrow(_this());
103 _NS = new SALOME_NamingService(_orb);
104 _NS->Register(pSession, "/Kernel/Session");
105 _IAPPThread->setNamingService(_NS);
107 catch (ServiceUnreachable&)
109 INFOS("Caught exception: Naming Service Unreachable");
114 INFOS("Caught unknown exception from Naming Service");
116 MESSAGE("NSregister end");
119 //=============================================================================
121 * Launches the GUI if there is none.
122 * The Corba method is oneway (corba client does'nt wait for GUI completion)
124 //=============================================================================
126 void SALOME_Session_i::GetInterface()
128 _GUIMutex.lock() ; // get access to boolean _isGUI
129 _isGUI = _IAPPThread->running();
132 _IAPPThread->start() ;
134 _GUIMutex.unlock() ; // release access to boolean _isGUI
137 //=============================================================================
139 * Kills the session if there are no active studies nore GUI
141 //=============================================================================
143 void SALOME_Session_i::StopSession()
146 QAD_Application::getDesktop()->closeDesktop( true );
149 _GUIMutex.lock(); // get access to boolean _isGUI
150 if ((! _isGUI) && (! _runningStudies))
152 MESSAGE("Ask for Session Kill, OK");
157 _GUIMutex.unlock() ; // release access to boolean _isGUI
158 MESSAGE("Ask for Session Kill, NOK");
159 if (_isGUI) throw SALOME::Session::GUIActive();
160 if (_runningStudies) throw SALOME::Session::RunningStudies();
165 //=============================================================================
167 * Send a SALOME::StatSession structure (see idl) to the client
168 * (number of running studies and presence of GUI)
170 //=============================================================================
172 SALOME::StatSession SALOME_Session_i::GetStatSession()
174 // update Session state
175 //qApp->lock(); // rollback bug
177 _isGUI = _IAPPThread->running();
181 if ( QAD_Application::getDesktop() && QAD_Application::getDesktop()->getActiveApp() )
182 _runningStudies = QAD_Application::getDesktop()->getActiveApp()->getStudies().count();
188 SALOME::StatSession_var myStats = new SALOME::StatSession ;
190 myStats->state = SALOME::running ;
192 myStats->state = SALOME::asleep ;
193 myStats->runningStudies = _runningStudies ;
194 myStats->activeGUI = _isGUI ;
195 return myStats._retn() ;