summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEmily Shaffer <emilyshaffer@google.com>2017-04-03 10:27:08 -0700
committerEmily Shaffer <emilyshaffer@google.com>2017-05-19 21:22:12 +0000
commit391f33039f7bc22e61fbcd2ebada31a6cb4a8ec6 (patch)
treed87ae6c171df80d768ebb99c0836d9971b89fb2e
parentd5899e7e0c1bfc0b69a9f5bc69267642ad6c038c (diff)
downloadphosphor-host-ipmid-391f33039f7bc22e61fbcd2ebada31a6cb4a8ec6.tar.gz
phosphor-host-ipmid-391f33039f7bc22e61fbcd2ebada31a6cb4a8ec6.zip
sensorhandler: Refactor find_sensor to eliminate redundant call
find_openbmc_path was being called within find_sensor as well as following find_sensor Change-Id: Ie94eab7afbe34f214a07bda49bfbce729b20f237 Signed-off-by: Emily Shaffer <emilyshaffer@google.com>
-rw-r--r--ipmisensor.cpp4
-rw-r--r--sensorhandler.cpp33
-rw-r--r--testit.cpp4
3 files changed, 23 insertions, 18 deletions
diff --git a/ipmisensor.cpp b/ipmisensor.cpp
index f39832f..10a0ec6 100644
--- a/ipmisensor.cpp
+++ b/ipmisensor.cpp
@@ -4,7 +4,7 @@
#include <malloc.h>
#include "sensorhandler.h"
-extern uint8_t find_sensor(uint8_t);
+extern uint8_t find_type_for_sensor_number(uint8_t);
struct sensorRES_t {
@@ -261,7 +261,7 @@ int updateSensorRecordFromSSRAESC(const void *record) {
uint8_t stype;
int index, i=0;
- stype = find_sensor(pRec->sensor_number);
+ stype = find_type_for_sensor_number(pRec->sensor_number);
// 0xC3 types use the assertion7_0 for the value to be set
// so skip the reseach and call the correct event reporting
diff --git a/sensorhandler.cpp b/sensorhandler.cpp
index 892511a..69f1911 100644
--- a/sensorhandler.cpp
+++ b/sensorhandler.cpp
@@ -290,36 +290,41 @@ uint8_t dbus_to_sensor_type_from_dbus(dbus_interface_t *a) {
}
}
+uint8_t get_type_from_interface(dbus_interface_t dbus_if) {
-uint8_t find_sensor(uint8_t sensor_number) {
-
- dbus_interface_t a;
char *p;
- int r;
uint8_t type;
- r = find_openbmc_path("SENSOR", sensor_number, &a);
-
- if (r < 0) { return 0; }
-
// This is where sensors that do not exist in dbus but do
// exist in the host code stop. This should indicate it
// is not a supported sensor
- if (a.interface[0] == 0) { return 0;}
+ if (dbus_if.interface[0] == 0) { return 0;}
- if (strstr(a.interface, "InventoryItem")) {
+ if (strstr(dbus_if.interface, "InventoryItem")) {
// InventoryItems are real frus. So need to get the
// fru_type property
- type = dbus_to_sensor_type_from_dbus(&a);
+ type = dbus_to_sensor_type_from_dbus(&dbus_if);
} else {
// Non InventoryItems
- p = strrchr (a.path, '/');
+ p = strrchr (dbus_if.path, '/');
type = dbus_to_sensor_type(p+1);
}
return type;
}
+// Replaces find_sensor
+uint8_t find_type_for_sensor_number(uint8_t num) {
+ int r;
+ dbus_interface_t dbus_if;
+ r = find_openbmc_path("SENSOR", num, &dbus_if);
+ if (r < 0) {
+ fprintf(stderr, "Could not find sensor %d\n", num);
+ return r;
+ }
+ return get_type_from_interface(dbus_if);
+}
+
@@ -337,7 +342,7 @@ ipmi_ret_t ipmi_sen_get_sensor_type(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
// need to ask Hostboot team
unsigned char buf[] = {0x00,0x6F};
- buf[0] = find_sensor(reqptr->sennum);
+ buf[0] = find_type_for_sensor_number(reqptr->sennum);
// HACK UNTIL Dbus gets updated or we find a better way
if (buf[0] == 0) {
@@ -492,7 +497,7 @@ ipmi_ret_t ipmi_sen_get_sensor_reading(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
return IPMI_CC_SENSOR_INVALID;
}
- type = find_sensor(reqptr->sennum);
+ type = get_type_from_interface(a);
if(type == 0) {
fprintf(stderr, "Failed to find Sensor 0x%02x\n", reqptr->sennum);
return IPMI_CC_SENSOR_INVALID;
diff --git a/testit.cpp b/testit.cpp
index a0cd2c1..072b5d7 100644
--- a/testit.cpp
+++ b/testit.cpp
@@ -12,7 +12,7 @@ unsigned char g_sensortype [][2] = {
{0xFF ,0xff}
};
-uint8_t find_sensor(uint8_t sensor_number) {
+uint8_t find_type_for_sensor_number(uint8_t sensor_number) {
int i=0;
uint8_t rc;
@@ -117,4 +117,4 @@ int main() {
testprep(); check_results(updateSensorRecordFromSSRAESC(testrec_invalidnumber), "", "");
return 0;
-} \ No newline at end of file
+}
OpenPOWER on IntegriCloud