1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #ifndef MUTATIONOFJB_TASK_H
24 #define MUTATIONOFJB_TASK_H
25 
26 #include "common/scummsys.h"
27 #include "common/ptr.h"
28 #include "common/array.h"
29 
30 namespace MutationOfJB {
31 
32 class TaskManager;
33 
34 /**
35  * Base class for tasks.
36  */
37 class Task {
38 public:
39 	enum State {
40 		IDLE,
41 		RUNNING,
42 		FINISHED
43 	};
44 
Task()45 	Task() : _taskManager(nullptr), _state(IDLE) {}
~Task()46 	virtual ~Task() {}
47 
48 	virtual void start() = 0;
49 	virtual void update() = 0;
stop()50 	virtual void stop() {
51 		assert(false);    // Assert by default - stopping might not be safe for all tasks.
52 	}
53 
setTaskManager(TaskManager * taskMan)54 	void setTaskManager(TaskManager *taskMan) {
55 		_taskManager = taskMan;
56 	}
57 
getTaskManager()58 	TaskManager *getTaskManager() {
59 		return _taskManager;
60 	}
61 
getState()62 	State getState() const {
63 		return _state;
64 	}
65 
66 protected:
setState(State state)67 	void setState(State state) {
68 		_state = state;
69 	}
70 
71 private:
72 	TaskManager *_taskManager;
73 	State _state;
74 };
75 
76 typedef Common::SharedPtr<Task> TaskPtr;
77 typedef Common::Array<Common::SharedPtr<Task> > TaskPtrs;
78 
79 }
80 
81 #endif
82