George Liu | 682ee18 | 2020-12-25 15:24:33 +0800 | [diff] [blame] | 1 | #include "custom_dbus.hpp" |
| 2 | |
| 3 | namespace pldm |
| 4 | { |
| 5 | namespace dbus |
| 6 | { |
| 7 | void CustomDBus::setLocationCode(const std::string& path, std::string value) |
| 8 | { |
| 9 | if (!location.contains(path)) |
| 10 | { |
| 11 | location.emplace(path, |
| 12 | std::make_unique<LocationIntf>( |
| 13 | pldm::utils::DBusHandler::getBus(), path.c_str())); |
| 14 | } |
| 15 | |
| 16 | location.at(path)->locationCode(value); |
| 17 | } |
| 18 | |
Patrick Williams | 366507c | 2025-02-03 14:28:01 -0500 | [diff] [blame] | 19 | std::optional<std::string> CustomDBus::getLocationCode( |
| 20 | const std::string& path) const |
George Liu | 682ee18 | 2020-12-25 15:24:33 +0800 | [diff] [blame] | 21 | { |
| 22 | if (location.contains(path)) |
| 23 | { |
| 24 | return location.at(path)->locationCode(); |
| 25 | } |
| 26 | |
| 27 | return std::nullopt; |
| 28 | } |
| 29 | |
Kamalkumar Patel | 56da574 | 2024-05-23 04:53:07 -0500 | [diff] [blame] | 30 | void CustomDBus::implementCpuCoreInterface(const std::string& path) |
| 31 | { |
| 32 | if (!cpuCore.contains(path)) |
| 33 | { |
| 34 | cpuCore.emplace(path, std::make_unique<CPUCore>( |
| 35 | pldm::utils::DBusHandler::getBus(), path)); |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | void CustomDBus::setMicroCode(const std::string& path, uint32_t value) |
| 40 | { |
| 41 | if (!cpuCore.contains(path)) |
| 42 | { |
| 43 | cpuCore.emplace(path, std::make_unique<CPUCore>( |
| 44 | pldm::utils::DBusHandler::getBus(), path)); |
| 45 | } |
| 46 | cpuCore.at(path)->microcode(value); |
| 47 | } |
| 48 | |
| 49 | std::optional<uint32_t> CustomDBus::getMicroCode(const std::string& path) const |
| 50 | { |
| 51 | if (cpuCore.contains(path)) |
| 52 | { |
| 53 | return cpuCore.at(path)->microcode(); |
| 54 | } |
| 55 | |
| 56 | return std::nullopt; |
| 57 | } |
Archana Kakani | bf1fd27 | 2024-06-05 13:25:53 -0500 | [diff] [blame] | 58 | |
| 59 | void CustomDBus::implementPCIeSlotInterface(const std::string& path) |
| 60 | { |
| 61 | if (!pcieSlot.contains(path)) |
| 62 | { |
| 63 | pcieSlot.emplace(path, std::make_unique<PCIeSlot>( |
| 64 | pldm::utils::DBusHandler::getBus(), path)); |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | void CustomDBus::setSlotType(const std::string& path, |
| 69 | const std::string& slotType) |
| 70 | { |
| 71 | auto typeOfSlot = |
| 72 | pldm::dbus::PCIeSlot::convertSlotTypesFromString(slotType); |
| 73 | if (pcieSlot.contains(path)) |
| 74 | { |
| 75 | pcieSlot.at(path)->slotType(typeOfSlot); |
| 76 | } |
| 77 | } |
Archana Kakani | 733b39d | 2024-06-05 21:05:20 -0500 | [diff] [blame] | 78 | |
| 79 | void CustomDBus::implementPCIeDeviceInterface(const std::string& path) |
| 80 | { |
| 81 | if (!pcieDevice.contains(path)) |
| 82 | { |
| 83 | pcieDevice.emplace(path, std::make_unique<PCIeDevice>( |
| 84 | pldm::utils::DBusHandler::getBus(), path)); |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | void CustomDBus::setPCIeDeviceProps(const std::string& path, size_t lanesInUse, |
| 89 | const std::string& value) |
| 90 | { |
| 91 | Generations generationsInUse = |
| 92 | pldm::dbus::PCIeSlot::convertGenerationsFromString(value); |
| 93 | |
| 94 | if (pcieDevice.contains(path)) |
| 95 | { |
| 96 | pcieDevice.at(path)->lanesInUse(lanesInUse); |
| 97 | pcieDevice.at(path)->generationInUse(generationsInUse); |
| 98 | } |
| 99 | } |
| 100 | |
Archana Kakani | b40f4f8 | 2024-06-06 01:04:38 -0500 | [diff] [blame] | 101 | void CustomDBus::implementCableInterface(const std::string& path) |
| 102 | { |
| 103 | if (!cable.contains(path)) |
| 104 | { |
| 105 | cable.emplace(path, std::make_unique<Cable>( |
| 106 | pldm::utils::DBusHandler::getBus(), path)); |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | void CustomDBus::setCableAttributes(const std::string& path, double length, |
| 111 | const std::string& cableDescription) |
| 112 | { |
| 113 | if (cable.contains(path)) |
| 114 | { |
| 115 | cable.at(path)->length(length); |
| 116 | cable.at(path)->cableTypeDescription(cableDescription); |
| 117 | } |
| 118 | } |
| 119 | |
Kamalkumar Patel | 2ed986c | 2024-05-08 02:20:47 -0500 | [diff] [blame] | 120 | void CustomDBus::implementMotherboardInterface(const std::string& path) |
| 121 | { |
| 122 | if (!motherboard.contains(path)) |
| 123 | { |
| 124 | motherboard.emplace(path, |
| 125 | std::make_unique<Motherboard>( |
| 126 | pldm::utils::DBusHandler::getBus(), path)); |
| 127 | } |
| 128 | } |
Archana Kakani | 413f51e | 2025-02-03 04:14:36 -0600 | [diff] [blame] | 129 | |
Archana Kakani | 42876b6 | 2025-02-04 04:22:29 -0600 | [diff] [blame] | 130 | void CustomDBus::implementFabricAdapter(const std::string& path) |
| 131 | { |
| 132 | if (!fabricAdapter.contains(path)) |
| 133 | { |
| 134 | fabricAdapter.emplace( |
| 135 | path, std::make_unique<FabricAdapter>( |
| 136 | pldm::utils::DBusHandler::getBus(), path.c_str())); |
| 137 | } |
| 138 | } |
| 139 | |
Archana Kakani | d432b48 | 2025-02-04 22:52:28 -0600 | [diff] [blame] | 140 | void CustomDBus::implementBoard(const std::string& path) |
| 141 | { |
| 142 | if (!board.contains(path)) |
| 143 | { |
| 144 | board.emplace(path, |
| 145 | std::make_unique<Board>( |
| 146 | pldm::utils::DBusHandler::getBus(), path.c_str())); |
| 147 | } |
| 148 | } |
| 149 | |
Archana Kakani | 24e9a9b | 2025-02-04 00:27:25 -0600 | [diff] [blame] | 150 | void CustomDBus::implementPowerSupplyInterface(const std::string& path) |
| 151 | { |
| 152 | if (!powersupply.contains(path)) |
| 153 | { |
| 154 | powersupply.emplace( |
| 155 | path, std::make_unique<PowerSupply>( |
| 156 | pldm::utils::DBusHandler::getBus(), path.c_str())); |
| 157 | } |
| 158 | } |
| 159 | |
Archana Kakani | 413f51e | 2025-02-03 04:14:36 -0600 | [diff] [blame] | 160 | void CustomDBus::implementFanInterface(const std::string& path) |
| 161 | { |
| 162 | if (!fan.contains(path)) |
| 163 | { |
| 164 | fan.emplace(path, |
| 165 | std::make_unique<Fan>(pldm::utils::DBusHandler::getBus(), |
| 166 | path.c_str())); |
| 167 | } |
| 168 | } |
| 169 | |
Archana Kakani | 17b1e8a | 2025-02-04 03:50:24 -0600 | [diff] [blame] | 170 | void CustomDBus::implementConnecterInterface(const std::string& path) |
| 171 | { |
| 172 | if (!connector.contains(path)) |
| 173 | { |
| 174 | connector.emplace( |
| 175 | path, std::make_unique<Connector>( |
| 176 | pldm::utils::DBusHandler::getBus(), path.c_str())); |
| 177 | } |
| 178 | } |
| 179 | |
Archana Kakani | db65c3b | 2025-02-03 05:27:28 -0600 | [diff] [blame] | 180 | void CustomDBus::implementChassisInterface(const std::string& path) |
| 181 | { |
| 182 | if (!chassis.contains(path)) |
| 183 | { |
| 184 | chassis.emplace(path, |
| 185 | std::make_unique<ItemChassis>( |
| 186 | pldm::utils::DBusHandler::getBus(), path.c_str())); |
| 187 | } |
| 188 | } |
| 189 | |
Archana Kakani | 1634a6e | 2025-02-04 01:12:29 -0600 | [diff] [blame] | 190 | void CustomDBus::implementAssetInterface(const std::string& path) |
| 191 | { |
| 192 | if (!asset.contains(path)) |
| 193 | { |
| 194 | asset.emplace(path, std::make_unique<Asset>( |
| 195 | pldm::utils::DBusHandler::getBus(), path)); |
| 196 | } |
| 197 | } |
| 198 | |
Archana Kakani | f935537 | 2025-02-04 03:13:24 -0600 | [diff] [blame] | 199 | void CustomDBus::setAvailabilityState(const std::string& path, |
| 200 | const bool& state) |
| 201 | { |
| 202 | if (!availabilityState.contains(path)) |
| 203 | { |
| 204 | availabilityState.emplace( |
| 205 | path, std::make_unique<Availability>( |
| 206 | pldm::utils::DBusHandler::getBus(), path.c_str())); |
| 207 | } |
| 208 | |
| 209 | availabilityState.at(path)->available(state); |
| 210 | } |
| 211 | |
Archana Kakani | c366447 | 2025-02-04 05:36:37 -0600 | [diff] [blame] | 212 | void CustomDBus::updateItemPresentStatus(const std::string& path, |
| 213 | bool isPresent) |
| 214 | { |
| 215 | if (!presentStatus.contains(path)) |
| 216 | { |
| 217 | presentStatus.emplace( |
| 218 | path, std::make_unique<InventoryItem>( |
| 219 | pldm::utils::DBusHandler::getBus(), path.c_str())); |
| 220 | std::filesystem::path ObjectPath(path); |
| 221 | |
| 222 | // Hardcode the present dbus property to true |
| 223 | presentStatus.at(path)->present(true); |
| 224 | |
| 225 | // Set the pretty name dbus property to the filename |
| 226 | // form the dbus path object |
| 227 | presentStatus.at(path)->prettyName(ObjectPath.filename()); |
| 228 | } |
| 229 | else |
| 230 | { |
| 231 | // object is already created |
| 232 | presentStatus.at(path)->present(isPresent); |
| 233 | } |
| 234 | } |
| 235 | |
Archana Kakani | 765cf03 | 2025-02-04 06:24:14 -0600 | [diff] [blame] | 236 | void CustomDBus::implementPanelInterface(const std::string& path) |
| 237 | { |
| 238 | if (!panel.contains(path)) |
| 239 | { |
| 240 | panel.emplace(path, |
| 241 | std::make_unique<Panel>( |
| 242 | pldm::utils::DBusHandler::getBus(), path.c_str())); |
| 243 | } |
| 244 | } |
| 245 | |
Archana Kakani | 2832f2c | 2025-02-04 22:29:30 -0600 | [diff] [blame] | 246 | void CustomDBus::implementVRMInterface(const std::string& path) |
| 247 | { |
| 248 | if (!vrm.contains(path)) |
| 249 | { |
| 250 | vrm.emplace(path, |
| 251 | std::make_unique<VRM>(pldm::utils::DBusHandler::getBus(), |
| 252 | path.c_str())); |
| 253 | } |
| 254 | } |
| 255 | |
George Liu | 682ee18 | 2020-12-25 15:24:33 +0800 | [diff] [blame] | 256 | } // namespace dbus |
| 257 | } // namespace pldm |