blob: 80ffda9734c37eee3609be83d12d215832392353 [file] [log] [blame]
George Liu682ee182020-12-25 15:24:33 +08001#pragma once
2
Archana Kakanib40f4f82024-06-06 01:04:38 -05003#include "cable.hpp"
Archana Kakanidb65c3b2025-02-03 05:27:28 -06004#include "chassis.hpp"
George Liu682ee182020-12-25 15:24:33 +08005#include "common/utils.hpp"
Kamalkumar Patel56da5742024-05-23 04:53:07 -05006#include "cpu_core.hpp"
Archana Kakani413f51e2025-02-03 04:14:36 -06007#include "fan.hpp"
Kamalkumar Patel2ed986c2024-05-08 02:20:47 -05008#include "motherboard.hpp"
Archana Kakani733b39d2024-06-05 21:05:20 -05009#include "pcie_device.hpp"
Archana Kakanibf1fd272024-06-05 13:25:53 -050010#include "pcie_slot.hpp"
Archana Kakani24e9a9b2025-02-04 00:27:25 -060011#include "power_supply.hpp"
George Liu682ee182020-12-25 15:24:33 +080012
13#include <sdbusplus/server.hpp>
14#include <xyz/openbmc_project/Inventory/Decorator/LocationCode/server.hpp>
15
16#include <memory>
17#include <optional>
18#include <string>
19#include <unordered_map>
20
21namespace pldm
22{
23namespace dbus
24{
25using ObjectPath = std::string;
26
Patrick Williams705fa982023-09-27 02:32:20 -050027using LocationIntf =
28 sdbusplus::server::object_t<sdbusplus::xyz::openbmc_project::Inventory::
29 Decorator::server::LocationCode>;
George Liu682ee182020-12-25 15:24:33 +080030
31/** @class CustomDBus
32 * @brief This is a custom D-Bus object, used to add D-Bus interface and update
33 * the corresponding properties value.
34 */
35class CustomDBus
36{
37 private:
38 CustomDBus() {}
39
40 public:
41 CustomDBus(const CustomDBus&) = delete;
42 CustomDBus(CustomDBus&&) = delete;
43 CustomDBus& operator=(const CustomDBus&) = delete;
44 CustomDBus& operator=(CustomDBus&&) = delete;
45 ~CustomDBus() = default;
46
47 static CustomDBus& getCustomDBus()
48 {
49 static CustomDBus customDBus;
50 return customDBus;
51 }
52
53 public:
54 /** @brief Set the LocationCode property
55 *
56 * @param[in] path - The object path
57 *
58 * @param[in] value - The value of the LocationCode property
59 */
60 void setLocationCode(const std::string& path, std::string value);
61
62 /** @brief Get the LocationCode property
63 *
Kamalkumar Patel56da5742024-05-23 04:53:07 -050064 * @param[in] path - The object path
George Liu682ee182020-12-25 15:24:33 +080065 *
66 * @return std::optional<std::string> - The value of the LocationCode
67 * property
68 */
69 std::optional<std::string> getLocationCode(const std::string& path) const;
Kamalkumar Patel56da5742024-05-23 04:53:07 -050070 /** @brief Implement CpuCore Interface
71 *
72 * @param[in] path - The object path
73 *
74 */
75 void implementCpuCoreInterface(const std::string& path);
76 /** @brief Set the microcode property
77 *
78 * @param[in] path - The object path
79 *
80 * @param[in] value - microcode value
81 */
82 void setMicroCode(const std::string& path, uint32_t value);
83
84 /** @brief Get the microcode property
85 *
86 * @param[in] path - The object path
87 *
88 * @return std::optional<uint32_t> - The value of the microcode value
89 */
90 std::optional<uint32_t> getMicroCode(const std::string& path) const;
George Liu682ee182020-12-25 15:24:33 +080091
Archana Kakanibf1fd272024-06-05 13:25:53 -050092 /** @brief Implement PCIeSlot Interface
93 *
94 * @param[in] path - the object path
95 */
96 void implementPCIeSlotInterface(const std::string& path);
97
98 /** @brief Set the slot type
99 *
100 * @param[in] path - the object path
101 * @param[in] slot type - Slot type
102 */
103 void setSlotType(const std::string& path, const std::string& slotType);
104
Archana Kakani733b39d2024-06-05 21:05:20 -0500105 /** @brief Implement PCIe Device Interface
106 *
107 * @param[in] path - the object path
108 */
109 void implementPCIeDeviceInterface(const std::string& path);
110
111 /** @brief Set PCIe Device Lanes in use property
112 *
113 * @param[in] path - the object path
114 * @param[in] lanesInUse - Lanes in use
115 * @param[in] value - Generation in use
116 */
117 void setPCIeDeviceProps(const std::string& path, size_t lanesInUse,
118 const std::string& value);
119
Archana Kakanib40f4f82024-06-06 01:04:38 -0500120 /** @brief Implement PCIe Cable Interface
121 *
122 * @param[in] path - the object path
123 */
124 void implementCableInterface(const std::string& path);
125
126 /** @brief set cable attributes
127 *
128 * @param[in] path - the object path
129 * @param[in] length - length of the wire
130 * @param[in] cableDescription - cable details
131 */
132 void setCableAttributes(const std::string& path, double length,
133 const std::string& cableDescription);
Kamalkumar Patel2ed986c2024-05-08 02:20:47 -0500134 /** @brief Implement interface for motherboard property
135 *
136 * @param[in] path - The object path
137 *
138 */
139 void implementMotherboardInterface(const std::string& path);
Archana Kakanib40f4f82024-06-06 01:04:38 -0500140
Archana Kakani413f51e2025-02-03 04:14:36 -0600141 /** @brief Implement Fan Interface
142 *
143 * @param[in] path - The object path
144 *
145 */
146 void implementFanInterface(const std::string& path);
147
Archana Kakanidb65c3b2025-02-03 05:27:28 -0600148 /** @brief Implement Chassis Interface
149 * @param[in] path - the object path
150 */
151 void implementChassisInterface(const std::string& path);
152
Archana Kakani24e9a9b2025-02-04 00:27:25 -0600153 /** @brief Implement PowerSupply Interface
154 *
155 * @param[in] path - The object path
156 *
157 */
158 void implementPowerSupplyInterface(const std::string& path);
159
George Liu682ee182020-12-25 15:24:33 +0800160 private:
161 std::unordered_map<ObjectPath, std::unique_ptr<LocationIntf>> location;
Kamalkumar Patel56da5742024-05-23 04:53:07 -0500162 std::unordered_map<ObjectPath, std::unique_ptr<CPUCore>> cpuCore;
Archana Kakanidb65c3b2025-02-03 05:27:28 -0600163 std::unordered_map<ObjectPath, std::unique_ptr<ItemChassis>> chassis;
Archana Kakani733b39d2024-06-05 21:05:20 -0500164 std::unordered_map<ObjectPath, std::unique_ptr<PCIeDevice>> pcieDevice;
Archana Kakanibf1fd272024-06-05 13:25:53 -0500165 std::unordered_map<ObjectPath, std::unique_ptr<PCIeSlot>> pcieSlot;
Archana Kakani24e9a9b2025-02-04 00:27:25 -0600166 std::unordered_map<ObjectPath, std::unique_ptr<PowerSupply>> powersupply;
Archana Kakanib40f4f82024-06-06 01:04:38 -0500167 std::unordered_map<ObjectPath, std::unique_ptr<Cable>> cable;
Kamalkumar Patel2ed986c2024-05-08 02:20:47 -0500168 std::unordered_map<ObjectPath, std::unique_ptr<Motherboard>> motherboard;
Archana Kakani413f51e2025-02-03 04:14:36 -0600169 std::unordered_map<ObjectPath, std::unique_ptr<Fan>> fan;
George Liu682ee182020-12-25 15:24:33 +0800170};
171
172} // namespace dbus
173} // namespace pldm