xref: /openbmc/pldm/host-bmc/dbus/custom_dbus.hpp (revision 2ed986c9)
1 #pragma once
2 
3 #include "cable.hpp"
4 #include "common/utils.hpp"
5 #include "cpu_core.hpp"
6 #include "motherboard.hpp"
7 #include "pcie_device.hpp"
8 #include "pcie_slot.hpp"
9 
10 #include <sdbusplus/server.hpp>
11 #include <xyz/openbmc_project/Inventory/Decorator/LocationCode/server.hpp>
12 
13 #include <memory>
14 #include <optional>
15 #include <string>
16 #include <unordered_map>
17 
18 namespace pldm
19 {
20 namespace dbus
21 {
22 using ObjectPath = std::string;
23 
24 using LocationIntf =
25     sdbusplus::server::object_t<sdbusplus::xyz::openbmc_project::Inventory::
26                                     Decorator::server::LocationCode>;
27 
28 /** @class CustomDBus
29  *  @brief This is a custom D-Bus object, used to add D-Bus interface and update
30  *         the corresponding properties value.
31  */
32 class CustomDBus
33 {
34   private:
CustomDBus()35     CustomDBus() {}
36 
37   public:
38     CustomDBus(const CustomDBus&) = delete;
39     CustomDBus(CustomDBus&&) = delete;
40     CustomDBus& operator=(const CustomDBus&) = delete;
41     CustomDBus& operator=(CustomDBus&&) = delete;
42     ~CustomDBus() = default;
43 
getCustomDBus()44     static CustomDBus& getCustomDBus()
45     {
46         static CustomDBus customDBus;
47         return customDBus;
48     }
49 
50   public:
51     /** @brief Set the LocationCode property
52      *
53      *  @param[in] path  - The object path
54      *
55      *  @param[in] value - The value of the LocationCode property
56      */
57     void setLocationCode(const std::string& path, std::string value);
58 
59     /** @brief Get the LocationCode property
60      *
61      *  @param[in] path - The object path
62      *
63      *  @return std::optional<std::string> - The value of the LocationCode
64      *          property
65      */
66     std::optional<std::string> getLocationCode(const std::string& path) const;
67     /** @brief Implement CpuCore Interface
68      *
69      *  @param[in] path - The object path
70      *
71      */
72     void implementCpuCoreInterface(const std::string& path);
73     /** @brief Set the microcode property
74      *
75      *  @param[in] path   - The object path
76      *
77      *  @param[in] value  - microcode value
78      */
79     void setMicroCode(const std::string& path, uint32_t value);
80 
81     /** @brief Get the microcode property
82      *
83      *  @param[in] path   - The object path
84      *
85      *  @return std::optional<uint32_t> - The value of the microcode value
86      */
87     std::optional<uint32_t> getMicroCode(const std::string& path) const;
88 
89     /** @brief Implement PCIeSlot Interface
90      *
91      *  @param[in] path - the object path
92      */
93     void implementPCIeSlotInterface(const std::string& path);
94 
95     /** @brief Set the slot type
96      *
97      *  @param[in] path - the object path
98      *  @param[in] slot type - Slot type
99      */
100     void setSlotType(const std::string& path, const std::string& slotType);
101 
102     /** @brief Implement PCIe Device Interface
103      *
104      *  @param[in] path - the object path
105      */
106     void implementPCIeDeviceInterface(const std::string& path);
107 
108     /** @brief Set PCIe Device Lanes in use property
109      *
110      *  @param[in] path - the object path
111      *  @param[in] lanesInUse - Lanes in use
112      *  @param[in] value - Generation in use
113      */
114     void setPCIeDeviceProps(const std::string& path, size_t lanesInUse,
115                             const std::string& value);
116 
117     /** @brief Implement PCIe Cable Interface
118      *
119      *  @param[in] path - the object path
120      */
121     void implementCableInterface(const std::string& path);
122 
123     /** @brief set cable attributes
124      *
125      *  @param[in] path - the object path
126      *  @param[in] length - length of the wire
127      *  @param[in] cableDescription - cable details
128      */
129     void setCableAttributes(const std::string& path, double length,
130                             const std::string& cableDescription);
131     /** @brief Implement interface for motherboard property
132      *
133      *  @param[in] path  - The object path
134      *
135      */
136     void implementMotherboardInterface(const std::string& path);
137 
138   private:
139     std::unordered_map<ObjectPath, std::unique_ptr<LocationIntf>> location;
140     std::unordered_map<ObjectPath, std::unique_ptr<CPUCore>> cpuCore;
141     std::unordered_map<ObjectPath, std::unique_ptr<PCIeDevice>> pcieDevice;
142     std::unordered_map<ObjectPath, std::unique_ptr<PCIeSlot>> pcieSlot;
143     std::unordered_map<ObjectPath, std::unique_ptr<Cable>> cable;
144     std::unordered_map<ObjectPath, std::unique_ptr<Motherboard>> motherboard;
145 };
146 
147 } // namespace dbus
148 } // namespace pldm
149