sensor: Populate entity id, instance and sensor name callback

Change-Id: Ie7bf403ae15d9b1a70216aab0c57362c3d4240e7
Signed-off-by: Tom Joseph <tomjoseph@in.ibm.com>
diff --git a/scripts/sensor-example.yaml b/scripts/sensor-example.yaml
index c4ff4d5..db0e694 100755
--- a/scripts/sensor-example.yaml
+++ b/scripts/sensor-example.yaml
@@ -11,6 +11,8 @@
   serviceInterface: org.freedesktop.DBus.Properties
   # Where the sensor value is represented - assertion bits/reading/event data
   readingType: assertion
+  # Sensor name would be occ0
+  sensorNamePattern: nameLeaf
   eventType: 0x6F
   # All the d-bus interfaces : properties that must be updated for this path
   interfaces:
@@ -35,6 +37,7 @@
   path: /system/chassis/motherboard/dimm1
   serviceInterface: xyz.openbmc_project.Inventory.Manager
   readingType: assertion
+  sensorNamePattern: nameLeaf
   interfaces:
     xyz.openbmc_project.State.Decorator.OperationalStatus:
       Functional:
@@ -70,6 +73,8 @@
   # serves as the value, or reading. Hence, the offset above is intentionally
   # 0xFF, to indicate not to check any specific bits in the assertion.
   readingType: readingAssertion
+  # Sensor name would be AttemptsLeft
+  sensorNamePattern: nameProperty
   sensorReadingType: 0x6F
   sensorType: 0xC3
   serviceInterface: org.freedesktop.DBus.Properties
@@ -83,6 +88,7 @@
             type: uint32_t
   path: /xyz/openbmc_project/state/host1
   readingType: readingAssertion
+  sensorNamePattern: nameProperty
   sensorReadingType: 0x6F
   sensorType: 0xC3
   serviceInterface: org.freedesktop.DBus.Properties
@@ -97,6 +103,7 @@
   mutability: Mutability::Write|Mutability::Read
   serviceInterface: org.freedesktop.DBus.Properties
   readingType: readingData
+  sensorNamePattern: nameLeaf
   interfaces:
     xyz.openbmc_project.Sensor.Value:
       Value:
@@ -110,6 +117,8 @@
   sensorReadingType: 0x6F
   serviceInterface: xyz.openbmc_project.Inventory.Manager
   readingType: assertion
+  # Sensor name would be cpu0_core22
+  sensorNamePattern: nameParentLeaf
   interfaces:
     xyz.openbmc_project.State.Decorator.OperationalStatus:
       Functional:
diff --git a/scripts/writesensor.mako.cpp b/scripts/writesensor.mako.cpp
index e081474..4644ff7 100644
--- a/scripts/writesensor.mako.cpp
+++ b/scripts/writesensor.mako.cpp
@@ -39,6 +39,8 @@
        path = sensor["path"]
        serviceInterface = sensor["serviceInterface"]
        sensorType = sensor["sensorType"]
+       entityID = sensor.get("entityID", 0)
+       instance = sensor.get("entityInstance", 0)
        readingType = sensor["sensorReadingType"]
        multiplier = sensor.get("multiplierM", 1)
        offsetB = sensor.get("offsetB", 0)
@@ -47,6 +49,8 @@
        scale = sensor.get("scale", 0)
        hasScale = "true" if "scale" in sensor.keys() else "false"
        valueReadingType = sensor["readingType"]
+       sensorNamePattern = sensor.get("sensorNamePattern", "nameLeaf")
+       sensorNameFunc = "get::" + sensorNamePattern
        updateFunc = interfaceDict[serviceInterface]["updateFunc"]
        updateFunc += sensor["readingType"]
        getFunc = interfaceDict[serviceInterface]["getFunc"]
@@ -63,10 +67,10 @@
            sensorInterface = next(iter(interfaces))
        mutability = sensor.get("mutability", "Mutability::Read")
 %>
-        ${sensorType},"${path}","${sensorInterface}",${readingType},${multiplier},
-        ${offsetB},${exp},${offsetB * pow(10,exp)},
-        ${hasScale},${scale},"${unit}",
-        ${updateFunc},${getFunc},Mutability(${mutability}),{
+        ${entityID},${instance},${sensorType},"${path}","${sensorInterface}",
+        ${readingType},${multiplier}, ${offsetB},${exp},
+        ${offsetB * pow(10,exp)}, ${hasScale},${scale},"${unit}",
+        ${updateFunc},${getFunc},Mutability(${mutability}),${sensorNameFunc},{
     % for interface,properties in interfaces.items():
             {"${interface}",{
             % for dbus_property,property_value in properties.items():
diff --git a/types.hpp b/types.hpp
index 2580063..260deb5 100644
--- a/types.hpp
+++ b/types.hpp
@@ -139,6 +139,8 @@
 
 struct Info
 {
+   EntityType entityType;
+   EntityInst instance;
    Type sensorType;
    InstancePath sensorPath;
    DbusInterface sensorInterface;
@@ -153,6 +155,7 @@
    std::function<uint8_t(SetSensorReadingReq&, const Info&)> updateFunc;
    std::function<GetSensorResponse(const Info&)> getFunc;
    Mutability mutability;
+   std::function<SensorName(const Info&)> sensorNameFunc;
    DbusInterfaceMap propertyInterfaces;
 };