host-bmc: Implement Asset interface

Adding support to host Asset dbus interface.  Based on the Topology data
received from remote PLDM terminus, PLDM hosts the dbus interface.  The
Asset interface is defined at [1].

Tested:
   Functional test passed

[1]: https://github.com/openbmc/phosphor-dbus-interfaces/blob/master/yaml/xyz/openbmc_project/Inventory/Decorator/Asset.interface.yaml

Change-Id: Ia32e69861192fca6db8c1613fbec281ca3faa3e8
Signed-off-by: Archana Kakani <archana.kakani@ibm.com>
diff --git a/host-bmc/dbus/asset.cpp b/host-bmc/dbus/asset.cpp
new file mode 100644
index 0000000..0bf18d3
--- /dev/null
+++ b/host-bmc/dbus/asset.cpp
@@ -0,0 +1,15 @@
+#include "asset.hpp"
+
+namespace pldm
+{
+namespace dbus
+{
+
+std::string Asset::partNumber(std::string value)
+{
+    return sdbusplus::xyz::openbmc_project::Inventory::Decorator::server::
+        Asset::partNumber(value);
+}
+
+} // namespace dbus
+} // namespace pldm
diff --git a/host-bmc/dbus/asset.hpp b/host-bmc/dbus/asset.hpp
new file mode 100644
index 0000000..e1188d7
--- /dev/null
+++ b/host-bmc/dbus/asset.hpp
@@ -0,0 +1,41 @@
+#pragma once
+
+#include <sdbusplus/bus.hpp>
+#include <sdbusplus/server.hpp>
+#include <sdbusplus/server/object.hpp>
+#include <xyz/openbmc_project/Inventory/Decorator/Asset/server.hpp>
+
+#include <string>
+
+namespace pldm
+{
+namespace dbus
+{
+
+using ItemAsset = sdbusplus::server::object_t<
+    sdbusplus::xyz::openbmc_project::Inventory::Decorator::server::Asset>;
+
+class Asset : public ItemAsset
+{
+  public:
+    Asset() = delete;
+    ~Asset() = default;
+    Asset(const Asset&) = delete;
+    Asset& operator=(const Asset&) = delete;
+    Asset(Asset&&) = delete;
+    Asset& operator=(Asset&&) = delete;
+
+    Asset(sdbusplus::bus_t& bus, const std::string& objPath) :
+        ItemAsset(bus, objPath.c_str()), path(objPath)
+    {
+        // no need to save this in pldm memory
+    }
+
+    std::string partNumber(std::string value) override;
+
+  private:
+    std::string path;
+};
+
+} // namespace dbus
+} // namespace pldm
diff --git a/host-bmc/dbus/custom_dbus.cpp b/host-bmc/dbus/custom_dbus.cpp
index 16b822a..f5dd592 100644
--- a/host-bmc/dbus/custom_dbus.cpp
+++ b/host-bmc/dbus/custom_dbus.cpp
@@ -157,5 +157,14 @@
     }
 }
 
+void CustomDBus::implementAssetInterface(const std::string& path)
+{
+    if (!asset.contains(path))
+    {
+        asset.emplace(path, std::make_unique<Asset>(
+                                pldm::utils::DBusHandler::getBus(), path));
+    }
+}
+
 } // namespace dbus
 } // namespace pldm
diff --git a/host-bmc/dbus/custom_dbus.hpp b/host-bmc/dbus/custom_dbus.hpp
index 80ffda9..7988bd9 100644
--- a/host-bmc/dbus/custom_dbus.hpp
+++ b/host-bmc/dbus/custom_dbus.hpp
@@ -1,5 +1,6 @@
 #pragma once
 
+#include "asset.hpp"
 #include "cable.hpp"
 #include "chassis.hpp"
 #include "common/utils.hpp"
@@ -157,7 +158,15 @@
      */
     void implementPowerSupplyInterface(const std::string& path);
 
+    /** @brief Implement Asset Interface
+     *
+     *  @param[in] path - The object path
+     *
+     */
+    void implementAssetInterface(const std::string& path);
+
   private:
+    std::unordered_map<ObjectPath, std::unique_ptr<Asset>> asset;
     std::unordered_map<ObjectPath, std::unique_ptr<LocationIntf>> location;
     std::unordered_map<ObjectPath, std::unique_ptr<CPUCore>> cpuCore;
     std::unordered_map<ObjectPath, std::unique_ptr<ItemChassis>> chassis;