blob: 1046416886316cc989a62b9668a0fad9fc3851dc [file] [log] [blame]
John Wedigd32b9662022-04-13 18:12:25 -07001
2#include "getConfig.hpp"
3
4#include <phosphor-logging/lg2.hpp>
5#include <sdbusplus/asio/connection.hpp>
6
7#include <cstdlib>
8#include <memory>
9#include <string>
10#include <utility>
11#include <variant>
12#include <vector>
13
14namespace estoraged
15{
16
17namespace mapper
18{
19constexpr const char* busName = "xyz.openbmc_project.ObjectMapper";
20constexpr const char* path = "/xyz/openbmc_project/object_mapper";
21constexpr const char* interface = "xyz.openbmc_project.ObjectMapper";
22constexpr const char* subtree = "GetSubTree";
23} // namespace mapper
24
25using GetSubTreeType = std::vector<
26 std::pair<std::string,
27 std::vector<std::pair<std::string, std::vector<std::string>>>>>;
28
29void GetStorageConfiguration::getStorageInfo(const std::string& path,
30 const std::string& owner)
31{
32 std::shared_ptr<GetStorageConfiguration> self = shared_from_this();
33 self->dbusConnection->async_method_call(
34 [self, path, owner](
35 const boost::system::error_code ec,
36 boost::container::flat_map<std::string, BasicVariantType>& data) {
37 if (ec)
38 {
39 lg2::error("Error getting properties for {PATH}", "PATH", path,
40 "REDFISH_MESSAGE_ID",
41 std::string("OpenBMC.0.1.GetStorageInfoFail"));
42 return;
43 }
44
45 self->respData[path] = std::move(data);
46 },
47 owner, path, "org.freedesktop.DBus.Properties", "GetAll",
48 emmcConfigInterface);
49}
50
51void GetStorageConfiguration::getConfiguration()
52{
53 std::shared_ptr<GetStorageConfiguration> self = shared_from_this();
54 dbusConnection->async_method_call(
55 [self](const boost::system::error_code ec, const GetSubTreeType& ret) {
56 if (ec)
57 {
58 lg2::error("Error calling mapper");
59 return;
60 }
61 for (const auto& [objPath, objDict] : ret)
62 {
63 if (objDict.empty())
64 {
65 return;
66 }
67 const std::string& objOwner = objDict.begin()->first;
68 /* Look for the config interface exposed by this object. */
69 for (const std::string& interface : objDict.begin()->second)
70 {
71 if (interface.compare(emmcConfigInterface) == 0)
72 {
73 /* Get the properties exposed by this interface. */
74 self->getStorageInfo(objPath, objOwner);
75 }
76 }
77 }
78 },
79 mapper::busName, mapper::path, mapper::interface, mapper::subtree, "/",
80 0, std::vector<const char*>(1, emmcConfigInterface));
81}
82
83GetStorageConfiguration::~GetStorageConfiguration()
84{
85 callback(respData);
86}
87
88} // namespace estoraged