Salome HOME
Merge branch 'V9_2_2_BR'
[modules/kernel.git] / src / ParallelContainer / SALOME_ParallelContainerProxyDummy.cxx
1 // Copyright (C) 2007-2019  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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, or (at your option) any later version.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  SALOME ParallelContainerProxyDummy : Proxy of a PaCO++ object using Dummy
24 //  File   : SALOME_ParallelContainerProxyDummy.cxx
25 //  Author : AndrĂ© Ribes, EDF
26 //  Module : SALOME PARALLEL
27 //
28 #include <iostream>
29 #include <string>
30 #include <stdio.h>
31
32 #ifndef WIN32
33 #include <unistd.h>
34 #else
35 #include <process.h>
36 #endif
37
38 // PaCO++ include
39 //#include "SALOME_ComponentPaCO_Engines_Container_server.h"
40 #include "SALOME_ParallelContainerProxy_i.hxx"
41 #include <paco_omni.h>
42 #include <paco_dummy.h>
43
44 #include "SALOME_NamingService.hxx"
45
46 #include "utilities.h"
47 #include "Basics_Utils.hxx"
48 #include "Utils_ORB_INIT.hxx"
49 #include "Utils_SINGLETON.hxx"
50 #include "SALOMETraceCollector.hxx"
51 #include "OpUtil.hxx"
52
53 #include "Container_init_python.hxx"
54
55 #ifdef DEBUG_PARALLEL
56 #include <signal.h>
57
58 void handler(int t) {
59   std::cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
60   std::cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
61   std::cerr << "SIGSEGV in :" << getpid() << std::endl;
62   std::cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
63   std::cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
64   while (1) {}
65 }
66 #endif
67
68 int main(int argc, char* argv[])
69 {
70   INFOS("Launching a parallel proxy container");
71
72 #ifdef DEBUG_PARALLEL
73   signal(SIGSEGV, handler);
74 #endif
75   // Initialise the ORB.
76   CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
77   KERNEL_PYTHON::init_python(argc,argv);
78
79   std::string containerName("");
80   if(argc > 1) {
81     containerName = argv[1];
82   }
83
84   int nbnodes = 1;
85   if(argc > 4) 
86     sscanf(argv[4],"%d",&nbnodes);
87
88   try {  
89     CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
90     ASSERT(!CORBA::is_nil(obj));
91     PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj);
92     PortableServer::POAManager_var pman = root_poa->the_POAManager();
93
94 #ifndef WIN32
95     // add this container to the kill list
96     char aCommand[100];
97     sprintf(aCommand, "addToKillList.py %d SALOME_ParallelContainerProxyDummy", getpid());
98     system(aCommand);
99 #endif
100
101     SALOME_NamingService * ns = new SALOME_NamingService(orb);
102
103     // PaCO++ code
104     paco_fabrique_manager* pfm = paco_getFabriqueManager();
105     pfm->register_com("dummy", new paco_dummy_fabrique());
106     pfm->register_thread("omnithread", new paco_omni_fabrique());
107
108     Container_proxy_impl_final * proxy = 
109       new Container_proxy_impl_final(orb,
110                                      pfm->get_thread("omnithread"),
111                                      root_poa,
112                                      containerName);
113     proxy->setLibCom("dummy", proxy);
114     proxy->setLibThread("omnithread");
115     // Topo of the parallel object
116     PaCO::PacoTopology_t serveur_topo;
117     serveur_topo.total = nbnodes;
118     proxy->setTopology(serveur_topo);
119
120     //PortableServer::ObjectId_var _id = root_poa->activate_object(proxy);
121     //obj = root_poa->id_to_reference(_id);
122     obj = proxy->_this();
123
124     // In the NamingService
125     std::string hostname = Kernel_Utils::GetHostname();
126     Engines::Container_var pCont = Engines::Container::_narrow(obj);
127     string _containerName = ns->BuildContainerNameForNS(containerName.c_str(),
128                                                         hostname.c_str());
129     std::cerr << "---------" << _containerName << "----------" << std::endl;
130     ns->Register(pCont, _containerName.c_str());
131     pman->activate();
132     orb->run();
133     PyGILState_Ensure();
134     //Delete python container that destroy orb from python (pyCont._orb.destroy())
135     Py_Finalize();
136     delete ns;
137   }
138   catch (PaCO::PACO_Exception& e)
139   {
140     INFOS("Caught PaCO::PACO_Exception");
141     std::cerr << e << std::endl;
142   }
143   catch(CORBA::SystemException&)
144   {
145     INFOS("Caught CORBA::SystemException.");
146   }
147   catch(PortableServer::POA::ServantAlreadyActive&)
148   {
149     INFOS("Caught CORBA::ServantAlreadyActiveException");
150   }
151   catch(CORBA::Exception&)
152   {
153     INFOS("Caught CORBA::Exception.");
154   }
155   catch(std::exception& exc)
156   {
157     INFOS("Caught std::exception - "<<exc.what()); 
158   }
159   catch(...)
160   {
161     INFOS("Caught unknown exception.");
162   }
163   return 0 ;
164 }
165