2 #include "InputPort.hxx"
3 #include "OutputPort.hxx"
4 #include "ComposedNode.hxx"
5 #include "InputDataStreamPort.hxx"
6 #include "OutputDataStreamPort.hxx"
8 using namespace YACS::ENGINE;
11 Node::Node(const string& name):_name(name),_inGate(this),_outGate(this),_father(0),_colour(YACS::White),_state(YACS::INITED)
20 * initialisation of all input and output ports and gates, for execution
26 for(set<OutputPort *>::iterator iter=_setOfOutputPort.begin();iter!=_setOfOutputPort.end();iter++)
28 for(set<InputPort *>::iterator iter2=_setOfInputPort.begin();iter2!=_setOfInputPort.end();iter2++)
30 if(_inGate.exIsReady())
31 _state=YACS::TOACTIVATE;
37 * get the set of all nodes connected to the outGate
40 set<Node *> Node::getOutNodes() const
43 set<InGate *> inGates=_outGate.edSetInGate();
44 for(set<InGate *>::iterator iter=inGates.begin();iter!=inGates.end();iter++)
45 ret.insert((*iter)->getNode());
50 * @note : Update the '_state' attribute.
51 * Typically called by 'this->_inGate' when 'this->_inGate' is ready.
54 void Node::exUpdateState()
56 if(_inGate.exIsReady())
57 if(areAllInputPortsValid())
58 _state=YACS::TOACTIVATE;
61 string what("Node::exUpdateState : Invalid graph given : Node with name \"");
62 what+=_name; what+="\" ready to run whereas some inputports are not set correctly\nCheck coherence DF/CF";
63 throw Exception(what);
67 int Node::getNumberOfInputPorts() const
69 return _setOfInputPort.size();
72 int Node::getNumberOfOutputPorts() const
74 return _setOfOutputPort.size();
77 InputPort *Node::getInputPort(const string& name) const throw(Exception)
79 return getPort<InputPort>(name,_setOfInputPort);
82 OutputPort *Node::getOutputPort(const string& name) const throw(Exception)
84 return getPort<OutputPort>(name,_setOfOutputPort);
87 InputDataStreamPort *Node::getInputDataStreamPort(const string& name) const throw(Exception)
89 return getPort<InputDataStreamPort>(name,_setOfInputDataStreamPort);
92 OutputDataStreamPort *Node::getOutputDataStreamPort(const string& name) const throw(Exception)
94 return getPort<OutputDataStreamPort>(name,_setOfOutputDataStreamPort);
99 * gets a set of the composed nodes that constitute the ascendancy of this node, starting from root
100 * or from a particular ancestor
101 * @param levelToStop composed node which is the oldest ancestor required
102 * @return ascendancy, direct father first in set.
105 set<ComposedNode *> Node::getAllAscendanceOf(ComposedNode *levelToStop)
107 set<ComposedNode *> ret;
108 for(ComposedNode *iter=_father;iter!=levelToStop && iter!=0; iter=iter->_father)
114 * @return Implementation of node: C++, Python, CORBA...
115 * _implementation is set by a derived class in a Runtime
116 * it normally applies only to elementaryNodes and it is used by Ports to select Data Converters.
117 * Potential problem with Ports attached to composed Nodes...
120 string Node::getImplementation()
122 return _implementation;
126 * checks if all input ports contains a valid data. Used at execution to change the state of the node
130 bool Node::areAllInputPortsValid() const
133 for(set<InputPort *>::const_iterator iter=_setOfInputPort.begin();iter!=_setOfInputPort.end();iter++)
135 ret=!(*iter)->isEmpty();
141 ComposedNode *Node::getRootNode() throw(Exception)
144 throw Exception("No root node");
145 ComposedNode *iter=_father;
152 * checks validity of ports name, that must not contain a particular character '?'
153 * USAGE NOT CLEAR, not used so far, when are those characters set ?
156 void Node::checkValidityOfPortName(const string& name) throw(Exception)
158 if(name.find(SEP_CHAR_IN_PORT, 0 )!=string::npos)
160 string what("Port name "); what+=name; what+="not valid because it contains character "; what+=SEP_CHAR_IN_PORT;
161 throw Exception(what);
166 * @note : Check that 'node1' and 'node2' have exactly the same father
167 * @exception : If 'node1' and 'node2' have NOT exactly the same father
169 ComposedNode *Node::checkHavingCommonFather(Node *node1, Node *node2) throw(Exception)
171 if(node1!=0 && node2!=0)
173 if(node1->_father==node2->_father)
174 return node1->_father;
176 throw Exception("check failed : nodes have not the same father");
180 * set color for inGates : display
181 * USAGE NOT CLEAR, not used so far
184 void Node::initForDFS() const
187 set<InGate *> inGates=_outGate.edSetInGate();
188 for(set<InGate *>::iterator iter=inGates.begin();iter!=inGates.end();iter++)
189 (*iter)->initForDFS();