GKD.RoboCtrl
RoboMaster Linux 电控:异步 IO、设备驱动与机器人控制
载入中...
搜索中...
未找到
roboctrl::async::task_context类 参考

异步任务上下文类。 更多...

详细描述

异步任务上下文类。

提供基于Asio的异步任务执行环境,支持协程任务的调度和执行。

在文件 async.hpp 第 55 行定义.

#include <async.hpp>

类 roboctrl::async::task_context 继承关系图:
roboctrl::async::task_context 的协作图:

类

struct  info_type
 

Public 类型

using task_type = awaitable<>
 
using shutdown_handler_type = std::function< task_type()>
 

Public 成员函数

void spawn (task_type &&task)
 添加一个协程任务到上下文中执行。
 
template<typename Fn , typename... Args>
void post (Fn &&fn, Args &&... args)
 添加一个任务到上下文中执行。
 
void set_shutdown_handler (shutdown_handler_type handler)
 注册异常或外部请求共用的一次性安全停机任务。
 
void request_shutdown () noexcept
 请求一次安全停机。
 
void run () noexcept
 开始运行任务上下文。
 
void stop ()
 
bool failed () const noexcept
 是否观察到过未处理的异步异常。
 
bool shutdown_requested () const noexcept
 是否已经进入一次性停机流程。
 
bool init (info_type _info)
 初始化 task_context
 
std::string desc () const
 task_context的描述
 
auto get_executor ()
 获取asio的executor。
 
auto asio_context () -> asio::io_context &
 获取asio的io_context。
 
- Public 成员函数 继承自 roboctrl::utils::singleton_base< task_context >
 singleton_base (const singleton_base &)=delete
 
singleton_base & operator= (const singleton_base &)=delete
 
- Public 成员函数 继承自 roboctrl::utils::immovable_base
 immovable_base (immovable_base &&)=delete
 
immovable_base & operator= (immovable_base &&)=delete
 
- Public 成员函数 继承自 roboctrl::utils::not_copyable_base
 not_copyable_base (const not_copyable_base &)=delete
 
not_copyable_base & operator= (const not_copyable_base &)=delete
 

额外继承的成员函数

- 静态 Public 成员函数 继承自 roboctrl::utils::singleton_base< task_context >
static task_context & instance ()
 获取单例实例
 
- Protected 成员函数 继承自 roboctrl::log::logable< task_context >
void log (log_level level, std::format_string< Args... > fmt, Args &&...args) const
 输出日志
 
void log_debug (std::format_string< Args... > fmt, Args &&...args) const
 输出debug日志
 
void log_info (std::format_string< Args... > fmt, Args &&...args) const
 输出info日志
 
void log_warn (std::format_string< Args... > fmt, Args &&...args) const
 输出warn日志
 
void log_error (std::format_string< Args... > fmt, Args &&...args) const
 输出error日志
 

成员类型定义说明

◆ shutdown_handler_type

using roboctrl::async::task_context::shutdown_handler_type = std::function<task_type()>

在文件 async.hpp 第 59 行定义.

◆ task_type

using roboctrl::async::task_context::task_type = awaitable<>

在文件 async.hpp 第 58 行定义.

构造及析构函数说明

◆ task_context()

task_context::task_context ( )
explicit

在文件 async.cpp 第 5 行定义.

成员函数说明

◆ asio_context()

auto roboctrl::async::task_context::asio_context ( ) -> asio::io_context&
inline

获取asio的io_context。

在文件 async.hpp 第 162 行定义.

◆ desc()

std::string roboctrl::async::task_context::desc ( ) const
inline

task_context的描述

在文件 async.hpp 第 148 行定义.

◆ failed()

bool roboctrl::async::task_context::failed ( ) const
inlinenoexcept

是否观察到过未处理的异步异常。

在文件 async.hpp 第 139 行定义.

◆ get_executor()

auto roboctrl::async::task_context::get_executor ( )
inline

获取asio的executor。

在文件 async.hpp 第 155 行定义.

◆ init()

bool task_context::init ( task_context::info_type  _info)

初始化 task_context

在文件 async.cpp 第 43 行定义.

◆ post()

template<typename Fn , typename... Args>
void roboctrl::async::task_context::post ( Fn &&  fn,
Args &&...  args 
)
inline

添加一个任务到上下文中执行。

模板参数
Fn任务类型
Args任务参数类型
参数
fn任务
args任务参数

示例:

roboctrl::post([](int a,int b){
std::print("{} + {} = {}\n",a,b,a+b);
},1,2);
auto post(Args &&... args)
添加一个任务到全局任务上下文中执行。
Definition async.hpp:207

在文件 async.hpp 第 101 行定义.

◆ request_shutdown()

void task_context::request_shutdown ( )
noexcept

请求一次安全停机。

首次请求会运行已注册的停机任务,待其完成后停止事件循环。重复请求 不会重复运行停机任务。

在文件 async.cpp 第 71 行定义.

◆ run()

void task_context::run ( )
noexcept

开始运行任务上下文。

在文件 async.cpp 第 22 行定义.

引用了 roboctrl::log::logable< task_context >::log_info().

◆ set_shutdown_handler()

void task_context::set_shutdown_handler ( shutdown_handler_type  handler)

注册异常或外部请求共用的一次性安全停机任务。

首个越过 spawn/post/run 边界的异常会启动该任务。事件循环会继续 运行,直到任务完成后才停止,从而允许上层先撤销执行器使能并等待 有界的零输出刷新窗口。停机任务自身不得无限等待。

在文件 async.cpp 第 17 行定义.

◆ shutdown_requested()

bool roboctrl::async::task_context::shutdown_requested ( ) const
inlinenoexcept

是否已经进入一次性停机流程。

在文件 async.hpp 第 142 行定义.

◆ spawn()

void task_context::spawn ( task_context::task_type &&  task)

添加一个协程任务到上下文中执行。

参数
task任务

示例:

while(true){
std::print("hello");
co_await roboctrl::wait_for(1s);
}
}());
awaitable< void > wait_for(const duration &duration)
协程任务等待。
Definition async.hpp:262
auto spawn(task_context::task_type &&task)
添加一个协程任务到全局任务上下文中执行。
Definition async.hpp:191
asio::awaitable< T > awaitable
协程任务类型。
Definition async.hpp:46

在文件 async.cpp 第 9 行定义.

◆ stop()

void task_context::stop ( )

在文件 async.cpp 第 38 行定义.


该类的文档由以下文件生成: