13#ifndef ML_BACKGROUND_TASK_H
14#define ML_BACKGROUND_TASK_H
22#include <ThirdPartyWarningsDisable.h>
23#include <boost/thread/mutex.hpp>
24#include <boost/thread/condition.hpp>
25#include <ThirdPartyWarningsRestore.h>
32class BackgroundTaskMessage;
33class BackgroundTaskStatusInformation;
67 virtual void run() = 0;
284 void aboutToFinish();
305 void runTaskFinishedCallback();
308 std::string _statusString;
310 mutable boost::mutex _statusMonitor;
311 boost::condition _statusNoLongerSuspended;
322 void* _taskFinishedCBUserData;
331 std::vector<Observer*> _observers;
#define MLBACKGROUNDTASKS_EXPORT
The base class of all background messages.
Abstract interface to observe the BackgroundTask.
virtual void logMessage(BackgroundTask *task, double elapsedSeconds, const std::string &message)=0
Called when a task logs additional messages for verbose logging.
virtual ~Observer()
Virtual destructor.
virtual void statusStringChanged(BackgroundTask *task, double elapsedSeconds, const std::string &status)=0
Called when the status string has changed.
virtual void statusChanged(BackgroundTask *task, double elapsedSeconds, BackgroundTask::Status status)=0
Called when the status has changed.
void setTaskFinishedCB(BackgroundTaskFinishedCB *callback, void *userdata)
friend class BackgroundTaskManager
void sendStatusStringChangedToObservers()
Sends the status string change to all observers.
void setSynchronousCancelField(NotifyField *field)
Sets a cancel field that is used in synchronous mode to check whether cancel was pressed.
void removeObserver(Observer *observer)
virtual ~BackgroundTask()
void sendMessageToGUI(BackgroundTaskMessage *message)
BackgroundTask(void *owner)
void waitAndExecuteNextMessage()
void addObserver(Observer *observer)
void setVerbose(bool flag)
void getStatusInformation(BackgroundTaskStatusInformation &info)
std::string statusString() const
friend struct BackgroundTaskManagerWorkerFunc
MLuint32 taskId() const
Returns the unique id of this task. The id of a task never changes.
void setSynchronous(bool flag)
Sets whether the task is handled synchronously. Call this only in the setup of the task,...
void sendStatusChangedToObservers()
Sends the status change to all observers.
virtual void setProgress(float progress)
void sendLogMessageToObservers(const std::string &msg)
Sends the status string change to all observers.
bool isVerbose() const
Checks whether task uses verbose logging.
bool isSynchronous() const
Checks whether the task is synchronous, which means it is not executed in a different thread.
void setOwnerWasDeleted()
Status
Defines current status of the task.
void logMessage(const std::string &message)
virtual void setStatusString(const std::string &status)
virtual void run()=0
Method that needs to be reimplemented. This is called from the worker thread.
void addIdleTime(double timeInSecs)
Adds given timeInSecs as spent idle time.
bool executeNextMessage()
double runningTime() const
Class to measure precise time intervals.
#define ML_DISALLOW_COPY_AND_ASSIGN(className)
Defines basic macros.
void BackgroundTaskFinishedCB(void *data, BackgroundTask *task)