获取远端蓝牙的所有属性
result = g_dbus_connection_call_sync( conn, "org.bluez", /org/bluez/hci0/dev_A4_C1_38_10_09_2C, "org.freedesktop.DBus.Properties", "GetAll", g_variant_new("(s)", "org.bluez.Device1"), G_VARIANT_TYPE("(a{sv})"), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error ); if(error != NULL) { printf("error get property: %s\n", error->message); g_error_free(error); return 1; } GVariantIter *prop_iter; gchar *prop_name; GVariant *prop_value; // 遍历所有属性 g_variant_get(result, "(a{sv})", &prop_iter); while (g_variant_iter_next(prop_iter, "{sv}", &prop_name, &prop_value)) { gchar *value_str = g_variant_print(prop_value, TRUE); g_print(" %s: %s\n", prop_name, value_str); g_free(value_str); g_variant_unref(prop_value); g_free(prop_name); } g_variant_iter_free(prop_iter); g_variant_unref(result);
标签:glib,variant,value,prop,---,iter,error,free,bluz From: https://www.cnblogs.com/god-of-death/p/18304753