SensorReading: Move set SensorReading to new API.

Rewrite "set SensorReading" command to use the newly introduced
IPMI provider API.

Tested:
Verified using ipmitool "set SensorReading", behavior is same before
and after the changes.

Signed-off-by: Deepak Kumar Sahu <deepakx.sahu@intel.com>
Change-Id: I9ee4276775e7c4a348c32a746e7fd7d55a943e06
diff --git a/sensorhandler.cpp b/sensorhandler.cpp
index b321e96..5a5870a 100644
--- a/sensorhandler.cpp
+++ b/sensorhandler.cpp
@@ -329,16 +329,54 @@
     return (analogSensorInterfaces.count(interface));
 }
 
-ipmi_ret_t setSensorReading(void* request)
+/**
+@brief This command is used to set sensorReading.
+
+@param
+    -  sensorNumber
+    -  operation
+    -  reading
+    -  assertOffset0_7
+    -  assertOffset8_14
+    -  deassertOffset0_7
+    -  deassertOffset8_14
+    -  eventData1
+    -  eventData2
+    -  eventData3
+
+@return completion code on success.
+**/
+
+ipmi::RspType<> ipmiSetSensorReading(uint8_t sensorNumber, uint8_t operation,
+                                     uint8_t reading, uint8_t assertOffset0_7,
+                                     uint8_t assertOffset8_14,
+                                     uint8_t deassertOffset0_7,
+                                     uint8_t deassertOffset8_14,
+                                     uint8_t eventData1, uint8_t eventData2,
+                                     uint8_t eventData3)
 {
-    ipmi::sensor::SetSensorReadingReq cmdData =
-        *(static_cast<ipmi::sensor::SetSensorReadingReq*>(request));
+    log<level::DEBUG>("IPMI SET_SENSOR",
+                      entry("SENSOR_NUM=0x%02x", sensorNumber));
+
+    ipmi::sensor::SetSensorReadingReq cmdData;
+
+    cmdData.number = sensorNumber;
+    cmdData.operation = operation;
+    cmdData.reading = reading;
+    cmdData.assertOffset0_7 = assertOffset0_7;
+    cmdData.assertOffset8_14 = assertOffset8_14;
+    cmdData.deassertOffset0_7 = deassertOffset0_7;
+    cmdData.deassertOffset8_14 = deassertOffset8_14;
+    cmdData.eventData1 = eventData1;
+    cmdData.eventData2 = eventData2;
+    cmdData.eventData3 = eventData3;
 
     // Check if the Sensor Number is present
-    const auto iter = sensors.find(cmdData.number);
+    const auto iter = sensors.find(sensorNumber);
     if (iter == sensors.end())
     {
-        return IPMI_CC_SENSOR_INVALID;
+        updateSensorRecordFromSSRAESC(&sensorNumber);
+        return ipmi::responseSuccess();
     }
 
     try
@@ -347,49 +385,24 @@
             (iter->second.mutability & ipmi::sensor::Mutability::Write))
         {
             log<level::ERR>("Sensor Set operation is not allowed",
-                            entry("SENSOR_NUM=%d", cmdData.number));
-            return IPMI_CC_ILLEGAL_COMMAND;
+                            entry("SENSOR_NUM=%d", sensorNumber));
+            return ipmi::responseIllegalCommand();
         }
-        return iter->second.updateFunc(cmdData, iter->second);
+        auto ipmiRC = iter->second.updateFunc(cmdData, iter->second);
+        return ipmi::response(ipmiRC);
     }
     catch (InternalFailure& e)
     {
         log<level::ERR>("Set sensor failed",
-                        entry("SENSOR_NUM=%d", cmdData.number));
+                        entry("SENSOR_NUM=%d", sensorNumber));
         commit<InternalFailure>();
+        return ipmi::responseUnspecifiedError();
     }
     catch (const std::runtime_error& e)
     {
         log<level::ERR>(e.what());
+        return ipmi::responseUnspecifiedError();
     }
-
-    return IPMI_CC_UNSPECIFIED_ERROR;
-}
-
-ipmi_ret_t ipmi_sen_set_sensor(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
-                               ipmi_request_t request, ipmi_response_t response,
-                               ipmi_data_len_t data_len, ipmi_context_t context)
-{
-    auto reqptr = static_cast<sensor_data_t*>(request);
-
-    log<level::DEBUG>("IPMI SET_SENSOR",
-                      entry("SENSOR_NUM=0x%02x", reqptr->sennum));
-
-    /*
-     * This would support the Set Sensor Reading command for the presence
-     * and functional state of Processor, Core & DIMM. For the remaining
-     * sensors the existing support is invoked.
-     */
-    auto ipmiRC = setSensorReading(request);
-
-    if (ipmiRC == IPMI_CC_SENSOR_INVALID)
-    {
-        updateSensorRecordFromSSRAESC(reqptr);
-        ipmiRC = IPMI_CC_OK;
-    }
-
-    *data_len = 0;
-    return ipmiRC;
 }
 
 ipmi_ret_t ipmi_sen_get_sensor_reading(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
@@ -1066,9 +1079,9 @@
                            ipmi_sen_get_sensor_type, PRIVILEGE_USER);
 
     // <Set Sensor Reading and Event Status>
-    ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_SET_SENSOR, nullptr,
-                           ipmi_sen_set_sensor, PRIVILEGE_OPERATOR);
-
+    ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnSensor,
+                          ipmi::sensor_event::cmdSetSensorReadingAndEvtSts,
+                          ipmi::Privilege::Operator, ipmiSetSensorReading);
     // <Get Sensor Reading>
     ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_GET_SENSOR_READING, nullptr,
                            ipmi_sen_get_sensor_reading, PRIVILEGE_USER);