summaryrefslogtreecommitdiff
path: root/src/tasks/Task.cpp
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-06-22 18:04:38 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-06-22 18:04:38 (GMT)
commiteb52f759de6f0805865fb7f31444f2b1421b4d25 (patch)
tree49b259400c8946a8bea84c7af3f758f86a59d976 /src/tasks/Task.cpp
parent55d90a44a8425f70b08d864570e255f4bad8ba4c (diff)
downloadpowder-eb52f759de6f0805865fb7f31444f2b1421b4d25.zip
powder-eb52f759de6f0805865fb7f31444f2b1421b4d25.tar.gz
Success/Failure return from Asyn Task, Prompt to visit website upon update failure
Diffstat (limited to 'src/tasks/Task.cpp')
-rw-r--r--src/tasks/Task.cpp60
1 files changed, 43 insertions, 17 deletions
diff --git a/src/tasks/Task.cpp b/src/tasks/Task.cpp
index 7be013e..b2ded16 100644
--- a/src/tasks/Task.cpp
+++ b/src/tasks/Task.cpp
@@ -47,37 +47,43 @@ bool Task::GetDone()
return done;
}
+bool Task::GetSuccess()
+{
+ return success;
+}
+
void Task::Poll()
{
if(!done)
{
int newProgress;
bool newDone = false;
+ bool newSuccess = false;
std::string newStatus;
std::string newError;
pthread_mutex_lock(&taskMutex);
newProgress = thProgress;
newDone = thDone;
+ newSuccess = thSuccess;
newStatus = std::string(thStatus);
newError = std::string(thError);
pthread_mutex_unlock(&taskMutex);
+ success = newSuccess;
+
if(newProgress!=progress) {
progress = newProgress;
- if(listener)
- listener->NotifyProgress(this);
+ notifyProgressMain();
}
if(newError!=error) {
error = std::string(newError);
- if(listener)
- listener->NotifyError(this);
+ notifyErrorMain();
}
if(newStatus!=status) {
status = std::string(newStatus);
- if(listener)
- listener->NotifyStatus(this);
+ notifyStatusMain();
}
if(done)
@@ -90,8 +96,7 @@ void Task::Poll()
if(newDone!=done)
{
done = newDone;
- if(listener)
- listener->NotifyDone(this);
+ notifyDoneMain();
}
}
}
@@ -106,7 +111,7 @@ void Task::before()
}
-void Task::doWork()
+bool Task::doWork()
{
notifyStatus("Fake progress");
for(int i = 0; i < 100; i++)
@@ -114,6 +119,7 @@ void Task::doWork()
notifyProgress(i);
usleep((100)*1000);
}
+ return true;
}
void Task::after()
@@ -123,8 +129,11 @@ void Task::after()
void * Task::doWork_helper(void * ref)
{
- ((Task*)ref)->doWork();
- ((Task*)ref)->notifyDone();
+ bool newSuccess = ((Task*)ref)->doWork();
+ pthread_mutex_lock(&((Task*)ref)->taskMutex);
+ ((Task*)ref)->thSuccess = newSuccess;
+ ((Task*)ref)->thDone = true;
+ pthread_mutex_unlock(&((Task*)ref)->taskMutex);
return NULL;
}
@@ -142,16 +151,33 @@ void Task::notifyStatus(std::string status)
pthread_mutex_unlock(&taskMutex);
}
-void Task::notifyDone()
+void Task::notifyError(std::string error)
{
pthread_mutex_lock(&taskMutex);
- thDone = true;
+ thError = std::string(error);
pthread_mutex_unlock(&taskMutex);
}
-void Task::notifyError(std::string error)
+void Task::notifyProgressMain()
{
- pthread_mutex_lock(&taskMutex);
- thError = std::string(error);
- pthread_mutex_unlock(&taskMutex);
+ if(listener)
+ listener->NotifyProgress(this);
+}
+
+void Task::notifyStatusMain()
+{
+ if(listener)
+ listener->NotifyStatus(this);
+}
+
+void Task::notifyDoneMain()
+{
+ if(listener)
+ listener->NotifyDone(this);
+}
+
+void Task::notifyErrorMain()
+{
+ if(listener)
+ listener->NotifyError(this);
}