1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : SALOME_Session_i.cxx
23 // Author : Paul RASCLE, EDF
26 #include "utilities.h"
28 #include "Session_Session_i.hxx"
30 #include "SALOME_NamingService.hxx"
31 #include "SALOME_Event.h"
33 #include "SUIT_Session.h"
34 #include "SUIT_Desktop.h"
35 #include "SUIT_Study.h"
37 #include "Basics_Utils.hxx"
40 #include <QWaitCondition>
42 // Open CASCADE Includes
43 #include <OSD_SharedLibrary.hxx>
44 #include <OSD_Function.hxx>
55 SALOME_Session_i::SALOME_Session_i(int argc,
58 PortableServer::POA_ptr poa,
60 QWaitCondition* GUILauncher)
66 _orb = CORBA::ORB::_duplicate(orb) ;
67 _poa = PortableServer::POA::_duplicate(poa) ;
69 _GUILauncher = GUILauncher;
70 _NS = new SALOME_NamingService(_orb);
71 _isShuttingDown = false;
72 //MESSAGE("constructor end");
76 returns Visu component
78 Engines::EngineComponent_ptr SALOME_Session_i::GetComponent(const char* theLibraryName)
80 typedef Engines::EngineComponent_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::EngineComponent::_nil();
93 SALOME_Session_i::~SALOME_Session_i()
96 //MESSAGE("destructor end");
100 tries to find the Corba Naming Service and to register the session,
101 gives naming service interface to _IAPPThread
103 void SALOME_Session_i::NSregister()
105 CORBA::Object_var obref=_this();
106 SALOME::Session_var pSession = SALOME::Session::_narrow(obref);
109 _NS->Register(pSession, "/Kernel/Session");
111 catch (ServiceUnreachable&)
113 INFOS("Caught exception: Naming Service Unreachable");
118 INFOS("Caught unknown exception from Naming Service");
120 //MESSAGE("Session registered in Naming Service");
124 Unregister session server from CORBA Naming Service
126 void SALOME_Session_i::NSunregister()
130 _NS->Destroy_Name("/Kernel/Session");
132 catch (ServiceUnreachable&)
134 INFOS("Caught exception: Naming Service Unreachable");
138 INFOS("Caught unknown exception from Naming Service");
143 Launches the GUI if there is none.
144 The Corba method is oneway (corba client does'nt wait for GUI completion)
146 void SALOME_Session_i::GetInterface()
150 if ( !SUIT_Session::session() )
152 _GUILauncher->wakeAll();
153 MESSAGE("SALOME_Session_i::GetInterface() called, starting GUI...");
158 Kills the session if there are no active studies nore GUI
160 class CloseEvent : public SALOME_Event
163 virtual void Execute() {
164 if ( SUIT_Session::session() )
165 SUIT_Session::session()->closeSession( SUIT_Session::DONT_SAVE );
170 Stop session (close all GUI windows)
172 void SALOME_Session_i::StopSession()
176 if ( SUIT_Session::session() ) {
177 ProcessVoidEvent( new CloseEvent() );
182 void SALOME_Session_i::Shutdown()
185 bool isBeingShuttingDown = _isShuttingDown;
186 _isShuttingDown = true;
188 if ( !isBeingShuttingDown ) {
189 if ( SUIT_Session::session() ) {
190 ProcessVoidEvent( new CloseEvent() );
193 _GUILauncher->wakeAll();
199 Send a SALOME::StatSession structure (see idl) to the client
200 (number of running studies and presence of GUI)
205 QtLock() { if ( qApp ) qApp->lock(); }
206 ~QtLock() { if ( qApp ) qApp->unlock(); }
210 SALOME::StatSession SALOME_Session_i::GetStatSession()
212 // update Session state
218 _isGUI = SUIT_Session::session();
219 if ( _isGUI && SUIT_Session::session()->activeApplication() )
220 _runningStudies = SUIT_Session::session()->activeApplication()->getNbStudies();
224 SALOME::StatSession_var myStats = new SALOME::StatSession ;
226 myStats->state = SALOME::running ;
227 else if (_isShuttingDown)
228 myStats->state = SALOME::shutdown ;
230 myStats->state = SALOME::asleep ;
231 myStats->runningStudies = _runningStudies ;
232 myStats->activeGUI = _isGUI ;
236 return myStats._retn() ;
239 CORBA::Long SALOME_Session_i::GetActiveStudyId()
242 if ( SUIT_Session::session() && SUIT_Session::session()->activeApplication() ) {
243 if ( SUIT_Session::session()->activeApplication()->activeStudy() ) // mkr : IPAL12128
244 aStudyId = SUIT_Session::session()->activeApplication()->activeStudy()->id();
249 CORBA::Long SALOME_Session_i::getPID() {
258 char* SALOME_Session_i::getHostname()
260 std::string aHostName = Kernel_Utils::GetHostname();
261 return CORBA::string_dup( aHostName.data() );
264 bool SALOME_Session_i::restoreVisualState(CORBA::Long theSavePoint)
266 class TEvent: public SALOME_Event {
269 TEvent(int savePoint) { _savePoint = savePoint; }
270 virtual void Execute() {
271 SUIT_Study* study = SUIT_Session::session()->activeApplication()->activeStudy();
273 study->restoreState(_savePoint);
278 if(SUIT_Session::session() && SUIT_Session::session()->activeApplication() ) {
279 SUIT_Study* study = SUIT_Session::session()->activeApplication()->activeStudy();
280 if(!study) SUIT_Session::session()->activeApplication()->createEmptyStudy();
281 ProcessVoidEvent( new TEvent(theSavePoint) );
288 void SALOME_Session_i::emitMessage(const char* theMessage)
290 class TEvent: public SALOME_Event {
292 TEvent(const char * msg) {
295 virtual void Execute() {
296 SUIT_Session::session()->activeApplication()->desktop()->emitMessage(_msg);
301 if ( SUIT_Session::session() ) {
302 if ( SUIT_Session::session()->activeApplication() ) {
303 if ( SUIT_Session::session()->activeApplication()->desktop() ) {
304 ProcessVoidEvent( new TEvent(theMessage) );
310 void SALOME_Session_i::emitMessageOneWay(const char* theMessage)
312 emitMessage(theMessage);