blob: 78cf7b2629575e25947e8a5d9bdd0e54625f058b [file] [log] [blame]
Wludzik, Jozef1477fe62021-01-02 11:56:10 +01001#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
11namespace utils
12{
13
14using SensorPath = std::string;
15using ServiceName = std::string;
16using Ifaces = std::vector<std::string>;
17using SensorIfaces = std::vector<std::pair<ServiceName, Ifaces>>;
18using SensorTree = std::pair<SensorPath, SensorIfaces>;
19
20inline 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