pcie: Use mapper calls to lookup busnames
This is a reaction to a /org/openbmc/managers/System API update.
The update removes the bus name field from the 'GetObjectByxxx'
method responses.
Change-Id: I061f8071097b4e870031198a509abe48a4128d82
Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
diff --git a/pciedetect/pcie_slot_present_obj.c b/pciedetect/pcie_slot_present_obj.c
index a2e7fd8..852a42a 100644
--- a/pciedetect/pcie_slot_present_obj.c
+++ b/pciedetect/pcie_slot_present_obj.c
@@ -26,13 +26,52 @@
/* ------------------------------------------------------------------------- */
+void
+get_service(GDBusConnection *connection, const char *obj,
+ const char **service, GError **error)
+{
+ GDBusProxy *proxy;
+ GVariant *result = NULL;
+ GVariantIter *iter;
+
+ *error = NULL;
+ proxy = g_dbus_proxy_new_sync(connection,
+ G_DBUS_PROXY_FLAGS_NONE,
+ NULL, /* GDBusInterfaceInfo* */
+ "org.openbmc.ObjectMapper", /* name */
+ "/org/openbmc/ObjectMapper", /* object path */
+ "org.openbmc.ObjectMapper", /* interface name */
+ NULL, /* GCancellable */
+ error);
+
+ result = g_dbus_proxy_call_sync(proxy,
+ "GetObject",
+ g_variant_new("(s)", obj),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ error);
+ if(*error)
+ goto exit;
+
+ g_variant_get(result, "(a{sas})", &iter);
+ g_variant_iter_next(iter, "{sas}", service, NULL);
+
+exit:
+ if(result)
+ g_variant_unref(result);
+}
+
int
-get_object(GDBusProxy *proxy, GPIO* gpio, object_info* obj_info)
+get_object(GDBusConnection *connection, GDBusProxy *proxy,
+ GPIO* gpio, object_info* obj_info)
{
g_print("Checking Presence: %s\n",gpio->name);
+ const char *gpio_bus = NULL;
GError *error;
GVariant *parm;
GVariant *result;
+ int rc=0;
error = NULL;
parm = g_variant_new("(ss)","GPIO_PRESENT",gpio->name);
@@ -44,13 +83,22 @@
NULL,
&error);
g_assert_no_error(error);
+ if(error)
+ goto exit;
GVariantIter *iter = g_variant_iter_new(result);
GVariant* v_result = g_variant_iter_next_value(iter);
- g_variant_get(v_result,"(sss)",&obj_info->bus_name,&obj_info->path,&obj_info->intf_name);
- int rc=0;
- if(strlen(obj_info->bus_name) == 0) {
+ g_variant_get(v_result,"(ss)",&obj_info->path,&obj_info->intf_name);
+
+ get_service(connection, obj_info->path, &gpio_bus, &error);
+ if(error)
+ goto exit;
+
+ obj_info->bus_name = gpio_bus;
+
+exit:
+ if(!gpio_bus || strlen(gpio_bus) == 0) {
rc = 1;
}
g_variant_unref(v_result);
@@ -116,6 +164,8 @@
gint
main(gint argc, gchar *argv[])
{
+ const char *sysmgr_path = "/org/openbmc/managers/System";
+ const char *sysmgr_bus = NULL;
GMainLoop *loop;
GDBusConnection *c;
GDBusProxy *sys_proxy;
@@ -125,17 +175,24 @@
error = NULL;
c = g_bus_get_sync(DBUS_TYPE, NULL, &error);
+ if(error)
+ goto exit;
- error = NULL;
+ get_service(c, sysmgr_path, &sysmgr_bus, &error);
+ if(error)
+ goto exit;
+
sys_proxy = g_dbus_proxy_new_sync(c,
G_DBUS_PROXY_FLAGS_NONE,
NULL, /* GDBusInterfaceInfo* */
- "org.openbmc.managers.System", /* name */
- "/org/openbmc/managers/System", /* object path */
+ sysmgr_bus, /* name */
+ sysmgr_path, /* object path */
"org.openbmc.managers.System", /* interface name */
NULL, /* GCancellable */
&error);
g_assert_no_error(error);
+ if(error)
+ goto exit;
int i = 0;
int rc = 0;
@@ -144,7 +201,7 @@
object_info obj_info;
uint8_t present;
do {
- rc = get_object(sys_proxy,&slots[i],&obj_info);
+ rc = get_object(c,sys_proxy,&slots[i],&obj_info);
if(rc) { break; }
rc = get_presence(c,&slots[i],&present);
//if (rc) { break; }
@@ -157,6 +214,9 @@
} while(0);
}
+exit:
+ if(sysmgr_bus)
+ g_free((char *)sysmgr_bus);
g_object_unref(c);
g_main_loop_unref(loop);
return 0;