xref: /openbmc/estoraged/src/getConfig.cpp (revision 439f0fd8)
1 
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 
14 namespace estoraged
15 {
16 
17 namespace mapper
18 {
19 constexpr const char* busName = "xyz.openbmc_project.ObjectMapper";
20 constexpr const char* path = "/xyz/openbmc_project/object_mapper";
21 constexpr const char* interface = "xyz.openbmc_project.ObjectMapper";
22 constexpr const char* subtree = "GetSubTree";
23 } // namespace mapper
24 
25 using GetSubTreeType = std::vector<
26     std::pair<std::string,
27               std::vector<std::pair<std::string, std::vector<std::string>>>>>;
28 
29 void 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 
51 void 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 
83 GetStorageConfiguration::~GetStorageConfiguration()
84 {
85     callback(respData);
86 }
87 
88 } // namespace estoraged
89