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
29 #include "utilities.h"
31 #include "Session_Session_i.hxx"
33 #include "SALOME_NamingService.hxx"
34 #include "SALOME_Event.hxx"
36 #include "SUIT_Session.h"
37 #include "SUIT_Application.h"
39 #include <qapplication.h>
41 // Open CASCADE Includes
42 #include <OSD_SharedLibrary.hxx>
43 #include <OSD_LoadMode.hxx>
44 #include <OSD_Function.hxx>
48 //=============================================================================
52 //=============================================================================
54 SALOME_Session_i::SALOME_Session_i(int argc,
57 PortableServer::POA_ptr poa,
59 QWaitCondition* GUILauncher)
65 _orb = CORBA::ORB::_duplicate(orb) ;
66 _poa = PortableServer::POA::_duplicate(poa) ;
68 _GUILauncher = GUILauncher;
69 //MESSAGE("constructor end");
72 //=============================================================================
74 * returns Visu component
76 //=============================================================================
78 Engines::Component_ptr SALOME_Session_i::GetComponent(const char* theLibraryName)
80 typedef Engines::Component_ptr TGetImpl(CORBA::ORB_ptr,
81 PortableServer::POA_ptr,
82 SALOME_NamingService*,QMutex*);
83 OSD_SharedLibrary aSharedLibrary(const_cast<char*>(theLibraryName));
84 if(aSharedLibrary.DlOpen(OSD_RTLD_LAZY))
85 if(OSD_Function anOSDFun = aSharedLibrary.DlSymb("GetImpl"))
86 return ((TGetImpl (*)) anOSDFun)(_orb,_poa,_NS,_GUIMutex);
87 return Engines::Component::_nil();
90 //=============================================================================
94 //=============================================================================
96 SALOME_Session_i::~SALOME_Session_i()
98 //MESSAGE("destructor end");
101 //=============================================================================
103 * tries to find the Corba Naming Service and to register the session,
104 * gives naming service interface to _IAPPThread
106 //=============================================================================
108 void SALOME_Session_i::NSregister()
110 SALOME::Session_ptr pSession = SALOME::Session::_narrow(_this());
113 _NS = new SALOME_NamingService(_orb);
114 _NS->Register(pSession, "/Kernel/Session");
116 catch (ServiceUnreachable&)
118 INFOS("Caught exception: Naming Service Unreachable");
123 INFOS("Caught unknown exception from Naming Service");
125 //MESSAGE("Session registered in Naming Service");
128 //=============================================================================
130 * Launches the GUI if there is none.
131 * The Corba method is oneway (corba client does'nt wait for GUI completion)
133 //=============================================================================
135 void SALOME_Session_i::GetInterface()
137 if( !SUIT_Session::session() ) {
138 _GUILauncher->wakeAll();
139 MESSAGE("SALOME_Session_i::GetInterface() called, starting GUI...")
143 //=============================================================================
145 * Kills the session if there are no active studies nore GUI
147 //=============================================================================
148 class CloseEvent : public SALOME_Event
151 virtual void Execute() {
152 //if ( SUIT_Application::getDesktop() )
153 // QAD_Application::getDesktop()->closeDesktop( true );
157 void SALOME_Session_i::StopSession()
159 ProcessVoidEvent( new CloseEvent() );
162 //=============================================================================
164 * Send a SALOME::StatSession structure (see idl) to the client
165 * (number of running studies and presence of GUI)
167 //=============================================================================
172 QtLock() { if ( qApp ) qApp->lock(); }
173 ~QtLock() { if ( qApp ) qApp->unlock(); }
177 SALOME::StatSession SALOME_Session_i::GetStatSession()
179 // update Session state
185 _isGUI = SUIT_Session::session();
186 if ( _isGUI && SUIT_Session::session()->activeApplication() )
187 _runningStudies = SUIT_Session::session()->activeApplication()->getNbStudies();
193 SALOME::StatSession_var myStats = new SALOME::StatSession ;
195 myStats->state = SALOME::running ;
197 myStats->state = SALOME::asleep ;
198 myStats->runningStudies = _runningStudies ;
199 myStats->activeGUI = _isGUI ;
200 return myStats._retn() ;
203 CORBA::Long SALOME_Session_i::GetActiveStudyId()
206 //if ( SUIT_Session::session() && SUIT_Session::session()->activeApplication() ) {
207 // aStudyId = SUIT_Session::session()->getActiveStudy()->getStudyId();