|
VLink 2.0.0
A high-performance communication middleware
|
Node in a directed acyclic task graph supporting condition branching and parallel execution. 更多...
#include <graph_task.h>
Public 类型 | |
| enum | Status : uint8_t { kStatusInActive = 0 , kStatusPending = 1 , kStatusRunning = 2 , kStatusDone = 3 } |
Execution state of the task within a single execute() pass. 更多... | |
| enum | Policy : uint8_t { kPolicyOnce = 0 , kPolicyMultiple = 1 , kPolicyWaitAll = 2 } |
| Execution policy controlling how many times and when the task runs. 更多... | |
| using | Callback = std::function<void()> |
| Callback type for regular (void-returning) tasks. | |
| using | ConditionCallback = std::function<int()> |
| Callback type for condition tasks; returns the branch index to activate. | |
| using | StatusCallback = std::function<void(const std::string&, Status)> |
| Callback for status change notifications. | |
Public 成员函数 | |
| template<class GraphEngineT> | |
| void | execute (GraphEngineT *graph_engine) |
| Submits this task (and all reachable successors) to a graph execution engine. | |
| void | cancel () |
Cancels this task; sets its status to kStatusInActive. | |
| void | precede (const std::shared_ptr< GraphTask > &task) |
Declares that this task must complete before task starts. | |
| void | succeed (const std::shared_ptr< GraphTask > &task) |
Declares that task must complete before this task starts. | |
| void | register_status_callback (StatusCallback &&callback) |
| Registers a callback invoked whenever this task's status changes. | |
| void | set_name (const std::string &name) |
| Sets the task name used in DOT export and status callbacks. | |
| void | set_group_name (const std::string &name) |
| Sets a group name for visual grouping in DOT export. | |
| void | set_condition_number (int condition_number) |
| Sets the number of condition branches this task can select. | |
| void | set_priority (uint16_t priority) |
| Sets the task dispatch priority (used by priority-aware engines). | |
| void | set_max_recursion_depth (uint32_t depth) |
| Sets the maximum recursion depth to guard against infinitely deep graphs. | |
| void | set_policy (Policy policy) |
| Sets the execution policy. | |
| std::string | get_name () const |
| Returns the task name. | |
| std::string | get_group_name () const |
| Returns the group name. | |
| int | get_condition_number () const |
| Returns the number of condition branches. | |
| uint16_t | get_priority () const |
| Returns the dispatch priority. | |
| uint32_t | get_max_recursion_depth () const |
| Returns the maximum recursion depth. | |
| Policy | get_policy () const |
| Returns the execution policy. | |
| Status | get_status () const |
| Returns the current execution status of this task. | |
| void | remove_precede_task (const std::shared_ptr< GraphTask > &task) |
| Removes a previously added predecessor dependency. | |
| void | remove_succeed_task (const std::shared_ptr< GraphTask > &task) |
| Removes a previously added successor dependency. | |
| std::vector< std::weak_ptr< GraphTask > > | get_precede_task_list () const |
| Returns the list of predecessor tasks (this task depends on them). | |
| std::vector< std::weak_ptr< GraphTask > > | get_succeed_task_list () const |
| Returns the list of successor tasks (they depend on this task). | |
| bool | is_condition_task () const |
Returns true if this task was created with create_condition(). | |
| bool | has_cycle () const |
| Detects whether the reachable sub-graph contains any cycles. | |
| std::string | export_to_dot () const |
| Exports the reachable sub-graph as a Graphviz DOT string. | |
静态 Public 成员函数 | |
| static std::shared_ptr< GraphTask > | create (Callback &&callback, int condition_number=0) |
| Creates a regular (void) task node. | |
| static std::shared_ptr< GraphTask > | create (const std::string &name, Callback &&callback, int condition_number=0) |
| Creates a named regular (void) task node. | |
| static std::shared_ptr< GraphTask > | create_condition (ConditionCallback &&callback, int condition_number=0) |
| Creates a condition task that returns a branch index. | |
| static std::shared_ptr< GraphTask > | create_condition (const std::string &name, ConditionCallback &&callback, int condition_number=0) |
| Creates a named condition task. | |
Protected 类型 | |
| using | FindTaskCallback = std::function<void(const std::shared_ptr<GraphTask>&)> |
Protected 成员函数 | |
| GraphTask (Callback &&callback, int condition_number) | |
| GraphTask (const std::string &name, Callback &&callback, int condition_number) | |
| GraphTask (ConditionCallback &&callback, int condition_number) | |
| GraphTask (const std::string &name, ConditionCallback &&callback, int condition_number) | |
| ~GraphTask () | |
| void | process_and_traverse (const FindTaskCallback &callback) |
Node in a directed acyclic task graph supporting condition branching and parallel execution.
Must be created via one of the static factory methods (create / create_condition). Inherits from std::enable_shared_from_this to safely pass shared_ptr to internal callbacks.
| using vlink::GraphTask::Callback = std::function<void()> |
Callback type for regular (void-returning) tasks.
| using vlink::GraphTask::ConditionCallback = std::function<int()> |
Callback type for condition tasks; returns the branch index to activate.
|
protected |
| using vlink::GraphTask::StatusCallback = std::function<void(const std::string&, Status)> |
| enum vlink::GraphTask::Policy : uint8_t |
Execution policy controlling how many times and when the task runs.
| 枚举值 | |
|---|---|
| kPolicyOnce | Run exactly once per execute() call (default) |
| kPolicyMultiple | Allow multiple invocations in a single pass |
| kPolicyWaitAll | Wait for ALL predecessors before running |
| enum vlink::GraphTask::Status : uint8_t |
Execution state of the task within a single execute() pass.
| 枚举值 | |
|---|---|
| kStatusInActive | Not yet submitted or cancelled |
| kStatusPending | Waiting for predecessors to complete |
| kStatusRunning | Currently executing |
| kStatusDone | Execution completed |
|
explicitprotected |
|
explicitprotected |
|
explicitprotected |
|
explicitprotected |
|
protected |
| void vlink::GraphTask::cancel | ( | ) |
Cancels this task; sets its status to kStatusInActive.
A cancelled task will not be executed even if all its predecessors complete.
|
staticnodiscard |
Creates a regular (void) task node.
| callback | Work function to execute. |
| condition_number | Number of successor branches available. 0 = no branches. |
|
staticnodiscard |
Creates a named regular (void) task node.
| name | Task name (used in DOT export and status callbacks). |
| callback | Work function to execute. |
| condition_number | Number of successor branches available. 0 = no branches. |
|
staticnodiscard |
Creates a condition task that returns a branch index.
The integer returned by callback selects which successor sub-graph to activate. Return values outside [0, condition_number) skip all successors.
| callback | Condition function returning the branch index. |
| condition_number | Number of possible branches. |
|
staticnodiscard |
Creates a named condition task.
| name | Task name. |
| callback | Condition function returning the branch index. |
| condition_number | Number of possible branches. |
|
inline |
Submits this task (and all reachable successors) to a graph execution engine.
Details
Traverses the reachable sub-graph, identifies tasks whose predecessors have all completed, and posts them to graph_engine using either post_task() or post_task_with_priority() (if available).
| GraphEngineT | Any type providing post_task(Callback) and optionally post_task_with_priority(Callback, uint16_t). MessageLoop, MultiLoop and ThreadPool all satisfy this. |
| graph_engine | Pointer to the execution engine. |
|
nodiscard |
Exports the reachable sub-graph as a Graphviz DOT string.
The DOT output can be passed to dot -Tpng to produce a dependency diagram.
|
nodiscard |
Returns the number of condition branches.
|
nodiscard |
Returns the group name.
|
nodiscard |
Returns the maximum recursion depth.
|
nodiscard |
Returns the task name.
|
nodiscard |
Returns the execution policy.
|
nodiscard |
Returns the list of predecessor tasks (this task depends on them).
|
nodiscard |
Returns the dispatch priority.
|
nodiscard |
Returns the current execution status of this task.
|
nodiscard |
Returns the list of successor tasks (they depend on this task).
|
nodiscard |
Detects whether the reachable sub-graph contains any cycles.
Uses DFS with a recursion stack to find back edges. A cycle-free graph is required for correct execute() behaviour.
true if a cycle is detected.
|
nodiscard |
Returns true if this task was created with create_condition().
true for condition tasks. | void vlink::GraphTask::precede | ( | const std::shared_ptr< GraphTask > & | task | ) |
Declares that this task must complete before task starts.
Equivalent to task->succeed(this_task).
| task | Successor task. |
|
protected |
| void vlink::GraphTask::register_status_callback | ( | StatusCallback && | callback | ) |
Registers a callback invoked whenever this task's status changes.
| callback | Called with (name, new_status) on every status transition. |
| void vlink::GraphTask::remove_precede_task | ( | const std::shared_ptr< GraphTask > & | task | ) |
Removes a previously added predecessor dependency.
| task | The predecessor to remove. |
| void vlink::GraphTask::remove_succeed_task | ( | const std::shared_ptr< GraphTask > & | task | ) |
Removes a previously added successor dependency.
| task | The successor to remove. |
| void vlink::GraphTask::set_condition_number | ( | int | condition_number | ) |
Sets the number of condition branches this task can select.
| condition_number | Branch count (used for condition tasks). |
| void vlink::GraphTask::set_group_name | ( | const std::string & | name | ) |
Sets a group name for visual grouping in DOT export.
| name | Group name string. |
| void vlink::GraphTask::set_max_recursion_depth | ( | uint32_t | depth | ) |
Sets the maximum recursion depth to guard against infinitely deep graphs.
If a task graph exceeds this depth during execution, a kFatal log is emitted. The default value is 10000.
| depth | Maximum depth. |
| void vlink::GraphTask::set_name | ( | const std::string & | name | ) |
Sets the task name used in DOT export and status callbacks.
| name | Task name string. |
| void vlink::GraphTask::set_policy | ( | Policy | policy | ) |
Sets the execution policy.
| policy | See Policy enum. |
| void vlink::GraphTask::set_priority | ( | uint16_t | priority | ) |
Sets the task dispatch priority (used by priority-aware engines).
| priority | Priority value. |
| void vlink::GraphTask::succeed | ( | const std::shared_ptr< GraphTask > & | task | ) |
Declares that task must complete before this task starts.
Equivalent to task->precede(this_task).
| task | Predecessor task. |