1 // Copyright (C) 2006-2021 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 #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;
51 ComplexWeight _weight;
53 // Management of multi property
54 bool _createDatastreamPorts;
55 bool _multi_port_node;
57 ElementaryNode(const std::string& name);
58 ElementaryNode(const ElementaryNode& other, ComposedNode *father);
59 void performDuplicationOfPlacement(const Node& other);
60 void performShallowDuplicationOfPlacement(const Node& other);
62 virtual ~ElementaryNode();
64 void init(bool start=true);
65 bool isDeployable() const;
66 ComponentInstance *getComponent();
67 const ComponentInstance *getComponent() const;
68 Container *getContainer();
69 YACS::StatesForNode getState() const;
70 void getReadyTasks(std::vector<Task *>& tasks);
71 void edRemovePort(Port *port) ;
72 std::list<ElementaryNode *> getRecursiveConstituents() const;
73 std::list<ProgressWeight> getProgressWeight() const;
74 Node *getChildByName(const std::string& name) const ;
75 virtual void checkBasicConsistency() const ;
76 ComposedNode *getDynClonerIfExists(const ComposedNode *levelToStop) const;
77 int getNumberOfInputPorts() const;
78 int getNumberOfOutputPorts() const;
79 std::string getInPortName(const InPort *) const ;
80 std::string getOutPortName(const OutPort *) const ;
81 InputPort *getInputPort(const std::string& name) const ;
82 OutputPort *getOutputPort(const std::string& name) const ;
83 std::list<InputPort *> getSetOfInputPort() const { return _setOfInputPort; }
84 std::list<OutputPort *> getSetOfOutputPort() const { return _setOfOutputPort; }
85 std::list<InputPort *> getLocalInputPorts() const { return _setOfInputPort; }
86 std::list<OutputPort *> getLocalOutputPorts() const { return _setOfOutputPort; }
87 std::set<OutPort *> getAllOutPortsLeavingCurrentScope() const;
88 std::set<InPort *> getAllInPortsComingFromOutsideOfCurrentScope() const;
89 virtual std::vector< std::pair<OutPort *, InPort *> > getSetOfLinksLeavingCurrentScope() const;
90 virtual std::vector< std::pair<InPort *, OutPort *> > getSetOfLinksComingInCurrentScope() const;
91 std::list<InputDataStreamPort *> getSetOfInputDataStreamPort() const { return _setOfInputDataStreamPort; }
92 std::list<OutputDataStreamPort *> getSetOfOutputDataStreamPort() const { return _setOfOutputDataStreamPort; }
93 InputDataStreamPort *getInputDataStreamPort(const std::string& name) const ;
94 OutputDataStreamPort *getOutputDataStreamPort(const std::string& name) const ;
95 virtual InputPort *createInputPort(const std::string& inputPortName, TypeCode* type);
96 virtual OutputPort *createOutputPort(const std::string& outputPortName, TypeCode* type);
97 virtual InputDataStreamPort *createInputDataStreamPort(const std::string& inputPortDSName, TypeCode* type);
98 virtual OutputDataStreamPort *createOutputDataStreamPort(const std::string& outputPortDSName, TypeCode* type);
99 virtual InputPort *edAddInputPort(const std::string& inputPortName, TypeCode* type) ;
100 virtual OutputPort *edAddOutputPort(const std::string& outputPortName, TypeCode* type) ;
101 virtual InputDataStreamPort *edAddInputDataStreamPort(const std::string& inputPortDSName, TypeCode* type) ;
102 virtual OutputDataStreamPort *edAddOutputDataStreamPort(const std::string& outputPortDSName, TypeCode* type) ;
103 virtual void edOrderInputPorts(const std::list<InputPort*>& ports);
104 virtual void edOrderOutputPorts(const std::list<OutputPort*>& ports);
106 virtual std::string typeName() {return "YACS__ENGINE__ElementaryNode";}
107 virtual void edUpdateState();
108 virtual void ensureLoading();
110 int getMaxLevelOfParallelism() const { return 1; }
111 ComplexWeight *getWeight() { return &_weight; }
112 void setWeight(double elementaryWeight);
113 void getWeightRegardingDPL(ComplexWeight *weight) { weight->addWeight(getWeight()); }
114 void partitionRegardingDPL(const PartDefinition *pd, std::map<ComposedNode *, YACS::BASES::AutoRefCnt<PartDefinition> >& zeMap) { }
123 virtual std::string getErrorDetails();
124 virtual void initService() { }
125 virtual void connectService() { }
126 virtual void disconnectService() { }
127 virtual void load() { }
128 virtual void getCoupledTasks(std::set<Task*>& coupledSet);
129 virtual void getCoupledNodes(std::set<Task*>& coupledSet);
130 void accept(Visitor *visitor);
132 // Used for runtime nodes that need
133 // to configure their services for the multi property
134 virtual void addDatastreamPortToInitMultiService(const std::string & port_name,
137 void initCommonPartWithoutStateManagement(bool start);
138 // Management of multi property
139 virtual void createMultiDatastreamPorts();
141 void edDisconnectAllLinksWithMe();
142 bool areAllInputPortsValid() const;
144 PORT *getPort(const std::string& name, const std::list<PORT *>& setOfPorts) const ;
145 template<class PORT, class ENUMTYPE>
146 PORT *edAddPort(const std::string& portName, std::list<PORT *>& setOfPorts, ENUMTYPE type) ;
147 template<class PORT, class ENUMTYPE>
148 bool edCheckAddPort(const std::string& portName, std::list<PORT *>& setOfPorts, ENUMTYPE type) ;
150 static void edRemovePortTypedFromSet(PORT *port, std::list<PORT *>& setOfPorts) ;
152 static bool isPortNameAlreadyExist(const std::string& portName, const std::list<PORT *>& setOfPorts);
156 * protected: get a port in a list given it's name
160 PORT *ElementaryNode::getPort(const std::string& name, const std::list<PORT *>& setOfPorts) const
162 for(typename std::list<PORT *>::const_iterator iter=setOfPorts.begin();iter!=setOfPorts.end();iter++)
164 if((*iter)->getName()==name)
167 std::string what="ElementaryNode::getPort : unexisting "; what+=PORT::NAME;
170 throw Exception(what);
174 * protected: add a port given it's name and type, in a given list of ports
175 * WHY TEMPLATE PARAMETER ENUMTYPE?
178 template<class PORT, class ENUMTYPE>
179 PORT *ElementaryNode::edAddPort(const std::string& portName, std::list<PORT *>& setOfPorts, ENUMTYPE type)
181 checkValidityOfPortName(portName);
182 if(isPortNameAlreadyExist<PORT>(portName, setOfPorts))
184 std::string what="Port of type "; what+=PORT::NAME; what += " with name : "; what+=portName; what+=" already exists";
185 throw Exception(what);
187 PORT *ret=new PORT(portName,this,type);
188 setOfPorts.push_back(ret);
192 template<class PORT, class ENUMTYPE>
193 bool ElementaryNode::edCheckAddPort(const std::string& portName, std::list<PORT *>& setOfPorts, ENUMTYPE type)
195 checkValidityOfPortName(portName);
196 if(isPortNameAlreadyExist<PORT>(portName, setOfPorts))
198 std::string what="Port of type "; what+=PORT::NAME; what += " with name : "; what+=portName; what+=" already exists";
199 throw Exception(what);
205 * protected: remove a port from a given list
209 void ElementaryNode::edRemovePortTypedFromSet(PORT *port, std::list<PORT *>& setOfPorts)
211 if(!isPortNameAlreadyExist<PORT>(port->getName(), setOfPorts))
212 throw Exception("Port is not part of the list : unable to remove it");
213 typename std::list<PORT *>::iterator iter=std::find(setOfPorts.begin(),setOfPorts.end(),port);
214 if(iter!=setOfPorts.end())
216 (*iter)->edRemoveAllLinksLinkedWithMe();
217 setOfPorts.erase(iter);
222 * protected: checks existence of a port, given it's name, in a list
226 bool ElementaryNode::isPortNameAlreadyExist(const std::string& portName, const std::list<PORT *>& setOfPorts)
228 for(typename std::list<PORT *>::const_iterator iter=setOfPorts.begin();iter!=setOfPorts.end();iter++)
230 if((*iter)->getName()==portName)