1 // Copyright (C) 2006-2015 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "ElementaryNode.hxx"
21 #include "Runtime.hxx"
22 #include "InputPort.hxx"
23 #include "OutputPort.hxx"
24 #include "ComposedNode.hxx"
25 #include "InputDataStreamPort.hxx"
26 #include "OutputDataStreamPort.hxx"
27 #include "Visitor.hxx"
29 #include "Container.hxx"
34 #include "YacsTrace.hxx"
36 using namespace YACS::ENGINE;
39 /*! \class YACS::ENGINE::ElementaryNode
40 * \brief Base class for all calculation nodes.
42 * This is an abstract class that must be specialized.
47 ElementaryNode::ElementaryNode(const std::string& name):
49 _createDatastreamPorts(false),
50 _multi_port_node(false)
54 ElementaryNode::ElementaryNode(const ElementaryNode& other, ComposedNode *father):Node(other,father)
56 _createDatastreamPorts = other._createDatastreamPorts;
57 _multi_port_node = other._multi_port_node;
58 for(list<InputPort *>::const_iterator iter1=other._setOfInputPort.begin();iter1!=other._setOfInputPort.end();iter1++)
59 _setOfInputPort.push_back((InputPort *)(*iter1)->clone(this));
60 for(list<OutputPort *>::const_iterator iter2=other._setOfOutputPort.begin();iter2!=other._setOfOutputPort.end();iter2++)
61 _setOfOutputPort.push_back((OutputPort *)(*iter2)->clone(this));
62 for(list<InputDataStreamPort *>::const_iterator iter3=other._setOfInputDataStreamPort.begin();iter3!=other._setOfInputDataStreamPort.end();iter3++)
63 _setOfInputDataStreamPort.push_back((InputDataStreamPort *)(*iter3)->clone(this));
64 for(list<OutputDataStreamPort *>::const_iterator iter4=other._setOfOutputDataStreamPort.begin();iter4!=other._setOfOutputDataStreamPort.end();iter4++)
65 _setOfOutputDataStreamPort.push_back((OutputDataStreamPort *)(*iter4)->clone(this));
68 void ElementaryNode::performDuplicationOfPlacement(const Node& other)
72 void ElementaryNode::performShallowDuplicationOfPlacement(const Node& other)
76 ElementaryNode::~ElementaryNode()
78 for(list<InputPort *>::iterator iter1=_setOfInputPort.begin();iter1!=_setOfInputPort.end();iter1++)
80 for(list<OutputPort *>::iterator iter2=_setOfOutputPort.begin();iter2!=_setOfOutputPort.end();iter2++)
82 for(list<InputDataStreamPort *>::iterator iter3=_setOfInputDataStreamPort.begin();iter3!=_setOfInputDataStreamPort.end();iter3++)
84 for(list<OutputDataStreamPort *>::iterator iter4=_setOfOutputDataStreamPort.begin();iter4!=_setOfOutputDataStreamPort.end();iter4++)
88 void ElementaryNode::init(bool start)
90 DEBTRACE("ElementaryNode::init " << getName() << " " << start << " " << _state);
92 for(list<OutputPort *>::iterator iter=_setOfOutputPort.begin();iter!=_setOfOutputPort.end();iter++)
94 for(list<InputPort *>::iterator iter2=_setOfInputPort.begin();iter2!=_setOfInputPort.end();iter2++)
95 (*iter2)->exInit(start);
97 if(_state == YACS::DISABLED)
99 exDisabledState(); // to refresh propagation of DISABLED state
102 setState(YACS::READY);
105 bool ElementaryNode::isDeployable() const
110 ComponentInstance *ElementaryNode::getComponent()
115 const ComponentInstance *ElementaryNode::getComponent() const
120 Container *ElementaryNode::getContainer()
125 YACS::StatesForNode ElementaryNode::getState() const
127 return Node::getState();
130 void ElementaryNode::exUpdateState()
132 DEBTRACE("ElementaryNode::exUpdateState: " << getName() << " " << _state );
133 if(_state==YACS::DISABLED)return;
134 if(_inGate.exIsReady())
135 if(areAllInputPortsValid())
137 if(_state == YACS::READY)
139 else if(_state == YACS::LOADED)
140 setState(YACS::TOACTIVATE);
144 string what("ElementaryNode::exUpdateState : Invalid graph given : Node with name \"");
145 what+=_name; what+="\" ready to run whereas some inputports are not set correctly\nCheck coherence DF/CF";
146 setState(YACS::INTERNALERR);
148 throw Exception(what);
152 int ElementaryNode::getNumberOfInputPorts() const
154 return _setOfInputPort.size();
157 int ElementaryNode::getNumberOfOutputPorts() const
159 return _setOfOutputPort.size();
162 InputPort *ElementaryNode::getInputPort(const std::string& name) const throw(YACS::Exception)
165 return Node::getInputPort(name);
167 catch(Exception& e) {}
168 return getPort<InputPort>(name,_setOfInputPort);
171 OutputPort *ElementaryNode::getOutputPort(const std::string& name) const throw(YACS::Exception)
173 return getPort<OutputPort>(name,_setOfOutputPort);
176 std::set<OutPort *> ElementaryNode::getAllOutPortsLeavingCurrentScope() const
179 list<OutPort *> temp=getSetOfOutPort();
180 for(list<OutPort *>::iterator iter2=temp.begin();iter2!=temp.end();iter2++)
182 set<InPort *> temp2=(*iter2)->edSetInPort();
189 std::set<InPort *> ElementaryNode::getAllInPortsComingFromOutsideOfCurrentScope() const
192 list<InPort *> temp=getSetOfInPort();
193 for(list<InPort *>::iterator iter2=temp.begin();iter2!=temp.end();iter2++)
195 set<OutPort *> temp2=(*iter2)->edSetOutPort();
202 std::vector< std::pair<OutPort *, InPort *> > ElementaryNode::getSetOfLinksLeavingCurrentScope() const
204 vector< pair<OutPort *, InPort *> > ret;
205 std::set<OutPort *> ports=getAllOutPortsLeavingCurrentScope();
206 for(set<OutPort *>::iterator iter2=ports.begin();iter2!=ports.end();iter2++)
208 set<InPort *> temp2=(*iter2)->edSetInPort();
209 for(set<InPort *>::iterator iter3=temp2.begin();iter3!=temp2.end();iter3++)
210 ret.push_back(pair<OutPort *, InPort *>(*iter2,*iter3));
215 std::vector< std::pair<InPort *, OutPort *> > ElementaryNode::getSetOfLinksComingInCurrentScope() const
217 vector< pair<InPort *, OutPort *> > ret;
218 set<InPort *> ports=getAllInPortsComingFromOutsideOfCurrentScope();
219 for(set<InPort *>::iterator iter2=ports.begin();iter2!=ports.end();iter2++)
221 set<OutPort *> temp2=(*iter2)->edSetOutPort();
222 for(set<OutPort *>::iterator iter3=temp2.begin();iter3!=temp2.end();iter3++)
224 std::set<OutPort *> trueOutPorts;
225 (*iter3)->getAllRepresented(trueOutPorts);
226 for(std::set<OutPort *>::iterator iter4=trueOutPorts.begin();iter4!=trueOutPorts.end();++iter4)
227 ret.push_back(pair<InPort *, OutPort *>(*iter2,*iter4));
233 InputDataStreamPort *ElementaryNode::getInputDataStreamPort(const std::string& name) const throw(YACS::Exception)
235 return getPort<InputDataStreamPort>(name,_setOfInputDataStreamPort);
238 OutputDataStreamPort *ElementaryNode::getOutputDataStreamPort(const std::string& name) const throw(YACS::Exception)
240 return getPort<OutputDataStreamPort>(name,_setOfOutputDataStreamPort);
243 void ElementaryNode::edDisconnectAllLinksWithMe()
246 Node::edDisconnectAllLinksWithMe();
249 for(list<InputPort *>::iterator iter=_setOfInputPort.begin();iter!=_setOfInputPort.end();iter++)
250 (*iter)->edRemoveAllLinksLinkedWithMe();
252 for(list<InputDataStreamPort *>::iterator iter2=_setOfInputDataStreamPort.begin();iter2!=_setOfInputDataStreamPort.end();iter2++)
253 (*iter2)->edRemoveAllLinksLinkedWithMe();
256 for(list<OutputPort *>::iterator iter=_setOfOutputPort.begin();iter!=_setOfOutputPort.end();iter++)
257 (*iter)->edRemoveAllLinksLinkedWithMe();
259 for(list<OutputDataStreamPort *>::iterator iter2=_setOfOutputDataStreamPort.begin();iter2!=_setOfOutputDataStreamPort.end();iter2++)
260 (*iter2)->edRemoveAllLinksLinkedWithMe();
264 * checks if all input ports contains a valid data. Used at execution to change the state of the node
268 bool ElementaryNode::areAllInputPortsValid() const
271 for(list<InputPort *>::const_iterator iter=_setOfInputPort.begin();iter!=_setOfInputPort.end();iter++)
273 ret=!(*iter)->isEmpty();
280 This method is used by the "multi" property of ElementaryNode to create
281 to create duplicated input and ouput datastream ports.
284 ElementaryNode::createMultiDatastreamPorts()
286 if (!_createDatastreamPorts)
288 _createDatastreamPorts = true;
289 for(list<InputDataStreamPort *>::const_iterator iter3 = _setOfInputDataStreamPort.begin(); iter3!=_setOfInputDataStreamPort.end();iter3++)
291 InputDataStreamPort * port = *iter3;
292 std::string port_name = port->getName();
293 std::map<std::string,std::string>::iterator it=_propertyMap.find(port_name);
295 if(it != _propertyMap.end())
297 std::string multi_str = it->second;
298 std::istringstream iss(multi_str);
300 throw Exception("Property multi port should be set with a stringified int not an: " + multi_str);
305 addDatastreamPortToInitMultiService(port_name, multi);
306 // Change name of first port
307 port->setName(port_name + "_0");
308 for (int i = 2; i <= multi; i++)
310 InputDataStreamPort * new_port = port->clone(this);
311 std::ostringstream number;
313 new_port->setName(port_name + "_" + number.str());
314 _setOfInputDataStreamPort.push_back(new_port);
315 _multi_port_node = true;
319 for(list<OutputDataStreamPort *>::const_iterator iter4 = _setOfOutputDataStreamPort.begin(); iter4!=_setOfOutputDataStreamPort.end();iter4++)
321 OutputDataStreamPort * port = *iter4;
322 std::string port_name = port->getName();
323 std::map<std::string,std::string>::iterator it=_propertyMap.find(port_name);
325 if(it != _propertyMap.end())
327 std::string multi_str = it->second;
328 std::istringstream iss(multi_str);
330 throw Exception("Property multi port should be set with a stringified int not an: " + multi_str);
335 addDatastreamPortToInitMultiService(port_name, multi);
336 // Change name of first port
337 port->setName(port_name + "_0");
338 for (int i = 2; i <= multi; i++)
340 OutputDataStreamPort * new_port = port->clone(this);
341 std::ostringstream number;
343 new_port->setName(port_name + "_" + number.str());
344 _setOfOutputDataStreamPort.push_back(new_port);
345 _multi_port_node = true;
353 * add this node task to a given set of ready tasks, if this task is ready to activate
356 void ElementaryNode::getReadyTasks(std::vector<Task *>& tasks)
358 DEBTRACE("ElementaryNode::getReadyTasks: " << getName() << " " << _state);
361 std::map<std::string,std::string>::iterator it=_propertyMap.find("multi");
362 if(it != _propertyMap.end())
364 std::string multi_str = it->second;
365 std::istringstream iss(multi_str);
367 throw Exception("Property multi should be set with a stringified int not an: " + multi_str);
370 if(_state==YACS::TOACTIVATE || _state==YACS::TOLOAD || _state==YACS::TORECONNECT)
374 std::map<std::string,std::string>::iterator it=_propertyMap.find("multi_working_dir");
375 if(it != _propertyMap.end())
377 std::string working_dir_base = it->second;
378 std::ostringstream working_dir_stream;
379 working_dir_stream << working_dir_base;
380 working_dir_stream << 1;
381 this->getContainer()->setProperty("workingdir", working_dir_stream.str());
383 tasks.push_back(this);
388 // Check output port -> cannot clone an Elementary Node with Output Ports connected
389 std::list<OutputPort *>::iterator it_output = _setOfOutputPort.begin();
390 for (;it_output != _setOfOutputPort.end(); it_output++)
392 if ((*it_output)->isConnected())
394 throw Exception("Property multi cannot be set on nodes with dataflow output ports connected");
399 std::map<std::string,std::string>::iterator it=_propertyMap.find("multi_working_dir");
400 if(it != _propertyMap.end())
402 std::string working_dir_base = it->second;
403 std::ostringstream working_dir_stream;
404 working_dir_stream << working_dir_base;
405 working_dir_stream << 1;
406 this->getContainer()->setProperty("workingdir", working_dir_stream.str());
408 tasks.push_back(this);
410 // Step 1: Create clones
411 for (int i = 1; i < multi; i++)
414 YACS::ENGINE::ElementaryNode * new_node = static_cast<YACS::ENGINE::ElementaryNode *>(clone(_father, false));
415 new_node->createMultiDatastreamPorts();
419 std::stringstream inamess;
420 inamess << getName() << "_" << i;
422 DEBTRACE("Create clone "<< iname << " of node " << getName());
423 new_node->setName(iname);
425 // For each input port connect it with the original output port
426 std::list<InputPort *> clone_list_inputPorts = new_node->getSetOfInputPort();
427 for(list<InputPort *>::const_iterator iter1=clone_list_inputPorts.begin(); iter1!=clone_list_inputPorts.end(); iter1++)
429 std::string input_port_name = (*iter1)->getName();
430 // Get Port Name in master node
431 InputPort * master_port = getInputPort(input_port_name);
432 for (std::set<OutPort *>::const_iterator itt=master_port->_backLinks.begin(); itt!=master_port->_backLinks.end();itt++)
435 getProc()->edAddDFLink((*itt),(*iter1));
439 // InputDataStreamPort connections
440 std::list<InputDataStreamPort *> clone_list_inputDatastreamPorts = new_node->getSetOfInputDataStreamPort();
441 for(list<InputDataStreamPort *>::iterator iter = clone_list_inputDatastreamPorts.begin(); iter != clone_list_inputDatastreamPorts.end(); iter++)
443 std::string port_name = (*iter)->getName();
444 InputDataStreamPort * orig_port = getInputDataStreamPort(port_name);
446 std::set<OutputDataStreamPort *> connected_ports = orig_port->getConnectedOutputDataStreamPort();
448 // Create datastream ports if not created
449 std::set<OutputDataStreamPort *>::const_iterator iter3;
450 for(iter3=connected_ports.begin();iter3!=connected_ports.end();iter3++)
452 ElementaryNode * node = (ElementaryNode *) (*iter3)->getNode();
453 node->createMultiDatastreamPorts();
455 std::string good_port_name;
456 std::stringstream temp_name;
457 std::string out_name = (*iter3)->getName();
458 out_name.erase(out_name.end()-1);
459 temp_name << out_name << i;
460 good_port_name = temp_name.str();
461 getProc()->edAddLink(node->getOutputDataStreamPort(good_port_name), (*iter));
465 // OutputDataStreamPort connections
466 std::list<OutputDataStreamPort *> clone_list_outputDatastreamPorts = new_node->getSetOfOutputDataStreamPort();
467 for(list<OutputDataStreamPort *>::iterator iter = clone_list_outputDatastreamPorts.begin(); iter != clone_list_outputDatastreamPorts.end(); iter++)
469 std::string port_name = (*iter)->getName();
470 OutputDataStreamPort * orig_port = getOutputDataStreamPort(port_name);
471 std::set<InputDataStreamPort *> dest_input_port = orig_port->_setOfInputDataStreamPort;
472 for(set<InputDataStreamPort *>::iterator dest_port = dest_input_port.begin(); dest_port != dest_input_port.end(); dest_port++)
474 ElementaryNode * dest_node = (ElementaryNode *)(*dest_port)->getNode();
475 // Add InputPort to dest node
476 dest_node->createMultiDatastreamPorts();
478 std::string good_port_name;
479 std::stringstream temp_name;
480 std::string in_name = (*dest_port)->getName();
481 in_name.erase(in_name.end()-1);
482 temp_name << in_name << i;
483 good_port_name = temp_name.str();
484 getProc()->edAddLink((*iter), dest_node->getInputDataStreamPort(good_port_name));
489 new_node->init(false);
490 new_node->exUpdateState();
492 // Set Control Link to done
493 std::list<OutGate *> clone_cl_back = new_node->getInGate()->getBackLinks();
494 for(std::list<OutGate *>::const_iterator iter=clone_cl_back.begin(); iter!=clone_cl_back.end(); iter++)
495 new_node->getInGate()->exNotifyFromPrecursor((*iter));
498 std::map<std::string,std::string>::iterator it=_propertyMap.find("multi_working_dir");
499 if(it != _propertyMap.end())
501 std::string working_dir_base = it->second;
502 std::ostringstream working_dir_stream;
503 working_dir_stream << working_dir_base;
504 working_dir_stream << i+1;
505 new_node->getContainer()->setProperty("workingdir", working_dir_stream.str());
507 tasks.push_back(new_node);
514 * remove port from node at edition. Ports are typed.
517 void ElementaryNode::edRemovePort(Port *port) throw(YACS::Exception)
519 DEBTRACE("ElementaryNode::edRemovePort ");
520 if(port->getNode()!=this)
521 throw Exception("ElementaryNode::edRemovePort : Port is not held by this node");
522 if(InputPort *p=dynamic_cast<InputPort *>(port))
523 edRemovePortTypedFromSet<InputPort>(p,_setOfInputPort);
524 else if(OutputPort *p=dynamic_cast<OutputPort *>(port))
525 edRemovePortTypedFromSet<OutputPort>(p,_setOfOutputPort);
526 else if(InputDataStreamPort *p=dynamic_cast<InputDataStreamPort *>(port))
527 edRemovePortTypedFromSet<InputDataStreamPort>(p,_setOfInputDataStreamPort);
528 else if(OutputDataStreamPort *p=dynamic_cast<OutputDataStreamPort *>(port))
529 edRemovePortTypedFromSet<OutputDataStreamPort>(p,_setOfOutputDataStreamPort);
531 throw Exception("ElementaryNode::edRemovePort : unknown port type");
537 * @return a set with only this node. (Same method in composed nodes)
540 list<ElementaryNode *> ElementaryNode::getRecursiveConstituents() const
542 list<ElementaryNode *> ret;
543 ret.push_back((ElementaryNode *)this);
547 //! Get the progress weight for all elementary nodes
549 * Only elementary nodes have weight. At this stage weight is 0 or 1 (it can be modified later following
550 * the kind of father)
552 list<ProgressWeight> ElementaryNode::getProgressWeight() const
554 list<ProgressWeight> ret;
555 ProgressWeight myWeight;
556 myWeight.weightTotal=1;
557 if (getState() == YACS::DONE)
558 myWeight.weightDone=1;
560 myWeight.weightDone=0;
561 ret.push_back(myWeight);
565 Node *ElementaryNode::getChildByName(const std::string& name) const throw(YACS::Exception)
567 string what("ElementaryNode does not agregate any nodes particullary node with name "); what+=name;
568 throw Exception(what);
571 void ElementaryNode::checkBasicConsistency() const throw(YACS::Exception)
573 DEBTRACE("ElementaryNode::checkBasicConsistency");
574 list<InputPort *>::const_iterator iter;
575 for(iter=_setOfInputPort.begin();iter!=_setOfInputPort.end();iter++)
576 (*iter)->checkBasicConsistency();
579 ComposedNode *ElementaryNode::getDynClonerIfExists(const ComposedNode *levelToStop) const
581 for(ComposedNode *iter=_father;iter!=levelToStop && iter!=0; iter=iter->_father)
582 if(!iter->isPlacementPredictableB4Run())
587 InputPort *ElementaryNode::createInputPort(const std::string& inputPortName, TypeCode* type)
589 return getRuntime()->createInputPort(inputPortName, _implementation, this, type);
593 * the input port is also published recursively in ancestors because it may be visible from everywhere.
594 * WARNING: CHECK CASE OF BLOC: ONLY INPUT PORTS NOT INTERNALLY CONNECTED MUST BE VISIBLE.
597 InputPort *ElementaryNode::edAddInputPort(const std::string& inputPortName, TypeCode* type) throw(YACS::Exception)
600 // Cannot create an InputPort defined with InPropertyPort name.
601 if (inputPortName == "__InPropertyPort__Node__YACS_")
603 string what("ElementaryNode::edAddInputPort: it is forbidden to add an InputPort with the name __InPropertyPort__Node__YACS_\"");
604 throw Exception(what);
608 if (edCheckAddPort<InputPort, TypeCode*>(inputPortName,_setOfInputPort,type))
610 ret = createInputPort(inputPortName, type);
611 _setOfInputPort.push_back(ret);
614 ComposedNode *iter=_father;
622 void ElementaryNode::edOrderInputPorts(const std::list<InputPort*>& ports)
624 std::set<InputPort *> s1;
625 std::set<InputPort *> s2;
626 for(list<InputPort *>::const_iterator it=_setOfInputPort.begin();it != _setOfInputPort.end();it++)
628 for(list<InputPort *>::const_iterator it=ports.begin();it != ports.end();it++)
632 throw Exception("ElementaryNode::edOrderInputPorts : port list must contain same ports as existing ones");
634 _setOfInputPort.clear();
635 for(list<InputPort *>::const_iterator it=ports.begin();it != ports.end();it++)
636 _setOfInputPort.push_back(*it);
639 void ElementaryNode::edOrderOutputPorts(const std::list<OutputPort*>& ports)
641 std::set<OutputPort *> s1;
642 std::set<OutputPort *> s2;
643 for(list<OutputPort *>::const_iterator it=_setOfOutputPort.begin();it != _setOfOutputPort.end();it++)
645 for(list<OutputPort *>::const_iterator it=ports.begin();it != ports.end();it++)
649 throw Exception("ElementaryNode::edOrderOutputPorts : port list must contain same ports as existing ones");
651 _setOfOutputPort.clear();
652 for(list<OutputPort *>::const_iterator it=ports.begin();it != ports.end();it++)
653 _setOfOutputPort.push_back(*it);
656 OutputPort *ElementaryNode::createOutputPort(const std::string& outputPortName, TypeCode* type)
658 return getRuntime()->createOutputPort(outputPortName, _implementation, this, type);
662 * TO SOLVE : The output port is not published in father. Father must create an output port.
663 * for now, publication is done the same way as input ports
666 OutputPort *ElementaryNode::edAddOutputPort(const std::string& outputPortName, TypeCode* type) throw(YACS::Exception)
669 if (edCheckAddPort<OutputPort, TypeCode*>(outputPortName,_setOfOutputPort,type))
671 ret = createOutputPort(outputPortName, type);
672 _setOfOutputPort.push_back(ret);
675 ComposedNode *iter=_father;
683 InputDataStreamPort *ElementaryNode::createInputDataStreamPort(const std::string& inputPortDSName, TypeCode* type)
685 return getRuntime()->createInputDataStreamPort(inputPortDSName, this, type);
688 InputDataStreamPort *ElementaryNode::edAddInputDataStreamPort(const std::string& inputPortDSName, TypeCode* type) throw(YACS::Exception)
690 InputDataStreamPort *ret = 0;
691 if (edCheckAddPort<InputDataStreamPort, TypeCode*>(inputPortDSName,_setOfInputDataStreamPort,type))
693 ret = createInputDataStreamPort(inputPortDSName, type);
694 _setOfInputDataStreamPort.push_back(ret);
700 OutputDataStreamPort *ElementaryNode::createOutputDataStreamPort(const std::string& outputPortDSName, TypeCode* type)
702 return getRuntime()->createOutputDataStreamPort(outputPortDSName, this, type);
705 OutputDataStreamPort *ElementaryNode::edAddOutputDataStreamPort(const std::string& outputPortDSName, TypeCode* type) throw(YACS::Exception)
707 OutputDataStreamPort *ret = 0;
708 if (edCheckAddPort<OutputDataStreamPort, TypeCode*>(outputPortDSName,_setOfOutputDataStreamPort,type))
710 ret = createOutputDataStreamPort(outputPortDSName, type);
711 _setOfOutputDataStreamPort.push_back(ret);
718 * get the input port name used by the current node (see composed nodes)
721 string ElementaryNode::getInPortName(const InPort * inPort) const throw(YACS::Exception)
723 Node *node = inPort->getNode();
726 string what("InputPort "); what += inPort->getName(); what += " does not belong to node "; what += node->getName();
727 throw Exception(what);
729 return inPort->getName();
732 string ElementaryNode::getOutPortName(const OutPort *outPort) const throw(YACS::Exception)
734 Node *node = outPort->getNode();
737 string what("OutputPort "); what += outPort->getName(); what += " does not belong to node "; what += node->getName();
738 throw Exception(what);
740 return outPort->getName();
743 void ElementaryNode::begin()
748 bool ElementaryNode::isReady()
750 return _state==TOACTIVATE;
753 void ElementaryNode::finished()
757 void ElementaryNode::aborted()
762 //! Notify this node that it is loaded
764 * When an elementary node has been loaded
765 * It is ready to be connected
768 void ElementaryNode::loaded()
772 //! Notify this node that it is connected
774 * When an elementary node has been connected it goes to TOACTIVATE state
775 * It is then ready to be executed
778 void ElementaryNode::connected()
780 if(_inGate.exIsReady())
781 if(areAllInputPortsValid())
783 setState(TOACTIVATE);
789 void ElementaryNode::accept(Visitor *visitor)
791 visitor->visitElementaryNode(this);
794 //! Give a description of error when node status is ERROR
798 std::string ElementaryNode::getErrorDetails()
800 return _errorDetails;
803 void ElementaryNode::edUpdateState()
805 DEBTRACE("ElementaryNode::edUpdateState: " << getName());
806 YACS::StatesForNode state=YACS::READY;
809 checkBasicConsistency();
815 _errorDetails=e.what();
817 DEBTRACE("ElementaryNode::edUpdateState: " << _errorDetails);
823 //! Put this node into TOLOAD state when possible
825 * Can be called by another ElementaryNode that is connected to this one by a datastream link
826 * These 2 nodes must be loaded at the same time as they are coupled
827 * It's the other node which requests this node loading
829 void ElementaryNode::ensureLoading()
831 DEBTRACE("ElementaryNode::ensureLoading: " << getName());
832 if(_state != YACS::READY)
834 setState(YACS::TOLOAD);
836 // request loading for all nodes connected to this one by datastream link
837 // Be careful that nodes can be connected in a loop. Put first this node in TOLOAD state to break the loop
838 std::list<OutputDataStreamPort *>::iterator iterout;
839 for(iterout = _setOfOutputDataStreamPort.begin(); iterout != _setOfOutputDataStreamPort.end(); iterout++)
841 OutputDataStreamPort *port=(OutputDataStreamPort *)*iterout;
842 std::set<InPort *> ports=port->edSetInPort();
843 std::set<InPort *>::iterator iter;
844 for(iter=ports.begin();iter != ports.end(); iter++)
846 Node* node= (*iter)->getNode();
847 node->ensureLoading();
850 std::list<InputDataStreamPort *>::iterator iterin;
851 for(iterin = _setOfInputDataStreamPort.begin(); iterin != _setOfInputDataStreamPort.end(); iterin++)
853 InputDataStreamPort *port=(InputDataStreamPort *)*iterin;
854 std::set<OutPort *> ports=port->edSetOutPort();
855 std::set<OutPort *>::iterator iter;
856 for(iter=ports.begin();iter != ports.end(); iter++)
858 Node* node= (*iter)->getNode();
859 node->ensureLoading();
864 //! Calls getCoupledNodes for Task interface
865 void ElementaryNode::getCoupledTasks(std::set<Task*>& coupledSet)
867 getCoupledNodes(coupledSet);
870 //! Put all nodes that are coupled to this node in coupledSet
871 void ElementaryNode::getCoupledNodes(std::set<Task*>& coupledSet)
873 if(coupledSet.find(this) != coupledSet.end())return;
875 coupledSet.insert(this);
877 std::list<OutputDataStreamPort *>::iterator iterout;
878 for(iterout = _setOfOutputDataStreamPort.begin(); iterout != _setOfOutputDataStreamPort.end(); iterout++)
880 OutputDataStreamPort *port=(OutputDataStreamPort *)*iterout;
881 std::set<InPort *> ports=port->edSetInPort();
882 std::set<InPort *>::iterator iter;
883 for(iter=ports.begin();iter != ports.end(); iter++)
885 Node* node= (*iter)->getNode();
886 node->getCoupledNodes(coupledSet);