1d32b9667SJohn Wedig 2d32b9667SJohn Wedig #include "getConfig.hpp" 3d32b9667SJohn Wedig 4*3cf9e806SJohn Wedig #include <boost/asio/steady_timer.hpp> 5d32b9667SJohn Wedig #include <phosphor-logging/lg2.hpp> 6d32b9667SJohn Wedig #include <sdbusplus/asio/connection.hpp> 7d32b9667SJohn Wedig 8*3cf9e806SJohn Wedig #include <chrono> 9d32b9667SJohn Wedig #include <cstdlib> 10d32b9667SJohn Wedig #include <memory> 11d32b9667SJohn Wedig #include <string> 12d32b9667SJohn Wedig #include <utility> 13d32b9667SJohn Wedig #include <variant> 14d32b9667SJohn Wedig #include <vector> 15d32b9667SJohn Wedig 16d32b9667SJohn Wedig namespace estoraged 17d32b9667SJohn Wedig { 18d32b9667SJohn Wedig 19d32b9667SJohn Wedig namespace mapper 20d32b9667SJohn Wedig { 21d32b9667SJohn Wedig constexpr const char* busName = "xyz.openbmc_project.ObjectMapper"; 22d32b9667SJohn Wedig constexpr const char* path = "/xyz/openbmc_project/object_mapper"; 23d32b9667SJohn Wedig constexpr const char* interface = "xyz.openbmc_project.ObjectMapper"; 24d32b9667SJohn Wedig constexpr const char* subtree = "GetSubTree"; 25d32b9667SJohn Wedig } // namespace mapper 26d32b9667SJohn Wedig 27d32b9667SJohn Wedig using GetSubTreeType = std::vector< 28d32b9667SJohn Wedig std::pair<std::string, 29d32b9667SJohn Wedig std::vector<std::pair<std::string, std::vector<std::string>>>>>; 30d32b9667SJohn Wedig 31d32b9667SJohn Wedig void GetStorageConfiguration::getStorageInfo(const std::string& path, 32*3cf9e806SJohn Wedig const std::string& owner, 33*3cf9e806SJohn Wedig size_t retries) 34d32b9667SJohn Wedig { 35d32b9667SJohn Wedig std::shared_ptr<GetStorageConfiguration> self = shared_from_this(); 36d32b9667SJohn Wedig self->dbusConnection->async_method_call( 37*3cf9e806SJohn Wedig [self, path, owner, retries]( 38d32b9667SJohn Wedig const boost::system::error_code ec, 39d32b9667SJohn Wedig boost::container::flat_map<std::string, BasicVariantType>& data) { 40d32b9667SJohn Wedig if (ec) 41d32b9667SJohn Wedig { 42*3cf9e806SJohn Wedig lg2::error( 43*3cf9e806SJohn Wedig "Error getting properties for {PATH}: {RETRIES} retries left", 44*3cf9e806SJohn Wedig "PATH", path, "RETRIES", retries - 1, "REDFISH_MESSAGE_ID", 45d32b9667SJohn Wedig std::string("OpenBMC.0.1.GetStorageInfoFail")); 46*3cf9e806SJohn Wedig if (retries == 0U) 47*3cf9e806SJohn Wedig { 48*3cf9e806SJohn Wedig return; 49*3cf9e806SJohn Wedig } 50*3cf9e806SJohn Wedig 51*3cf9e806SJohn Wedig auto timer = std::make_shared<boost::asio::steady_timer>( 52*3cf9e806SJohn Wedig self->dbusConnection->get_io_context()); 53*3cf9e806SJohn Wedig timer->expires_after(std::chrono::seconds(10)); 54*3cf9e806SJohn Wedig timer->async_wait([self, timer, path, owner, 55*3cf9e806SJohn Wedig retries](boost::system::error_code ec) { 56*3cf9e806SJohn Wedig if (ec) 57*3cf9e806SJohn Wedig { 58*3cf9e806SJohn Wedig lg2::error("Timer error!"); 59*3cf9e806SJohn Wedig return; 60*3cf9e806SJohn Wedig } 61*3cf9e806SJohn Wedig self->getStorageInfo(path, owner, retries - 1); 62*3cf9e806SJohn Wedig }); 63*3cf9e806SJohn Wedig 64d32b9667SJohn Wedig return; 65d32b9667SJohn Wedig } 66d32b9667SJohn Wedig 67d32b9667SJohn Wedig self->respData[path] = std::move(data); 68d32b9667SJohn Wedig }, 69d32b9667SJohn Wedig owner, path, "org.freedesktop.DBus.Properties", "GetAll", 70d32b9667SJohn Wedig emmcConfigInterface); 71d32b9667SJohn Wedig } 72d32b9667SJohn Wedig 73d32b9667SJohn Wedig void GetStorageConfiguration::getConfiguration() 74d32b9667SJohn Wedig { 75d32b9667SJohn Wedig std::shared_ptr<GetStorageConfiguration> self = shared_from_this(); 76d32b9667SJohn Wedig dbusConnection->async_method_call( 77d32b9667SJohn Wedig [self](const boost::system::error_code ec, const GetSubTreeType& ret) { 78d32b9667SJohn Wedig if (ec) 79d32b9667SJohn Wedig { 80d32b9667SJohn Wedig lg2::error("Error calling mapper"); 81d32b9667SJohn Wedig return; 82d32b9667SJohn Wedig } 83d32b9667SJohn Wedig for (const auto& [objPath, objDict] : ret) 84d32b9667SJohn Wedig { 85d32b9667SJohn Wedig if (objDict.empty()) 86d32b9667SJohn Wedig { 87d32b9667SJohn Wedig return; 88d32b9667SJohn Wedig } 89d32b9667SJohn Wedig const std::string& objOwner = objDict.begin()->first; 90d32b9667SJohn Wedig /* Look for the config interface exposed by this object. */ 91d32b9667SJohn Wedig for (const std::string& interface : objDict.begin()->second) 92d32b9667SJohn Wedig { 93d32b9667SJohn Wedig if (interface.compare(emmcConfigInterface) == 0) 94d32b9667SJohn Wedig { 95d32b9667SJohn Wedig /* Get the properties exposed by this interface. */ 96d32b9667SJohn Wedig self->getStorageInfo(objPath, objOwner); 97d32b9667SJohn Wedig } 98d32b9667SJohn Wedig } 99d32b9667SJohn Wedig } 100d32b9667SJohn Wedig }, 101d32b9667SJohn Wedig mapper::busName, mapper::path, mapper::interface, mapper::subtree, "/", 102d32b9667SJohn Wedig 0, std::vector<const char*>(1, emmcConfigInterface)); 103d32b9667SJohn Wedig } 104d32b9667SJohn Wedig 105d32b9667SJohn Wedig GetStorageConfiguration::~GetStorageConfiguration() 106d32b9667SJohn Wedig { 107d32b9667SJohn Wedig callback(respData); 108d32b9667SJohn Wedig } 109d32b9667SJohn Wedig 110d32b9667SJohn Wedig } // namespace estoraged 111