1 // Copyright (C) 2006-2012 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.
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 __SWITCH_HXX__
21 #define __SWITCH_HXX__
23 #include "YACSlibEngineExport.hxx"
24 #include "StaticDefinedComposedNode.hxx"
25 #include "ElementaryNode.hxx"
26 #include "AnyInputPort.hxx"
27 #include "OutPort.hxx"
37 class YACSLIBENGINE_EXPORT CollectorSwOutPort : public OutPort
41 int edGetNumberOfOutLinks() const;
42 std::set<InPort *> edSetInPort() const;
43 bool isAlreadyLinkedWith(InPort *with) const;
44 std::string getNameOfTypeOfCurrentInstance() const;
45 void edRemoveAllLinksLinkedWithMe() throw(Exception);
46 TypeOfChannel getTypeOfChannel() const;
47 void getAllRepresented(std::set<OutPort *>& represented) const;
48 bool addInPort(InPort *inPort) throw(Exception);
49 int removeInPort(InPort *inPort, bool forward) throw(Exception);
51 void getHumanReprOfIncompleteCases(std::ostream& stream) const;
52 private://Specific part
53 bool removePotentialProducerForMaster();
54 void checkConsistency(LinkInfo& info) const;
55 CollectorSwOutPort(Switch *master, InPort *port);
56 CollectorSwOutPort(const CollectorSwOutPort& other, Switch *master);
57 void addPotentialProducerForMaster(OutPort *port);
58 bool checkManagementOfPort(OutPort *port) throw(Exception);
61 std::string _className;
62 OutPort *_currentProducer;
63 std::map<int, OutPort *> _potentialProducers;
66 class FakeNodeForSwitch : public ElementaryNode
74 FakeNodeForSwitch(Switch *sw, bool normalFinish, bool internalError=false);
75 FakeNodeForSwitch(const FakeNodeForSwitch& other);
76 Node *simpleClone(ComposedNode *father, bool editionOnly) const;
77 void exForwardFailed();
78 void exForwardFinished();
84 class YACSLIBENGINE_EXPORT Switch : public StaticDefinedComposedNode
86 friend class FakeNodeForSwitch;
87 friend class CollectorSwOutPort;
89 static const char DEFAULT_NODE_NAME[];
90 static const char SELECTOR_INPUTPORT_NAME[];
91 static const int ID_FOR_DEFAULT_NODE;
93 AnyInputPort _condition;
94 std::map< int , Node * > _mapOfNode;//Nodes ownered
95 FakeNodeForSwitch *_undispatchableNotificationNode;
96 std::map<InPort *, CollectorSwOutPort * > _outPortsCollector;
97 mutable std::vector<CollectorSwOutPort *> _alreadyExistingCollectors;
99 Switch(const Switch& other, ComposedNode *father, bool editionOnly);
100 Switch(const std::string& name);
102 void exUpdateState();
103 void init(bool start=true);
104 //Node* DISOWNnode is a SWIG notation to indicate that the ownership of the node is transfered to C++
105 Node *edSetDefaultNode(Node *DISOWNnode);
106 Node *edReleaseDefaultNode() throw(Exception);
107 Node *edReleaseCase(int caseId) throw(Exception);
108 Node *edGetNode(int caseId);
109 Node *edSetNode(int caseId, Node *DISOWNnode) throw(Exception);
110 void edChangeCase(int oldCase, int newCase);
111 virtual bool edAddChild(Node *DISOWNnode) throw(Exception);
113 void getReadyTasks(std::vector<Task *>& tasks);
114 void selectRunnableTasks(std::vector<Task *>& tasks);
115 std::list<Node *> edGetDirectDescendants() const;
116 InputPort *edGetConditionPort() { return &_condition; }
117 void writeDot(std::ostream &os) const;
118 int getNumberOfInputPorts() const;
119 void edRemoveChild(Node *node) throw(Exception);
120 std::list<InputPort *> getSetOfInputPort() const;
121 std::list<InputPort *> getLocalInputPorts() const;
122 YACS::StatesForNode getEffectiveState() const;
123 YACS::StatesForNode getEffectiveState(const Node* node) const;
124 OutPort *getOutPort(const std::string& name) const throw(Exception);
125 InputPort* getInputPort(const std::string& name) const throw(Exception);
126 Node *getChildByShortName(const std::string& name) const throw(Exception);
127 std::string getMyQualifiedName(const Node *directSon) const;
128 std::string getCaseId(const Node *node) const throw(Exception);
129 virtual void accept(Visitor *visitor);
130 int getRankOfNode(Node *node) const;
131 virtual std::string typeName() {return "YACS__ENGINE__Switch";}
133 YACS::Event updateStateOnFinishedEventFrom(Node *node);
134 Node *simpleClone(ComposedNode *father, bool editionOnly=true) const;
135 std::set<InPort *> getAllInPortsComingFromOutsideOfCurrentScope() const;
136 void checkLinkPossibility(OutPort *start, const std::list<ComposedNode *>& pointsOfViewStart,
137 InPort *end, const std::list<ComposedNode *>& pointsOfViewEnd) throw(Exception);
138 void buildDelegateOf(std::pair<OutPort *, OutPort *>& port, InPort *finalTarget, const std::list<ComposedNode *>& pointsOfView);
139 void getDelegateOf(std::pair<OutPort *, OutPort *>& port, InPort *finalTarget, const std::list<ComposedNode *>& pointsOfView) throw(Exception);
140 void releaseDelegateOf(OutPort *portDwn, OutPort *portUp, InPort *finalTarget, const std::list<ComposedNode *>& pointsOfView) throw(Exception);
141 void checkCFLinks(const std::list<OutPort *>& starts, InputPort *end, unsigned char& alreadyFed, bool direction, LinkInfo& info) const;
142 void checkControlDependancy(OutPort *start, InPort *end, bool cross,
143 std::map < ComposedNode *, std::list < OutPort * > >& fw,
144 std::vector<OutPort *>& fwCross,
145 std::map< ComposedNode *, std::list < OutPort *> >& bw,
146 LinkInfo& info) const;
147 void checkNoCyclePassingThrough(Node *node) throw(Exception);
149 int getNbOfCases() const;
150 static std::string getRepresentationOfCase(int i);