11477fe6aSWludzik, Jozef #pragma once 21477fe6aSWludzik, Jozef 31477fe6aSWludzik, Jozef #include <boost/asio/spawn.hpp> 41477fe6aSWludzik, Jozef #include <sdbusplus/asio/object_server.hpp> 51477fe6aSWludzik, Jozef 61477fe6aSWludzik, Jozef #include <array> 71477fe6aSWludzik, Jozef #include <string> 81477fe6aSWludzik, Jozef #include <utility> 91477fe6aSWludzik, Jozef #include <vector> 101477fe6aSWludzik, Jozef 111477fe6aSWludzik, Jozef namespace utils 121477fe6aSWludzik, Jozef { 131477fe6aSWludzik, Jozef 141477fe6aSWludzik, Jozef using SensorPath = std::string; 151477fe6aSWludzik, Jozef using ServiceName = std::string; 161477fe6aSWludzik, Jozef using Ifaces = std::vector<std::string>; 171477fe6aSWludzik, Jozef using SensorIfaces = std::vector<std::pair<ServiceName, Ifaces>>; 181477fe6aSWludzik, Jozef using SensorTree = std::pair<SensorPath, SensorIfaces>; 191477fe6aSWludzik, Jozef 20*94f71c51SSzymon Dompke constexpr std::array<const char*, 1> sensorInterfaces = { 21*94f71c51SSzymon Dompke "xyz.openbmc_project.Sensor.Value"}; 22*94f71c51SSzymon Dompke 231477fe6aSWludzik, Jozef inline std::vector<SensorTree> getSubTreeSensors(boost::asio::yield_context & yield,const std::shared_ptr<sdbusplus::asio::connection> & bus)241477fe6aSWludzik, Jozef getSubTreeSensors(boost::asio::yield_context& yield, 251477fe6aSWludzik, Jozef const std::shared_ptr<sdbusplus::asio::connection>& bus) 261477fe6aSWludzik, Jozef { 271477fe6aSWludzik, Jozef boost::system::error_code ec; 281477fe6aSWludzik, Jozef 291477fe6aSWludzik, Jozef auto tree = bus->yield_method_call<std::vector<SensorTree>>( 301477fe6aSWludzik, Jozef yield, ec, "xyz.openbmc_project.ObjectMapper", 311477fe6aSWludzik, Jozef "/xyz/openbmc_project/object_mapper", 321477fe6aSWludzik, Jozef "xyz.openbmc_project.ObjectMapper", "GetSubTree", 33*94f71c51SSzymon Dompke "/xyz/openbmc_project/sensors", 2, sensorInterfaces); 341477fe6aSWludzik, Jozef if (ec) 351477fe6aSWludzik, Jozef { 361477fe6aSWludzik, Jozef throw std::runtime_error("Failed to query ObjectMapper!"); 371477fe6aSWludzik, Jozef } 381477fe6aSWludzik, Jozef return tree; 391477fe6aSWludzik, Jozef } 401477fe6aSWludzik, Jozef 41*94f71c51SSzymon Dompke inline std::vector<SensorTree> getSubTreeSensors(const std::shared_ptr<sdbusplus::asio::connection> & bus)42*94f71c51SSzymon Dompke getSubTreeSensors(const std::shared_ptr<sdbusplus::asio::connection>& bus) 43*94f71c51SSzymon Dompke { 44*94f71c51SSzymon Dompke auto method_call = 45*94f71c51SSzymon Dompke bus->new_method_call("xyz.openbmc_project.ObjectMapper", 46*94f71c51SSzymon Dompke "/xyz/openbmc_project/object_mapper", 47*94f71c51SSzymon Dompke "xyz.openbmc_project.ObjectMapper", "GetSubTree"); 48*94f71c51SSzymon Dompke method_call.append("/xyz/openbmc_project/sensors/", 2, sensorInterfaces); 49*94f71c51SSzymon Dompke auto reply = bus->call(method_call); 50*94f71c51SSzymon Dompke 51*94f71c51SSzymon Dompke std::vector<SensorTree> tree; 52*94f71c51SSzymon Dompke reply.read(tree); 53*94f71c51SSzymon Dompke 54*94f71c51SSzymon Dompke return tree; 55*94f71c51SSzymon Dompke } 56*94f71c51SSzymon Dompke 571477fe6aSWludzik, Jozef } // namespace utils 58