John Wedig | d32b966 | 2022-04-13 18:12:25 -0700 | [diff] [blame] | 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) { |
Patrick Williams | 04c28fa | 2023-05-10 07:51:24 -0500 | [diff] [blame] | 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 | } |
John Wedig | d32b966 | 2022-04-13 18:12:25 -0700 | [diff] [blame] | 44 | |
Patrick Williams | 04c28fa | 2023-05-10 07:51:24 -0500 | [diff] [blame] | 45 | self->respData[path] = std::move(data); |
Patrick Williams | ff1b64f | 2023-10-20 11:19:56 -0500 | [diff] [blame] | 46 | }, |
John Wedig | d32b966 | 2022-04-13 18:12:25 -0700 | [diff] [blame] | 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) { |
Patrick Williams | 04c28fa | 2023-05-10 07:51:24 -0500 | [diff] [blame] | 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()) |
John Wedig | d32b966 | 2022-04-13 18:12:25 -0700 | [diff] [blame] | 64 | { |
John Wedig | d32b966 | 2022-04-13 18:12:25 -0700 | [diff] [blame] | 65 | return; |
| 66 | } |
Patrick Williams | 04c28fa | 2023-05-10 07:51:24 -0500 | [diff] [blame] | 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) |
John Wedig | d32b966 | 2022-04-13 18:12:25 -0700 | [diff] [blame] | 70 | { |
Patrick Williams | 04c28fa | 2023-05-10 07:51:24 -0500 | [diff] [blame] | 71 | if (interface.compare(emmcConfigInterface) == 0) |
John Wedig | d32b966 | 2022-04-13 18:12:25 -0700 | [diff] [blame] | 72 | { |
Patrick Williams | 04c28fa | 2023-05-10 07:51:24 -0500 | [diff] [blame] | 73 | /* Get the properties exposed by this interface. */ |
| 74 | self->getStorageInfo(objPath, objOwner); |
John Wedig | d32b966 | 2022-04-13 18:12:25 -0700 | [diff] [blame] | 75 | } |
| 76 | } |
Patrick Williams | 04c28fa | 2023-05-10 07:51:24 -0500 | [diff] [blame] | 77 | } |
Patrick Williams | ff1b64f | 2023-10-20 11:19:56 -0500 | [diff] [blame] | 78 | }, |
John Wedig | d32b966 | 2022-04-13 18:12:25 -0700 | [diff] [blame] | 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 |