1 // Copyright (C) 2006-2016 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::initCommonPartWithoutStateManagement(bool start)
90 for(list<OutputPort *>::iterator iter=_setOfOutputPort.begin();iter!=_setOfOutputPort.end();iter++)
92 for(list<InputPort *>::iterator iter2=_setOfInputPort.begin();iter2!=_setOfInputPort.end();iter2++)
93 (*iter2)->exInit(start);
97 void ElementaryNode::init(bool start)
99 DEBTRACE("ElementaryNode::init " << getName() << " " << start << " " << _state);
100 initCommonPartWithoutStateManagement(start);
101 if(_state == YACS::DISABLED)
103 exDisabledState(); // to refresh propagation of DISABLED state
106 setState(YACS::READY);
109 bool ElementaryNode::isDeployable() const
114 ComponentInstance *ElementaryNode::getComponent()
119 const ComponentInstance *ElementaryNode::getComponent() const
124 Container *ElementaryNode::getContainer()
129 YACS::StatesForNode ElementaryNode::getState() const
131 return Node::getState();
134 void ElementaryNode::exUpdateState()
136 DEBTRACE("ElementaryNode::exUpdateState: " << getName() << " " << _state );
137 if(_state==YACS::DISABLED)return;
138 if(_inGate.exIsReady())
139 if(areAllInputPortsValid())
141 if(_state == YACS::READY)
143 else if(_state == YACS::LOADED)
144 setState(YACS::TOACTIVATE);
148 string what("ElementaryNode::exUpdateState : Invalid graph given : Node with name \"");
149 what+=_name; what+="\" ready to run whereas some inputports are not set correctly\nCheck coherence DF/CF";
150 setState(YACS::INTERNALERR);
152 throw Exception(what);
156 int ElementaryNode::getNumberOfInputPorts() const
158 return _setOfInputPort.size();
161 int ElementaryNode::getNumberOfOutputPorts() const
163 return _setOfOutputPort.size();
166 InputPort *ElementaryNode::getInputPort(const std::string& name) const throw(YACS::Exception)
169 return Node::getInputPort(name);
171 catch(Exception& e) {}
172 return getPort<InputPort>(name,_setOfInputPort);
175 OutputPort *ElementaryNode::getOutputPort(const std::string& name) const throw(YACS::Exception)
177 return getPort<OutputPort>(name,_setOfOutputPort);
180 std::set<OutPort *> ElementaryNode::getAllOutPortsLeavingCurrentScope() const
183 list<OutPort *> temp=getSetOfOutPort();
184 for(list<OutPort *>::iterator iter2=temp.begin();iter2!=temp.end();iter2++)
186 set<InPort *> temp2=(*iter2)->edSetInPort();
193 std::set<InPort *> ElementaryNode::getAllInPortsComingFromOutsideOfCurrentScope() const
196 list<InPort *> temp=getSetOfInPort();
197 for(list<InPort *>::iterator iter2=temp.begin();iter2!=temp.end();iter2++)
199 set<OutPort *> temp2=(*iter2)->edSetOutPort();
206 std::vector< std::pair<OutPort *, InPort *> > ElementaryNode::getSetOfLinksLeavingCurrentScope() const
208 vector< pair<OutPort *, InPort *> > ret;
209 std::set<OutPort *> ports=getAllOutPortsLeavingCurrentScope();
210 for(set<OutPort *>::iterator iter2=ports.begin();iter2!=ports.end();iter2++)
212 set<InPort *> temp2=(*iter2)->edSetInPort();
213 for(set<InPort *>::iterator iter3=temp2.begin();iter3!=temp2.end();iter3++)
214 ret.push_back(pair<OutPort *, InPort *>(*iter2,*iter3));
219 std::vector< std::pair<InPort *, OutPort *> > ElementaryNode::getSetOfLinksComingInCurrentScope() const
221 vector< pair<InPort *, OutPort *> > ret;
222 set<InPort *> ports=getAllInPortsComingFromOutsideOfCurrentScope();
223 for(set<InPort *>::iterator iter2=ports.begin();iter2!=ports.end();iter2++)
225 set<OutPort *> temp2=(*iter2)->edSetOutPort();
226 for(set<OutPort *>::iterator iter3=temp2.begin();iter3!=temp2.end();iter3++)
228 std::set<OutPort *> trueOutPorts;
229 (*iter3)->getAllRepresented(trueOutPorts);
230 for(std::set<OutPort *>::iterator iter4=trueOutPorts.begin();iter4!=trueOutPorts.end();++iter4)
231 ret.push_back(pair<InPort *, OutPort *>(*iter2,*iter4));
237 InputDataStreamPort *ElementaryNode::getInputDataStreamPort(const std::string& name) const throw(YACS::Exception)
239 return getPort<InputDataStreamPort>(name,_setOfInputDataStreamPort);
242 OutputDataStreamPort *ElementaryNode::getOutputDataStreamPort(const std::string& name) const throw(YACS::Exception)
244 return getPort<OutputDataStreamPort>(name,_setOfOutputDataStreamPort);
247 void ElementaryNode::edDisconnectAllLinksWithMe()
250 Node::edDisconnectAllLinksWithMe();
253 for(list<InputPort *>::iterator iter=_setOfInputPort.begin();iter!=_setOfInputPort.end();iter++)
254 (*iter)->edRemoveAllLinksLinkedWithMe();
256 for(list<InputDataStreamPort *>::iterator iter2=_setOfInputDataStreamPort.begin();iter2!=_setOfInputDataStreamPort.end();iter2++)
257 (*iter2)->edRemoveAllLinksLinkedWithMe();
260 for(list<OutputPort *>::iterator iter=_setOfOutputPort.begin();iter!=_setOfOutputPort.end();iter++)
261 (*iter)->edRemoveAllLinksLinkedWithMe();
263 for(list<OutputDataStreamPort *>::iterator iter2=_setOfOutputDataStreamPort.begin();iter2!=_setOfOutputDataStreamPort.end();iter2++)
264 (*iter2)->edRemoveAllLinksLinkedWithMe();
268 * checks if all input ports contains a valid data. Used at execution to change the state of the node
272 bool ElementaryNode::areAllInputPortsValid() const
275 for(list<InputPort *>::const_iterator iter=_setOfInputPort.begin();iter!=_setOfInputPort.end();iter++)
277 ret=!(*iter)->isEmpty();
284 This method is used by the "multi" property of ElementaryNode to create
285 to create duplicated input and ouput datastream ports.
288 ElementaryNode::createMultiDatastreamPorts()
290 if (!_createDatastreamPorts)
292 _createDatastreamPorts = true;
293 for(list<InputDataStreamPort *>::const_iterator iter3 = _setOfInputDataStreamPort.begin(); iter3!=_setOfInputDataStreamPort.end();iter3++)
295 InputDataStreamPort * port = *iter3;
296 std::string port_name = port->getName();
297 std::map<std::string,std::string>::iterator it=_propertyMap.find(port_name);
299 if(it != _propertyMap.end())
301 std::string multi_str = it->second;
302 std::istringstream iss(multi_str);
304 throw Exception("Property multi port should be set with a stringified int not an: " + multi_str);
309 addDatastreamPortToInitMultiService(port_name, multi);
310 // Change name of first port
311 port->setName(port_name + "_0");
312 for (int i = 2; i <= multi; i++)
314 InputDataStreamPort * new_port = port->clone(this);
315 std::ostringstream number;
317 new_port->setName(port_name + "_" + number.str());
318 _setOfInputDataStreamPort.push_back(new_port);
319 _multi_port_node = true;
323 for(list<OutputDataStreamPort *>::const_iterator iter4 = _setOfOutputDataStreamPort.begin(); iter4!=_setOfOutputDataStreamPort.end();iter4++)
325 OutputDataStreamPort * port = *iter4;
326 std::string port_name = port->getName();
327 std::map<std::string,std::string>::iterator it=_propertyMap.find(port_name);
329 if(it != _propertyMap.end())
331 std::string multi_str = it->second;
332 std::istringstream iss(multi_str);
334 throw Exception("Property multi port should be set with a stringified int not an: " + multi_str);
339 addDatastreamPortToInitMultiService(port_name, multi);
340 // Change name of first port
341 port->setName(port_name + "_0");
342 for (int i = 2; i <= multi; i++)
344 OutputDataStreamPort * new_port = port->clone(this);
345 std::ostringstream number;
347 new_port->setName(port_name + "_" + number.str());
348 _setOfOutputDataStreamPort.push_back(new_port);
349 _multi_port_node = true;
357 * add this node task to a given set of ready tasks, if this task is ready to activate
360 void ElementaryNode::getReadyTasks(std::vector<Task *>& tasks)
362 DEBTRACE("ElementaryNode::getReadyTasks: " << getName() << " " << _state);
365 std::map<std::string,std::string>::iterator it=_propertyMap.find("multi");
366 if(it != _propertyMap.end())
368 std::string multi_str = it->second;
369 std::istringstream iss(multi_str);
371 throw Exception("Property multi should be set with a stringified int not an: " + multi_str);
374 if(_state==YACS::TOACTIVATE || _state==YACS::TOLOAD || _state==YACS::TORECONNECT)
378 std::map<std::string,std::string>::iterator it=_propertyMap.find("multi_working_dir");
379 if(it != _propertyMap.end())
381 std::string working_dir_base = it->second;
382 std::ostringstream working_dir_stream;
383 working_dir_stream << working_dir_base;
384 working_dir_stream << 1;
385 this->getContainer()->setProperty("workingdir", working_dir_stream.str());
387 tasks.push_back(this);
392 // Check output port -> cannot clone an Elementary Node with Output Ports connected
393 std::list<OutputPort *>::iterator it_output = _setOfOutputPort.begin();
394 for (;it_output != _setOfOutputPort.end(); it_output++)
396 if ((*it_output)->isConnected())
398 throw Exception("Property multi cannot be set on nodes with dataflow output ports connected");
403 std::map<std::string,std::string>::iterator it=_propertyMap.find("multi_working_dir");
404 if(it != _propertyMap.end())
406 std::string working_dir_base = it->second;
407 std::ostringstream working_dir_stream;
408 working_dir_stream << working_dir_base;
409 working_dir_stream << 1;
410 this->getContainer()->setProperty("workingdir", working_dir_stream.str());
412 tasks.push_back(this);
414 // Step 1: Create clones
415 for (int i = 1; i < multi; i++)
418 YACS::ENGINE::ElementaryNode * new_node = static_cast<YACS::ENGINE::ElementaryNode *>(clone(_father, false));
419 new_node->createMultiDatastreamPorts();
423 std::stringstream inamess;
424 inamess << getName() << "_" << i;
426 DEBTRACE("Create clone "<< iname << " of node " << getName());
427 new_node->setName(iname);
429 // For each input port connect it with the original output port
430 std::list<InputPort *> clone_list_inputPorts = new_node->getSetOfInputPort();
431 for(list<InputPort *>::const_iterator iter1=clone_list_inputPorts.begin(); iter1!=clone_list_inputPorts.end(); iter1++)
433 std::string input_port_name = (*iter1)->getName();
434 // Get Port Name in master node
435 InputPort * master_port = getInputPort(input_port_name);
436 for (std::set<OutPort *>::const_iterator itt=master_port->_backLinks.begin(); itt!=master_port->_backLinks.end();itt++)
439 getProc()->edAddDFLink((*itt),(*iter1));
443 // InputDataStreamPort connections
444 std::list<InputDataStreamPort *> clone_list_inputDatastreamPorts = new_node->getSetOfInputDataStreamPort();
445 for(list<InputDataStreamPort *>::iterator iter = clone_list_inputDatastreamPorts.begin(); iter != clone_list_inputDatastreamPorts.end(); iter++)
447 std::string port_name = (*iter)->getName();
448 InputDataStreamPort * orig_port = getInputDataStreamPort(port_name);
450 std::set<OutputDataStreamPort *> connected_ports = orig_port->getConnectedOutputDataStreamPort();
452 // Create datastream ports if not created
453 std::set<OutputDataStreamPort *>::const_iterator iter3;
454 for(iter3=connected_ports.begin();iter3!=connected_ports.end();iter3++)
456 ElementaryNode * node = (ElementaryNode *) (*iter3)->getNode();
457 node->createMultiDatastreamPorts();
459 std::string good_port_name;
460 std::stringstream temp_name;
461 std::string out_name = (*iter3)->getName();
462 out_name.erase(out_name.end()-1);
463 temp_name << out_name << i;
464 good_port_name = temp_name.str();
465 getProc()->edAddLink(node->getOutputDataStreamPort(good_port_name), (*iter));
469 // OutputDataStreamPort connections
470 std::list<OutputDataStreamPort *> clone_list_outputDatastreamPorts = new_node->getSetOfOutputDataStreamPort();
471 for(list<OutputDataStreamPort *>::iterator iter = clone_list_outputDatastreamPorts.begin(); iter != clone_list_outputDatastreamPorts.end(); iter++)
473 std::string port_name = (*iter)->getName();
474 OutputDataStreamPort * orig_port = getOutputDataStreamPort(port_name);
475 std::set<InputDataStreamPort *> dest_input_port = orig_port->_setOfInputDataStreamPort;
476 for(set<InputDataStreamPort *>::iterator dest_port = dest_input_port.begin(); dest_port != dest_input_port.end(); dest_port++)
478 ElementaryNode * dest_node = (ElementaryNode *)(*dest_port)->getNode();
479 // Add InputPort to dest node
480 dest_node->createMultiDatastreamPorts();
482 std::string good_port_name;
483 std::stringstream temp_name;
484 std::string in_name = (*dest_port)->getName();
485 in_name.erase(in_name.end()-1);
486 temp_name << in_name << i;
487 good_port_name = temp_name.str();
488 getProc()->edAddLink((*iter), dest_node->getInputDataStreamPort(good_port_name));
493 new_node->init(false);
494 new_node->exUpdateState();
496 // Set Control Link to done
497 std::list<OutGate *> clone_cl_back = new_node->getInGate()->getBackLinks();
498 for(std::list<OutGate *>::const_iterator iter=clone_cl_back.begin(); iter!=clone_cl_back.end(); iter++)
499 new_node->getInGate()->exNotifyFromPrecursor((*iter));
502 std::map<std::string,std::string>::iterator it=_propertyMap.find("multi_working_dir");
503 if(it != _propertyMap.end())
505 std::string working_dir_base = it->second;
506 std::ostringstream working_dir_stream;
507 working_dir_stream << working_dir_base;
508 working_dir_stream << i+1;
509 new_node->getContainer()->setProperty("workingdir", working_dir_stream.str());
511 tasks.push_back(new_node);
518 * remove port from node at edition. Ports are typed.
521 void ElementaryNode::edRemovePort(Port *port) throw(YACS::Exception)
523 DEBTRACE("ElementaryNode::edRemovePort ");
524 if(port->getNode()!=this)
525 throw Exception("ElementaryNode::edRemovePort : Port is not held by this node");
526 if(InputPort *p=dynamic_cast<InputPort *>(port))
527 edRemovePortTypedFromSet<InputPort>(p,_setOfInputPort);
528 else if(OutputPort *p=dynamic_cast<OutputPort *>(port))
529 edRemovePortTypedFromSet<OutputPort>(p,_setOfOutputPort);
530 else if(InputDataStreamPort *p=dynamic_cast<InputDataStreamPort *>(port))
531 edRemovePortTypedFromSet<InputDataStreamPort>(p,_setOfInputDataStreamPort);
532 else if(OutputDataStreamPort *p=dynamic_cast<OutputDataStreamPort *>(port))
533 edRemovePortTypedFromSet<OutputDataStreamPort>(p,_setOfOutputDataStreamPort);
535 throw Exception("ElementaryNode::edRemovePort : unknown port type");
541 * @return a set with only this node. (Same method in composed nodes)
544 list<ElementaryNode *> ElementaryNode::getRecursiveConstituents() const
546 list<ElementaryNode *> ret;
547 ret.push_back((ElementaryNode *)this);
551 //! Get the progress weight for all elementary nodes
553 * Only elementary nodes have weight. At this stage weight is 0 or 1 (it can be modified later following
554 * the kind of father)
556 list<ProgressWeight> ElementaryNode::getProgressWeight() const
558 list<ProgressWeight> ret;
559 ProgressWeight myWeight;
560 myWeight.weightTotal=1;
561 if (getState() == YACS::DONE)
562 myWeight.weightDone=1;
564 myWeight.weightDone=0;
565 ret.push_back(myWeight);
569 Node *ElementaryNode::getChildByName(const std::string& name) const throw(YACS::Exception)
571 string what("ElementaryNode does not agregate any nodes particullary node with name "); what+=name;
572 throw Exception(what);
575 void ElementaryNode::checkBasicConsistency() const throw(YACS::Exception)
577 DEBTRACE("ElementaryNode::checkBasicConsistency");
578 list<InputPort *>::const_iterator iter;
579 for(iter=_setOfInputPort.begin();iter!=_setOfInputPort.end();iter++)
580 (*iter)->checkBasicConsistency();
583 ComposedNode *ElementaryNode::getDynClonerIfExists(const ComposedNode *levelToStop) const
585 for(ComposedNode *iter=_father;iter!=levelToStop && iter!=0; iter=iter->_father)
586 if(!iter->isPlacementPredictableB4Run())
591 InputPort *ElementaryNode::createInputPort(const std::string& inputPortName, TypeCode* type)
593 return getRuntime()->createInputPort(inputPortName, _implementation, this, type);
597 * the input port is also published recursively in ancestors because it may be visible from everywhere.
598 * WARNING: CHECK CASE OF BLOC: ONLY INPUT PORTS NOT INTERNALLY CONNECTED MUST BE VISIBLE.
601 InputPort *ElementaryNode::edAddInputPort(const std::string& inputPortName, TypeCode* type) throw(YACS::Exception)
604 // Cannot create an InputPort defined with InPropertyPort name.
605 if (inputPortName == "__InPropertyPort__Node__YACS_")
607 string what("ElementaryNode::edAddInputPort: it is forbidden to add an InputPort with the name __InPropertyPort__Node__YACS_\"");
608 throw Exception(what);
612 if (edCheckAddPort<InputPort, TypeCode*>(inputPortName,_setOfInputPort,type))
614 ret = createInputPort(inputPortName, type);
615 _setOfInputPort.push_back(ret);
618 ComposedNode *iter=_father;
626 void ElementaryNode::edOrderInputPorts(const std::list<InputPort*>& ports)
628 std::set<InputPort *> s1;
629 std::set<InputPort *> s2;
630 for(list<InputPort *>::const_iterator it=_setOfInputPort.begin();it != _setOfInputPort.end();it++)
632 for(list<InputPort *>::const_iterator it=ports.begin();it != ports.end();it++)
636 throw Exception("ElementaryNode::edOrderInputPorts : port list must contain same ports as existing ones");
638 _setOfInputPort.clear();
639 for(list<InputPort *>::const_iterator it=ports.begin();it != ports.end();it++)
640 _setOfInputPort.push_back(*it);
643 void ElementaryNode::edOrderOutputPorts(const std::list<OutputPort*>& ports)
645 std::set<OutputPort *> s1;
646 std::set<OutputPort *> s2;
647 for(list<OutputPort *>::const_iterator it=_setOfOutputPort.begin();it != _setOfOutputPort.end();it++)
649 for(list<OutputPort *>::const_iterator it=ports.begin();it != ports.end();it++)
653 throw Exception("ElementaryNode::edOrderOutputPorts : port list must contain same ports as existing ones");
655 _setOfOutputPort.clear();
656 for(list<OutputPort *>::const_iterator it=ports.begin();it != ports.end();it++)
657 _setOfOutputPort.push_back(*it);
660 OutputPort *ElementaryNode::createOutputPort(const std::string& outputPortName, TypeCode* type)
662 return getRuntime()->createOutputPort(outputPortName, _implementation, this, type);
666 * TO SOLVE : The output port is not published in father. Father must create an output port.
667 * for now, publication is done the same way as input ports
670 OutputPort *ElementaryNode::edAddOutputPort(const std::string& outputPortName, TypeCode* type) throw(YACS::Exception)
673 if (edCheckAddPort<OutputPort, TypeCode*>(outputPortName,_setOfOutputPort,type))
675 ret = createOutputPort(outputPortName, type);
676 _setOfOutputPort.push_back(ret);
679 ComposedNode *iter=_father;
687 InputDataStreamPort *ElementaryNode::createInputDataStreamPort(const std::string& inputPortDSName, TypeCode* type)
689 return getRuntime()->createInputDataStreamPort(inputPortDSName, this, type);
692 InputDataStreamPort *ElementaryNode::edAddInputDataStreamPort(const std::string& inputPortDSName, TypeCode* type) throw(YACS::Exception)
694 InputDataStreamPort *ret = 0;
695 if (edCheckAddPort<InputDataStreamPort, TypeCode*>(inputPortDSName,_setOfInputDataStreamPort,type))
697 ret = createInputDataStreamPort(inputPortDSName, type);
698 _setOfInputDataStreamPort.push_back(ret);
704 OutputDataStreamPort *ElementaryNode::createOutputDataStreamPort(const std::string& outputPortDSName, TypeCode* type)
706 return getRuntime()->createOutputDataStreamPort(outputPortDSName, this, type);
709 OutputDataStreamPort *ElementaryNode::edAddOutputDataStreamPort(const std::string& outputPortDSName, TypeCode* type) throw(YACS::Exception)
711 OutputDataStreamPort *ret = 0;
712 if (edCheckAddPort<OutputDataStreamPort, TypeCode*>(outputPortDSName,_setOfOutputDataStreamPort,type))
714 ret = createOutputDataStreamPort(outputPortDSName, type);
715 _setOfOutputDataStreamPort.push_back(ret);
722 * get the input port name used by the current node (see composed nodes)
725 string ElementaryNode::getInPortName(const InPort * inPort) const throw(YACS::Exception)
727 Node *node = inPort->getNode();
730 string what("InputPort "); what += inPort->getName(); what += " does not belong to node "; what += node->getName();
731 throw Exception(what);
733 return inPort->getName();
736 string ElementaryNode::getOutPortName(const OutPort *outPort) const throw(YACS::Exception)
738 Node *node = outPort->getNode();
741 string what("OutputPort "); what += outPort->getName(); what += " does not belong to node "; what += node->getName();
742 throw Exception(what);
744 return outPort->getName();
747 void ElementaryNode::begin()
752 bool ElementaryNode::isReady()
754 return _state==TOACTIVATE;
757 void ElementaryNode::finished()
761 void ElementaryNode::aborted()
766 //! Notify this node that it is loaded
768 * When an elementary node has been loaded
769 * It is ready to be connected
772 void ElementaryNode::loaded()
776 //! Notify this node that it is connected
778 * When an elementary node has been connected it goes to TOACTIVATE state
779 * It is then ready to be executed
782 void ElementaryNode::connected()
784 if(_inGate.exIsReady())
785 if(areAllInputPortsValid())
787 setState(TOACTIVATE);
793 void ElementaryNode::accept(Visitor *visitor)
795 visitor->visitElementaryNode(this);
798 //! Give a description of error when node status is ERROR
802 std::string ElementaryNode::getErrorDetails()
804 return _errorDetails;
807 void ElementaryNode::edUpdateState()
809 DEBTRACE("ElementaryNode::edUpdateState: " << getName());
810 YACS::StatesForNode state=YACS::READY;
813 checkBasicConsistency();
819 _errorDetails=e.what();
821 DEBTRACE("ElementaryNode::edUpdateState: " << _errorDetails);
827 //! Put this node into TOLOAD state when possible
829 * Can be called by another ElementaryNode that is connected to this one by a datastream link
830 * These 2 nodes must be loaded at the same time as they are coupled
831 * It's the other node which requests this node loading
833 void ElementaryNode::ensureLoading()
835 DEBTRACE("ElementaryNode::ensureLoading: " << getName());
836 if(_state != YACS::READY)
838 setState(YACS::TOLOAD);
840 // request loading for all nodes connected to this one by datastream link
841 // Be careful that nodes can be connected in a loop. Put first this node in TOLOAD state to break the loop
842 std::list<OutputDataStreamPort *>::iterator iterout;
843 for(iterout = _setOfOutputDataStreamPort.begin(); iterout != _setOfOutputDataStreamPort.end(); iterout++)
845 OutputDataStreamPort *port=(OutputDataStreamPort *)*iterout;
846 std::set<InPort *> ports=port->edSetInPort();
847 std::set<InPort *>::iterator iter;
848 for(iter=ports.begin();iter != ports.end(); iter++)
850 Node* node= (*iter)->getNode();
851 node->ensureLoading();
854 std::list<InputDataStreamPort *>::iterator iterin;
855 for(iterin = _setOfInputDataStreamPort.begin(); iterin != _setOfInputDataStreamPort.end(); iterin++)
857 InputDataStreamPort *port=(InputDataStreamPort *)*iterin;
858 std::set<OutPort *> ports=port->edSetOutPort();
859 std::set<OutPort *>::iterator iter;
860 for(iter=ports.begin();iter != ports.end(); iter++)
862 Node* node= (*iter)->getNode();
863 node->ensureLoading();
868 //! Calls getCoupledNodes for Task interface
869 void ElementaryNode::getCoupledTasks(std::set<Task*>& coupledSet)
871 getCoupledNodes(coupledSet);
874 //! Put all nodes that are coupled to this node in coupledSet
875 void ElementaryNode::getCoupledNodes(std::set<Task*>& coupledSet)
877 if(coupledSet.find(this) != coupledSet.end())return;
879 coupledSet.insert(this);
881 std::list<OutputDataStreamPort *>::iterator iterout;
882 for(iterout = _setOfOutputDataStreamPort.begin(); iterout != _setOfOutputDataStreamPort.end(); iterout++)
884 OutputDataStreamPort *port=(OutputDataStreamPort *)*iterout;
885 std::set<InPort *> ports=port->edSetInPort();
886 std::set<InPort *>::iterator iter;
887 for(iter=ports.begin();iter != ports.end(); iter++)
889 Node* node= (*iter)->getNode();
890 node->getCoupledNodes(coupledSet);