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
38 # include <sys/time.h>
48 #include "SALOME_Container_i.hxx"
49 #include "utilities.h"
50 #include "Utils_ORB_INIT.hxx"
51 #include "Utils_SINGLETON.hxx"
55 #include <Utils_Timer.hxx>
58 #include "Container_init_python.hxx"
62 extern "C" void HandleServerSideSignals(CORBA::ORB_ptr theORB);
66 #include <sys/types.h>
68 # include <sys/wait.h>
72 typedef void (*sighandler_t)(int);
73 sighandler_t setsig(int sig, sighandler_t handler)
75 struct sigaction context, ocontext;
76 context.sa_handler = handler;
77 sigemptyset(&context.sa_mask);
79 if (sigaction(sig, &context, &ocontext) == -1)
81 return ocontext.sa_handler;
88 if(getenv ("DEBUGGER"))
90 std::stringstream exec;
91 exec << "$DEBUGGER SALOME_Container " << getpid() << "&";
92 std::cerr << exec.str() << std::endl;
93 system(exec.str().c_str());
99 void Handler(int theSigId)
101 std::cerr << "SIGSEGV: " << std::endl;
103 //to exit or not to exit
107 void terminateHandler(void)
109 std::cerr << "Terminate: not managed exception !" << std::endl;
113 void unexpectedHandler(void)
115 std::cerr << "Unexpected: unexpected exception !" << std::endl;
119 int main(int argc, char* argv[])
122 MPI_Init(&argc,&argv);
126 if(getenv ("DEBUGGER"))
128 setsig(SIGSEGV,&Handler);
129 set_terminate(&terminateHandler);
130 set_unexpected(&unexpectedHandler);
134 // Initialise the ORB.
135 //SRN: BugID: IPAL9541, it's necessary to set a size of one message to be at least 100Mb
136 //CORBA::ORB_var orb = CORBA::ORB_init( argc , argv ) ;
137 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
138 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
139 CORBA::ORB_ptr orb = init(argc , argv ) ;
141 // LocalTraceCollector *myThreadTrace = SALOMETraceCollector::instance(orb);
147 bool isSupervContainer = false;
148 if (strcmp(argv[1],"SuperVisionContainer") == 0) isSupervContainer = true;
150 if (!isSupervContainer)
153 // char* _argv[] = {""};
154 KERNEL_PYTHON::init_python(argc,argv);
159 PySys_SetArgv( argc , argv ) ;
162 char *containerName = (char *)"";
165 containerName = argv[1] ;
170 CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
171 ASSERT(!CORBA::is_nil(obj));
172 PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj);
174 PortableServer::POAManager_var pman = root_poa->the_POAManager();
176 // add new container to the kill list
178 stringstream aCommand ;
179 aCommand << "addToKillList.py " << getpid() << " SALOME_Container" << ends ;
180 system(aCommand.str().c_str());
183 new Engines_Container_i(orb, root_poa, containerName , argc , argv );
191 timer.ShowAbsolute();
194 HandleServerSideSignals(orb);
196 if (!isSupervContainer)
199 //Delete python container that destroy orb from python (pyCont._orb.destroy())
207 catch(CORBA::SystemException&)
209 INFOS("Caught CORBA::SystemException.");
211 catch(PortableServer::POA::ServantAlreadyActive&)
213 INFOS("Caught CORBA::ServantAlreadyActiveException");
215 catch(CORBA::Exception&)
217 INFOS("Caught CORBA::Exception.");
219 catch(std::exception& exc)
221 INFOS("Caught std::exception - "<<exc.what());
225 INFOS("Caught unknown exception.");
233 //LocalTraceBufferPool* bp1 = LocalTraceBufferPool::instance();
234 //bp1->deleteInstance(bp1);