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"
37 #include <qapplication.h>
39 #include <qwaitcondition.h>
41 #include "SALOMEGUI_Application.h"
43 #include "QAD_MessageBox.h"
44 #include "QAD_Application.h"
45 #include "QAD_Settings.h"
46 #include "QAD_Config.h"
47 #include "QAD_Tools.h"
48 #include "QAD_ResourceMgr.h"
49 #include "Utils_CatchSignals.h"
50 #include "Utils_SALOME_Exception.hxx"
51 #include "Utils_CorbaException.hxx"
52 #include "SALOMEGUI_QtCatchCorbaException.hxx"
55 #include <SALOMEconfig.h>
56 #include CORBA_SERVER_HEADER(SALOME_Session)
57 #include CORBA_SERVER_HEADER(SALOMEDS)
59 #include "utilities.h"
61 #include "SALOME_Session_i.hxx"
63 #include "Session_ServerLauncher.hxx"
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 // ----------------------------------------------------------------------------
75 // ----------------------------------------------------------------------------
77 //! CORBA server for SALOME Session
79 * SALOME_Session Server launches a SALOME session servant.
80 * The servant registers to the Naming Service.
81 * See SALOME_Session.idl for interface specification.
83 * Main services offered by the servant are:
85 * - stop Session (must be idle)
89 int main(int argc, char **argv)
93 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
94 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()) ;
96 CORBA::ORB_var &orb = init( orbArgc , argv ) ;
98 CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
99 PortableServer::POA_var poa = PortableServer::POA::_narrow(obj);
101 PortableServer::POAManager_var pman = poa->the_POAManager() ;
103 INFOS("pman->activate()");
105 SALOME_NamingService *_NS = new SALOME_NamingService(orb);
107 Utils_CatchSignals aCatch;
110 // 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 MESSAGE("waiting wakeAll()");
121 _ServerLaunch.wait(&_GUIMutex); // to be reseased by Launch server thread when ready:
122 // atomic operation lock - unlock on mutex
123 // unlock mutex: serverThread runs, calls _ServerLaunch->wakeAll()
124 // this thread wakes up, and lock mutex
126 INFOS("Session activated, Launch IAPP...");
129 QApplication *_qappl = new QApplication(qappArgc, argv );
130 INFOS("creation QApplication");
133 QAD_ASSERT ( QObject::connect(_qappl, SIGNAL(lastWindowClosed()), _qappl, SLOT(quit()) ) );
134 SALOMEGUI_Application* _mw = new SALOMEGUI_Application ( "MDTV-Standard", "HDF", "hdf" );
135 INFOS("creation SALOMEGUI_Application");
138 if ( !SALOMEGUI_Application::addToDesktop ( _mw, _NS ) )
140 QAD_MessageBox::error1 ( 0,
141 QObject::tr("ERR_ERROR"),
142 QObject::tr("ERR_APP_INITFAILED"),
143 QObject::tr("BUT_OK") );
148 QFileInfo prgInfo(argv[0]);
149 QDir prgDir(prgInfo.dirPath(true));
150 QAD_CONFIG->setPrgDir(prgDir); // CWD is program directory
151 QAD_CONFIG->createConfigFile(false); // Create config file
152 // ~/.tr(MEN_APPNAME)/tr(MEN_APPNAME).conf if there's none
153 QAD_CONFIG->readConfigFile(); // Read config file
155 _qappl->setPalette( QAD_Application::getPalette() );
157 //Utils_CatchSignals aCatch;
160 /* Run 'SALOMEGUI' application */
161 QAD_Application::run();
163 // T2.12 - catch exceptions thrown on attempts to modified a locked study
168 MESSAGE("run(): starting the main event loop");
169 int _ret = _qappl->exec();
172 catch (SALOME::SALOME_Exception& e)
174 QtCatchCorbaException(e);
176 catch(SALOMEDS::StudyBuilder::LockProtection&)
178 INFOS("run(): An attempt to modify a locked study has not been handled by QAD_Operation");
179 QApplication::restoreOverrideCursor();
180 QAD_MessageBox::warn1 ( (QWidget*)QAD_Application::getDesktop(),
181 QObject::tr("WRN_WARNING"),
182 QObject::tr("WRN_STUDY_LOCKED"),
183 QObject::tr("BUT_OK") );
185 catch (const CORBA::Exception& e)
189 CORBA::TypeCode_var tc = tmp.type();
190 const char *p = tc->name();
191 INFOS ("run(): CORBA exception of the kind : "<<p<< " is caught");
193 QApplication::restoreOverrideCursor();
194 QAD_MessageBox::error1 ( (QWidget*)QAD_Application::getDesktop(),
195 QObject::tr("ERR_ERROR"),
196 QObject::tr("ERR_APP_EXCEPTION")
197 + QObject::tr(" CORBA exception ") + QObject::tr(p),
198 QObject::tr("BUT_OK") );
200 catch(std::exception& e)
202 INFOS("run(): An exception has been caught");
203 QApplication::restoreOverrideCursor();
204 QAD_MessageBox::error1 ( (QWidget*)QAD_Application::getDesktop(),
205 QObject::tr("ERR_ERROR"),
206 QObject::tr("ERR_APP_EXCEPTION")+ " " +QObject::tr(e.what()),
207 QObject::tr("BUT_OK") );
211 INFOS("run(): An exception has been caught");
212 QApplication::restoreOverrideCursor();
213 QAD_MessageBox::error1 ( (QWidget*)QAD_Application::getDesktop(),
214 QObject::tr("ERR_ERROR"),
215 QObject::tr("ERR_APP_EXCEPTION"),
216 QObject::tr("BUT_OK") );
219 //aCatch.Deactivate();
220 QString confMsg = "Settings create $HOME/."
221 + QObject::tr("MEN_APPNAME") + "/" + QObject::tr("MEN_APPNAME") + ".conf";
223 QAD_CONFIG->createConfigFile(true);
226 myServerLauncher->KillAll();
229 catch (SALOME_Exception& e)
231 INFOS("run(): SALOME::SALOME_Exception is caught: "<<e.what());
233 catch (CORBA::SystemException& e)
235 INFOS("Caught CORBA::SystemException.");
237 catch (CORBA::Exception& e)
239 INFOS("Caught CORBA::Exception.");
242 CORBA::TypeCode_var tc = tmp.type();
243 const char *p = tc->name();
244 INFOS ("run(): CORBA exception of the kind : "<<p<< " is caught");
246 catch(std::exception& e)
248 INFOS("run(): An exception has been caught: " <<e.what());
252 INFOS("Caught unknown exception.");
254 MESSAGE("End of SALOME_Session_Server");