return BLUETOOTH_ERROR_NONE;
}
-static char *__bt_extract_device_path(GVariantIter *iter, char *address)
-{
- char *object_path = NULL;
- char device_address[BT_ADDRESS_STRING_SIZE] = { 0 };
-
- /* Parse the signature: oa{sa{sv}}} */
- while (g_variant_iter_loop(iter, "{&oa{sa{sv}}}", &object_path,
- NULL)) {
- if (!object_path) {
- BT_ERR("Unable to get object path");
- return NULL;
- }
- _bt_convert_device_path_to_address(object_path, device_address);
- if (g_strcmp0(address, device_address) == 0)
- return g_strdup(object_path);
-
- }
-
- BT_ERR("Unable to get object path");
- return NULL;
-}
-
char *_bt_get_device_object_path(char *address)
{
char *object_path = NULL;
- GDBusConnection *conn;
- GDBusProxy *manager_proxy;
GVariant *result = NULL;
- GVariantIter *iter = NULL;
-
- conn = _bt_gdbus_get_system_gconn();
- retv_if(conn == NULL, NULL);
+ GDBusProxy *proxy;
+ GError *error = NULL;
- manager_proxy = _bt_get_manager_proxy();
- retv_if(manager_proxy == NULL, NULL);
+ proxy = _bt_get_adapter_proxy();
+ retv_if(proxy == NULL, NULL);
- result = g_dbus_proxy_call_sync(manager_proxy, "GetManagedObjects",
- NULL,
+ result = g_dbus_proxy_call_sync(proxy, "FindDevice",
+ g_variant_new("(s)", address),
G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- NULL);
- if (!result) {
- BT_ERR("Can't get managed objects");
+ -1, NULL, &error);
+ if (result == NULL) {
+ if (error) {
+ BT_ERR("FindDevice Fail: %s", error->message);
+ g_clear_error(&error);
+ }
return NULL;
}
- /* signature of GetManagedObjects: a{oa{sa{sv}}} */
- g_variant_get(result, "(a{oa{sa{sv}}})", &iter);
- object_path = __bt_extract_device_path(iter, address);
- g_variant_iter_free(iter);
+ g_variant_get(result, "(o)", &object_path);
+
g_variant_unref(result);
return object_path;
}
adapter_proxy = _bt_get_adapter_proxy();
retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
- result = g_dbus_proxy_call_sync(adapter_proxy, "FindDevice",
- g_variant_new("(s)", bonding_info->addr),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- NULL);
- if (result == NULL)
- return BLUETOOTH_ERROR_INTERNAL;
-
- g_variant_get(result , "(o)", &device_path);
- g_variant_unref(result);
-
+ device_path = _bt_get_device_object_path(bonding_info->addr);
retv_if(device_path == NULL, BLUETOOTH_ERROR_INTERNAL);
result = g_dbus_proxy_call_sync(adapter_proxy, "UnpairDevice",
NULL,
&err);
g_free(device_path);
- if (err != NULL) {
- BT_ERR("UnpairDevice Fail: %s", err->message);
- g_error_free(err);
+ if (result == NULL) {
+ if (err != NULL) {
+ BT_ERR("UnpairDevice Fail: %s", err->message);
+ g_error_free(err);
+ }
return BLUETOOTH_ERROR_INTERNAL;
}
+ g_variant_unref(result);
return __bt_retry_bond();
}
int _bt_network_connect(int request_id, int role,
bluetooth_device_address_t *device_address)
{
- const gchar *device_path = NULL;
+ gchar *device_path = NULL;
char address[BT_ADDRESS_STRING_SIZE] = { 0 };
char remote_role[BLUETOOTH_UUID_STRING_MAX] = { 0 };
bt_function_data_t *func_data;
GDBusProxy *adapter_proxy;
GDBusProxy *profile_proxy;
GDBusConnection *conn;
- GVariant *result = NULL;
- GError*err = NULL;
BT_CHECK_PARAMETER(device_address, return);
_bt_convert_addr_type_to_string(address, device_address->addr);
- result = g_dbus_proxy_call_sync(adapter_proxy, "FindDevice",
- g_variant_new("(s)", address),
- G_DBUS_CALL_FLAGS_NONE,
- -1, NULL, &err);
- if (result == NULL) {
- BT_ERR("Error occurred in call to FindDevice");
- if (err) {
- BT_ERR("Error: %s", err->message);
- g_clear_error(&err);
- }
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- device_path = g_variant_get_string(result, NULL);
+ device_path = _bt_get_device_object_path(address);
if (device_path == NULL) {
BT_ERR("No paired device");
- g_variant_unref(result);
return BLUETOOTH_ERROR_NOT_PAIRED;
}
NULL, BT_BLUEZ_NAME,
device_path, BT_NETWORK_CLIENT_INTERFACE, NULL, NULL);
- g_variant_unref(result);
+ g_free(device_path);
retv_if(profile_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
func_data = g_malloc0(sizeof(bt_function_data_t));
func_data->address = g_strdup(address);
int _bt_network_disconnect(int request_id,
bluetooth_device_address_t *device_address)
{
- const gchar *device_path = NULL;
+ gchar *device_path = NULL;
char address[BT_ADDRESS_STRING_SIZE] = { 0 };
bt_function_data_t *func_data;
GDBusProxy *adapter_proxy;
GDBusProxy *profile_proxy;
GDBusConnection *conn;
- GVariant *result = NULL;
- GError*err = NULL;
BT_CHECK_PARAMETER(device_address, return);
_bt_convert_addr_type_to_string(address, device_address->addr);
- result = g_dbus_proxy_call_sync(adapter_proxy, "FindDevice",
- g_variant_new("(s)", address),
- G_DBUS_CALL_FLAGS_NONE,
- -1, NULL, &err);
- if (result == NULL) {
- BT_ERR("Error occurred in call to FindDevice");
- if (err) {
- BT_ERR("Error: %s", err->message);
- g_clear_error(&err);
- }
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- device_path = g_variant_get_string(result, NULL);
+ device_path = _bt_get_device_object_path(address);
if (device_path == NULL) {
BT_ERR("No paired device");
- g_variant_unref(result);
return BLUETOOTH_ERROR_NOT_PAIRED;
}
NULL, BT_BLUEZ_NAME,
device_path, BT_NETWORK_CLIENT_INTERFACE, NULL, NULL);
- g_variant_unref(result);
+ g_free(device_path);
retv_if(profile_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
func_data = g_malloc0(sizeof(bt_function_data_t));
func_data->address = g_strdup(address);