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