1 #pragma once 2 3 #include <boost/container/flat_map.hpp> 4 #include <sdbusplus/asio/connection.hpp> 5 6 #include <cstdlib> 7 #include <functional> 8 #include <memory> 9 10 namespace estoraged 11 { 12 13 using BasicVariantType = 14 std::variant<std::vector<std::string>, std::string, int64_t, uint64_t, 15 double, int32_t, uint32_t, int16_t, uint16_t, uint8_t, bool>; 16 17 /* Map of properties for the config interface. */ 18 using StorageData = boost::container::flat_map<std::string, BasicVariantType>; 19 using ManagedStorageType = 20 boost::container::flat_map<sdbusplus::message::object_path, StorageData>; 21 22 const constexpr char* emmcConfigInterface = 23 "xyz.openbmc_project.Configuration.EmmcDevice"; 24 25 /** @class GetStorageConfiguration 26 * @brief Object used to find Entity Manager config objects. 27 * @details eStoraged will create a new D-Bus object for each config object. 28 */ 29 class GetStorageConfiguration : 30 public std::enable_shared_from_this<GetStorageConfiguration> 31 { 32 public: 33 /** @brief Constructor for GetStorageConfiguration 34 * 35 * @param[in] connection - shared_ptr to D-Bus connection object. 36 * @param[in] callbackFunc - callback to run after finding the config 37 * objects. 38 */ GetStorageConfiguration(std::shared_ptr<sdbusplus::asio::connection> connection,std::function<void (ManagedStorageType & resp)> && callbackFunc)39 GetStorageConfiguration( 40 std::shared_ptr<sdbusplus::asio::connection> connection, 41 std::function<void(ManagedStorageType& resp)>&& callbackFunc) : 42 dbusConnection(std::move(connection)), callback(std::move(callbackFunc)) 43 {} 44 45 GetStorageConfiguration& operator=(const GetStorageConfiguration&) = delete; 46 GetStorageConfiguration(const GetStorageConfiguration&) = delete; 47 GetStorageConfiguration(GetStorageConfiguration&&) = default; 48 GetStorageConfiguration& operator=(GetStorageConfiguration&&) = default; 49 50 /** @brief Destructor for GetStorageConfiguration. 51 * @details This will execute the callback provided to the constructor. 52 */ 53 ~GetStorageConfiguration(); 54 55 /** @brief Find the Entity Manager config objects for eStoraged. */ 56 void getConfiguration(); 57 58 /** @brief Get the D-Bus properties from the config object. 59 * 60 * @param[in] path - D-Bus object path of the config object. 61 * @param[in] owner - D-Bus service that owns the config object. 62 * @param[in] retries - (optional) Number of times to retry, if needed. 63 */ 64 void getStorageInfo(const std::string& path, const std::string& owner, 65 size_t retries = 5); 66 67 /** @brief Map containing config objects with corresponding properties. */ 68 ManagedStorageType respData; 69 70 /** @brief Connection to D-Bus. */ 71 std::shared_ptr<sdbusplus::asio::connection> dbusConnection; 72 73 private: 74 /** @brief callback to process the config object data in respData. */ 75 std::function<void(ManagedStorageType& resp)> callback; 76 }; 77 78 } // namespace estoraged 79