Handle FRU records from host
- Get FRU record table from host and traverse the entity structure
from the FRU record set PDR, and create D-Bus object.
- When the FRU field type is a PLDM_OEM_FRU_FIELD_TYPE_LOCATION_CODE
, the location code is used to populate the
xyz.openbmc_project.Inventory.Decorator.LocationCode D-Bus
interface for the corresponding FRU.
Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: I482c4d371f76b4881109ef420dfd9543e1aa810b
diff --git a/host-bmc/custom_dbus.hpp b/host-bmc/custom_dbus.hpp
new file mode 100644
index 0000000..6ff7daa
--- /dev/null
+++ b/host-bmc/custom_dbus.hpp
@@ -0,0 +1,68 @@
+#pragma once
+
+#include "common/utils.hpp"
+
+#include <sdbusplus/server.hpp>
+#include <xyz/openbmc_project/Inventory/Decorator/LocationCode/server.hpp>
+
+#include <memory>
+#include <optional>
+#include <string>
+#include <unordered_map>
+
+namespace pldm
+{
+namespace dbus
+{
+using ObjectPath = std::string;
+
+using LocationIntf = sdbusplus::server::object::object<
+ sdbusplus::xyz::openbmc_project::Inventory::Decorator::server::
+ LocationCode>;
+
+/** @class CustomDBus
+ * @brief This is a custom D-Bus object, used to add D-Bus interface and update
+ * the corresponding properties value.
+ */
+class CustomDBus
+{
+ private:
+ CustomDBus() {}
+
+ public:
+ CustomDBus(const CustomDBus&) = delete;
+ CustomDBus(CustomDBus&&) = delete;
+ CustomDBus& operator=(const CustomDBus&) = delete;
+ CustomDBus& operator=(CustomDBus&&) = delete;
+ ~CustomDBus() = default;
+
+ static CustomDBus& getCustomDBus()
+ {
+ static CustomDBus customDBus;
+ return customDBus;
+ }
+
+ public:
+ /** @brief Set the LocationCode property
+ *
+ * @param[in] path - The object path
+ *
+ * @param[in] value - The value of the LocationCode property
+ */
+ void setLocationCode(const std::string& path, std::string value);
+
+ /** @brief Get the LocationCode property
+ *
+ * @param[in] path - The object path
+ *
+ * @return std::optional<std::string> - The value of the LocationCode
+ * property
+ */
+ std::optional<std::string> getLocationCode(const std::string& path) const;
+
+ private:
+ std::unordered_map<ObjectPath, std::unique_ptr<LocationIntf>> location;
+};
+
+} // namespace dbus
+} // namespace pldm