summaryrefslogtreecommitdiff
path: root/src/tasks/Task.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/tasks/Task.cpp')
-rw-r--r--src/tasks/Task.cpp84
1 files changed, 84 insertions, 0 deletions
diff --git a/src/tasks/Task.cpp b/src/tasks/Task.cpp
new file mode 100644
index 0000000..c20a0ea
--- /dev/null
+++ b/src/tasks/Task.cpp
@@ -0,0 +1,84 @@
+/*
+ * Task.cpp
+ *
+ * Created on: Apr 6, 2012
+ * Author: Simon
+ */
+
+
+#include <unistd.h>
+#include "Task.h"
+#include "TaskListener.h"
+
+void Task::SetTaskListener(TaskListener * listener)
+{
+ this->listener = listener;
+}
+
+void Task::Start()
+{
+ pthread_create(&doWorkThread, 0, &Task::doWork_helper, this);
+}
+
+int Task::GetProgress()
+{
+ return progress;
+}
+
+std::string Task::GetStatus()
+{
+ return status;
+}
+
+bool Task::GetDone()
+{
+ return done;
+}
+
+Task::~Task()
+{
+
+}
+
+void Task::doWork()
+{
+ notifyStatus("Fake progress");
+ for(int i = 0; i < 100; i++)
+ {
+ notifyProgress(i);
+ usleep((100)*1000);
+ }
+}
+
+void * Task::doWork_helper(void * ref)
+{
+ ((Task*)ref)->doWork();
+ ((Task*)ref)->notifyDone();
+ return NULL;
+}
+
+void Task::notifyProgress(int progress)
+{
+ if(this->progress!=progress) {
+ this->progress = progress;
+ if(listener)
+ listener->NotifyProgress(this);
+ }
+}
+
+void Task::notifyStatus(std::string status)
+{
+ if(this->status!=status) {
+ this->status = status;
+ if(listener)
+ listener->NotifyStatus(this);
+ }
+}
+
+void Task::notifyDone()
+{
+ if(listener)
+ {
+ done = true; listener->NotifyDone(this);
+ }
+}