OpendTect-6_4  6.4
task.h
Go to the documentation of this file.
1 #ifndef task_h
2 #define task_h
3 
4 /*+
5 ________________________________________________________________________
6 
7  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
8  Author: A.H.Bril/K.Tingdahl
9  Date: 13-10-1999
10  RCS: $Id$
11 ________________________________________________________________________
12 
13 -*/
14 
15 #include "basicmod.h"
16 #include "namedobj.h"
17 #include "objectset.h"
18 #include "threadlock.h"
19 #include "uistring.h"
20 
21 class ProgressMeter;
22 namespace Threads { class ConditionVar; }
23 
24 
28 mExpClass(Basic) Task : public NamedObject
30 public:
31 
32  virtual ~Task();
33 
34  virtual void setProgressMeter(ProgressMeter*) {}
36 
37  virtual od_int64 nrDone() const { return -1; }
43  virtual od_int64 totalNr() const { return -1; }
47  virtual uiString uiMessage() const;
48  virtual uiString uiNrDoneText() const;
49  static uiString stdNrDoneText() { return tr("Nr Done"); }
50  static uiString uiStdNrDoneText() { return tr("Nr Done"); }
51  //< will disappear
52 
53  virtual bool execute() = 0;
54 
55  enum Control { Run, Pause, Stop };
56  virtual void enableWorkControl(bool=true);
58  bool workControlEnabled() const;
59  virtual void controlWork(Control);
60  virtual Control getState() const;
61 
62 protected:
63 
64  Task(const char* nm=0);
65  virtual bool shouldContinue();
69 
70 private:
71 
72  //In 7.0, this function will return a uiString
73  virtual const char* message() const { return 0; }
74  //In 7.0, this function will return a uiString
75  virtual const char* nrDoneText() const { return 0; }
76 
77 };
78 
79 
82 mExpClass(Basic) TaskGroup : public Task
83 {
84 public:
85  TaskGroup();
86  ~TaskGroup() { deepErase( tasks_ ); cleanUp(); }
87  void addTask( Task* );
88  //Becomes mine
89 
90  void setParallel(bool);
91  void showCumulativeCount(bool yn);
92  void setEmpty();
93  void getTasks(TaskGroup&);
94 
95  void setProgressMeter(ProgressMeter*);
96  virtual od_int64 nrDone() const;
97  virtual od_int64 totalNr() const;
98 
99  uiString uiMessage() const;
100  uiString uiNrDoneText() const;
101 
102  virtual bool execute();
103 
104  void enableWorkControl(bool=true);
105  virtual void controlWork(Control);
106  virtual Control getState() const;
107 
108 protected:
109 
111  int curtask_;
112 
114 
115 private:
116  void cleanUp();
117 };
118 
119 
125 {
126 public:
127  SequentialTask(const char* nm=0);
128  virtual ~SequentialTask();
129 
130  void setProgressMeter(ProgressMeter*);
131  ProgressMeter* progressMeter() { return progressmeter_; }
132  const ProgressMeter* progressMeter() const { return progressmeter_; }
133 
134  virtual int doStep();
141  static int ErrorOccurred() { return -1; }
142  static int Finished() { return 0; }
143  static int MoreToDo() { return 1; }
144  static int WarningAvailable() { return 2; }
145 
146  bool execute();
147 
148 protected:
149 
150  virtual int nextStep() = 0;
159 };
160 
161 
162 
170 {
171 public:
172  static bool execute(TaskRunner* tr, Task& );
174 
175  TaskRunner() : execres_(false) {}
176  virtual ~TaskRunner() {}
177 
178  virtual bool execute(Task& t)
179  { return (execres_ = t.execute()); }
180  virtual bool execResult() const { return execres_; }
181 
182 protected:
183 
184  bool execres_;
185 
186 };
187 
188 
189 #endif
#define mExpClass(module)
Definition: commondefs.h:160
Is an object that faciliates many threads to wait for something to happen.
Definition: thread.h:108
A lock of a type that (hopefully) suits your needs. To use it, you need the Locker class...
Definition: threadlock.h:53
is an interface where processes can report their progress.
Definition: progressmeter.h:21
#define mODTextTranslationClass(clss)
Definition: uistring.h:38
static int ErrorOccurred()
Definition: task.h:141
ProgressMeter * progressMeter()
Definition: task.h:131
TaskRunner()
Definition: task.h:175
static uiString stdNrDoneText()
Definition: task.h:49
#define od_int64
Definition: plftypes.h:36
static uiString uiStdNrDoneText()
Definition: task.h:50
Definition: uistring.h:89
static int MoreToDo()
Definition: task.h:143
Threads::Lock lock_
Definition: task.h:113
int lastupdate_
Definition: task.h:158
int curtask_
Definition: task.h:111
virtual ~TaskRunner()
Definition: task.h:176
A collection of tasks, that behave as a single task.
Definition: task.h:82
const ProgressMeter * progressMeter() const
Definition: task.h:132
Threads::ConditionVar * workcontrolcondvar_
Definition: task.h:68
interface to threads that should be portable.
Definition: atomic.h:28
The generalization of something (e.g. a computation) where the steps must be done in sequence...
Definition: task.h:124
static int Finished()
Definition: task.h:142
Class that can execute a task.
Definition: task.h:169
Control
Definition: task.h:55
virtual const char * nrDoneText() const
Definition: task.h:75
virtual void setProgressMeter(ProgressMeter *)
Must be called before execute()
Definition: task.h:34
virtual int64_t totalNr() const
Definition: task.h:43
virtual bool execute(Task &t)
Definition: task.h:178
Object with a name.
Definition: namedobj.h:35
Control control_
Definition: task.h:67
virtual int64_t nrDone() const
Definition: task.h:37
ObjectSet< Task > tasks_
Definition: task.h:110
ProgressMeter * progressmeter_
Definition: task.h:157
int doStep()
bool execres_
Definition: task.h:184
static int WarningAvailable()
Definition: task.h:144
Generalization of something (e.g. a computation) that needs to be done in multiple steps...
Definition: task.h:28
virtual bool execResult() const
Definition: task.h:180
virtual bool execute()=0
~TaskGroup()
Definition: task.h:86
virtual const char * message() const
Definition: task.h:73
void deepErase(ObjectSet< T > &os)
empty the ObjectSet deleting all objects pointed to.
Definition: objectset.h:118

Generated at for the OpendTect seismic interpretation project. Copyright (C): dGB Beheer B. V. 2019