1 // Copyright (C) 2006-2008 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
19 #ifndef __ELEMENTARYNODE_HXX__
20 #define __ELEMENTARYNODE_HXX__
37 class InputDataStreamPort;
38 class OutputDataStreamPort;
40 class ElementaryNode : public Node, public Task
42 friend class ComposedNode;
44 std::list<InputPort *> _setOfInputPort;
45 std::list<OutputPort *> _setOfOutputPort;
46 std::list<InputDataStreamPort *> _setOfInputDataStreamPort;
47 std::list<OutputDataStreamPort *> _setOfOutputDataStreamPort;
49 ElementaryNode(const std::string& name);
50 ElementaryNode(const ElementaryNode& other, ComposedNode *father);
51 void performDuplicationOfPlacement(const Node& other);
53 virtual ~ElementaryNode();
55 void init(bool start=true);
56 bool isDeployable() const;
57 ComponentInstance *getComponent();
58 YACS::StatesForNode getState() const;
59 void getReadyTasks(std::vector<Task *>& tasks);
60 void edRemovePort(Port *port) throw(Exception);
61 std::list<ElementaryNode *> getRecursiveConstituents() const;
62 Node *getChildByName(const std::string& name) const throw(Exception);
63 virtual void checkBasicConsistency() const throw(Exception);
64 ComposedNode *getDynClonerIfExists(const ComposedNode *levelToStop) const;
65 int getNumberOfInputPorts() const;
66 int getNumberOfOutputPorts() const;
67 std::string getInPortName(const InPort *) const throw (Exception);
68 std::string getOutPortName(const OutPort *) const throw (Exception);
69 InputPort *getInputPort(const std::string& name) const throw(Exception);
70 OutputPort *getOutputPort(const std::string& name) const throw(Exception);
71 std::list<InputPort *> getSetOfInputPort() const { return _setOfInputPort; }
72 std::list<OutputPort *> getSetOfOutputPort() const { return _setOfOutputPort; }
73 std::list<InputPort *> getLocalInputPorts() const { return _setOfInputPort; }
74 std::list<OutputPort *> getLocalOutputPorts() const { return _setOfOutputPort; }
75 std::set<OutPort *> getAllOutPortsLeavingCurrentScope() const;
76 std::set<InPort *> getAllInPortsComingFromOutsideOfCurrentScope() const;
77 virtual std::vector< std::pair<OutPort *, InPort *> > getSetOfLinksLeavingCurrentScope() const;
78 virtual std::vector< std::pair<InPort *, OutPort *> > getSetOfLinksComingInCurrentScope() const;
79 std::list<InputDataStreamPort *> getSetOfInputDataStreamPort() const { return _setOfInputDataStreamPort; }
80 std::list<OutputDataStreamPort *> getSetOfOutputDataStreamPort() const { return _setOfOutputDataStreamPort; }
81 InputDataStreamPort *getInputDataStreamPort(const std::string& name) const throw(Exception);
82 OutputDataStreamPort *getOutputDataStreamPort(const std::string& name) const throw(Exception);
83 virtual InputPort *createInputPort(const std::string& inputPortName, TypeCode* type);
84 virtual OutputPort *createOutputPort(const std::string& outputPortName, TypeCode* type);
85 virtual InputDataStreamPort *createInputDataStreamPort(const std::string& inputPortDSName, TypeCode* type);
86 virtual OutputDataStreamPort *createOutputDataStreamPort(const std::string& outputPortDSName, TypeCode* type);
87 virtual InputPort *edAddInputPort(const std::string& inputPortName, TypeCode* type) throw(Exception);
88 virtual OutputPort *edAddOutputPort(const std::string& outputPortName, TypeCode* type) throw(Exception);
89 virtual InputDataStreamPort *edAddInputDataStreamPort(const std::string& inputPortDSName, TypeCode* type) throw(Exception);
90 virtual OutputDataStreamPort *edAddOutputDataStreamPort(const std::string& outputPortDSName, TypeCode* type) throw(Exception);
91 virtual void edOrderInputPorts(const std::list<InputPort*>& ports);
92 virtual void edOrderOutputPorts(const std::list<OutputPort*>& ports);
94 virtual std::string typeName() {return "YACS__ENGINE__ElementaryNode";}
95 virtual void edUpdateState();
96 virtual void ensureLoading();
105 virtual std::string getErrorDetails();
106 virtual void initService() { }
107 virtual void connectService() { }
108 virtual void disconnectService() { }
109 virtual void load() { }
110 void accept(Visitor *visitor);
112 void edDisconnectAllLinksWithMe();
113 bool areAllInputPortsValid() const;
115 PORT *getPort(const std::string& name, const std::list<PORT *>& setOfPorts) const throw(Exception);
116 template<class PORT, class ENUMTYPE>
117 PORT *edAddPort(const std::string& portName, std::list<PORT *>& setOfPorts, ENUMTYPE type) throw(Exception);
118 template<class PORT, class ENUMTYPE>
119 bool edCheckAddPort(const std::string& portName, std::list<PORT *>& setOfPorts, ENUMTYPE type) throw(Exception);
121 static void edRemovePortTypedFromSet(PORT *port, std::list<PORT *>& setOfPorts) throw(Exception);
123 static bool isPortNameAlreadyExist(const std::string& portName, const std::list<PORT *>& setOfPorts);
127 * protected: get a port in a list given it's name
131 PORT *ElementaryNode::getPort(const std::string& name, const std::list<PORT *>& setOfPorts) const throw(Exception)
133 for(typename std::list<PORT *>::const_iterator iter=setOfPorts.begin();iter!=setOfPorts.end();iter++)
135 if((*iter)->getName()==name)
138 std::string what="ElementaryNode::getPort : unexisting "; what+=PORT::NAME;
141 throw Exception(what);
145 * protected: add a port given it's name and type, in a given list of ports
146 * WHY TEMPLATE PARAMETER ENUMTYPE?
149 template<class PORT, class ENUMTYPE>
150 PORT *ElementaryNode::edAddPort(const std::string& portName, std::list<PORT *>& setOfPorts, ENUMTYPE type) throw(Exception)
152 checkValidityOfPortName(portName);
153 if(isPortNameAlreadyExist<PORT>(portName, setOfPorts))
155 std::string what="Port of type "; what+=PORT::NAME; what += " with name : "; what+=portName; what+=" already exists";
156 throw Exception(what);
158 PORT *ret=new PORT(portName,this,type);
159 setOfPorts.push_back(ret);
163 template<class PORT, class ENUMTYPE>
164 bool ElementaryNode::edCheckAddPort(const std::string& portName, std::list<PORT *>& setOfPorts, ENUMTYPE type) throw(Exception)
166 checkValidityOfPortName(portName);
167 if(isPortNameAlreadyExist<PORT>(portName, setOfPorts))
169 std::string what="Port of type "; what+=PORT::NAME; what += " with name : "; what+=portName; what+=" already exists";
170 throw Exception(what);
176 * protected: remove a port from a given list
180 void ElementaryNode::edRemovePortTypedFromSet(PORT *port, std::list<PORT *>& setOfPorts) throw(Exception)
182 if(!isPortNameAlreadyExist<PORT>(port->getName(), setOfPorts))
183 throw Exception("Port is not part of the list : unable to remove it");
184 typename std::list<PORT *>::iterator iter=std::find(setOfPorts.begin(),setOfPorts.end(),port);
185 if(iter!=setOfPorts.end())
187 (*iter)->edRemoveAllLinksLinkedWithMe();
188 setOfPorts.erase(iter);
193 * protected: checks existence of a port, given it's name, in a list
197 bool ElementaryNode::isPortNameAlreadyExist(const std::string& portName, const std::list<PORT *>& setOfPorts)
199 for(typename std::list<PORT *>::const_iterator iter=setOfPorts.begin();iter!=setOfPorts.end();iter++)
201 if((*iter)->getName()==portName)