Salome HOME
9955cb13e6285481cc73512bda1968abc8d26f6f
[modules/yacs.git] / src / engine / Node.hxx
1 // Copyright (C) 2006-2024  CEA, EDF
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef __NODE_HXX__
21 #define __NODE_HXX__
22
23 #include "YACSlibEngineExport.hxx"
24 #include "PlayGround.hxx"
25 #include "AutoRefCnt.hxx"
26 #include "InGate.hxx"
27 #include "OutGate.hxx"
28 #include "Exception.hxx"
29 #include "define.hxx"
30
31 #include <set>
32 #include <string>
33 #include <vector>
34 #include <map>
35
36 namespace YACS
37 {
38   namespace ENGINE
39   {
40     void YACSLIBENGINE_EXPORT StateLoader(Node* node, YACS::StatesForNode state);
41     class Task;
42     class InPort;
43     class OutPort;
44     class InputPort;
45     class OutputPort;
46     class InPropertyPort;
47     class ForEachLoop;
48     class DynParaLoop;
49     class ComposedNode;
50     class Proc;
51     class ElementaryNode;
52     class Switch;
53     class InputDataStreamPort;
54     class OutputDataStreamPort;
55     class Visitor;
56
57     struct ProgressWeight
58     {
59         int weightDone;
60         int weightTotal;
61     };
62
63     class YACSLIBENGINE_EXPORT NodeStateNameMap : public std::map<YACS::StatesForNode, std::string>
64     {
65     public:
66       NodeStateNameMap();
67     };
68
69     class YACSLIBENGINE_EXPORT Node
70     {
71       friend class Bloc;
72       friend class Loop;
73       friend class Switch;
74       friend class InputPort;
75       friend class OutputPort;
76       friend class InPropertyPort;
77       friend class DynParaLoop;
78       friend class ForEachLoop;
79       friend class ComposedNode;
80       friend class ElementaryNode;
81       friend class Visitor;
82       friend void StateLoader(Node* node, YACS::StatesForNode state);
83     public:
84       mutable YACS::Colour _colour;
85     protected:
86       InGate _inGate;
87       OutGate _outGate;
88       InPropertyPort * _inPropertyPort;
89       std::string _name;
90       ComposedNode *_father;
91       YACS::StatesForNode _state;
92       int _modified;
93       std::string _errorDetails;
94       static const char SEP_CHAR_IN_PORT[];
95       static int _total;
96       int _numId;
97       std::string _implementation;
98       std::map<std::string,std::string> _propertyMap;
99       Node *_eventReceiver=nullptr;
100     protected:
101       Node(const std::string& name);
102       Node(const Node& other, ComposedNode *father);
103       //! performs a duplication of placement using clone method of containers and components. clone behaviour is driven by attachOnCloning attribute.
104       virtual void performDuplicationOfPlacement(const Node& other) = 0;
105       //! performs a also duplication of placement but here containers and components are not copied at all whatever the value of attachedOnCloning.
106       virtual void performShallowDuplicationOfPlacement(const Node& other) = 0;
107       virtual Node *simpleClone(ComposedNode *father, bool editionOnly=true) const = 0;
108     public:
109       virtual ~Node();
110       virtual void init(bool start=true);
111       virtual void shutdown(int level);
112       virtual void resetState(int level);
113       //! \b This method \b MUST \b NEVER \b BE \b VIRTUAL
114       Node *clone(ComposedNode *father, bool editionOnly=true) const;
115       //! \b This method \b MUST \b NEVER \b BE \b VIRTUAL
116       Node *cloneWithoutCompAndContDeepCpy(ComposedNode *father, bool editionOnly=true) const;
117       void setState(YACS::StatesForNode theState); // To centralize state changes
118       virtual YACS::StatesForNode getState() const { return _state; }
119       virtual YACS::StatesForNode getEffectiveState() const;
120       virtual YACS::StatesForNode getEffectiveState(const Node*) const;
121       std::string getColorState(YACS::StatesForNode state) const;
122       static std::string getStateName(YACS::StatesForNode state);
123       InGate *getInGate() { return &_inGate; }
124       OutGate *getOutGate() { return &_outGate; }
125       const std::string& getName() const { return _name; }
126       void setName(const std::string& name);
127       ComposedNode * getFather() const { return _father; }
128       const std::string getId() const;
129       bool exIsControlReady() const;
130       std::list<Node *> getOutNodes() const;
131       virtual void writeDot(std::ostream &os) const;
132       virtual void exUpdateState();
133       virtual void exFailedState();
134       virtual void exDisabledState();
135       virtual void getReadyTasks(std::vector<Task *>& tasks) = 0;
136       virtual std::list<ElementaryNode *> getRecursiveConstituents() const = 0;
137       virtual std::list<ProgressWeight> getProgressWeight() const = 0;
138       virtual int getNumberOfInputPorts() const = 0;
139       virtual int getNumberOfOutputPorts() const = 0;
140       std::list<InPort *> getSetOfInPort() const;
141       std::list<OutPort *> getSetOfOutPort() const;
142       virtual std::list<InputPort *> getSetOfInputPort() const = 0;
143       virtual std::list<OutputPort *> getSetOfOutputPort() const = 0;
144       virtual std::list<InputPort *> getLocalInputPorts() const = 0;
145       virtual std::list<OutputPort *> getLocalOutputPorts() const = 0;
146       virtual std::set<InputPort *> edGetSetOfUnitializedInputPort() const;
147       virtual bool edAreAllInputPortInitialized() const;
148       virtual std::string getInPortName(const InPort *) const = 0;
149       virtual std::string getOutPortName(const OutPort *) const = 0;
150       virtual std::list<InputDataStreamPort *> getSetOfInputDataStreamPort() const = 0;
151       virtual std::list<OutputDataStreamPort *> getSetOfOutputDataStreamPort() const = 0;
152       InPort *getInPort(const std::string& name) const;
153       InPropertyPort *getInPropertyPort() const;
154       virtual OutPort *getOutPort(const std::string& name) const;
155       virtual std::set<OutPort *> getAllOutPortsLeavingCurrentScope() const = 0;
156       virtual std::set<InPort *> getAllInPortsComingFromOutsideOfCurrentScope() const = 0;
157       virtual std::vector< std::pair<OutPort *, InPort *> > getSetOfLinksLeavingCurrentScope() const = 0;
158       virtual std::vector< std::pair<InPort *, OutPort *> > getSetOfLinksComingInCurrentScope() const =0;
159       virtual InputPort *getInputPort(const std::string& name) const;
160       virtual OutputPort *getOutputPort(const std::string& name) const = 0;
161       virtual InputDataStreamPort *getInputDataStreamPort(const std::string& name) const = 0;
162       virtual OutputDataStreamPort *getOutputDataStreamPort(const std::string& name) const = 0;
163       std::list<ComposedNode *> getAllAscendanceOf(ComposedNode *levelToStop = 0) const;
164       bool operator>(const Node& other) const;
165       bool operator<(const Node& other) const;
166       std::string getImplementation() const;
167       DynParaLoop *getClosestDPLAmongAncestors() const;
168       virtual ComposedNode *getRootNode() const;
169       virtual void setProperty(const std::string& name,const std::string& value);
170       virtual std::string getProperty(const std::string& name);
171       std::map<std::string,std::string> getProperties() ;
172       std::map<std::string,std::string> getPropertyMap() { return _propertyMap; }
173       virtual void setProperties(std::map<std::string,std::string> properties);
174       virtual Node *getChildByName(const std::string& name) const = 0;
175       virtual Proc *getProc();
176       virtual const Proc *getProc() const;
177       virtual void accept(Visitor *visitor) = 0;
178       virtual int getMaxLevelOfParallelism() const = 0;
179       virtual void getWeightRegardingDPL(ComplexWeight *weight) = 0;
180       virtual void partitionRegardingDPL(const PartDefinition *pd, std::map<ComposedNode *, YACS::BASES::AutoRefCnt<PartDefinition> >& zeMap) = 0;
181       std::string getQualifiedName() const;
182       int getNumId();
183       std::vector<std::pair<std::string,int> > getDPLScopeInfo(ComposedNode *gfn);
184       virtual void applyDPLScope(ComposedNode *gfn);
185       virtual void sendEvent(const std::string& event);
186       virtual void sendEvent2(const std::string& event, void *something);
187       static std::map<int,Node *> idMap;
188       virtual std::string typeName() { return "YACS__ENGINE__Node"; }
189       virtual std::string getErrorDetails() const { return _errorDetails; }
190       virtual void setErrorDetails(const std::string& error) { _errorDetails=error; }
191       virtual void modified();
192       virtual int isModified() { return _modified; }
193       virtual int isValid();
194       virtual void edUpdateState();
195       virtual std::string getErrorReport();
196       virtual std::string getContainerLog();
197       virtual void ensureLoading();
198       virtual void getCoupledNodes(std::set<Task*>& coupledNodes) { }
199       virtual void cleanNodes();
200     protected:
201       virtual void exForwardFailed();
202       virtual void exForwardFinished();
203       virtual void edDisconnectAllLinksWithMe();
204       static void checkValidityOfPortName(const std::string& name);
205       static ComposedNode *checkHavingCommonFather(Node *node1, Node *node2);
206     public:
207       static void checkValidityOfNodeName(const std::string& name);
208     };
209
210   }
211 }
212
213 #endif