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