1 // SALOME Session : implementation of Session_ServerLauncher.cxx
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 : Session_ServerLauncher.xx
25 // Author : Paul RASCLE, EDF
29 #include "Session_ServerLauncher.hxx"
31 #include "Utils_SALOME_Exception.hxx"
32 #include "utilities.h"
34 //=============================================================================
36 * default constructor not for use
38 //=============================================================================
40 Session_ServerLauncher::Session_ServerLauncher()
42 ASSERT(0); // must not be called
45 //=============================================================================
49 //=============================================================================
51 Session_ServerLauncher::Session_ServerLauncher(int argc,
54 PortableServer::POA_ptr poa,
56 QWaitCondition *ServerLaunch)
60 _orb = CORBA::ORB::_duplicate(orb);
61 _root_poa = PortableServer::POA::_duplicate(poa);
63 _ServerLaunch = ServerLaunch;
66 //=============================================================================
70 //=============================================================================
72 Session_ServerLauncher::~Session_ServerLauncher()
76 //=============================================================================
78 * Check args and activate servers
80 //=============================================================================
82 void Session_ServerLauncher::run()
84 //MESSAGE("Session_ServerLauncher::run");
85 _GUIMutex->lock(); // lock released by calling thread when ready: wait(mutex)
86 //MESSAGE("Server Launcher thread free to go...");
92 _orb->run(); // this thread wait, during omniORB process events
95 //=============================================================================
97 * controls and dispatchs arguments given with command
99 //=============================================================================
101 void Session_ServerLauncher::CheckArgs()
104 ServArg aServArg(0,0,0);
105 _argCopy.reserve(_argc);
106 for (int iarg=0; iarg <_argc; iarg++)
110 _argCopy.push_back(_argv[iarg]);
113 case 0: // looking for "--with"
115 if (strcmp(_argv[iarg],"--with")==0)
119 case 1: // looking for server type
121 for (int i=0; i<Session_ServerThread::NB_SRV_TYP; i++)
122 if (strcmp(_argv[iarg],Session_ServerThread::_serverTypes[i])==0)
124 aServArg._servType = i;
130 case 2: // looking for "("
132 if (strcmp(_argv[iarg],"(")!=0)
134 INFOS("parenthesis '(' is required here...");
135 for (int i=0; i<iarg; i++)
136 cerr << _argv[i] << " ";
138 throw SALOME_Exception(LOCALIZED("Error in command arguments, missing prenthesis"));
142 aServArg._firstArg=iarg+1; // arg after '('
147 case 3: // looking for arguments
149 if (strcmp(_argv[iarg],")")==0) // end of arguments = ')'
151 aServArg._lastArg=iarg-1; // arg before ')'
152 MESSAGE("server : "<< Session_ServerThread::_serverTypes[aServArg._servType]);
153 for (int i=aServArg._firstArg; i<=aServArg._lastArg; i++)
154 MESSAGE(" arg : " << _argCopy[i]);
155 _argServToLaunch.push_back(aServArg);
168 throw SALOME_Exception(LOCALIZED("Error in command arguments, missing server type"));
170 throw SALOME_Exception(LOCALIZED("Error in command arguments, missing parenthesis '('"));
172 throw SALOME_Exception(LOCALIZED("Error in command arguments, missing parenthesis ')'"));
175 //=============================================================================
179 //=============================================================================
181 void Session_ServerLauncher::ActivateAll()
183 list<ServArg>::iterator itServ;
184 for (itServ = _argServToLaunch.begin(); itServ !=_argServToLaunch.end(); itServ++)
186 int argc = 2 + (*itServ)._lastArg - (*itServ)._firstArg;
187 char** argv = new char*[argc+1];
188 argv[argc]=0; // for Engines_Container_i constructor...
189 int servType = (*itServ)._servType;
190 argv[0]=strdup(Session_ServerThread::_serverTypes[servType]);
193 for (int i=0; i<argc-1; i++)
194 //argv[i+1] = _argCopy[(*itServ)._firstArg + i].c_str();
195 argv[i+1] = _argv[(*itServ)._firstArg + i];
198 std::cout << "*** activating [" << argc << "] : " << argv[0] << std::endl;
200 Session_ServerThread* aServerThread
201 = new Session_ServerThread(argc, argv, _orb,_root_poa,_GUIMutex);
202 _serverThreads.push_front(aServerThread);
204 aServerThread->Init();
207 // Always launch Session Server
210 char** argv = new char*[argc];
212 Session_SessionThread* aServerThread
213 = new Session_SessionThread(argc, argv, _orb,_root_poa,_GUIMutex,_ServerLaunch);
214 _serverThreads.push_front(aServerThread);
216 aServerThread->Init();
219 //=============================================================================
221 * Destruction des classes serveur dans l'ordre inverse de creation
223 //=============================================================================
225 void Session_ServerLauncher::KillAll()
227 MESSAGE("Session_ServerLauncher::KillAll()");
228 list<Session_ServerThread*>::reverse_iterator itServ;
229 for (itServ = _serverThreads.rbegin(); itServ !=_serverThreads.rend(); itServ++)