blob: 5f074456add16db8dbf0f35277c866f0cc496336 [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
Szymon Dompke94f71c52021-12-10 07:16:33 +010020constexpr std::array<const char*, 1> sensorInterfaces = {
21 "xyz.openbmc_project.Sensor.Value"};
22
Wludzik, Jozef1477fe62021-01-02 11:56:10 +010023inline std::vector<SensorTree>
24 getSubTreeSensors(boost::asio::yield_context& yield,
25 const std::shared_ptr<sdbusplus::asio::connection>& bus)
26{
Wludzik, Jozef1477fe62021-01-02 11:56:10 +010027 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 Dompke94f71c52021-12-10 07:16:33 +010033 "/xyz/openbmc_project/sensors", 2, sensorInterfaces);
Wludzik, Jozef1477fe62021-01-02 11:56:10 +010034 if (ec)
35 {
36 throw std::runtime_error("Failed to query ObjectMapper!");
37 }
38 return tree;
39}
40
Szymon Dompke94f71c52021-12-10 07:16:33 +010041inline 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, Jozef1477fe62021-01-02 11:56:10 +010057} // namespace utils