James Feist | 284a0f9 | 2018-04-05 15:28:16 -0700 | [diff] [blame^] | 1 | #include <iostream> |
| 2 | #include <sdbusplus/bus.hpp> |
| 3 | #include <sdbusplus/server.hpp> |
| 4 | #include <sdbusplus/asio/connection.hpp> |
| 5 | #include <boost/asio.hpp> |
| 6 | |
| 7 | int main() |
| 8 | { |
| 9 | using GetSubTreeType = std::vector<std::pair< |
| 10 | std::string, |
| 11 | std::vector<std::pair<std::string, std::vector<std::string>>>>>; |
| 12 | using message = sdbusplus::message::message; |
| 13 | // setup connection to dbus |
| 14 | boost::asio::io_service io; |
| 15 | auto conn = std::make_shared<sdbusplus::asio::connection>(io); |
| 16 | |
| 17 | // test async method call and async send |
| 18 | auto mesg = |
| 19 | conn->new_method_call("xyz.openbmc_project.ObjectMapper", |
| 20 | "/xyz/openbmc_project/object_mapper", |
| 21 | "xyz.openbmc_project.ObjectMapper", "GetSubTree"); |
| 22 | |
| 23 | static const auto depth = 2; |
| 24 | static const std::vector<std::string> interfaces = { |
| 25 | "xyz.openbmc_project.Sensor.Value"}; |
| 26 | mesg.append("/xyz/openbmc_project/Sensors", depth, interfaces); |
| 27 | |
| 28 | conn->async_send(mesg, [](boost::system::error_code ec, message& ret) { |
| 29 | std::cout << "async_send callback\n"; |
| 30 | if (ec || ret.is_method_error()) |
| 31 | { |
| 32 | std::cerr << "error with async_send\n"; |
| 33 | return; |
| 34 | } |
| 35 | GetSubTreeType data; |
| 36 | ret.read(data); |
| 37 | for (auto& item : data) |
| 38 | { |
| 39 | std::cout << item.first << "\n"; |
| 40 | } |
| 41 | }); |
| 42 | |
| 43 | conn->async_method_call( |
| 44 | [](boost::system::error_code ec, GetSubTreeType& subtree) { |
| 45 | std::cout << "async_method_call callback\n"; |
| 46 | if (ec) |
| 47 | { |
| 48 | std::cerr << "error with async_method_call\n"; |
| 49 | return; |
| 50 | } |
| 51 | for (auto& item : subtree) |
| 52 | { |
| 53 | std::cout << item.first << "\n"; |
| 54 | } |
| 55 | |
| 56 | }, |
| 57 | "xyz.openbmc_project.ObjectMapper", |
| 58 | "/xyz/openbmc_project/object_mapper", |
| 59 | "xyz.openbmc_project.ObjectMapper", "GetSubTree", |
| 60 | "/org/openbmc/control", 2, std::vector<std::string>()); |
| 61 | |
| 62 | io.run(); |
| 63 | |
| 64 | return 0; |
| 65 | } |