Salome HOME
To avoid compilation pb on RedHat 8.0.
[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 <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
73         // Initialise the ORB.
74         ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance();
75         ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
76         CORBA::ORB_var orb = init(0, 0);
77         //CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
78
79         char *containerName = "";
80         if(argc > 1) {
81                 containerName = argv[1];
82         }
83
84         try {  
85                 CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
86                 ASSERT(!CORBA::is_nil(obj));
87                 PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj);
88                 PortableServer::POAManager_var pman = root_poa->the_POAManager();
89
90 #ifndef WNT
91                 // add this container to the kill list
92                 char aCommand[100];
93                 sprintf(aCommand, "addToKillList.py %d SALOME_ParallelContainerProxy", getpid());
94                 system(aCommand);
95 #endif
96
97                 SALOME_NamingService * ns = new SALOME_NamingService(CORBA::ORB::_duplicate(orb));
98                 Engines::Container_proxy_impl * proxy = new Engines::Container_proxy_impl(CORBA::ORB::_duplicate(orb)); 
99
100                 // PaCO++ code
101                 paco_fabrique_manager* pfm = paco_getFabriqueManager();
102                 // Global context
103                 PaCO_operation * global_ptr =  proxy->getContext("global_paco_context");
104                 pfm->register_com("dummy", new paco_dummy_fabrique());
105                 global_ptr->setLibCom("dummy", NULL);
106                 pfm->register_thread("omnithread", new paco_omni_fabrique());
107                 global_ptr->setLibThread("omnithread");
108                 global_ptr->setTypeClient(true);
109                 // The proxy is a PaCO++ client
110                 PaCO::PacoTopology_t client_topo;
111                 client_topo.total = 1;
112                 global_ptr->setClientTopo(client_topo);
113                 // Topo of the parallel object
114                 PaCO::PacoTopology_t serveur_topo;
115                 serveur_topo.total = 1;
116                 proxy->setTopo(serveur_topo);
117
118                 PortableServer::ObjectId_var _id = root_poa->activate_object(proxy);
119                 obj = root_poa->id_to_reference(_id);
120
121                 // In the NamingService
122                 string hostname = GetHostname();
123                 Engines::Container_var pCont = Engines::Container::_narrow(obj);
124                 string _containerName = ns->BuildContainerNameForNS(containerName,
125                                                                                                                                                                                                                                 hostname.c_str());
126                 cerr << "---------" << _containerName << "----------" << endl;
127                 ns->Register(pCont, _containerName.c_str());
128                 pman->activate();
129                 orb->run();
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