Task
Task
#include <icy/sched/task.h>class TaskDefined in src/sched/include/icy/sched/task.h:32
Inherits:
Task,ISerializable
Scheduled task with an attached trigger and scheduler association.
List of all members
| Name | Kind | Owner |
|---|---|---|
Scheduler | friend | Declared here |
Task | function | Declared here |
Task | function | Declared here |
serialize | function | Declared here |
deserialize | function | Declared here |
createTrigger | function | Declared here |
setTrigger | function | Declared here |
trigger | function | Declared here |
scheduler | function | Declared here |
remaining | function | Declared here |
type | function | Declared here |
name | function | Declared here |
setName | function | Declared here |
~Task | function | Declared here |
_type | variable | Declared here |
_name | variable | Declared here |
_scheduler | variable | Declared here |
_trigger | variable | Declared here |
_mutex | variable | Declared here |
beforeRun | function | Declared here |
run | function | Declared here |
afterRun | function | Declared here |
TaskRunner | friend | Inherited from Task |
Task | function | Inherited from Task |
destroy | function | Inherited from Task |
destroyed | function | Inherited from Task |
repeating | function | Inherited from Task |
id | function | Inherited from Task |
~Task | function | Inherited from Task |
Task | function | Inherited from Task |
operator= | function | Inherited from Task |
Task | function | Inherited from Task |
operator= | function | Inherited from Task |
_id | variable | Inherited from Task |
_repeating | variable | Inherited from Task |
_destroyed | variable | Inherited from Task |
run | function | Inherited from Task |
Runnable | function | Inherited from Runnable |
~Runnable | function | Inherited from Runnable |
run | function | Inherited from Runnable |
cancel | function | Inherited from Runnable |
cancelled | function | Inherited from Runnable |
exit | variable | Inherited from Runnable |
~ISerializable | function | Inherited from ISerializable |
serialize | function | Inherited from ISerializable |
deserialize | function | Inherited from ISerializable |
Inherited from Task
| Kind | Name | Description |
|---|---|---|
friend | TaskRunner | Tasks belong to a TaskRunner instance. |
function | Task | |
function | destroy virtual | Sets the task to destroyed state. |
function | destroyed virtual const | Signals that the task should be disposed of. |
function | repeating virtual const | Signals that the task should be called repeatedly by the TaskRunner. If this returns false the task will be cancelled. |
function | id virtual const | Unique task ID. |
function | ~Task virtual | |
function | Task | Deleted constructor. |
function | operator= | Deleted assignment operator. |
function | Task | Deleted constructor. |
function | operator= | Deleted assignment operator. |
variable | _id | |
variable | _repeating | |
variable | _destroyed | |
function | run virtual override | 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. |
Inherited from Runnable
| Kind | Name | Description |
|---|---|---|
function | Runnable inline | |
function | ~Runnable virtual | Defaulted destructor. |
function | run virtual | The run method will be called by the asynchronous context. |
function | cancel virtual inline | Cancel the current task. The run() method should return ASAP. |
function | cancelled virtual const inline | Returns true when the task has been cancelled. |
variable | exit |
Inherited from ISerializable
| Kind | Name | Description |
|---|---|---|
function | ~ISerializable virtual | Defaulted destructor. |
function | serialize virtual | Serializes this object's state into root. |
function | deserialize virtual | Populates this object's state from root. |
Friends
| Name | Description |
|---|---|
Scheduler |
Scheduler
friend class SchedulerDefined in src/sched/include/icy/sched/task.h:111
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 override | Serializes the task to JSON. |
void | deserialize virtual override | 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 = "")Defined in src/sched/include/icy/sched/task.h:40
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 = "")Defined in src/sched/include/icy/sched/task.h:46
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 override
virtual void serialize(json::Value & root) overrideDefined in src/sched/include/icy/sched/task.h:51
Serializes the task to JSON.
Reimplements
deserialize
virtual override
virtual void deserialize(json::Value & root) overrideDefined in src/sched/include/icy/sched/task.h:54
Deserializes the task from JSON.
Reimplements
createTrigger
inline
template<typename T> inline T * createTrigger()Defined in src/sched/include/icy/sched/task.h:61
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)Defined in src/sched/include/icy/sched/task.h:71
Replaces the current trigger with trigger.
Parameters
triggerOwning pointer to the new trigger; must not be null before calling.
trigger
sched::Trigger & trigger()Defined in src/sched/include/icy/sched/task.h:75
Returns a reference to the associated sched::Trigger or throws an exception.
scheduler
Scheduler & scheduler()Defined in src/sched/include/icy/sched/task.h:79
Returns a reference to the associated Scheduler or throws an exception.
remaining
const
std::int64_t remaining() constDefined in src/sched/include/icy/sched/task.h:85
Returns 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() constDefined in src/sched/include/icy/sched/task.h:88
Returns the registered type string for this task.
name
const
std::string name() constDefined in src/sched/include/icy/sched/task.h:91
Returns the human-readable display name of this task.
setName
void setName(const std::string & name)Defined in src/sched/include/icy/sched/task.h:95
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 _typeDefined in src/sched/include/icy/sched/task.h:113
_name
std::string _nameDefined in src/sched/include/icy/sched/task.h:114
_scheduler
sched::Scheduler * _schedulerDefined in src/sched/include/icy/sched/task.h:115
_trigger
std::unique_ptr< sched::Trigger > _triggerDefined in src/sched/include/icy/sched/task.h:116
_mutex
std::mutex _mutexDefined in src/sched/include/icy/sched/task.h:117
Protected Methods
| Return | Name | Description |
|---|---|---|
bool | beforeRun virtual | |
void | run virtual override | 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()Defined in src/sched/include/icy/sched/task.h:100
run
virtual override
virtual void run() overrideDefined in src/sched/include/icy/sched/task.h:101
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.
Reimplements
afterRun
virtual
virtual bool afterRun()