1 #ifndef __COMPOSEDNODE_HXX__
2 #define __COMPOSEDNODE_HXX__
5 #include "Scheduler.hxx"
22 class ComposedNode : public Node, public Scheduler
27 friend class ElementaryNode;
29 static const char SEP_CHAR_BTW_LEVEL[];
31 ComposedNode(const std::string& name);
32 ComposedNode(const ComposedNode& other, ComposedNode *father);
33 void performDuplicationOfPlacement(const Node& other);
35 virtual ~ComposedNode();
37 void init(bool start=true);
38 std::string getName() const;
39 std::string getTaskName(Task *task) const;
40 DeploymentTree getDeploymentTree() 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::list<Node *> edGetDirectDescendants() const = 0;
54 std::list<ElementaryNode *> getRecursiveConstituents() const;
55 std::list<Node *> getAllRecursiveNodes();
56 virtual std::list<Node *> getAllRecursiveConstituents(); // first implementation
57 std::string getInPortName(const InPort *) const throw (Exception);
58 std::string getOutPortName(const OutPort *) const throw (Exception);
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 virtual 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 virtual std::string typeName() {return "YACS__ENGINE__ComposedNode";}
80 virtual void edUpdateState();
81 virtual std::string getErrorReport();
83 ComposedNode *getRootNode() const throw(Exception);
84 bool isNodeAlreadyAggregated(const Node *node) const;
85 virtual bool isNameAlreadyUsed(const std::string& name) const;
86 Node *isInMyDescendance(Node *nodeToTest) const;
87 std::string getChildName(const Node* node) const throw(Exception);
88 virtual std::string getMyQualifiedName(const Node *directSon) const;
89 Node *getChildByName(const std::string& name) const throw(Exception);
90 static ComposedNode *getLowestCommonAncestor(Node *node1, Node *node2) throw(Exception);
92 void accept(Visitor *visitor);
96 bool operator()(ComposedNode *n1, ComposedNode *n2) const
102 void edDisconnectAllLinksWithMe();
103 static bool splitNamesBySep(const std::string& globalName, const char separator[],
104 std::string& firstPart, std::string& lastPart, bool priority) throw(Exception);
105 virtual void edRemoveChild(Node *node) throw(Exception);
106 virtual Node *getChildByShortName(const std::string& name) const throw(Exception) = 0;
107 YACS::Event updateStateFrom(Node *node, YACS::Event event);//update the state of this. Precondition : node->_father == this
108 virtual YACS::Event updateStateOnStartEventFrom(Node *node);//transition 3 doc P.R
109 virtual YACS::Event updateStateOnFinishedEventFrom(Node *node) = 0;//transition 9 doc P.R.
110 virtual YACS::Event updateStateOnFailedEventFrom(Node *node);//transition 9 doc P.R.
111 virtual void checkLinkPossibility(OutPort *start, const std::list<ComposedNode *>& pointsOfViewStart,
112 InPort *end, const std::list<ComposedNode *>& pointsOfViewEnd) throw(Exception);
113 virtual void buildDelegateOf(InPort * & port, OutPort *initialStart, const std::list<ComposedNode *>& pointsOfView);
114 virtual void buildDelegateOf(std::pair<OutPort *, OutPort *>& port, InPort *finalTarget, const std::list<ComposedNode *>& pointsOfView);
115 virtual void getDelegateOf(InPort * & port, OutPort *initialStart, const std::list<ComposedNode *>& pointsOfView) throw(Exception);
116 virtual void getDelegateOf(std::pair<OutPort *, OutPort *>& port, InPort *finalTarget, const std::list<ComposedNode *>& pointsOfView) throw(Exception);
117 virtual void releaseDelegateOf(InPort * & port, OutPort *initialStart, const std::list<ComposedNode *>& pointsOfView) throw(Exception);
118 virtual void releaseDelegateOf(OutPort *portDwn, OutPort *portUp, InPort *finalTarget, const std::list<ComposedNode *>& pointsOfView) throw(Exception);
119 virtual void checkNoCyclePassingThrough(Node *node) throw(Exception) = 0;
120 void checkInMyDescendance(Node *nodeToTest) const throw(Exception);
121 template <class PORT>
122 std::string getPortName(const PORT * port) const throw (Exception);
123 //For CF Computations
124 void checkNoCrossHierachyWith(Node *node) const throw (Exception);
125 virtual void performCFComputations(LinkInfo& info) const;
126 virtual void destructCFComputations(LinkInfo& info) const;
127 Node *getLowestNodeDealingAll(const std::list<OutPort *>& ports) const;
128 void checkLinksCoherenceRegardingControl(const std::vector<OutPort *>& starts,
129 InputPort *end, LinkInfo& info) const throw(Exception);
130 virtual void checkControlDependancy(OutPort *start, InPort *end, bool cross,
131 std::map < ComposedNode *, std::list < OutPort * >, SortHierarc >& fw,
132 std::vector<OutPort *>& fwCross,
133 std::map< ComposedNode *, std::list < OutPort *>, SortHierarc >& bw,
134 LinkInfo& info) const = 0;
135 void solveObviousOrDelegateCFLinks(const std::list<OutPort *>& starts, InputPort *end, unsigned char& alreadyFed, bool direction, LinkInfo& info) const;
136 virtual void checkCFLinks(const std::list<OutPort *>& starts, InputPort *end, unsigned char& alreadyFed, bool direction, LinkInfo& info) const;
138 //For internal calculations.
139 static const unsigned char FED_ST = 2;
140 static const unsigned char FREE_ST = 0;
141 static const unsigned char FED_DS_ST = 1;
144 template <class PORT>
145 std::string ComposedNode::getPortName(const PORT * port) const throw (Exception)
147 Node *node = port->getNode();
148 std::string portName = port->getName();
149 checkInMyDescendance(node);
151 while (father != this)
153 portName = father->getQualifiedName() + Node::SEP_CHAR_IN_PORT + portName;
154 father = father->_father;