| John Wedig | d32b966 | 2022-04-13 18:12:25 -0700 | [diff] [blame] | 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 | */ | 
|  | 39 | GetStorageConfiguration( | 
|  | 40 | std::shared_ptr<sdbusplus::asio::connection> connection, | 
|  | 41 | std::function<void(ManagedStorageType& resp)>&& callbackFunc) : | 
|  | 42 | dbusConnection(std::move(connection)), | 
|  | 43 | callback(std::move(callbackFunc)) | 
|  | 44 | {} | 
|  | 45 |  | 
|  | 46 | GetStorageConfiguration& operator=(const GetStorageConfiguration&) = delete; | 
|  | 47 | GetStorageConfiguration(const GetStorageConfiguration&) = delete; | 
|  | 48 | GetStorageConfiguration(GetStorageConfiguration&&) = default; | 
|  | 49 | GetStorageConfiguration& operator=(GetStorageConfiguration&&) = default; | 
|  | 50 |  | 
|  | 51 | /** @brief Destructor for GetStorageConfiguration. | 
|  | 52 | *  @details This will execute the callback provided to the constructor. | 
|  | 53 | */ | 
|  | 54 | ~GetStorageConfiguration(); | 
|  | 55 |  | 
|  | 56 | /** @brief Find the Entity Manager config objects for eStoraged. */ | 
|  | 57 | void getConfiguration(); | 
|  | 58 |  | 
|  | 59 | /** @brief Get the D-Bus properties from the config object. | 
|  | 60 | * | 
|  | 61 | *  @param[in] path - D-Bus object path of the config object. | 
|  | 62 | *  @param[in] owner - D-Bus service that owns the config object. | 
| John Wedig | 3cf9e80 | 2024-04-30 14:13:05 -0700 | [diff] [blame] | 63 | *  @param[in] retries - (optional) Number of times to retry, if needed. | 
| John Wedig | d32b966 | 2022-04-13 18:12:25 -0700 | [diff] [blame] | 64 | */ | 
| John Wedig | 3cf9e80 | 2024-04-30 14:13:05 -0700 | [diff] [blame] | 65 | void getStorageInfo(const std::string& path, const std::string& owner, | 
|  | 66 | size_t retries = 5); | 
| John Wedig | d32b966 | 2022-04-13 18:12:25 -0700 | [diff] [blame] | 67 |  | 
|  | 68 | /** @brief Map containing config objects with corresponding properties. */ | 
|  | 69 | ManagedStorageType respData; | 
|  | 70 |  | 
|  | 71 | /** @brief Connection to D-Bus. */ | 
|  | 72 | std::shared_ptr<sdbusplus::asio::connection> dbusConnection; | 
|  | 73 |  | 
|  | 74 | private: | 
|  | 75 | /** @brief callback to process the config object data in respData. */ | 
|  | 76 | std::function<void(ManagedStorageType& resp)> callback; | 
|  | 77 | }; | 
|  | 78 |  | 
|  | 79 | } // namespace estoraged |