1 // Copyright (C) 2007-2012 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
23 // SALOME Session : implementation of Session_ServerLauncher.cxx
24 // File : Session_ServerLauncher.xx
25 // Author : Paul RASCLE, EDF
27 #include "Session_ServerLauncher.hxx"
28 #include "Session_ServerThread.hxx"
30 #include "Utils_SALOME_Exception.hxx"
31 #include "utilities.h"
34 #include <QWaitCondition>
37 default constructor not for use
39 Session_ServerLauncher::Session_ServerLauncher()
41 ASSERT(0); // must not be called
47 Session_ServerLauncher::Session_ServerLauncher(int argc,
50 PortableServer::POA_ptr poa,
52 QWaitCondition *ServerLaunch,
54 QWaitCondition *SessionStarted)
58 _orb = CORBA::ORB::_duplicate(orb);
59 _root_poa = PortableServer::POA::_duplicate(poa);
61 _ServerLaunch = ServerLaunch;
62 _SessionMutex = SessionMutex;
63 _SessionStarted = SessionStarted;
72 Session_ServerLauncher::~Session_ServerLauncher()
77 Check args and activate servers
79 void Session_ServerLauncher::run()
81 // wait until main thread is ready
82 _GUIMutex->lock(); // ... lock mutex (it is unlocked my calling thread
83 // wait condition's wait(mutex)
84 _GUIMutex->unlock(); // ... and unlock it 'cause it is not more needed
87 _ServerLaunch->wakeAll();
92 // wait until main thread is ready
93 _GUIMutex->lock(); // ... lock mutex (it is unlocked my calling thread
94 // wait condition's wait(mutex)
95 _GUIMutex->unlock(); // ... and unlock it 'cause it is not more needed
98 _ServerLaunch->wakeAll();
101 //_orb->run(); // No need to call orb->run() : it waits on a lock. Qt is already waiting in the mainloop.
105 controls and dispatchs arguments given with command
107 void Session_ServerLauncher::CheckArgs()
110 ServArg aServArg(0,0,0);
111 _argCopy.reserve(_argc);
112 for (int iarg=0; iarg <_argc; iarg++)
116 _argCopy.push_back(_argv[iarg]);
119 case 0: // looking for "--with"
121 if (strcmp(_argv[iarg],"--with")==0)
125 case 1: // looking for server type
127 // Temporary solution
128 // Issue 21337 - no more SalomeApp_Engine_i activation here
129 // TODO: To be removed as soon as any trace of SalomeAppEngine
130 // has been eliminated from KERNEL scripts
131 if (strcmp(_argv[iarg], "SalomeAppEngine")==0){
133 iarg += 2; // skipping "()"
136 // Temporary solution
138 for (int i=0; i<Session_ServerThread::NB_SRV_TYP; i++)
139 if (strcmp(_argv[iarg],Session_ServerThread::_serverTypes[i])==0)
141 aServArg._servType = i;
147 case 2: // looking for "("
149 if (strcmp(_argv[iarg],"(")!=0)
151 INFOS("parenthesis '(' is required here...");
152 for (int i=0; i<iarg; i++)
153 std::cerr << _argv[i] << " ";
154 std::cerr << std::endl;
155 throw SALOME_Exception(LOCALIZED("Error in command arguments, missing prenthesis"));
159 aServArg._firstArg=iarg+1; // arg after '('
164 case 3: // looking for arguments
166 if (strcmp(_argv[iarg],")")==0) // end of arguments = ')'
168 aServArg._lastArg=iarg-1; // arg before ')'
169 MESSAGE("server : "<< Session_ServerThread::_serverTypes[aServArg._servType]);
170 for (int i=aServArg._firstArg; i<=aServArg._lastArg; i++)
171 MESSAGE(" arg : " << _argCopy[i]);
172 _argServToLaunch.push_back(aServArg);
185 throw SALOME_Exception(LOCALIZED("Error in command arguments, missing server type"));
187 throw SALOME_Exception(LOCALIZED("Error in command arguments, missing parenthesis '('"));
189 throw SALOME_Exception(LOCALIZED("Error in command arguments, missing parenthesis ')'"));
192 void Session_ServerLauncher::ActivateAll()
194 std::list<ServArg>::iterator itServ;
195 for (itServ = _argServToLaunch.begin(); itServ !=_argServToLaunch.end(); itServ++)
197 int argc = 2 + (*itServ)._lastArg - (*itServ)._firstArg;
198 char** argv = new char*[argc+1];
199 argv[argc]=0; // for Engines_Container_i constructor...
200 int servType = (*itServ)._servType;
201 argv[0]=strdup(Session_ServerThread::_serverTypes[servType]);
204 for (int i=0; i<argc-1; i++)
205 //argv[i+1] = _argCopy[(*itServ)._firstArg + i].c_str();
206 argv[i+1] = _argv[(*itServ)._firstArg + i];
209 MESSAGE("*** activating [" << argc << "] : " << argv[0]);
211 Session_ServerThread* aServerThread
212 = new Session_ServerThread(argc, argv, _orb,_root_poa);
213 _serverThreads.push_front(aServerThread);
215 aServerThread->Init();
220 // Always launch Session Server
221 MESSAGE("*** activating [ SESSION ] ");
224 char** argv = new char*[argc];
225 argv[0] = (char*)"Session";
226 Session_SessionThread* aServerThread
227 = new Session_SessionThread(argc, argv, _orb,_root_poa,_SessionMutex,_SessionStarted);
228 _serverThreads.push_front(aServerThread);
229 aServerThread->Init();
233 void Session_ServerLauncher::ShutdownAll()
235 MESSAGE("Session_ServerLauncher::ShutdownAll()");
236 std::list<Session_ServerThread*>::reverse_iterator itServ;
237 for (itServ = _serverThreads.rbegin(); itServ !=_serverThreads.rend(); itServ++)
239 (*itServ)->Shutdown();
244 Destruction des classes serveur dans l'ordre inverse de creation
246 void Session_ServerLauncher::KillAll()
248 MESSAGE("Session_ServerLauncher::KillAll()");
249 std::list<Session_ServerThread*>::reverse_iterator itServ;
250 for (itServ = _serverThreads.rbegin(); itServ !=_serverThreads.rend(); itServ++)