]> SALOME platform Git repositories - modules/yacs.git/blob - src/engine/Executor.hxx
Salome HOME
copy tag mergefrom_BR_V0_1_CC_Salome_04oct07
[modules/yacs.git] / src / engine / Executor.hxx
1 #ifndef __EXECUTOR_HXX__
2 #define __EXECUTOR_HXX__
3
4 #include "Mutex.hxx"
5 #include "Thread.hxx"
6 #include "Semaphore.hxx"
7 #include "Exception.hxx"
8 #include "define.hxx"
9
10 #include <list>
11 #include <vector>
12 #include <string>
13 #include <fstream>
14
15 namespace YACS
16 {
17   namespace ENGINE
18   {
19     class Scheduler;
20     class ComposedNode;
21     class Task;
22     
23 /*! \brief Threaded Executor 
24  *
25  * \ingroup Executors
26  *
27  *
28  */
29     class Executor
30     {
31     protected:
32       Scheduler *_mainSched;
33       ComposedNode *_root;
34       int _nbOfConcurrentThreads;
35       YACS::BASES::Mutex _mutexForNbOfConcurrentThreads;
36       YACS::BASES::Condition _condForNewTasksToPerform;
37       YACS::BASES::Semaphore _semForMaxThreads;
38       YACS::BASES::Condition _condForStepByStep;
39       YACS::BASES::Condition _condForPilot;
40       YACS::BASES::Mutex _mutexForSchedulerUpdate;
41       YACS::BASES::Mutex _mutexForTrace;
42       bool _toContinue;
43       bool _isOKToEnd;
44       bool _stopOnErrorRequested;
45       bool _dumpOnErrorRequested;
46       bool _errorDetected;
47       bool _isRunningunderExternalControl;
48       bool _isWaitingEventsFromRunningTasks;
49       int _numberOfRunningTasks;
50       int _semThreadCnt;
51       YACS::ExecutorState _executorState;
52       YACS::ExecutionMode _execMode;
53       std::list<std::string> _listOfBreakPoints;
54       std::list<std::string> _listOfTasksToLoad;
55       std::vector<Task *> _tasks; 
56       std::vector<Task *> _tasksSave; 
57       std::list< YACS::BASES::Thread * > _groupOfAllThreadsCreated;
58       std::ofstream _trace;
59       std::string _dumpErrorFile;
60     public:
61       Executor();
62       ~Executor();
63       void RunA(Scheduler *graph,int debug=0, bool fromScratch=true);
64       void RunW(Scheduler *graph,int debug=0, bool fromScratch=true) { RunB(graph, debug, fromScratch); }
65       void RunB(Scheduler *graph,int debug=0, bool fromScratch=true);
66       YACS::ExecutionMode getCurrentExecMode();
67       YACS::ExecutorState getExecutorState();
68       void setExecMode(YACS::ExecutionMode mode);
69       void setListOfBreakPoints(std::list<std::string> listOfBreakPoints);
70       std::list<std::string> getTasksToLoad();
71       bool setStepsToExecute(std::list<std::string> listToExecute);
72       bool resumeCurrentBreakPoint();
73       bool isNotFinished();
74       void stopExecution();
75       bool saveState(const std::string& xmlFile);
76       bool loadState();
77       int getNbOfThreads();
78       void displayDot(Scheduler *graph);
79       void setStopOnError(bool dumpRequested=false, std::string xmlFile="");
80       void waitPause();
81     protected:
82       bool checkBreakPoints();
83       void waitResume();
84       void loadTask(Task *task);
85       void launchTasks(std::vector<Task*>& tasks);
86       void launchTask(Task *task);
87       void wakeUp();
88       void sleepWhileNoEventsFromAnyRunningTask();
89       void notifyEndOfThread(YACS::BASES::Thread *thread);
90       void traceExec(Task *task, const std::string& message);
91       void _displayDot(Scheduler *graph);
92       virtual void sendEvent(const std::string& event);
93     protected:
94       static void *functionForTaskExecution(void *);
95     };
96   }
97 }
98
99 #endif