blob: 077cdb6a821112a680af583f825966995553c01a [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) :
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 Wedig3cf9e802024-04-30 14:13:05 -070063 * @param[in] retries - (optional) Number of times to retry, if needed.
John Wedigd32b9662022-04-13 18:12:25 -070064 */
John Wedig3cf9e802024-04-30 14:13:05 -070065 void getStorageInfo(const std::string& path, const std::string& owner,
66 size_t retries = 5);
John Wedigd32b9662022-04-13 18:12:25 -070067
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