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