Wludzik, Jozef | 1477fe6 | 2021-01-02 11:56:10 +0100 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <boost/asio/spawn.hpp> |
| 4 | #include <sdbusplus/asio/object_server.hpp> |
| 5 | |
| 6 | #include <array> |
| 7 | #include <string> |
| 8 | #include <utility> |
| 9 | #include <vector> |
| 10 | |
| 11 | namespace utils |
| 12 | { |
| 13 | |
| 14 | using SensorPath = std::string; |
| 15 | using ServiceName = std::string; |
| 16 | using Ifaces = std::vector<std::string>; |
| 17 | using SensorIfaces = std::vector<std::pair<ServiceName, Ifaces>>; |
| 18 | using SensorTree = std::pair<SensorPath, SensorIfaces>; |
| 19 | |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 20 | constexpr std::array<const char*, 1> sensorInterfaces = { |
| 21 | "xyz.openbmc_project.Sensor.Value"}; |
| 22 | |
Wludzik, Jozef | 1477fe6 | 2021-01-02 11:56:10 +0100 | [diff] [blame] | 23 | inline std::vector<SensorTree> |
| 24 | getSubTreeSensors(boost::asio::yield_context& yield, |
| 25 | const std::shared_ptr<sdbusplus::asio::connection>& bus) |
| 26 | { |
Wludzik, Jozef | 1477fe6 | 2021-01-02 11:56:10 +0100 | [diff] [blame] | 27 | boost::system::error_code ec; |
| 28 | |
| 29 | auto tree = bus->yield_method_call<std::vector<SensorTree>>( |
| 30 | yield, ec, "xyz.openbmc_project.ObjectMapper", |
| 31 | "/xyz/openbmc_project/object_mapper", |
| 32 | "xyz.openbmc_project.ObjectMapper", "GetSubTree", |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 33 | "/xyz/openbmc_project/sensors", 2, sensorInterfaces); |
Wludzik, Jozef | 1477fe6 | 2021-01-02 11:56:10 +0100 | [diff] [blame] | 34 | if (ec) |
| 35 | { |
| 36 | throw std::runtime_error("Failed to query ObjectMapper!"); |
| 37 | } |
| 38 | return tree; |
| 39 | } |
| 40 | |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 41 | inline std::vector<SensorTree> |
| 42 | getSubTreeSensors(const std::shared_ptr<sdbusplus::asio::connection>& bus) |
| 43 | { |
| 44 | auto method_call = |
| 45 | bus->new_method_call("xyz.openbmc_project.ObjectMapper", |
| 46 | "/xyz/openbmc_project/object_mapper", |
| 47 | "xyz.openbmc_project.ObjectMapper", "GetSubTree"); |
| 48 | method_call.append("/xyz/openbmc_project/sensors/", 2, sensorInterfaces); |
| 49 | auto reply = bus->call(method_call); |
| 50 | |
| 51 | std::vector<SensorTree> tree; |
| 52 | reply.read(tree); |
| 53 | |
| 54 | return tree; |
| 55 | } |
| 56 | |
Wludzik, Jozef | 1477fe6 | 2021-01-02 11:56:10 +0100 | [diff] [blame] | 57 | } // namespace utils |