#include <icy/sched/task.h>Inherits:
Task,ISerializable
Scheduled task with an attached trigger and scheduler association.
| 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(const std::string & type, const std::string & name)Constructs a detached task without an associated scheduler. A trigger must be set before scheduling.
type Registered type name used by TaskFactory.
name Human-readable display name.
Task(Scheduler & scheduler, const std::string & type, const std::string & name)Constructs a task associated with the given scheduler.
scheduler Scheduler that will own and run this task.
type Registered type name used by TaskFactory.
name Human-readable display name.
virtual
virtual void serialize(json::Value & root)Serializes the task to JSON.
virtual
virtual void deserialize(json::Value & root)Deserializes the task from JSON.
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.
T A concrete subclass of sched::Trigger.Raw pointer to the newly created trigger (still owned by this task).
void setTrigger(std::unique_ptr< sched::Trigger > trigger)Replaces the current trigger with trigger.
trigger Owning pointer to the new trigger; must not be null before calling.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.
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.
const
std::string type() constReturns the registered type string for this task.
const
std::string name() constReturns the human-readable display name of this task.
void setName(const std::string & name)Sets the human-readable display name.
name New display name.| Return | Name | Description |
|---|---|---|
std::string | _type | |
std::string | _name | |
sched::Scheduler * | _scheduler | |
std::unique_ptr< sched::Trigger > | _trigger | |
std::mutex | _mutex |
std::string _typestd::string _namesched::Scheduler * _schedulerstd::unique_ptr< sched::Trigger > _triggerstd::mutex _mutex| 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 |
virtual
virtual bool beforeRun()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.
virtual
virtual bool afterRun()