PaCO++  0.05
PaCO++_src.cc
Go to the documentation of this file.
1 
2 #include "PaCO++_operation.h"
3 #include "PaCO++_src.h"
4 
6 
7 static ostream &
8 operator<<(ostream & os, const CORBA::Exception & e)
9 {
10  CORBA::Any tmp;
11  tmp <<=e ;
12  CORBA::TypeCode_var tc = tmp.type();
13  const char * p = tc->name ();
14  if (*p != '\0')
15  os << p;
16  else
17  os << tc->id();
18  return os;
19 }
20 
21 void* paco_orb_run(void* arg)
22 {
23  CORBA::ORB_ptr orb = (CORBA::ORB_ptr) arg;
24  orb->run();
25  return (void*) 0;
26 }
27 
29 {
30  static paco_fabrique_manager* pfm=NULL;
31 
32  if (!pfm)
33  pfm = new paco_fabrique_manager();
34 
35  return pfm;
36 }
37 
38 
39 // class InterfaceManager_impl
40 
42 {
43  _orb = current_orb;
44  _current_uid = 0;
45  _totalNode = -1;
46  _workNode = -1;
48  _rtn = 0; // normal
49 }
50 
52 
53 void
55 {
56  _rtn = rtn;
57 }
58 
59 void
60 InterfaceManager_impl::setTotalNode(CORBA::Short totalNode)
61 {
62  if (totalNode > 0)
63  {
64  _totalNode = totalNode;
65  // Init de _informations_temp;
70  }
72 }
73 
74 void
76 {
77  serveur_topo = topo;
78  setTotalNode(topo.total);
79 }
80 
81 void
82 InterfaceManager_impl::setWorkNode(CORBA::Short totalNode)
83 {
84  _workNode = totalNode;
85 }
86 
87 void
88 InterfaceManager_impl::setNewNode(const char * node, const CORBA::Short rank)
89 {
90 
91 try
92  {
93  //CORBA::Object_var object = _orb->string_to_object(node);
94  //PaCO::InterfaceParallel_var interface = PaCO::InterfaceParallel::_narrow(object);
95  // CORBA::Short rank = interface->getDeployRank();
96 
97  if (_rtn == 1)
98  cerr << "Return Proxy : Adding node : " << rank << endl;
99  else
100  cerr << "Adding node : " << rank << endl;
101  // _informations_temp.nodes[_totalNodeReceived] = node;
102  _informations_temp.nodes[rank] = node;
105  {
106  if (_rtn == 1)
107  cerr << "Return Proxy : All the node are registered" << endl;
108  else
109  cerr << "All the node are registered" << endl;
110 
114  if (_rtn == 1)
115  {
116  // connection for the server side
117  this->finish();
118  }
119  _totalNodeReceived = 0;
121  }
122  }
123  catch (const CORBA::Exception & e)
124  {
125  cerr << " Node : " << node << endl;
126  cerr << " InterfaceManager_impl::setNewNode : Exception : " << e << endl;
127  }
128 
129 }
130 
131 void
133 {
134  return_str = (char *) ref;
135  // Now we have to give this reference to all the nodes
136  CORBA::ULong i;
137  CORBA::Object_var object;
138  PaCO::InterfaceParallel_var interface;
139  CORBA::ULong lgth;
140  if (_workNode == -1) { lgth = _nodes.length();}
141  else { lgth = _workNode;}
142  for (i = 0; i<lgth; i++)
143  {
144  object = _orb->string_to_object(_nodes[i]);
145  interface = PaCO::InterfaceParallel::_narrow(object);
146  interface->refReturnObject(return_str.c_str());
147  }
148 }
149 
150 char *
152 {
153  // cerr << " Return string : " << return_str << endl;
154  char * p = new char[return_str.length()+1];
155  return_str.copy(p,string::npos);
156  p[return_str.length()]=0;
157  // return (char *) return_str.c_str();
158  return p;
159 }
160 
161 // CORBA::Short
162 // InterfaceManager_impl::getTotalNode()
163 // {
164 // return _totalNode;
165 // }
166 
167 void
168 InterfaceManager_impl::return_ok(const CORBA::Short client_id)
169 {
170  CORBA::ULong i;
171  CORBA::Object_var object;
172  PaCO::InterfaceParallel_var interface;
173  CORBA::ULong lgth;
174  if (_workNode == -1) { lgth = _nodes.length();}
175  else { lgth = _workNode;}
176  cerr << "Adding a new client !!!!" << endl;
177  // cerr << "WARNING : in this version PaCO++ only plays with the last client !" << endl;
178  for (i = 0; i<lgth; i++)
179  {
180  //cerr << "Init work node : " << i << endl;
181  object = _orb->string_to_object(_nodes[i]);
182  interface = PaCO::InterfaceParallel::_narrow(object);
183  interface->connect_return_object(client_id);
184  }
185 }
186 
187 void
189 {
190  if (_rtn == 1)
191  cerr << "Return Proxy : Deploy the parallel CORBA object" << endl;
192  else
193  cerr << "Deploy the parallel CORBA object" << endl;
194 
195  // Initialize the nodes
196  CORBA::Object_var object;
197  PaCO::InterfaceParallel_var interface;
198  if (_workNode == -1)
199  {
200  if (_rtn == 1)
201  cerr << "Return Proxy : Deploying all the nodes" << endl;
202  else
203  cerr << "Deploying all the nodes" << endl;
204 
205  for ( CORBA::ULong i = 0; i<_nodes.length(); i++)
206  {
207  if (_rtn == 1)
208  cerr << "Return Proxy : Deploying node : " << i << endl;
209  else
210  cerr << "Deploying node : " << i << endl;
211 
212  object = _orb->string_to_object(_nodes[i]);
213  interface = PaCO::InterfaceParallel::_narrow(object);
214  interface->init_InterfaceParallel(i,_nodes.length(), _informations.serveur_topo);
215 
216  if (_rtn == 0)
217  {
218  cerr << "Exception handling part..." << endl;
220  ref_nodes.length(_nodes.length());
221  for (CORBA::ULong j = 0; j<_nodes.length(); j++)
222  {
223  ref_nodes[j] = _nodes[j];
224  }
225  interface->setRef(ref_nodes);
226  cerr << "Exception handling part...done" << endl;
227  }
228  }
229  }
230  else
231  {
232  cerr << "Deploying " << _workNode << " nodes" << endl;
233  for ( CORBA::Long i = 0; i<_workNode; i++)
234  {
235  cerr << "Deploying node : " << i << endl;
236  object = _orb->string_to_object(_nodes[i]);
237  interface = PaCO::InterfaceParallel::_narrow(object);
238  interface->init_InterfaceParallel(i,_nodes.length(), _informations.serveur_topo);
239  }
240  }
241  if (_rtn == 0)
242  {
243  // connecting the client to the interface manager
244  cerr << "Finishing...\n";
245  this->finish();
246  cerr << "Finishing...done\n";
247  }
248 }
249 
252 {
253 // cerr << "In "<<__FUNCTION__ << ":"<<(void*)this<<endl;
254  _current_uid++;
257  // cerr << "Out "<<__FUNCTION__ << ":"<<(void*)this<<endl;
258  return retour;
259 }
260 
261 // class InterfaceParallel_impl
262 
263 InterfaceParallel_impl::InterfaceParallel_impl(CORBA::ORB_ptr current_orb, char * ior)
264 {
265  _myRank = -1;
266  _totalNode = -1;
267  _orb = current_orb;
268  _ior = ior;
269 }
270 
272 {
273 }
274 
275 void
277 {
278  cerr << "Debut de deploy()"<< endl;
279  _deployRank = rank;
280  CORBA::Object_var object;
281  object = _orb->string_to_object(_ior.c_str());
282  PaCO::InterfaceManager_var interface;
283  interface = PaCO::InterfaceManager::_narrow(object);
284  char * obj = _orb->object_to_string(_this());
285  try
286  {
287  interface->setNewNode(obj, rank);
288  }
289  catch (const CORBA::Exception & e)
290  {
291  cerr << "Argument : " << obj << endl;
292  cerr << "InterfaceParallel_impl::deploy : Exception : " << e << endl;
293  }
294  cerr << "Fin de deploy()"<< endl;
295 }
296 
297 CORBA::Short
299 {
300  return _myRank;
301 }
302 
303 CORBA::Short
305 {
306  return _deployRank;
307 }
308 
309 CORBA::Short
311 {
312  return _totalNode;
313 }
314 
315 void
316 InterfaceParallel_impl::init_InterfaceParallel(CORBA::Short myRank, CORBA::Short totalNode)
317 {
318  _myRank = myRank;
319  _totalNode = totalNode;
320  cerr << "Servant : " << myRank << " initialized" << endl;
321 }
322 
325 {
326  return NULL;
327 }
328 
329 void
331 {
332  return_object = (char *) ref;
333 }
334 
335 void
337 {
338  _ref_nodes.length(ref_nodes.length());
339  for (CORBA::ULong i = 0; i<ref_nodes.length(); i++)
340  _ref_nodes[i] = ref_nodes[i];
341 }
virtual PaCO::ConnectionInfos * getConnectionInfos()
Definition: PaCO++_src.cc:324
virtual void setRef(const PaCO::InterfaceParallel::ref &ref_nodes)
Definition: PaCO++_src.cc:336
virtual void setTopo(const PaCO::PacoTopology_t &topo)
Definition: PaCO++_src.cc:75
PaCO::PacoTopology_t serveur_topo
Definition: PaCO++_src.h:54
CORBA::ORB_ptr _orb
Definition: PaCO++_src.h:46
void * paco_orb_run(void *arg)
Definition: PaCO++_src.cc:21
CORBA::Short _totalNodeReceived
Definition: PaCO++_src.h:50
sequence< string > ref
Definition: PaCO++.idl:97
CORBA::Short getTotalNode()
Definition: PaCO++_src.cc:310
PaCO::ConnectionInfos _informations_temp
Definition: PaCO++_src.h:53
virtual ~InterfaceParallel_impl()
Definition: PaCO++_src.cc:271
virtual void setWorkNode(CORBA::Short totalNode)
Definition: PaCO++_src.cc:82
virtual void updateContexts()=0
virtual void setTotalNode(CORBA::Short totalNode)
Definition: PaCO++_src.cc:60
CORBA::Short getDeployRank()
Definition: PaCO++_src.cc:304
CORBA::Short _totalNode
Definition: PaCO++_src.h:49
CORBA::Short _current_uid
Definition: PaCO++_src.h:48
virtual char * getReturn()
Definition: PaCO++_src.cc:151
PaCO::ConnectionInfos _informations
Definition: PaCO++_src.h:52
void init_InterfaceParallel(CORBA::Short myRank, CORBA::Short totalNode)
Definition: PaCO++_src.cc:316
InterfaceManager_impl(CORBA::ORB_ptr current_orb)
Definition: PaCO++_src.cc:41
unsigned long total
Definition: PaCO++.idl:35
virtual void return_ok(const CORBA::Short client_id)
Definition: PaCO++_src.cc:168
PacoTopology_t serveur_topo
Definition: PaCO++.idl:61
PaCO::PacoTopology_t PacoTopologySeq
Definition: PaCO++_src.cc:5
paco_fabrique_manager * paco_getFabriqueManager()
Definition: PaCO++_src.cc:28
static ostream & operator<<(ostream &os, const CORBA::Exception &e)
Definition: PaCO++_src.cc:8
virtual void setConnectionInfos()
Definition: PaCO++_src.cc:188
void deploy(CORBA::Short rank)
Definition: PaCO++_src.cc:276
virtual void setNewNode(const char *node, const CORBA::Short rank)
Definition: PaCO++_src.cc:88
virtual void finish()=0
virtual void setReturn(const char *ref)
Definition: PaCO++_src.cc:132
CORBA::Short getMyRank()
Definition: PaCO++_src.cc:298
sequence< string > nodes
Definition: PaCO++.idl:59
CORBA::Short _workNode
Definition: PaCO++_src.h:51
virtual ~InterfaceManager_impl()
Definition: PaCO++_src.cc:51
PaCO::ConnectionInfos::_nodes_seq _nodes
Definition: PaCO++_src.h:47
InterfaceParallel_impl(CORBA::ORB_ptr current_orb, char *ior)
Definition: PaCO++_src.cc:263
void refReturnObject(const char *ref)
Definition: PaCO++_src.cc:330
virtual PaCO::ConnectionInfos * getConnectionInfos()
Definition: PaCO++_src.cc:251