#include "getConfig.hpp" #include #include #include #include #include #include #include #include #include #include namespace estoraged { namespace mapper { constexpr const char* busName = "xyz.openbmc_project.ObjectMapper"; constexpr const char* path = "/xyz/openbmc_project/object_mapper"; constexpr const char* interface = "xyz.openbmc_project.ObjectMapper"; constexpr const char* subtree = "GetSubTree"; } // namespace mapper using GetSubTreeType = std::vector< std::pair>>>>; void GetStorageConfiguration::getStorageInfo(const std::string& path, const std::string& owner, size_t retries) { std::shared_ptr self = shared_from_this(); self->dbusConnection->async_method_call( [self, path, owner, retries]( const boost::system::error_code ec, boost::container::flat_map& data) { if (ec) { lg2::error( "Error getting properties for {PATH}: {RETRIES} retries left", "PATH", path, "RETRIES", retries - 1, "REDFISH_MESSAGE_ID", std::string("OpenBMC.0.1.GetStorageInfoFail")); if (retries == 0U) { return; } auto timer = std::make_shared( self->dbusConnection->get_io_context()); timer->expires_after(std::chrono::seconds(10)); timer->async_wait([self, timer, path, owner, retries](boost::system::error_code ec) { if (ec) { lg2::error("Timer error!"); return; } self->getStorageInfo(path, owner, retries - 1); }); return; } self->respData[path] = std::move(data); }, owner, path, "org.freedesktop.DBus.Properties", "GetAll", emmcConfigInterface); } void GetStorageConfiguration::getConfiguration() { std::shared_ptr self = shared_from_this(); dbusConnection->async_method_call( [self](const boost::system::error_code ec, const GetSubTreeType& ret) { if (ec) { lg2::error("Error calling mapper"); return; } for (const auto& [objPath, objDict] : ret) { if (objDict.empty()) { return; } const std::string& objOwner = objDict.begin()->first; /* Look for the config interface exposed by this object. */ for (const std::string& interface : objDict.begin()->second) { if (interface.compare(emmcConfigInterface) == 0) { /* Get the properties exposed by this interface. */ self->getStorageInfo(objPath, objOwner); } } } }, mapper::busName, mapper::path, mapper::interface, mapper::subtree, "/", 0, std::vector(1, emmcConfigInterface)); } GetStorageConfiguration::~GetStorageConfiguration() { callback(respData); } } // namespace estoraged