1 // Copyright (C) 2007-2021 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, or (at your option) any later version.
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 Container : implementation of container and engine for Kernel
24 // File : SALOME_Container.cxx
25 // Author : Paul RASCLE, EDF - MARC TAJCHMAN, CEA
29 #ifdef _MPI_SEQ_CONTAINER_
41 # include <sys/time.h>
51 #include "SALOME_Container_Common.hxx"
52 #include "SALOME_Container_i.hxx"
53 #include "utilities.h"
54 #include "Utils_ORB_INIT.hxx"
55 #include "Utils_SINGLETON.hxx"
59 #include <Utils_Timer.hxx>
62 #include "Container_init_python.hxx"
64 extern "C" void HandleServerSideSignals(CORBA::ORB_ptr theORB);
68 #include <sys/types.h>
70 # include <sys/wait.h>
75 void AttachDebugger();
77 void terminateHandler();
78 void unexpectedHandler();
81 void (* setsig(int, void (*)(int)))(int);
83 typedef void (*sighandler_t)(int);
84 sighandler_t setsig(int sig, sighandler_t handler)
86 struct sigaction context, ocontext;
87 context.sa_handler = handler;
88 sigemptyset(&context.sa_mask);
90 if (sigaction(sig, &context, &ocontext) == -1)
92 return ocontext.sa_handler;
99 if(getenv ("DEBUGGER"))
101 std::stringstream exec;
102 exec << "$DEBUGGER SALOME_Container " << getpid() << "&";
103 std::cerr << exec.str() << std::endl;
104 system(exec.str().c_str());
110 void Handler(int theSigId)
112 std::cerr << "Signal= "<< theSigId << std::endl;
114 //to exit or not to exit
118 void terminateHandler(void)
120 std::cerr << "Terminate: not managed exception !" << std::endl;
124 void unexpectedHandler(void)
126 std::cerr << "Unexpected: unexpected exception !" << std::endl;
130 int container_common_main(int argc, char* argv[], std::unique_ptr<SALOME_NamingService_Container_Abstract> ns)
132 #ifdef _MPI_SEQ_CONTAINER_
134 MPI_Init(&argc,&argv);
139 if(getenv ("DEBUGGER"))
141 setsig(SIGSEGV,&Handler);
142 setsig(SIGFPE,&Handler);
143 std::set_terminate(&terminateHandler);
144 std::set_unexpected(&unexpectedHandler);
148 // Initialise the ORB.
149 //SRN: BugID: IPAL9541, it's necessary to set a size of one message to be at least 100Mb
150 //CORBA::ORB_var orb = CORBA::ORB_init( argc , argv ) ;
151 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
152 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
153 CORBA::ORB_ptr orb = init(argc , argv ) ;
155 // LocalTraceCollector *myThreadTrace = SALOMETraceCollector::instance(orb);
162 KERNEL_PYTHON::init_python(argc,argv);
164 char *containerName = (char *)"";
167 containerName = argv[1] ;
172 CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
173 ASSERT(!CORBA::is_nil(obj));
174 PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj);
176 PortableServer::POAManager_var pman = root_poa->the_POAManager();
178 // add new container to the kill list
180 std::stringstream aCommand ;
181 aCommand << "addToKillList.py " << getpid() << " SALOME_Container" << std::ends ;
182 system(aCommand.str().c_str());
185 new Engines_Container_i(orb, root_poa, containerName , argc , argv, ns.get() );
194 timer.ShowAbsolute();
197 HandleServerSideSignals(orb);
199 //#define MEMORYLEAKS
202 //Destroy orb from python (for chasing memory leaks)
203 PyRun_SimpleString("from omniORB import CORBA");
204 PyRun_SimpleString("orb=CORBA.ORB_init([''], CORBA.ORB_ID)");
205 PyRun_SimpleString("orb.destroy()");
209 catch(CORBA::SystemException&)
211 INFOS("Caught CORBA::SystemException.");
213 catch(PortableServer::POA::ServantAlreadyActive&)
215 INFOS("Caught CORBA::ServantAlreadyActiveException");
217 catch(CORBA::Exception&)
219 INFOS("Caught CORBA::Exception.");
221 catch(std::exception& exc)
223 INFOS("Caught std::exception - "<<exc.what());
227 INFOS("Caught unknown exception.");
230 #ifdef _MPI_SEQ_CONTAINER_