1 // Copyright (C) 2006-2013 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.
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 #ifndef __ELEMENTARYNODE_HXX__
21 #define __ELEMENTARYNODE_HXX__
23 #include "YACSlibEngineExport.hxx"
40 class InputDataStreamPort;
41 class OutputDataStreamPort;
43 class YACSLIBENGINE_EXPORT ElementaryNode : public Node, public Task
45 friend class ComposedNode;
47 std::list<InputPort *> _setOfInputPort;
48 std::list<OutputPort *> _setOfOutputPort;
49 std::list<InputDataStreamPort *> _setOfInputDataStreamPort;
50 std::list<OutputDataStreamPort *> _setOfOutputDataStreamPort;
52 // Management of multi property
53 bool _createDatastreamPorts;
54 bool _multi_port_node;
56 ElementaryNode(const std::string& name);
57 ElementaryNode(const ElementaryNode& other, ComposedNode *father);
58 void performDuplicationOfPlacement(const Node& other);
60 virtual ~ElementaryNode();
62 void init(bool start=true);
63 bool isDeployable() const;
64 ComponentInstance *getComponent();
65 Container *getContainer();
66 YACS::StatesForNode getState() const;
67 void getReadyTasks(std::vector<Task *>& tasks);
68 void edRemovePort(Port *port) throw(Exception);
69 std::list<ElementaryNode *> getRecursiveConstituents() const;
70 Node *getChildByName(const std::string& name) const throw(Exception);
71 virtual void checkBasicConsistency() const throw(Exception);
72 ComposedNode *getDynClonerIfExists(const ComposedNode *levelToStop) const;
73 int getNumberOfInputPorts() const;
74 int getNumberOfOutputPorts() const;
75 std::string getInPortName(const InPort *) const throw (Exception);
76 std::string getOutPortName(const OutPort *) const throw (Exception);
77 InputPort *getInputPort(const std::string& name) const throw(Exception);
78 OutputPort *getOutputPort(const std::string& name) const throw(Exception);
79 std::list<InputPort *> getSetOfInputPort() const { return _setOfInputPort; }
80 std::list<OutputPort *> getSetOfOutputPort() const { return _setOfOutputPort; }
81 std::list<InputPort *> getLocalInputPorts() const { return _setOfInputPort; }
82 std::list<OutputPort *> getLocalOutputPorts() const { return _setOfOutputPort; }
83 std::set<OutPort *> getAllOutPortsLeavingCurrentScope() const;
84 std::set<InPort *> getAllInPortsComingFromOutsideOfCurrentScope() const;
85 virtual std::vector< std::pair<OutPort *, InPort *> > getSetOfLinksLeavingCurrentScope() const;
86 virtual std::vector< std::pair<InPort *, OutPort *> > getSetOfLinksComingInCurrentScope() const;
87 std::list<InputDataStreamPort *> getSetOfInputDataStreamPort() const { return _setOfInputDataStreamPort; }
88 std::list<OutputDataStreamPort *> getSetOfOutputDataStreamPort() const { return _setOfOutputDataStreamPort; }
89 InputDataStreamPort *getInputDataStreamPort(const std::string& name) const throw(Exception);
90 OutputDataStreamPort *getOutputDataStreamPort(const std::string& name) const throw(Exception);
91 virtual InputPort *createInputPort(const std::string& inputPortName, TypeCode* type);
92 virtual OutputPort *createOutputPort(const std::string& outputPortName, TypeCode* type);
93 virtual InputDataStreamPort *createInputDataStreamPort(const std::string& inputPortDSName, TypeCode* type);
94 virtual OutputDataStreamPort *createOutputDataStreamPort(const std::string& outputPortDSName, TypeCode* type);
95 virtual InputPort *edAddInputPort(const std::string& inputPortName, TypeCode* type) throw(Exception);
96 virtual OutputPort *edAddOutputPort(const std::string& outputPortName, TypeCode* type) throw(Exception);
97 virtual InputDataStreamPort *edAddInputDataStreamPort(const std::string& inputPortDSName, TypeCode* type) throw(Exception);
98 virtual OutputDataStreamPort *edAddOutputDataStreamPort(const std::string& outputPortDSName, TypeCode* type) throw(Exception);
99 virtual void edOrderInputPorts(const std::list<InputPort*>& ports);
100 virtual void edOrderOutputPorts(const std::list<OutputPort*>& ports);
102 virtual std::string typeName() {return "YACS__ENGINE__ElementaryNode";}
103 virtual void edUpdateState();
104 virtual void ensureLoading();
113 virtual std::string getErrorDetails();
114 virtual void initService() { }
115 virtual void connectService() { }
116 virtual void disconnectService() { }
117 virtual void load() { }
118 virtual void getCoupledTasks(std::set<Task*>& coupledSet);
119 virtual void getCoupledNodes(std::set<Task*>& coupledSet);
120 void accept(Visitor *visitor);
122 // Used for runtime nodes that need
123 // to configure their services for the multi property
124 virtual void addDatastreamPortToInitMultiService(const std::string & port_name,
127 // Management of multi property
128 virtual void createMultiDatastreamPorts();
130 void edDisconnectAllLinksWithMe();
131 bool areAllInputPortsValid() const;
133 PORT *getPort(const std::string& name, const std::list<PORT *>& setOfPorts) const throw(Exception);
134 template<class PORT, class ENUMTYPE>
135 PORT *edAddPort(const std::string& portName, std::list<PORT *>& setOfPorts, ENUMTYPE type) throw(Exception);
136 template<class PORT, class ENUMTYPE>
137 bool edCheckAddPort(const std::string& portName, std::list<PORT *>& setOfPorts, ENUMTYPE type) throw(Exception);
139 static void edRemovePortTypedFromSet(PORT *port, std::list<PORT *>& setOfPorts) throw(Exception);
141 static bool isPortNameAlreadyExist(const std::string& portName, const std::list<PORT *>& setOfPorts);
145 * protected: get a port in a list given it's name
149 PORT *ElementaryNode::getPort(const std::string& name, const std::list<PORT *>& setOfPorts) const throw(Exception)
151 for(typename std::list<PORT *>::const_iterator iter=setOfPorts.begin();iter!=setOfPorts.end();iter++)
153 if((*iter)->getName()==name)
156 std::string what="ElementaryNode::getPort : unexisting "; what+=PORT::NAME;
159 throw Exception(what);
163 * protected: add a port given it's name and type, in a given list of ports
164 * WHY TEMPLATE PARAMETER ENUMTYPE?
167 template<class PORT, class ENUMTYPE>
168 PORT *ElementaryNode::edAddPort(const std::string& portName, std::list<PORT *>& setOfPorts, ENUMTYPE type) throw(Exception)
170 checkValidityOfPortName(portName);
171 if(isPortNameAlreadyExist<PORT>(portName, setOfPorts))
173 std::string what="Port of type "; what+=PORT::NAME; what += " with name : "; what+=portName; what+=" already exists";
174 throw Exception(what);
176 PORT *ret=new PORT(portName,this,type);
177 setOfPorts.push_back(ret);
181 template<class PORT, class ENUMTYPE>
182 bool ElementaryNode::edCheckAddPort(const std::string& portName, std::list<PORT *>& setOfPorts, ENUMTYPE type) throw(Exception)
184 checkValidityOfPortName(portName);
185 if(isPortNameAlreadyExist<PORT>(portName, setOfPorts))
187 std::string what="Port of type "; what+=PORT::NAME; what += " with name : "; what+=portName; what+=" already exists";
188 throw Exception(what);
194 * protected: remove a port from a given list
198 void ElementaryNode::edRemovePortTypedFromSet(PORT *port, std::list<PORT *>& setOfPorts) throw(Exception)
200 if(!isPortNameAlreadyExist<PORT>(port->getName(), setOfPorts))
201 throw Exception("Port is not part of the list : unable to remove it");
202 typename std::list<PORT *>::iterator iter=std::find(setOfPorts.begin(),setOfPorts.end(),port);
203 if(iter!=setOfPorts.end())
205 (*iter)->edRemoveAllLinksLinkedWithMe();
206 setOfPorts.erase(iter);
211 * protected: checks existence of a port, given it's name, in a list
215 bool ElementaryNode::isPortNameAlreadyExist(const std::string& portName, const std::list<PORT *>& setOfPorts)
217 for(typename std::list<PORT *>::const_iterator iter=setOfPorts.begin();iter!=setOfPorts.end();iter++)
219 if((*iter)->getName()==portName)