Task
Task
#include <icy/sched/task.h>Inherits:
Task,ISerializable
Scheduled task with an attached trigger and scheduler association.
Public Methods
| Return | Name | Description |
|---|---|---|
Task | Constructs a detached task without an associated scheduler. A trigger must be set before scheduling. | |
Task | Constructs a task associated with the given scheduler. | |
void | serialize virtual | Serializes the task to JSON. |
void | deserialize virtual | Deserializes the task from JSON. |
T * | createTrigger inline | Creates a trigger of type T, attaches it to this task, and returns a raw pointer to it. Ownership of the trigger is transferred to this task. |
void | setTrigger | Replaces the current trigger with trigger. |
sched::Trigger & | trigger | Returns a reference to the associated sched::Trigger or throws an exception. |
Scheduler & | scheduler | Returns a reference to the associated Scheduler or throws an exception. |
std::int64_t | remaining const | Returns the milliseconds remaining until the next scheduled timeout. An sched::Trigger must be associated or an exception will be thrown. |
std::string | type const | Returns the registered type string for this task. |
std::string | name const | Returns the human-readable display name of this task. |
void | setName | Sets the human-readable display name. |
Task
Task(const std::string & type, const std::string & name)Constructs a detached task without an associated scheduler. A trigger must be set before scheduling.
Parameters
typeRegistered type name used by TaskFactory.nameHuman-readable display name.
Task
Task(Scheduler & scheduler, const std::string & type, const std::string & name)Constructs a task associated with the given scheduler.
Parameters
schedulerScheduler that will own and run this task.typeRegistered type name used by TaskFactory.nameHuman-readable display name.
serialize
virtual
virtual void serialize(json::Value & root)Serializes the task to JSON.
deserialize
virtual
virtual void deserialize(json::Value & root)Deserializes the task from JSON.
createTrigger
inline
template<typename T> inline T * createTrigger()Creates a trigger of type T, attaches it to this task, and returns a raw pointer to it. Ownership of the trigger is transferred to this task.
Parameters
TA concrete subclass of sched::Trigger.
Returns
Raw pointer to the newly created trigger (still owned by this task).
setTrigger
void setTrigger(std::unique_ptr< sched::Trigger > trigger)Replaces the current trigger with trigger.
Parameters
triggerOwning pointer to the new trigger; must not be null before calling.
trigger
sched::Trigger & trigger()Returns a reference to the associated sched::Trigger or throws an exception.
scheduler
Scheduler & scheduler()Returns a reference to the associated Scheduler or throws an exception.
remaining
const
std::int64_t remaining() constReturns the milliseconds remaining until the next scheduled timeout. An sched::Trigger must be associated or an exception will be thrown.
type
const
std::string type() constReturns the registered type string for this task.
name
const
std::string name() constReturns the human-readable display name of this task.
setName
void setName(const std::string & name)Sets the human-readable display name.
Parameters
nameNew display name.
Protected Attributes
| Return | Name | Description |
|---|---|---|
std::string | _type | |
std::string | _name | |
sched::Scheduler * | _scheduler | |
std::unique_ptr< sched::Trigger > | _trigger | |
std::mutex | _mutex |
_type
std::string _type_name
std::string _name_scheduler
sched::Scheduler * _scheduler_trigger
std::unique_ptr< sched::Trigger > _trigger_mutex
std::mutex _mutexProtected Methods
| Return | Name | Description |
|---|---|---|
bool | beforeRun virtual | |
void | run | Called by the TaskRunner to run the task. Override this method to implement task action. Returning true means the task should be called again, and false will cause the task to be destroyed. The task will similarly be destroyed if destroy() was called during the current task iteration. |
bool | afterRun virtual |
beforeRun
virtual
virtual bool beforeRun()run
void run()Called by the TaskRunner to run the task. Override this method to implement task action. Returning true means the task should be called again, and false will cause the task to be destroyed. The task will similarly be destroyed if destroy() was called during the current task iteration.
afterRun
virtual
virtual bool afterRun()