xref: /openbmc/estoraged/include/getConfig.hpp (revision 439f0fd8)
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.
63      */
64     void getStorageInfo(const std::string& path, const std::string& owner);
65 
66     /** @brief Map containing config objects with corresponding properties. */
67     ManagedStorageType respData;
68 
69     /** @brief Connection to D-Bus. */
70     std::shared_ptr<sdbusplus::asio::connection> dbusConnection;
71 
72   private:
73     /** @brief callback to process the config object data in respData. */
74     std::function<void(ManagedStorageType& resp)> callback;
75 };
76 
77 } // namespace estoraged
78