wavelength 1.0.0
Loading...
Searching...
No Matches
task.h
Go to the documentation of this file.
1#pragma once
2
9class Task {
10public:
18
24 Task() : mState(kStateIdle) {
25 }
26
33 virtual ~Task();
34
42 int Poll();
43
50 void Start();
51
58 void Stop();
59
69 void Finish(bool bSucceeded);
70
78 int GetState() const;
79
80protected:
87 virtual void OnStart() {
88 }
89
96 virtual void OnStop() {
97 }
98
105 virtual void OnPoll() {
106 }
107
108private:
110 int mState;
111};
void Finish(bool bSucceeded)
End the task from outside its poll, and call OnStop() when it was running.
Task()
Construct an idle task.
Definition task.h:24
void Start()
Enter the running state and call OnStart(), unless the task is already running.
virtual void OnStop()
Abandon the work.
Definition task.h:96
void Stop()
Call OnStop() when the task is running, and return to the idle state.
virtual void OnStart()
Begin the work.
Definition task.h:87
virtual ~Task()
Release the task.
virtual void OnPoll()
Advance the work, and set mState to kStateDone when it finishes.
Definition task.h:105
int Poll()
Report the state after giving a running task one poll.
int GetState() const
Report mState.
State
Values of mState.
Definition task.h:12
@ kStateIdle
Definition task.h:13
@ kStateRunning
Definition task.h:14
@ kStateFailed
Definition task.h:16
@ kStateDone
Definition task.h:15