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 ParallelContainerNodeDummy : launcher of a PaCO++ object
23 // File : SALOME_ParallelContainerNodeDummy.cxx
24 // Author : André Ribes, EDF
25 // Module : SALOME PARALLEL
37 #include "SALOME_ParallelContainer_i.hxx"
39 #include <paco_omni.h>
40 #include <paco_dummy.h>
42 #include "SALOME_NamingService.hxx"
44 #include "utilities.h"
45 #include "Basics_Utils.hxx"
46 #include "Utils_ORB_INIT.hxx"
47 #include "Utils_SINGLETON.hxx"
48 #include "SALOMETraceCollector.hxx"
51 #include "Container_init_python.hxx"
59 cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
60 cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
61 cerr << "SIGSEGV in :" << getpid() << endl;
62 cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
63 cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
68 typedef void (*sighandler_t)(int);
69 sighandler_t setsig(int sig, sighandler_t handler)
71 struct sigaction context, ocontext;
72 context.sa_handler = handler;
73 sigemptyset(&context.sa_mask);
75 if (sigaction(sig, &context, &ocontext) == -1)
77 return ocontext.sa_handler;
82 if(getenv ("DEBUGGER"))
84 std::stringstream exec;
85 exec << "$DEBUGGER SALOME_ParallelContainerNodeDummy " << getpid() << "&";
86 std::cerr << exec.str() << std::endl;
87 system(exec.str().c_str());
92 void Handler(int theSigId)
94 std::cerr << "SIGSEGV: " << std::endl;
96 //to exit or not to exit
100 void terminateHandler(void)
102 std::cerr << "Terminate: not managed exception !" << std::endl;
106 void unexpectedHandler(void)
108 std::cerr << "Unexpected: unexpected exception !" << std::endl;
112 int main(int argc, char* argv[])
114 INFOS("Launching a parallel container node");
116 if(getenv ("DEBUGGER"))
118 setsig(SIGSEGV,&Handler);
119 set_terminate(&terminateHandler);
120 set_unexpected(&unexpectedHandler);
123 // Initialise the ORB.
124 CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
125 KERNEL_PYTHON::init_python(argc,argv);
127 std::string containerName("");
129 containerName = argv[1];
131 std::string proxy_hostname("");
133 proxy_hostname = argv[3];
137 sscanf(argv[4],"%d",&myid);
140 CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
141 PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj);
142 PortableServer::POAManager_var pman = root_poa->the_POAManager();
145 // add this container to the kill list
147 sprintf(aCommand, "addToKillList.py %d SALOME_ParallelContainerNode", getpid());
151 SALOME_NamingService * ns = new SALOME_NamingService(orb);
153 string proxyNameInNS = ns->BuildContainerNameForNS(containerName.c_str(),
154 proxy_hostname.c_str());
155 obj = ns->Resolve(proxyNameInNS.c_str());
156 char * proxy_ior = orb->object_to_string(obj);
159 string node_name = containerName + "Node";
160 Engines_Parallel_Container_i * servant = new Engines_Parallel_Container_i(CORBA::ORB::_duplicate(orb),
166 paco_fabrique_manager * pfm = paco_getFabriqueManager();
167 pfm->register_com("dummy", new paco_dummy_fabrique());
168 pfm->register_thread("omni", new paco_omni_fabrique());
169 servant->setLibCom("dummy", servant);
170 servant->setLibThread("omni");
173 obj = servant->_this();
175 // In the NamingService
176 string hostname = Kernel_Utils::GetHostname();
178 snprintf(buffer, 5, "%d", myid);
179 node_name = node_name + buffer;
180 string _containerName = ns->BuildContainerNameForNS((char*) node_name.c_str(),
182 cerr << "---------" << _containerName << "----------" << endl;
183 ns->Register(obj, _containerName.c_str());
187 //Delete python container that destroy orb from python (pyCont._orb.destroy())
189 CORBA::string_free(proxy_ior);
192 catch (PaCO::PACO_Exception& e)
194 INFOS("Caught PaCO::PACO_Exception");
195 std::cerr << e << std::endl;
197 catch(CORBA::SystemException&)
199 INFOS("Caught CORBA::SystemException.");
201 catch(PortableServer::POA::ServantAlreadyActive&)
203 INFOS("Caught CORBA::ServantAlreadyActiveException");
205 catch(CORBA::Exception&)
207 INFOS("Caught CORBA::Exception.");
209 catch(omniORB::fatalException& fe)
211 INFOS("Caught omniORB::fatalException:");
212 INFOS(" file: " << fe.file());
213 INFOS(" line: " << fe.line());
214 INFOS(" mesg: " << fe.errmsg());
216 catch(std::exception& exc)
218 INFOS("Caught std::exception - "<<exc.what());
222 INFOS("Caught unknown exception.");