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 20 inline std::vector<SensorTree> 21 getSubTreeSensors(boost::asio::yield_context& yield, 22 const std::shared_ptr<sdbusplus::asio::connection>& bus) 23 { 24 std::array<const char*, 1> interfaces = { 25 "xyz.openbmc_project.Sensor.Value"}; 26 boost::system::error_code ec; 27 28 auto tree = bus->yield_method_call<std::vector<SensorTree>>( 29 yield, ec, "xyz.openbmc_project.ObjectMapper", 30 "/xyz/openbmc_project/object_mapper", 31 "xyz.openbmc_project.ObjectMapper", "GetSubTree", 32 "/xyz/openbmc_project/sensors", 2, interfaces); 33 if (ec) 34 { 35 throw std::runtime_error("Failed to query ObjectMapper!"); 36 } 37 return tree; 38 } 39 40 } // namespace utils 41