summaryrefslogtreecommitdiff
path: root/src/tasks/Task.cpp
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-06-21 14:49:32 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-06-21 14:49:32 (GMT)
commit550f6e28e012ceba8df9274fc71c7fbddfd90530 (patch)
treef4047461c04db78e0d8c8b0a81125c6030074908 /src/tasks/Task.cpp
parent8fc3325b1c55a84d29c3b4fafe242af279c09fe5 (diff)
downloadpowder-550f6e28e012ceba8df9274fc71c7fbddfd90530.zip
powder-550f6e28e012ceba8df9274fc71c7fbddfd90530.tar.gz
Stage 1 of update process completed
Diffstat (limited to 'src/tasks/Task.cpp')
-rw-r--r--src/tasks/Task.cpp88
1 files changed, 56 insertions, 32 deletions
diff --git a/src/tasks/Task.cpp b/src/tasks/Task.cpp
index dfb8a2b..7be013e 100644
--- a/src/tasks/Task.cpp
+++ b/src/tasks/Task.cpp
@@ -10,7 +10,7 @@
#include "Task.h"
#include "TaskListener.h"
-void Task::SetTaskListener(TaskListener * listener)
+void Task::AddTaskListener(TaskListener * listener)
{
this->listener = listener;
}
@@ -37,6 +37,11 @@ std::string Task::GetStatus()
return status;
}
+std::string Task::GetError()
+{
+ return error;
+}
+
bool Task::GetDone()
{
return done;
@@ -44,38 +49,50 @@ bool Task::GetDone()
void Task::Poll()
{
- int newProgress;
- bool newDone = false;
- std::string newStatus;
- pthread_mutex_lock(&taskMutex);
- newProgress = thProgress;
- newDone = thDone;
- newStatus = std::string(thStatus);
- pthread_mutex_unlock(&taskMutex);
-
- if(newProgress!=progress) {
- progress = newProgress;
- if(listener)
- listener->NotifyProgress(this);
- }
- if(newStatus!=status) {
- status = std::string(newStatus);
- if(listener)
- listener->NotifyStatus(this);
- }
-
- if(done)
+ if(!done)
{
- pthread_join(doWorkThread, NULL);
- pthread_mutex_destroy(&taskMutex);
- after();
- }
-
- if(newDone!=done)
- {
- done = newDone;
- if(listener)
- listener->NotifyDone(this);
+ int newProgress;
+ bool newDone = false;
+ std::string newStatus;
+ std::string newError;
+ pthread_mutex_lock(&taskMutex);
+ newProgress = thProgress;
+ newDone = thDone;
+ newStatus = std::string(thStatus);
+ newError = std::string(thError);
+ pthread_mutex_unlock(&taskMutex);
+
+ if(newProgress!=progress) {
+ progress = newProgress;
+ if(listener)
+ listener->NotifyProgress(this);
+ }
+
+ if(newError!=error) {
+ error = std::string(newError);
+ if(listener)
+ listener->NotifyError(this);
+ }
+
+ if(newStatus!=status) {
+ status = std::string(newStatus);
+ if(listener)
+ listener->NotifyStatus(this);
+ }
+
+ if(done)
+ {
+ pthread_join(doWorkThread, NULL);
+ pthread_mutex_destroy(&taskMutex);
+ after();
+ }
+
+ if(newDone!=done)
+ {
+ done = newDone;
+ if(listener)
+ listener->NotifyDone(this);
+ }
}
}
@@ -131,3 +148,10 @@ void Task::notifyDone()
thDone = true;
pthread_mutex_unlock(&taskMutex);
}
+
+void Task::notifyError(std::string error)
+{
+ pthread_mutex_lock(&taskMutex);
+ thError = std::string(error);
+ pthread_mutex_unlock(&taskMutex);
+}