summaryrefslogtreecommitdiff
path: root/src/tasks/Task.h
blob: a025ac10b15923dc93f1733207c80ed90d8841eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
 * Task.h
 *
 *  Created on: Apr 6, 2012
 *      Author: Simon
 */

#ifndef TASK_H_
#define TASK_H_

#include <string>
#include <pthread.h>
#undef GetUserName //God dammit microsoft!
#include "TaskListener.h"

class TaskListener;
class Task {
public:
	void AddTaskListener(TaskListener * listener);
	void Start();
	int GetProgress();
	bool GetDone();
	bool GetSuccess();
	std::string GetError();
	std::string GetStatus();
	void Poll();
	Task() : listener(NULL) { progress = 0; }
	virtual ~Task();
protected:
	int progress;
	bool done;
	bool success;
	std::string status;
	std::string error;

	int thProgress;
	bool thDone;
	bool thSuccess;
	std::string thStatus;
	std::string thError;

	TaskListener * listener;
	pthread_t doWorkThread;
	pthread_mutex_t taskMutex;
	pthread_cond_t taskCond;


	virtual void before();
	virtual void after();
	virtual bool doWork();
	static void * doWork_helper(void * ref);

	virtual void notifyProgress(int progress);
	virtual void notifyError(std::string error);
	virtual void notifyStatus(std::string status);

	virtual void notifyProgressMain();
	virtual void notifyErrorMain();
	virtual void notifyStatusMain();
	virtual void notifyDoneMain();
};

#endif /* TASK_H_ */