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 "Utils_ORB_INIT.hxx"
46 #include "Utils_SINGLETON.hxx"
47 #include "SALOMETraceCollector.hxx"
56 cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
57 cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
58 cerr << "SIGSEGV in :" << getpid() << endl;
59 cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
60 cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
65 typedef void (*sighandler_t)(int);
66 sighandler_t setsig(int sig, sighandler_t handler)
68 struct sigaction context, ocontext;
69 context.sa_handler = handler;
70 sigemptyset(&context.sa_mask);
72 if (sigaction(sig, &context, &ocontext) == -1)
74 return ocontext.sa_handler;
79 if(getenv ("DEBUGGER"))
81 std::stringstream exec;
82 exec << "$DEBUGGER SALOME_ParallelContainerNodeDummy " << getpid() << "&";
83 std::cerr << exec.str() << std::endl;
84 system(exec.str().c_str());
89 void Handler(int theSigId)
91 std::cerr << "SIGSEGV: " << std::endl;
93 //to exit or not to exit
97 void terminateHandler(void)
99 std::cerr << "Terminate: not managed exception !" << std::endl;
103 void unexpectedHandler(void)
105 std::cerr << "Unexpected: unexpected exception !" << std::endl;
109 int main(int argc, char* argv[])
111 INFOS("Launching a parallel container node");
113 if(getenv ("DEBUGGER"))
115 setsig(SIGSEGV,&Handler);
116 set_terminate(&terminateHandler);
117 set_unexpected(&unexpectedHandler);
120 // Initialise the ORB.
121 CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
123 std::string containerName("");
125 containerName = argv[1];
127 std::string hostname("");
133 CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
134 PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj);
135 PortableServer::POAManager_var pman = root_poa->the_POAManager();
138 // add this container to the kill list
140 sprintf(aCommand, "addToKillList.py %d SALOME_ParallelContainerNode", getpid());
144 SALOME_NamingService * ns = new SALOME_NamingService(CORBA::ORB::_duplicate(orb));
146 string proxyNameInNS = ns->BuildContainerNameForNS(containerName.c_str(),
148 obj = ns->Resolve(proxyNameInNS.c_str());
149 char * proxy_ior = orb->object_to_string(obj);
152 string node_name = containerName + "Node";
153 Engines_Parallel_Container_i * servant = new Engines_Parallel_Container_i(CORBA::ORB::_duplicate(orb),
157 (char*) node_name.c_str(),
160 paco_fabrique_manager * pfm = paco_getFabriqueManager();
161 pfm->register_com("dummy", new paco_dummy_fabrique());
162 pfm->register_thread("omni", new paco_omni_fabrique());
163 servant->setLibCom("dummy", servant);
164 servant->setLibThread("omni");
167 PortableServer::ObjectId * _id = root_poa->activate_object(servant);
168 servant->set_id(_id);
169 obj = root_poa->id_to_reference(*_id);
171 // In the NamingService
172 string hostname = Kernel_Utils::GetHostname();
175 snprintf(buffer, 5, "%d", myid);
176 node_name = node_name + buffer;
177 string _containerName = ns->BuildContainerNameForNS((char*) node_name.c_str(),
179 cerr << "---------" << _containerName << "----------" << endl;
180 ns->Register(obj, _containerName.c_str());
184 catch (PaCO::PACO_Exception& e)
186 INFOS("Caught PaCO::PACO_Exception");
187 std::cerr << e << std::endl;
189 catch(CORBA::SystemException&)
191 INFOS("Caught CORBA::SystemException.");
193 catch(PortableServer::POA::ServantAlreadyActive&)
195 INFOS("Caught CORBA::ServantAlreadyActiveException");
197 catch(CORBA::Exception&)
199 INFOS("Caught CORBA::Exception.");
201 catch(std::exception& exc)
203 INFOS("Caught std::exception - "<<exc.what());
207 INFOS("Caught unknown exception.");