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

#include <TaskScheduler.h>

Public Member Functions

 TaskContext () noexcept
 
 TaskContext (TaskScheduler::TaskQueue::Container::node_type &&task, std::weak_ptr< TaskScheduler > &&owner) noexcept
 
 TaskContext (TaskContext const &right)=delete
 
 TaskContext (TaskContext &&right) noexcept
 
TaskContextoperator= (TaskContext const &right)=delete
 
TaskContextoperator= (TaskContext &&right) noexcept
 
 ~TaskContext ()
 
bool IsExpired () const
 Returns true if the owner was deallocated and this context has expired.
 
bool IsInGroup (TaskScheduler::group_t group) const
 Returns true if the event is in the given group.
 
TaskContextSetGroup (TaskScheduler::group_t 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.
 
TaskContextRepeat (TaskScheduler::duration_t duration)
 
TaskContextRepeat ()
 
TaskContextRepeat (std::chrono::milliseconds min, std::chrono::milliseconds max)
 
TaskContextAsync (std::function< void()> callable)
 
TaskContextSchedule (TaskScheduler::duration_t time, TaskScheduler::task_handler_t task)
 
TaskContextSchedule (TaskScheduler::duration_t time, TaskScheduler::group_t group, TaskScheduler::task_handler_t task)
 
TaskContextSchedule (std::chrono::milliseconds min, std::chrono::milliseconds max, TaskScheduler::task_handler_t task)
 
TaskContextSchedule (std::chrono::milliseconds min, std::chrono::milliseconds max, TaskScheduler::group_t group, TaskScheduler::task_handler_t task)
 
TaskContextCancelAll ()
 Cancels all tasks from within the context.
 
TaskContextCancelGroup (TaskScheduler::group_t group)
 Cancel all tasks of a single group from within the context.
 
TaskContextCancelGroupsOf (std::span< TaskScheduler::group_t > groups)
 
TaskContextDelayAll (TaskScheduler::duration_t duration)
 Delays all tasks with the given duration from within the context.
 
TaskContextDelayAll (std::chrono::milliseconds min, std::chrono::milliseconds max)
 Delays all tasks with a random duration between min and max from within the context.
 
TaskContextDelayGroup (TaskScheduler::group_t group, TaskScheduler::duration_t duration)
 Delays all tasks of a group with the given duration from within the context.
 
TaskContextDelayGroup (TaskScheduler::group_t group, std::chrono::milliseconds min, std::chrono::milliseconds max)
 Delays all tasks of a group with a random duration between min and max from within the context.
 
TaskContextRescheduleAll (TaskScheduler::duration_t duration)
 Reschedule all tasks with the given duration.
 
TaskContextRescheduleAll (std::chrono::milliseconds min, std::chrono::milliseconds max)
 Reschedule all tasks with a random duration between min and max.
 
TaskContextRescheduleGroup (TaskScheduler::group_t group, TaskScheduler::duration_t duration)
 Reschedule all tasks of a group with the given duration.
 
TaskContextRescheduleGroup (TaskScheduler::group_t group, std::chrono::milliseconds min, std::chrono::milliseconds max)
 Reschedule all tasks of a group with a random duration between min and max.
 

Private Member Functions

void Invoke ()
 Invokes the associated hook of the task.
 
TaskScheduler::TaskContainerGetTaskContainer () noexcept
 
TaskScheduler::TaskGetTask () const noexcept
 

Private Attributes

std::variant< TaskScheduler::TaskQueue::Container::node_type, TaskScheduler::TaskContainer_task
 Associated task.
 
std::weak_ptr< TaskScheduler_owner
 Owner.
 

Friends

class TaskScheduler
 

Detailed Description

Definition at line 369 of file TaskScheduler.h.

Constructor & Destructor Documentation

◆ TaskContext() [1/4]

TaskContext::TaskContext ( )
inlinenoexcept

Definition at line 382 of file TaskScheduler.h.

◆ TaskContext() [2/4]

TaskContext::TaskContext ( TaskScheduler::TaskQueue::Container::node_type &&  task,
std::weak_ptr< TaskScheduler > &&  owner 
)
explicitnoexcept

Definition at line 265 of file TaskScheduler.cpp.

◆ TaskContext() [3/4]

TaskContext::TaskContext ( TaskContext const &  right)
delete

◆ TaskContext() [4/4]

TaskContext::TaskContext ( TaskContext &&  right)
noexcept

Definition at line 270 of file TaskScheduler.cpp.

◆ ~TaskContext()

TaskContext::~TaskContext ( )
default

Member Function Documentation

◆ Async()

TaskContext & TaskContext::Async ( std::function< void()>  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 344 of file TaskScheduler.cpp.

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

◆ CancelAll()

TaskContext & TaskContext::CancelAll ( )

Cancels all tasks from within the context.

Definition at line 368 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  group)

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

Definition at line 376 of file TaskScheduler.cpp.

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

◆ CancelGroupsOf()

TaskContext & TaskContext::CancelGroupsOf ( std::span< TaskScheduler::group_t 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 384 of file TaskScheduler.cpp.

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

◆ ClearGroup()

TaskContext & TaskContext::ClearGroup ( )

Removes the group from the event.

Definition at line 308 of file TaskScheduler.cpp.

◆ DelayAll() [1/2]

TaskContext & TaskContext::DelayAll ( std::chrono::milliseconds  min,
std::chrono::milliseconds  max 
)
inline

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

Definition at line 491 of file TaskScheduler.h.

+ Here is the call graph for this function:

◆ DelayAll() [2/2]

TaskContext & TaskContext::DelayAll ( TaskScheduler::duration_t  duration)

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

Definition at line 392 of file TaskScheduler.cpp.

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

◆ DelayGroup() [1/2]

TaskContext & TaskContext::DelayGroup ( TaskScheduler::group_t  group,
std::chrono::milliseconds  min,
std::chrono::milliseconds  max 
)
inline

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

Definition at line 501 of file TaskScheduler.h.

+ Here is the call graph for this function:

◆ DelayGroup() [2/2]

TaskContext & TaskContext::DelayGroup ( TaskScheduler::group_t  group,
TaskScheduler::duration_t  duration 
)

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

Definition at line 400 of file TaskScheduler.cpp.

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

◆ GetRepeatCounter()

TaskScheduler::repeated_t TaskContext::GetRepeatCounter ( ) const

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

Definition at line 314 of file TaskScheduler.cpp.

+ Here is the caller graph for this function:

◆ GetTask()

TaskScheduler::Task * TaskContext::GetTask ( ) const
privatenoexcept

Definition at line 441 of file TaskScheduler.cpp.

◆ GetTaskContainer()

TaskScheduler::TaskContainer & TaskContext::GetTaskContainer ( )
privatenoexcept

Definition at line 429 of file TaskScheduler.cpp.

◆ Invoke()

void TaskContext::Invoke ( )
private

Invokes the associated hook of the task.

Definition at line 424 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 292 of file TaskScheduler.cpp.

◆ IsInGroup()

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

Returns true if the event is in the given group.

Definition at line 297 of file TaskScheduler.cpp.

◆ operator=() [1/2]

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

Definition at line 277 of file TaskScheduler.cpp.

◆ operator=() [2/2]

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

◆ Repeat() [1/3]

TaskContext & TaskContext::Repeat ( )

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 339 of file TaskScheduler.cpp.

◆ Repeat() [2/3]

TaskContext & TaskContext::Repeat ( std::chrono::milliseconds  min,
std::chrono::milliseconds  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 432 of file TaskScheduler.h.

+ Here is the call graph for this function:

◆ Repeat() [3/3]

TaskContext & TaskContext::Repeat ( TaskScheduler::duration_t  duration)

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 319 of file TaskScheduler.cpp.

+ Here is the caller graph for this function:

◆ RescheduleAll() [1/2]

TaskContext & TaskContext::RescheduleAll ( std::chrono::milliseconds  min,
std::chrono::milliseconds  max 
)
inline

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

Definition at line 512 of file TaskScheduler.h.

+ Here is the call graph for this function:

◆ RescheduleAll() [2/2]

TaskContext & TaskContext::RescheduleAll ( TaskScheduler::duration_t  duration)

Reschedule all tasks with the given duration.

Definition at line 408 of file TaskScheduler.cpp.

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

◆ RescheduleGroup() [1/2]

TaskContext & TaskContext::RescheduleGroup ( TaskScheduler::group_t  group,
std::chrono::milliseconds  min,
std::chrono::milliseconds  max 
)
inline

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

Definition at line 522 of file TaskScheduler.h.

+ Here is the call graph for this function:

◆ RescheduleGroup() [2/2]

TaskContext & TaskContext::RescheduleGroup ( TaskScheduler::group_t  group,
TaskScheduler::duration_t  duration 
)

Reschedule all tasks of a group with the given duration.

Definition at line 416 of file TaskScheduler.cpp.

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

◆ Schedule() [1/4]

TaskContext & TaskContext::Schedule ( std::chrono::milliseconds  min,
std::chrono::milliseconds  max,
TaskScheduler::group_t  group,
TaskScheduler::task_handler_t  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 470 of file TaskScheduler.h.

+ Here is the call graph for this function:

◆ Schedule() [2/4]

TaskContext & TaskContext::Schedule ( std::chrono::milliseconds  min,
std::chrono::milliseconds  max,
TaskScheduler::task_handler_t  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 460 of file TaskScheduler.h.

+ Here is the call graph for this function:

◆ Schedule() [3/4]

TaskContext & TaskContext::Schedule ( TaskScheduler::duration_t  time,
TaskScheduler::group_t  group,
TaskScheduler::task_handler_t  task 
)

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 360 of file TaskScheduler.cpp.

◆ Schedule() [4/4]

TaskContext & TaskContext::Schedule ( TaskScheduler::duration_t  time,
TaskScheduler::task_handler_t  task 
)

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 352 of file TaskScheduler.cpp.

+ Here is the caller graph for this function:

◆ SetGroup()

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

Sets the event in the given group.

Definition at line 302 of file TaskScheduler.cpp.

Friends And Related Symbol Documentation

◆ TaskScheduler

friend class TaskScheduler
friend

Definition at line 371 of file TaskScheduler.h.

Member Data Documentation

◆ _owner

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

Owner.

Definition at line 378 of file TaskScheduler.h.

◆ _task

std::variant<TaskScheduler::TaskQueue::Container::node_type , TaskScheduler::TaskContainer > TaskContext::_task
private

Associated task.

Definition at line 375 of file TaskScheduler.h.


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