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_Server.cxx
25 // Author : Paul RASCLE, EDF
29 #include "Utils_ORB_INIT.hxx"
30 #include "Utils_SINGLETON.hxx"
31 #include "SALOME_NamingService.hxx"
36 #include <qapplication.h>
38 #include <qwaitcondition.h>
40 #include "SALOMEGUI_Application.h"
42 #include "QAD_MessageBox.h"
43 #include "QAD_Application.h"
44 #include "QAD_Settings.h"
45 #include "QAD_Config.h"
46 #include "QAD_Tools.h"
47 #include "QAD_ResourceMgr.h"
48 #include "Utils_SALOME_Exception.hxx"
49 #include "Utils_CorbaException.hxx"
50 #include "SALOMEGUI_QtCatchCorbaException.hxx"
51 #include "SALOME_Event.hxx"
53 #include <SALOMEconfig.h>
54 #include CORBA_SERVER_HEADER(SALOME_Session)
55 #include CORBA_SERVER_HEADER(SALOMEDS)
57 #include "utilities.h"
58 #include "LocalTraceCollector.hxx"
60 #include "SALOME_Session_i.hxx"
62 #include "Session_ServerLauncher.hxx"
64 extern "C" int HandleSignals(QApplication *theQApplication);
66 /*! - read arguments, define list of server to launch with their arguments.
67 * - wait for naming service
68 * - create and run a thread for launch of all servers
72 //! CORBA server for SALOME Session
74 * SALOME_Session Server launches a SALOME session servant.
75 * The servant registers to the Naming Service.
76 * See SALOME_Session.idl for interface specification.
78 * Main services offered by the servant are:
80 * - stop Session (must be idle)
87 static int MYDEBUG = 0;
89 static int MYDEBUG = 0;
92 int main(int argc, char **argv)
94 SALOME_Event::GetSessionThread();
95 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
97 CORBA::ORB_var &orb = init( orbArgc , argv ) ;
98 LocalTraceCollector *myThreadTrace = LocalTraceCollector::instance(orb);
101 CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
102 PortableServer::POA_var poa = PortableServer::POA::_narrow(obj);
104 PortableServer::POAManager_var pman = poa->the_POAManager() ;
106 INFOS("pman->activate()");
108 SALOME_NamingService *_NS = new SALOME_NamingService(orb);
110 // CORBA Servant Launcher
112 QWaitCondition _ServerLaunch;
113 _GUIMutex.lock(); // to block Launch server thread until wait(mutex)
115 Session_ServerLauncher* myServerLauncher
116 = new Session_ServerLauncher(argc, argv, orb, poa, &_GUIMutex, &_ServerLaunch);
117 myServerLauncher->start();
119 QApplication *_qappl = 0;
121 // Allow multiple activation/deactivation of GUI
123 MESSAGE("waiting wakeAll()");
124 _ServerLaunch.wait(&_GUIMutex); // to be reseased by Launch server thread when ready:
125 // atomic operation lock - unlock on mutex
126 // unlock mutex: serverThread runs, calls _ServerLaunch->wakeAll()
127 // this thread wakes up, and lock mutex
129 INFOS("Session activated, Launch IAPP...");
133 _qappl = new QApplication(qappArgc, argv );
135 INFOS("creation QApplication");
138 QAD_ASSERT ( QObject::connect(_qappl, SIGNAL(lastWindowClosed()), _qappl, SLOT(quit()) ) );
139 SALOMEGUI_Application* _mw = new SALOMEGUI_Application ( "MDTV-Standard", "HDF", "hdf" );
140 INFOS("creation SALOMEGUI_Application");
143 if ( !SALOMEGUI_Application::addToDesktop ( _mw, _NS ) ) {
144 QAD_MessageBox::error1 ( 0,
145 QObject::tr("ERR_ERROR"),
146 QObject::tr("ERR_APP_INITFAILED"),
147 QObject::tr("BUT_OK") );
150 QFileInfo prgInfo(argv[0]);
151 QDir prgDir(prgInfo.dirPath(true));
152 QAD_CONFIG->setPrgDir(prgDir); // CWD is program directory
153 QAD_CONFIG->createConfigFile(false); // Create config file
154 // ~/.tr(MEN_APPNAME)/tr(MEN_APPNAME).conf if there's none
155 QAD_CONFIG->readConfigFile(); // Read config file
157 _qappl->setPalette( QAD_Application::getPalette() );
159 /* Run 'SALOMEGUI' application */
160 QAD_Application::run();
162 // T2.12 - catch exceptions thrown on attempts to modified a locked study
166 MESSAGE("run(): starting the main event loop");
167 int _ret = HandleSignals(_qappl);
170 catch (SALOME::SALOME_Exception& e)
172 QtCatchCorbaException(e);
174 catch(SALOMEDS::StudyBuilder::LockProtection&)
176 INFOS("run(): An attempt to modify a locked study has not been handled by QAD_Operation");
177 QApplication::restoreOverrideCursor();
178 QAD_MessageBox::warn1 ( (QWidget*)QAD_Application::getDesktop(),
179 QObject::tr("WRN_WARNING"),
180 QObject::tr("WRN_STUDY_LOCKED"),
181 QObject::tr("BUT_OK") );
183 catch (const CORBA::Exception& e)
187 CORBA::TypeCode_var tc = tmp.type();
188 const char *p = tc->name();
189 INFOS ("run(): CORBA exception of the kind : "<<p<< " is caught");
191 QApplication::restoreOverrideCursor();
192 QAD_MessageBox::error1 ( (QWidget*)QAD_Application::getDesktop(),
193 QObject::tr("ERR_ERROR"),
194 QObject::tr("ERR_APP_EXCEPTION")
195 + QObject::tr(" CORBA exception ") + QObject::tr(p),
196 QObject::tr("BUT_OK") );
198 catch(std::exception& e)
200 INFOS("run(): An exception has been caught");
201 QApplication::restoreOverrideCursor();
202 QAD_MessageBox::error1 ( (QWidget*)QAD_Application::getDesktop(),
203 QObject::tr("ERR_ERROR"),
204 QObject::tr("ERR_APP_EXCEPTION")+ "\n" +QObject::tr(e.what()),
205 QObject::tr("BUT_OK") );
209 INFOS("run(): An exception has been caught");
210 QApplication::restoreOverrideCursor();
211 QAD_MessageBox::error1 ( (QWidget*)QAD_Application::getDesktop(),
212 QObject::tr("ERR_ERROR"),
213 QObject::tr("ERR_APP_EXCEPTION"),
214 QObject::tr("BUT_OK") );
217 QString confMsg = "Settings create "
218 + QAD_CONFIG->getConfigDir().absPath() + "/" + QObject::tr("MEN_APPNAME") + ".conf";
220 QAD_CONFIG->createConfigFile(true);
223 // Prepare _GUIMutex for a new GUI activation
228 myServerLauncher->KillAll();
230 catch (SALOME_Exception& e)
232 INFOS("run(): SALOME::SALOME_Exception is caught: "<<e.what());
234 catch (CORBA::SystemException& e)
236 INFOS("Caught CORBA::SystemException.");
238 catch (CORBA::Exception& e)
240 INFOS("Caught CORBA::Exception.");
243 CORBA::TypeCode_var tc = tmp.type();
244 const char *p = tc->name();
245 INFOS ("run(): CORBA exception of the kind : "<<p<< " is caught");
247 catch(std::exception& e)
249 INFOS("run(): An exception has been caught: " <<e.what());
253 INFOS("Caught unknown exception.");
255 MESSAGE("End of SALOME_Session_Server");
256 delete myThreadTrace;