OpendTect  6.3
task.h
Go to the documentation of this file.
1 #pragma once
2 
3 /*+
4 ________________________________________________________________________
5 
6  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
7  Author: A.H.Bril/K.Tingdahl
8  Date: 13-10-1999
9 ________________________________________________________________________
10 
11 -*/
12 
13 #include "basicmod.h"
14 #include "namedobj.h"
15 #include "objectset.h"
16 #include "threadlock.h"
17 #include "uistring.h"
18 
19 class ProgressMeter;
20 namespace Threads { class ConditionVar; }
21 
22 
28 public:
29 
30  virtual ~Task();
31 
32  virtual void setProgressMeter(ProgressMeter*) {}
34 
35  virtual uiString message() const { return stdMessage(); }
36  virtual uiString nrDoneText() const { return stdNrDoneText(); }
37  virtual od_int64 nrDone() const { return -1; }
39  virtual od_int64 totalNr() const { return -1; }
41  virtual uiRetVal errorWithDetails() const { return uiRetVal(message()); }
42 
43  virtual bool execute() = 0;
44 
45  enum Control { Run, Pause, Stop };
46  virtual void enableWorkControl(bool=true);
48  bool workControlEnabled() const;
49  virtual void controlWork(Control);
50  virtual Control getState() const;
51 
52  static uiString stdMessage() { return tr("Working");}
53  static uiString stdNrDoneText() { return tr("Nr Done");}
54 
55 protected:
56 
57  Task(const char* nm=0);
58  virtual bool shouldContinue();
62 
63 };
64 
65 
76 public:
77 
78  od_int64 nrDone() const;
80  od_int64 totalNr() const { return 100; }
81 
83  { return tr("Percentage done"); }
84 
85  void enableWorkControl(bool=true);
86  void controlWork(Control);
88 
89  int nrTasks() const { return controlledtasks_.size();}
90  const Task* getTask(int idx) const { return controlledtasks_[idx]; }
91 
92 protected:
93 
94  void controlTask(Task*);
96  void setEmpty();
97 
98 private:
99 
102 
103 };
104 
105 
109 {
110 public:
111  TaskGroup();
112  ~TaskGroup() { deepErase( tasks_ ); }
113  void addTask( Task* );
114  //Becomes mine
115 
116  void setParallel(bool) {}
117  void showCumulativeCount( bool yn )
118  { showcumulativecount_ = yn; }
119 
120  void setProgressMeter(ProgressMeter*);
121  void setEmpty();
122  void getTasks(TaskGroup&);
123 
124  od_int64 nrDone() const;
125  od_int64 totalNr() const;
126 
127  uiString message() const;
128  uiString nrDoneText() const;
129 
130  virtual bool execute();
131 
132 protected:
133 
135  int curtask_;
137 
139 
140 };
141 
142 
148 {
149 public:
150  SequentialTask(const char* nm=0);
151  virtual ~SequentialTask() {}
152 
153  void setProgressMeter(ProgressMeter*);
154  ProgressMeter* progressMeter() { return progressmeter_; }
155  const ProgressMeter* progressMeter() const { return progressmeter_; }
156 
157  virtual int doStep();
164  static int ErrorOccurred() { return -1; }
165  static int Finished() { return 0; }
166  static int MoreToDo() { return 1; }
167  static int WarningAvailable() { return 2; }
168 
169  bool execute();
170 
171 protected:
172 
173  virtual int nextStep() = 0;
182 
183 };
184 
185 
186 
194 {
195 public:
196  static bool execute(TaskRunner* tskr, Task& );
198 
199  TaskRunner() : execres_(false) {}
200  virtual ~TaskRunner() {}
201 
202  virtual bool execute(Task& t)
203  { return (execres_ = t.execute()); }
204  virtual bool execResult() const { return execres_; }
205 
206 protected:
207 
208  bool execres_;
209 
210 };
static uiString stdMessage()
Definition: task.h:52
#define mExpClass(module)
Definition: commondefs.h:157
Is an object that faciliates many threads to wait for something to happen.
Definition: thread.h:108
void showCumulativeCount(bool yn)
Definition: task.h:117
A lock of a type that (hopefully) suits your needs. To use it, you need the Locker class...
Definition: threadlock.h:51
bool showcumulativecount_
Definition: task.h:136
is an interface where processes can report their progress.
Definition: progressmeter.h:19
#define mODTextTranslationClass(clss)
Definition: uistring.h:37
static int ErrorOccurred()
Definition: task.h:164
ProgressMeter * progressMeter()
Definition: task.h:154
TaskRunner()
Definition: task.h:199
static uiString stdNrDoneText()
Definition: task.h:53
#define od_int64
Definition: plftypes.h:34
void setParallel(bool)
Definition: task.h:116
int nrTasks() const
Definition: task.h:89
virtual uiRetVal errorWithDetails() const
Definition: task.h:41
Definition: uistring.h:88
static int MoreToDo()
Definition: task.h:166
Threads::Lock lock_
Definition: task.h:138
int lastupdate_
Definition: task.h:181
int curtask_
Definition: task.h:135
const Task * getTask(int idx) const
Definition: task.h:90
virtual ~TaskRunner()
Definition: task.h:200
A collection of tasks, that behave as a single task.
Definition: task.h:108
const ProgressMeter * progressMeter() const
Definition: task.h:155
Threads::ConditionVar * workcontrolcondvar_
Definition: task.h:61
interface to threads that should be portable.
Definition: atomic.h:24
void message(const char *)
default: to stderr
The generalization of something (e.g. a computation) where the steps must be done in sequence...
Definition: task.h:147
static int Finished()
Definition: task.h:165
virtual uiString nrDoneText() const
Definition: task.h:36
Class that can execute a task.
Definition: task.h:193
Control
Definition: task.h:45
virtual uiString message() const
Definition: task.h:35
virtual ~SequentialTask()
Definition: task.h:151
int64_t totalNr() const
Definition: task.h:80
virtual void setProgressMeter(ProgressMeter *)
Must be called before execute()
Definition: task.h:32
virtual int64_t totalNr() const
Definition: task.h:39
virtual bool execute(Task &t)
Definition: task.h:202
TypeSet< float > nrdoneweights_
Definition: task.h:101
Definition: uistring.h:299
Definition: task.h:74
ObjectSet< Task > controlledtasks_
Definition: task.h:100
Control control_
Definition: task.h:60
virtual int64_t nrDone() const
Definition: task.h:37
ObjectSet< Task > tasks_
Definition: task.h:134
ProgressMeter * progressmeter_
Definition: task.h:180
int doStep()
uiString nrDoneText() const
Definition: task.h:82
bool execres_
Definition: task.h:208
static int WarningAvailable()
Definition: task.h:167
Generalization of something (e.g. a computation) that needs to be done in multiple steps...
Definition: task.h:26
virtual bool execResult() const
Definition: task.h:204
CallBacker object with a name. Use if you want your object to be able to send and receive CallBack&#39;s...
Definition: namedobj.h:50
virtual bool execute()=0
~TaskGroup()
Definition: task.h:112
void deepErase(ObjectSet< T > &os)
empty the ObjectSet deleting all objects pointed to.
Definition: objectset.h:122

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