赞
踩
sdbusplus除了提供以同步的方式调用service的method外,还提供了多种异步调用的方式。
下面的例子通过async_method_call完成异步调用:
-
- //async_call_method.cpp
- #include <iostream>
- #include <string>
- #include <vector>
- #include <tuple>
- #include <boost/asio.hpp>
- #include <sdbusplus/bus.hpp>
- #include <sdbusplus/asio/connection.hpp>
- #include <sdbusplus/asio/object_server.hpp>
-
- using namespace std;
- using namespace sdbusplus;
-
- void doAsyncCallMethod()
- {
- using return_type = vector<tuple<uint32_t, string, message::object_path>>;
- boost::asio::io_context io;
- auto b = bus::new_default_system();
- auto conn = make_shared<sdbusplus::asio::connection>(io, bus::details::bus_friend::get_busp(b));
- conn->async_method_call(
- [](boost::system::error_code ec, return_type users) {
- if (ec)
- {
- cout<<"ListUsers r
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。