summaryrefslogtreecommitdiffstats
path: root/chassishandler.cpp
diff options
context:
space:
mode:
authorSergey Solomin <sergey.solomin@us.ibm.com>2016-08-23 09:07:28 -0500
committerSergey Solomin <sergey.solomin@us.ibm.com>2016-08-25 13:37:57 -0500
commiteb9b814403895d6435e04f02a9ff6c2b1b02cf54 (patch)
tree4a1713845844f874799a1b188db209adeaa3e085 /chassishandler.cpp
parentbc40c178bb0b345ed1edf553b94369330003af34 (diff)
downloadphosphor-host-ipmid-eb9b814403895d6435e04f02a9ff6c2b1b02cf54.tar.gz
phosphor-host-ipmid-eb9b814403895d6435e04f02a9ff6c2b1b02cf54.zip
Hard-coded service name replaced with call to ObjectMapper
In the openbmc code, the dbus service name is hardcoded. The ObjectMapper provides a way to find out the service name by issuing a GetObject method call to the ObjectMapper. That functionality is implemented in mapper.c The output of the call to the mapper is a service name. Resolves openbmc/openbmc#319. Change-Id: I724a31ede6bdf3ae4b361e730857b1f2696a8966 Signed-off-by: Sergey Solomin <sergey.solomin@us.ibm.com>
Diffstat (limited to 'chassishandler.cpp')
-rw-r--r--chassishandler.cpp22
1 files changed, 14 insertions, 8 deletions
diff --git a/chassishandler.cpp b/chassishandler.cpp
index ded9157..92d9752 100644
--- a/chassishandler.cpp
+++ b/chassishandler.cpp
@@ -15,7 +15,6 @@
// OpenBMC Chassis Manager dbus framework
-const char *chassis_bus_name = "org.openbmc.control.Chassis";
const char *chassis_object_name = "/org/openbmc/control/chassis0";
const char *chassis_intf_name = "org.openbmc.control.Chassis";
@@ -42,7 +41,7 @@ int dbus_get_property(const char *name, char **buf)
r = mapper_get_service(bus, settings_object_name, &connection);
if (r < 0) {
- fprintf(stderr, "Failed to get connection, return value: %d.\n", r);
+ fprintf(stderr, "Failed to get connection, return value: %s.\n", strerror(-r));
goto finish;
}
@@ -107,7 +106,7 @@ int dbus_set_property(const char * name, const char *value)
r = mapper_get_service(bus, settings_object_name, &connection);
if (r < 0) {
- fprintf(stderr, "Failed to get connection, return value: %d.\n", r);
+ fprintf(stderr, "Failed to get connection, return value: %s.\n", strerror(-r));
goto finish;
}
@@ -180,9 +179,10 @@ int ipmi_chassis_power_control(const char *method)
{
// sd_bus error
int rc = 0;
+ char *busname = NULL;
- // SD Bus error report mechanism.
- sd_bus_error bus_error = SD_BUS_ERROR_NULL;
+ // SD Bus error report mechanism.
+ sd_bus_error bus_error = SD_BUS_ERROR_NULL;
// Response from the call. Although there is no response for this call,
// obligated to mention this to make compiler happy.
@@ -190,9 +190,13 @@ int ipmi_chassis_power_control(const char *method)
// Gets a hook onto either a SYSTEM or SESSION bus
sd_bus *bus_type = ipmid_get_sd_bus_connection();
-
+ rc = mapper_get_service(bus_type, chassis_object_name, &busname);
+ if (rc < 0) {
+ fprintf(stderr, "Failed to get bus name, return value: %s.\n", strerror(-rc));
+ goto finish;
+ }
rc = sd_bus_call_method(bus_type, // On the System Bus
- chassis_bus_name, // Service to contact
+ busname, // Service to contact
chassis_object_name, // Object path
chassis_intf_name, // Interface name
method, // Method to be called
@@ -208,10 +212,12 @@ int ipmi_chassis_power_control(const char *method)
printf("Chassis Power Off initiated successfully\n");
}
+finish:
sd_bus_error_free(&bus_error);
sd_bus_message_unref(response);
+ free(busname);
- return rc;
+ return rc;
}
OpenPOWER on IntegriCloud