TrinityCore
Loading...
Searching...
No Matches
TaskContext Class Reference

#include <TaskScheduler.h>

Public Member Functions

 TaskContext ()
 
 TaskContext (TaskScheduler::TaskContainer &&task, std::weak_ptr< TaskScheduler > &&owner)
 
 TaskContext (TaskContext const &right)
 
 TaskContext (TaskContext &&right)
 
TaskContextoperator= (TaskContext const &right)
 
TaskContextoperator= (TaskContext &&right)
 
bool IsExpired () const
 Returns true if the owner was deallocated and this context has expired.
 
bool IsInGroup (TaskScheduler::group_t const group) const
 Returns true if the event is in the given group.
 
TaskContextSetGroup (TaskScheduler::group_t const group)
 Sets the event in the given group.
 
TaskContextClearGroup ()
 Removes the group from the event.
 
TaskScheduler::repeated_t GetRepeatCounter () const
 Returns the repeat counter which increases every time the task is repeated.
 
template<class _Rep , class _Period >
TaskContextRepeat (std::chrono::duration< _Rep, _Period > const &duration)
 
TaskContextRepeat ()
 
template<class _RepLeft , class _PeriodLeft , class _RepRight , class _PeriodRight >
TaskContextRepeat (std::chrono::duration< _RepLeft, _PeriodLeft > const &min, std::chrono::duration< _RepRight, _PeriodRight > const &max)
 
TaskContextAsync (std::function< void()> const &callable)
 
template<class _Rep , class _Period >
TaskContextSchedule (std::chrono::duration< _Rep, _Period > const &time, TaskScheduler::task_handler_t const &task)
 
template<class _Rep , class _Period >
TaskContextSchedule (std::chrono::duration< _Rep, _Period > const &time, TaskScheduler::group_t const group, TaskScheduler::task_handler_t const &task)
 
template<class _RepLeft , class _PeriodLeft , class _RepRight , class _PeriodRight >
TaskContextSchedule (std::chrono::duration< _RepLeft, _PeriodLeft > const &min, std::chrono::duration< _RepRight, _PeriodRight > const &max, TaskScheduler::task_handler_t const &task)
 
template<class _RepLeft , class _PeriodLeft , class _RepRight , class _PeriodRight >
TaskContextSchedule (std::chrono::duration< _RepLeft, _PeriodLeft > const &min, std::chrono::duration< _RepRight, _PeriodRight > const &max, TaskScheduler::group_t const group, TaskScheduler::task_handler_t const &task)
 
TaskContextCancelAll ()
 Cancels all tasks from within the context.
 
TaskContextCancelGroup (TaskScheduler::group_t const group)
 Cancel all tasks of a single group from within the context.
 
TaskContextCancelGroupsOf (std::vector< TaskScheduler::group_t > const &groups)
 
template<class _Rep , class _Period >
TaskContextDelayAll (std::chrono::duration< _Rep, _Period > const &duration)
 Delays all tasks with the given duration from within the context.
 
template<class _RepLeft , class _PeriodLeft , class _RepRight , class _PeriodRight >
TaskContextDelayAll (std::chrono::duration< _RepLeft, _PeriodLeft > const &min, std::chrono::duration< _RepRight, _PeriodRight > const &max)
 Delays all tasks with a random duration between min and max from within the context.
 
template<class _Rep , class _Period >
TaskContextDelayGroup (TaskScheduler::group_t const group, std::chrono::duration< _Rep, _Period > const &duration)
 Delays all tasks of a group with the given duration from within the context.
 
template<class _RepLeft , class _PeriodLeft , class _RepRight , class _PeriodRight >
TaskContextDelayGroup (TaskScheduler::group_t const group, std::chrono::duration< _RepLeft, _PeriodLeft > const &min, std::chrono::duration< _RepRight, _PeriodRight > const &max)
 Delays all tasks of a group with a random duration between min and max from within the context.
 
template<class _Rep , class _Period >
TaskContextRescheduleAll (std::chrono::duration< _Rep, _Period > const &duration)
 Reschedule all tasks with the given duration.
 
template<class _RepLeft , class _PeriodLeft , class _RepRight , class _PeriodRight >
TaskContextRescheduleAll (std::chrono::duration< _RepLeft, _PeriodLeft > const &min, std::chrono::duration< _RepRight, _PeriodRight > const &max)
 Reschedule all tasks with a random duration between min and max.
 
template<class _Rep , class _Period >
TaskContextRescheduleGroup (TaskScheduler::group_t const group, std::chrono::duration< _Rep, _Period > const &duration)
 Reschedule all tasks of a group with the given duration.
 
template<class _RepLeft , class _PeriodLeft , class _RepRight , class _PeriodRight >
TaskContextRescheduleGroup (TaskScheduler::group_t const group, std::chrono::duration< _RepLeft, _PeriodLeft > const &min, std::chrono::duration< _RepRight, _PeriodRight > const &max)
 Reschedule all tasks of a group with a random duration between min and max.
 

Private Member Functions

TaskContextDispatch (std::function< TaskScheduler &(TaskScheduler &)> const &apply)
 Dispatches an action safe on the TaskScheduler.
 
void AssertOnConsumed () const
 Asserts if the task was consumed already.
 
void Invoke ()
 Invokes the associated hook of the task.
 

Private Attributes

TaskScheduler::TaskContainer _task
 Associated task.
 
std::weak_ptr< TaskScheduler_owner
 Owner.
 
std::shared_ptr< bool > _consumed
 Marks the task as consumed.
 

Friends

class TaskScheduler
 

Detailed Description

Definition at line 391 of file TaskScheduler.h.

Constructor & Destructor Documentation

◆ TaskContext() [1/4]

TaskContext::TaskContext ( )
inline

Definition at line 409 of file TaskScheduler.h.

◆ TaskContext() [2/4]

TaskContext::TaskContext ( TaskScheduler::TaskContainer &&  task,
std::weak_ptr< TaskScheduler > &&  owner 
)
inlineexplicit

Definition at line 413 of file TaskScheduler.h.

◆ TaskContext() [3/4]

TaskContext::TaskContext ( TaskContext const &  right)
inline

Definition at line 417 of file TaskScheduler.h.

◆ TaskContext() [4/4]

TaskContext::TaskContext ( TaskContext &&  right)
inline

Definition at line 421 of file TaskScheduler.h.

Member Function Documentation

◆ AssertOnConsumed()

void TaskContext::AssertOnConsumed ( ) const
private

Asserts if the task was consumed already.

Definition at line 220 of file TaskScheduler.cpp.

◆ Async()

TaskContext & TaskContext::Async ( std::function< void()> const &  callable)

Schedule a callable function that is executed at the next update tick from within the context. Its safe to modify the TaskScheduler from within the callable.

Definition at line 200 of file TaskScheduler.cpp.

+ Here is the call graph for this function:

◆ CancelAll()

TaskContext & TaskContext::CancelAll ( )

Cancels all tasks from within the context.

Definition at line 205 of file TaskScheduler.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ CancelGroup()

TaskContext & TaskContext::CancelGroup ( TaskScheduler::group_t const  group)

Cancel all tasks of a single group from within the context.

Definition at line 210 of file TaskScheduler.cpp.

+ Here is the call graph for this function:

◆ CancelGroupsOf()

TaskContext & TaskContext::CancelGroupsOf ( std::vector< TaskScheduler::group_t > const &  groups)

Cancels all groups in the given std::vector from within the context. Hint: Use std::initializer_list for this: "{1, 2, 3, 4}"

Definition at line 215 of file TaskScheduler.cpp.

+ Here is the call graph for this function:

◆ ClearGroup()

TaskContext & TaskContext::ClearGroup ( )

Removes the group from the event.

Definition at line 189 of file TaskScheduler.cpp.

◆ DelayAll() [1/2]

template<class _Rep , class _Period >
TaskContext & TaskContext::DelayAll ( std::chrono::duration< _Rep, _Period > const &  duration)
inline

Delays all tasks with the given duration from within the context.

Definition at line 562 of file TaskScheduler.h.

◆ DelayAll() [2/2]

template<class _RepLeft , class _PeriodLeft , class _RepRight , class _PeriodRight >
TaskContext & TaskContext::DelayAll ( std::chrono::duration< _RepLeft, _PeriodLeft > const &  min,
std::chrono::duration< _RepRight, _PeriodRight > const &  max 
)
inline

Delays all tasks with a random duration between min and max from within the context.

Definition at line 569 of file TaskScheduler.h.

+ Here is the call graph for this function:

◆ DelayGroup() [1/2]

template<class _Rep , class _Period >
TaskContext & TaskContext::DelayGroup ( TaskScheduler::group_t const  group,
std::chrono::duration< _Rep, _Period > const &  duration 
)
inline

Delays all tasks of a group with the given duration from within the context.

Definition at line 577 of file TaskScheduler.h.

◆ DelayGroup() [2/2]

template<class _RepLeft , class _PeriodLeft , class _RepRight , class _PeriodRight >
TaskContext & TaskContext::DelayGroup ( TaskScheduler::group_t const  group,
std::chrono::duration< _RepLeft, _PeriodLeft > const &  min,
std::chrono::duration< _RepRight, _PeriodRight > const &  max 
)
inline

Delays all tasks of a group with a random duration between min and max from within the context.

Definition at line 584 of file TaskScheduler.h.

+ Here is the call graph for this function:

◆ Dispatch()

TaskContext & TaskContext::Dispatch ( std::function< TaskScheduler &(TaskScheduler &)> const &  apply)
private

Dispatches an action safe on the TaskScheduler.

Definition at line 165 of file TaskScheduler.cpp.

◆ GetRepeatCounter()

TaskScheduler::repeated_t TaskContext::GetRepeatCounter ( ) const

Returns the repeat counter which increases every time the task is repeated.

Definition at line 195 of file TaskScheduler.cpp.

+ Here is the caller graph for this function:

◆ Invoke()

void TaskContext::Invoke ( )
private

Invokes the associated hook of the task.

Definition at line 227 of file TaskScheduler.cpp.

+ Here is the caller graph for this function:

◆ IsExpired()

bool TaskContext::IsExpired ( ) const

Returns true if the owner was deallocated and this context has expired.

Definition at line 173 of file TaskScheduler.cpp.

◆ IsInGroup()

bool TaskContext::IsInGroup ( TaskScheduler::group_t const  group) const

Returns true if the event is in the given group.

Definition at line 178 of file TaskScheduler.cpp.

◆ operator=() [1/2]

TaskContext & TaskContext::operator= ( TaskContext &&  right)
inline

Definition at line 434 of file TaskScheduler.h.

◆ operator=() [2/2]

TaskContext & TaskContext::operator= ( TaskContext const &  right)
inline

Definition at line 425 of file TaskScheduler.h.

◆ Repeat() [1/3]

TaskContext & TaskContext::Repeat ( )
inline

Repeats the event with the same duration. This will consume the task context, its not possible to repeat the task again from the same task context!

Definition at line 477 of file TaskScheduler.h.

◆ Repeat() [2/3]

template<class _Rep , class _Period >
TaskContext & TaskContext::Repeat ( std::chrono::duration< _Rep, _Period > const &  duration)
inline

Repeats the event and sets a new duration. std::chrono::seconds(5) for example. This will consume the task context, its not possible to repeat the task again from the same task context!

Definition at line 462 of file TaskScheduler.h.

+ Here is the call graph for this function:

◆ Repeat() [3/3]

template<class _RepLeft , class _PeriodLeft , class _RepRight , class _PeriodRight >
TaskContext & TaskContext::Repeat ( std::chrono::duration< _RepLeft, _PeriodLeft > const &  min,
std::chrono::duration< _RepRight, _PeriodRight > const &  max 
)
inline

Repeats the event and set a new duration that is randomized between min and max. std::chrono::seconds(5) for example. This will consume the task context, its not possible to repeat the task again from the same task context!

Definition at line 487 of file TaskScheduler.h.

+ Here is the call graph for this function:

◆ RescheduleAll() [1/2]

template<class _Rep , class _Period >
TaskContext & TaskContext::RescheduleAll ( std::chrono::duration< _Rep, _Period > const &  duration)
inline

Reschedule all tasks with the given duration.

Definition at line 593 of file TaskScheduler.h.

+ Here is the call graph for this function:

◆ RescheduleAll() [2/2]

template<class _RepLeft , class _PeriodLeft , class _RepRight , class _PeriodRight >
TaskContext & TaskContext::RescheduleAll ( std::chrono::duration< _RepLeft, _PeriodLeft > const &  min,
std::chrono::duration< _RepRight, _PeriodRight > const &  max 
)
inline

Reschedule all tasks with a random duration between min and max.

Definition at line 600 of file TaskScheduler.h.

+ Here is the call graph for this function:

◆ RescheduleGroup() [1/2]

template<class _Rep , class _Period >
TaskContext & TaskContext::RescheduleGroup ( TaskScheduler::group_t const  group,
std::chrono::duration< _Rep, _Period > const &  duration 
)
inline

Reschedule all tasks of a group with the given duration.

Definition at line 608 of file TaskScheduler.h.

◆ RescheduleGroup() [2/2]

template<class _RepLeft , class _PeriodLeft , class _RepRight , class _PeriodRight >
TaskContext & TaskContext::RescheduleGroup ( TaskScheduler::group_t const  group,
std::chrono::duration< _RepLeft, _PeriodLeft > const &  min,
std::chrono::duration< _RepRight, _PeriodRight > const &  max 
)
inline

Reschedule all tasks of a group with a random duration between min and max.

Definition at line 615 of file TaskScheduler.h.

+ Here is the call graph for this function:

◆ Schedule() [1/4]

template<class _Rep , class _Period >
TaskContext & TaskContext::Schedule ( std::chrono::duration< _Rep, _Period > const &  time,
TaskScheduler::group_t const  group,
TaskScheduler::task_handler_t const &  task 
)
inline

Schedule an event with a fixed rate from within the context. Its possible that the new event is executed immediately! Use TaskScheduler::Async to create a task which will be called at the next update tick.

Definition at line 517 of file TaskScheduler.h.

+ Here is the call graph for this function:

◆ Schedule() [2/4]

template<class _Rep , class _Period >
TaskContext & TaskContext::Schedule ( std::chrono::duration< _Rep, _Period > const &  time,
TaskScheduler::task_handler_t const &  task 
)
inline

Schedule an event with a fixed rate from within the context. Its possible that the new event is executed immediately! Use TaskScheduler::Async to create a task which will be called at the next update tick.

Definition at line 502 of file TaskScheduler.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Schedule() [3/4]

template<class _RepLeft , class _PeriodLeft , class _RepRight , class _PeriodRight >
TaskContext & TaskContext::Schedule ( std::chrono::duration< _RepLeft, _PeriodLeft > const &  min,
std::chrono::duration< _RepRight, _PeriodRight > const &  max,
TaskScheduler::group_t const  group,
TaskScheduler::task_handler_t const &  task 
)
inline

Schedule an event with a randomized rate between min and max rate from within the context. Its possible that the new event is executed immediately! Use TaskScheduler::Async to create a task which will be called at the next update tick.

Definition at line 543 of file TaskScheduler.h.

+ Here is the call graph for this function:

◆ Schedule() [4/4]

template<class _RepLeft , class _PeriodLeft , class _RepRight , class _PeriodRight >
TaskContext & TaskContext::Schedule ( std::chrono::duration< _RepLeft, _PeriodLeft > const &  min,
std::chrono::duration< _RepRight, _PeriodRight > const &  max,
TaskScheduler::task_handler_t const &  task 
)
inline

Schedule an event with a randomized rate between min and max rate from within the context. Its possible that the new event is executed immediately! Use TaskScheduler::Async to create a task which will be called at the next update tick.

Definition at line 532 of file TaskScheduler.h.

+ Here is the call graph for this function:

◆ SetGroup()

TaskContext & TaskContext::SetGroup ( TaskScheduler::group_t const  group)

Sets the event in the given group.

Definition at line 183 of file TaskScheduler.cpp.

Friends And Related Symbol Documentation

◆ TaskScheduler

friend class TaskScheduler
friend

Definition at line 393 of file TaskScheduler.h.

Member Data Documentation

◆ _consumed

std::shared_ptr<bool> TaskContext::_consumed
private

Marks the task as consumed.

Definition at line 402 of file TaskScheduler.h.

◆ _owner

std::weak_ptr<TaskScheduler> TaskContext::_owner
private

Owner.

Definition at line 399 of file TaskScheduler.h.

◆ _task

TaskScheduler::TaskContainer TaskContext::_task
private

Associated task.

Definition at line 396 of file TaskScheduler.h.


The documentation for this class was generated from the following files: