-// SALOME Session : implementation of Session.idl
+// SALOME Session : implementation of Session.idl
//
-// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
+// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
//
-// File : SALOME_Session_Server.cxx
-// Author : Paul RASCLE, EDF
-// Module : SALOME
-// $Header$
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
+//
+//
+//
+// File : SALOME_Session_Server.cxx
+// Author : Paul RASCLE, EDF
+// Module : SALOME
#include <Container_init_python.hxx>
#include "Utils_ORB_INIT.hxx"
#include "Session_Session_i.hxx"
#include "Session_ServerLauncher.hxx"
+#include "SUIT_Tools.h"
#include "SUIT_Session.h"
#include "SUIT_Application.h"
#include "SUIT_MessageBox.h"
-#include "SUIT_Tools.h"
-
#include "SUIT_ExceptionHandler.h"
-using namespace std;
-extern "C" int HandleSignals(QApplication *theQApplication);
+extern "C" int HandleSignals( QApplication *theQApplication );
/*! - read arguments, define list of server to launch with their arguments.
- * - wait for naming service
- * - create and run a thread for launch of all servers
- *
- */
+ * - wait for naming service
+ * - create and run a thread for launch of all servers
+ *
+*/
//! CORBA server for SALOME Session
/*!
- * SALOME_Session Server launches a SALOME session servant.
- * The servant registers to the Naming Service.
- * See SALOME_Session.idl for interface specification.
+ * SALOME_Session Server launches a SALOME session servant.
+ * The servant registers to the Naming Service.
+ * See SALOME_Session.idl for interface specification.
*
- * Main services offered by the servant are:
- * - launch GUI
- * - stop Session (must be idle)
- * - get session state
+ * Main services offered by the servant are:
+ * - launch GUI
+ * - stop Session ( must be idle )
+ * - get session state
*/
QString salomeVersion()
return ver;
}
-PyObject *salome_shared_modules_module = NULL;
+PyObject* salome_shared_modules_module = 0;
-void MessageOutput( QtMsgType type, const char *msg )
+void MessageOutput( QtMsgType type, const char* msg )
{
- switch ( type ) {
+ switch ( type )
+ {
case QtDebugMsg:
MESSAGE( "Debug: " << msg );
break;
}
};
-class SALOME_QApplication : public QApplication
+class SALOME_QApplication : public QApplication
{
public:
- SALOME_QApplication( int& argc, char** argv ) : QApplication( argc, argv )
- {
- myHandler = 0;
- }
-
- virtual bool notify( QObject* receiver, QEvent* e )
+ SALOME_QApplication( int& argc, char** argv ) : QApplication( argc, argv ), myHandler ( 0 ) {}
+
+ virtual bool notify( QObject* receiver, QEvent* e )
{
return myHandler ? myHandler->handle( receiver, e ) :
- QApplication::notify( receiver, e );
+ QApplication::notify( receiver, e );
}
- SUIT_ExceptionHandler* handler() const { return myHandler; }
+ SUIT_ExceptionHandler* handler() const { return myHandler; }
void setHandler( SUIT_ExceptionHandler* h ) { myHandler = h; }
private:
- SUIT_ExceptionHandler* myHandler;
+ SUIT_ExceptionHandler* myHandler;
};
// class which calls SALOME::Session::GetInterface() from another thread
-// to avoid mutual lock (if called from the same thread as main()
+// to avoid mutual lock ( if called from the same thread as main()
class GetInterfaceThread : public QThread
{
-public:
+public:
GetInterfaceThread( SALOME::Session_var s ) : session ( s ) {}
protected:
virtual void run()
{
if ( !CORBA::is_nil( session ) )
- session->GetInterface();
+ session->GetInterface();
else
- printf( "\nFATAL ERROR: SALOME::Session object is nil! Can not display GUI\n\n" );
+ printf( "\nFATAL ERROR: SALOME::Session object is nil! Can not display GUI\n\n" );
}
private:
SALOME::Session_var session;
// returns true if 'str' is found in argv
bool isFound( const char* str, int argc, char** argv )
{
- for ( int i = 1; i <= (argc-1); i++ )
+ for ( int i = 1; i <= ( argc-1 ); i++ )
if ( !strcmp( argv[i], str ) )
return true;
return false;
}
// ---------------------------- MAIN -----------------------
-int main(int argc, char **argv)
+int main( int argc, char **argv )
{
qInstallMsgHandler( MessageOutput );
// QApplication should be create before all other operations
- // When uses QApplication::libraryPaths() (example, QFile::encodeName())
+ // When uses QApplication::libraryPaths() ( example, QFile::encodeName() )
// qApp used for detection of the executable dir path.
SALOME_QApplication _qappl( argc, argv );
- ASSERT( QObject::connect(&_qappl, SIGNAL( lastWindowClosed() ), &_qappl, SLOT( quit() ) ) );
- QString path( ::getenv( "GUI_ROOT_DIR" ) );
- if ( !path.isEmpty() )
- path += QDir::separator();
- path += QString( "bin/salome" );
+ ASSERT( QObject::connect( &_qappl, SIGNAL( lastWindowClosed() ), &_qappl, SLOT( quit() ) ) );
+
+ QString path = QDir::convertSeparators( SUIT_Tools::addSlash( QString( ::getenv( "GUI_ROOT_DIR" ) ) ) + QString( "bin/salome" ) );
_qappl.addLibraryPath( path );
+
_qappl.setStyle( "salome" );
- /*
- Python initialisation : only once
- */
-
- int _argc = 1;
- char* _argv[] = {""};
- KERNEL_PYTHON::init_python(_argc,_argv);
- PyEval_RestoreThread(KERNEL_PYTHON::_gtstate);
- if ( !KERNEL_PYTHON::salome_shared_modules_module ) // import only once
- {
- KERNEL_PYTHON::salome_shared_modules_module =
- PyImport_ImportModule("salome_shared_modules");
- }
- if ( !KERNEL_PYTHON::salome_shared_modules_module )
- {
- INFOS("salome_shared_modules_module == NULL");
- PyErr_Print();
- PyErr_Clear();
- }
- PyEval_ReleaseThread(KERNEL_PYTHON::_gtstate);
-
int result = -1;
- // 1. create ORB, get RootPOA object, NamingService, etc.
- ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
- ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()) ;
- int orbArgc = 1;
- CORBA::ORB_var &orb = init( orbArgc , argv ) ;
- SALOMETraceCollector *myThreadTrace = SALOMETraceCollector::instance(orb);
+ CORBA::ORB_var orb;
+ PortableServer::POA_var poa;
+
+ SUIT_Session* aGUISession = 0;
+ SALOME_NamingService* _NS = 0;
GetInterfaceThread* guiThread = 0;
+ SALOMETraceCollector* myThreadTrace = 0;
+ Session_ServerLauncher* myServerLauncher = 0;
- try
- {
+ try {
+
+ // Python initialisation : only once
+
+ int _argc = 1;
+ char* _argv[] = {""};
+ KERNEL_PYTHON::init_python( _argc,_argv );
+ PyEval_RestoreThread( KERNEL_PYTHON::_gtstate );
+ if ( !KERNEL_PYTHON::salome_shared_modules_module ) // import only once
+ KERNEL_PYTHON::salome_shared_modules_module = PyImport_ImportModule( "salome_shared_modules" );
+ if ( !KERNEL_PYTHON::salome_shared_modules_module )
+ {
+ INFOS( "salome_shared_modules_module == NULL" );
+ PyErr_Print();
+ PyErr_Clear();
+ }
+ PyEval_ReleaseThread( KERNEL_PYTHON::_gtstate );
+
+ // Create ORB, get RootPOA object, NamingService, etc.
+ ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance();
+ ASSERT( SINGLETON_<ORB_INIT>::IsAlreadyExisting() );
+ int orbArgc = 1;
+ orb = init( orbArgc, argv );
+ myThreadTrace = SALOMETraceCollector::instance( orb );
+
+ // Install SALOME thread event handler
SALOME_Event::GetSessionThread();
- CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
- PortableServer::POA_var poa = PortableServer::POA::_narrow(obj);
+ CORBA::Object_var obj = orb->resolve_initial_references( "RootPOA" );
+ poa = PortableServer::POA::_narrow( obj );
- PortableServer::POAManager_var pman = poa->the_POAManager() ;
+ PortableServer::POAManager_var pman = poa->the_POAManager();
pman->activate() ;
- INFOS("pman->activate()");
+ INFOS( "pman->activate()" );
- SALOME_NamingService *_NS = new SALOME_NamingService(orb);
+ _NS = new SALOME_NamingService( orb );
- // CORBA Servant Launcher
- QMutex _GUIMutex ;
- QWaitCondition _ServerLaunch, _SessionStarted;
- _GUIMutex.lock(); // to block Launch server thread until wait(mutex)
-
- // 2. activate embedded CORBA servers: Registry, SALOMEDS, etc.
- Session_ServerLauncher* myServerLauncher
- = new Session_ServerLauncher(argc, argv, orb, poa, &_GUIMutex, &_ServerLaunch, &_SessionStarted);
+ result = 0;
+ }
+ catch ( SALOME_Exception& e ) {
+ INFOS( "run(): SALOME::SALOME_Exception is caught: "<<e.what() );
+ }
+ catch ( CORBA::SystemException& e ) {
+ INFOS( "Caught CORBA::SystemException." );
+ }
+ catch ( CORBA::Exception& e ) {
+ INFOS( "Caught CORBA::Exception." );
+ CORBA::Any tmp;
+ tmp<<= e;
+ CORBA::TypeCode_var tc = tmp.type();
+ const char *p = tc->name();
+ INFOS ( "run(): CORBA exception of the kind : "<<p<< " is caught" );
+ }
+ catch ( exception& e ) {
+ INFOS( "run(): An exception has been caught: " <<e.what() );
+ }
+ catch (...) {
+ INFOS( "Caught unknown exception." );
+ }
+
+ // CORBA Servant Launcher
+ QMutex _GUIMutex;
+ QWaitCondition _ServerLaunch, _SessionStarted;
+
+ if ( !result )
+ {
+ _GUIMutex.lock(); // to block Launch server thread until wait( mutex )
+
+ // Activate embedded CORBA servers: Registry, SALOMEDS, etc.
+ myServerLauncher = new Session_ServerLauncher( argc, argv, orb, poa, &_GUIMutex, &_ServerLaunch, &_SessionStarted );
myServerLauncher->start();
-
- _ServerLaunch.wait(&_GUIMutex); // to be reseased by Launch server thread when ready
- // show splash screen if "SPLASH" parameter was passed (default)
- if ( isFound( "SPLASH", argc, argv ) )
+ _ServerLaunch.wait( &_GUIMutex ); // to be reseased by Launch server thread when ready:
+
+ // show splash screen if "SPLASH" parameter was passed ( default )
+ if ( isFound( "SPLASH", argc, argv ) )
{
// create temporary resource manager just to load splash icon
SUIT_ResourceMgr resMgr( "SalomeApp", QString( "%1Config" ) );
resMgr.setVersion( salomeVersion() );
resMgr.setCurrentFormat( "xml" );
resMgr.loadLanguage( "SalomeApp", "en" );
- // create splash object: widget (splash with progress bar) and "pinging" thread
+
+ // create splash object: widget ( splash with progress bar ) and "pinging" thread
InquireServersGUI splash;
splash.setPixmap( resMgr.loadPixmap( "SalomeApp", QObject::tr( "ABOUT" ) ) );
SUIT_Tools::centerWidget( &splash, _qappl.desktop() );
-
+
_qappl.setMainWidget( &splash );
QObject::connect( &_qappl, SIGNAL( lastWindowClosed() ), &_qappl, SLOT( quit() ) );
- splash.show(); // display splash with running progress bar
- _qappl.exec(); // wait untill splash closes (progress runs till end or Cancel is pressed)
-
- //int q = 0;
- //while ( q++ < 10 )
- // sleep( 1 );
-
- if ( splash.getExitStatus() ) // 1 is error
- exit( splash.getExitStatus() ); // quit applicaiton
+ splash.show(); // display splash with running progress bar
+ _qappl.exec(); // wait untill splash closes ( progress runs till end or Cancel is pressed )
+
+ result = splash.getExitStatus(); // 1 is error
}
else
_SessionStarted.wait();
+ }
- // call Session::GetInterface() if "GUI" parameter was passed (default)
- if ( isFound( "GUI", argc, argv ) )
- {
- CORBA::Object_var obj = _NS->Resolve("/Kernel/Session");
- SALOME::Session_var session = SALOME::Session::_narrow( obj ) ;
- ASSERT (! CORBA::is_nil( session ) );
+ // call Session::GetInterface() if "GUI" parameter was passed ( default )
+ if ( !result && isFound( "GUI", argc, argv ) )
+ {
+ CORBA::Object_var obj = _NS->Resolve( "/Kernel/Session" );
+ SALOME::Session_var session = SALOME::Session::_narrow( obj ) ;
+ ASSERT ( ! CORBA::is_nil( session ) );
- INFOS("Session activated, Launch IAPP...");
- guiThread = new GetInterfaceThread( session );
- guiThread->start();
- }
+ INFOS( "Session activated, Launch IAPP..." );
+ guiThread = new GetInterfaceThread( session );
+ guiThread->start();
+ }
- // 3. GUI activation
+ if ( !result )
+ {
+
+ // GUI activation
// Allow multiple activation/deactivation of GUI
- while ( 1 )
+ while ( true )
{
- MESSAGE("waiting wakeAll()");
- _ServerLaunch.wait(&_GUIMutex); // to be reseased by Launch server thread when ready:
+ MESSAGE( "waiting wakeAll()" );
+ _ServerLaunch.wait( &_GUIMutex ); // to be reseased by Launch server thread when ready:
// atomic operation lock - unlock on mutex
- // unlock mutex: serverThread runs, calls _ServerLaunch->wakeAll()
+ // unlock mutex: serverThread runs, calls _ServerLaunch->wakeAll()
// this thread wakes up, and lock mutex
-
+
_GUIMutex.unlock();
- // 3.1 SUIT_Session creation
- SUIT_Session* aGUISession = new SALOME_Session();
- INFOS("creation SUIT_Application");
-
- SCRUTE(_NS);
-
- // 3.3 run GUI loop
- // T2.12 - catch exceptions thrown on attempts to modified a locked study
- MESSAGE("run(): starting the main event loop");
-
- // 3.2 load SalomeApp dynamic library
+ // SUIT_Session creation
+ aGUISession = new SALOME_Session();
+
+ // Load SalomeApp dynamic library
+ INFOS( "creation SUIT_Application" );
SUIT_Application* aGUIApp = aGUISession->startApplication( "SalomeApp", 0, 0 );
- if ( aGUIApp )
+ if ( aGUIApp )
{
_qappl.setHandler( aGUISession->handler() ); // after loading SalomeApp application
// aGUISession contains SalomeApp_ExceptionHandler
+ // Run GUI loop
+ MESSAGE( "run(): starting the main event loop" );
result = _qappl.exec();
if ( result == SUIT_Session::FROM_GUI ) // desktop is closed by user from GUI
break;
}
+ delete aGUISession;
+ aGUISession = 0;
+
// Prepare _GUIMutex for a new GUI activation
- _GUIMutex.lock();
+ _GUIMutex.lock();
}
-
- //orb->shutdown(0);
- myServerLauncher->KillAll(); // kill embedded servers
- }
- catch (SALOME_Exception& e)
- {
- INFOS("run(): SALOME::SALOME_Exception is caught: "<<e.what());
- }
- catch (CORBA::SystemException& e)
- {
- INFOS("Caught CORBA::SystemException.");
- }
- catch (CORBA::Exception& e)
- {
- INFOS("Caught CORBA::Exception.");
- CORBA::Any tmp;
- tmp<<= e;
- CORBA::TypeCode_var tc = tmp.type();
- const char *p = tc->name();
- INFOS ("run(): CORBA exception of the kind : "<<p<< " is caught");
- }
- catch(exception& e)
- {
- INFOS("run(): An exception has been caught: " <<e.what());
- }
- catch (...)
- {
- INFOS("Caught unknown exception.");
}
+
+ if ( myServerLauncher )
+ myServerLauncher->KillAll(); // kill embedded servers
+
+ delete aGUISession;
+ delete guiThread;
+ delete myServerLauncher;
+ delete _NS;
delete myThreadTrace;
- if ( guiThread )
- delete guiThread;
- return result ;
+
+ return result;
}
// SALOME Session : implementation of Session.idl
//
// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
//
//
//
//=============================================================================
/*! SALOME_Session_i
* constructor
- */
+ */
//=============================================================================
-SALOME_Session_i::SALOME_Session_i(int argc,
- char ** argv,
- CORBA::ORB_ptr orb,
- PortableServer::POA_ptr poa,
+SALOME_Session_i::SALOME_Session_i(int argc,
+ char ** argv,
+ CORBA::ORB_ptr orb,
+ PortableServer::POA_ptr poa,
QMutex* GUIMutex,
QWaitCondition* GUILauncher)
{
//=============================================================================
/*! GetVisuComponent
* returns Visu component
- */
+ */
//=============================================================================
Engines::Component_ptr SALOME_Session_i::GetComponent(const char* theLibraryName)
//=============================================================================
/*! ~SALOME_Session_i
* destructor
- */
+ */
//=============================================================================
SALOME_Session_i::~SALOME_Session_i()
{
- //MESSAGE("destructor end");
+ //MESSAGE("destructor end");
}
//=============================================================================
/*! NSregister
* tries to find the Corba Naming Service and to register the session,
* gives naming service interface to _IAPPThread
- */
+ */
//=============================================================================
void SALOME_Session_i::NSregister()
{
INFOS("Caught unknown exception from Naming Service");
}
- //MESSAGE("Session registered in Naming Service");
+ //MESSAGE("Session registered in Naming Service");
}
//=============================================================================
/*! GetInterface
* Launches the GUI if there is none.
* The Corba method is oneway (corba client does'nt wait for GUI completion)
- */
+ */
//=============================================================================
void SALOME_Session_i::GetInterface()
{
_GUIMutex->lock();
_GUIMutex->unlock();
- if( !SUIT_Session::session() ) {
+ if ( !SUIT_Session::session() )
+ {
_GUILauncher->wakeAll();
MESSAGE("SALOME_Session_i::GetInterface() called, starting GUI...")
- }
+ }
}
//=============================================================================
/*! StopSession
* Kills the session if there are no active studies nore GUI
- */
+ */
//=============================================================================
class CloseEvent : public SALOME_Event
{
{
ProcessVoidEvent( new CloseEvent() );
}
-
+
//=============================================================================
/*! StatSession
* Send a SALOME::StatSession structure (see idl) to the client
* (number of running studies and presence of GUI)
- */
+ */
//=============================================================================
class QtLock
SALOME::StatSession SALOME_Session_i::GetStatSession()
{
// update Session state
- _GUIMutex->lock();
+ _GUIMutex->lock();
_runningStudies = 0;
{
QtLock lock;
_isGUI = SUIT_Session::session();
- if ( _isGUI && SUIT_Session::session()->activeApplication() )
+ if ( _isGUI && SUIT_Session::session()->activeApplication() )
_runningStudies = SUIT_Session::session()->activeApplication()->getNbStudies();
}