Back to index

salome-kernel  6.5.0
SALOME_ParallelContainerNodeDummy.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  SALOME ParallelContainerNodeDummy : launcher of a PaCO++ object
00024 //  File   : SALOME_ParallelContainerNodeDummy.cxx
00025 //  Author : André Ribes, EDF
00026 //  Module : SALOME PARALLEL
00027 //
00028 #include <iostream>
00029 #include <string>
00030 #include <stdio.h>
00031 
00032 #ifndef WIN32
00033 #include <unistd.h>
00034 #else
00035 #include <process.h>
00036 #endif
00037 
00038 #include "SALOME_ParallelContainer_i.hxx"
00039 
00040 #include <paco_omni.h>
00041 #include <paco_dummy.h>
00042 
00043 #include "SALOME_NamingService.hxx"
00044 
00045 #include "utilities.h"
00046 #include "Basics_Utils.hxx"
00047 #include "Utils_ORB_INIT.hxx"
00048 #include "Utils_SINGLETON.hxx"
00049 #include "SALOMETraceCollector.hxx"
00050 #include "OpUtil.hxx"
00051 
00052 #include "Container_init_python.hxx"
00053 
00054 #ifdef _DEBUG_
00055 #include <signal.h>
00056 
00057 void handler(int t) {
00058   std::cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
00059   std::cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
00060   std::cerr << "SIGSEGV in :" << getpid() << std::endl;
00061   std::cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
00062   std::cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
00063   while (1) {}
00064 }
00065 #endif
00066 
00067 typedef void (*sighandler_t)(int);
00068 sighandler_t setsig(int sig, sighandler_t handler)
00069 {
00070   struct sigaction context, ocontext;
00071   context.sa_handler = handler;
00072   sigemptyset(&context.sa_mask);
00073   context.sa_flags = 0;
00074   if (sigaction(sig, &context, &ocontext) == -1)
00075     return SIG_ERR;
00076   return ocontext.sa_handler;
00077 }
00078 
00079 void AttachDebugger()
00080 {
00081   if(getenv ("DEBUGGER"))
00082   {
00083     std::stringstream exec;
00084     exec << "$DEBUGGER SALOME_ParallelContainerNodeDummy " << getpid() << "&";
00085     std::cerr << exec.str() << std::endl;
00086     system(exec.str().c_str());
00087     while(1);
00088   }
00089 }
00090 
00091 void Handler(int theSigId)
00092 {
00093   std::cerr << "SIGSEGV: "  << std::endl;
00094   AttachDebugger();
00095   //to exit or not to exit
00096   exit(1);
00097 }
00098 
00099 void terminateHandler(void)
00100 {
00101   std::cerr << "Terminate: not managed exception !"  << std::endl;
00102   AttachDebugger();
00103 }
00104 
00105 void unexpectedHandler(void)
00106 {
00107   std::cerr << "Unexpected: unexpected exception !"  << std::endl;
00108   AttachDebugger();
00109 }
00110 
00111 int main(int argc, char* argv[])
00112 {
00113   INFOS("Launching a parallel container node");
00114 
00115   if(getenv ("DEBUGGER"))
00116   {
00117     setsig(SIGSEGV,&Handler);
00118     set_terminate(&terminateHandler);
00119     set_unexpected(&unexpectedHandler);
00120   }
00121 
00122   // Initialise the ORB.
00123   CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
00124   KERNEL_PYTHON::init_python(argc,argv);
00125 
00126   std::string containerName("");
00127   if(argc > 1) {
00128     containerName = argv[1];
00129   }
00130   std::string proxy_hostname("");
00131   if(argc > 3) {
00132     proxy_hostname = argv[3];
00133   }
00134   int myid = 0;
00135   if(argc > 4) 
00136     sscanf(argv[4],"%d",&myid);
00137 
00138   try {  
00139     CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
00140     PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj);
00141     PortableServer::POAManager_var pman = root_poa->the_POAManager();
00142 
00143 #ifndef WIN32
00144     // add this container to the kill list
00145     char aCommand[100];
00146     sprintf(aCommand, "addToKillList.py %d SALOME_ParallelContainerNode", getpid());
00147     system(aCommand);
00148 #endif
00149 
00150     SALOME_NamingService * ns = new SALOME_NamingService(orb);
00151     // Get the proxy
00152     std::string proxyNameInNS = ns->BuildContainerNameForNS(containerName.c_str(), 
00153                                                        proxy_hostname.c_str());
00154     obj = ns->Resolve(proxyNameInNS.c_str());
00155     char * proxy_ior = orb->object_to_string(obj);
00156 
00157     // Creating a node
00158     std::string node_name = containerName + "Node";
00159     Engines_Parallel_Container_i * servant = new Engines_Parallel_Container_i(CORBA::ORB::_duplicate(orb), 
00160                                                                               proxy_ior,
00161                                                                               myid,
00162                                                                               root_poa,
00163                                                                               node_name);
00164     // PaCO++ init
00165     paco_fabrique_manager * pfm = paco_getFabriqueManager();
00166     pfm->register_com("dummy", new paco_dummy_fabrique());
00167     pfm->register_thread("omni", new paco_omni_fabrique());
00168     servant->setLibCom("dummy", servant);
00169     servant->setLibThread("omni");
00170 
00171     // Activation
00172     obj = servant->_this();
00173 
00174     // In the NamingService
00175     string hostname = Kernel_Utils::GetHostname();
00176     char buffer [5];
00177     snprintf(buffer, 5, "%d", myid);
00178     node_name = node_name + buffer;
00179     string _containerName = ns->BuildContainerNameForNS((char*) node_name.c_str(),
00180                                                         hostname.c_str());
00181     std::cerr << "---------" << _containerName << "----------" << std::endl;
00182     ns->Register(obj, _containerName.c_str());
00183     pman->activate();
00184     orb->run();
00185     PyGILState_Ensure();
00186     //Delete python container that destroy orb from python (pyCont._orb.destroy())
00187     Py_Finalize();
00188     CORBA::string_free(proxy_ior);
00189     delete ns;
00190   }
00191   catch (PaCO::PACO_Exception& e)
00192   {
00193     INFOS("Caught PaCO::PACO_Exception");
00194     std::cerr << e << std::endl;
00195   }
00196   catch(CORBA::SystemException&)
00197   {
00198     INFOS("Caught CORBA::SystemException.");
00199   }
00200   catch(PortableServer::POA::ServantAlreadyActive&)
00201   {
00202     INFOS("Caught CORBA::ServantAlreadyActiveException");
00203   }
00204   catch(CORBA::Exception&)
00205   {
00206     INFOS("Caught CORBA::Exception.");
00207   }
00208   catch(omniORB::fatalException& fe) 
00209   {
00210     INFOS("Caught omniORB::fatalException:");
00211     INFOS(" file: " << fe.file());
00212     INFOS(" line: " << fe.line());
00213     INFOS(" mesg: " << fe.errmsg());
00214   }
00215   catch(std::exception& exc)
00216   {
00217     INFOS("Caught std::exception - "<<exc.what()); 
00218   }
00219   catch(...)
00220   {
00221     INFOS("Caught unknown exception.");
00222   }
00223   return 0 ;
00224 }
00225