Salome HOME
be5ee2add53943c6a59abdf885131a84fef38fef
[modules/kernel.git] / src / ParallelContainer / SALOME_ParallelContainerProxyDummy.cxx
1 //  Copyright (C) 2007-2008  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.
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 //  SALOME ParallelContainerProxyDummy : Proxy of a PaCO++ object using Dummy
23 //  File   : SALOME_ParallelContainerProxyDummy.cxx
24 //  Author : AndrĂ© Ribes, EDF
25 //  Module : SALOME PARALLEL
26 //
27 #include <iostream>
28 #include <string>
29 #include <stdio.h>
30
31 #ifndef WIN32
32 #include <unistd.h>
33 #else
34 #include <process.h>
35 #endif
36
37 // PaCO++ include
38 //#include "SALOME_ComponentPaCO_Engines_Container_server.h"
39 #include "SALOME_ParallelContainerProxy_i.hxx"
40 #include <paco_omni.h>
41 #include <paco_dummy.h>
42
43 #include "SALOME_NamingService.hxx"
44
45 #include "utilities.h"
46 #include "Utils_ORB_INIT.hxx"
47 #include "Utils_SINGLETON.hxx"
48 #include "SALOMETraceCollector.hxx"
49 #include "OpUtil.hxx"
50
51 #ifdef DEBUG_PARALLEL
52 #include <signal.h>
53 using namespace std;
54
55 void handler(int t) {
56   cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
57   cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
58   cerr << "SIGSEGV in :" << getpid() << endl;
59   cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
60   cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
61   while (1) {}
62 }
63 #endif
64
65 int main(int argc, char* argv[])
66 {
67   INFOS("Launching a parallel proxy container");
68
69 #ifdef DEBUG_PARALLEL
70   signal(SIGSEGV, handler);
71 #endif
72   // Initialise the ORB.
73   CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
74
75   std::string containerName("");
76   if(argc > 1) {
77     containerName = argv[1];
78   }
79
80   try {  
81     CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
82     ASSERT(!CORBA::is_nil(obj));
83     PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj);
84     PortableServer::POAManager_var pman = root_poa->the_POAManager();
85
86 #ifndef WIN32
87     // add this container to the kill list
88     char aCommand[100];
89     sprintf(aCommand, "addToKillList.py %d SALOME_ParallelContainerProxyDummy", getpid());
90     system(aCommand);
91 #endif
92
93     SALOME_NamingService * ns = new SALOME_NamingService(CORBA::ORB::_duplicate(orb));
94 //    Engines::Container_proxy_impl * proxy = 
95 //      new Engines::Container_proxy_impl(orb,
96 //                                      new paco_omni_fabrique());
97
98     Container_proxy_impl_final * proxy = 
99       new Container_proxy_impl_final(orb,
100                                      new paco_omni_fabrique());
101     // PaCO++ code
102     paco_fabrique_manager* pfm = paco_getFabriqueManager();
103     pfm->register_com("dummy", new paco_dummy_fabrique());
104     proxy->setLibCom("dummy", proxy);
105     pfm->register_thread("omnithread", new paco_omni_fabrique());
106     proxy->setLibThread("omnithread");
107     // Topo of the parallel object
108     PaCO::PacoTopology_t serveur_topo;
109     serveur_topo.total = 1;
110     proxy->setTopology(serveur_topo);
111
112     PortableServer::ObjectId_var _id = root_poa->activate_object(proxy);
113     obj = root_poa->id_to_reference(_id);
114
115     // In the NamingService
116     string hostname = Kernel_Utils::GetHostname();
117     Engines::Container_var pCont = Engines::Container::_narrow(obj);
118     string _containerName = ns->BuildContainerNameForNS(containerName.c_str(),
119                                                         hostname.c_str());
120     cerr << "---------" << _containerName << "----------" << endl;
121     ns->Register(pCont, _containerName.c_str());
122     pman->activate();
123     orb->run();
124   }
125   catch (PaCO::PACO_Exception& e)
126   {
127     INFOS("Caught PaCO::PACO_Exception");
128     std::cerr << e << std::endl;
129   }
130   catch(CORBA::SystemException&)
131   {
132     INFOS("Caught CORBA::SystemException.");
133   }
134   catch(PortableServer::POA::ServantAlreadyActive&)
135   {
136     INFOS("Caught CORBA::ServantAlreadyActiveException");
137   }
138   catch(CORBA::Exception&)
139   {
140     INFOS("Caught CORBA::Exception.");
141   }
142   catch(std::exception& exc)
143   {
144     INFOS("Caught std::exception - "<<exc.what()); 
145   }
146   catch(...)
147   {
148     INFOS("Caught unknown exception.");
149   }
150   return 0 ;
151 }
152