1 // SALOME Container : implementation of container and engine for Kernel
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.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : SALOME_Container.cxx
25 // Author : Paul RASCLE, EDF - MARC TAJCHMAN, CEA
39 # include <sys/time.h>
49 #include "SALOME_Container_i.hxx"
50 #include "utilities.h"
51 #include "Utils_ORB_INIT.hxx"
52 #include "Utils_SINGLETON.hxx"
56 #include <Utils_Timer.hxx>
59 #include "Container_init_python.hxx"
63 extern "C" void HandleServerSideSignals(CORBA::ORB_ptr theORB);
67 #include <sys/types.h>
70 typedef void (*sighandler_t)(int);
71 sighandler_t setsig(int sig, sighandler_t handler)
73 struct sigaction context, ocontext;
74 context.sa_handler = handler;
75 sigemptyset(&context.sa_mask);
77 if (sigaction(sig, &context, &ocontext) == -1)
79 return ocontext.sa_handler;
84 if(getenv ("DEBUGGER"))
86 std::stringstream exec;
87 exec << "$DEBUGGER SALOME_Container " << getpid() << "&";
88 std::cerr << exec.str() << std::endl;
89 system(exec.str().c_str());
94 void Handler(int theSigId)
96 std::cerr << "SIGSEGV: " << std::endl;
98 //to exit or not to exit
102 void terminateHandler(void)
104 std::cerr << "Terminate: not managed exception !" << std::endl;
108 void unexpectedHandler(void)
110 std::cerr << "Unexpected: unexpected exception !" << std::endl;
114 int main(int argc, char* argv[])
117 MPI_Init(&argc,&argv);
120 if(getenv ("DEBUGGER"))
122 setsig(SIGSEGV,&Handler);
123 set_terminate(&terminateHandler);
124 set_unexpected(&unexpectedHandler);
127 // Initialise the ORB.
128 //SRN: BugID: IPAL9541, it's necessary to set a size of one message to be at least 100Mb
129 //CORBA::ORB_var orb = CORBA::ORB_init( argc , argv ) ;
130 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
131 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
132 CORBA::ORB_ptr orb = init(argc , argv ) ;
134 // LocalTraceCollector *myThreadTrace = SALOMETraceCollector::instance(orb);
140 bool isSupervContainer = false;
141 if (strcmp(argv[1],"SuperVisionContainer") == 0) isSupervContainer = true;
143 if (!isSupervContainer)
146 char* _argv[] = {""};
147 KERNEL_PYTHON::init_python(argc,argv);
152 PySys_SetArgv( argc , argv ) ;
155 char *containerName = "";
158 containerName = argv[1] ;
163 CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
164 ASSERT(!CORBA::is_nil(obj));
165 PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj);
167 PortableServer::POAManager_var pman = root_poa->the_POAManager();
169 // add new container to the kill list
171 stringstream aCommand ;
172 aCommand << "addToKillList.py " << getpid() << " SALOME_Container" << ends ;
173 system(aCommand.str().c_str());
176 Engines_Container_i * myContainer
177 = new Engines_Container_i(orb, root_poa, containerName , argc , argv );
185 timer.ShowAbsolute();
188 HandleServerSideSignals(orb);
190 if (!isSupervContainer)
192 PyGILState_STATE gstate = PyGILState_Ensure();
193 //Delete python container that destroy orb from python (pyCont._orb.destroy())
201 catch(CORBA::SystemException&)
203 INFOS("Caught CORBA::SystemException.");
205 catch(PortableServer::POA::ServantAlreadyActive&)
207 INFOS("Caught CORBA::ServantAlreadyActiveException");
209 catch(CORBA::Exception&)
211 INFOS("Caught CORBA::Exception.");
213 catch(std::exception& exc)
215 INFOS("Caught std::exception - "<<exc.what());
219 INFOS("Caught unknown exception.");
227 //LocalTraceBufferPool* bp1 = LocalTraceBufferPool::instance();
228 //bp1->deleteInstance(bp1);