blob: a32064152d665b6f3ae655b1b492faa776de938b [file] [log] [blame]
George Liu682ee182020-12-25 15:24:33 +08001#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
13namespace pldm
14{
15namespace dbus
16{
17using ObjectPath = std::string;
18
Patrick Williams705fa982023-09-27 02:32:20 -050019using LocationIntf =
20 sdbusplus::server::object_t<sdbusplus::xyz::openbmc_project::Inventory::
21 Decorator::server::LocationCode>;
George Liu682ee182020-12-25 15:24:33 +080022
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 */
27class 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