Page MenuHomePhorge

TaskManager.h
No OneTemporary

Size
4 KB
Referenced Files
None
Subscribers
None

TaskManager.h

#ifndef _ECHO_TASKMANAGER_H_
#define _ECHO_TASKMANAGER_H_
#include <list>
#include <boost/shared_ptr.hpp>
#include <boost/make_shared.hpp>
#include "../Types.h"
#include "../Chrono/Chrono.h"
#include "Task.h"
namespace Echo
{
class Task;
/**
* TaskManagers manages a list of tasks.
* Tasks are added to task managers in order to be updated, receive pause and resume
* notifications and are started and stopped as needed.
*
*/
class TaskManager
{
public:
TaskManager(std::string name = "");
~TaskManager();
bool HasTask(Task* task) const;
bool HasTask(Task& task) const
{
return HasTask(&task);
}
inline bool HasAtLeastOneTask() const
{
return !mTaskList.empty();
}
void SetTaskManagerName(const std::string& name)
{
mManagerName = name;
}
const std::string& GetTaskManagerName() const
{
return mManagerName;
}
const bool& GetExecuting() const
{
return mExecuting;
}
const bool& GetPaused() const
{
return mPaused;
}
bool StartTasks();
void StopTasks();
bool AddTask(Task* task);
bool AddTask(Task& task)
{
return AddTask(&task);
}
void RemoveTask(Task* tTask);
void RemoveTask(Task& task)
{
RemoveTask(&task);
}
void RemoveTask(const std::string& taskName);
void RemoveAllTasks();
Task* FindTask(const std::string& name);
void PauseAllActiveTasks(bool applicationPause = false);
void ResumeAllPreviouslyActiveTasks(bool applicationResume = false);
void TaskWasPaused(Task& task);
void TaskWasResumed(Task& task);
void UpdateTasks(Seconds lastFrameTime);
void CleanUpTasks();
//!\ brief Get the number of active tasks in this manager.
//!\ param includeChildTaskManagerTasks if true include the number of tasks active in child state manages too.
//!\ param outputTaskList Outputs task names to std cout.
//!\ param indendDepth this method is recursive and this parameter is used to set the indent depth for the task lists.
size_t GetNumberOfActiveTasks(bool includeChildTaskManagerTasks = true, bool outputTaskList = false,size_t indentDepth = 0) const;
//!\ brief Get the number of tasks in this manager.
//!\ param includeChildTaskManagerTasks if true include the number of tasks active in child state manages too.
//!\ param outputTaskList Outputs task names to std cout.
//!\ param indendDepth this method is recursive and this parameter is used to set the indent depth for the task lists.
size_t GetNumberOfTasks(bool includeChildTaskManagerTasks = false, bool outputTaskList = false,size_t indentDepth = 0) const;
private:
class TaskInfo
{
public:
TaskInfo(Task* task)
{
mHasBeenRemoved = make_shared<bool>(false);
mHasBeenPaused = make_shared<bool>(false);
mCurrentPriority = task->GetPriority();
mTask = task;
}
TaskInfo(const TaskInfo& otherTaskInfo)
{
mTask = otherTaskInfo.mTask;
mHasBeenRemoved = otherTaskInfo.mHasBeenRemoved;
mHasBeenPaused = otherTaskInfo.mHasBeenPaused;
mCurrentPriority = otherTaskInfo.mCurrentPriority;
}
const TaskInfo& operator=(const TaskInfo& otherTaskInfo)
{
mTask = otherTaskInfo.mTask;
mHasBeenRemoved = otherTaskInfo.mHasBeenRemoved;
mHasBeenPaused = otherTaskInfo.mHasBeenPaused;
mCurrentPriority = otherTaskInfo.mCurrentPriority;
return *this;
}
bool operator<(const TaskInfo& other)
{
return (mCurrentPriority < other.mCurrentPriority);
}
bool operator==(const TaskInfo& otherTaskInfo) const
{
return (mTask == otherTaskInfo.GetTask());
}
bool operator==(const Task* otherTask) const
{
return (mTask == otherTask);
}
inline Task* GetTask() const
{
return mTask;
}
inline const bool& GetHasBeenRemoved() const
{
return *mHasBeenRemoved;
}
void SetHasBeenRemoved(bool hasBeenRemoved)
{
*mHasBeenRemoved = hasBeenRemoved;
}
inline const bool& GetHasBeenPaused() const
{
return *mHasBeenPaused;
}
void SetHasBeenPaused(bool hasBeenPaused)
{
*mHasBeenPaused = hasBeenPaused;
}
void UpdatePriority()
{
if(!mTask)
{
mCurrentPriority = mTask->GetPriority();
}
}
private:
Task* mTask;
u32 mCurrentPriority;
boost::shared_ptr<bool> mHasBeenRemoved; //!< Will always be valid, we use a shared pointer to easily share the value.
boost::shared_ptr<bool> mHasBeenPaused; //!< Will always be valid, we use a shared pointer to easily share the value.
};
typedef std::list< TaskInfo > TaskList;
typedef TaskList::iterator TaskListIterator;
typedef TaskList::const_iterator TaskListConstIterator;
std::string mManagerName;
TaskList mTaskList;
TaskList mActiveTaskList;
TaskList mPreviouslyActiveTaskList;
bool mExecuting;
bool mPaused;
};
}
#endif

File Metadata

Mime Type
text/x-c++
Expires
Sun, May 18, 8:59 PM (1 h, 48 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
76947
Default Alt Text
TaskManager.h (4 KB)

Event Timeline