]> SALOME platform Git repositories - modules/yacs.git/blob - src/engine/InGate.cxx
Salome HOME
mergefrom branch BR_V511_PR tag mergeto_trunk_03feb09
[modules/yacs.git] / src / engine / InGate.cxx
1 //  Copyright (C) 2006-2008  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.
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 #include "InGate.hxx"
20 #include "Node.hxx"
21
22 //#define _DEVDEBUG_
23 #include "YacsTrace.hxx"
24
25 using namespace YACS::ENGINE;
26 using namespace std;
27
28 const char InGate::NAME[]="InGate";
29
30 InGate::InGate(Node *node):Port(node)
31 {
32 }
33
34 InGate::~InGate()
35 {
36 }
37
38 string InGate::getNameOfTypeOfCurrentInstance() const
39 {
40   return NAME;
41 }
42
43 void InGate::edDisconnectAllLinksToMe()
44 {
45   for(map<OutGate *, bool >::iterator iter=_backLinks.begin();iter!=_backLinks.end();iter++)
46     ((*iter).first)->edRemoveInGate(this,false);
47   _backLinks.clear();
48 }
49
50 //! Notify this port that an upstream node connected by a control flow link is finished
51 /*!
52  *  Calls the node's gate method : Node::exUpdateState
53  *
54  *  Called by OutGate::exNotifyDone
55  */
56 void InGate::exNotifyFromPrecursor(OutGate *from)
57 {
58   DEBTRACE("InGate::exNotifyFromPrecursor");
59   map< OutGate *, bool >::iterator iter=_backLinks.find(from);
60   (*iter).second=true;
61   if(exIsReady())
62     _node->exUpdateState();
63 }
64
65 //! Notify this port that an upstream node connected by a control flow link has failed
66 /*!
67  *
68  */
69 void InGate::exNotifyFailed()
70 {
71   if(_node) _node->exFailedState();
72 }
73
74 //! Notify this port that an upstream node connected by a control flow link has been disabled
75 /*!
76  *
77  */
78 void InGate::exNotifyDisabled()
79 {
80   if(_node)
81     _node->exDisabledState();
82 }
83
84 void InGate::edAppendPrecursor(OutGate *from)
85 {
86   _backLinks[from]=false;
87 }
88
89 void InGate::edRemovePrecursor(OutGate *from)
90 {
91   _backLinks.erase(from);
92 }
93
94 int InGate::getNumberOfBackLinks() const
95 {
96   return _backLinks.size();
97 }
98
99 void InGate::exReset()
100 {
101   for(map<OutGate *, bool >::iterator iter=_backLinks.begin();iter!=_backLinks.end();iter++)
102     (*iter).second=false;
103 }
104
105 bool InGate::exIsReady() const
106 {
107   bool isReady=true;
108   for(map<OutGate *, bool >::const_iterator iter=_backLinks.begin();iter!=_backLinks.end() && isReady;iter++)
109     isReady=(*iter).second;
110   return isReady;
111 }
112
113 std::list<OutGate *> InGate::getBackLinks()
114 {
115   list<OutGate *> listo;
116   for(map<OutGate *, bool >::iterator iter=_backLinks.begin();iter!=_backLinks.end();iter++)
117     listo.push_back(iter->first);
118   return listo;  
119 }
120
121 void InGate::setPrecursorDone(OutGate *from)
122 {
123   map< OutGate *, bool >::iterator iter=_backLinks.find(from);
124   (*iter).second=true;  
125 }