1 // Copyright (C) 2007-2008 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
22 // SALOME Container : implementation of container and engine for Kernel
23 // File : SALOME_Container.cxx
24 // Author : Paul RASCLE, EDF - MARC TAJCHMAN, CEA
28 #ifdef _MPI_SEQ_CONTAINER_
40 # include <sys/time.h>
50 #include "SALOME_Container_i.hxx"
51 #include "utilities.h"
52 #include "Utils_ORB_INIT.hxx"
53 #include "Utils_SINGLETON.hxx"
57 #include <Utils_Timer.hxx>
60 #include "Container_init_python.hxx"
64 extern "C" void HandleServerSideSignals(CORBA::ORB_ptr theORB);
68 #include <sys/types.h>
70 # include <sys/wait.h>
73 void AttachDebugger();
75 void terminateHandler();
76 void unexpectedHandler();
79 void (* setsig(int, void (*)(int)))(int);
81 typedef void (*sighandler_t)(int);
82 sighandler_t setsig(int sig, sighandler_t handler)
84 struct sigaction context, ocontext;
85 context.sa_handler = handler;
86 sigemptyset(&context.sa_mask);
88 if (sigaction(sig, &context, &ocontext) == -1)
90 return ocontext.sa_handler;
97 if(getenv ("DEBUGGER"))
99 std::stringstream exec;
100 exec << "$DEBUGGER SALOME_Container " << getpid() << "&";
101 std::cerr << exec.str() << std::endl;
102 system(exec.str().c_str());
108 void Handler(int theSigId)
110 std::cerr << "SIGSEGV: " << std::endl;
112 //to exit or not to exit
116 void terminateHandler(void)
118 std::cerr << "Terminate: not managed exception !" << std::endl;
122 void unexpectedHandler(void)
124 std::cerr << "Unexpected: unexpected exception !" << std::endl;
128 int main(int argc, char* argv[])
130 #ifdef _MPI_SEQ_CONTAINER_
132 MPI_Init(&argc,&argv);
137 if(getenv ("DEBUGGER"))
139 setsig(SIGSEGV,&Handler);
140 set_terminate(&terminateHandler);
141 set_unexpected(&unexpectedHandler);
145 // Initialise the ORB.
146 //SRN: BugID: IPAL9541, it's necessary to set a size of one message to be at least 100Mb
147 //CORBA::ORB_var orb = CORBA::ORB_init( argc , argv ) ;
148 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
149 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
150 CORBA::ORB_ptr orb = init(argc , argv ) ;
152 // LocalTraceCollector *myThreadTrace = SALOMETraceCollector::instance(orb);
158 bool isSupervContainer = false;
159 if (strcmp(argv[1],"SuperVisionContainer") == 0) isSupervContainer = true;
161 if (!isSupervContainer)
164 // char* _argv[] = {""};
165 KERNEL_PYTHON::init_python(argc,argv);
170 PySys_SetArgv( argc , argv ) ;
173 char *containerName = (char *)"";
176 containerName = argv[1] ;
181 CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
182 ASSERT(!CORBA::is_nil(obj));
183 PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj);
185 PortableServer::POAManager_var pman = root_poa->the_POAManager();
187 // add new container to the kill list
189 stringstream aCommand ;
190 aCommand << "addToKillList.py " << getpid() << " SALOME_Container" << ends ;
191 system(aCommand.str().c_str());
194 new Engines_Container_i(orb, root_poa, containerName , argc , argv );
202 timer.ShowAbsolute();
205 HandleServerSideSignals(orb);
207 if (!isSupervContainer)
210 //Destroy orb from python (for chasing memory leaks)
211 //PyRun_SimpleString("from omniORB import CORBA");
212 //PyRun_SimpleString("orb=CORBA.ORB_init([''], CORBA.ORB_ID)");
213 //PyRun_SimpleString("orb.destroy()");
221 catch(CORBA::SystemException&)
223 INFOS("Caught CORBA::SystemException.");
225 catch(PortableServer::POA::ServantAlreadyActive&)
227 INFOS("Caught CORBA::ServantAlreadyActiveException");
229 catch(CORBA::Exception&)
231 INFOS("Caught CORBA::Exception.");
233 catch(std::exception& exc)
235 INFOS("Caught std::exception - "<<exc.what());
239 INFOS("Caught unknown exception.");
242 #ifdef _MPI_SEQ_CONTAINER_