blob: 563a0574f2e7f5eb5d0c7bbfcb4030d7a122ecbe [file] [log] [blame]
John Wedigd32b9662022-04-13 18:12:25 -07001
2#include "getConfig.hpp"
3
John Wedig3cf9e802024-04-30 14:13:05 -07004#include <boost/asio/steady_timer.hpp>
John Wedigd32b9662022-04-13 18:12:25 -07005#include <phosphor-logging/lg2.hpp>
6#include <sdbusplus/asio/connection.hpp>
7
John Wedig3cf9e802024-04-30 14:13:05 -07008#include <chrono>
John Wedigd32b9662022-04-13 18:12:25 -07009#include <cstdlib>
10#include <memory>
11#include <string>
12#include <utility>
13#include <variant>
14#include <vector>
15
16namespace estoraged
17{
18
19namespace mapper
20{
21constexpr const char* busName = "xyz.openbmc_project.ObjectMapper";
22constexpr const char* path = "/xyz/openbmc_project/object_mapper";
23constexpr const char* interface = "xyz.openbmc_project.ObjectMapper";
24constexpr const char* subtree = "GetSubTree";
25} // namespace mapper
26
27using GetSubTreeType = std::vector<
28 std::pair<std::string,
29 std::vector<std::pair<std::string, std::vector<std::string>>>>>;
30
31void GetStorageConfiguration::getStorageInfo(const std::string& path,
John Wedig3cf9e802024-04-30 14:13:05 -070032 const std::string& owner,
33 size_t retries)
John Wedigd32b9662022-04-13 18:12:25 -070034{
35 std::shared_ptr<GetStorageConfiguration> self = shared_from_this();
36 self->dbusConnection->async_method_call(
John Wedig3cf9e802024-04-30 14:13:05 -070037 [self, path, owner, retries](
John Wedigd32b9662022-04-13 18:12:25 -070038 const boost::system::error_code ec,
39 boost::container::flat_map<std::string, BasicVariantType>& data) {
Patrick Williams04c28fa2023-05-10 07:51:24 -050040 if (ec)
41 {
John Wedig3cf9e802024-04-30 14:13:05 -070042 lg2::error(
43 "Error getting properties for {PATH}: {RETRIES} retries left",
44 "PATH", path, "RETRIES", retries - 1, "REDFISH_MESSAGE_ID",
45 std::string("OpenBMC.0.1.GetStorageInfoFail"));
46 if (retries == 0U)
47 {
48 return;
49 }
50
51 auto timer = std::make_shared<boost::asio::steady_timer>(
52 self->dbusConnection->get_io_context());
53 timer->expires_after(std::chrono::seconds(10));
54 timer->async_wait([self, timer, path, owner,
55 retries](boost::system::error_code ec) {
56 if (ec)
57 {
58 lg2::error("Timer error!");
59 return;
60 }
61 self->getStorageInfo(path, owner, retries - 1);
62 });
63
Patrick Williams04c28fa2023-05-10 07:51:24 -050064 return;
65 }
John Wedigd32b9662022-04-13 18:12:25 -070066
Patrick Williams04c28fa2023-05-10 07:51:24 -050067 self->respData[path] = std::move(data);
Patrick Williamsff1b64f2023-10-20 11:19:56 -050068 },
John Wedigd32b9662022-04-13 18:12:25 -070069 owner, path, "org.freedesktop.DBus.Properties", "GetAll",
70 emmcConfigInterface);
71}
72
73void GetStorageConfiguration::getConfiguration()
74{
75 std::shared_ptr<GetStorageConfiguration> self = shared_from_this();
76 dbusConnection->async_method_call(
77 [self](const boost::system::error_code ec, const GetSubTreeType& ret) {
Patrick Williams04c28fa2023-05-10 07:51:24 -050078 if (ec)
79 {
80 lg2::error("Error calling mapper");
81 return;
82 }
83 for (const auto& [objPath, objDict] : ret)
84 {
85 if (objDict.empty())
John Wedigd32b9662022-04-13 18:12:25 -070086 {
John Wedigd32b9662022-04-13 18:12:25 -070087 return;
88 }
Patrick Williams04c28fa2023-05-10 07:51:24 -050089 const std::string& objOwner = objDict.begin()->first;
90 /* Look for the config interface exposed by this object. */
91 for (const std::string& interface : objDict.begin()->second)
John Wedigd32b9662022-04-13 18:12:25 -070092 {
Patrick Williams04c28fa2023-05-10 07:51:24 -050093 if (interface.compare(emmcConfigInterface) == 0)
John Wedigd32b9662022-04-13 18:12:25 -070094 {
Patrick Williams04c28fa2023-05-10 07:51:24 -050095 /* Get the properties exposed by this interface. */
96 self->getStorageInfo(objPath, objOwner);
John Wedigd32b9662022-04-13 18:12:25 -070097 }
98 }
Patrick Williams04c28fa2023-05-10 07:51:24 -050099 }
Patrick Williamsff1b64f2023-10-20 11:19:56 -0500100 },
John Wedigd32b9662022-04-13 18:12:25 -0700101 mapper::busName, mapper::path, mapper::interface, mapper::subtree, "/",
102 0, std::vector<const char*>(1, emmcConfigInterface));
103}
104
105GetStorageConfiguration::~GetStorageConfiguration()
106{
107 callback(respData);
108}
109
110} // namespace estoraged