1 // SUPERV GraphExecutor : contains classes that permit execution of graphs and particularly the execution automaton
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : DataFlowBase_FiniteStateMachine.cxx
25 // Author : Jean Rahuel, CEA
35 #include "DataFlowExecutor_FiniteStateMachine.hxx"
37 void * start_function( void *p ) ;
40 #define VoidState SUPERV::VoidState
41 #define ToSuspendStartState SUPERV::ToSuspendStartState
42 #define ToSuspendState SUPERV::ToSuspendState
43 #define ToSuspendDoneState SUPERV::ToSuspendDoneState
44 #define ToKillState SUPERV::ToKillState
45 #define ToKillDoneState SUPERV::ToKillDoneState
46 #define ToStopState SUPERV::ToStopState
50 #define UnKnownState GraphExecutor::UnKnownState
51 #define DataUndefState GraphExecutor::DataUndefState
52 #define DataWaitingState GraphExecutor::DataWaitingState
53 #define DataReadyState GraphExecutor::DataReadyState
54 #define SuspendedReadyState GraphExecutor::SuspendedReadyState
55 #define SuspendedReadyToResumeState GraphExecutor::SuspendedReadyToResumeState
56 #define ResumedReadyState GraphExecutor::ResumedReadyState
57 #define KilledReadyState GraphExecutor::KilledReadyState
58 #define StoppedReadyState GraphExecutor::StoppedReadyState
59 #define ExecutingState GraphExecutor::ExecutingState
60 #define SuspendedExecutingState GraphExecutor::SuspendedExecutingState
61 #define ResumedExecutingState GraphExecutor::ResumedExecutingState
62 #define KilledExecutingState GraphExecutor::KilledExecutingState
63 #define StoppedExecutingState GraphExecutor::StoppedExecutingState
64 #define SuccessedExecutingState GraphExecutor::SuccessedExecutingState
65 #define ErroredExecutingState GraphExecutor::ErroredExecutingState
66 #define SuspendedSuccessedState GraphExecutor::SuspendedSuccessedState
67 #define SuspendedErroredState GraphExecutor::SuspendedErroredState
68 #define SuspendedSuccessedToReStartState GraphExecutor::SuspendedSuccessedToReStartState
69 #define SuspendedErroredToReStartState GraphExecutor::SuspendedErroredToReStartState
70 #define ResumedSuccessedState GraphExecutor::ResumedSuccessedState
71 #define ResumedErroredState GraphExecutor::ResumedErroredState
72 #define KilledSuccessedState GraphExecutor::KilledSuccessedState
73 #define KilledErroredState GraphExecutor::KilledErroredState
74 #define StoppedSuccessedState GraphExecutor::StoppedSuccessedState
75 #define StoppedErroredState GraphExecutor::StoppedErroredState
76 #define SuccessedState GraphExecutor::SuccessedState
77 #define ErroredState GraphExecutor::ErroredState
78 #define SuspendedState GraphExecutor::SuspendedState
79 #define KilledState GraphExecutor::KilledState
80 #define StoppedState GraphExecutor::StoppedState
81 #define ReRunnedState GraphExecutor::ReRunnedState
82 #define ReStartedState GraphExecutor::ReStartedState
83 #define LoadingState GraphExecutor::LoadingState
84 #define NumberOfAutomatonStates GraphExecutor::NumberOfAutomatonStates
88 #define UndefinedEvent GraphExecutor::UndefinedEvent
89 #define NewThreadEvent GraphExecutor::NewThreadEvent
90 #define SuspendEvent GraphExecutor::SuspendEvent
91 #define ToResumeEvent GraphExecutor::ToResumeEvent
92 #define ResumeEvent GraphExecutor::ResumeEvent
93 #define KillEvent GraphExecutor::KillEvent
94 #define StopEvent GraphExecutor::StopEvent
95 #define ExecuteEvent GraphExecutor::ExecuteEvent
96 #define SuccessEvent GraphExecutor::SuccessEvent
97 #define ErrorEvent GraphExecutor::ErrorEvent
98 #define ReStartEvent GraphExecutor::ReStartEvent
99 #define ReStartAndSuspendEvent GraphExecutor::ReStartAndSuspendEvent
100 #define NoDataReadyEvent GraphExecutor::NoDataReadyEvent
101 #define SomeDataReadyEvent GraphExecutor::SomeDataReadyEvent
102 #define NotAllDataReadyEvent GraphExecutor::NotAllDataReadyEvent
103 #define AllDataReadyEvent GraphExecutor::AllDataReadyEvent
104 #define ReadyEvent GraphExecutor::ReadyEvent
105 #define SuspendedReadyEvent GraphExecutor::SuspendedReadyEvent
106 #define ResumedReadyEvent GraphExecutor::ResumedReadyEvent
107 #define KilledReadyEvent GraphExecutor::KilledReadyEvent
108 #define StoppedReadyEvent GraphExecutor::StoppedReadyEvent
109 #define ExecutingEvent GraphExecutor::ExecutingEvent
110 #define SuspendedExecutingEvent GraphExecutor::SuspendedExecutingEvent
111 #define ResumedExecutingEvent GraphExecutor::ResumedExecutingEvent
112 #define KilledExecutingEvent GraphExecutor::KilledExecutingEvent
113 #define StoppedExecutingEvent GraphExecutor::StoppedExecutingEvent
114 #define SuccessedExecutingEvent GraphExecutor::SuccessedExecutingEvent
115 #define ErroredExecutingEvent GraphExecutor::ErroredExecutingEvent
116 #define SuspendedSuccessedEvent GraphExecutor::SuspendedSuccessedEvent
117 #define SuspendedErroredEvent GraphExecutor::SuspendedErroredEvent
118 #define ResumedSuccessedEvent GraphExecutor::ResumedSuccessedEvent
119 #define ResumedErroredEvent GraphExecutor::ResumedErroredEvent
120 #define KilledEvent GraphExecutor::KilledEvent
121 #define StoppedEvent GraphExecutor::StoppedEvent
122 #define ToReStartEvent GraphExecutor::ToReStartEvent
123 #define ReStartedEvent GraphExecutor::ReStartedEvent
124 #define ReStartedAndSuspendEvent GraphExecutor::ReStartedAndSuspendEvent
125 #define EndExecuteEvent GraphExecutor::EndExecuteEvent
126 #define NumberOfEvents GraphExecutor::NumberOfEvents
128 GraphExecutor::FiniteStateMachine::FiniteStateMachine() {
129 // cdebug_in << "FiniteStateMachine::FiniteStateMachine" << endl;
131 _ControlStateName[ VoidState ] = "VoidState" ;
132 _ControlStateName[ ToSuspendStartState ]= "ToSuspendStartState" ;
133 _ControlStateName[ ToSuspendState ] = "ToSuspendState" ;
134 _ControlStateName[ ToSuspendDoneState ] = "ToSuspendDoneState" ;
135 _ControlStateName[ ToKillState ] = "ToKillState" ;
136 _ControlStateName[ ToKillDoneState ] = "ToKillDoneState" ;
137 _ControlStateName[ ToStopState ] = "ToStopState" ;
139 _StateName[ UnKnownState ] = "UnKnownState" ;
140 _StateName[ DataUndefState ] = "DataUndefState" ;
141 _StateName[ DataWaitingState ] = "DataWaitingState" ;
142 _StateName[ DataReadyState ] = "DataReadyState" ;
143 _StateName[ SuspendedReadyState ] = "SuspendedReadyState" ;
144 _StateName[ SuspendedReadyToResumeState ] = "SuspendedReadyToResumeState" ;
145 _StateName[ ResumedReadyState ] = "ResumedReadyState" ;
146 _StateName[ KilledReadyState ] = "KilledReadyState" ;
147 _StateName[ StoppedReadyState ] = "StoppedReadyState" ;
148 _StateName[ ExecutingState ] = "ExecutingState" ;
149 _StateName[ SuspendedExecutingState ] = "SuspendedExecutingState" ;
150 _StateName[ ResumedExecutingState ] = "ResumedExecutingState" ;
151 _StateName[ KilledExecutingState ] = "KilledExecutingState" ;
152 _StateName[ StoppedExecutingState ] = "StoppedExecutingState" ;
153 _StateName[ SuccessedExecutingState ] = "SuccessedExecutingState" ;
154 _StateName[ ErroredExecutingState ] = "ErroredExecutingState" ;
155 _StateName[ SuspendedSuccessedState ] = "SuspendedSuccessedState" ;
156 _StateName[ SuspendedErroredState ] = "SuspendedErroredState" ;
157 _StateName[ SuspendedSuccessedToReStartState ] = "SuspendedSuccessedToReStartState" ;
158 _StateName[ SuspendedErroredToReStartState ] = "SuspendedErroredToReStartState" ;
159 _StateName[ ResumedSuccessedState ] = "ResumedSuccessedState" ;
160 _StateName[ ResumedErroredState ] = "ResumedErroredState" ;
161 _StateName[ KilledSuccessedState ] = "KilledSuccessedState" ;
162 _StateName[ KilledErroredState ] = "KilledErroredState" ;
163 _StateName[ StoppedSuccessedState ] = "StoppedSuccessedState" ;
164 _StateName[ StoppedErroredState ] = "StoppedErroredState" ;
165 _StateName[ SuccessedState ] = "SuccessedState" ;
166 _StateName[ ErroredState ] = "ErroredState" ;
167 _StateName[ SuspendedState ] = "SuspendedState" ;
168 _StateName[ KilledState ] = "KilledState" ;
169 _StateName[ StoppedState ] = "StoppedState" ;
170 _StateName[ ReRunnedState ] = "ReRunnedState" ;
171 _StateName[ ReStartedState ] = "ReStartedState" ;
172 _StateName[ LoadingState ] = "LoadingState" ;
174 _EventName[ UndefinedEvent ] = "UndefinedEvent" ;
175 _EventName[ NewThreadEvent ] = "NewThreadEvent" ;
176 _EventName[ SuspendEvent ] = "SuspendEvent" ;
177 _EventName[ ToResumeEvent ] = "ToResumeEvent" ;
178 _EventName[ ResumeEvent ] = "ResumeEvent" ;
179 _EventName[ KillEvent ] = "KillEvent" ;
180 _EventName[ StopEvent ] = "StopEvent" ;
181 _EventName[ ExecuteEvent ] = "ExecuteEvent" ;
182 _EventName[ SuccessEvent ] = "SuccessEvent" ;
183 _EventName[ ErrorEvent ] = "ErrorEvent" ;
184 _EventName[ ToReStartEvent ] = "ToReStartEvent" ;
185 _EventName[ ReStartEvent ] = "ReStartEvent" ;
186 _EventName[ ReStartAndSuspendEvent ] = "ReStartAndSuspendEvent" ;
187 _EventName[ NoDataReadyEvent ] = "NoDataReadyEvent" ;
188 _EventName[ SomeDataReadyEvent ] = "SomeDataReadyEvent" ;
189 _EventName[ NotAllDataReadyEvent ] = "NotAllDataReadyEvent" ;
190 _EventName[ AllDataReadyEvent ] = "AllDataReadyEvent" ;
191 _EventName[ ReadyEvent ] = "ReadyEvent" ;
192 _EventName[ SuspendedReadyEvent ] = "SuspendedReadyEvent" ;
193 _EventName[ ResumedReadyEvent ] = "ResumedReadyEvent" ;
194 _EventName[ KilledReadyEvent ] = "KilledReadyEvent" ;
195 _EventName[ StoppedReadyEvent ] = "StoppedReadyEvent" ;
196 _EventName[ ExecutingEvent ] = "ExecutingEvent" ;
197 _EventName[ SuspendedExecutingEvent ] = "SuspendedExecutingEvent" ;
198 _EventName[ ResumedExecutingEvent ] = "ResumedExecutingEvent" ;
199 _EventName[ KilledExecutingEvent ] = "KilledExecutingEvent" ;
200 _EventName[ StoppedExecutingEvent ] = "StoppedExecutingEvent" ;
201 _EventName[ SuccessedExecutingEvent ] = "SuccessedExecutingEvent" ;
202 _EventName[ ErroredExecutingEvent ] = "ErroredExecutingEvent" ;
203 _EventName[ SuspendedSuccessedEvent ] = "SuspendedSuccessedEvent" ;
204 _EventName[ SuspendedErroredEvent ] = "SuspendedErroredEvent" ;
205 _EventName[ ResumedSuccessedEvent ] = "ResumedSuccessedEvent" ;
206 _EventName[ ResumedErroredEvent ] = "ResumedErroredEvent" ;
207 _EventName[ KilledEvent ] = "KilledEvent" ;
208 _EventName[ StoppedEvent ] = "StoppedEvent" ;
209 _EventName[ ReStartedEvent ] = "ReStartedEvent" ;
210 _EventName[ ReStartedAndSuspendEvent ]= "ReStartedAndSuspendEvent" ;
211 _EventName[ EndExecuteEvent ] = "EndExecuteEvent" ;
213 _ActionName[ ErrorAction ] = "ErrorAction" ;
214 _ActionName[ VoidAction ] = "VoidAction" ;
215 _ActionName[ executeAction ] = "executeAction" ;
216 _ActionName[ ExecuteAction ] = "ExecuteAction" ;
217 _ActionName[ DataWaiting_SomeDataReadyAction ] = "DataWaiting_SomeDataReadyAction" ;
218 _ActionName[ DataUndef_NotAllDataReadyAction ] = "DataUndef_NotAllDataReadyAction";
219 _ActionName[ DataUndef_AllDataReadyAction ] = "DataUndef_AllDataReadyAction" ;
221 _ActionName[ DataReady_SuspendAction ] = "DataReady_SuspendAction" ;
222 _ActionName[ SuspendedReady_ResumeAction ] = "SuspendedReady_ResumeAction" ;
223 _ActionName[ DataReady_KillAction ] = "DataReady_KillAction" ;
224 _ActionName[ DataReady_StopAction ] = "DataReady_StopAction" ;
226 _ActionName[ DataReady_ExecuteAction ] = "DataReady_ExecuteAction" ;
228 _ActionName[ Executing_SuspendAction ] = "Executing_SuspendAction" ;
229 _ActionName[ SuspendedExecuting_ResumeAction ] = "SuspendedExecuting_ResumeAction" ;
230 _ActionName[ Executing_KillAction ] = "Executing_KillAction" ;
231 _ActionName[ Executing_StopAction ] = "Executing_StopAction" ;
233 _ActionName[ Executing_SuccessAction ] = "Executing_SuccessAction" ;
234 _ActionName[ Executing_ErrorAction ] = "Executing_ErrorAction" ;
235 _ActionName[ Successed_SuccessAction ] = "Successed_SuccessAction" ;
236 _ActionName[ Errored_ErrorAction ] = "Errored_ErrorAction" ;
238 _ActionName[ Successed_SuspendAction ] = "Successed_SuspendAction" ;
239 _ActionName[ Errored_SuspendAction ] = "Errored_SuspendAction" ;
240 _ActionName[ SuspendedSuccessed_ResumeAction ] = "SuspendedSuccessed_ResumeAction" ;
241 _ActionName[ SuspendedErrored_ResumeAction ] = "SuspendedErrored_ResumeAction" ;
242 _ActionName[ Successed_KillAction ] = "Successed_KillAction" ;
243 _ActionName[ Errored_KillAction ] = "Errored_KillAction" ;
244 _ActionName[ Successed_StopAction ] = "Successed_StopAction" ;
245 _ActionName[ Errored_StopAction ] = "Errored_StopAction" ;
247 _ActionName[ SuspendedSuccessed_ReStartAction ] = "SuspendedSuccessed_ReStartAction" ;
248 _ActionName[ SuspendedErrored_ReStartAction ] = "SuspendedErrored_ReStartAction" ;
249 _ActionName[ SuspendedSuccessed_ReStartAndSuspendAction ] = "SuspendedSuccessed_ReStartAndSuspendAction" ;
250 _ActionName[ SuspendedErrored_ReStartAndSuspendAction ] = "SuspendedErrored_ReStartAndSuspendAction" ;
252 _GraphStateName[ SUPERV::UndefinedState ] = "UndefinedState" ;
253 _GraphStateName[ SUPERV::NoState ] = "NoState" ;
254 _GraphStateName[ SUPERV::EditingState ] = "EditingState" ;
255 _GraphStateName[ SUPERV::SuspendState ] = "SuspendState" ;
256 _GraphStateName[ SUPERV::WaitingState ] = "WaitingState" ;
257 _GraphStateName[ SUPERV::ReadyState ] = "ReadyState" ;
258 _GraphStateName[ SUPERV::SuspendReadyState ] = "SuspendReadyState" ;
259 _GraphStateName[ SUPERV::RunningState ] = "RunningState" ;
260 _GraphStateName[ SUPERV::DoneState ] = "DoneState" ;
261 _GraphStateName[ SUPERV::ErrorState ] = "ErrorState" ;
262 _GraphStateName[ SUPERV::SuspendDoneState ] = "SuspendDoneState" ;
263 _GraphStateName[ SUPERV::SuspendErroredState ] = "SuspendErroredState" ;
264 _GraphStateName[ SUPERV::KillState ] = "KillState" ;
265 _GraphStateName[ SUPERV::StopState ] = "StopState" ;
266 _GraphStateName[ SUPERV::ReRunState ] = "ReRunState" ;
267 _GraphStateName[ SUPERV::ReStartState ] = "ReStartState" ;
270 // NewStates = _TransitionTable[ States ] [ Events ]
271 // associated action = _ActionTable[ NewStates ] [ Events ]
272 for ( i = 0 ; i < NumberOfAutomatonStates ; i++ ) {
273 for ( j = 0 ; j < NumberOfEvents ; j++ ) {
274 // id est = SameState and VoidAction
275 _TransitionTable[ i ][ j ] = (GraphExecutor::AutomatonState ) i ;
276 _ActionTable[ i ][ j ] = GraphExecutor::ErrorAction ;
279 // OneEvent ===> Change of State and associated Action :
280 // _TransitionTable[ OldState ][ OneEvent ] gives a NewState
281 // _Action[ NewState ][ OneEvent ] gives what to do
284 // NoDataReadyEvent :
285 _TransitionTable[ DataUndefState ][ NoDataReadyEvent ] = DataWaitingState ;
286 _ActionTable[ DataWaitingState ][ NoDataReadyEvent ] = VoidAction ;
287 // SomeDataReadyEvent :
288 _TransitionTable[ DataWaitingState ][ SomeDataReadyEvent ] = DataUndefState ;
289 _ActionTable[ DataUndefState ][ SomeDataReadyEvent ] = DataWaiting_SomeDataReadyAction;
290 _TransitionTable[ DataReadyState ][ SomeDataReadyEvent ] = DataUndefState ;
291 _ActionTable[ DataUndefState ][ SomeDataReadyEvent ] = DataWaiting_SomeDataReadyAction;
292 // NotAllDataReadyEvent :
293 _TransitionTable[ DataUndefState ][ NotAllDataReadyEvent ] = DataWaitingState ;
294 _ActionTable[ DataWaitingState ][ NotAllDataReadyEvent ] = DataUndef_NotAllDataReadyAction;
296 _TransitionTable[ DataUndefState ][ AllDataReadyEvent ] = DataReadyState ;
297 _ActionTable[ DataReadyState ][ AllDataReadyEvent ] = DataUndef_AllDataReadyAction ;
299 // DATAS-READY-CONTROL :
301 _TransitionTable[ DataReadyState ][ SuspendEvent ] = SuspendedReadyState ;
302 _ActionTable[ SuspendedReadyState ][ SuspendEvent ] = DataReady_SuspendAction;
304 _TransitionTable[ SuspendedReadyState ][ ToResumeEvent ] = SuspendedReadyToResumeState ;
305 _ActionTable[ SuspendedReadyToResumeState ][ ToResumeEvent ] = VoidAction ;
307 _TransitionTable[ SuspendedReadyToResumeState ][ ResumeEvent ] = ResumedReadyState ;
308 _ActionTable[ ResumedReadyState ][ ResumeEvent] = SuspendedReady_ResumeAction ;
310 _TransitionTable[ SuspendedReadyState ][ KillEvent ] = KilledReadyState ;
312 _TransitionTable[ SuspendedReadyState ][ StopEvent ] = StoppedReadyState ;
314 _TransitionTable[ DataReadyState ][ KillEvent ] = KilledReadyState ;
315 _ActionTable[ KilledReadyState ][ KillEvent] = DataReady_KillAction ;
317 _TransitionTable[ DataReadyState ][ StopEvent ] = StoppedReadyState ;
318 _ActionTable[ StoppedReadyState ][ StopEvent] = DataReady_StopAction ;
322 _TransitionTable[ SuspendedReadyToResumeState ][ ExecuteEvent ] = ExecutingState ;
324 _TransitionTable[ ResumedReadyState ][ ExecuteEvent ] = ExecutingState ;
326 _TransitionTable[ DataReadyState ][ ExecuteEvent ] = ExecutingState ;
328 _TransitionTable[ ReStartedState ][ ExecuteEvent ] = ExecutingState ;
329 _ActionTable[ ExecutingState ][ ExecuteEvent ] = DataReady_ExecuteAction;
333 _TransitionTable[ ExecutingState ][ SuspendEvent ] = SuspendedExecutingState ;
334 _ActionTable[ SuspendedExecutingState ][ SuspendEvent ] = Executing_SuspendAction;
336 _TransitionTable[ SuspendedExecutingState ][ ResumeEvent ] = ResumedExecutingState ;
337 _ActionTable[ ResumedExecutingState ][ ResumeEvent] = SuspendedExecuting_ResumeAction;
339 _TransitionTable[ ResumedExecutingState ][ ExecuteEvent ] = ExecutingState ;
341 _TransitionTable[ SuspendedExecutingState ][ KillEvent ] = KilledExecutingState ;
343 _TransitionTable[ SuspendedExecutingState ][ StopEvent ] = StoppedExecutingState ;
345 _TransitionTable[ ExecutingState ][ KillEvent ] = KilledExecutingState ;
346 _ActionTable[ KilledExecutingState ][ KillEvent] = Executing_KillAction;
347 _TransitionTable[ KilledExecutingState ][ KillEvent ] = KilledState ;
348 _ActionTable[ KilledState ][ KillEvent] = VoidAction;
350 _TransitionTable[ ExecutingState ][ StopEvent ] = StoppedExecutingState ;
351 _ActionTable[ StoppedExecutingState ][ StopEvent] = Executing_StopAction;
352 _TransitionTable[ StoppedExecutingState ][ StopEvent ] = StoppedState ;
353 _ActionTable[ StoppedState ][ StopEvent] = VoidAction;
357 _TransitionTable[ ExecutingState ][ SuccessEvent ] = SuccessedExecutingState ;
358 _ActionTable[ SuccessedExecutingState ][ SuccessEvent ] = Executing_SuccessAction;
359 // SuspendedExecutingState : NO ResumeEvent 13-03-2003
360 _TransitionTable[ SuspendedExecutingState ][ SuccessEvent ] = SuccessedExecutingState ;
361 _ActionTable[ SuccessedExecutingState ][ SuccessEvent ] = Executing_SuccessAction;
363 _TransitionTable[ ExecutingState ][ ErrorEvent ] = ErroredExecutingState ;
364 _ActionTable[ ErroredExecutingState ][ ErrorEvent ] = Executing_ErrorAction;
365 // SuspendedExecutingState : NO ResumeEvent 13-03-2003
366 _TransitionTable[ SuspendedExecutingState ][ ErrorEvent ] = ErroredExecutingState ;
367 _ActionTable[ ErroredExecutingState ][ ErrorEvent ] = Executing_ErrorAction;
370 // SuccessedExecutingState - SuccessEvent
371 _TransitionTable[ SuccessedExecutingState ][ SuccessEvent ] = SuccessedState ;
372 _ActionTable[ SuccessedState ][ SuccessEvent ] = Successed_SuccessAction ;
373 // ErroredExecutingState - ErrorEvent
374 _TransitionTable[ ErroredExecutingState ][ ErrorEvent ] = ErroredState ;
375 _ActionTable[ ErroredState ][ ErrorEvent ] = Errored_ErrorAction ;
377 // SuccessedState - SuspendEvent
378 _TransitionTable[ SuccessedExecutingState ][ SuspendEvent ] = SuspendedSuccessedState ;
379 _ActionTable[ SuspendedSuccessedState ][ SuspendEvent ] = Successed_SuspendAction;
380 // ErroredState - SuspendEvent
381 _TransitionTable[ ErroredExecutingState ][ SuspendEvent ] = SuspendedErroredState ;
382 _ActionTable[ SuspendedErroredState ][ SuspendEvent ] = Errored_SuspendAction;
384 // SuccessedState - KillEvent
385 _TransitionTable[ SuccessedExecutingState ][ KillEvent ] = KilledSuccessedState ;
386 _ActionTable[ KilledSuccessedState ][ KillEvent ] = Successed_KillAction;
387 // ErroredState - KillEvent
388 _TransitionTable[ ErroredExecutingState ][ KillEvent ] = KilledErroredState ;
389 _ActionTable[ KilledErroredState ][ KillEvent ] = Errored_KillAction;
391 // SuccessedState - StopEvent
392 _TransitionTable[ SuccessedExecutingState ][ StopEvent ] = StoppedSuccessedState ;
393 _ActionTable[ StoppedSuccessedState ][ StopEvent ] = Successed_StopAction;
394 // ErroredState - StopEvent
395 _TransitionTable[ ErroredExecutingState ][ StopEvent ] = StoppedErroredState ;
396 _ActionTable[ StoppedErroredState ][ StopEvent ] = Errored_StopAction;
398 // SuspendedSuccessedState - ResumeEvent
399 _TransitionTable[ SuspendedSuccessedState ][ ResumeEvent ] = ResumedSuccessedState ;
400 _ActionTable[ ResumedSuccessedState ][ ResumeEvent ] = SuspendedSuccessed_ResumeAction;
402 _TransitionTable[ ResumedSuccessedState ][ ResumedSuccessedEvent ] = SuccessedState ;
403 _ActionTable[ SuccessedState ][ ResumedSuccessedEvent] = Successed_SuccessAction;
405 // SuspendedErroredState - ResumeEvent
406 _TransitionTable[ SuspendedErroredState ][ ResumeEvent ] = ResumedErroredState ;
407 _ActionTable[ ResumedErroredState ][ ResumeEvent ] = SuspendedErrored_ResumeAction;
408 _TransitionTable[ ResumedErroredState ][ ResumedErroredEvent ] = ErroredState ;
409 _ActionTable[ ErroredState ][ ResumedErroredEvent ] = Errored_ErrorAction;
411 // SuccessedState - KillEvent
412 _TransitionTable[ SuccessedState ][ KillEvent ] = KilledSuccessedState ;
413 _ActionTable[ KilledSuccessedState ][ KillEvent] = Successed_KillAction;
414 _TransitionTable[ KilledSuccessedState ][ KillEvent ] = KilledState ;
415 _ActionTable[ KilledState ][ KillEvent ] = VoidAction;
416 // ErroredState - KillEvent
417 _TransitionTable[ ErroredState ][ KillEvent ] = KilledErroredState ;
418 _ActionTable[ KilledErroredState ][ KillEvent] = Errored_KillAction;
419 _TransitionTable[ KilledErroredState ][ KillEvent ] = KilledState ;
420 _ActionTable[ KilledState ][ KillEvent ] = VoidAction;
422 // SuccessedState - StopEvent
423 _TransitionTable[ SuccessedState ][ StopEvent ] = StoppedSuccessedState ;
424 _ActionTable[ StoppedSuccessedState ][ StopEvent] = Successed_StopAction;
425 _TransitionTable[ StoppedSuccessedState ][ StopEvent ] = StoppedState ;
426 _ActionTable[ StoppedState ][ StopEvent ] = VoidAction;
427 // ErroredState - StopEvent
428 _TransitionTable[ ErroredState ][ StopEvent ] = StoppedErroredState ;
429 _ActionTable[ StoppedErroredState ][ StopEvent] = Errored_StopAction;
430 _TransitionTable[ StoppedErroredState ][ StopEvent ] = StoppedState ;
431 _ActionTable[ StoppedState ][ StopEvent ] = VoidAction;
434 _TransitionTable[ SuspendedSuccessedState ][ ToReStartEvent ] = SuspendedSuccessedToReStartState ;
435 _ActionTable[ SuspendedSuccessedToReStartState ][ ToReStartEvent] = VoidAction ;
437 _TransitionTable[ SuspendedSuccessedToReStartState ][ ReStartEvent ] = ReStartedState ;
438 _TransitionTable[ SuspendedSuccessedToReStartState ][ ReStartAndSuspendEvent ] = ReStartedState ;
440 _TransitionTable[ SuspendedErroredState ][ ToReStartEvent ] = SuspendedErroredToReStartState ;
441 _ActionTable[ SuspendedErroredToReStartState ][ ToReStartEvent] = VoidAction ;
443 _TransitionTable[ SuspendedErroredToReStartState ][ ReStartEvent ] = ReStartedState ;
444 _TransitionTable[ SuspendedErroredToReStartState ][ ReStartAndSuspendEvent ] = ReStartedState ;
446 _ActionTable[ ReStartedState ][ ReStartEvent] = SuspendedSuccessed_ReStartAction;
447 _ActionTable[ ReStartedState ][ ReStartAndSuspendEvent] = SuspendedSuccessed_ReStartAndSuspendAction;
449 pthread_mutex_init( &_MutexJoinWait , NULL ) ;
450 if ( pthread_cond_init( &_JoinWait , NULL ) ) {
451 perror("pthread_cond_init( &_JoinWait , NULL )") ;
455 if ( pthread_create( &_JoinThreadNo , NULL , start_function , this ) ) {
456 char * msg = "Cannot pthread_create " ;
460 pthread_mutex_init( &_MutexPythonWait , NULL ) ;
461 _MutexPythonLocked = false ;
463 _GraphExecutingNumber = 0 ;
464 _PyInitModule = false ;
466 // cdebug_out << "FiniteStateMachine::FiniteStateMachine _TransitionTable "
470 void * start_function( void *p ) {
471 GraphExecutor::FiniteStateMachine *anAutomaton = (GraphExecutor::FiniteStateMachine *) p;
472 if ( pthread_setcanceltype( PTHREAD_CANCEL_ASYNCHRONOUS , NULL ) ) {
473 perror("pthread_setcanceltype ") ;
476 if ( pthread_setcancelstate( PTHREAD_CANCEL_ENABLE , NULL ) ) {
477 perror("pthread_setcancelstate ") ;
480 anAutomaton->JoinThread() ;
481 pthread_exit( PTHREAD_CANCELED ) ;
484 int GraphExecutor::FiniteStateMachine::ExecNumber() {
487 int RetVal = _ExecNumber ;
488 _GraphExecutingNumber += 1 ;
493 void GraphExecutor::FiniteStateMachine::Executed() {
495 _GraphExecutingNumber -= 1 ;
496 if ( _GraphExecutingNumber == 0 ) {
497 map< string , PyObject * >::iterator aPyFunction ;
498 for ( aPyFunction = _MapOfPyFunctions.begin() ; aPyFunction != _MapOfPyFunctions.end() ; aPyFunction++ ) {
499 if ( !strcmp( aPyFunction->first.c_str() , "PyObjRef" ) ||
500 !strcmp( aPyFunction->first.c_str() , "PyObjIor" ) ) {
501 //cout << "GraphExecutor::FiniteStateMachine::Executed " << aPyFunction->first << " keeped ..."<< endl ;
504 //cout << "GraphExecutor::FiniteStateMachine::Executed " << aPyFunction->first << " erased ..."<< endl ;
505 _MapOfPyFunctions.erase( aPyFunction->first ) ;
510 //cout << "GraphExecutor::FiniteStateMachine::Executed _GraphExecutingNumber " << _GraphExecutingNumber
511 // << " != 0 ==> no erase" << endl ;
517 void GraphExecutor::FiniteStateMachine::PyInitModule( bool aPyInitModule ) {
518 _PyInitModule = aPyInitModule ;
521 bool GraphExecutor::FiniteStateMachine::PyInitModule() {
522 bool InitedModule = _PyInitModule ;
523 _PyInitModule = true ;
524 return InitedModule ;
527 void GraphExecutor::FiniteStateMachine::PyLock() {
528 // cout << pthread_self() << " GraphExecutor::FiniteStateMachine::PyLock " << &_MutexPythonWait << endl ;
529 if ( pthread_mutex_lock( &_MutexPythonWait ) ) {
530 perror( "GraphExecutor::FiniteStateMachine::PyLock" ) ;
533 _MutexPythonLocked = true ;
534 // cout << pthread_self() << " GraphExecutor::FiniteStateMachine::PyLocked " << &_MutexPythonWait << endl ;
537 void GraphExecutor::FiniteStateMachine::PyUnLock() {
538 // cout << pthread_self() << " GraphExecutor::FiniteStateMachine::PyUnLock " << &_MutexPythonWait << endl ;
539 if ( pthread_mutex_unlock( &_MutexPythonWait ) ) {
540 perror( "GraphExecutor::FiniteStateMachine::PyUnLock" ) ;
543 _MutexPythonLocked = false ;
544 // cout << pthread_self() << " GraphExecutor::FiniteStateMachine::PyUnLocked " << &_MutexPythonWait << endl ;
547 void GraphExecutor::FiniteStateMachine::PyLockReset() {
548 if ( _MutexPythonLocked ) {
553 PyObject * GraphExecutor::FiniteStateMachine::PyFunction( const char * aPyFuncName ) {
555 PyObject * RetVal = NULL ;
556 bool PyObjRefIor = !strcmp( aPyFuncName , "PyObjRef" ) || !strcmp( aPyFuncName , "PyObjIor" ) ;
557 PyObject * PyFunctionMapped = _MapOfPyFunctions[ aPyFuncName ] ;
558 if ( _GraphExecutingNumber > 1 && !PyObjRefIor ) {
559 RetVal = PyFunctionMapped ;
560 //cout << "GraphExecutor::FiniteStateMachine::PyFunction( '" << aPyFuncName << "' ) --> " ;
562 //cout << RetVal << " ob_refcnt " << RetVal->ob_refcnt ;
570 RetVal = PyFunctionMapped ;
571 //cout << "GraphExecutor::FiniteStateMachine::PyFunction( '" << aPyFuncName << "' ) --> " ;
572 if ( RetVal && PyObjRefIor ) {
573 //cout << RetVal << " " << RetVal->ob_refcnt << endl ;
576 //cout << RetVal << " " << RetVal->ob_refcnt << endl ;
577 // _MapOfPyFunctions.erase( aPyFuncName ) ;
578 // cout << "GraphExecutor::FiniteStateMachine::PyFunction( '" << aPyFuncName << "' ) erased --> NULL" << endl ;
581 //cout << " NULL" << endl ;
588 bool GraphExecutor::FiniteStateMachine::PyFunction( const char * aPyFuncName , PyObject * aPyFunction ) {
590 bool RetVal = false ;
591 if ( _MapOfPyFunctions[ aPyFuncName ] != NULL ) {
592 //PyObject * aPyFunc = _MapOfPyFunctions[ aPyFuncName ] ;
593 //cout << "GraphExecutor::FiniteStateMachine::PyFunction( '" << aPyFuncName << "' , " << aPyFunction
594 // << " ) ob_refcnt " << aPyFunction->ob_refcnt << " already mapped : " << aPyFunc << " ob_refcnt "
595 // << aPyFunc->ob_refcnt << endl ;
598 _MapOfPyFunctions[ aPyFuncName ] = aPyFunction ;
599 //cout << "GraphExecutor::FiniteStateMachine::PyFunction( '" << aPyFuncName << "' , " << aPyFunction
600 // << " ) ob_refcnt " << aPyFunction->ob_refcnt << " mapped" << endl ;
607 GraphBase::Graph * GraphExecutor::FiniteStateMachine::MapGraph( const char * aGraphName ) {
608 GraphBase::Graph * aGraph = _MapOfGraphs[ aGraphName ] ;
609 //cout << "MapGraph " << aGraphName << " --> " << aGraph << endl ;
613 bool GraphExecutor::FiniteStateMachine::MapGraph( GraphBase::Graph * aGraph , const char * aGraphName ) {
614 if ( MapGraph( aGraphName ) ) {
617 _MapOfGraphs[ aGraphName ] = aGraph ;
621 void GraphExecutor::FiniteStateMachine::EraseGraph( const char * aGraphName ) {
622 _MapOfGraphs.erase( aGraphName ) ;
625 bool GraphExecutor::FiniteStateMachine::GraphName( const char * aGraphName ) {
626 return _MapOfGraphNames[ aGraphName ] ;
629 string GraphExecutor::FiniteStateMachine::GraphInstanceName( const char * aGraphName ) {
630 int GraphInstanceNumber = _MapOfGraphNames[ aGraphName ] ;
631 if ( GraphInstanceNumber ) {
632 _MapOfGraphNames[ aGraphName ] = GraphInstanceNumber + 1 ;
635 GraphInstanceNumber = 0 ;
636 _MapOfGraphNames[ aGraphName ] = GraphInstanceNumber + 1 ;
638 string theGraphInstanceName = string( aGraphName ) ;
639 if ( GraphInstanceNumber ) {
640 theGraphInstanceName += "_" ;
642 // astr << GraphInstanceNumber << ends ;
643 astr << GraphInstanceNumber ;
644 theGraphInstanceName += astr.str() ;
646 //cout << "GraphExecutor::FiniteStateMachine::GraphInstanceName( " << aGraphName << " ) --> "
647 // << theGraphInstanceName << endl ;
648 return theGraphInstanceName ;
652 void GraphExecutor::FiniteStateMachine::JoinThread() {
653 if ( pthread_mutex_lock( &_MutexJoinWait ) ) {
654 perror("FiniteStateMachine:JoinThread pthread_mutex_lock ") ;
657 while ( _JoinThread ) {
658 while ( _ThreadList.size() == 0) {
659 // MESSAGE( pthread_self() << " FiniteStateMachine:Join pthread_cond_wait" );
660 if ( pthread_cond_wait( &_JoinWait , &_MutexJoinWait ) ) {
661 perror("FiniteStateMachine:JoinThread pthread_cond_wait ") ;
664 pthread_t _Thread = _ThreadList.front() ;
665 // MESSAGE( pthread_self() << " FiniteStateMachine:JoinThread pthread_cond_waited : " << _Thread )
666 // MESSAGE( pthread_self() << " FiniteStateMachine:JoinThread pthread_join : " << _Thread );
667 int joinsts = pthread_join( _Thread , NULL ) ;
669 perror("FiniteStateMachine:JoinThread pthread_join ") ;
670 MESSAGE( pthread_self() << " FiniteStateMachine:JoinThread pthread_join : " << _Thread
675 MESSAGE( pthread_self() << " FiniteStateMachine:JoinThread pthread_joined : " << _Thread );
676 _ThreadList.pop_front() ;
679 if ( pthread_mutex_unlock( &_MutexJoinWait ) ) {
680 perror("FiniteStateMachine:JoinThread pthread_mutex_unlock ") ;
685 void GraphExecutor::FiniteStateMachine::JoinThread( pthread_t aThread ) {
686 if ( pthread_mutex_lock( &_MutexJoinWait ) ) {
687 perror("Join pthread_mutex_lock ") ;
690 // MESSAGE(pthread_self() << " JoinThread pthread_cond_signal for " << aThread)
691 _ThreadList.push_back( aThread ) ;
692 if ( pthread_cond_signal( &_JoinWait ) ) {
693 perror("Join pthread_cond_signal ") ;
695 // MESSAGE( pthread_self() << " JoinThread pthread_cond_signaled for " << aThread)
697 if ( pthread_mutex_unlock( &_MutexJoinWait ) ) {
698 perror("Join pthread_mutex_unlock ") ;
703 ostream & operator<< (ostream &f ,const GraphExecutor::AutomatonState & aState ) {
705 case GraphExecutor::UnKnownState :
708 case GraphExecutor::DataUndefState :
709 f << "DataUndefState";
711 case GraphExecutor::DataWaitingState :
712 f << "DataWaitingState";
714 case GraphExecutor::DataReadyState :
715 f << "DataReadyState";
717 case GraphExecutor::SuspendedReadyState :
718 f << "SuspendedReadyState";
720 case GraphExecutor::SuspendedReadyToResumeState :
721 f << "SuspendedReadyToResumeState";
723 case GraphExecutor::ResumedReadyState :
724 f << "ResumedReadyState";
726 case GraphExecutor::KilledReadyState :
727 f << "KilledReadyState";
729 case GraphExecutor::StoppedReadyState :
730 f << "StoppedReadyState";
732 case GraphExecutor::ExecutingState :
733 f << "ExecutingState";
735 case GraphExecutor::SuspendedExecutingState :
736 f << "SuspendedExecutingState";
738 case GraphExecutor::ResumedExecutingState :
739 f << "ResumedExecutingState";
741 case GraphExecutor::KilledExecutingState :
742 f << "KilledExecutingState";
744 case GraphExecutor::StoppedExecutingState :
745 f << "StoppedExecutingState";
747 case GraphExecutor::SuccessedExecutingState :
748 f << "SuccessedExecutingState";
750 case GraphExecutor::ErroredExecutingState :
751 f << "ErroredExecutingState";
753 case GraphExecutor::SuspendedSuccessedState :
754 f << "SuspendedSuccessedState";
756 case GraphExecutor::SuspendedErroredState :
757 f << "SuspendedErroredState";
759 case GraphExecutor::ResumedSuccessedState :
760 f << "ResumedSuccessedState";
762 case GraphExecutor::ResumedErroredState :
763 f << "ResumedErroredState";
765 case GraphExecutor::KilledSuccessedState :
766 f << "KilledSuccessedState";
768 case GraphExecutor::KilledErroredState :
769 f << "KilledErroredState";
771 case GraphExecutor::StoppedSuccessedState :
772 f << "StoppedSuccessedState";
774 case GraphExecutor::StoppedErroredState :
775 f << "StoppedErroredState";
777 case GraphExecutor::SuccessedState :
778 f << "SuccessedState";
780 case GraphExecutor::ErroredState :
783 case GraphExecutor::SuspendedState :
784 f << "SuspendedState";
786 case GraphExecutor::KilledState :
789 case GraphExecutor::StoppedState :
792 case GraphExecutor::SuspendedSuccessedToReStartState :
793 f << "SuspendedSuccessedToReStartState";
795 case GraphExecutor::SuspendedErroredToReStartState :
796 f << "SuspendedErroredToReStartState";
798 case GraphExecutor::ReRunnedState :
799 f << "ReRunnedState";
801 case GraphExecutor::ReStartedState :
802 f << "ReStartedState";
804 case GraphExecutor::LoadingState :
808 f << "GraphExecutor::AutomatonState_?";