Back to index

salome-kernel  6.5.0
SALOME_ParallelContainerProxyDummy.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 ParallelContainerProxyDummy : Proxy of a PaCO++ object using Dummy
00024 //  File   : SALOME_ParallelContainerProxyDummy.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 // PaCO++ include
00039 //#include "SALOME_ComponentPaCO_Engines_Container_server.h"
00040 #include "SALOME_ParallelContainerProxy_i.hxx"
00041 #include <paco_omni.h>
00042 #include <paco_dummy.h>
00043 
00044 #include "SALOME_NamingService.hxx"
00045 
00046 #include "utilities.h"
00047 #include "Basics_Utils.hxx"
00048 #include "Utils_ORB_INIT.hxx"
00049 #include "Utils_SINGLETON.hxx"
00050 #include "SALOMETraceCollector.hxx"
00051 #include "OpUtil.hxx"
00052 
00053 #include "Container_init_python.hxx"
00054 
00055 #ifdef DEBUG_PARALLEL
00056 #include <signal.h>
00057 
00058 void handler(int t) {
00059   std::cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
00060   std::cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
00061   std::cerr << "SIGSEGV in :" << getpid() << std::endl;
00062   std::cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
00063   std::cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
00064   while (1) {}
00065 }
00066 #endif
00067 
00068 int main(int argc, char* argv[])
00069 {
00070   INFOS("Launching a parallel proxy container");
00071 
00072 #ifdef DEBUG_PARALLEL
00073   signal(SIGSEGV, handler);
00074 #endif
00075   // Initialise the ORB.
00076   CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
00077   KERNEL_PYTHON::init_python(argc,argv);
00078 
00079   std::string containerName("");
00080   if(argc > 1) {
00081     containerName = argv[1];
00082   }
00083 
00084   int nbnodes = 1;
00085   if(argc > 4) 
00086     sscanf(argv[4],"%d",&nbnodes);
00087 
00088   try {  
00089     CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
00090     ASSERT(!CORBA::is_nil(obj));
00091     PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj);
00092     PortableServer::POAManager_var pman = root_poa->the_POAManager();
00093 
00094 #ifndef WIN32
00095     // add this container to the kill list
00096     char aCommand[100];
00097     sprintf(aCommand, "addToKillList.py %d SALOME_ParallelContainerProxyDummy", getpid());
00098     system(aCommand);
00099 #endif
00100 
00101     SALOME_NamingService * ns = new SALOME_NamingService(orb);
00102 
00103     // PaCO++ code
00104     paco_fabrique_manager* pfm = paco_getFabriqueManager();
00105     pfm->register_com("dummy", new paco_dummy_fabrique());
00106     pfm->register_thread("omnithread", new paco_omni_fabrique());
00107 
00108     Container_proxy_impl_final * proxy = 
00109       new Container_proxy_impl_final(orb,
00110                                      pfm->get_thread("omnithread"),
00111                                      root_poa,
00112                                      containerName);
00113     proxy->setLibCom("dummy", proxy);
00114     proxy->setLibThread("omnithread");
00115     // Topo of the parallel object
00116     PaCO::PacoTopology_t serveur_topo;
00117     serveur_topo.total = nbnodes;
00118     proxy->setTopology(serveur_topo);
00119 
00120     //PortableServer::ObjectId_var _id = root_poa->activate_object(proxy);
00121     //obj = root_poa->id_to_reference(_id);
00122     obj = proxy->_this();
00123 
00124     // In the NamingService
00125     std::string hostname = Kernel_Utils::GetHostname();
00126     Engines::Container_var pCont = Engines::Container::_narrow(obj);
00127     string _containerName = ns->BuildContainerNameForNS(containerName.c_str(),
00128                                                         hostname.c_str());
00129     std::cerr << "---------" << _containerName << "----------" << std::endl;
00130     ns->Register(pCont, _containerName.c_str());
00131     pman->activate();
00132     orb->run();
00133     PyGILState_Ensure();
00134     //Delete python container that destroy orb from python (pyCont._orb.destroy())
00135     Py_Finalize();
00136     delete ns;
00137   }
00138   catch (PaCO::PACO_Exception& e)
00139   {
00140     INFOS("Caught PaCO::PACO_Exception");
00141     std::cerr << e << std::endl;
00142   }
00143   catch(CORBA::SystemException&)
00144   {
00145     INFOS("Caught CORBA::SystemException.");
00146   }
00147   catch(PortableServer::POA::ServantAlreadyActive&)
00148   {
00149     INFOS("Caught CORBA::ServantAlreadyActiveException");
00150   }
00151   catch(CORBA::Exception&)
00152   {
00153     INFOS("Caught CORBA::Exception.");
00154   }
00155   catch(std::exception& exc)
00156   {
00157     INFOS("Caught std::exception - "<<exc.what()); 
00158   }
00159   catch(...)
00160   {
00161     INFOS("Caught unknown exception.");
00162   }
00163   return 0 ;
00164 }
00165