George Liu | 682ee18 | 2020-12-25 15:24:33 +0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "common/utils.hpp" |
| 4 | |
| 5 | #include <sdbusplus/server.hpp> |
| 6 | #include <xyz/openbmc_project/Inventory/Decorator/LocationCode/server.hpp> |
| 7 | |
| 8 | #include <memory> |
| 9 | #include <optional> |
| 10 | #include <string> |
| 11 | #include <unordered_map> |
| 12 | |
| 13 | namespace pldm |
| 14 | { |
| 15 | namespace dbus |
| 16 | { |
| 17 | using ObjectPath = std::string; |
| 18 | |
| 19 | using LocationIntf = sdbusplus::server::object::object< |
| 20 | sdbusplus::xyz::openbmc_project::Inventory::Decorator::server:: |
| 21 | LocationCode>; |
| 22 | |
| 23 | /** @class CustomDBus |
| 24 | * @brief This is a custom D-Bus object, used to add D-Bus interface and update |
| 25 | * the corresponding properties value. |
| 26 | */ |
| 27 | class CustomDBus |
| 28 | { |
| 29 | private: |
| 30 | CustomDBus() {} |
| 31 | |
| 32 | public: |
| 33 | CustomDBus(const CustomDBus&) = delete; |
| 34 | CustomDBus(CustomDBus&&) = delete; |
| 35 | CustomDBus& operator=(const CustomDBus&) = delete; |
| 36 | CustomDBus& operator=(CustomDBus&&) = delete; |
| 37 | ~CustomDBus() = default; |
| 38 | |
| 39 | static CustomDBus& getCustomDBus() |
| 40 | { |
| 41 | static CustomDBus customDBus; |
| 42 | return customDBus; |
| 43 | } |
| 44 | |
| 45 | public: |
| 46 | /** @brief Set the LocationCode property |
| 47 | * |
| 48 | * @param[in] path - The object path |
| 49 | * |
| 50 | * @param[in] value - The value of the LocationCode property |
| 51 | */ |
| 52 | void setLocationCode(const std::string& path, std::string value); |
| 53 | |
| 54 | /** @brief Get the LocationCode property |
| 55 | * |
| 56 | * @param[in] path - The object path |
| 57 | * |
| 58 | * @return std::optional<std::string> - The value of the LocationCode |
| 59 | * property |
| 60 | */ |
| 61 | std::optional<std::string> getLocationCode(const std::string& path) const; |
| 62 | |
| 63 | private: |
| 64 | std::unordered_map<ObjectPath, std::unique_ptr<LocationIntf>> location; |
| 65 | }; |
| 66 | |
| 67 | } // namespace dbus |
| 68 | } // namespace pldm |