summaryrefslogtreecommitdiffstats
path: root/sensorhandler.cpp
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 /sensorhandler.cpp
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>
Diffstat (limited to 'sensorhandler.cpp')
-rw-r--r--sensorhandler.cpp33
1 files changed, 19 insertions, 14 deletions
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;
OpenPOWER on IntegriCloud