--- smsdaemon/Task.h 2008/06/09 18:15:53 26 +++ smsdaemon/Task.h 2009/12/26 23:01:01 520 @@ -1,12 +1,58 @@ #ifndef __TASK_H__ #define __TASK_H__ +#include + +class ISmsTransceiver; + +/* A Task is some piece of code that must be executed regularly, no matter whether + * the daemon has received any SMS. + * + * Tasks exist in two flavours: persistant and temporary. + * + * A persistant task is one which lives throughout the execution of the smsdaemon instance. + * A pointer to a persistant task can be retrieved via TaskManager::GetTask(std::string name), + * and thus it must have a unique name. + * + * A temporary tasks is of a more short-lived nature. It behaves like a fire-and-forget piece of code. + * A temporary task can be created at any time by any piece of code. This creation must be dynamicaly + * through the new() operator. When created it registers itself with the task manager, and here after any + * references to the task must be nulled. + * When the temporary task has done its work it must set the protected variale to true, and the + * task instance will here after be deleted by the task-manager. + * Temporary tasks does not need a unique name, and once created you cannot get a pointer to it again. + */ class Task { public: - virtual void ExecuteTask() = 0; + Task(std::string name, bool isTemporary); + + std::string GetName() + { + return _name; + } + + void RegisterTask(); + + virtual void ExecuteTask(ISmsTransceiver& modem) = 0; + + bool IsTemporary() + { + return _isTemporary; + } + bool IsFinished() + { + return _isFinished; + } + virtual ~Task() {} +protected: + bool _isFinished; + +private: + std::string _name; + bool _isTemporary; }; #endif // __TASK_H__