5 #define protected public
6 #include <omniORB4/CORBA.h>
7 #include <omniORB4/internal/typecode.h>
10 #include "RuntimeSALOME.hxx"
11 #include "CORBANode.hxx"
12 #include "CORBAComponent.hxx"
13 #include "SalomeComponent.hxx"
14 #include "CORBAPorts.hxx"
15 #include "OutputDataStreamPort.hxx"
16 #include "CalStreamPort.hxx"
20 #include "SALOME_NamingService.hxx"
21 #include "SALOME_LifeCycleCORBA.hxx"
24 #include <omniORB4/CORBA.h>
30 #include "YacsTrace.hxx"
32 using namespace YACS::ENGINE;
35 const char CORBANode::IMPL_NAME[]="CORBA";
36 const char CORBANode::KIND[]="CORBA";
38 std::string CORBANode::getKind() const
43 //! CORBANode constructor
44 CORBANode::CORBANode(const std::string& name): ServiceNode(name)
46 _implementation=IMPL_NAME;
49 CORBANode::CORBANode(const CORBANode& other,ComposedNode *father):ServiceNode(other,father)
51 _implementation=IMPL_NAME;
54 //! Execute the service on the component associated to the node
55 void CORBANode::execute()
57 DEBTRACE( "+++++++++++++ CorbaNode::execute: " << getName() << " +++++++++++++++" );
59 //DII request building :
60 // a service gets all its in parameters first
61 // then all its out parameters
62 // no inout parameters
63 // the return value (if any) is the first out parameter
64 // not yet user exception (only CORBA exception)
66 CORBA::Object_var objComponent=((CORBAComponent*)_component)->getCompoPtr();
67 CORBA::Request_var req = objComponent->_request(_method.c_str());
68 CORBA::NVList_ptr arguments = req->arguments() ;
70 DEBTRACE( "+++++++++++++++++CorbaNode::inputs+++++++++++++++++" )
73 list<InputPort *>::iterator iter2;
74 for(iter2 = _setOfInputPort.begin(); iter2 != _setOfInputPort.end(); iter2++)
76 InputCorbaPort *p=(InputCorbaPort *)*iter2;
77 DEBTRACE( "port name: " << p->getName() )
78 DEBTRACE( "port kind: " << p->edGetType()->kind() )
79 CORBA::Any* ob=p->getAny();
81 CORBA::TypeCode_var typcod= ob->type();
82 switch(p->edGetType()->kind())
101 if(*ob >>= CORBA::Any::to_boolean(b))
104 DEBTRACE( "not a boolean" )
107 DEBTRACE( typcod->id() )
113 //add_value makes a copy of any (*ob). This copy will be deleted with the request
114 arguments->add_value( p->getName().c_str() , *ob , CORBA::ARG_IN ) ;
119 DEBTRACE( "+++++++++++++++++CorbaNode::outputs+++++++++++++++++" )
120 list<OutputPort *>::iterator iter;
121 for(iter = _setOfOutputPort.begin(); iter != _setOfOutputPort.end(); iter++)
123 OutputCorbaPort *p=(OutputCorbaPort *)*iter;
124 DEBTRACE( "port name: " << p->getName() )
125 DEBTRACE( "port kind: " << p->edGetType()->kind() )
126 CORBA::Any* ob=p->getAnyOut();
128 DEBTRACE("refcount CORBA : " << ((omni::TypeCode_base*)ob->pd_tc.in())->pd_ref_count);
130 //add_value makes a copy of any. Copy will be deleted with request
131 arguments->add_value( p->getName().c_str() , *ob , CORBA::ARG_OUT );
133 DEBTRACE("refcount CORBA : " << ((omni::TypeCode_base*)ob->pd_tc.in())->pd_ref_count);
138 req->set_return_type(CORBA::_tc_void);
140 //req->exceptions()->add(eo::_tc_SALOME_Exception);
142 DEBTRACE( "+++++++++++++++++CorbaNode::calculation+++++++++++++++++" << _method )
144 CORBA::Exception *exc =req->env()->exception();
147 DEBTRACE( "An exception was thrown!" )
148 DEBTRACE( "The raised exception is of Type:" << exc->_name() )
149 throw Exception("Execution problem");
152 DEBTRACE( "++++++++++++CorbaNode::outputs++++++++++++" )
153 int out_param=in_param;
154 for(iter = _setOfOutputPort.begin(); iter != _setOfOutputPort.end(); iter++)
156 OutputCorbaPort *p=(OutputCorbaPort *)*iter;
157 DEBTRACE( "port name: " << p->getName() )
158 DEBTRACE( "port kind: " << p->edGetType()->kind() )
159 DEBTRACE( "port number: " << out_param )
160 CORBA::Any *ob=arguments->item(out_param)->value();
162 DEBTRACE("refcount CORBA : " << ((omni::TypeCode_base*)ob->pd_tc.in())->pd_ref_count);
165 CORBA::TypeCode_var tc=ob->type();
166 switch(p->edGetType()->kind())
190 //OutputPort must copy the input Any(ob).
191 //This Any will be deleted with the request.
192 //Copy is made by the method put.
194 out_param=out_param+1;
196 DEBTRACE("refcount CORBA : " << ((omni::TypeCode_base*)ob->pd_tc.in())->pd_ref_count);
199 DEBTRACE( "++++++++++++++++++++++++++++++++++++++++++" )
201 //Request has been deleted (_var )
202 //All anys given to the request are deleted : don't forget to copy them
203 //if you want to keep them
205 list<OutputPort *>::const_iterator iter;
206 for(iter = _setOfOutputPort.begin(); iter != _setOfOutputPort.end(); iter++)
208 OutputCorbaPort *p=(OutputCorbaPort *)*iter;
209 CORBA::Any *ob=p->getAny();
210 DEBTRACE("refcount CORBA : " << ((omni::TypeCode_base*)ob->pd_tc.in())->pd_ref_count);
213 DEBTRACE( "+++++++++++++++++ End CorbaNode::execute: " << getName() << " +++++++++++++++++" )
216 //! Clone the node : must also clone the component instance ?
217 Node *CORBANode::simpleClone(ComposedNode *father, bool editionOnly) const
219 return new CORBANode(*this,father);
222 //! Create a CORBANode with the same component object and no input or output port
224 * \param name : node name
225 * \return a new CORBANode node
227 ServiceNode* CORBANode::createNode(const std::string& name)
230 CORBANode* node= new CORBANode(name);
231 node->setComponent(_component);
237 const char SalomeNode::KIND[]="Salome";
239 std::string SalomeNode::getKind() const
244 //! SalomeNode constructor
245 SalomeNode::SalomeNode(const std::string& name):ServiceNode(name)
247 _implementation=CORBANode::IMPL_NAME;
250 SalomeNode::SalomeNode(const SalomeNode& other,ComposedNode *father):ServiceNode(other,father)
252 _implementation=CORBANode::IMPL_NAME;
255 SalomeNode::~SalomeNode()
260 //! Init the datastream ports of the component associated to the node
261 void SalomeNode::initService()
263 DEBTRACE( "SalomeNode::initService: "<<getName())
264 if(_setOfInputDataStreamPort.size() == 0 && _setOfOutputDataStreamPort.size() == 0)return;
266 CORBA::Object_var objComponent=((SalomeComponent*)_component)->getCompoPtr();
267 Engines::Superv_Component_var compo=Engines::Superv_Component::_narrow(objComponent);
268 if( CORBA::is_nil(compo) )
270 throw Exception("Can't get reference to DSC object (or it was nil).");
272 compo->init_service(_method.c_str());
275 //! Connect the datastream ports of the component associated to the node
276 void SalomeNode::connectService()
278 DEBTRACE( "SalomeNode::connectService: "<<getName())
279 if(_setOfOutputDataStreamPort.size() == 0)return;
281 CORBA::Object_var objComponent=((SalomeComponent*)_component)->getCompoPtr();
282 SALOME_NamingService NS(getSALOMERuntime()->getOrb()) ;
283 SALOME_LifeCycleCORBA LCC(&NS) ;
284 CORBA::Object_var obj = NS.Resolve("/ConnectionManager");
285 Engines::ConnectionManager_var manager=Engines::ConnectionManager::_narrow(obj);
286 Engines::Superv_Component_var me=Engines::Superv_Component::_narrow(objComponent);
287 std::list<OutputDataStreamPort *>::iterator iter;
288 Engines::ConnectionManager::connectionId id;
289 for(iter = _setOfOutputDataStreamPort.begin(); iter != _setOfOutputDataStreamPort.end(); iter++)
291 OutputDataStreamPort *port=(OutputDataStreamPort *)*iter;
292 std::set<InPort *> ports=port->edSetInPort();
293 std::set<InPort *>::iterator iterout;
294 for(iterout=ports.begin();iterout != ports.end(); iterout++)
296 //It's only possible to connect 2 SalomeNode : try to get a SalomeNode
297 SalomeNode* snode= dynamic_cast<SalomeNode*>((*iterout)->getNode());
298 if(snode == 0) //don't connect, it's not a SalomeNode
299 throw Exception("Can't connect : not a SalomeNode");
301 CORBA::Object_var comp=((SalomeComponent*)snode->getComponent())->getCompoPtr();
302 Engines::Superv_Component_var other=Engines::Superv_Component::_narrow(comp);
303 id=manager->connect(me,port->getName().c_str(),other,(*iterout)->getName().c_str());
308 //Init component port properties
309 for(iter = _setOfOutputDataStreamPort.begin(); iter != _setOfOutputDataStreamPort.end(); iter++)
311 (*iter)->initPortProperties();
313 std::list<InputDataStreamPort *>::iterator iterin;
314 for(iterin = _setOfInputDataStreamPort.begin(); iterin != _setOfInputDataStreamPort.end(); iterin++)
316 (*iterin)->initPortProperties();
320 //! Disconnect the datastream ports of the component associated to the node
321 void SalomeNode::disconnectService()
323 DEBTRACE( "SalomeNode::disconnectService: "<<getName())
324 if(ids.size() == 0)return;
326 SALOME_NamingService NS(getSALOMERuntime()->getOrb()) ;
327 SALOME_LifeCycleCORBA LCC(&NS) ;
328 CORBA::Object_var obj = NS.Resolve("/ConnectionManager");
329 Engines::ConnectionManager_var manager=Engines::ConnectionManager::_narrow(obj);
330 std::list<Engines::ConnectionManager::connectionId>::iterator iter;
331 for(iter = ids.begin(); iter != ids.end(); iter++)
333 manager->disconnect(*iter,Engines::DSC::RemovingConnection);
339 //! Execute the service on the component associated to the node
340 void SalomeNode::execute()
342 DEBTRACE( "+++++++++++++++++ SalomeNode::execute: " << getName() << " +++++++++++++++++" )
344 CORBA::Object_var objComponent=((SalomeComponent*)_component)->getCompoPtr();
345 //DII request building :
346 // a service gets all its in parameters first
347 // then all its out parameters
348 // no inout parameters
349 // the return value (if any) is the first out parameter
350 // not yet user exception (only CORBA exception)
352 CORBA::Request_var req = objComponent->_request(_method.c_str());
353 CORBA::NVList_ptr arguments = req->arguments() ;
355 DEBTRACE( "+++++++++++++++++SalomeNode::inputs+++++++++++++++++" )
358 list<InputPort *>::iterator iter2;
359 for(iter2 = _setOfInputPort.begin(); iter2 != _setOfInputPort.end(); iter2++)
361 InputCorbaPort *p=(InputCorbaPort *)*iter2;
362 DEBTRACE( "port name: " << p->getName() )
363 DEBTRACE( "port kind: " << p->edGetType()->kind() )
364 CORBA::Any* ob=p->getAny();
366 CORBA::TypeCode_var tc;
367 switch(p->edGetType()->kind())
391 //add_value makes a copy of any. Copy will be deleted with request
392 arguments->add_value( p->getName().c_str() , *ob , CORBA::ARG_IN ) ;
397 DEBTRACE( "+++++++++++++++++SalomeNode::outputs+++++++++++++++++" )
398 list<OutputPort *>::iterator iter;
399 for(iter = _setOfOutputPort.begin(); iter != _setOfOutputPort.end(); iter++)
401 OutputCorbaPort *p=(OutputCorbaPort *)*iter;
402 DEBTRACE( "port name: " << p->getName() )
403 DEBTRACE( "port kind: " << p->edGetType()->kind() )
404 CORBA::Any* ob=p->getAnyOut();
405 //add_value makes a copy of any. Copy will be deleted with request
406 arguments->add_value( p->getName().c_str() , *ob , CORBA::ARG_OUT );
410 //if return type is set to void (not mandatory, it's set by default)
411 //the return value will not be marshalled as a return value but
412 //as the first out argument (don't forget to add it as the first output argument)
413 req->set_return_type(CORBA::_tc_void);
415 //req->exceptions()->add(eo::_tc_SALOME_Exception);
417 DEBTRACE( "+++++++++++++++++SalomeNode::calculation+++++++++++++++++" << _method )
419 CORBA::Exception *exc =req->env()->exception();
422 DEBTRACE( "An exception was thrown!" )
423 DEBTRACE( "The raised exception is of Type:" << exc->_name() )
424 throw Exception("Execution problem");
427 DEBTRACE( "++++++++++++SalomeNode::outputs++++++++++++" )
428 int out_param=in_param;
429 for(iter = _setOfOutputPort.begin(); iter != _setOfOutputPort.end(); iter++)
431 OutputCorbaPort *p=(OutputCorbaPort *)*iter;
432 DEBTRACE( "port name: " << p->getName() )
433 DEBTRACE( "port kind: " << p->edGetType()->kind() )
434 DEBTRACE( "port number: " << out_param )
435 CORBA::Any *ob=arguments->item(out_param)->value();
437 switch(p->edGetType()->kind())
458 //OutputPort must copy the input Any(ob).
459 //This Any will be deleted with the request.
460 //Copy is made by the method put.
462 out_param=out_param+1;
465 //Request has been deleted (_var )
466 //All anys given to the request are deleted : don't forget to copy them
467 //if you want to keep them
468 DEBTRACE( "+++++++++++++++++ End SalomeNode::execute: " << getName() << " +++++++++++++++++" )
471 Node *SalomeNode::simpleClone(ComposedNode *father, bool editionOnly) const
473 return new SalomeNode(*this,father);
476 //! Create a SalomeNode with the same component object and no input or output port
478 * \param name : node name
479 * \return a new SalomeNode node
481 ServiceNode* SalomeNode::createNode(const std::string& name)
483 SalomeNode* node=new SalomeNode(name);
484 node->setComponent(_component);