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