blob: bcb79504ca3f837f032a2062010b85a87784cb86 [file] [log] [blame]
John Wedigd32b9662022-04-13 18:12:25 -07001#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
10namespace estoraged
11{
12
13using 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. */
18using StorageData = boost::container::flat_map<std::string, BasicVariantType>;
19using ManagedStorageType =
20 boost::container::flat_map<sdbusplus::message::object_path, StorageData>;
21
22const 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 */
29class 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) :
Patrick Williams15b63e12024-08-16 15:22:01 -040042 dbusConnection(std::move(connection)), callback(std::move(callbackFunc))
John Wedigd32b9662022-04-13 18:12:25 -070043 {}
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.
John Wedig3cf9e802024-04-30 14:13:05 -070062 * @param[in] retries - (optional) Number of times to retry, if needed.
John Wedigd32b9662022-04-13 18:12:25 -070063 */
John Wedig3cf9e802024-04-30 14:13:05 -070064 void getStorageInfo(const std::string& path, const std::string& owner,
65 size_t retries = 5);
John Wedigd32b9662022-04-13 18:12:25 -070066
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