]> SALOME platform Git repositories - modules/yacs.git/blob - src/engine/ComposedNode.hxx
Salome HOME
1082ae90b98718e6d10dfb1f2404ea5f27e99510
[modules/yacs.git] / src / engine / ComposedNode.hxx
1 #ifndef __COMPOSEDNODE_HXX__
2 #define __COMPOSEDNODE_HXX__
3
4 #include "Node.hxx"
5 #include "Scheduler.hxx"
6
7 #include <set>
8 #include <string>
9 #include <vector>
10
11 namespace YACS
12 {
13   namespace ENGINE
14   {
15     class Bloc;
16     class InPort;
17     class OutPort;
18     class LinkInfo;
19     class ElementaryNode;
20     
21     class ComposedNode : public Node, public Scheduler
22     {
23       friend class Bloc;
24       friend class OutPort;
25       friend class ElementaryNode;
26     protected:
27       static const char SEP_CHAR_BTW_LEVEL[];
28     protected:
29       ComposedNode(const std::string& name);
30       ComposedNode(const ComposedNode& other, ComposedNode *father);
31       void performDuplicationOfPlacement(const Node& other);
32     public:
33       virtual ~ComposedNode();
34       bool isFinished();
35       void init(bool start=true);
36       std::string getName() const;
37       std::string getTaskName(Task *task) const;
38       DeploymentTree getDeploymentTree() const;
39       bool operator>(const ComposedNode& other) const;
40       bool operator<(const ComposedNode& other) const;
41       DeploymentTree checkDeploymentTree(bool deep) const throw(Exception);
42       std::vector<Task *> getNextTasks(bool& isMore);
43       virtual bool isPlacementPredictableB4Run() const = 0;
44       void notifyFrom(const Task *sender, YACS::Event event);
45       bool edAddLink(OutPort *start, InPort *end) throw(Exception);
46       virtual bool edAddDFLink(OutPort *start, InPort *end) throw(Exception);
47       bool edAddLink(OutGate *start, InGate *end) throw(Exception);
48       bool edAddCFLink(Node *nodeS, Node *nodeE) throw(Exception);
49       void edRemoveCFLink(Node *nodeS, Node *nodeE) throw(Exception);
50       void edRemoveLink(OutPort *start, InPort *end) throw(Exception);
51       void edRemoveLink(OutGate *start, InGate *end) throw(Exception);
52       virtual bool isRepeatedUnpredictablySeveralTimes() const { return false; }
53       virtual std::set<Node *> edGetDirectDescendants() const =  0;
54       std::set<ElementaryNode *> getRecursiveConstituents() const;
55       std::set<Node *> getAllRecursiveNodes();
56       virtual std::set<Node *> getAllRecursiveConstituents(); // first implementation
57       std::string getInPortName(const InPort *) const throw (Exception);
58       std::string getOutPortName(const OutPort *) const throw (Exception);
59       //
60       int getNumberOfInputPorts() const;
61       int getNumberOfOutputPorts() const;
62       std::list<InputPort *> getSetOfInputPort() const;
63       std::list<OutputPort *> getSetOfOutputPort() const;
64       std::list<InputPort *> getLocalInputPorts() const;
65       std::list<OutputPort *> getLocalOutputPorts() const;
66       std::set<OutPort *> getAllOutPortsLeavingCurrentScope() const;
67       std::set<InPort *> getAllInPortsComingFromOutsideOfCurrentScope() const;
68       std::list<InputDataStreamPort *> getSetOfInputDataStreamPort() const;
69       std::list<OutputDataStreamPort *> getSetOfOutputDataStreamPort() const;
70       OutPort *getOutPort(const std::string& name) const throw(Exception);
71       InputPort *getInputPort(const std::string& name) const throw(Exception);
72       OutputPort *getOutputPort(const std::string& name) const throw(Exception);
73       InputDataStreamPort *getInputDataStreamPort(const std::string& name) const throw(Exception);
74       OutputDataStreamPort *getOutputDataStreamPort(const std::string& name) const throw(Exception);
75       std::vector< std::pair<OutPort *, InPort *> > getSetOfInternalLinks() const;
76       std::vector< std::pair<OutPort *, InPort *> > getSetOfLinksLeavingCurrentScope() const;
77       void checkConsistency(LinkInfo& info) const throw(Exception);
78       virtual std::vector< std::pair<InPort *, OutPort *> > getSetOfLinksComingInCurrentScope() const;
79       //
80       ComposedNode *getRootNode() throw(Exception);
81       bool isNodeAlreadyAggregated(Node *node) const;
82       Node *isInMyDescendance(Node *nodeToTest) const;
83       std::string getChildName(Node* node) const throw(Exception);
84       virtual std::string getMyQualifiedName(const Node *directSon) const;
85       Node *getChildByName(const std::string& name) const throw(Exception);
86       static ComposedNode *getLowestCommonAncestor(Node *node1, Node *node2) throw(Exception);
87       void loaded();
88       void accept(Visitor *visitor);
89     protected:
90       void edDisconnectAllLinksWithMe();
91       static bool splitNamesBySep(const std::string& globalName, const char separator[],
92                                   std::string& firstPart, std::string& lastPart, bool priority) throw(Exception);
93       virtual void edRemoveChild(Node *node) throw(Exception);
94       virtual Node *getChildByShortName(const std::string& name) const throw(Exception) = 0;
95       YACS::Event updateStateFrom(Node *node, YACS::Event event);//update the state of this. Precondition : node->_father == this
96       virtual YACS::Event updateStateOnStartEventFrom(Node *node);//transition 3 doc P.R
97       virtual YACS::Event updateStateOnFinishedEventFrom(Node *node) = 0;//transition 9 doc P.R.
98       virtual YACS::Event updateStateOnFailedEventFrom(Node *node);//transition 9 doc P.R.
99       virtual void checkLinkPossibility(OutPort *start, const std::set<ComposedNode *>& pointsOfViewStart,
100                                         InPort *end, const std::set<ComposedNode *>& pointsOfViewEnd) throw(Exception);
101       virtual void buildDelegateOf(InPort * & port, OutPort *initialStart, const std::set<ComposedNode *>& pointsOfView);
102       virtual void buildDelegateOf(std::pair<OutPort *, OutPort *>& port, InPort *finalTarget, const std::set<ComposedNode *>& pointsOfView);
103       virtual void getDelegateOf(InPort * & port, OutPort *initialStart, const std::set<ComposedNode *>& pointsOfView) throw(Exception);
104       virtual void getDelegateOf(std::pair<OutPort *, OutPort *>& port, InPort *finalTarget, const std::set<ComposedNode *>& pointsOfView) throw(Exception);
105       virtual void releaseDelegateOf(InPort * & port, OutPort *initialStart, const std::set<ComposedNode *>& pointsOfView) throw(Exception);
106       virtual void releaseDelegateOf(OutPort *portDwn, OutPort *portUp, InPort *finalTarget, const std::set<ComposedNode *>& pointsOfView) throw(Exception);
107       virtual void checkNoCyclePassingThrough(Node *node) throw(Exception) = 0;
108       void checkInMyDescendance(Node *nodeToTest) const throw(Exception);
109       template <class PORT>
110       std::string getPortName(const PORT * port) const throw (Exception);
111       //For CF Computations
112       virtual void performCFComputations(LinkInfo& info) const;
113       virtual void destructCFComputations(LinkInfo& info) const;
114       void checkLinksCoherenceRegardingControl(const std::map<OutPort *, std::vector<OutPort *> >& starts,
115                                                InputPort *end, LinkInfo& info) const throw(Exception);
116       virtual void checkControlDependancy(OutPort *start, InPort *end, bool cross,
117                                           std::map < ComposedNode *,  std::list < OutPort * > >& fw,
118                                           std::vector<OutPort *>& fwCross,
119                                           std::map< ComposedNode *, std::list < OutPort *> >& bw,
120                                           LinkInfo& info) const;
121       virtual void checkCFLinks(const std::list< OutPort *>& starts, InputPort *end, unsigned char& alreadyFed, bool direction, LinkInfo& info) const;
122     protected:
123       //For internal calculations.
124       static const unsigned char FED_ST = 2;
125       static const unsigned char FREE_ST = 0;
126       static const unsigned char FED_DS_ST = 1;
127     };
128
129     template <class PORT>
130     std::string ComposedNode::getPortName(const PORT * port) const throw (Exception)
131     {
132       Node *node = port->getNode();
133       std::string portName = port->getName();  
134       checkInMyDescendance(node);
135       Node *father = node;
136       while (father != this)
137         {
138           portName = father->getQualifiedName() + Node::SEP_CHAR_IN_PORT + portName;
139           father = father->_father;
140         }
141       return portName;
142     }
143   }
144 }
145
146 #endif