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 if(start) //complete initialization
103 setState(YACS::READY);
104 else if(_state > YACS::LOADED)//partial initialization (inside a loop)
105 setState(YACS::TORECONNECT);
108 bool ElementaryNode::isDeployable() const
113 ComponentInstance *ElementaryNode::getComponent()
118 const ComponentInstance *ElementaryNode::getComponent() const
123 Container *ElementaryNode::getContainer()
128 YACS::StatesForNode ElementaryNode::getState() const
130 return Node::getState();
133 void ElementaryNode::exUpdateState()
135 DEBTRACE("ElementaryNode::exUpdateState: " << getName() << " " << _state );
136 if(_state==YACS::DISABLED)return;
137 if(_inGate.exIsReady())
138 if(areAllInputPortsValid())
140 if(_state == YACS::READY)
142 else if(_state == YACS::LOADED)
143 setState(YACS::TOACTIVATE);
147 string what("ElementaryNode::exUpdateState : Invalid graph given : Node with name \"");
148 what+=_name; what+="\" ready to run whereas some inputports are not set correctly\nCheck coherence DF/CF";
149 setState(YACS::INTERNALERR);
151 throw Exception(what);
155 int ElementaryNode::getNumberOfInputPorts() const
157 return _setOfInputPort.size();
160 int ElementaryNode::getNumberOfOutputPorts() const
162 return _setOfOutputPort.size();
165 InputPort *ElementaryNode::getInputPort(const std::string& name) const throw(YACS::Exception)
168 return Node::getInputPort(name);
170 catch(Exception& e) {}
171 return getPort<InputPort>(name,_setOfInputPort);
174 OutputPort *ElementaryNode::getOutputPort(const std::string& name) const throw(YACS::Exception)
176 return getPort<OutputPort>(name,_setOfOutputPort);
179 std::set<OutPort *> ElementaryNode::getAllOutPortsLeavingCurrentScope() const
182 list<OutPort *> temp=getSetOfOutPort();
183 for(list<OutPort *>::iterator iter2=temp.begin();iter2!=temp.end();iter2++)
185 set<InPort *> temp2=(*iter2)->edSetInPort();
192 std::set<InPort *> ElementaryNode::getAllInPortsComingFromOutsideOfCurrentScope() const
195 list<InPort *> temp=getSetOfInPort();
196 for(list<InPort *>::iterator iter2=temp.begin();iter2!=temp.end();iter2++)
198 set<OutPort *> temp2=(*iter2)->edSetOutPort();
205 std::vector< std::pair<OutPort *, InPort *> > ElementaryNode::getSetOfLinksLeavingCurrentScope() const
207 vector< pair<OutPort *, InPort *> > ret;
208 std::set<OutPort *> ports=getAllOutPortsLeavingCurrentScope();
209 for(set<OutPort *>::iterator iter2=ports.begin();iter2!=ports.end();iter2++)
211 set<InPort *> temp2=(*iter2)->edSetInPort();
212 for(set<InPort *>::iterator iter3=temp2.begin();iter3!=temp2.end();iter3++)
213 ret.push_back(pair<OutPort *, InPort *>(*iter2,*iter3));
218 std::vector< std::pair<InPort *, OutPort *> > ElementaryNode::getSetOfLinksComingInCurrentScope() const
220 vector< pair<InPort *, OutPort *> > ret;
221 set<InPort *> ports=getAllInPortsComingFromOutsideOfCurrentScope();
222 for(set<InPort *>::iterator iter2=ports.begin();iter2!=ports.end();iter2++)
224 set<OutPort *> temp2=(*iter2)->edSetOutPort();
225 for(set<OutPort *>::iterator iter3=temp2.begin();iter3!=temp2.end();iter3++)
227 std::set<OutPort *> trueOutPorts;
228 (*iter3)->getAllRepresented(trueOutPorts);
229 for(std::set<OutPort *>::iterator iter4=trueOutPorts.begin();iter4!=trueOutPorts.end();++iter4)
230 ret.push_back(pair<InPort *, OutPort *>(*iter2,*iter4));
236 InputDataStreamPort *ElementaryNode::getInputDataStreamPort(const std::string& name) const throw(YACS::Exception)
238 return getPort<InputDataStreamPort>(name,_setOfInputDataStreamPort);
241 OutputDataStreamPort *ElementaryNode::getOutputDataStreamPort(const std::string& name) const throw(YACS::Exception)
243 return getPort<OutputDataStreamPort>(name,_setOfOutputDataStreamPort);
246 void ElementaryNode::edDisconnectAllLinksWithMe()
249 Node::edDisconnectAllLinksWithMe();
252 for(list<InputPort *>::iterator iter=_setOfInputPort.begin();iter!=_setOfInputPort.end();iter++)
253 (*iter)->edRemoveAllLinksLinkedWithMe();
255 for(list<InputDataStreamPort *>::iterator iter2=_setOfInputDataStreamPort.begin();iter2!=_setOfInputDataStreamPort.end();iter2++)
256 (*iter2)->edRemoveAllLinksLinkedWithMe();
259 for(list<OutputPort *>::iterator iter=_setOfOutputPort.begin();iter!=_setOfOutputPort.end();iter++)
260 (*iter)->edRemoveAllLinksLinkedWithMe();
262 for(list<OutputDataStreamPort *>::iterator iter2=_setOfOutputDataStreamPort.begin();iter2!=_setOfOutputDataStreamPort.end();iter2++)
263 (*iter2)->edRemoveAllLinksLinkedWithMe();
267 * checks if all input ports contains a valid data. Used at execution to change the state of the node
271 bool ElementaryNode::areAllInputPortsValid() const
274 for(list<InputPort *>::const_iterator iter=_setOfInputPort.begin();iter!=_setOfInputPort.end();iter++)
276 ret=!(*iter)->isEmpty();
283 This method is used by the "multi" property of ElementaryNode to create
284 to create duplicated input and ouput datastream ports.
287 ElementaryNode::createMultiDatastreamPorts()
289 if (!_createDatastreamPorts)
291 _createDatastreamPorts = true;
292 for(list<InputDataStreamPort *>::const_iterator iter3 = _setOfInputDataStreamPort.begin(); iter3!=_setOfInputDataStreamPort.end();iter3++)
294 InputDataStreamPort * port = *iter3;
295 std::string port_name = port->getName();
296 std::map<std::string,std::string>::iterator it=_propertyMap.find(port_name);
298 if(it != _propertyMap.end())
300 std::string multi_str = it->second;
301 std::istringstream iss(multi_str);
303 throw Exception("Property multi port should be set with a stringified int not an: " + multi_str);
308 addDatastreamPortToInitMultiService(port_name, multi);
309 // Change name of first port
310 port->setName(port_name + "_0");
311 for (int i = 2; i <= multi; i++)
313 InputDataStreamPort * new_port = port->clone(this);
314 std::ostringstream number;
316 new_port->setName(port_name + "_" + number.str());
317 _setOfInputDataStreamPort.push_back(new_port);
318 _multi_port_node = true;
322 for(list<OutputDataStreamPort *>::const_iterator iter4 = _setOfOutputDataStreamPort.begin(); iter4!=_setOfOutputDataStreamPort.end();iter4++)
324 OutputDataStreamPort * port = *iter4;
325 std::string port_name = port->getName();
326 std::map<std::string,std::string>::iterator it=_propertyMap.find(port_name);
328 if(it != _propertyMap.end())
330 std::string multi_str = it->second;
331 std::istringstream iss(multi_str);
333 throw Exception("Property multi port should be set with a stringified int not an: " + multi_str);
338 addDatastreamPortToInitMultiService(port_name, multi);
339 // Change name of first port
340 port->setName(port_name + "_0");
341 for (int i = 2; i <= multi; i++)
343 OutputDataStreamPort * new_port = port->clone(this);
344 std::ostringstream number;
346 new_port->setName(port_name + "_" + number.str());
347 _setOfOutputDataStreamPort.push_back(new_port);
348 _multi_port_node = true;
356 * add this node task to a given set of ready tasks, if this task is ready to activate
359 void ElementaryNode::getReadyTasks(std::vector<Task *>& tasks)
361 DEBTRACE("ElementaryNode::getReadyTasks: " << getName() << " " << _state);
364 std::map<std::string,std::string>::iterator it=_propertyMap.find("multi");
365 if(it != _propertyMap.end())
367 std::string multi_str = it->second;
368 std::istringstream iss(multi_str);
370 throw Exception("Property multi should be set with a stringified int not an: " + multi_str);
373 if(_state==YACS::TOACTIVATE || _state==YACS::TOLOAD || _state==YACS::TORECONNECT)
377 std::map<std::string,std::string>::iterator it=_propertyMap.find("multi_working_dir");
378 if(it != _propertyMap.end())
380 std::string working_dir_base = it->second;
381 std::ostringstream working_dir_stream;
382 working_dir_stream << working_dir_base;
383 working_dir_stream << 1;
384 this->getContainer()->setProperty("workingdir", working_dir_stream.str());
386 tasks.push_back(this);
391 // Check output port -> cannot clone an Elementary Node with Output Ports connected
392 std::list<OutputPort *>::iterator it_output = _setOfOutputPort.begin();
393 for (;it_output != _setOfOutputPort.end(); it_output++)
395 if ((*it_output)->isConnected())
397 throw Exception("Property multi cannot be set on nodes with dataflow output ports connected");
402 std::map<std::string,std::string>::iterator it=_propertyMap.find("multi_working_dir");
403 if(it != _propertyMap.end())
405 std::string working_dir_base = it->second;
406 std::ostringstream working_dir_stream;
407 working_dir_stream << working_dir_base;
408 working_dir_stream << 1;
409 this->getContainer()->setProperty("workingdir", working_dir_stream.str());
411 tasks.push_back(this);
413 // Step 1: Create clones
414 for (int i = 1; i < multi; i++)
417 YACS::ENGINE::ElementaryNode * new_node = static_cast<YACS::ENGINE::ElementaryNode *>(clone(_father, false));
418 new_node->createMultiDatastreamPorts();
422 std::stringstream inamess;
423 inamess << getName() << "_" << i;
425 DEBTRACE("Create clone "<< iname << " of node " << getName());
426 new_node->setName(iname);
428 // For each input port connect it with the original output port
429 std::list<InputPort *> clone_list_inputPorts = new_node->getSetOfInputPort();
430 for(list<InputPort *>::const_iterator iter1=clone_list_inputPorts.begin(); iter1!=clone_list_inputPorts.end(); iter1++)
432 std::string input_port_name = (*iter1)->getName();
433 // Get Port Name in master node
434 InputPort * master_port = getInputPort(input_port_name);
435 for (std::set<OutPort *>::const_iterator itt=master_port->_backLinks.begin(); itt!=master_port->_backLinks.end();itt++)
438 getProc()->edAddDFLink((*itt),(*iter1));
442 // InputDataStreamPort connections
443 std::list<InputDataStreamPort *> clone_list_inputDatastreamPorts = new_node->getSetOfInputDataStreamPort();
444 for(list<InputDataStreamPort *>::iterator iter = clone_list_inputDatastreamPorts.begin(); iter != clone_list_inputDatastreamPorts.end(); iter++)
446 std::string port_name = (*iter)->getName();
447 InputDataStreamPort * orig_port = getInputDataStreamPort(port_name);
449 std::set<OutputDataStreamPort *> connected_ports = orig_port->getConnectedOutputDataStreamPort();
451 // Create datastream ports if not created
452 std::set<OutputDataStreamPort *>::const_iterator iter3;
453 for(iter3=connected_ports.begin();iter3!=connected_ports.end();iter3++)
455 ElementaryNode * node = (ElementaryNode *) (*iter3)->getNode();
456 node->createMultiDatastreamPorts();
458 std::string good_port_name;
459 std::stringstream temp_name;
460 std::string out_name = (*iter3)->getName();
461 out_name.erase(out_name.end()-1);
462 temp_name << out_name << i;
463 good_port_name = temp_name.str();
464 getProc()->edAddLink(node->getOutputDataStreamPort(good_port_name), (*iter));
468 // OutputDataStreamPort connections
469 std::list<OutputDataStreamPort *> clone_list_outputDatastreamPorts = new_node->getSetOfOutputDataStreamPort();
470 for(list<OutputDataStreamPort *>::iterator iter = clone_list_outputDatastreamPorts.begin(); iter != clone_list_outputDatastreamPorts.end(); iter++)
472 std::string port_name = (*iter)->getName();
473 OutputDataStreamPort * orig_port = getOutputDataStreamPort(port_name);
474 std::set<InputDataStreamPort *> dest_input_port = orig_port->_setOfInputDataStreamPort;
475 for(set<InputDataStreamPort *>::iterator dest_port = dest_input_port.begin(); dest_port != dest_input_port.end(); dest_port++)
477 ElementaryNode * dest_node = (ElementaryNode *)(*dest_port)->getNode();
478 // Add InputPort to dest node
479 dest_node->createMultiDatastreamPorts();
481 std::string good_port_name;
482 std::stringstream temp_name;
483 std::string in_name = (*dest_port)->getName();
484 in_name.erase(in_name.end()-1);
485 temp_name << in_name << i;
486 good_port_name = temp_name.str();
487 getProc()->edAddLink((*iter), dest_node->getInputDataStreamPort(good_port_name));
492 new_node->init(false);
493 new_node->exUpdateState();
495 // Set Control Link to done
496 std::list<OutGate *> clone_cl_back = new_node->getInGate()->getBackLinks();
497 for(std::list<OutGate *>::const_iterator iter=clone_cl_back.begin(); iter!=clone_cl_back.end(); iter++)
498 new_node->getInGate()->exNotifyFromPrecursor((*iter));
501 std::map<std::string,std::string>::iterator it=_propertyMap.find("multi_working_dir");
502 if(it != _propertyMap.end())
504 std::string working_dir_base = it->second;
505 std::ostringstream working_dir_stream;
506 working_dir_stream << working_dir_base;
507 working_dir_stream << i+1;
508 new_node->getContainer()->setProperty("workingdir", working_dir_stream.str());
510 tasks.push_back(new_node);
517 * remove port from node at edition. Ports are typed.
520 void ElementaryNode::edRemovePort(Port *port) throw(YACS::Exception)
522 DEBTRACE("ElementaryNode::edRemovePort ");
523 if(port->getNode()!=this)
524 throw Exception("ElementaryNode::edRemovePort : Port is not held by this node");
525 if(InputPort *p=dynamic_cast<InputPort *>(port))
526 edRemovePortTypedFromSet<InputPort>(p,_setOfInputPort);
527 else if(OutputPort *p=dynamic_cast<OutputPort *>(port))
528 edRemovePortTypedFromSet<OutputPort>(p,_setOfOutputPort);
529 else if(InputDataStreamPort *p=dynamic_cast<InputDataStreamPort *>(port))
530 edRemovePortTypedFromSet<InputDataStreamPort>(p,_setOfInputDataStreamPort);
531 else if(OutputDataStreamPort *p=dynamic_cast<OutputDataStreamPort *>(port))
532 edRemovePortTypedFromSet<OutputDataStreamPort>(p,_setOfOutputDataStreamPort);
534 throw Exception("ElementaryNode::edRemovePort : unknown port type");
540 * @return a set with only this node. (Same method in composed nodes)
543 list<ElementaryNode *> ElementaryNode::getRecursiveConstituents() const
545 list<ElementaryNode *> ret;
546 ret.push_back((ElementaryNode *)this);
550 //! Get the progress weight for all elementary nodes
552 * Only elementary nodes have weight. At this stage weight is 0 or 1 (it can be modified later following
553 * the kind of father)
555 list<ProgressWeight> ElementaryNode::getProgressWeight() const
557 list<ProgressWeight> ret;
558 ProgressWeight myWeight;
559 myWeight.weightTotal=1;
560 if (getState() == YACS::DONE)
561 myWeight.weightDone=1;
563 myWeight.weightDone=0;
564 ret.push_back(myWeight);
568 Node *ElementaryNode::getChildByName(const std::string& name) const throw(YACS::Exception)
570 string what("ElementaryNode does not agregate any nodes particullary node with name "); what+=name;
571 throw Exception(what);
574 void ElementaryNode::checkBasicConsistency() const throw(YACS::Exception)
576 DEBTRACE("ElementaryNode::checkBasicConsistency");
577 list<InputPort *>::const_iterator iter;
578 for(iter=_setOfInputPort.begin();iter!=_setOfInputPort.end();iter++)
579 (*iter)->checkBasicConsistency();
582 ComposedNode *ElementaryNode::getDynClonerIfExists(const ComposedNode *levelToStop) const
584 for(ComposedNode *iter=_father;iter!=levelToStop && iter!=0; iter=iter->_father)
585 if(!iter->isPlacementPredictableB4Run())
590 InputPort *ElementaryNode::createInputPort(const std::string& inputPortName, TypeCode* type)
592 return getRuntime()->createInputPort(inputPortName, _implementation, this, type);
596 * the input port is also published recursively in ancestors because it may be visible from everywhere.
597 * WARNING: CHECK CASE OF BLOC: ONLY INPUT PORTS NOT INTERNALLY CONNECTED MUST BE VISIBLE.
600 InputPort *ElementaryNode::edAddInputPort(const std::string& inputPortName, TypeCode* type) throw(YACS::Exception)
603 // Cannot create an InputPort defined with InPropertyPort name.
604 if (inputPortName == "__InPropertyPort__Node__YACS_")
606 string what("ElementaryNode::edAddInputPort: it is forbidden to add an InputPort with the name __InPropertyPort__Node__YACS_\"");
607 throw Exception(what);
611 if (edCheckAddPort<InputPort, TypeCode*>(inputPortName,_setOfInputPort,type))
613 ret = createInputPort(inputPortName, type);
614 _setOfInputPort.push_back(ret);
617 ComposedNode *iter=_father;
625 void ElementaryNode::edOrderInputPorts(const std::list<InputPort*>& ports)
627 std::set<InputPort *> s1;
628 std::set<InputPort *> s2;
629 for(list<InputPort *>::const_iterator it=_setOfInputPort.begin();it != _setOfInputPort.end();it++)
631 for(list<InputPort *>::const_iterator it=ports.begin();it != ports.end();it++)
635 throw Exception("ElementaryNode::edOrderInputPorts : port list must contain same ports as existing ones");
637 _setOfInputPort.clear();
638 for(list<InputPort *>::const_iterator it=ports.begin();it != ports.end();it++)
639 _setOfInputPort.push_back(*it);
642 void ElementaryNode::edOrderOutputPorts(const std::list<OutputPort*>& ports)
644 std::set<OutputPort *> s1;
645 std::set<OutputPort *> s2;
646 for(list<OutputPort *>::const_iterator it=_setOfOutputPort.begin();it != _setOfOutputPort.end();it++)
648 for(list<OutputPort *>::const_iterator it=ports.begin();it != ports.end();it++)
652 throw Exception("ElementaryNode::edOrderOutputPorts : port list must contain same ports as existing ones");
654 _setOfOutputPort.clear();
655 for(list<OutputPort *>::const_iterator it=ports.begin();it != ports.end();it++)
656 _setOfOutputPort.push_back(*it);
659 OutputPort *ElementaryNode::createOutputPort(const std::string& outputPortName, TypeCode* type)
661 return getRuntime()->createOutputPort(outputPortName, _implementation, this, type);
665 * TO SOLVE : The output port is not published in father. Father must create an output port.
666 * for now, publication is done the same way as input ports
669 OutputPort *ElementaryNode::edAddOutputPort(const std::string& outputPortName, TypeCode* type) throw(YACS::Exception)
672 if (edCheckAddPort<OutputPort, TypeCode*>(outputPortName,_setOfOutputPort,type))
674 ret = createOutputPort(outputPortName, type);
675 _setOfOutputPort.push_back(ret);
678 ComposedNode *iter=_father;
686 InputDataStreamPort *ElementaryNode::createInputDataStreamPort(const std::string& inputPortDSName, TypeCode* type)
688 return getRuntime()->createInputDataStreamPort(inputPortDSName, this, type);
691 InputDataStreamPort *ElementaryNode::edAddInputDataStreamPort(const std::string& inputPortDSName, TypeCode* type) throw(YACS::Exception)
693 InputDataStreamPort *ret = 0;
694 if (edCheckAddPort<InputDataStreamPort, TypeCode*>(inputPortDSName,_setOfInputDataStreamPort,type))
696 ret = createInputDataStreamPort(inputPortDSName, type);
697 _setOfInputDataStreamPort.push_back(ret);
703 OutputDataStreamPort *ElementaryNode::createOutputDataStreamPort(const std::string& outputPortDSName, TypeCode* type)
705 return getRuntime()->createOutputDataStreamPort(outputPortDSName, this, type);
708 OutputDataStreamPort *ElementaryNode::edAddOutputDataStreamPort(const std::string& outputPortDSName, TypeCode* type) throw(YACS::Exception)
710 OutputDataStreamPort *ret = 0;
711 if (edCheckAddPort<OutputDataStreamPort, TypeCode*>(outputPortDSName,_setOfOutputDataStreamPort,type))
713 ret = createOutputDataStreamPort(outputPortDSName, type);
714 _setOfOutputDataStreamPort.push_back(ret);
721 * get the input port name used by the current node (see composed nodes)
724 string ElementaryNode::getInPortName(const InPort * inPort) const throw(YACS::Exception)
726 Node *node = inPort->getNode();
729 string what("InputPort "); what += inPort->getName(); what += " does not belong to node "; what += node->getName();
730 throw Exception(what);
732 return inPort->getName();
735 string ElementaryNode::getOutPortName(const OutPort *outPort) const throw(YACS::Exception)
737 Node *node = outPort->getNode();
740 string what("OutputPort "); what += outPort->getName(); what += " does not belong to node "; what += node->getName();
741 throw Exception(what);
743 return outPort->getName();
746 void ElementaryNode::begin()
751 bool ElementaryNode::isReady()
753 return _state==TOACTIVATE;
756 void ElementaryNode::finished()
760 void ElementaryNode::aborted()
765 //! Notify this node that it is loaded
767 * When an elementary node has been loaded
768 * It is ready to be connected
771 void ElementaryNode::loaded()
775 //! Notify this node that it is connected
777 * When an elementary node has been connected it goes to TOACTIVATE state
778 * It is then ready to be executed
781 void ElementaryNode::connected()
783 if(_inGate.exIsReady())
784 if(areAllInputPortsValid())
786 setState(TOACTIVATE);
792 void ElementaryNode::accept(Visitor *visitor)
794 visitor->visitElementaryNode(this);
797 //! Give a description of error when node status is ERROR
801 std::string ElementaryNode::getErrorDetails()
803 return _errorDetails;
806 void ElementaryNode::edUpdateState()
808 DEBTRACE("ElementaryNode::edUpdateState: " << getName());
809 YACS::StatesForNode state=YACS::READY;
812 checkBasicConsistency();
818 _errorDetails=e.what();
820 DEBTRACE("ElementaryNode::edUpdateState: " << _errorDetails);
826 //! Put this node into TOLOAD state when possible
828 * Can be called by another ElementaryNode that is connected to this one by a datastream link
829 * These 2 nodes must be loaded at the same time as they are coupled
830 * It's the other node which requests this node loading
832 void ElementaryNode::ensureLoading()
834 DEBTRACE("ElementaryNode::ensureLoading: " << getName());
835 if(_state != YACS::READY)
837 setState(YACS::TOLOAD);
839 // request loading for all nodes connected to this one by datastream link
840 // Be careful that nodes can be connected in a loop. Put first this node in TOLOAD state to break the loop
841 std::list<OutputDataStreamPort *>::iterator iterout;
842 for(iterout = _setOfOutputDataStreamPort.begin(); iterout != _setOfOutputDataStreamPort.end(); iterout++)
844 OutputDataStreamPort *port=(OutputDataStreamPort *)*iterout;
845 std::set<InPort *> ports=port->edSetInPort();
846 std::set<InPort *>::iterator iter;
847 for(iter=ports.begin();iter != ports.end(); iter++)
849 Node* node= (*iter)->getNode();
850 node->ensureLoading();
853 std::list<InputDataStreamPort *>::iterator iterin;
854 for(iterin = _setOfInputDataStreamPort.begin(); iterin != _setOfInputDataStreamPort.end(); iterin++)
856 InputDataStreamPort *port=(InputDataStreamPort *)*iterin;
857 std::set<OutPort *> ports=port->edSetOutPort();
858 std::set<OutPort *>::iterator iter;
859 for(iter=ports.begin();iter != ports.end(); iter++)
861 Node* node= (*iter)->getNode();
862 node->ensureLoading();
867 //! Calls getCoupledNodes for Task interface
868 void ElementaryNode::getCoupledTasks(std::set<Task*>& coupledSet)
870 getCoupledNodes(coupledSet);
873 //! Put all nodes that are coupled to this node in coupledSet
874 void ElementaryNode::getCoupledNodes(std::set<Task*>& coupledSet)
876 if(coupledSet.find(this) != coupledSet.end())return;
878 coupledSet.insert(this);
880 std::list<OutputDataStreamPort *>::iterator iterout;
881 for(iterout = _setOfOutputDataStreamPort.begin(); iterout != _setOfOutputDataStreamPort.end(); iterout++)
883 OutputDataStreamPort *port=(OutputDataStreamPort *)*iterout;
884 std::set<InPort *> ports=port->edSetInPort();
885 std::set<InPort *>::iterator iter;
886 for(iter=ports.begin();iter != ports.end(); iter++)
888 Node* node= (*iter)->getNode();
889 node->getCoupledNodes(coupledSet);