platform-mc: Add pldm entity inventory path

This commit exposes inventory path of each sensor to under the
entity's inventory path that it belongs to. In each path, the
xyz.openbmc_project.Inventory.Source.PLDM.Entity interface is
implemented with ContainerID, EntityInstanceNumber and EntityType
properties.

Signed-off-by: Chau Ly <chaul@amperecomputing.com>
Change-Id: Icf10349b7d272c6b050259151d71f21efedb0162
diff --git a/platform-mc/numeric_sensor.cpp b/platform-mc/numeric_sensor.cpp
index 25d420d..ab59154 100644
--- a/platform-mc/numeric_sensor.cpp
+++ b/platform-mc/numeric_sensor.cpp
@@ -15,6 +15,31 @@
 namespace platform_mc
 {
 
+inline bool NumericSensor::createInventoryPath(
+    const std::string& associationPath, const std::string& sensorName,
+    const uint16_t entityType, const uint16_t entityInstanceNum,
+    const uint16_t containerId)
+{
+    auto& bus = pldm::utils::DBusHandler::getBus();
+    std::string invPath = associationPath + "/" + sensorName;
+    try
+    {
+        entityIntf = std::make_unique<EntityIntf>(bus, invPath.c_str());
+    }
+    catch (const sdbusplus::exception_t& e)
+    {
+        lg2::error(
+            "Failed to create Entity interface for compact numeric sensor {PATH} error - {ERROR}",
+            "PATH", invPath, "ERROR", e);
+        return false;
+    }
+    entityIntf->entityType(entityType);
+    entityIntf->entityInstanceNumber(entityInstanceNum);
+    entityIntf->containerID(containerId);
+
+    return true;
+}
+
 NumericSensor::NumericSensor(
     const pldm_tid_t tid, const bool sensorDisabled,
     std::shared_ptr<pldm_numeric_sensor_value_pdr> pdr, std::string& sensorName,
@@ -333,6 +358,12 @@
 
     hysteresis = unitModifier(conversionFormula(hysteresis));
 
+    if (!createInventoryPath(associationPath, sensorName, pdr->entity_type,
+                             pdr->entity_instance_num, pdr->container_id))
+    {
+        throw sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument();
+    }
+
     try
     {
         availabilityIntf =
@@ -587,6 +618,12 @@
 
     hysteresis = unitModifier(conversionFormula(hysteresis));
 
+    if (!createInventoryPath(associationPath, sensorName, pdr->entity_type,
+                             pdr->entity_instance, pdr->container_id))
+    {
+        throw sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument();
+    }
+
     try
     {
         availabilityIntf =