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>
69 # include <sys/wait.h>
73 typedef void (*sighandler_t)(int);
74 sighandler_t setsig(int sig, sighandler_t handler)
76 struct sigaction context, ocontext;
77 context.sa_handler = handler;
78 sigemptyset(&context.sa_mask);
80 if (sigaction(sig, &context, &ocontext) == -1)
82 return ocontext.sa_handler;
89 if(getenv ("DEBUGGER"))
91 std::stringstream exec;
92 exec << "$DEBUGGER SALOME_Container " << getpid() << "&";
93 std::cerr << exec.str() << std::endl;
94 system(exec.str().c_str());
100 void Handler(int theSigId)
102 std::cerr << "SIGSEGV: " << std::endl;
104 //to exit or not to exit
108 void terminateHandler(void)
110 std::cerr << "Terminate: not managed exception !" << std::endl;
114 void unexpectedHandler(void)
116 std::cerr << "Unexpected: unexpected exception !" << std::endl;
120 int main(int argc, char* argv[])
123 MPI_Init(&argc,&argv);
127 if(getenv ("DEBUGGER"))
129 setsig(SIGSEGV,&Handler);
130 set_terminate(&terminateHandler);
131 set_unexpected(&unexpectedHandler);
135 // Initialise the ORB.
136 //SRN: BugID: IPAL9541, it's necessary to set a size of one message to be at least 100Mb
137 //CORBA::ORB_var orb = CORBA::ORB_init( argc , argv ) ;
138 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
139 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
140 CORBA::ORB_ptr orb = init(argc , argv ) ;
142 // LocalTraceCollector *myThreadTrace = SALOMETraceCollector::instance(orb);
148 bool isSupervContainer = false;
149 if (strcmp(argv[1],"SuperVisionContainer") == 0) isSupervContainer = true;
151 if (!isSupervContainer)
154 // char* _argv[] = {""};
155 KERNEL_PYTHON::init_python(argc,argv);
160 PySys_SetArgv( argc , argv ) ;
163 char *containerName = (char *)"";
166 containerName = argv[1] ;
171 CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
172 ASSERT(!CORBA::is_nil(obj));
173 PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj);
175 PortableServer::POAManager_var pman = root_poa->the_POAManager();
177 // add new container to the kill list
179 stringstream aCommand ;
180 aCommand << "addToKillList.py " << getpid() << " SALOME_Container" << ends ;
181 system(aCommand.str().c_str());
184 new Engines_Container_i(orb, root_poa, containerName , argc , argv );
192 timer.ShowAbsolute();
195 HandleServerSideSignals(orb);
197 if (!isSupervContainer)
200 //Delete python container that destroy orb from python (pyCont._orb.destroy())
208 catch(CORBA::SystemException&)
210 INFOS("Caught CORBA::SystemException.");
212 catch(PortableServer::POA::ServantAlreadyActive&)
214 INFOS("Caught CORBA::ServantAlreadyActiveException");
216 catch(CORBA::Exception&)
218 INFOS("Caught CORBA::Exception.");
220 catch(std::exception& exc)
222 INFOS("Caught std::exception - "<<exc.what());
226 INFOS("Caught unknown exception.");
234 //LocalTraceBufferPool* bp1 = LocalTraceBufferPool::instance();
235 //bp1->deleteInstance(bp1);