2012-04-06 18:45:24 -05:00
|
|
|
/*
|
|
|
|
* Task.h
|
|
|
|
*
|
|
|
|
* Created on: Apr 6, 2012
|
|
|
|
* Author: Simon
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef TASK_H_
|
|
|
|
#define TASK_H_
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <pthread.h>
|
|
|
|
#include "TaskListener.h"
|
|
|
|
|
|
|
|
class TaskListener;
|
|
|
|
class Task {
|
|
|
|
public:
|
2012-06-21 09:49:32 -05:00
|
|
|
void AddTaskListener(TaskListener * listener);
|
2012-04-06 18:45:24 -05:00
|
|
|
void Start();
|
|
|
|
int GetProgress();
|
|
|
|
bool GetDone();
|
2012-06-22 13:04:38 -05:00
|
|
|
bool GetSuccess();
|
2012-06-21 09:49:32 -05:00
|
|
|
std::string GetError();
|
2012-04-06 18:45:24 -05:00
|
|
|
std::string GetStatus();
|
2012-06-20 11:51:51 -05:00
|
|
|
void Poll();
|
2012-07-28 19:33:28 -05:00
|
|
|
Task() : listener(NULL) { progress = 0; }
|
2012-04-06 18:45:24 -05:00
|
|
|
virtual ~Task();
|
|
|
|
protected:
|
|
|
|
int progress;
|
|
|
|
bool done;
|
2012-06-22 13:04:38 -05:00
|
|
|
bool success;
|
2012-04-06 18:45:24 -05:00
|
|
|
std::string status;
|
2012-06-21 09:49:32 -05:00
|
|
|
std::string error;
|
2012-06-20 11:51:51 -05:00
|
|
|
|
|
|
|
int thProgress;
|
|
|
|
bool thDone;
|
2012-06-22 13:04:38 -05:00
|
|
|
bool thSuccess;
|
2012-06-20 11:51:51 -05:00
|
|
|
std::string thStatus;
|
2012-06-21 09:49:32 -05:00
|
|
|
std::string thError;
|
2012-06-20 11:51:51 -05:00
|
|
|
|
2012-04-06 18:45:24 -05:00
|
|
|
TaskListener * listener;
|
|
|
|
pthread_t doWorkThread;
|
2012-06-20 11:51:51 -05:00
|
|
|
pthread_mutex_t taskMutex;
|
|
|
|
pthread_cond_t taskCond;
|
|
|
|
|
2012-06-21 07:22:52 -05:00
|
|
|
|
|
|
|
virtual void before();
|
|
|
|
virtual void after();
|
2012-06-22 13:04:38 -05:00
|
|
|
virtual bool doWork();
|
2012-04-06 18:45:24 -05:00
|
|
|
static void * doWork_helper(void * ref);
|
2012-06-20 11:51:51 -05:00
|
|
|
|
2012-06-21 09:49:32 -05:00
|
|
|
virtual void notifyProgress(int progress);
|
|
|
|
virtual void notifyError(std::string error);
|
|
|
|
virtual void notifyStatus(std::string status);
|
2012-06-22 13:04:38 -05:00
|
|
|
|
|
|
|
virtual void notifyProgressMain();
|
|
|
|
virtual void notifyErrorMain();
|
|
|
|
virtual void notifyStatusMain();
|
|
|
|
virtual void notifyDoneMain();
|
2012-04-06 18:45:24 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* TASK_H_ */
|