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"
59 #include "SALOME_Session_i.hxx"
61 #include "Session_ServerLauncher.hxx"
63 extern "C" int HandleSignals(QApplication *theQApplication);
65 /*! - read arguments, define list of server to launch with their arguments.
66 * - wait for naming service
67 * - create and run a thread for launch of all servers
71 //! CORBA server for SALOME Session
73 * SALOME_Session Server launches a SALOME session servant.
74 * The servant registers to the Naming Service.
75 * See SALOME_Session.idl for interface specification.
77 * Main services offered by the servant are:
79 * - stop Session (must be idle)
86 static int MYDEBUG = 0;
88 static int MYDEBUG = 0;
91 int main(int argc, char **argv)
95 SALOME_Event::GetSessionThread();
97 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
98 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()) ;
100 CORBA::ORB_var &orb = init( orbArgc , argv ) ;
102 CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
103 PortableServer::POA_var poa = PortableServer::POA::_narrow(obj);
105 PortableServer::POAManager_var pman = poa->the_POAManager() ;
107 INFOS("pman->activate()");
109 SALOME_NamingService *_NS = new SALOME_NamingService(orb);
111 // CORBA Servant Launcher
113 QWaitCondition _ServerLaunch;
114 _GUIMutex.lock(); // to block Launch server thread until wait(mutex)
116 Session_ServerLauncher* myServerLauncher
117 = new Session_ServerLauncher(argc, argv, orb, poa, &_GUIMutex, &_ServerLaunch);
118 myServerLauncher->start();
120 QApplication *_qappl = 0;
122 // Allow multiple activation/deactivation of GUI
124 MESSAGE("waiting wakeAll()");
125 _ServerLaunch.wait(&_GUIMutex); // to be reseased by Launch server thread when ready:
126 // atomic operation lock - unlock on mutex
127 // unlock mutex: serverThread runs, calls _ServerLaunch->wakeAll()
128 // this thread wakes up, and lock mutex
130 INFOS("Session activated, Launch IAPP...");
134 _qappl = new QApplication(qappArgc, argv );
136 INFOS("creation QApplication");
139 QAD_ASSERT ( QObject::connect(_qappl, SIGNAL(lastWindowClosed()), _qappl, SLOT(quit()) ) );
140 SALOMEGUI_Application* _mw = new SALOMEGUI_Application ( "MDTV-Standard", "HDF", "hdf" );
141 INFOS("creation SALOMEGUI_Application");
144 if ( !SALOMEGUI_Application::addToDesktop ( _mw, _NS ) ) {
145 QAD_MessageBox::error1 ( 0,
146 QObject::tr("ERR_ERROR"),
147 QObject::tr("ERR_APP_INITFAILED"),
148 QObject::tr("BUT_OK") );
151 QFileInfo prgInfo(argv[0]);
152 QDir prgDir(prgInfo.dirPath(true));
153 QAD_CONFIG->setPrgDir(prgDir); // CWD is program directory
154 QAD_CONFIG->createConfigFile(false); // Create config file
155 // ~/.tr(MEN_APPNAME)/tr(MEN_APPNAME).conf if there's none
156 QAD_CONFIG->readConfigFile(); // Read config file
158 _qappl->setPalette( QAD_Application::getPalette() );
160 /* Run 'SALOMEGUI' application */
161 QAD_Application::run();
163 // T2.12 - catch exceptions thrown on attempts to modified a locked study
167 MESSAGE("run(): starting the main event loop");
168 int _ret = HandleSignals(_qappl);
171 catch (SALOME::SALOME_Exception& e)
173 QtCatchCorbaException(e);
175 catch(SALOMEDS::StudyBuilder::LockProtection&)
177 INFOS("run(): An attempt to modify a locked study has not been handled by QAD_Operation");
178 QApplication::restoreOverrideCursor();
179 QAD_MessageBox::warn1 ( (QWidget*)QAD_Application::getDesktop(),
180 QObject::tr("WRN_WARNING"),
181 QObject::tr("WRN_STUDY_LOCKED"),
182 QObject::tr("BUT_OK") );
184 catch (const CORBA::Exception& e)
188 CORBA::TypeCode_var tc = tmp.type();
189 const char *p = tc->name();
190 INFOS ("run(): CORBA exception of the kind : "<<p<< " is caught");
192 QApplication::restoreOverrideCursor();
193 QAD_MessageBox::error1 ( (QWidget*)QAD_Application::getDesktop(),
194 QObject::tr("ERR_ERROR"),
195 QObject::tr("ERR_APP_EXCEPTION")
196 + QObject::tr(" CORBA exception ") + QObject::tr(p),
197 QObject::tr("BUT_OK") );
199 catch(std::exception& e)
201 INFOS("run(): An exception has been caught");
202 QApplication::restoreOverrideCursor();
203 QAD_MessageBox::error1 ( (QWidget*)QAD_Application::getDesktop(),
204 QObject::tr("ERR_ERROR"),
205 QObject::tr("ERR_APP_EXCEPTION")+ "\n" +QObject::tr(e.what()),
206 QObject::tr("BUT_OK") );
210 INFOS("run(): An exception has been caught");
211 QApplication::restoreOverrideCursor();
212 QAD_MessageBox::error1 ( (QWidget*)QAD_Application::getDesktop(),
213 QObject::tr("ERR_ERROR"),
214 QObject::tr("ERR_APP_EXCEPTION"),
215 QObject::tr("BUT_OK") );
218 QString confMsg = "Settings create "
219 + QAD_CONFIG->getConfigDir().absPath() + "/" + QObject::tr("MEN_APPNAME") + ".conf";
221 QAD_CONFIG->createConfigFile(true);
224 // Prepare _GUIMutex for a new GUI activation
229 myServerLauncher->KillAll();
231 catch (SALOME_Exception& e)
233 INFOS("run(): SALOME::SALOME_Exception is caught: "<<e.what());
235 catch (CORBA::SystemException& e)
237 INFOS("Caught CORBA::SystemException.");
239 catch (CORBA::Exception& e)
241 INFOS("Caught CORBA::Exception.");
244 CORBA::TypeCode_var tc = tmp.type();
245 const char *p = tc->name();
246 INFOS ("run(): CORBA exception of the kind : "<<p<< " is caught");
248 catch(std::exception& e)
250 INFOS("run(): An exception has been caught: " <<e.what());
254 INFOS("Caught unknown exception.");