1 #ifndef __ELEMENTARYNODE_HXX__
2 #define __ELEMENTARYNODE_HXX__
18 class InputDataStreamPort;
19 class OutputDataStreamPort;
21 class ElementaryNode : public Node, public Task
23 friend class ComposedNode;
25 std::list<InputPort *> _setOfInputPort;
26 std::list<OutputPort *> _setOfOutputPort;
27 std::list<InputDataStreamPort *> _setOfInputDataStreamPort;
28 std::list<OutputDataStreamPort *> _setOfOutputDataStreamPort;
30 ElementaryNode(const std::string& name);
31 ElementaryNode(const ElementaryNode& other, ComposedNode *father);
32 void performDuplicationOfPlacement(const Node& other);
34 virtual ~ElementaryNode();
36 void init(bool start=true);
37 bool isDeployable() const;
38 ComponentInstance *getComponent();
39 YACS::StatesForNode getState() const;
40 void getReadyTasks(std::vector<Task *>& tasks);
41 void edRemovePort(Port *port) throw(Exception);
42 std::list<ElementaryNode *> getRecursiveConstituents() const;
43 Node *getChildByName(const std::string& name) const throw(Exception);
44 virtual void checkBasicConsistency() const throw(Exception);
45 ComposedNode *getDynClonerIfExists(const ComposedNode *levelToStop) const;
46 int getNumberOfInputPorts() const;
47 int getNumberOfOutputPorts() const;
48 std::string getInPortName(const InPort *) const throw (Exception);
49 std::string getOutPortName(const OutPort *) const throw (Exception);
50 InputPort *getInputPort(const std::string& name) const throw(Exception);
51 OutputPort *getOutputPort(const std::string& name) const throw(Exception);
52 std::list<InputPort *> getSetOfInputPort() const { return _setOfInputPort; }
53 std::list<OutputPort *> getSetOfOutputPort() const { return _setOfOutputPort; }
54 std::list<InputPort *> getLocalInputPorts() const { return _setOfInputPort; }
55 std::list<OutputPort *> getLocalOutputPorts() const { return _setOfOutputPort; }
56 std::set<OutPort *> getAllOutPortsLeavingCurrentScope() const;
57 std::set<InPort *> getAllInPortsComingFromOutsideOfCurrentScope() const;
58 virtual std::vector< std::pair<OutPort *, InPort *> > getSetOfLinksLeavingCurrentScope() const;
59 virtual std::vector< std::pair<InPort *, OutPort *> > getSetOfLinksComingInCurrentScope() const;
60 std::list<InputDataStreamPort *> getSetOfInputDataStreamPort() const { return _setOfInputDataStreamPort; }
61 std::list<OutputDataStreamPort *> getSetOfOutputDataStreamPort() const { return _setOfOutputDataStreamPort; }
62 InputDataStreamPort *getInputDataStreamPort(const std::string& name) const throw(Exception);
63 OutputDataStreamPort *getOutputDataStreamPort(const std::string& name) const throw(Exception);
64 virtual InputPort *createInputPort(const std::string& inputPortName, TypeCode* type);
65 virtual OutputPort *createOutputPort(const std::string& outputPortName, TypeCode* type);
66 virtual InputDataStreamPort *createInputDataStreamPort(const std::string& inputPortDSName, TypeCode* type);
67 virtual OutputDataStreamPort *createOutputDataStreamPort(const std::string& outputPortDSName, TypeCode* type);
68 virtual InputPort *edAddInputPort(const std::string& inputPortName, TypeCode* type) throw(Exception);
69 virtual OutputPort *edAddOutputPort(const std::string& outputPortName, TypeCode* type) throw(Exception);
70 virtual InputDataStreamPort *edAddInputDataStreamPort(const std::string& inputPortDSName, TypeCode* type) throw(Exception);
71 virtual OutputDataStreamPort *edAddOutputDataStreamPort(const std::string& outputPortDSName, TypeCode* type) throw(Exception);
72 virtual std::string typeName() {return "YACS__ENGINE__ElementaryNode";}
73 virtual void edUpdateState();
74 virtual void ensureLoading();
82 virtual std::string getErrorDetails();
83 virtual void initService() { }
84 virtual void connectService() { }
85 virtual void disconnectService() { }
86 virtual void load() { }
87 void accept(Visitor *visitor);
89 void edDisconnectAllLinksWithMe();
90 bool areAllInputPortsValid() const;
92 PORT *getPort(const std::string& name, const std::list<PORT *>& setOfPorts) const throw(Exception);
93 template<class PORT, class ENUMTYPE>
94 PORT *edAddPort(const std::string& portName, std::list<PORT *>& setOfPorts, ENUMTYPE type) throw(Exception);
95 template<class PORT, class ENUMTYPE>
96 bool edCheckAddPort(const std::string& portName, std::list<PORT *>& setOfPorts, ENUMTYPE type) throw(Exception);
98 static void edRemovePortTypedFromSet(PORT *port, std::list<PORT *>& setOfPorts) throw(Exception);
100 static bool isPortNameAlreadyExist(const std::string& portName, const std::list<PORT *>& setOfPorts);
104 * protected: get a port in a list given it's name
108 PORT *ElementaryNode::getPort(const std::string& name, const std::list<PORT *>& setOfPorts) const throw(Exception)
110 for(typename std::list<PORT *>::const_iterator iter=setOfPorts.begin();iter!=setOfPorts.end();iter++)
112 if((*iter)->getName()==name)
115 std::string what="ElementaryNode::getPort : unexisting "; what+=PORT::NAME;
118 throw Exception(what);
122 * protected: add a port given it's name and type, in a given list of ports
123 * WHY TEMPLATE PARAMETER ENUMTYPE?
126 template<class PORT, class ENUMTYPE>
127 PORT *ElementaryNode::edAddPort(const std::string& portName, std::list<PORT *>& setOfPorts, ENUMTYPE type) throw(Exception)
129 checkValidityOfPortName(portName);
130 if(isPortNameAlreadyExist<PORT>(portName, setOfPorts))
132 std::string what="Port of type "; what+=PORT::NAME; what += " with name : "; what+=portName; what+=" already exists";
133 throw Exception(what);
135 PORT *ret=new PORT(portName,this,type);
136 setOfPorts.push_back(ret);
140 template<class PORT, class ENUMTYPE>
141 bool ElementaryNode::edCheckAddPort(const std::string& portName, std::list<PORT *>& setOfPorts, ENUMTYPE type) throw(Exception)
143 checkValidityOfPortName(portName);
144 if(isPortNameAlreadyExist<PORT>(portName, setOfPorts))
146 std::string what="Port of type "; what+=PORT::NAME; what += " with name : "; what+=portName; what+=" already exists";
147 throw Exception(what);
153 * protected: remove a port from a given list
157 void ElementaryNode::edRemovePortTypedFromSet(PORT *port, std::list<PORT *>& setOfPorts) throw(Exception)
159 if(!isPortNameAlreadyExist<PORT>(port->getName(), setOfPorts))
160 throw Exception("Port is not part of the list : unable to remove it");
161 typename std::list<PORT *>::iterator iter=std::find(setOfPorts.begin(),setOfPorts.end(),port);
162 if(iter!=setOfPorts.end())
164 (*iter)->edRemoveAllLinksLinkedWithMe();
165 setOfPorts.erase(iter);
170 * protected: checks existence of a port, given it's name, in a list
174 bool ElementaryNode::isPortNameAlreadyExist(const std::string& portName, const std::list<PORT *>& setOfPorts)
176 for(typename std::list<PORT *>::const_iterator iter=setOfPorts.begin();iter!=setOfPorts.end();iter++)
178 if((*iter)->getName()==portName)