Add LocationContext support to NsmChassis

LocationConext config support is added to NsmChassis.

Fixes nvbug https://nvbugspro.nvidia.com/bug/5793515

Signed-off-by: Karthick Sundarrajan <ksundarrajan@nvidia.com>


(cherry picked from commit 14fa6cfeceb4a329f047c0225708fb41daf73654)

Co-authored-by: Karthick Sundarrajan <ksundarrajan@nvidia.com>
diff --git a/nsmd/nsmChassis/nsmChassis.cpp b/nsmd/nsmChassis/nsmChassis.cpp
index 05864a1..97306de 100644
--- a/nsmd/nsmChassis/nsmChassis.cpp
+++ b/nsmd/nsmChassis/nsmChassis.cpp
@@ -164,6 +164,24 @@
     device->addStaticSensor(chassisLocationCode);
 }
 
+static void
+    createLocationContext(std::shared_ptr<NsmDevice> device,
+                          const std::string& name,
+                          const dbus::PropertyMap& allCurrentIfaceProperties)
+{
+    std::string locationContext;
+    if (allCurrentIfaceProperties.count("LocationContext"))
+    {
+        locationContext = std::get<std::string>(
+            allCurrentIfaceProperties.at("LocationContext"));
+    }
+
+    auto chassisLocationContext =
+        std::make_shared<NsmChassis<LocationContextIntf>>(name);
+    chassisLocationContext->invoke(pdiMethod(locationContext), locationContext);
+    device->addStaticSensor(chassisLocationContext);
+}
+
 static void createPowerLimit(std::shared_ptr<NsmDevice> device,
                              const std::string& name,
                              const dbus::PropertyMap& allCurrentIfaceProperties)
@@ -315,6 +333,10 @@
     {
         createLocationCode(device, name, allCurrentIfaceProperties);
     }
+    if (allCurrentIfaceProperties.count("LocationContext"))
+    {
+        createLocationContext(device, name, allCurrentIfaceProperties);
+    }
     if (allCurrentIfaceProperties.count("ChassisType"))
     {
         createChassisType(device, name, allCurrentIfaceProperties);
diff --git a/nsmd/nsmChassis/nsmChassis.hpp b/nsmd/nsmChassis/nsmChassis.hpp
index 5a148fa..363b9a5 100644
--- a/nsmd/nsmChassis/nsmChassis.hpp
+++ b/nsmd/nsmChassis/nsmChassis.hpp
@@ -30,6 +30,7 @@
 #include <xyz/openbmc_project/Inventory/Decorator/Dimension/server.hpp>
 #include <xyz/openbmc_project/Inventory/Decorator/Location/server.hpp>
 #include <xyz/openbmc_project/Inventory/Decorator/LocationCode/server.hpp>
+#include <xyz/openbmc_project/Inventory/Decorator/LocationContext/server.hpp>
 #include <xyz/openbmc_project/Inventory/Decorator/PCIeRefClock/server.hpp>
 #include <xyz/openbmc_project/Inventory/Decorator/PowerLimit/server.hpp>
 #include <xyz/openbmc_project/Inventory/Item/Chassis/server.hpp>
@@ -49,6 +50,8 @@
 using DimensionIntf = object_t<Inventory::Decorator::server::Dimension>;
 using LocationIntf = object_t<Inventory::Decorator::server::Location>;
 using LocationCodeIntf = object_t<Inventory::Decorator::server::LocationCode>;
+using LocationContextIntf =
+    object_t<Inventory::Decorator::server::LocationContext>;
 using MctpUuidIntf = object_t<MCTP::server::UUID>;
 using PowerLimitIntf = object_t<Inventory::Decorator::server::PowerLimit>;
 using PCIeRefClockIntf = object_t<Inventory::Decorator::server::PCIeRefClock>;