1 // SALOME ParallelContainerNodeDummy : launcher of a PaCO++ object
3 // Copyright (C) 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SALOME_ParallelContainerNodeDummy.cxx
25 // Author : André Ribes, EDF
26 // Module : SALOME PARALLEL
38 #include "SALOME_ParallelContainer_i.hxx"
40 #include <paco_omni.h>
41 #include <paco_dummy.h>
43 #include "SALOME_NamingService.hxx"
45 #include "utilities.h"
46 #include "Utils_ORB_INIT.hxx"
47 #include "Utils_SINGLETON.hxx"
48 #include "SALOMETraceCollector.hxx"
57 cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
58 cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
59 cerr << "SIGSEGV in :" << getpid() << endl;
60 cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
61 cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
66 typedef void (*sighandler_t)(int);
67 sighandler_t setsig(int sig, sighandler_t handler)
69 struct sigaction context, ocontext;
70 context.sa_handler = handler;
71 sigemptyset(&context.sa_mask);
73 if (sigaction(sig, &context, &ocontext) == -1)
75 return ocontext.sa_handler;
80 if(getenv ("DEBUGGER"))
82 std::stringstream exec;
83 exec << "$DEBUGGER SALOME_ParallelContainerNodeDummy " << getpid() << "&";
84 std::cerr << exec.str() << std::endl;
85 system(exec.str().c_str());
90 void Handler(int theSigId)
92 std::cerr << "SIGSEGV: " << std::endl;
94 //to exit or not to exit
98 void terminateHandler(void)
100 std::cerr << "Terminate: not managed exception !" << std::endl;
104 void unexpectedHandler(void)
106 std::cerr << "Unexpected: unexpected exception !" << std::endl;
110 int main(int argc, char* argv[])
112 INFOS("Launching a parallel container node");
114 if(getenv ("DEBUGGER"))
116 setsig(SIGSEGV,&Handler);
117 set_terminate(&terminateHandler);
118 set_unexpected(&unexpectedHandler);
121 // Initialise the ORB.
122 CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
124 std::string containerName("");
126 containerName = argv[1];
128 std::string hostname("");
134 CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
135 PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj);
136 PortableServer::POAManager_var pman = root_poa->the_POAManager();
139 // add this container to the kill list
141 sprintf(aCommand, "addToKillList.py %d SALOME_ParallelContainerNode", getpid());
145 SALOME_NamingService * ns = new SALOME_NamingService(CORBA::ORB::_duplicate(orb));
147 string proxyNameInNS = ns->BuildContainerNameForNS(containerName.c_str(),
149 obj = ns->Resolve(proxyNameInNS.c_str());
150 char * proxy_ior = orb->object_to_string(obj);
153 string node_name = containerName + "Node";
154 Engines_Parallel_Container_i * servant = new Engines_Parallel_Container_i(CORBA::ORB::_duplicate(orb),
158 (char*) node_name.c_str(),
161 paco_fabrique_manager * pfm = paco_getFabriqueManager();
162 pfm->register_com("dummy", new paco_dummy_fabrique());
163 pfm->register_thread("omni", new paco_omni_fabrique());
164 servant->setLibCom("dummy", servant);
165 servant->setLibThread("omni");
168 PortableServer::ObjectId * _id = root_poa->activate_object(servant);
169 servant->set_id(_id);
170 obj = root_poa->id_to_reference(*_id);
172 // In the NamingService
173 string hostname = GetHostname();
176 snprintf(buffer, 5, "%d", myid);
177 node_name = node_name + buffer;
178 string _containerName = ns->BuildContainerNameForNS((char*) node_name.c_str(),
180 cerr << "---------" << _containerName << "----------" << endl;
181 ns->Register(obj, _containerName.c_str());
185 catch (PaCO::PACO_Exception& e)
187 INFOS("Caught PaCO::PACO_Exception");
188 std::cerr << e << std::endl;
190 catch(CORBA::SystemException&)
192 INFOS("Caught CORBA::SystemException.");
194 catch(PortableServer::POA::ServantAlreadyActive&)
196 INFOS("Caught CORBA::ServantAlreadyActiveException");
198 catch(CORBA::Exception&)
200 INFOS("Caught CORBA::Exception.");
202 catch(std::exception& exc)
204 INFOS("Caught std::exception - "<<exc.what());
208 INFOS("Caught unknown exception.");