Merge the code from private 08/95808/1 accepted/tizen/ivi/20161108.001302 accepted/tizen/mobile/20161108.001201 accepted/tizen/tv/20161108.001234 accepted/tizen/wearable/20161108.001247 submit/tizen/20161107.085724
authorDoHyun Pyun <dh79.pyun@samsung.com>
Thu, 3 Nov 2016 02:00:34 +0000 (11:00 +0900)
committerDoHyun Pyun <dh79.pyun@samsung.com>
Sun, 6 Nov 2016 23:41:38 +0000 (08:41 +0900)
branch:devel/bluetooth/master
=================================================
commit da8a21b4dd39e2aa6ea65bae11e1e5ecf63aa8a5
Author: Seungyoun Ju <sy39.ju@samsung.com>
Date:   Tue Oct 4 20:41:11 2016 +0900
==================================================

Change-Id: I075896db0e203006ef09f445339d77f351a0abe3
Signed-off-by: DoHyun Pyun <dh79.pyun@samsung.com>
38 files changed:
bt-api/bt-adapter.c
bt-api/bt-audio.c
bt-api/bt-avrcp.c
bt-api/bt-common.c
bt-api/bt-device.c
bt-api/bt-event-handler.c
bt-api/bt-gatt-client.c
bt-api/bt-gatt-service.c
bt-api/bt-hid-device.c
bt-api/bt-rfcomm-client.c
bt-api/bt-rfcomm-server.c
bt-api/bt-telephony.c
bt-api/include/bt-common.h
bt-api/include/bt-request-sender.h
bt-service/bt-request-handler.c
bt-service/bt-service-adapter-le.c
bt-service/bt-service-adapter.c
bt-service/bt-service-audio.c
bt-service/bt-service-avrcp-controller.c
bt-service/bt-service-avrcp.c
bt-service/bt-service-common.c
bt-service/bt-service-device.c
bt-service/bt-service-event-receiver.c
bt-service/bt-service-gap-agent.c
bt-service/bt-service-headset-connection.c
bt-service/bt-service-hid.c
bt-service/bt-service-network.c
bt-service/bt-service-obex-agent.c
bt-service/bt-service-obex-server.c
bt-service/bt-service-oob.c
bt-service/bt-service-opp-client.c
bt-service/bt-service-pbap.c
bt-service/include/bt-service-adapter.h
bt-service/include/bt-service-audio.h
bt-service/include/bt-service-common.h
bt-service/include/bt-service-device.h
include/bluetooth-api.h
include/bt-internal-types.h

index 11f9c92..42fea38 100644 (file)
@@ -86,7 +86,7 @@ BT_EXPORT_API int bluetooth_enable_adapter(void)
 {
        int result;
 
-       BT_INFO("");
+       BT_INFO_C("### Enable adapter");
        retv_if(bluetooth_check_adapter() == BLUETOOTH_ADAPTER_ENABLED,
                                BLUETOOTH_ERROR_DEVICE_ALREADY_ENABLED);
 
@@ -110,7 +110,7 @@ BT_EXPORT_API int bluetooth_disable_adapter(void)
 {
        int result;
 
-       BT_INFO("");
+       BT_INFO_C("### Disable adapter");
        BT_CHECK_ENABLED(return);
 
        BT_INIT_PARAMS();
@@ -128,7 +128,7 @@ BT_EXPORT_API int bluetooth_recover_adapter(void)
 {
        int result;
 
-       BT_INFO("");
+       BT_INFO("Recover adapter");
        BT_CHECK_ENABLED(return);
 
        BT_INIT_PARAMS();
index 1bd297e..ca46144 100644 (file)
@@ -1152,7 +1152,7 @@ BT_EXPORT_API int bluetooth_hf_is_ibr_supported(gboolean *ibr_supported)
        g_variant_get(reply, "(b)", &is_supported);
        *ibr_supported = is_supported;
 
-       BT_DBG("%s", *ibr_supported ? "Supported":"Not Supported");
+       BT_DBG("%s", *ibr_supported ? "Supported" : "Not Supported");
 
        g_variant_unref(reply);
        return ret;
index 4774ff4..50cab77 100644 (file)
@@ -357,7 +357,7 @@ BT_EXPORT_API int bluetooth_media_target_disconnect(
                                        sizeof(bluetooth_device_address_t));
 
        result = _bt_send_request_async(BT_BLUEZ_SERVICE,
-                               BT_AVRCP_TARGET_DISCONNECT,in_param1,
+                               BT_AVRCP_TARGET_DISCONNECT, in_param1,
                                in_param2, in_param3, in_param4,
                                user_info->cb, user_info->user_data);
 
index 7a82445..a59a1ec 100644 (file)
@@ -250,7 +250,7 @@ void _bt_convert_addr_string_to_secure_string(char *addr,
        ret_if(addr == NULL);
 
        len = strlen(address);
-       ret_if(len != BT_ADDRESS_STRING_SIZE- 1);
+       ret_if(len != BT_ADDRESS_STRING_SIZE - 1);
 
        strncpy(addr, address, len);
 
@@ -1298,10 +1298,12 @@ int _bt_get_adapter_path(GDBusConnection *conn, char *path)
        result = g_dbus_proxy_call_sync(manager_proxy, "DefaultAdapter", NULL,
                        G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err);
        if (!result) {
-               if (err != NULL)
-                       BT_ERR("Fail to get DefaultAdapter (Error: %s)", err->message);
-               else
+               if (err != NULL) {
+                       if (!g_strrstr(err->message, "ServiceUnknown"))
+                               BT_ERR("Fail to get DefaultAdapter (Error: %s)", err->message);
+               } else {
                        BT_ERR("Fail to get DefaultAdapter");
+               }
 
                goto fail;
        }
index 0d80b05..da19a75 100644 (file)
@@ -182,6 +182,31 @@ BT_EXPORT_API int bluetooth_get_bonded_device(const bluetooth_device_address_t *
        return result;
 }
 
+BT_EXPORT_API int bluetooth_get_is_alias_set(const bluetooth_device_address_t *device_address,
+                               gboolean *is_alias_set)
+{
+       int result;
+
+       BT_CHECK_PARAMETER(device_address, return);
+       BT_CHECK_PARAMETER(is_alias_set, return);
+       BT_CHECK_ENABLED(return);
+
+       BT_INIT_PARAMS();
+       BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       g_array_append_vals(in_param1, device_address, sizeof(bluetooth_device_address_t));
+
+       result = _bt_send_request(BT_BLUEZ_SERVICE, BT_GET_IS_ALIAS_SET,
+               in_param1, in_param2, in_param3, in_param4, &out_param);
+
+       if (result == BLUETOOTH_ERROR_NONE)
+               *is_alias_set = g_array_index(out_param, gboolean, 0);
+
+       BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       return result;
+}
+
 BT_EXPORT_API int bluetooth_get_remote_device(const bluetooth_device_address_t *device_address)
 {
        return BLUETOOTH_ERROR_NONE;
index 14ba549..2f685bb 100644 (file)
@@ -428,7 +428,9 @@ gboolean __bt_reliable_disable_cb(gpointer user_data)
 #ifdef RFCOMM_DIRECT
         _bt_rfcomm_server_free_all();
 #endif
-       bluetooth_hid_device_deactivate();
+
+       _bluetooth_hid_free_hid_info();
+
        BT_DBG("-");
        return FALSE;
 }
@@ -893,7 +895,7 @@ void __bt_device_event_filter(GDBusConnection *connection,
                g_variant_get(parameters, "(i&s@ay)", &result, &char_handle, &char_value_var);
 
                len = g_variant_get_size(char_value_var);
-               ret_if (char_value_var == NULL);
+               ret_if(char_value_var == NULL);
 
                if (len > 0)
                        value = (char *)g_variant_get_data(char_value_var);
@@ -1068,10 +1070,10 @@ void __bt_device_event_filter(GDBusConnection *connection,
                                        result, &profile_info,
                                        event_info->cb, event_info->user_data);
                }
-               if (trust & (PROFILE_SUPPORTED <<)) { /* Bit 2 & 3 - for MAP Supported */
+               if (trust & (PROFILE_SUPPORTED << 2)) { /* Bit 2 & 3 - for MAP Supported */
                        profile_info.profile = TRUSTED_PROFILE_MAP;
                        profile_info.supported = TRUE;
-                       if (trust & (1 <<)) /* Bit 3 - for PBAP Trusted */
+                       if (trust & (1 << 3)) /* Bit 3 - for PBAP Trusted */
                                profile_info.trusted = TRUE;
                        else
                                profile_info.trusted = FALSE;
@@ -1080,10 +1082,10 @@ void __bt_device_event_filter(GDBusConnection *connection,
                                        result, &profile_info,
                                        event_info->cb, event_info->user_data);
                }
-               if (trust & (PROFILE_SUPPORTED <<)) { /* Bit 4 & 5- for SAP Supported */
+               if (trust & (PROFILE_SUPPORTED << 4)) { /* Bit 4 & 5- for SAP Supported */
                        profile_info.profile = TRUSTED_PROFILE_SAP;
                        profile_info.supported = TRUE;
-                       if (trust & (1 <<)) /* Bit 5 - for SAP Trusted */
+                       if (trust & (1 << 5)) /* Bit 5 - for SAP Trusted */
                                profile_info.trusted = TRUE;
                        else
                                profile_info.trusted = FALSE;
@@ -2138,7 +2140,7 @@ void __bt_pbap_client_event_filter(GDBusConnection *connection,
 
                success = !result;
 
-               for(i = 0; i < count; i++)
+               for (i = 0; i < count; i++)
                        BT_DBG("%s", list[i]);
 
                BT_DBG("address: %s, result: %d, count: %d, success: %d",
@@ -2186,7 +2188,7 @@ void __bt_pbap_client_event_filter(GDBusConnection *connection,
 
                list = (gchar **)g_variant_get_strv(string_var, &count);
                success = !result;
-               for(i = 0; i < count; i++)
+               for (i = 0; i < count; i++)
                        BT_DBG("%s", list[i]);
 
                BT_DBG("address: %s success: %d", address, success);
index cb66417..233f0e0 100644 (file)
@@ -260,13 +260,13 @@ BT_EXPORT_API int bluetooth_gatt_get_service_property(const char *service_handle
        memset(service, 0, sizeof(bt_gatt_service_property_t));
 
        while (g_variant_iter_loop(property_iter, "{sv}", &key, &value)) {
-               if (!g_strcmp0(key,"UUID")) {
+               if (!g_strcmp0(key, "UUID")) {
                        char *name = NULL;
-                       service->uuid = g_variant_dup_string(value,&len);
+                       service->uuid = g_variant_dup_string(value, &len);
                        _bt_get_uuid_specification_name(service->uuid, &name);
                        BT_INFO("======> Service : %s [%s]", service->uuid, name);
                        g_free(name);
-               } else if(!g_strcmp0(key, "Primary")) {
+               } else if (!g_strcmp0(key, "Primary")) {
                        service->primary = g_variant_get_boolean(value);
 
                } else if (!g_strcmp0(key, "Includes")) {
@@ -293,7 +293,7 @@ BT_EXPORT_API int bluetooth_gatt_get_service_property(const char *service_handle
                                service->char_handle.handle =
                                                __get_string_array_from_gptr_array(gp_array);
                        }
-                       BT_DBG("Characteristics count : %d",service->char_handle.count);
+                       BT_DBG("Characteristics count : %d", service->char_handle.count);
                        g_ptr_array_free(gp_array, TRUE);
                        g_variant_iter_free(char_iter);
                }
@@ -510,6 +510,7 @@ static void __bluetooth_internal_get_char_cb(GDBusProxy *proxy,
        g_strfreev(svc_char.handle_info.handle);
        g_free(svc_char.service_handle);
        g_variant_iter_free(char_iter);
+       g_variant_unref(value);
        g_object_unref(proxy);
 }
 
@@ -560,7 +561,7 @@ static int __get_permission_flag(char *permission)
 
        retv_if(permission == NULL, ret);
 
-       BT_INFO("permission = %s",permission);
+       BT_INFO("permission = %s", permission);
 
        if (!g_strcmp0(permission, "broadcast")) {
                ret = BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_BROADCAST;
@@ -655,13 +656,13 @@ BT_EXPORT_API int bluetooth_gatt_get_characteristics_property(
        characteristic->handle = g_strdup(char_handle);
 
        while (g_variant_iter_loop(property_iter, "{sv}", &key, &value)) {
-               if (!g_strcmp0(key,"UUID")) {
+               if (!g_strcmp0(key, "UUID")) {
                        char *name = NULL;
-                       characteristic->uuid = g_variant_dup_string(value,&len);
+                       characteristic->uuid = g_variant_dup_string(value, &len);
                        _bt_get_uuid_specification_name(characteristic->uuid, &name);
                        BT_INFO("Characteristic : %s [%s]", characteristic->uuid, name);
                        g_free(name);
-               } else if(!g_strcmp0(key, "Value")) {
+               } else if (!g_strcmp0(key, "Value")) {
                        gb_array = g_byte_array_new();
                        g_variant_get(value, "ay", &char_value_iter);
                        while (g_variant_iter_loop(char_value_iter, "y",  &char_value)) {
@@ -769,6 +770,7 @@ void bluetooth_gatt_get_char_from_uuid_cb(GDBusProxy *proxy,
 
        bluetooth_gatt_free_char_property(&characteristic);
        g_variant_iter_free(char_iter);
+       g_variant_unref(value);
        g_free(user_data);
 }
 
@@ -867,17 +869,17 @@ BT_EXPORT_API int bluetooth_gatt_get_char_descriptor_property(
        descriptor->handle = g_strdup(descriptor_handle);
 
        while (g_variant_iter_loop(property_iter, "{sv}", &key, &value)) {
-               if (!g_strcmp0(key,"UUID")) {
+               if (!g_strcmp0(key, "UUID")) {
                        char *name = NULL;
-                       descriptor->uuid = g_variant_dup_string(value,&len);
+                       descriptor->uuid = g_variant_dup_string(value, &len);
                        _bt_get_uuid_specification_name(descriptor->uuid, &name);
-                       BT_INFO("Descriptor : %s [%s]",descriptor->uuid, name);
+                       BT_INFO("Descriptor : %s [%s]", descriptor->uuid, name);
                        g_free(name);
                } else if (!g_strcmp0(key, "Value")) {
                        gb_array = g_byte_array_new();
                        g_variant_get(value, "ay", &desc_value_iter);
-                       while(g_variant_iter_loop(desc_value_iter, "y",  &char_value)) {
-                               BT_DBG("value of descriptor = %d",char_value);
+                       while (g_variant_iter_loop(desc_value_iter, "y",  &char_value)) {
+                               BT_DBG("value of descriptor = %d", char_value);
                                g_byte_array_append(gb_array, &char_value, 1);
                        }
                        g_variant_iter_free(desc_value_iter);
@@ -1340,6 +1342,7 @@ static void bluetooth_gatt_get_char_desc_cb(GDBusProxy *proxy,
        bluetooth_gatt_free_char_property(&characteristic);
 
        g_variant_iter_free(char_iter);
+       g_variant_unref(value);
        BT_DBG("-");
 }
 
index a79cf40..4a04b94 100644 (file)
@@ -1397,6 +1397,8 @@ void register_application_cb(GObject *object, GAsyncResult *res, gpointer user_d
                                                error->code, error->message);
                        g_clear_error(&error);
                }
+       } else {
+               g_variant_unref(result);
        }
 }
 
@@ -1420,6 +1422,8 @@ void unregister_application_cb(GObject *object, GAsyncResult *res,
                                        error->code, error->message);
                        g_clear_error(&error);
                }
+       } else {
+               g_variant_unref(result);
        }
 }
 
index d58edbd..9d76bd2 100644 (file)
@@ -143,7 +143,7 @@ int _bt_hid_device_get_fd(const char *address, int *ctrl, int *intr)
                        g_error_free(err);
                }
        } else {
-               g_variant_get (result, "(hh)", &index1, &index2);
+               g_variant_get(result, "(hh)", &index1, &index2);
                int fd1 = g_unix_fd_list_get(out_fd_list, index1, NULL);
                int fd2 = g_unix_fd_list_get(out_fd_list, index2, NULL);
 
@@ -183,7 +183,7 @@ static void __hid_connected_cb(hid_connected_device_info_t *info,
                conn_info.socket_fd = info->intr_fd;
        else
                conn_info.socket_fd = info->ctrl_fd;
-       _bt_convert_addr_string_to_type (conn_info.device_addr.addr , info->address);
+       _bt_convert_addr_string_to_type(conn_info.device_addr.addr, info->address);
 
        if (result == BLUETOOTH_ERROR_NONE)
                BT_INFO_C("Connected [HID Device]");
@@ -313,6 +313,13 @@ void __free_hid_info(hid_info_t *info)
        g_free(info);
 }
 
+static gboolean __is_error_by_disconnect(GError *err)
+{
+       return !g_strcmp0(err->message, "Connection reset by peer") ||
+                       !g_strcmp0(err->message, "Connection timed out") ||
+                       !g_strcmp0(err->message, "Software caused connection abort");
+}
+
 static gboolean __received_cb(GIOChannel *chan, GIOCondition cond,
                                                                gpointer data)
 {
@@ -460,7 +467,21 @@ static gboolean __received_cb(GIOChannel *chan, GIOCondition cond,
                if (data.address)
                        g_free((char *)data.address);
        } else {
-               BT_INFO("Error while reading data");
+               BT_ERR("Error while reading data %d [%s]", status, info->address);
+               if (err) {
+                       BT_ERR("IO Channel read error [%s]", err->message);
+                       if (status == G_IO_STATUS_ERROR &&
+                                       __is_error_by_disconnect(err)) {
+                               BT_DBG("cond : %d", cond);
+                               g_error_free(err);
+                               __hid_disconnect(info);
+                               return FALSE;
+                       }
+                       g_error_free(err);
+               } else if (status == G_IO_STATUS_EOF) {
+                       __hid_disconnect(info);
+                       return FALSE;
+               }
        }
        return TRUE;
 }
@@ -533,6 +554,17 @@ static hid_info_t *__register_method()
        return info;
 }
 
+void _bluetooth_hid_free_hid_info(void)
+{
+       if (hid_info == NULL) {
+               BT_DBG("hid_info is already NULL");
+               return;
+       }
+
+       __free_hid_info(hid_info);
+       hid_info = NULL;
+}
+
 BT_EXPORT_API int bluetooth_hid_device_init(hid_cb_func_ptr callback_ptr, void *user_data)
 {
        int ret;
@@ -596,7 +628,7 @@ BT_EXPORT_API int bluetooth_hid_device_activate(void)
        profile_info.uuid = hid_info->uuid;
 
        BT_INFO("uuid %s", profile_info.uuid);
-       result = _bt_register_profile_platform(&profile_info, FALSE);
+       result = _bt_register_profile(&profile_info, FALSE);
 
        return result;
 }
@@ -614,8 +646,8 @@ BT_EXPORT_API int bluetooth_hid_device_deactivate(void)
 
        _bt_unregister_profile(hid_info->path);
 
-       __free_hid_info(hid_info);
-       hid_info = NULL;
+       _bluetooth_hid_free_hid_info();
+
        return BLUETOOTH_ERROR_NONE;
 }
 
@@ -646,6 +678,8 @@ BT_EXPORT_API int bluetooth_hid_device_connect(const char *remote_addr)
 }
 BT_EXPORT_API int bluetooth_hid_device_disconnect(const char *remote_addr)
 {
+       BT_CHECK_PARAMETER(remote_addr, return);
+
        if (_bt_check_privilege(BT_CHECK_PRIVILEGE, BT_HID_DEVICE_DISCONNECT)
                 == BLUETOOTH_ERROR_PERMISSION_DEINED) {
                BT_ERR("Don't have a privilege to use this API");
@@ -672,6 +706,8 @@ BT_EXPORT_API int bluetooth_hid_device_send_mouse_event(const char *remote_addr,
        int written = 0;
        hid_connected_device_info_t *info = NULL;
 
+       BT_CHECK_PARAMETER(remote_addr, return);
+
        switch (privilege_token_send_mouse) {
        case 0:
                result = _bt_check_privilege(BT_CHECK_PRIVILEGE, BT_HID_DEVICE_SEND_MOUSE_EVENT);
@@ -719,6 +755,8 @@ BT_EXPORT_API int bluetooth_hid_device_send_key_event(const char *remote_addr,
        int written = 0;
        hid_connected_device_info_t *info = NULL;
 
+       BT_CHECK_PARAMETER(remote_addr, return);
+
        switch (privilege_token_send_key) {
        case 0:
                result = _bt_check_privilege(BT_CHECK_PRIVILEGE, BT_HID_DEVICE_SEND_KEY_EVENT);
@@ -839,6 +877,8 @@ BT_EXPORT_API int bluetooth_hid_device_reply_to_report(const char *remote_addr,
                return BLUETOOTH_ERROR_INVALID_PARAM;
        }
 
+       BT_CHECK_PARAMETER(remote_addr, return);
+
        switch (privilege_token_reply) {
        case 0:
                result = _bt_check_privilege(BT_CHECK_PRIVILEGE, BT_HID_DEVICE_SEND_REPLY_TO_REPORT);
@@ -864,9 +904,9 @@ BT_EXPORT_API int bluetooth_hid_device_reply_to_report(const char *remote_addr,
        }
 
        BT_INFO("htype %d ptype %d", htype, ptype);
-       switch(htype) {
+       switch (htype) {
                case HTYPE_TRANS_GET_REPORT: {
-                       switch(ptype) {
+                       switch (ptype) {
                                case PTYPE_DATA_RTYPE_INPUT: {
                                        output_report.type = BT_HID_TRANS_DATA |
                                                        BT_HID_DATA_RTYPE_INPUT;
index fc47c87..93f5ea6 100644 (file)
@@ -53,7 +53,7 @@ static int privilege_token;
 typedef struct {
        char bt_addr[BT_ADDRESS_STRING_SIZE];
        int fd;
-       int watch_id;
+       guint watch_id;
        gboolean disconnected;
 } rfcomm_conn_info_t;
 
@@ -129,12 +129,11 @@ static void __bt_free_conn(rfcomm_conn_info_t *conn)
        if (conn == NULL)
                return;
 
-       if (conn->fd > 0)
-               close(conn->fd);
        if (conn->watch_id > 0) {
                g_source_remove(conn->watch_id);
                conn->watch_id = 0;
        }
+
        g_free(conn);
 
        BT_DBG("-");
@@ -245,21 +244,26 @@ static void _bt_rfcomm_disconnect_conn_info(rfcomm_conn_info_t *conn_info,
 
        bluetooth_rfcomm_disconnection_t disconn_info;
        bt_event_info_t *event_info = NULL;
+
        if (conn_info->disconnected == FALSE)
                return;
+
        event_info = _bt_event_get_cb_data(BT_RFCOMM_CLIENT_EVENT);
        if (event_info == NULL) {
+               __rfcomm_remove_conn_info_t(info, conn_info->bt_addr);
+
                if (info->rfcomm_conns == NULL)
                        rfcomm_cb_data_remove(info);
                return;
        }
+
        memset(&disconn_info, 0x00, sizeof(bluetooth_rfcomm_disconnection_t));
        disconn_info.device_role = RFCOMM_ROLE_CLIENT;
        g_strlcpy(disconn_info.uuid, info->uuid, BLUETOOTH_UUID_STRING_MAX);
-       BT_DBG("Disconnected FD [%d]", conn_info->fd);
        _bt_convert_addr_string_to_type(disconn_info.device_addr.addr,
                                        conn_info->bt_addr);
 
+       BT_DBG("Disconnected FD [%d]", conn_info->fd);
        disconn_info.socket_fd = conn_info->fd;
 
        BT_DBG("Disconnection Result[%d] BT_ADDRESS[%s] UUID[%s] FD[%d]",
@@ -269,10 +273,8 @@ static void _bt_rfcomm_disconnect_conn_info(rfcomm_conn_info_t *conn_info,
                        BLUETOOTH_ERROR_NONE, &disconn_info,
                        event_info->cb, event_info->user_data);
 
-       if (conn_info) {
-               BT_DBG("List is present deleting it");
-               __rfcomm_remove_conn_info_t(info, conn_info->bt_addr);
-       }
+       __rfcomm_remove_conn_info_t(info, conn_info->bt_addr);
+
        if (info->rfcomm_conns == NULL)
                rfcomm_cb_data_remove(info);
 
@@ -281,8 +283,10 @@ static void _bt_rfcomm_disconnect_conn_info(rfcomm_conn_info_t *conn_info,
 
 static gboolean __rfcomm_client_disconnect(gpointer user_data)
 {
-       rfcomm_cb_data_t *info = (rfcomm_cb_data_t *) user_data;
+       rfcomm_cb_data_t *info = (rfcomm_cb_data_t *)user_data;
+
        BT_INFO_C("### Disconnected [RFCOMM Client]");
+
        retv_if(info == NULL, FALSE);
 
        if (g_slist_find(rfcomm_clients, info) == NULL) {
@@ -290,8 +294,10 @@ static gboolean __rfcomm_client_disconnect(gpointer user_data)
                return FALSE;
        }
        info->idle_id = 0;
+
        g_slist_foreach(info->rfcomm_conns,
-               (GFunc) _bt_rfcomm_disconnect_conn_info, info);
+               (GFunc)_bt_rfcomm_disconnect_conn_info, info);
+
        BT_DBG("-");
        return FALSE;
 }
@@ -322,12 +328,17 @@ static gboolean __client_data_received_cb(GIOChannel *chan, GIOCondition cond,
        fd = g_io_channel_unix_get_fd(chan);
        if (cond & (G_IO_NVAL | G_IO_HUP | G_IO_ERR)) {
                BT_ERR_C("RFComm Client  disconnected: %d", fd);
+
                conn_info = __get_conn_info_from_fd(info, fd);
                if (conn_info == NULL) {
                        BT_ERR("No Connection info found with FD [%d]", fd);
                        return FALSE;
                }
-               conn_info->disconnected = TRUE;
+
+               if (conn_info->disconnected == FALSE) {
+                       close(conn_info->fd);
+                       conn_info->disconnected = TRUE;
+               }
                __rfcomm_client_disconnect(info);
                return FALSE;
        }
@@ -346,12 +357,17 @@ static gboolean __client_data_received_cb(GIOChannel *chan, GIOCondition cond,
                                        __is_error_by_disconnect(err)) {
                                BT_ERR("cond : %d", cond);
                                g_error_free(err);
+
                                conn_info = __get_conn_info_from_fd(info, fd);
                                if (conn_info == NULL) {
                                        BT_ERR("No Connection info found with FD [%d]", fd);
                                        return FALSE;
                                }
-                               conn_info->disconnected = TRUE;
+
+                               if (conn_info->disconnected == FALSE) {
+                                       close(conn_info->fd);
+                                       conn_info->disconnected = TRUE;
+                               }
                                __rfcomm_client_disconnect(info);
                                return FALSE;
                        }
@@ -454,6 +470,7 @@ static void __bt_connect_response_cb(GDBusProxy *proxy, GAsyncResult *res,
 
 {
        GError *error = NULL;
+       GVariant *value;
        rfcomm_cb_data_t *cb_data;
        char dev_address[BT_ADDRESS_STRING_SIZE];
        const char *path;
@@ -463,7 +480,8 @@ static void __bt_connect_response_cb(GDBusProxy *proxy, GAsyncResult *res,
 
        cb_data = user_data;
 
-       if (!g_dbus_proxy_call_finish(proxy, res, &error)) {
+       value = g_dbus_proxy_call_finish(proxy, res, &error);
+       if (value == NULL) {
                int result;
                g_dbus_error_strip_remote_error(error);
                BT_ERR("Error : %s \n", error->message);
@@ -477,7 +495,10 @@ static void __bt_connect_response_cb(GDBusProxy *proxy, GAsyncResult *res,
                __rfcomm_client_connected_cb(cb_data, dev_address, result);
 
                g_error_free(error);
+       } else {
+               g_variant_unref(value);
        }
+
        if (proxy)
                g_object_unref(proxy);
 
@@ -490,6 +511,7 @@ static void __bt_discover_service_response_cb(GDBusProxy *proxy,
        rfcomm_cb_data_t *cb_data;
        int ret = 0;
        GError *err = NULL;
+       GVariant *value;
        bt_register_profile_info_t info = {0};
        int result = BLUETOOTH_ERROR_NONE;
        char dev_address[BT_ADDRESS_STRING_SIZE];
@@ -505,9 +527,11 @@ static void __bt_discover_service_response_cb(GDBusProxy *proxy,
 
        _bt_convert_device_path_to_address(path, dev_address);
        BT_DBG("Device Adress [%s]", dev_address);
-       g_dbus_proxy_call_finish(proxy, res, &err);
+       value = g_dbus_proxy_call_finish(proxy, res, &err);
        if (proxy)
                g_object_unref(proxy);
+       if (value)
+               g_variant_unref(value);
 
        if (err != NULL) {
                g_dbus_error_strip_remote_error(err);
@@ -636,6 +660,7 @@ BT_EXPORT_API int bluetooth_rfcomm_connect(
                cb_data->object_id = object_id;
                cb_data->id = id;
        }
+
        conn = g_new0(rfcomm_conn_info_t, 1);
        conn->fd = -1;
        _bt_convert_addr_type_to_string(conn->bt_addr,
@@ -643,6 +668,7 @@ BT_EXPORT_API int bluetooth_rfcomm_connect(
 
        BT_DBG("Connecting to %s uuid %s", conn->bt_addr, remote_uuid);
        cb_data->rfcomm_conns = g_slist_append(cb_data->rfcomm_conns, conn);
+
        ret = _bt_discover_services(conn->bt_addr, (char *)remote_uuid,
                                __bt_discover_service_response_cb, cb_data);
        if (ret != BLUETOOTH_ERROR_NONE) {
@@ -652,6 +678,7 @@ BT_EXPORT_API int bluetooth_rfcomm_connect(
                        rfcomm_cb_data_remove(cb_data);
                return BLUETOOTH_ERROR_INTERNAL;
        }
+
        if (g_slist_find(rfcomm_clients, cb_data) == NULL) {
                BT_INFO("Adding callback information to rfcomm_clients");
                rfcomm_clients = g_slist_append(rfcomm_clients, cb_data);
@@ -766,7 +793,9 @@ BT_EXPORT_API int bluetooth_rfcomm_disconnect(int socket_fd)
 #ifdef RFCOMM_DIRECT
        rfcomm_cb_data_t *info;
        rfcomm_conn_info_t *conn_info;
+
        BT_INFO_C("### Disconnect RFCOMM");
+
        BT_CHECK_ENABLED(return);
 
        if (_bt_check_privilege(BT_BLUEZ_SERVICE, BT_RFCOMM_SOCKET_DISCONNECT)
@@ -775,6 +804,7 @@ BT_EXPORT_API int bluetooth_rfcomm_disconnect(int socket_fd)
                return BLUETOOTH_ERROR_PERMISSION_DEINED;
        }
 
+       BT_DBG("Requested FD %d", socket_fd);
        if (socket_fd < 0) {
                BT_ERR("Invalid FD");
                return BLUETOOTH_ERROR_INVALID_PARAM;
@@ -786,19 +816,28 @@ BT_EXPORT_API int bluetooth_rfcomm_disconnect(int socket_fd)
                BT_DBG("Could not find in client, so check in server");
                return bluetooth_rfcomm_server_disconnect(socket_fd);
        }
+
        conn_info = __get_conn_info_from_fd(info, socket_fd);
        if (conn_info == NULL) {
-               BT_ERR("FATAL Error");
+               BT_ERR("Could not find connection info");
                return BLUETOOTH_ERROR_INTERNAL;
        }
-       if (conn_info->watch_id <= 0) {
+
+       if (conn_info->watch_id == 0 || conn_info->disconnected) {
                BT_ERR("Invalid state");
                return BLUETOOTH_ERROR_NOT_CONNECTED;
        }
+
+       close(conn_info->fd);
        conn_info->disconnected = TRUE;
-       close(socket_fd);
+
        BT_INFO("conn_info %s", conn_info->bt_addr);
        _bt_disconnect_profile(conn_info->bt_addr, info->uuid, NULL, NULL);
+
+       /*
+        * ToDo : If idle_id is not zero, it means disconnect request is
+        * going on. Such a case, in-progress error should be returned.
+        */
        if (info->idle_id == 0)
                info->idle_id = g_idle_add(__rfcomm_client_disconnect, info);
 
index f58f50b..557911c 100644 (file)
 static GSList *rfcomm_nodes;
 
 typedef struct {
+       bluetooth_device_address_t addr;
+       int fd;
+       guint watch_id;
+       gboolean disconnected;
+} rfcomm_conn_t;
+
+typedef struct {
        guint object_id;
        gchar *path;
        int id;
        char *uuid;
-       int fd;
-       GIOChannel *data_io;
-       guint data_id;
-       bluetooth_device_address_t addr;
+       GSList *rfcomm_conns;
        guint disconnect_idle_id;
 } rfcomm_info_t;
 
@@ -66,12 +70,17 @@ static rfcomm_info_t *__find_rfcomm_info_with_id(int id)
 static rfcomm_info_t *__find_rfcomm_info_with_fd(int fd)
 {
        GSList *l;
+       GSList *ll;
 
        for (l = rfcomm_nodes; l != NULL; l = l->next) {
                rfcomm_info_t *info = l->data;
 
-               if (info->fd == fd)
-                       return info;
+               for (ll = info->rfcomm_conns; ll; ll = ll->next) {
+                       rfcomm_conn_t *conn = ll->data;
+
+                       if (conn && conn->fd == fd)
+                               return info;
+               }
        }
 
        return NULL;
@@ -105,6 +114,37 @@ static rfcomm_info_t *__find_rfcomm_info_with_uuid(const char *uuid)
        return NULL;
 }
 
+static rfcomm_conn_t *__find_rfcomm_conn_with_fd(rfcomm_info_t *info,
+                                                     int fd)
+{
+       GSList *l;
+       rfcomm_conn_t *conn;
+
+       for (l = info->rfcomm_conns; l; l = l->next) {
+               conn = l->data;
+
+               if (conn && conn->fd == fd)
+                       return conn;
+       }
+
+       return NULL;
+}
+
+static void __rfcomm_remove_conn(rfcomm_info_t *info, int fd)
+{
+       rfcomm_conn_t *conn;
+
+       conn = __find_rfcomm_conn_with_fd(info, fd);
+       if (conn == NULL)
+               return;
+
+       info->rfcomm_conns = g_slist_remove(info->rfcomm_conns, conn);
+
+       if (conn->watch_id > 0)
+               g_source_remove(conn->watch_id);
+       g_free(conn);
+}
+
 gboolean _check_uuid_path(char *path, char *uuid)
 {
        rfcomm_info_t *info = NULL;
@@ -118,15 +158,17 @@ gboolean _check_uuid_path(char *path, char *uuid)
        return FALSE;
 }
 
-static void __connected_cb(rfcomm_info_t *info, bt_event_info_t *event_info)
+static void __connected_cb(rfcomm_info_t *info, rfcomm_conn_t *conn,
+                          bt_event_info_t *event_info)
 {
        bluetooth_rfcomm_connection_t conn_info;
 
        memset(&conn_info, 0x00, sizeof(bluetooth_rfcomm_connection_t));
+
        conn_info.device_role = RFCOMM_ROLE_SERVER;
        g_strlcpy(conn_info.uuid, info->uuid, BLUETOOTH_UUID_STRING_MAX);
-       conn_info.socket_fd = info->fd;
-       conn_info.device_addr = info->addr;
+       conn_info.socket_fd = conn->fd;
+       conn_info.device_addr = conn->addr;
        conn_info.server_id = info->id;
 
        BT_INFO_C("### Connected [RFCOMM Server]");
@@ -135,44 +177,58 @@ static void __connected_cb(rfcomm_info_t *info, bt_event_info_t *event_info)
                        event_info->cb, event_info->user_data);
 }
 
-static gboolean __rfcomm_server_disconnect(rfcomm_info_t *info)
+static void __rfcomm_server_disconnect_conn(rfcomm_conn_t *conn,
+                                           rfcomm_info_t *info)
 {
        bluetooth_rfcomm_disconnection_t disconn_info;
-       int fd = info->fd;
        bt_event_info_t *event_info;
 
-       BT_INFO_C("### Disconnected [RFCOMM Server]");
+       if (conn == NULL)
+               return;
 
-       if (info->data_id > 0) {
-               g_source_remove(info->data_id);
-               info->data_id = 0;
-       }
+       if (conn->disconnected == FALSE)
+               return;
 
-       if (info->fd >= 0) {
-               close(info->fd);
-               info->fd = -1;
+       if (conn->watch_id > 0) {
+               g_source_remove(conn->watch_id);
+               conn->watch_id = 0;
        }
 
-       if (info->data_io) {
-               g_io_channel_shutdown(info->data_io, TRUE, NULL);
-               g_io_channel_unref(info->data_io);
-               info->data_io = NULL;
-       }
-       info->disconnect_idle_id = 0;
        event_info = _bt_event_get_cb_data(BT_RFCOMM_SERVER_EVENT);
-       if (event_info == NULL)
-               return FALSE;
+       if (event_info == NULL) {
+               __rfcomm_remove_conn(info, conn->fd);
+               return;
+       }
 
        memset(&disconn_info, 0x00, sizeof(bluetooth_rfcomm_disconnection_t));
        disconn_info.device_role = RFCOMM_ROLE_SERVER;
        g_strlcpy(disconn_info.uuid, info->uuid, BLUETOOTH_UUID_STRING_MAX);
-       disconn_info.socket_fd = fd;
-       disconn_info.device_addr = info->addr;
+       disconn_info.device_addr = conn->addr;
+
+       BT_DBG("Disconnected FD [%d]", conn->fd);
+       disconn_info.socket_fd = conn->fd;
 
        _bt_common_event_cb(BLUETOOTH_EVENT_RFCOMM_DISCONNECTED,
                        BLUETOOTH_ERROR_NONE, &disconn_info,
                        event_info->cb, event_info->user_data);
 
+       __rfcomm_remove_conn(info, conn->fd);
+}
+
+static gboolean __rfcomm_server_disconnect(rfcomm_info_t *info)
+{
+       BT_INFO_C("### Disconnected [RFCOMM Server]");
+
+       if (g_slist_find(rfcomm_nodes, info) == NULL) {
+               BT_INFO("rfcomm resource is already freed");
+               return FALSE;
+       }
+
+       info->disconnect_idle_id = 0;
+
+       g_slist_foreach(info->rfcomm_conns,
+                       (GFunc)__rfcomm_server_disconnect_conn, info);
+
        BT_DBG("-");
        return FALSE;
 }
@@ -191,17 +247,18 @@ static gboolean __data_received_cb(GIOChannel *chan, GIOCondition cond,
        gsize len = 0;
        int result = BLUETOOTH_ERROR_NONE;
        rfcomm_info_t *info = data;
+       rfcomm_conn_t *conn;
        bt_event_info_t *event_info;
        bluetooth_rfcomm_received_data_t data_r;
        GIOStatus status = G_IO_STATUS_NORMAL;
        GError *err = NULL;
+       int fd;
 
        retv_if(info == NULL, FALSE);
 
-       event_info = _bt_event_get_cb_data(BT_RFCOMM_SERVER_EVENT);
-
+       fd = g_io_channel_unix_get_fd(chan);
        if (cond & (G_IO_NVAL | G_IO_HUP | G_IO_ERR)) {
-               BT_ERR_C("RFComm Server  disconnected: %d", info->fd);
+               BT_ERR_C("RFComm Server disconnected: %d", fd);
 
                if (info->disconnect_idle_id > 0) {
                        BT_INFO("Disconnect idle still not process remove source");
@@ -209,6 +266,16 @@ static gboolean __data_received_cb(GIOChannel *chan, GIOCondition cond,
                        info->disconnect_idle_id = 0;
                }
 
+               conn = __find_rfcomm_conn_with_fd(info, fd);
+               if (conn == NULL) {
+                       BT_ERR("No Connection info found with FD [%d]", fd);
+                       return FALSE;
+               }
+
+               if (conn->disconnected == FALSE) {
+                       close(conn->fd);
+                       conn->disconnected = TRUE;
+               }
                __rfcomm_server_disconnect(info);
                return FALSE;
        }
@@ -216,39 +283,53 @@ static gboolean __data_received_cb(GIOChannel *chan, GIOCondition cond,
        buffer = g_malloc0(BT_RFCOMM_BUFFER_LEN + 1);
 
        status =  g_io_channel_read_chars(chan, buffer, BT_RFCOMM_BUFFER_LEN,
-                       &len, &err);
+                                               &len, &err);
        if (status != G_IO_STATUS_NORMAL) {
                BT_ERR("IO Channel read is failed with %d", status);
 
                g_free(buffer);
-               if (err) {
-                       BT_ERR("IO Channel read error [%s]", err->message);
-                       if (status == G_IO_STATUS_ERROR &&
-                                       __is_error_by_disconnect(err)) {
-                               BT_ERR("cond : %d", cond);
-                               g_error_free(err);
-                               if (info->disconnect_idle_id > 0) {
-                                       BT_INFO("Disconnect idle still not process remove source");
-                                       g_source_remove(info->disconnect_idle_id);
-                                       info->disconnect_idle_id = 0;
-                               }
-                               __rfcomm_server_disconnect(info);
+               if (!err)
+                       return TRUE;
+
+               BT_ERR("IO Channel read error [%s]", err->message);
+               if (status == G_IO_STATUS_ERROR &&
+                   __is_error_by_disconnect(err)) {
+                       BT_ERR("cond : %d", cond);
+                       g_error_free(err);
+
+                       if (info->disconnect_idle_id > 0) {
+                               BT_INFO("Disconnect idle still not process remove source");
+                               g_source_remove(info->disconnect_idle_id);
+                               info->disconnect_idle_id = 0;
+                       }
+
+                       conn = __find_rfcomm_conn_with_fd(info, fd);
+                       if (conn == NULL) {
+                               BT_ERR("No Connection info found with FD [%d]", fd);
                                return FALSE;
                        }
-                       g_error_free(err);
+
+                       if (conn->disconnected == FALSE) {
+                               close(conn->fd);
+                               conn->disconnected = TRUE;
+                       }
+                       __rfcomm_server_disconnect(info);
+                       return FALSE;
                }
+               g_error_free(err);
                return TRUE;
        }
 
        if (len == 0)
                BT_ERR("Length is zero");
 
+       event_info = _bt_event_get_cb_data(BT_RFCOMM_SERVER_EVENT);
        if (event_info == NULL) {
                g_free(buffer);
                return TRUE;
        }
 
-       data_r.socket_fd = info->fd;
+       data_r.socket_fd = fd;
        data_r.buffer_size = len;
        data_r.buffer = buffer;
 
@@ -264,6 +345,8 @@ static gboolean __data_received_cb(GIOChannel *chan, GIOCondition cond,
 int new_server_connection(const char *path, int fd, bluetooth_device_address_t *addr)
 {
        rfcomm_info_t *info;
+       rfcomm_conn_t *conn;
+       GIOChannel *data_io;
        bt_event_info_t *event_info;
 
        BT_DBG("%s %d", path, fd);
@@ -272,21 +355,25 @@ int new_server_connection(const char *path, int fd, bluetooth_device_address_t *
        if (info == NULL)
                return -1;
 
-       info->fd = fd;
-       memcpy(&info->addr, addr, sizeof(bluetooth_device_address_t));
+       conn = g_new0(rfcomm_conn_t, 1);
+       conn->fd = fd;
+       memcpy(&conn->addr, addr, sizeof(bluetooth_device_address_t));
+       info->rfcomm_conns = g_slist_append(info->rfcomm_conns, conn);
 
-       info->data_io = g_io_channel_unix_new(info->fd);
+       data_io = g_io_channel_unix_new(conn->fd);
 
-       g_io_channel_set_encoding(info->data_io, NULL, NULL);
-       g_io_channel_set_flags(info->data_io, G_IO_FLAG_NONBLOCK, NULL);
+       g_io_channel_set_encoding(data_io, NULL, NULL);
+       g_io_channel_set_flags(data_io, G_IO_FLAG_NONBLOCK, NULL);
 
-       info->data_id = g_io_add_watch(info->data_io,
+       conn->watch_id = g_io_add_watch(data_io,
                           G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
                           __data_received_cb, info);
 
+       g_io_channel_unref(data_io);
+
        event_info = _bt_event_get_cb_data(BT_RFCOMM_SERVER_EVENT);
        if (event_info) {
-               __connected_cb(info, event_info);
+               __connected_cb(info, conn, event_info);
        }
 
        return 0;
@@ -310,18 +397,17 @@ static rfcomm_info_t *__register_method()
                __rfcomm_delete_id(id);
                return NULL;
        }
-       info = g_new(rfcomm_info_t, 1);
+       info = g_new0(rfcomm_info_t, 1);
        info->object_id = (guint)object_id;
        info->path = path;
        info->id = id;
-       info->fd = -1;
 
        rfcomm_nodes = g_slist_append(rfcomm_nodes, info);
 
        return info;
 }
 
-static rfcomm_info_t *__register_method_2(const char *path,const char *bus_name)
+static rfcomm_info_t *__register_method_2(const char *path, const char *bus_name)
 {
        rfcomm_info_t *info;
        int object_id;
@@ -330,22 +416,29 @@ static rfcomm_info_t *__register_method_2(const char *path,const char *bus_name)
        if (object_id < 0) {
                return NULL;
        }
-       info = g_new(rfcomm_info_t, 1);
+       info = g_new0(rfcomm_info_t, 1);
        info->object_id = (guint)object_id;
        info->path = g_strdup(path);
        info->id = -1;
-       info->fd = -1;
 
        rfcomm_nodes = g_slist_append(rfcomm_nodes, info);
 
        return info;
 }
 
-void free_rfcomm_info(rfcomm_info_t *info)
+void free_rfcomm_conn(rfcomm_conn_t *conn, rfcomm_info_t *info)
 {
-       bt_event_info_t *event_info;
+       if (conn->disconnected == FALSE) {
+               close(conn->fd);
+               conn->disconnected = TRUE;
+       }
+       __rfcomm_server_disconnect_conn(conn, info);
+}
 
+void free_rfcomm_info(rfcomm_info_t *info)
+{
        BT_DBG("");
+
        if (info->disconnect_idle_id > 0) {
                BT_INFO("Disconnect idle still not process remove source");
                g_source_remove(info->disconnect_idle_id);
@@ -355,12 +448,7 @@ void free_rfcomm_info(rfcomm_info_t *info)
        __rfcomm_delete_id(info->id);
        _bt_unregister_gdbus(info->object_id);
 
-       if (info->fd >= 0) {
-               event_info = _bt_event_get_cb_data(BT_RFCOMM_SERVER_EVENT);
-               if (event_info)
-                       BT_DBG("event type %d", event_info->event_type);
-               __rfcomm_server_disconnect(info);
-       }
+       g_slist_foreach(info->rfcomm_conns, (GFunc)free_rfcomm_conn, info);
 
        g_free(info->path);
        g_free(info->uuid);
@@ -473,7 +561,7 @@ BT_EXPORT_API int bluetooth_rfcomm_create_socket_ex(const char *uuid, const char
 }
 
 
-BT_EXPORT_API int bluetooth_rfcomm_remove_socket(int socket_fd)
+BT_EXPORT_API int bluetooth_rfcomm_remove_socket(int id)
 {
 #ifdef RFCOMM_DIRECT
        rfcomm_info_t *info;
@@ -489,15 +577,15 @@ BT_EXPORT_API int bluetooth_rfcomm_remove_socket(int socket_fd)
                return BLUETOOTH_ERROR_PERMISSION_DEINED;
        }
 
-       if (socket_fd < 0) {
-               BT_ERR("Invalid FD");
+       if (id < 0) {
+               BT_ERR("Invalid ID");
                return BLUETOOTH_ERROR_INVALID_PARAM;
        }
 
 #ifdef RFCOMM_DIRECT
-       BT_INFO("RFCOMM Remove socket request from app, fd=[%d]", socket_fd);
+       BT_INFO("RFCOMM Remove socket request from app, ID [%d]", id);
 
-       info = __find_rfcomm_info_with_id(socket_fd);
+       info = __find_rfcomm_info_with_id(id);
        if (info == NULL)
                return BLUETOOTH_ERROR_INVALID_PARAM;
 
@@ -512,7 +600,7 @@ BT_EXPORT_API int bluetooth_rfcomm_remove_socket(int socket_fd)
        BT_INIT_PARAMS();
        BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
 
-       g_array_append_vals(in_param1, &socket_fd, sizeof(int));
+       g_array_append_vals(in_param1, &id, sizeof(int));
 
        result = _bt_send_request(BT_BLUEZ_SERVICE, BT_RFCOMM_REMOVE_SOCKET,
                in_param1, in_param2, in_param3, in_param4, &out_param);
@@ -520,7 +608,7 @@ BT_EXPORT_API int bluetooth_rfcomm_remove_socket(int socket_fd)
        BT_DBG("result: %x", result);
 
        if (result == BLUETOOTH_ERROR_NONE) {
-               _bt_remove_server(socket_fd);
+               _bt_remove_server(id);
        }
 
        BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
@@ -564,6 +652,7 @@ BT_EXPORT_API int bluetooth_rfcomm_server_disconnect(int socket_fd)
 {
 #ifdef RFCOMM_DIRECT
        rfcomm_info_t *info;
+       rfcomm_conn_t *conn;
 
        char address[20];
 
@@ -577,19 +666,24 @@ BT_EXPORT_API int bluetooth_rfcomm_server_disconnect(int socket_fd)
        if (info == NULL)
                return BLUETOOTH_ERROR_INVALID_PARAM;
 
-       if (info->data_io == NULL)
+       conn = __find_rfcomm_conn_with_fd(info, socket_fd);
+       if (conn == NULL)
+               return BLUETOOTH_ERROR_INVALID_PARAM;
+
+       if (conn->watch_id == 0 || conn->disconnected)
                return BLUETOOTH_ERROR_NOT_CONNECTED;
 
-       g_io_channel_shutdown(info->data_io, TRUE, NULL);
-       g_io_channel_unref(info->data_io);
-       info->data_io = NULL;
+       close(conn->fd);
+       conn->disconnected = TRUE;
+
+       _bt_convert_addr_type_to_string(address, conn->addr.addr);
 
-       _bt_convert_addr_type_to_string(address, info->addr.addr);
        BT_DBG("Address %s", address);
        _bt_disconnect_profile(address, info->uuid, NULL, NULL);
 
-       info->disconnect_idle_id = g_idle_add((GSourceFunc)
-                                                       __rfcomm_server_disconnect, info);
+       if (info->disconnect_idle_id == 0)
+               info->disconnect_idle_id = g_idle_add(
+                               (GSourceFunc)__rfcomm_server_disconnect, info);
        BT_DBG("-");
 
        return BLUETOOTH_ERROR_NONE;
@@ -649,25 +743,28 @@ BT_EXPORT_API gboolean bluetooth_rfcomm_is_server_uuid_available(const char *uui
 BT_EXPORT_API int bluetooth_rfcomm_server_is_connected(const bluetooth_device_address_t *device_address, gboolean *connected)
 {
        GSList *l;
+       GSList *ll;
        rfcomm_info_t *info;
-       char connected_addr[BT_ADDRESS_STRING_SIZE] = { 0 };
-       char input_addr[BT_ADDRESS_STRING_SIZE] = { 0 };
+       rfcomm_conn_t *conn;
 
        BT_CHECK_PARAMETER(device_address, return);
        BT_CHECK_PARAMETER(connected, return);
 
-       _bt_convert_addr_type_to_string(input_addr, (unsigned char *)device_address->addr);
-
        *connected = FALSE;
 
-       for (l = rfcomm_nodes; l != NULL; l = l->next) {
+       for (l = rfcomm_nodes; l; l = l->next) {
                info = l->data;
 
-               if (info == NULL)
+               if (info == NULL || info->rfcomm_conns == NULL)
                        continue;
-               _bt_convert_addr_type_to_string(connected_addr, info->addr.addr);
 
-               if (g_strcmp0(connected_addr, input_addr) == 0) {
+               for (ll = info->rfcomm_conns; ll; ll = ll->next) {
+                       conn = ll->data;
+
+                       if (memcmp(device_address, &conn->addr,
+                                       sizeof(bluetooth_device_address_t)))
+                               continue;
+
                        *connected = TRUE;
                        return BLUETOOTH_ERROR_NONE;
                }
@@ -676,7 +773,7 @@ BT_EXPORT_API int bluetooth_rfcomm_server_is_connected(const bluetooth_device_ad
        return BLUETOOTH_ERROR_NONE;
 }
 
-BT_EXPORT_API int bluetooth_rfcomm_listen_and_accept(int socket_fd, int max_pending_connection)
+BT_EXPORT_API int bluetooth_rfcomm_listen_and_accept(int id, int max_pending_connection)
 {
 #ifdef RFCOMM_DIRECT
        rfcomm_info_t *info;
@@ -686,8 +783,8 @@ BT_EXPORT_API int bluetooth_rfcomm_listen_and_accept(int socket_fd, int max_pend
 #endif
 
        BT_CHECK_ENABLED(return);
-       if (socket_fd < 0) {
-               BT_ERR("Invalid FD");
+       if (id < 0) {
+               BT_ERR("Invalid ID");
                return BLUETOOTH_ERROR_INVALID_PARAM;
        }
 
@@ -701,7 +798,7 @@ BT_EXPORT_API int bluetooth_rfcomm_listen_and_accept(int socket_fd, int max_pend
 #ifdef RFCOMM_DIRECT
        BT_INFO("RFCOMM Listen & accept from app");
 
-       info = __find_rfcomm_info_with_id(socket_fd);
+       info = __find_rfcomm_info_with_id(id);
        if (info == NULL)
                return BLUETOOTH_ERROR_INVALID_PARAM;
 
@@ -723,7 +820,7 @@ BT_EXPORT_API int bluetooth_rfcomm_listen_and_accept(int socket_fd, int max_pend
        BT_INIT_PARAMS();
        BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
 
-       g_array_append_vals(in_param1, &socket_fd, sizeof(int));
+       g_array_append_vals(in_param1, &id, sizeof(int));
        g_array_append_vals(in_param2, &max_pending_connection, sizeof(int));
        g_array_append_vals(in_param3, &native_service, sizeof(gboolean));
 
@@ -738,7 +835,9 @@ BT_EXPORT_API int bluetooth_rfcomm_listen_and_accept(int socket_fd, int max_pend
 #endif
 }
 
-BT_EXPORT_API int bluetooth_rfcomm_listen_and_accept_ex(const char *uuid, int max_pending_connection, const char *bus_name, const char *path)
+BT_EXPORT_API int bluetooth_rfcomm_listen_and_accept_ex(const char *uuid,
+                                       int max_pending_connection,
+                                       const char *bus_name, const char *path)
 {
 #ifdef RFCOMM_DIRECT
        rfcomm_info_t *info;
@@ -777,7 +876,7 @@ BT_EXPORT_API int bluetooth_rfcomm_listen_and_accept_ex(const char *uuid, int ma
 #endif
 }
 
-BT_EXPORT_API int bluetooth_rfcomm_listen(int socket_fd, int max_pending_connection)
+BT_EXPORT_API int bluetooth_rfcomm_listen(int id, int max_pending_connection)
 {
 #ifdef RFCOMM_DIRECT
        rfcomm_info_t *info;
@@ -787,6 +886,10 @@ BT_EXPORT_API int bluetooth_rfcomm_listen(int socket_fd, int max_pending_connect
 #endif
 
        BT_CHECK_ENABLED(return);
+       if (id < 0) {
+               BT_ERR("Invalid ID");
+               return BLUETOOTH_ERROR_INVALID_PARAM;
+       }
 
 #ifdef TIZEN_DPM_ENABLE
        if (_bt_check_dpm(BT_DPM_SPP, NULL) == BT_DPM_RESTRICTED) {
@@ -795,15 +898,10 @@ BT_EXPORT_API int bluetooth_rfcomm_listen(int socket_fd, int max_pending_connect
        }
 #endif
 
-       if (socket_fd < 0) {
-               BT_ERR("Invalid FD");
-               return BLUETOOTH_ERROR_INVALID_PARAM;
-       }
-
 #ifdef RFCOMM_DIRECT
        BT_INFO("RFCOMM Listen");
 
-       info = __find_rfcomm_info_with_id(socket_fd);
+       info = __find_rfcomm_info_with_id(id);
        if (info == NULL)
                return BLUETOOTH_ERROR_INVALID_PARAM;
 
@@ -823,13 +921,13 @@ BT_EXPORT_API int bluetooth_rfcomm_listen(int socket_fd, int max_pending_connect
                return result;
 
        return _bt_register_osp_server_in_agent(BT_RFCOMM_SERVER, info->uuid,
-                                               info->path, socket_fd);
+                                               info->path, id);
 
 #else
        BT_INIT_PARAMS();
        BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
 
-       g_array_append_vals(in_param1, &socket_fd, sizeof(int));
+       g_array_append_vals(in_param1, &id, sizeof(int));
        g_array_append_vals(in_param2, &max_pending_connection, sizeof(int));
        g_array_append_vals(in_param3, &native_service, sizeof(gboolean));
 
@@ -839,7 +937,7 @@ BT_EXPORT_API int bluetooth_rfcomm_listen(int socket_fd, int max_pending_connect
        BT_DBG("result: %x", result);
 
         if (result == BLUETOOTH_ERROR_NONE) {
-                _bt_add_server(socket_fd);
+                _bt_add_server(id);
         }
 
        BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
index 0e22c2e..b739577 100644 (file)
@@ -1311,7 +1311,7 @@ BT_EXPORT_API int bluetooth_telephony_init(bt_telephony_func_ptr cb,
 
        if (is_initialized == TRUE) {
                BT_ERR("Bluetooth telephony already initilized");
-               return BLUETOOTH_TELEPHONY_ERROR_ALREADY_INITIALIZED;
+               return BLUETOOTH_TELEPHONY_ERROR_NONE;
        }
 
        is_initialized = TRUE;
@@ -1326,7 +1326,7 @@ BT_EXPORT_API int bluetooth_telephony_init(bt_telephony_func_ptr cb,
        /* Call Path */
        snprintf(telephony_info.call_path, sizeof(telephony_info.call_path),
                                        CSD_CALL_APP_PATH, getpid());
-       BT_DBG("Call Path = %s", telephony_info.call_path);
+       BT_INFO("Call Path = %s", telephony_info.call_path);
        memset(telephony_info.address, 0x00, sizeof(telephony_info.address));
 
        if (__bluetooth_telephony_proxy_init()) {
index 79bd9f1..fb61b24 100644 (file)
@@ -174,8 +174,7 @@ extern "C" {
 
 #define BT_CHECK_ENABLED_INTERNAL(func) \
        do { \
-               if (_bt_check_enabled_internal() == FALSE) \
-               { \
+               if (_bt_check_enabled_internal() == FALSE) { \
                        BT_ERR("BT BREDR is not enabled"); \
                        func BLUETOOTH_ERROR_DEVICE_NOT_ENABLED; \
                } \
@@ -370,6 +369,8 @@ void _bt_rfcomm_server_free_all();
 gboolean _check_uuid_path(char *path, char *uuid);
 #endif
 
+void _bluetooth_hid_free_hid_info(void);
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
index fd8cefc..9c40c3b 100644 (file)
@@ -41,7 +41,10 @@ int _bt_sync_send_request(int service_type, int service_function,
 
 #define _bt_send_request(a, b, format ...) ( \
        { \
-       if (a == BT_BLUEZ_SERVICE || a == BT_OBEX_SERVICE) \
+       if ((a != BT_CHECK_PRIVILEGE && (a == BT_BLUEZ_SERVICE || a == BT_OBEX_SERVICE)) && \
+               (b != BT_GET_LOCAL_NAME && b != BT_GET_LOCAL_ADDRESS && \
+                b != BT_GET_BONDED_DEVICE && b != BT_IS_DEVICE_CONNECTED && \
+                b != BT_GET_BONDED_DEVICES && b != BT_GET_DISCOVERABLE_MODE)) \
                BT_INFO_C("Sync Request => type=%s, fn=%s(0x%x)", #a, #b, b); \
        else \
                BT_DBG("Sync Request => type=%s, fn=%s(0x%x)", #a, #b, b); \
@@ -56,7 +59,10 @@ int _bt_async_send_request(int service_type, int service_function,
 
 #define _bt_send_request_async(a, b, format ...) ( \
        { \
-       if (a == BT_BLUEZ_SERVICE || a == BT_OBEX_SERVICE) \
+       if ((a != BT_CHECK_PRIVILEGE && (a == BT_BLUEZ_SERVICE || a == BT_OBEX_SERVICE)) && \
+               (b != BT_GET_LOCAL_NAME && b != BT_GET_LOCAL_ADDRESS && \
+                b != BT_GET_BONDED_DEVICE && b != BT_IS_DEVICE_CONNECTED && \
+                b != BT_GET_BONDED_DEVICES && b != BT_GET_DISCOVERABLE_MODE)) \
                BT_INFO_C("Async Request => type=%s, fn=%s(0x%x)", #a, #b, b); \
        else \
                BT_DBG("Async Request => type=%s, fn=%s(0x%x)", #a, #b, b); \
index caeda68..fbd0d07 100644 (file)
@@ -799,6 +799,19 @@ int __bt_bluez_request(int function_name,
                }
                break;
        }
+       case BT_GET_IS_ALIAS_SET: {
+               bluetooth_device_address_t address = { {0} };
+               gboolean is_alias_set = FALSE;
+
+               __bt_service_get_parameters(in_param1,
+                               &address, sizeof(bluetooth_device_address_t));
+
+               result = _bt_is_alias_set(&address, &is_alias_set);
+               if (result == BLUETOOTH_ERROR_NONE)
+                       g_array_append_vals(*out_param1, &is_alias_set, sizeof(gboolean));
+
+               break;
+       }
        case BT_BOND_DEVICE: {
                bluetooth_device_address_t address = { {0} };
 
@@ -2826,6 +2839,7 @@ gboolean __bt_service_check_privilege(int function_name,
         case BT_IS_CONNECTABLE:
         case BT_GET_BONDED_DEVICES:
         case BT_GET_BONDED_DEVICE:
+       case BT_GET_IS_ALIAS_SET:
         case BT_IS_DEVICE_CONNECTED:
         case BT_GET_SPEAKER_GAIN:
         case BT_SET_SPEAKER_GAIN:
index fb4ac2c..4768de5 100644 (file)
@@ -400,7 +400,7 @@ int _bt_set_advertising(const char *sender, int adv_handle, gboolean enable, gbo
                __bt_register_adv_slot_owner(sender, adv_handle, slot_id);
 
        le_adv_slot[slot_id].is_advertising = enable;
-       BT_INFO("Set advertising [%d]", enable);
+       BT_INFO_C("### Set advertising [%d]", enable);
 
        if (ret)
                g_variant_unref(ret);
@@ -467,7 +467,7 @@ int _bt_set_custom_advertising(const char *sender, int adv_handle,
        max = params->interval_max / BT_ADV_INTERVAL_SPLIT;
 
        ret = g_dbus_proxy_call_sync(proxy, "SetAdvertisingParameters",
-                       g_variant_new("(uuuui)", min, max, 
+                       g_variant_new("(uuuui)", min, max,
                        params->filter_policy, params->type,
                        slot_id), G_DBUS_CALL_FLAGS_NONE,
                        -1, NULL, &error);
@@ -574,6 +574,9 @@ int _bt_hold_current_advertising(void)
 
                le_adv_slot[0].hold_timer_id = g_timeout_add(2000,
                                __bt_hold_current_advertising_timeout_cb, NULL);
+       } else {
+               BT_ERR("It's NOT advertising");
+               return BLUETOOTH_ERROR_NOT_IN_OPERATION;
        }
 
        return BLUETOOTH_ERROR_NONE;
@@ -2279,7 +2282,7 @@ int _bt_le_set_data_length(bluetooth_device_address_t *device_address,
                return BLUETOOTH_ERROR_INTERNAL;
        }
 
-       conn = _bt_get_system_gconn();
+       conn = _bt_gdbus_get_system_gconn();
        if (conn == NULL) {
                BT_ERR("conn == NULL");
                g_free(device_path);
index f58325c..5242f0c 100644 (file)
@@ -96,7 +96,7 @@ GDBusProxy *_bt_init_core_proxy(void)
        GDBusProxy *proxy;
        GDBusConnection *conn;
 
-       conn = _bt_get_system_gconn();
+       conn = _bt_gdbus_get_system_gconn();
        if (!conn)
                return NULL;
 
@@ -301,7 +301,7 @@ static int __bt_get_bonded_device_info(gchar *device_path,
        BT_CHECK_PARAMETER(device_path, return);
        BT_CHECK_PARAMETER(dev_info, return);
 
-       conn = _bt_get_system_gconn();
+       conn = _bt_gdbus_get_system_gconn();
        retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
 
        device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
@@ -345,8 +345,6 @@ static int __bt_get_bonded_device_info(gchar *device_path,
                } else if (!g_strcmp0(key, "Name")) {
                        if (!name)
                                g_variant_get(value, "s", &name);
-               } else if(!g_strcmp0(key, "IsAliasSet")) {
-                       dev_info->is_alias_set = g_variant_get_boolean(value);
                } else if (!g_strcmp0(key, "Class")) {
                        cod = g_variant_get_uint32(value);
                } else if (!g_strcmp0(key, "Connected")) {
@@ -662,7 +660,7 @@ void _bt_set_le_disabled(int result)
 
        /* Send disabled event */
        _bt_send_event(BT_LE_ADAPTER_EVENT, BLUETOOTH_EVENT_LE_DISABLED,
-                       g_variant_new_int32(result));
+                       g_variant_new("(i)", result));
 }
 
 void *_bt_get_adapter_agent(void)
@@ -1025,6 +1023,31 @@ static gboolean __bt_adapter_enabled_cb(gpointer user_data)
 }
 #endif
 
+int _bt_enable_adapter_check_status(void)
+{
+       bt_status_t status = _bt_adapter_get_status();
+       bt_le_status_t le_status = _bt_adapter_get_le_status();
+
+       BT_DBG("");
+
+       if (status == BT_ACTIVATING) {
+               BT_ERR("Enabling in progress");
+               return BLUETOOTH_ERROR_IN_PROGRESS;
+       }
+
+       if (status == BT_ACTIVATED) {
+               BT_ERR("Already enabled");
+               return BLUETOOTH_ERROR_DEVICE_ALREADY_ENABLED;
+       }
+
+       if (status == BT_DEACTIVATING || le_status == BT_LE_DEACTIVATING) {
+               BT_ERR("Disabling in progress");
+               return BLUETOOTH_ERROR_DEVICE_BUSY;
+       }
+
+       return BLUETOOTH_ERROR_NONE;
+}
+
 int _bt_enable_adapter(void)
 {
        GDBusProxy *proxy;
@@ -1138,7 +1161,7 @@ static gboolean __bt_disconnect_all(void)
 
        BT_DBG("");
 
-       conn = _bt_get_system_gconn();
+       conn = _bt_gdbus_get_system_gconn();
 
        device_list = g_array_new(FALSE, FALSE, sizeof(gchar));
 
@@ -1270,6 +1293,25 @@ int _bt_disable_cb(void)
        return BLUETOOTH_ERROR_NONE;
 }
 
+int _bt_disable_adapter_check_status(void)
+{
+       bt_status_t status = _bt_adapter_get_status();
+
+       BT_DBG("");
+
+       if (status == BT_DEACTIVATING) {
+               BT_DBG("Disabling in progress");
+               return BLUETOOTH_ERROR_IN_PROGRESS;
+       }
+
+       if (status == BT_DEACTIVATED) {
+               BT_DBG("Already disabled");
+               return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
+       }
+
+       return BLUETOOTH_ERROR_NONE;
+}
+
 int _bt_disable_adapter(void)
 {
        BT_DBG("+");
@@ -2436,7 +2478,7 @@ int _bt_get_bonded_devices(GArray **dev_list)
        GVariantIter *iter = NULL;
        GError *error = NULL;
 
-       conn = _bt_get_system_conn();
+       conn = _bt_gdbus_get_system_gconn();
        retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
 
        manager_proxy = _bt_get_manager_proxy();
@@ -2484,7 +2526,7 @@ int _bt_get_profile_connected_devices(char *profile_uuid, GArray **addr_list)
        GDBusProxy *device_proxy = NULL;
        gboolean is_connected = FALSE;
 
-       conn = _bt_get_system_conn();
+       conn = _bt_gdbus_get_system_gconn();
        retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
 
        manager_proxy = _bt_get_manager_proxy();
@@ -2603,6 +2645,75 @@ int _bt_get_bonded_device_info(bluetooth_device_address_t *device_address,
        return ret;
 }
 
+int _bt_is_alias_set(bluetooth_device_address_t *device_address, gboolean *is_alias_set)
+{
+       char *object_path = NULL;
+       char address[BT_ADDRESS_STRING_SIZE] = { 0 };
+       gboolean alias_set = FALSE;
+
+       GDBusConnection *conn;
+       GDBusProxy *device_proxy;
+       GError *error = NULL;
+       GVariant *result = NULL;
+       GVariant *temp = NULL;
+
+
+       BT_CHECK_PARAMETER(device_address, return);
+       BT_CHECK_PARAMETER(is_alias_set, return);
+
+       _bt_convert_addr_type_to_string(address, device_address->addr);
+
+       object_path = _bt_get_device_object_path(address);
+       retv_if(object_path == NULL, BLUETOOTH_ERROR_NOT_PAIRED);
+
+       conn = _bt_gdbus_get_system_gconn();
+       if (conn == NULL) {
+               g_free(object_path);
+               return BLUETOOTH_ERROR_INTERNAL;
+       }
+
+       device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
+                       NULL,
+                       BT_BLUEZ_NAME,
+                       object_path,
+                       BT_PROPERTIES_INTERFACE,
+                       NULL, NULL);
+       if (device_proxy == NULL) {
+               g_free(object_path);
+               return BLUETOOTH_ERROR_INTERNAL;
+       }
+
+       result = g_dbus_proxy_call_sync(device_proxy, "Get",
+                       g_variant_new("(ss)", BT_DEVICE_INTERFACE, "IsAliasSet"),
+                       G_DBUS_CALL_FLAGS_NONE,
+                       -1,
+                       NULL,
+                       &error);
+
+       if (!result) {
+               BT_ERR("Error occured in Proxy call");
+               if (error != NULL) {
+                       BT_ERR("Getting is_alias_set property failed: [%s]\n", error->message);
+                       g_error_free(error);
+               }
+               g_object_unref(device_proxy);
+               g_free(object_path);
+               return BLUETOOTH_ERROR_INTERNAL;
+       }
+
+       g_variant_get(result, "(v)", &temp);
+       alias_set = g_variant_get_boolean(temp);
+       *is_alias_set = alias_set;
+       BT_DBG("address: [%s] | *is_alias_set: %s", address, *is_alias_set ? "TRUE" : "FALSE");
+       g_variant_unref(temp);
+       g_variant_unref(result);
+       g_object_unref(device_proxy);
+
+       g_free(object_path);
+
+       return BLUETOOTH_ERROR_NONE;
+}
+
 int _bt_get_timeout_value(int *timeout)
 {
        time_t current_time;
@@ -2771,19 +2882,19 @@ int _bt_service_set_alarm(int timeout, bt_set_alarm_cb call_back, void *user_dat
        int result = BLUETOOTH_ERROR_NONE;
        bt_service_alarm_t *alarm = NULL;
 
-       if(!call_back || !alarm_id)
+       if (!call_back || !alarm_id)
                return BLUETOOTH_ERROR_INVALID_PARAM;
 
        if (!alarm_mgr.is_alarm_initialized) {
                result = alarmmgr_init("bt-service");
                if (result != 0) {
-                       BT_ERR("Failed to initialize alarm = %d",result);
+                       BT_ERR("Failed to initialize alarm = %d", result);
                        result = BLUETOOTH_ERROR_INTERNAL;
                        goto finish;
                }
                result = alarmmgr_set_cb(alarm_cb, NULL);
                if (result != 0) {
-                       BT_ERR("Failed to set the callback = %d",result);
+                       BT_ERR("Failed to set the callback = %d", result);
                        result = BLUETOOTH_ERROR_INTERNAL;
                        goto finish;
                }
@@ -2791,13 +2902,13 @@ int _bt_service_set_alarm(int timeout, bt_set_alarm_cb call_back, void *user_dat
        }
 
        alarm = g_malloc0(sizeof(bt_service_alarm_t));
-       if(!alarm)
+       if (!alarm)
                return BLUETOOTH_ERROR_MEMORY_ALLOCATION;
 
        result = alarmmgr_add_alarm(ALARM_TYPE_VOLATILE, timeout,
                                                0, NULL, alarm_id);
        if (result != 0) {
-               BT_ERR("Failed to create alarm error = %d",result);
+               BT_ERR("Failed to create alarm error = %d", result);
                result = BLUETOOTH_ERROR_INTERNAL;
                g_free(alarm);
                goto finish;
@@ -2909,37 +3020,23 @@ static gboolean _bt_adapter_request_delayed_cb(gpointer user_data)
 
 int _bt_adapter_request_delayed(int function)
 {
-       bt_status_t status = _bt_adapter_get_status();
-       bt_le_status_t le_status = _bt_adapter_get_le_status();
+       int ret;
 
        switch (function) {
        case BT_ENABLE_ADAPTER:
-               if (status == BT_ACTIVATING) {
-                       BT_ERR("Enabling in progress");
-                       return BLUETOOTH_ERROR_IN_PROGRESS;
-               }
-
-               if (status == BT_ACTIVATED) {
-                       BT_ERR("Already enabled");
-                       return BLUETOOTH_ERROR_DEVICE_ALREADY_ENABLED;
-               }
-
-               if (status == BT_DEACTIVATING || le_status == BT_LE_DEACTIVATING) {
-                       BT_ERR("Disabling in progress");
-                       return BLUETOOTH_ERROR_DEVICE_BUSY;
-               }
+               ret = _bt_enable_adapter_check_status();
+               if (ret == BLUETOOTH_ERROR_NONE)
+                       _bt_adapter_set_status(BT_ACTIVATING);
+               else
+                       return ret;
 
                break;
        case BT_DISABLE_ADAPTER:
-               if (status == BT_DEACTIVATING) {
-                       BT_DBG("Disabling in progress");
-                       return BLUETOOTH_ERROR_IN_PROGRESS;
-               }
-
-               if (status == BT_DEACTIVATED) {
-                       BT_DBG("Already disabled");
-                       return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
-               }
+               ret = _bt_disable_adapter_check_status();
+               if (ret == BLUETOOTH_ERROR_NONE)
+                       _bt_adapter_set_status(BT_DEACTIVATING);
+               else
+                       return ret;
 
                break;
        default:
index c9948b7..52856c4 100644 (file)
@@ -145,7 +145,7 @@ void _bt_audio_check_pending_connect()
                _bt_audio_connect(pdata->req_id,
                                BT_AUDIO_A2DP,
                                &device_address,
-                               pdata->out_param);
+                               NULL);
 
                g_free(pdata->address);
                g_free(pdata);
@@ -179,7 +179,6 @@ static void __bt_audio_request_cb(GDBusProxy *proxy, GAsyncResult *res,
        }
 
        if (func_data->pending != BT_PENDING_NONE && g_error == NULL) {
-
                bluetooth_device_address_t device_address;
                _bt_convert_addr_string_to_type(device_address.addr,
                                        func_data->address);
@@ -191,20 +190,16 @@ static void __bt_audio_request_cb(GDBusProxy *proxy, GAsyncResult *res,
 
                                pdata = g_new0(bt_audio_function_data_t, 1);
                                pdata->req_id = func_data->req_id;
-                               pdata->out_param = func_data->out_param;
                                pdata->address = strdup(func_data->address);
                                pdata->pending = func_data->pending;
                        } else
                                goto check_req_info;
 
                } else {
-
                        if (_bt_is_service_connected(func_data->address
                                                        , BT_AUDIO_HSP)) {
                                _bt_audio_disconnect(func_data->req_id,
-                                       BT_AUDIO_HSP,
-                                       &device_address,
-                                       func_data->out_param);
+                                       BT_AUDIO_HSP, &device_address, NULL);
                        } else
                                goto check_req_info;
                }
@@ -243,7 +238,7 @@ check_req_info:
                _bt_convert_addr_string_to_type(device_address.addr,
                                g_wait_data->address);
                _bt_audio_connect(g_wait_data->req_id, g_wait_data->type,
-                               &device_address, g_wait_data->out_param1);
+                               &device_address, NULL);
        }
 
        /* Event will be sent by the event reciever */
@@ -364,7 +359,7 @@ gboolean __bt_is_companion_device(const char *addr)
 #endif
 
 static int __bt_is_headset_connected(int type, int req_id,
-                               const char *address, GArray *out_param1)
+                               const char *address)
 {
        gboolean connected = FALSE;
        char connected_address[BT_ADDRESS_STRING_SIZE + 1];
@@ -431,7 +426,6 @@ static int __bt_is_headset_connected(int type, int req_id,
                        g_wait_data->req_id = req_id;
                        g_wait_data->type = type;
                        g_wait_data->ag_flag = FALSE;
-                       g_wait_data->out_param1 = out_param1;
 
                        /* Set disconnection type */
                        __bt_set_headset_disconnection_type(connected_address);
@@ -441,8 +435,6 @@ static int __bt_is_headset_connected(int type, int req_id,
        return value;
 }
 
-
-
 static int __bt_is_headset_connecting(int type)
 {
        bt_connected_headset_data_t *connected_device = NULL;
@@ -461,7 +453,6 @@ static int __bt_is_headset_connecting(int type)
        return BLUETOOTH_ERROR_NONE;
 }
 
-
 int __bt_is_headset_disconnecting(int type)
 {
        bt_connected_headset_data_t *connected_device = NULL;
@@ -481,7 +472,6 @@ int __bt_is_headset_disconnecting(int type)
        return BLUETOOTH_ERROR_NONE;
 }
 
-
 void _bt_set_audio_wait_data_flag(gboolean flag)
 {
        BT_DBG("_bt_set_audio_wait_data_flag \n");
@@ -701,7 +691,7 @@ int _bt_audio_connect(int request_id, int type,
        adapter_proxy = _bt_get_adapter_proxy();
        retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
 
-       g_conn = _bt_get_system_gconn();
+       g_conn = _bt_gdbus_get_system_gconn();
        retv_if(g_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
 
        _bt_convert_addr_type_to_string(address, device_address->addr);
@@ -717,7 +707,6 @@ int _bt_audio_connect(int request_id, int type,
        func_data->req_id = request_id;
        func_data->type = type;
        func_data->pending = BT_PENDING_NONE;
-       func_data->out_param = out_param1;
 
        result = _bt_get_restrict_profile(device_address, RESTRICTED_PROFILE_HFP_HS, &hfp_hs_restricted);
        if (result != BLUETOOTH_ERROR_NONE)
@@ -788,7 +777,7 @@ int _bt_audio_connect(int request_id, int type,
        }
        BT_INFO("Connecting to service %s", uuid);
 
-       value = __bt_is_headset_connected(type, request_id, address, out_param1);
+       value = __bt_is_headset_connected(type, request_id, address);
 
        if (value == BLUETOOTH_ERROR_ALREADY_CONNECT) {
                return BLUETOOTH_ERROR_ALREADY_CONNECT;
@@ -816,10 +805,14 @@ int _bt_audio_connect(int request_id, int type,
                return BLUETOOTH_ERROR_IN_PROGRESS;
        }
 
+       if (out_param1)
+               g_array_free(out_param1, TRUE);
+
        return BLUETOOTH_ERROR_NONE;
 fail:
-       g_array_append_vals(out_param1, address,
-                       BT_ADDRESS_STR_LEN);
+       if (out_param1 != NULL)
+               g_array_append_vals(out_param1, address,
+                               BT_ADDRESS_STR_LEN);
 
        return result;
 }
@@ -843,7 +836,7 @@ int _bt_audio_disconnect(int request_id, int type,
        adapter_proxy = _bt_get_adapter_proxy();
        retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
 
-       g_conn = _bt_get_system_gconn();
+       g_conn = _bt_gdbus_get_system_gconn();
        retv_if(g_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
 
        _bt_convert_addr_type_to_string(address, device_address->addr);
@@ -858,7 +851,6 @@ int _bt_audio_disconnect(int request_id, int type,
        func_data->address = g_strdup(address);
        func_data->req_id = request_id;
        func_data->pending = BT_PENDING_NONE;
-       func_data->out_param = out_param1;
        func_data->type = type;
 
        switch (type) {
@@ -927,6 +919,9 @@ int _bt_audio_disconnect(int request_id, int type,
        }
        _bt_add_headset_to_list(type, BT_STATE_DISCONNECTING, address);
 
+       if (out_param1)
+               g_array_free(out_param1, TRUE);
+
        return BLUETOOTH_ERROR_NONE;
 fail:
        if (out_param1 != NULL)
@@ -978,7 +973,7 @@ int _bt_hf_connect(int request_id,
                goto fail;
        }
 
-       g_conn = _bt_get_system_gconn();
+       g_conn = _bt_gdbus_get_system_gconn();
        if (g_conn == NULL) {
                result = BLUETOOTH_ERROR_INTERNAL;
                goto fail;
@@ -1016,6 +1011,9 @@ int _bt_hf_connect(int request_id,
                return ret;
        }
        g_free(uuid);
+       if (out_param1)
+               g_array_free(out_param1, TRUE);
+
        return BLUETOOTH_ERROR_NONE;
 fail:
        if (out_param1 != NULL)
@@ -1048,7 +1046,7 @@ int _bt_hf_disconnect(int request_id,
                goto fail;
        }
 
-       g_conn = _bt_get_system_gconn();
+       g_conn = _bt_gdbus_get_system_gconn();
        if (g_conn == NULL) {
                result = BLUETOOTH_ERROR_INTERNAL;
                goto fail;
@@ -1077,6 +1075,9 @@ int _bt_hf_disconnect(int request_id,
                return ret;
        }
        g_free(uuid);
+       if (out_param1)
+               g_array_free(out_param1, TRUE);
+
        return BLUETOOTH_ERROR_NONE;
 fail:
        if (out_param1 != NULL)
@@ -1093,7 +1094,7 @@ int _bt_audio_set_content_protect(gboolean status)
 
        BT_DBG("+\n");
 
-       conn = _bt_get_system_gconn();
+       conn = _bt_gdbus_get_system_gconn();
        retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
 
        BT_DBG("Content Protection status = [%d]", status);
@@ -1133,8 +1134,7 @@ static void __bt_auto_connect_request_cb(GDBusProxy *proxy, GAsyncResult *res,
                g_dbus_error_strip_remote_error(err);
                BT_INFO("Auto_connect_request Dbus Call Error: %s", err->message);
 
-               if (strcmp("Host is down", err->message))
-               {
+               if (strcmp("Host is down", err->message)) {
                        BT_INFO("Fail reason is not 'Host Down'. Terminate auto connect");
                        _bt_audio_stop_auto_connect();
                        vconf_set_str(BT_LAST_CONNECTED_DEVICE, "");
index f443319..ba406f0 100644 (file)
@@ -116,7 +116,7 @@ static int __bt_media_send_control_msg(const char *name)
 
        BT_INFO("Command [%s]", name);
 
-       conn = _bt_get_system_conn();
+       conn = _bt_gdbus_get_system_gconn();
        retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
 
        control_path = __bt_get_control_device_path();
@@ -207,7 +207,7 @@ GDBusProxy *__bt_get_control_properties_proxy(void)
        retv_if(control_path == NULL, NULL);
        BT_DBG("control_path = %s", control_path);
 
-       conn = _bt_get_system_conn();
+       conn = _bt_gdbus_get_system_gconn();
        retv_if(conn == NULL, NULL);
 
        proxy = g_dbus_proxy_new_sync(conn,
@@ -389,7 +389,7 @@ int _bt_avrcp_control_get_property(int type, unsigned int *value)
                        case SHUFFLE:
                        case SCAN:
                        case STATUS:
-                               name =(char *)g_variant_get_data(reply);
+                               name = (char *)g_variant_get_data(reply);
                                if (name)
                                        *value = __bt_media_attrval_to_val(type, name);
                                BT_INFO("Type[%s] and Value[%s]", __bt_media_type_to_str(type), name);
@@ -483,15 +483,15 @@ static int __bt_avrcp_control_parse_properties(
                        BT_DBG("Value : %s ", value_string);
                        metadata->title = g_strdup(value_string);
                } else if (strcasecmp(key, "Artist") == 0) {
-                       value_string =(char *)g_variant_get_string(value, NULL);
+                       value_string = (char *)g_variant_get_string(value, NULL);
                        BT_DBG("Value : %s ", value_string);
                        metadata->artist = g_strdup(value_string);
                } else if (strcasecmp(key, "Album") == 0) {
-                       value_string =(char *)g_variant_get_string(value, NULL);
+                       value_string = (char *)g_variant_get_string(value, NULL);
                        BT_DBG("Value : %s ", value_string);
                        metadata->album = g_strdup(value_string);
                } else if (strcasecmp(key, "Genre") == 0) {
-                       value_string =(char *)g_variant_get_string(value, NULL);
+                       value_string = (char *)g_variant_get_string(value, NULL);
                        BT_DBG("Value : %s ", value_string);
                        metadata->genre = g_strdup(value_string);
                } else if (strcasecmp(key, "Duration") == 0) {
@@ -535,7 +535,7 @@ int _bt_avrcp_control_get_track_info(media_metadata_attributes_t *metadata)
 
        retv_if(metadata == NULL, BLUETOOTH_ERROR_INTERNAL);
 
-       conn = _bt_get_system_conn();
+       conn = _bt_gdbus_get_system_gconn();
        retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
 
        control_path = __bt_get_control_device_path();
index c4e6e0d..cd6c898 100644 (file)
@@ -56,7 +56,6 @@ static bt_player_settinngs_t player_status[] = {
        { STATUS_INVALID, "" }
 };
 
-static GDBusConnection *bt_gdbus_conn = NULL;
 static guint avrcp_reg_id = 0;
 
 /* Introspection data exposed from bt-service */
@@ -247,6 +246,7 @@ static GDBusNodeInfo *__bt_avrcp_create_method_node_info
 int _bt_register_media_player(void)
 {
        BT_DBG("+");
+       GDBusConnection *g_conn;
        gchar *adapter_path;
        gboolean shuffle_status;
        gchar *path;
@@ -263,17 +263,15 @@ int _bt_register_media_player(void)
        player_settings.position = 0;
        shuffle_status = FALSE;
 
-       if (bt_gdbus_conn == NULL) {
-               bt_gdbus_conn = _bt_get_system_gconn();
-               retv_if(bt_gdbus_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-       }
+       g_conn = _bt_gdbus_get_system_gconn();
+       retv_if(g_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
 
        node_info = __bt_avrcp_create_method_node_info(
                                bt_avrcp_bluez_introspection_xml);
        if (node_info == NULL)
                return BLUETOOTH_ERROR_INTERNAL;
 
-       avrcp_reg_id = g_dbus_connection_register_object(bt_gdbus_conn,
+       avrcp_reg_id = g_dbus_connection_register_object(g_conn,
                                        BT_MEDIA_OBJECT_PATH,
                                        node_info->interfaces[0],
                                        &method_table,
@@ -289,7 +287,7 @@ int _bt_register_media_player(void)
        adapter_path = _bt_get_adapter_path();
        retv_if(adapter_path == NULL, BLUETOOTH_ERROR_INTERNAL);
 
-       proxy =  g_dbus_proxy_new_sync(bt_gdbus_conn,
+       proxy =  g_dbus_proxy_new_sync(g_conn,
                        G_DBUS_PROXY_FLAGS_NONE, NULL,
                        BT_BLUEZ_NAME, adapter_path,
                        BT_MEDIA_INTERFACE, NULL, &error);
@@ -348,8 +346,13 @@ int _bt_register_media_player(void)
 
 static void __bt_avrcp_unregister_object_path(void)
 {
+       GDBusConnection *g_conn;
+
+       g_conn = _bt_gdbus_get_system_gconn();
+       ret_if(g_conn == NULL);
+
        if (avrcp_reg_id > 0) {
-               g_dbus_connection_unregister_object(bt_gdbus_conn,
+               g_dbus_connection_unregister_object(g_conn,
                                                        avrcp_reg_id);
                avrcp_reg_id = 0;
        }
@@ -358,6 +361,7 @@ static void __bt_avrcp_unregister_object_path(void)
 int _bt_unregister_media_player(void)
 {
        BT_DBG("+");
+       GDBusConnection *g_conn;
        GDBusProxy *proxy;
        gchar *adapter_path;
        GVariant *ret;
@@ -365,15 +369,21 @@ int _bt_unregister_media_player(void)
        gchar *path;
        int result = BLUETOOTH_ERROR_NONE;
 
-       retv_if(bt_gdbus_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
        adapter_path = _bt_get_adapter_path();
        if (adapter_path == NULL) {
                result = BLUETOOTH_ERROR_INTERNAL;
                goto FAIL;
        }
 
-       proxy =  g_dbus_proxy_new_sync(bt_gdbus_conn,
+       g_conn = _bt_gdbus_get_system_gconn();
+       if (g_conn == NULL) {
+               BT_ERR("g_conn is NULL");
+               g_free(adapter_path);
+               result = BLUETOOTH_ERROR_INTERNAL;
+               goto FAIL;
+       }
+
+       proxy =  g_dbus_proxy_new_sync(g_conn,
                        G_DBUS_PROXY_FLAGS_NONE, NULL,
                        BT_BLUEZ_NAME, adapter_path,
                        BT_MEDIA_INTERFACE, NULL, &error);
@@ -413,11 +423,6 @@ int _bt_unregister_media_player(void)
 FAIL:
        __bt_avrcp_unregister_object_path();
 
-       if (bt_gdbus_conn) {
-               g_object_unref(bt_gdbus_conn);
-               bt_gdbus_conn = NULL;
-       }
-
        BT_DBG("-");
        return result;
 }
@@ -426,7 +431,7 @@ int _bt_avrcp_set_track_info(media_metadata_attributes_t *meta_data)
 {
        BT_DBG("+");
        char *interface = BT_MEDIA_PLAYER_INTERFACE;
-       GDBusConnection *conn;
+       GDBusConnection *g_conn;
        GError *error = NULL;
        GVariantBuilder *builder = NULL;
        GVariantBuilder *inner_builder = NULL;
@@ -435,8 +440,8 @@ int _bt_avrcp_set_track_info(media_metadata_attributes_t *meta_data)
 
        retv_if(meta_data == NULL, BLUETOOTH_ERROR_INTERNAL);
 
-       conn = bt_gdbus_conn;
-       retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
+       g_conn = _bt_gdbus_get_system_gconn();;
+       retv_if(g_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
 
        builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
        inner_builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
@@ -469,7 +474,7 @@ int _bt_avrcp_set_track_info(media_metadata_attributes_t *meta_data)
        g_variant_builder_add(builder, "{sv}",
                "Metadata", g_variant_new("a{sv}", inner_builder));
 
-       ret = g_dbus_connection_emit_signal(conn, NULL, BT_MEDIA_OBJECT_PATH,
+       ret = g_dbus_connection_emit_signal(g_conn, NULL, BT_MEDIA_OBJECT_PATH,
                                DBUS_INTERFACE_PROPERTIES,
                                "PropertiesChanged",
                                g_variant_new("(sa{sv})",
@@ -494,20 +499,20 @@ int _bt_avrcp_set_track_info(media_metadata_attributes_t *meta_data)
 int _bt_avrcp_set_interal_property(int type, media_player_settings_t *properties)
 {
        BT_DBG("+");
-       GDBusConnection *conn;
+       GDBusConnection *g_conn;
        int value;
        media_metadata_attributes_t meta_data;
        gboolean shuffle;
        GVariantBuilder *builder = NULL;
        GVariant *children[1];
 
-       conn = bt_gdbus_conn;
-       retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
+       g_conn = _bt_gdbus_get_system_gconn();;
+       retv_if(g_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
 
        switch (type) {
        case REPEAT:
                value = properties->repeat;
-               if (!__bt_media_emit_property_changed(conn, BT_MEDIA_OBJECT_PATH,
+               if (!__bt_media_emit_property_changed(g_conn, BT_MEDIA_OBJECT_PATH,
                                BT_MEDIA_PLAYER_INTERFACE, "LoopStatus",
                                g_variant_new_string(loopstatus_settings[value].property))) {
                        BT_ERR("Error sending the PropertyChanged signal \n");
@@ -521,7 +526,7 @@ int _bt_avrcp_set_interal_property(int type, media_player_settings_t *properties
                else
                        shuffle = TRUE;
 
-               if (!__bt_media_emit_property_changed(conn, BT_MEDIA_OBJECT_PATH,
+               if (!__bt_media_emit_property_changed(g_conn, BT_MEDIA_OBJECT_PATH,
                                BT_MEDIA_PLAYER_INTERFACE, "Shuffle",
                                g_variant_new_boolean(shuffle))) {
                        BT_ERR("Error sending the PropertyChanged signal \n");
@@ -530,7 +535,7 @@ int _bt_avrcp_set_interal_property(int type, media_player_settings_t *properties
                break;
        case STATUS:
                value = properties->status;
-               if (!__bt_media_emit_property_changed(conn, BT_MEDIA_OBJECT_PATH,
+               if (!__bt_media_emit_property_changed(g_conn, BT_MEDIA_OBJECT_PATH,
                                BT_MEDIA_PLAYER_INTERFACE, "PlaybackStatus",
                                g_variant_new_string(player_status[value].property))) {
                        BT_ERR("Error sending the PropertyChanged signal \n");
@@ -539,7 +544,7 @@ int _bt_avrcp_set_interal_property(int type, media_player_settings_t *properties
                break;
        case POSITION:
                value = properties->position;
-               if (!__bt_media_emit_property_changed(conn, BT_MEDIA_OBJECT_PATH,
+               if (!__bt_media_emit_property_changed(g_conn, BT_MEDIA_OBJECT_PATH,
                                BT_MEDIA_PLAYER_INTERFACE, "Position",
                                g_variant_new_uint32(value))) {
                        BT_ERR("Error sending the PropertyChanged signal \n");
@@ -573,9 +578,9 @@ int _bt_avrcp_set_interal_property(int type, media_player_settings_t *properties
                                "xesam:trackNumber", g_variant_new_int32(meta_data.number));
 
                g_variant_builder_add(builder, "{sv}",
-                               "mpris:lenght", g_variant_new_int64(meta_data.duration));
+                               "mpris:length", g_variant_new_int64(meta_data.duration));
 
-               if (!__bt_media_emit_property_changed(conn, BT_MEDIA_OBJECT_PATH,
+               if (!__bt_media_emit_property_changed(g_conn, BT_MEDIA_OBJECT_PATH,
                                BT_MEDIA_PLAYER_INTERFACE, "Metadata",
                                g_variant_new("a{sv}", builder))) {
                        BT_ERR("Error sending the PropertyChanged signal \n");
index 4b43c34..cf00e0d 100644 (file)
@@ -45,25 +45,23 @@ static void *net_conn;
 
 static GDBusProxy *adapter_properties_proxy;
 
-static GDBusConnection *system_gconn = NULL;
-
 GDBusConnection *_bt_gdbus_init_system_gconn(void)
 {
        GError *error = NULL;
 
        dbus_threads_init_default();
 
-       if (system_gconn != NULL)
-               return system_gconn;
+       if (system_conn != NULL)
+               return system_conn;
 
-       system_gconn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
+       system_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
 
-       if (!system_gconn) {
+       if (!system_conn) {
                BT_ERR("Unable to connect to dbus: %s", error->message);
                g_clear_error(&error);
        }
 
-       return system_gconn;
+       return system_conn;
 }
 
 GDBusConnection *_bt_gdbus_get_system_gconn(void)
@@ -71,10 +69,9 @@ GDBusConnection *_bt_gdbus_get_system_gconn(void)
        GDBusConnection *local_system_gconn = NULL;
        GError *error = NULL;
 
-       if (system_gconn == NULL) {
-               system_gconn = _bt_gdbus_init_system_gconn();
-       } else if (g_dbus_connection_is_closed(system_gconn)) {
-
+       if (system_conn == NULL) {
+               system_conn = _bt_gdbus_init_system_gconn();
+       } else if (g_dbus_connection_is_closed(system_conn)) {
                local_system_gconn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
 
                if (!local_system_gconn) {
@@ -82,22 +79,67 @@ GDBusConnection *_bt_gdbus_get_system_gconn(void)
                        g_clear_error(&error);
                }
 
-               system_gconn = local_system_gconn;
+               system_conn = local_system_gconn;
        }
 
-       return system_gconn;
+       return system_conn;
+}
+
+GDBusConnection *_bt_gdbus_init_session_gconn(void)
+{
+       GError *error = NULL;
+
+       if (!g_thread_supported()) {
+               g_thread_init(NULL);
+       }
+
+       dbus_threads_init_default();
+
+       if (session_conn != NULL)
+               return session_conn;
+
+       session_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
+
+       if (!session_conn) {
+               BT_ERR("Unable to connect to dbus: %s", error->message);
+               g_clear_error(&error);
+       }
+
+       return session_conn;
+}
+
+GDBusConnection *_bt_gdbus_get_session_gconn(void)
+{
+       GDBusConnection *local_session_gconn = NULL;
+       GError *error = NULL;
+
+       if (session_conn == NULL) {
+               session_conn = _bt_gdbus_init_session_gconn();
+       } else if (g_dbus_connection_is_closed(session_conn)) {
+               local_session_gconn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
+
+               if (!local_session_gconn) {
+                       BT_ERR("Unable to connect to dbus: %s", error->message);
+                       g_clear_error(&error);
+               }
+
+               session_conn = local_session_gconn;
+       }
+
+       return session_conn;
 }
 
 static GDBusProxy *__bt_init_manager_proxy(void)
 {
+       GDBusConnection *g_conn;
        GDBusProxy *proxy;
 
-       if (system_conn == NULL) {
-               system_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL);
-               retv_if(system_conn == NULL, NULL);
-       }
+       dbus_threads_init_default();
+
+       g_conn = _bt_gdbus_get_system_gconn();
+       retv_if(g_conn == NULL, NULL);
 
-       proxy = g_dbus_proxy_new_sync(system_conn, G_DBUS_PROXY_FLAGS_NONE,
+       proxy = g_dbus_proxy_new_sync(g_conn, G_DBUS_PROXY_FLAGS_NONE,
                                                                NULL, BT_BLUEZ_NAME,
                                                                BT_MANAGER_PATH, BT_MANAGER_INTERFACE,  NULL, NULL);
 
@@ -113,14 +155,15 @@ static GDBusProxy *__bt_init_manager_proxy(void)
 
 static GDBusProxy *__bt_init_adapter_proxy(void)
 {
+       GDBusConnection *g_conn;
        GDBusProxy *manager_proxy;
        GDBusProxy *proxy;
        char *adapter_path = NULL;
 
-       if (system_conn == NULL) {
-               system_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL);
-               retv_if(system_conn == NULL, NULL);
-       }
+       dbus_threads_init_default();
+
+       g_conn = _bt_gdbus_get_system_gconn();
+       retv_if(g_conn == NULL, NULL);
 
        manager_proxy = _bt_get_manager_proxy();
        retv_if(manager_proxy == NULL, NULL);
@@ -128,7 +171,7 @@ static GDBusProxy *__bt_init_adapter_proxy(void)
        adapter_path = _bt_get_adapter_path();
        retv_if(adapter_path == NULL, NULL);
 
-       proxy = g_dbus_proxy_new_sync(system_conn, G_DBUS_PROXY_FLAGS_NONE,
+       proxy = g_dbus_proxy_new_sync(g_conn, G_DBUS_PROXY_FLAGS_NONE,
                                                                NULL, BT_BLUEZ_NAME,
                                                                adapter_path, BT_ADAPTER_INTERFACE,  NULL, NULL);
 
@@ -143,14 +186,15 @@ static GDBusProxy *__bt_init_adapter_proxy(void)
 
 static GDBusProxy *__bt_init_adapter_properties_proxy(void)
 {
+       GDBusConnection *g_conn;
        GDBusProxy *manager_proxy;
        GDBusProxy *proxy;
        char *adapter_path = NULL;
 
-       if (system_conn == NULL) {
-               system_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL);
-               retv_if(system_conn == NULL, NULL);
-       }
+       dbus_threads_init_default();
+
+       g_conn = _bt_gdbus_get_system_gconn();
+       retv_if(g_conn == NULL, NULL);
 
        manager_proxy = _bt_get_manager_proxy();
        retv_if(manager_proxy == NULL, NULL);
@@ -158,7 +202,7 @@ static GDBusProxy *__bt_init_adapter_properties_proxy(void)
        adapter_path = _bt_get_adapter_path();
        retv_if(adapter_path == NULL, NULL);
 
-       proxy = g_dbus_proxy_new_sync(system_conn, G_DBUS_PROXY_FLAGS_NONE,
+       proxy = g_dbus_proxy_new_sync(g_conn, G_DBUS_PROXY_FLAGS_NONE,
                                                                        NULL, BT_BLUEZ_NAME,
                                                                        adapter_path, BT_PROPERTIES_INTERFACE,  NULL, NULL);
 
@@ -171,50 +215,6 @@ static GDBusProxy *__bt_init_adapter_properties_proxy(void)
        return proxy;
 }
 
-GDBusConnection *__bt_init_system_gconn(void)
-{
-       if (system_conn == NULL)
-               system_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL);
-
-       return system_conn;
-}
-
-GDBusConnection *__bt_init_session_conn(void)
-{
-       if (session_conn == NULL)
-               session_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL);
-
-       return session_conn;
-}
-
-GDBusConnection *_bt_get_session_gconn(void)
-{
-       return (session_conn) ? session_conn : __bt_init_session_conn();
-}
-
-GDBusConnection *_bt_get_system_gconn(void)
-{
-       return (system_conn) ? system_conn : __bt_init_system_gconn();
-}
-
-GDBusConnection *_bt_get_system_conn(void)
-{
-       GDBusConnection *g_conn;
-
-       if (system_conn == NULL) {
-               g_conn = __bt_init_system_gconn();
-       } else {
-               g_conn = system_conn;
-       }
-
-       if (!g_conn) {
-               BT_ERR("Unable to get dbus connection");
-               return NULL;
-       }
-
-       return g_conn;
-}
-
 GDBusProxy *_bt_get_manager_proxy(void)
 {
        if (manager_proxy) {
@@ -309,7 +309,7 @@ char *_bt_get_adapter_path(void)
        GVariantIter *iter = NULL;
        char *adapter_path = NULL;
 
-       conn = _bt_get_system_conn();
+       conn = _bt_gdbus_get_system_gconn();
        retv_if(conn == NULL, NULL);
 
        manager_proxy = _bt_get_manager_proxy();
@@ -428,7 +428,7 @@ void _bt_convert_addr_string_to_secure_string(char *addr,
        ret_if(addr == NULL);
 
        len = strlen(address);
-       ret_if(len != BT_ADDRESS_STRING_SIZE- 1);
+       ret_if(len != BT_ADDRESS_STRING_SIZE - 1);
 
        strncpy(addr, address, len);
 
@@ -640,7 +640,7 @@ char *_bt_get_device_object_path(char *address)
        GVariant *result = NULL;
        GVariantIter *iter = NULL;
 
-       conn = _bt_get_system_conn();
+       conn = _bt_gdbus_get_system_gconn();
        retv_if(conn == NULL, NULL);
 
        manager_proxy = _bt_get_manager_proxy();
@@ -776,7 +776,7 @@ char *_bt_convert_error_to_string(int error)
 
 char * _bt_convert_disc_reason_to_string(int reason)
 {
-       switch(reason) {
+       switch (reason) {
        case (int)BLUETOOTH_ERROR_PAGE_TIMEOUT:
                return "Page timeout";
        case (int)BLUETOOTH_ERROR_CONNECTION_TIMEOUT:
@@ -890,7 +890,7 @@ int _bt_eventsystem_set_value(const char *event, const char *key, const char *va
        return ret;
 }
 
-void __bt_get_auth_info(GVariant *reply,  char *auth_info)
+void __bt_get_auth_info(GVariant *reply, char *auth_info)
 {
        int cursor;
        GVariant *tmp_value;
@@ -901,8 +901,7 @@ void __bt_get_auth_info(GVariant *reply,  char *auth_info)
        guint8 m_value;
        int i = 0;
 
-
-       tmp_value = g_variant_lookup_value (reply, "IsAliasSet",
+       tmp_value = g_variant_lookup_value(reply, "IsAliasSet",
                                                                G_VARIANT_TYPE_BOOLEAN);
        if (tmp_value) {
                is_alias_set = g_variant_get_boolean(tmp_value);
index 55d0a97..61ec43a 100644 (file)
@@ -84,12 +84,20 @@ typedef struct {
        char *pin_code;
 } bt_pin_code_info_t;
 
+typedef struct {
+       int req_id;
+       bluetooth_device_address_t bd_addr;
+       gboolean auto_connect;
+} bt_pending_le_conn_info_s;
+
 gboolean is_device_creating;
 bt_funcion_data_t *bonding_info;
 bt_funcion_data_t *searching_info;
 bt_funcion_data_t *att_mtu_req_info;
 
 static GSList *pin_info_list = NULL;
+static bt_pending_le_conn_info_s *pending_le_conn_info = NULL;
+static guint pending_le_conn_timer_id = 0;
 
 /* This HID Mouse does not support pairing precedure. need to skip it. */
 #define SMB_MOUSE_LAP_ADDR "00:12:A1"
@@ -209,7 +217,7 @@ static gboolean __bt_launch_unable_to_pairing_syspopup(int result)
        bundle *b = NULL;
        GDBusConnection *conn;
 
-       conn = _bt_get_system_gconn();
+       conn = _bt_gdbus_get_system_gconn();
        if (conn == NULL)
                return FALSE;
 
@@ -350,7 +358,7 @@ bt_remote_dev_info_t *_bt_get_remote_device_info_by_object_path(
 
        retv_if(object_path == NULL, NULL);
 
-       conn = _bt_get_system_gconn();
+       conn = _bt_gdbus_get_system_gconn();
        if (conn == NULL) {
                BT_ERR("conn == NULL");
                return NULL;
@@ -389,7 +397,7 @@ bt_remote_dev_info_t *_bt_get_remote_device_info_by_object_path(
                        g_variant_unref(tmp_value);
                }
 
-               tmp_value = g_variant_lookup_value (value, "IsAliasSet", G_VARIANT_TYPE_BOOLEAN);
+               tmp_value = g_variant_lookup_value(value, "IsAliasSet", G_VARIANT_TYPE_BOOLEAN);
                if (tmp_value) {
                        dev_info->is_alias_set = g_variant_get_boolean(tmp_value);
                        g_variant_unref(tmp_value);
@@ -701,6 +709,7 @@ static void __bt_bond_device_cb(GDBusProxy *proxy, GAsyncResult *res,
 {
        int result = BLUETOOTH_ERROR_NONE;
        GError *err = NULL;
+       GVariant *reply;
        GVariant *out_param1;
        request_info_t *req_info;
        bluetooth_device_info_t dev_info;
@@ -711,7 +720,9 @@ static void __bt_bond_device_cb(GDBusProxy *proxy, GAsyncResult *res,
        /* Terminate ALL system popup */
        syspopup_destroy_all();
 
-       g_dbus_proxy_call_finish(proxy, res, &err);
+       reply = g_dbus_proxy_call_finish(proxy, res, &err);
+       if (reply)
+               g_variant_unref(reply);
 
        is_device_creating = FALSE;
 
@@ -767,7 +778,7 @@ static void __bt_bond_device_cb(GDBusProxy *proxy, GAsyncResult *res,
                        result = BLUETOOTH_ERROR_HOST_DOWN;
                } else if (g_strrstr(err->message, BT_DBUS_TIMEOUT_MESSAGE)) {
                        BT_INFO("Cancel already running bonding");
-                       if(__bt_cancel_bonding() != BLUETOOTH_ERROR_NONE) {
+                       if (__bt_cancel_bonding() != BLUETOOTH_ERROR_NONE) {
                                BT_INFO("Error while Cancelling bonding");
                                /* we need to unref proxy so continue */
                        }
@@ -846,7 +857,7 @@ static void __bt_bond_device_cb(GDBusProxy *proxy, GAsyncResult *res,
        }
 
        remote_dev_info = _bt_get_remote_device_info(bonding_info->addr);
-       if(!remote_dev_info)
+       if (!remote_dev_info)
                goto dbus_return;
 
        GVariant *uuids = NULL;
@@ -945,7 +956,7 @@ int _bt_bond_device(int request_id,
                return BLUETOOTH_ERROR_DEVICE_BUSY;
        }
 
-       conn = _bt_get_system_gconn();
+       conn = _bt_gdbus_get_system_gconn();
        retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
 
        _bt_convert_addr_type_to_string(address, device_address->addr);
@@ -1053,13 +1064,16 @@ static void __bt_unbond_cb(GDBusProxy *proxy, GAsyncResult *res,
                                        gpointer user_data)
 {
        GError *err = NULL;
+       GVariant *reply;
        GVariant *out_param1;
        int result = BLUETOOTH_ERROR_NONE;
        bt_funcion_data_t *unbonding_info;
        bluetooth_device_info_t dev_info;
        request_info_t *req_info;
 
-       g_dbus_proxy_call_finish(proxy, res, &err);
+       reply = g_dbus_proxy_call_finish(proxy, res, &err);
+       if (reply)
+               g_variant_unref(reply);
 
        unbonding_info = user_data;
 
@@ -1147,7 +1161,7 @@ int _bt_unbond_device(int request_id,
                goto fail;
        }
 
-       conn = _bt_get_system_gconn();
+       conn = _bt_gdbus_get_system_gconn();
        if (conn == NULL) {
                BT_ERR("conn is NULL");
                result = BLUETOOTH_ERROR_INTERNAL;
@@ -1211,6 +1225,7 @@ static void __bt_discover_cb(GDBusProxy *proxy, GAsyncResult *res,
                                        gpointer user_data)
 {
        GError *err = NULL;
+       GVariant *reply;
        GVariant *out_param1;
        int result = BLUETOOTH_ERROR_NONE;
        bluetooth_device_info_t dev_info;
@@ -1221,7 +1236,9 @@ static void __bt_discover_cb(GDBusProxy *proxy, GAsyncResult *res,
        GVariantBuilder *builder = NULL;
        int i = 0;
 
-       g_dbus_proxy_call_finish(proxy, res, &err);
+       reply = g_dbus_proxy_call_finish(proxy, res, &err);
+       if (reply)
+               g_variant_unref(reply);
 
        g_object_unref(proxy);
 
@@ -1265,7 +1282,7 @@ static void __bt_discover_cb(GDBusProxy *proxy, GAsyncResult *res,
        }
 
        remote_dev_info = _bt_get_remote_device_info(searching_info->addr);
-       if(!remote_dev_info)
+       if (!remote_dev_info)
                goto dbus_return;
 
 event:
@@ -1360,7 +1377,7 @@ int _bt_search_device(int request_id,
        _bt_convert_addr_type_to_string(searching_info->addr,
                                        device_address->addr);
 
-       conn = _bt_get_system_gconn();
+       conn = _bt_gdbus_get_system_gconn();
        retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
 
 
@@ -1439,7 +1456,7 @@ int _bt_set_alias(bluetooth_device_address_t *device_address,
        adapter_proxy = _bt_get_adapter_proxy();
        retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
 
-       conn = _bt_get_system_gconn();
+       conn = _bt_gdbus_get_system_gconn();
        retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
 
        _bt_convert_addr_type_to_string(address, device_address->addr);
@@ -1493,7 +1510,7 @@ int _bt_set_authorization(bluetooth_device_address_t *device_address,
 
        BT_CHECK_PARAMETER(device_address, return);
 
-       conn = _bt_get_system_gconn();
+       conn = _bt_gdbus_get_system_gconn();
        retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
 
        _bt_convert_addr_type_to_string(address, device_address->addr);
@@ -1538,7 +1555,7 @@ int _bt_set_authorization(bluetooth_device_address_t *device_address,
        }
 
        result = g_dbus_proxy_call_sync(device_proxy, "Set",
-                                g_variant_new("(ssv)", BT_DEVICE_INTERFACE, "Trusted", g_variant_new("b",authorize)),
+                                g_variant_new("(ssv)", BT_DEVICE_INTERFACE, "Trusted", g_variant_new("b", authorize)),
                                 G_DBUS_CALL_FLAGS_NONE,
                                 -1,
                                 NULL,
@@ -1573,7 +1590,7 @@ int _bt_is_gatt_connected(bluetooth_device_address_t *device_address,
 
        BT_CHECK_PARAMETER(device_address, return);
 
-       conn = _bt_get_system_gconn();
+       conn = _bt_gdbus_get_system_gconn();
        retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
 
        _bt_convert_addr_type_to_string(address, device_address->addr);
@@ -1653,7 +1670,7 @@ int _bt_is_device_connected(bluetooth_device_address_t *device_address,
        adapter_proxy = _bt_get_adapter_proxy();
        retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
 
-       conn = _bt_get_system_gconn();
+       conn = _bt_gdbus_get_system_gconn();
        retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
 
        _bt_convert_addr_type_to_string(address, device_address->addr);
@@ -1768,7 +1785,7 @@ int _bt_get_connected_link(bluetooth_device_address_t *device_address,
 
        BT_CHECK_PARAMETER(device_address, return);
 
-       conn = _bt_get_system_gconn();
+       conn = _bt_gdbus_get_system_gconn();
        retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
 
        _bt_convert_addr_type_to_string(address, device_address->addr);
@@ -1875,8 +1892,8 @@ done:
        }
 }
 
-int _bt_connect_le_device(int req_id, const bluetooth_device_address_t *bd_addr,
-               gboolean auto_connect)
+static int __bt_connect_le_device_internal(int req_id, const bluetooth_device_address_t *bd_addr,
+       gboolean auto_connect)
 {
        char device_address[BT_ADDRESS_STRING_SIZE] = { 0 };
        gchar *device_path = NULL;
@@ -1887,7 +1904,7 @@ int _bt_connect_le_device(int req_id, const bluetooth_device_address_t *bd_addr,
 
        BT_CHECK_PARAMETER(bd_addr, return);
 
-       conn = _bt_get_system_gconn();
+       conn = _bt_gdbus_get_system_gconn();
        retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
 
        _bt_convert_addr_type_to_string(device_address,
@@ -1921,11 +1938,6 @@ int _bt_connect_le_device(int req_id, const bluetooth_device_address_t *bd_addr,
 
        func_data->req_id = req_id;
 
-       ret = _bt_hold_current_advertising();
-       if (ret != BLUETOOTH_ERROR_NONE) {
-               BT_ERR("Unable to hold advertising");
-       }
-
        g_dbus_proxy_call(device_proxy, "ConnectLE",
                        g_variant_new("(b)", auto_connect),
                        G_DBUS_CALL_FLAGS_NONE,
@@ -1945,6 +1957,57 @@ fail:
        return ret;
 }
 
+static gboolean __bt_connect_le_timer_cb(gpointer user_data)
+{
+       BT_INFO("Try to initiate pending LE connection");
+
+       pending_le_conn_timer_id = 0;
+
+       __bt_connect_le_device_internal(pending_le_conn_info->req_id,
+               &pending_le_conn_info->bd_addr,
+               pending_le_conn_info->auto_connect);
+
+       g_free(pending_le_conn_info);
+       pending_le_conn_info = NULL;
+
+       return FALSE;
+}
+
+void _bt_pending_connect_le_device(void)
+{
+       if (pending_le_conn_timer_id > 0) {
+               g_source_remove(pending_le_conn_timer_id);
+               __bt_connect_le_timer_cb(NULL);
+       }
+}
+
+int _bt_connect_le_device(int req_id, const bluetooth_device_address_t *bd_addr,
+               gboolean auto_connect)
+{
+       int ret = BLUETOOTH_ERROR_NONE;
+
+       BT_CHECK_PARAMETER(bd_addr, return);
+
+       ret = _bt_hold_current_advertising();
+       if (ret == BLUETOOTH_ERROR_NONE) {
+               BT_INFO("Current advertising is held");
+               pending_le_conn_info = g_malloc0(sizeof(bt_pending_le_conn_info_s));
+               pending_le_conn_info->req_id = req_id;
+               memcpy(pending_le_conn_info->bd_addr.addr, bd_addr->addr,
+                               BLUETOOTH_ADDRESS_LENGTH);
+               pending_le_conn_info->auto_connect = auto_connect;
+
+               pending_le_conn_timer_id =
+                       g_timeout_add(1000, __bt_connect_le_timer_cb, NULL);
+
+               return BLUETOOTH_ERROR_NONE;
+       }
+
+       BT_ERR("Unable to hold advertising");
+
+       return __bt_connect_le_device_internal(req_id, bd_addr, auto_connect);
+}
+
 int _bt_disconnect_le_device(int req_id,
                const bluetooth_device_address_t *bd_addr)
 {
@@ -1957,7 +2020,7 @@ int _bt_disconnect_le_device(int req_id,
 
        BT_CHECK_PARAMETER(bd_addr, return);
 
-       conn = _bt_get_system_gconn();
+       conn = _bt_gdbus_get_system_gconn();
        retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
 
        _bt_convert_addr_type_to_string(device_address,
@@ -2026,7 +2089,7 @@ int _bt_connect_le_ipsp_device(const bluetooth_device_address_t *bd_addr)
        _bt_convert_addr_type_to_string(device_address,
                        (unsigned char *)bd_addr->addr);
 
-       conn = _bt_get_system_gconn();
+       conn = _bt_gdbus_get_system_gconn();
        retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
 
        adapter_proxy = _bt_get_adapter_proxy();
@@ -2080,7 +2143,7 @@ int _bt_disconnect_le_ipsp_device(const bluetooth_device_address_t *bd_addr)
        _bt_convert_addr_type_to_string(device_address,
                        (unsigned char *)bd_addr->addr);
 
-       conn = _bt_get_system_gconn();
+       conn = _bt_gdbus_get_system_gconn();
        retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
 
        adapter_proxy = _bt_get_adapter_proxy();
@@ -2129,7 +2192,7 @@ int _bt_connect_profile(char *address, char *uuid,
        GVariant *result = NULL;
        GError *error = NULL;
 
-       conn = _bt_get_system_gconn();
+       conn = _bt_gdbus_get_system_gconn();
        retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
 
        object_path = _bt_get_device_object_path(address);
@@ -2181,7 +2244,7 @@ int _bt_disconnect_profile(char *address, char *uuid,
        GDBusProxy *proxy;
        GDBusConnection *conn;
 
-       conn = _bt_get_system_gconn();
+       conn = _bt_gdbus_get_system_gconn();
        retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
 
        object_path = _bt_get_device_object_path(address);
@@ -2345,7 +2408,7 @@ int _bt_le_conn_update(unsigned char *device_address,
                goto fail;
        }
 
-       conn = _bt_get_system_gconn();
+       conn = _bt_gdbus_get_system_gconn();
        if (conn == NULL) {
                BT_ERR("conn NULL");
                ret = BLUETOOTH_ERROR_INTERNAL;
@@ -2634,7 +2697,7 @@ int _bt_set_trust_profile(bluetooth_device_address_t *bd_addr,
                        bd_addr->addr[4], bd_addr->addr[5],
                        profile, trust);
 
-       conn = _bt_get_system_gconn();
+       conn = _bt_gdbus_get_system_gconn();
        retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
 
        _bt_convert_addr_type_to_string(address, bd_addr->addr);
@@ -2696,7 +2759,7 @@ int _bt_get_trust_profile(bluetooth_device_address_t *bd_addr,
                        bd_addr->addr[4], bd_addr->addr[5],
                        profile, *trust);
 
-       conn = _bt_get_system_gconn();
+       conn = _bt_gdbus_get_system_gconn();
        retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
 
        _bt_convert_addr_type_to_string(address, bd_addr->addr);
@@ -2760,7 +2823,7 @@ int _bt_set_restrict_profile(bluetooth_device_address_t *bd_addr,
                        bd_addr->addr[4], bd_addr->addr[5],
                        profile, restricted);
 
-       conn = _bt_get_system_gconn();
+       conn = _bt_gdbus_get_system_gconn();
        retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
 
        _bt_convert_addr_type_to_string(address, bd_addr->addr);
@@ -2822,7 +2885,7 @@ int _bt_get_restrict_profile(bluetooth_device_address_t *bd_addr,
                        bd_addr->addr[4], bd_addr->addr[5],
                        profile, *restricted);
 
-       conn = _bt_get_system_gconn();
+       conn = _bt_gdbus_get_system_gconn();
        retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
 
        _bt_convert_addr_type_to_string(address, bd_addr->addr);
@@ -2916,8 +2979,8 @@ static void __bt_request_att_mtu_device_cb(GDBusProxy *proxy, GAsyncResult *res,
                goto dbus_return;
 
        if (val) {
-                g_variant_get (val, "(qy)", &mtu, &status);
-                g_variant_unref (val);
+                g_variant_get(val, "(qy)", &mtu, &status);
+                g_variant_unref(val);
        }
 
        BT_DBG("MTU %d, Status %d, %s", mtu, status, att_mtu_req_info->addr);
@@ -2974,7 +3037,7 @@ int _bt_request_att_mtu(int request_id, bluetooth_device_address_t *device_addre
                return BLUETOOTH_ERROR_DEVICE_BUSY;
        }
 
-       conn = _bt_get_system_gconn();
+       conn = _bt_gdbus_get_system_gconn();
        retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
 
        adapter_proxy = _bt_get_adapter_proxy();
@@ -3032,7 +3095,7 @@ int _bt_get_att_mtu(bluetooth_device_address_t *device_address,
 
        BT_CHECK_PARAMETER(device_address, return);
 
-       conn = _bt_get_system_gconn();
+       conn = _bt_gdbus_get_system_gconn();
        retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
 
        _bt_convert_addr_type_to_string(address, device_address->addr);
@@ -3096,7 +3159,7 @@ int _bt_get_device_ida(bluetooth_device_address_t *device_address,
 
        BT_CHECK_PARAMETER(device_address, return);
 
-       conn = _bt_get_system_gconn();
+       conn = _bt_gdbus_get_system_gconn();
        retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
 
        _bt_convert_addr_type_to_string(address, device_address->addr);
index 3610110..0581b01 100644 (file)
@@ -105,7 +105,7 @@ static bt_le_adv_info_t *__bt_get_adv_ind_info(char *addr)
        retv_if(!addr, NULL);
        bt_le_adv_info_t *adv_info = NULL;
        GList *current = g_list_first((GList *)p_adv_ind_list);
-       while(current && current->data) {
+       while (current && current->data) {
                adv_info = (bt_le_adv_info_t *)current->data;
                if (adv_info && !g_strcmp0(adv_info->addr, addr))
                        return adv_info;
@@ -202,7 +202,7 @@ static gboolean __bt_parse_device_properties(GVariant *item,
                } else if (strcasecmp(key, "UUIDs") == 0) {
                        char **uuid_value;
                        gsize size = 0;
-                       int i =0;
+                       int i = 0;
                        size = g_variant_get_size(val);
 
                        if (size > 0) {
@@ -1841,7 +1841,7 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path
                         */
                        _bt_obex_check_pending_transfer(address);
                        _bt_opp_client_is_sending(&sending);
-                       if(sending == TRUE)
+                       if (sending == TRUE)
                                _bt_opp_client_check_pending_transfer(address);
                }
                param = g_variant_new("(isy)", result, address, addr_type);
@@ -1956,7 +1956,7 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path
                                _bt_audio_connect(wait_list->req_id,
                                                        wait_list->type,
                                                        &device_address,
-                                                       wait_list->out_param1);
+                                                       NULL);
                        }
                } else if (strcmp(profile_uuid, AVRCP_TARGET_UUID) == 0) {
 
@@ -2031,7 +2031,7 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path
                                        _bt_audio_connect(wait_list->req_id,
                                                        wait_list->type,
                                                        &device_address,
-                                                       wait_list->out_param1);
+                                                       NULL);
                                        /* Now free the wait list */
                                        _bt_rel_wait_data();
                                }
@@ -2312,7 +2312,7 @@ void _bt_handle_headset_event(GVariant *msg, const char *path)
                        _bt_convert_addr_string_to_type(device_address.addr,
                                                        wait_list->address);
                        _bt_audio_connect(wait_list->req_id, wait_list->type,
-                                       &device_address, wait_list->out_param1);
+                                       &device_address, NULL);
                        _bt_rel_wait_data();
                } else if (event == BLUETOOTH_EVENT_AG_CONNECTED) {
                        /* Add data to the connected list */
@@ -2449,7 +2449,7 @@ void _bt_handle_sink_event(GVariant *msg, const char *path)
                                        _bt_audio_connect(wait_list->req_id,
                                                                wait_list->type,
                                                                &device_address,
-                                                               wait_list->out_param1);
+                                                               NULL);
                                }
                                g_free(address);
                        } else if (strcasecmp(value, "Connected") == 0) {
index 8ceb7fa..d8d4b19 100644 (file)
@@ -306,7 +306,7 @@ gboolean gap_agent_reply_authorize(GapAgentPrivate *agent, const guint accept,
                if (accept == GAP_AGENT_ACCEPT) {
                        g_dbus_method_invocation_return_value(priv->reply_context, NULL);
                } else if (accept == GAP_AGENT_ACCEPT_ALWAYS) {
-                       bluetooth_device_address_t addr = {{0,}};
+                       bluetooth_device_address_t addr = { { 0, } };
                        int result;
 
                        _bt_convert_addr_string_to_type(addr.addr,
@@ -331,7 +331,7 @@ gboolean gap_agent_reply_authorize(GapAgentPrivate *agent, const guint accept,
                                                "CanceledbyUser");
                                break;
                        case GAP_AGENT_REJECT: {
-                               bluetooth_device_address_t addr = {{0,}};
+                               bluetooth_device_address_t addr = { { 0, } };
                                int result;
 
                                _bt_convert_addr_string_to_type(addr.addr,
@@ -487,7 +487,7 @@ static gboolean __gap_agent_unregister(GapAgentPrivate *agent)
        }
 
        reply = g_dbus_proxy_call_sync(agent_manager, "UnregisterAgent",
-                       g_variant_new("o", priv->path),
+                       g_variant_new("(o)", priv->path),
                        G_DBUS_CALL_FLAGS_NONE, -1,
                        NULL, &error);
        g_object_unref(agent_manager);
@@ -617,7 +617,7 @@ static void __bt_gap_agent_method(GDBusConnection *connection,
                if (!agent->cb.passkey_func)
                        return;
 
-               conn = _bt_get_system_gconn();
+               conn = _bt_gdbus_get_system_gconn();
                if (conn == NULL)
                        return;
 
@@ -683,7 +683,7 @@ static void __bt_gap_agent_method(GDBusConnection *connection,
                if (!priv->cb.passkey_func)
                        return;
 
-               conn = _bt_get_system_gconn();
+               conn = _bt_gdbus_get_system_gconn();
                if (conn == NULL)
                        return;
 
@@ -755,7 +755,7 @@ static void __bt_gap_agent_method(GDBusConnection *connection,
                if (!priv->cb.display_func)
                        return;
 
-               conn = _bt_get_system_gconn();
+               conn = _bt_gdbus_get_system_gconn();
                if (conn == NULL)
                        return;
 
@@ -812,7 +812,7 @@ static void __bt_gap_agent_method(GDBusConnection *connection,
                if (!priv->cb.confirm_func)
                        return;
 
-               conn = _bt_get_system_gconn();
+               conn = _bt_gdbus_get_system_gconn();
                if (conn == NULL)
                        return;
 
@@ -880,7 +880,7 @@ static void __bt_gap_agent_method(GDBusConnection *connection,
                if (!priv->cb.authorize_func)
                        return;
 
-               conn = _bt_get_system_gconn();
+               conn = _bt_gdbus_get_system_gconn();
                if (conn == NULL)
                        return;
 
index c048b24..f88ffce 100644 (file)
@@ -98,6 +98,7 @@ gboolean connect_remote_media_audio(gpointer user_data)
                if (list == NULL) {
                        BT_INFO("Head Set didn't initiated a2dp connection");
                        BT_INFO("local device initiating A2DP connection");
+
                        _bt_audio_connect(0, BT_AUDIO_A2DP,
                                        &conn_info->dev_info.device_address, NULL);
                } else {
@@ -111,6 +112,7 @@ gboolean connect_remote_media_audio(gpointer user_data)
                if (list == NULL) {
                        BT_INFO("Headset didn't initiated HFP connection");
                        BT_INFO("local device intiating HFP Connection");
+
                        _bt_audio_connect(0, BT_AUDIO_HSP,
                                        &conn_info->dev_info.device_address, NULL);
                } else {
@@ -132,7 +134,7 @@ void _bt_get_bluetooth_device_info(char *remote_address, bluetooth_device_info_t
        if (device == NULL)
                return;
 
-       dev_list = g_array_new (FALSE, FALSE, sizeof(gchar));
+       dev_list = g_array_new(FALSE, FALSE, sizeof(gchar));
 
        _bt_get_bonded_devices(&dev_list);
        size = (dev_list->len) / sizeof(bluetooth_device_info_t);
index 67f733c..b691f5a 100644 (file)
@@ -173,7 +173,7 @@ int _bt_hid_connect(int request_id,
        adapter_proxy = _bt_get_adapter_proxy();
        retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
        */
-       conn = _bt_get_system_gconn();
+       conn = _bt_gdbus_get_system_gconn();
        retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
 
        _bt_convert_addr_type_to_string(address, device_address->addr);
@@ -212,7 +212,7 @@ int _bt_hid_disconnect(int request_id,
        adapter_proxy = _bt_get_adapter_proxy();
        retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
        */
-       conn = _bt_get_system_gconn();
+       conn = _bt_gdbus_get_system_gconn();
        retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
 
        _bt_convert_addr_type_to_string(address, device_address->addr);
index e175573..2d40fa2 100644 (file)
@@ -255,7 +255,7 @@ int _bt_network_activate(void)
        GDBusConnection *conn;
        GDBusProxy *server_proxy;
 
-       conn = _bt_get_system_gconn();
+       conn = _bt_gdbus_get_system_gconn();
        retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
 
        adapter_path = _bt_get_adapter_path();
@@ -306,7 +306,7 @@ int _bt_network_deactivate(void)
        GDBusProxy *server_proxy;
        int ret = BLUETOOTH_ERROR_NONE;
 
-       conn = _bt_get_system_gconn();
+       conn = _bt_gdbus_get_system_gconn();
        retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
 
        adapter_path = _bt_get_adapter_path();
@@ -384,7 +384,7 @@ int _bt_network_connect(int request_id, int role,
        adapter_proxy = _bt_get_adapter_proxy();
        retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
 
-       conn = _bt_get_system_gconn();
+       conn = _bt_gdbus_get_system_gconn();
        retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
 
        _bt_convert_addr_type_to_string(address, device_address->addr);
@@ -449,7 +449,7 @@ int _bt_network_disconnect(int request_id,
        adapter_proxy = _bt_get_adapter_proxy();
        retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
 
-       conn = _bt_get_system_gconn();
+       conn = _bt_gdbus_get_system_gconn();
        retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
 
        _bt_convert_addr_type_to_string(address, device_address->addr);
@@ -508,7 +508,7 @@ int _bt_network_server_disconnect(int request_id,
 
        BT_CHECK_PARAMETER(device_address, return);
 
-       conn = _bt_get_system_gconn();
+       conn = _bt_gdbus_get_system_gconn();
        retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
 
        adapter_path = _bt_get_adapter_path();
index cdee90c..092c996 100644 (file)
@@ -577,7 +577,7 @@ void _bt_obex_set_progress_cb(char *object_path,
 void _bt_obex_set_complete_cb(char *object_path,
                        bt_obex_complete_cb func, gpointer data)
 {
-       bt_obex_agent_info *info =__find_obex_agent_info(object_path);;
+       bt_obex_agent_info *info = __find_obex_agent_info(object_path);;
        if (info == NULL)
                return;
 
index 398784a..e46d1f8 100644 (file)
@@ -259,7 +259,7 @@ static char *__bt_get_remote_device_name(const char *bdaddress)
        device_path = _bt_get_device_object_path((char *)bdaddress);
        retv_if(device_path == NULL, NULL);
 
-       conn = _bt_get_system_gconn();
+       conn = _bt_gdbus_get_system_gconn();
        retv_if(conn == NULL, NULL);
        BT_INFO("Device_path %s", device_path);
        device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
@@ -326,7 +326,7 @@ static void __bt_get_remote_device_name_authinfo(const char *bdaddress,
        device_path = _bt_get_device_object_path((char *)bdaddress);
        ret_if(device_path == NULL);
 
-       conn = _bt_get_system_gconn();
+       conn = _bt_gdbus_get_system_gconn();
        ret_if(conn == NULL);
        BT_INFO("Device_path %s", device_path);
        device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
@@ -370,7 +370,7 @@ static void __bt_get_remote_device_name_authinfo(const char *bdaddress,
                                g_variant_unref(temp_value);
                        DBG_SECURE("Name = %s", name);
                }
-               temp_value = g_variant_lookup_value (value, "IsAliasSet", G_VARIANT_TYPE_BOOLEAN);
+               temp_value = g_variant_lookup_value(value, "IsAliasSet", G_VARIANT_TYPE_BOOLEAN);
                if (temp_value) {
                        is_alias_set = g_variant_get_boolean(temp_value);
                        g_variant_unref(temp_value);
@@ -407,7 +407,7 @@ static GDBusProxy *__bt_get_transfer_proxy(const char *transfer_path)
        GDBusProxy *proxy;
        GError *err = NULL;
 
-       conn = _bt_get_session_gconn();
+       conn = _bt_gdbus_get_session_gconn();
        retv_if(conn == NULL, NULL);
 
        proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
@@ -430,7 +430,7 @@ static GDBusProxy *__bt_get_transfer_properties_proxy(const char *transfer_path)
        GDBusConnection *conn;
        GDBusProxy *proxy;
        GError *err = NULL;
-       conn = _bt_get_session_gconn();
+       conn = _bt_gdbus_get_session_gconn();
        retv_if(conn == NULL, NULL);
 
        proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
@@ -606,7 +606,7 @@ static gboolean __bt_authorize_cb(GDBusMethodInvocation *context,
        memcpy(agent_info.auth_info->contact_auth_info, auth_info, 5);
 
        session_info = __bt_find_session_by_path((char *)path);
-       if(NULL == session_info) {
+       if (NULL == session_info) {
                session_info = g_malloc0(sizeof(bt_session_info_t));
                session_info->path = g_strdup(path);
                session_info->address = g_strdup(bdaddress);
@@ -623,7 +623,7 @@ static gboolean __bt_authorize_cb(GDBusMethodInvocation *context,
                return TRUE;
        }
 
-       if(session_info->authorized == FALSE) {
+       if (session_info->authorized == FALSE) {
                _bt_launch_system_popup(BT_AGENT_EVENT_EXCHANGE_REQUEST, device_name,
                                        auth_info, NULL, NULL, BT_OBEX_SERVER_AGENT_PATH);
        } else {
@@ -726,7 +726,7 @@ done:
        __bt_free_auth_info(agent_info.auth_info);
        agent_info.auth_info = NULL;
 
-       g_variant_builder_unref (builder);
+       g_variant_builder_unref(builder);
 
        _bt_send_event(BT_OPP_SERVER_EVENT,
                BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_STARTED,
@@ -823,7 +823,7 @@ void _bt_obex_transfer_completed(const char *transfer_path, gboolean success)
                _bt_send_event(BT_OPP_SERVER_EVENT,
                        BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_STARTED,
                        param);
-               g_variant_builder_unref (builder);
+               g_variant_builder_unref(builder);
        }
        param = g_variant_new("(issssstii)", result,
                                transfer_info->filename,
@@ -900,7 +900,7 @@ int _bt_register_obex_server(void)
        GError *g_error = NULL;
 
        /* Get the session bus. */
-       g_conn = _bt_get_session_gconn();
+       g_conn = _bt_gdbus_get_session_gconn();
        retv_if(g_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
 
        _bt_obex_agent_new(BT_OBEX_SERVER_AGENT_PATH);
@@ -1134,11 +1134,11 @@ void _bt_obex_server_reply_accept(void)
        _bt_send_event(BT_OPP_SERVER_EVENT, BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_AUTHORIZE, param);
 
        session_info = __bt_find_session_by_path(agent_info.auth_info->transfer_path);
-       if(NULL == session_info) {
+
+       if (NULL == session_info)
                BT_ERR("Couldn't get the session info from the list");
-       } else {
+       else
                session_info->authorized = TRUE;
-       }
 }
 
 int _bt_obex_server_reject_authorize(void)
index 4d08e2c..c5dcc71 100644 (file)
@@ -61,7 +61,7 @@ int _bt_oob_read_local_data(bt_oob_data_t *local_oob_data)
 
        BT_CHECK_PARAMETER(local_oob_data, return);
 
-       conn = _bt_get_system_conn();
+       conn = _bt_gdbus_get_system_gconn();
        retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
 
        adapter_path = _bt_get_adapter_path();
@@ -97,7 +97,7 @@ int _bt_oob_read_local_data(bt_oob_data_t *local_oob_data)
                return BLUETOOTH_ERROR_INTERNAL;
        }
 
-       g_variant_get(reply ,"(@ay@ay@ay@ay)", &hash192, &randomizer192,
+       g_variant_get(reply"(@ay@ay@ay@ay)", &hash192, &randomizer192,
                        &hash256, &randomizer256);
        g_variant_unref(reply);
 
@@ -156,7 +156,7 @@ int _bt_oob_add_remote_data(
        BT_CHECK_PARAMETER(remote_device_address, return);
        BT_CHECK_PARAMETER(remote_oob_data, return);
 
-       conn = _bt_get_system_conn();
+       conn = _bt_gdbus_get_system_gconn();
        retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
 
        adapter_path = _bt_get_adapter_path();
@@ -256,7 +256,7 @@ int _bt_oob_remove_remote_data(
 
        BT_CHECK_PARAMETER(remote_device_address, return);
 
-       conn = _bt_get_system_conn();
+       conn = _bt_gdbus_get_system_gconn();
        retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
 
        adapter_path = _bt_get_adapter_path();
index 152a556..d4310c5 100644 (file)
@@ -269,7 +269,7 @@ gboolean _bt_obex_client_started(const char *transfer_path)
        }
 
        /* Get the session bus. */
-       g_conn = _bt_get_session_gconn();
+       g_conn = _bt_gdbus_get_session_gconn();
        retv_if(g_conn == NULL, FALSE);
        properties_proxy = g_dbus_proxy_new_sync(g_conn, G_DBUS_PROXY_FLAGS_NONE,
                                                NULL, BT_OBEXD_DBUS_NAME,
@@ -340,9 +340,13 @@ static void __bt_sending_release_cb(GDBusProxy *proxy,
        GError *error = NULL;
        int result = BLUETOOTH_ERROR_NONE;
        GVariant *param = NULL;
-       g_dbus_proxy_call_finish(proxy, res, &error);
+       GVariant *reply = NULL;
+
+       reply = g_dbus_proxy_call_finish(proxy, res, &error);
        if (proxy)
                g_object_unref(proxy);
+       if (reply)
+               g_variant_unref(reply);
 
        if (error) {
                BT_ERR("%s", error->message);
@@ -404,7 +408,7 @@ static int _bt_remove_session()
        GDBusProxy *session_proxy;
        GError *err = NULL;
 
-       g_conn = _bt_get_session_gconn();
+       g_conn = _bt_gdbus_get_session_gconn();
        retv_if(g_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
        retv_if(sending_info->session_path == NULL, BLUETOOTH_ERROR_INVALID_PARAM);
 
@@ -579,7 +583,7 @@ void _bt_sending_files(void)
                return;
        if (file_offset < sending_info->file_count) {
                /* Get the session bus. */
-               g_conn = _bt_get_session_gconn();
+               g_conn = _bt_gdbus_get_session_gconn();
                ret_if(g_conn == NULL);
 
                client_proxy = g_dbus_proxy_new_sync(g_conn, G_DBUS_PROXY_FLAGS_NONE,
@@ -595,11 +599,11 @@ void _bt_sending_files(void)
                                /* For IOPT compliance, change "text/x-iMelody" to "audio/imelody"
                                 * because few devices(multimedia players) reject the OPP put for text objects
                                 * since they support only multimedia files exchange */
-                               if(!strcasecmp(mime_type, "text/x-iMelody")) {
+                               if (!strcasecmp(mime_type, "text/x-iMelody")) {
                                        strncpy(mime_type, "audio/imelody", BT_MIME_TYPE_MAX_LEN);
                                        BT_DBG("over writing mime type to  = %s", mime_type);
                                }
-                               if(!strcasecmp(mime_type, "text/vcard")) {
+                               if (!strcasecmp(mime_type, "text/vcard")) {
                                        strncpy(mime_type, "text/x-vcard", BT_MIME_TYPE_MAX_LEN);
                                        BT_DBG("over writing mime type to  = %s", mime_type);
                                }
@@ -619,7 +623,7 @@ void _bt_sending_files(void)
                        return;
                }
 
-       }else{
+       } else {
                file_offset = 0;
                __bt_sending_release();
        }
@@ -716,7 +720,7 @@ static int __bt_opp_client_start_sending(int request_id, char *address,
        BT_CHECK_PARAMETER(file_name_array, return);
 
        /* Get the session bus. */
-       g_conn = _bt_get_session_gconn();
+       g_conn = _bt_gdbus_get_session_gconn();
        retv_if(g_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
 
        client_proxy =  g_dbus_proxy_new_sync(g_conn, G_DBUS_PROXY_FLAGS_NONE,
index d0cd93a..9cbf004 100644 (file)
@@ -109,7 +109,6 @@ char *SEARCH_FIELD[] = {
 
 static char *g_pbap_session_path = NULL;
 static char *g_pbap_server_address = NULL;
-static GDBusConnection *dbus_connection = NULL;
 static GDBusProxy *g_pbap_proxy = NULL;
 
 static struct {
@@ -283,6 +282,8 @@ void __bt_pbap_connect_cb(GDBusProxy *proxy,
                BT_DBG("Session Path = %s\n", g_pbap_session_path);
                result = BLUETOOTH_ERROR_NONE;
                g_pbap_server_address = g_strdup(address_string);
+
+               g_variant_unref(value);
        }
 
        signal = g_variant_new("(is)", result, address_string);
@@ -298,6 +299,7 @@ void __bt_pbap_connect_cb(GDBusProxy *proxy,
 int _bt_pbap_connect(const bluetooth_device_address_t *address)
 {
        BT_DBG("+");
+       GDBusConnection *g_conn;
        GError *error = NULL;
        char address_string[18] = { 0, };
        char *ptr = NULL;
@@ -317,13 +319,12 @@ int _bt_pbap_connect(const bluetooth_device_address_t *address)
 
        _bt_convert_addr_type_to_string(address_string, (unsigned char *)address->addr);
        BT_DBG("Address String: %s", address_string);
-       dbus_connection = _bt_get_session_gconn();
-       if (dbus_connection == NULL) {
-                       BT_ERR("Couldn't connect to system bus");
+       g_conn = _bt_gdbus_get_session_gconn();
+       if (g_conn == NULL) {
+                       BT_ERR("Couldn't connect to session bus");
                        return EXIT_FAILURE;
        }
-
-       g_pbap_proxy =  g_dbus_proxy_new_sync(dbus_connection,
+       g_pbap_proxy =  g_dbus_proxy_new_sync(g_conn,
                        G_DBUS_PROXY_FLAGS_NONE, NULL,
                        PBAP_OBEX_CLIENT_SERVICE, PBAP_OBEX_CLIENT_PATH,
                        PBAP_OBEX_CLIENT_INTERFACE, NULL, &error);
@@ -388,6 +389,8 @@ void __bt_pbap_disconnect_cb(GDBusProxy *proxy,
                result = BLUETOOTH_ERROR_NONE;
                selected_path.folder = -1;
                selected_path.type = -1;
+
+               g_variant_unref(value);
        }
 
        /* If the result is success, the event reciever will send the disconnect event */
@@ -572,6 +575,8 @@ void __bt_pbap_get_phonebook_cb(GDBusProxy *proxy,
                transfer_info->filename = (char *)filename;
                transfer_info->operation = PULL_ALL;
                transfers = g_slist_append(transfers, transfer_info);
+
+               g_variant_unref(value);
        }
 
        g_object_unref(proxy);
@@ -1113,6 +1118,7 @@ int _bt_pbap_get_phonebook_size(const bluetooth_device_address_t *address,
                int source, int type)
 {
        BT_DBG("+");
+       GDBusConnection *g_conn;
        GDBusProxy *g_pbap_session_proxy = NULL;
        char address_string[18] = { 0, };
        char *source_string = NULL;
@@ -1141,7 +1147,13 @@ int _bt_pbap_get_phonebook_size(const bluetooth_device_address_t *address,
        BT_DBG("Address[%s] Source[%s] Type[%s]",
                        address_string, source_string, type_string);
        BT_DBG("Session Path = %s\n", g_pbap_session_path);
-       g_pbap_session_proxy =  g_dbus_proxy_new_sync(dbus_connection,
+
+       g_conn = _bt_gdbus_get_session_gconn();
+       if (g_conn == NULL) {
+               BT_ERR("Couldn't connect to session bus");
+               return 0;
+       }
+       g_pbap_session_proxy =  g_dbus_proxy_new_sync(g_conn,
                        G_DBUS_PROXY_FLAGS_NONE, NULL,
                        PBAP_SESSION_SERVICE, g_pbap_session_path,
                        PBAP_SESSION_INTERFACE, NULL, &err);
@@ -1189,6 +1201,7 @@ int _bt_pbap_get_phonebook(const bluetooth_device_address_t *address,
                int source, int type, bt_pbap_pull_parameters_t *app_param)
 {
        BT_DBG("+");
+       GDBusConnection *g_conn;
        GDBusProxy *g_pbap_session_proxy = NULL;
        char address_string[18] = { 0, };
        char *source_string = NULL;
@@ -1221,7 +1234,13 @@ int _bt_pbap_get_phonebook(const bluetooth_device_address_t *address,
                        address_string, source_string, type_string);
 
        BT_DBG("Session Path = %s\n", g_pbap_session_path);
-       g_pbap_session_proxy =  g_dbus_proxy_new_sync(dbus_connection,
+
+       g_conn = _bt_gdbus_get_session_gconn();
+       if (g_conn == NULL) {
+               BT_ERR("Couldn't connect to session bus");
+               return 0;
+       }
+       g_pbap_session_proxy =  g_dbus_proxy_new_sync(g_conn,
                        G_DBUS_PROXY_FLAGS_NONE, NULL,
                        PBAP_SESSION_SERVICE, g_pbap_session_path,
                        PBAP_SESSION_INTERFACE, NULL, &err);
@@ -1268,6 +1287,7 @@ int _bt_pbap_get_list(const bluetooth_device_address_t *address, int source,
                int type,  bt_pbap_list_parameters_t *app_param)
 {
        BT_DBG("+");
+       GDBusConnection *g_conn;
        GDBusProxy *g_pbap_session_proxy = NULL;
        char address_string[18] = { 0, };
        char *source_string = NULL;
@@ -1300,7 +1320,13 @@ int _bt_pbap_get_list(const bluetooth_device_address_t *address, int source,
                        address_string, source_string, type_string);
 
        BT_DBG("Session Path = %s\n", g_pbap_session_path);
-       g_pbap_session_proxy =  g_dbus_proxy_new_sync(dbus_connection,
+
+       g_conn = _bt_gdbus_get_session_gconn();
+       if (g_conn == NULL) {
+               BT_ERR("Couldn't connect to session bus");
+               return 0;
+       }
+       g_pbap_session_proxy =  g_dbus_proxy_new_sync(g_conn,
                        G_DBUS_PROXY_FLAGS_NONE, NULL,
                        PBAP_SESSION_SERVICE, g_pbap_session_path,
                        PBAP_SESSION_INTERFACE, NULL, &err);
@@ -1349,6 +1375,7 @@ int _bt_pbap_pull_vcard(const bluetooth_device_address_t *address,
                int source, int type, bt_pbap_pull_vcard_parameters_t *app_param)
 {
        BT_DBG("+");
+       GDBusConnection *g_conn;
        GDBusProxy *g_pbap_session_proxy = NULL;
        char address_string[18] = { 0, };
        char *source_string = NULL;
@@ -1380,7 +1407,13 @@ int _bt_pbap_pull_vcard(const bluetooth_device_address_t *address,
                        address_string, source_string, type_string);
 
        BT_DBG("Session Path = %s\n", g_pbap_session_path);
-       g_pbap_session_proxy =  g_dbus_proxy_new_sync(dbus_connection,
+
+       g_conn = _bt_gdbus_get_session_gconn();
+       if (g_conn == NULL) {
+               BT_ERR("Couldn't connect to session bus");
+               return 0;
+       }
+       g_pbap_session_proxy =  g_dbus_proxy_new_sync(g_conn,
                        G_DBUS_PROXY_FLAGS_NONE, NULL,
                        PBAP_SESSION_SERVICE, g_pbap_session_path,
                        PBAP_SESSION_INTERFACE, NULL, &err);
@@ -1427,6 +1460,7 @@ int _bt_pbap_phonebook_search(const bluetooth_device_address_t *address,
                int source, int type, bt_pbap_search_parameters_t *app_param)
 {
        BT_DBG("+");
+       GDBusConnection *g_conn;
        GDBusProxy *g_pbap_session_proxy = NULL;
        char address_string[18] = { 0, };
        char *source_string = NULL;
@@ -1459,7 +1493,12 @@ int _bt_pbap_phonebook_search(const bluetooth_device_address_t *address,
 
        BT_DBG("Session Path = %s\n", g_pbap_session_path);
 
-       g_pbap_session_proxy =  g_dbus_proxy_new_sync(dbus_connection,
+       g_conn = _bt_gdbus_get_session_gconn();
+       if (g_conn == NULL) {
+               BT_ERR("Couldn't connect to session bus");
+               return 0;
+       }
+       g_pbap_session_proxy =  g_dbus_proxy_new_sync(g_conn,
                        G_DBUS_PROXY_FLAGS_NONE, NULL,
                        PBAP_SESSION_SERVICE, g_pbap_session_path,
                        PBAP_SESSION_INTERFACE, NULL, &err);
index e1de163..1787cc5 100644 (file)
@@ -44,8 +44,14 @@ typedef enum {
 
 int _bt_adapter_request_delayed(int function);
 
+int _bt_enable_adapter_check_status(void);
+
 int _bt_enable_adapter(void);
 
+int _bt_disable_adapter_check_status(void);
+
+void _bt_keep_bt_status_vconf(void);
+
 int _bt_disable_adapter(void);
 
 int _bt_recover_adapter(void);
@@ -107,6 +113,8 @@ int _bt_get_profile_connected_devices(char *profile_uuid, GArray **addr_list);
 int _bt_get_bonded_device_info(bluetooth_device_address_t *device_address,
                                bluetooth_device_info_t *dev_info);
 
+int _bt_is_alias_set(bluetooth_device_address_t *device_address, gboolean *is_alias_set);
+
 int _bt_get_timeout_value(int *timeout);
 
 gboolean _bt_is_discovering(void);
index 3d902c5..8bc9875 100644 (file)
@@ -33,7 +33,6 @@ typedef struct {
        int disconnection_type;
        char *address;
        gboolean ag_flag;
-       GArray *out_param1;
 } bt_headset_wait_t;
 
 typedef struct {
@@ -51,7 +50,6 @@ typedef struct {
        int req_id;
        char *address;
        bt_pending_request_t  pending;
-       GArray *out_param;
        int type;
 } bt_audio_function_data_t;
 
index d774b13..95e2a68 100644 (file)
@@ -349,11 +349,9 @@ typedef struct {
        char *address;
 } bt_function_data_t;
 
-GDBusConnection *_bt_get_system_conn(void);
+GDBusConnection *_bt_gdbus_get_system_gconn(void);
 
-GDBusConnection *_bt_get_system_gconn(void);
-
-GDBusConnection *_bt_get_session_gconn(void);
+GDBusConnection *_bt_gdbus_get_session_gconn(void);
 
 void *_bt_get_net_conn(void);
 
index a364cfd..5391e22 100644 (file)
@@ -80,6 +80,8 @@ char *_bt_get_bonded_device_name(char *address);
 
 gboolean _bt_is_bonding_device_address(const char *address);
 
+void _bt_pending_connect_le_device(void);
+
 int _bt_connect_le_device(int req_id, const bluetooth_device_address_t *bd_addr,
                gboolean auto_connect);
 
index fd99aa5..18e24e1 100644 (file)
@@ -1134,7 +1134,7 @@ typedef enum {
        HTYPE_TRANS_SET_PROTOCOL,
        HTYPE_TRANS_DATA,
        HTYPE_TRANS_UNKNOWN
-}bt_hid_header_type_t;
+} bt_hid_header_type_t;
 
 /**
  * HID Param type
@@ -1142,7 +1142,7 @@ typedef enum {
 typedef enum {
        PTYPE_DATA_RTYPE_INPUT,
        PTYPE_DATA_RTYPE_OUTPUT
-}bt_hid_param_type_t;
+} bt_hid_param_type_t;
 
 /**
  * Stucture to hid receive data
@@ -3366,6 +3366,32 @@ void bt_get_bonded_device(void)
 int bluetooth_get_bonded_device(const bluetooth_device_address_t *device_address,
                                        bluetooth_device_info_t *dev_info);
 
+
+/**
+ * @fn int bluetooth_get_is_alias_set(const bluetooth_device_address_t *device_address,
+ *                                     gboolean *is_alias_set)
+ * @brief Get is_alias_set property of device
+ *
+ * This API gets is_alias_set property of a bonded device.
+ *
+ * This function is a synchronous call.
+ * Information for is_alias_set property can be obtained only when result code is BLUETOOTH_ERROR_NONE.
+ * If not,there is no valid information in the is_alias_set.
+ *
+ * @return     BLUETOOTH_ERROR_NONE - Success \n
+ *                     BLUETOOTH_ERROR_NOT_SUPPORT - Opreation not supported \n
+ * @remark None
+ @code
+       int ret = 0;
+       gboolean alias_set;
+       bluetooth_device_address_t device_address = {{0x00,0x1C,0x43,0x2B,0x1A,0xE5}};
+
+       ret = bluetooth_get_is_alias_set(&device_address, &alias_set);
+ @endcode
+ */
+int bluetooth_get_is_alias_set(const bluetooth_device_address_t *device_address,
+                               gboolean *is_alias_set);
+
 /**
  * @fn int bluetooth_set_alias(const bluetooth_device_address_t *device_address, const char *alias)
  * @brief set alias for bonded device
index e9532d3..8990ef0 100644 (file)
@@ -193,6 +193,7 @@ typedef enum {
        BT_SEARCH_SERVICE,
        BT_CANCEL_SEARCH_SERVICE,
        BT_GET_BONDED_DEVICE,
+       BT_GET_IS_ALIAS_SET,
        BT_SET_ALIAS,
        BT_SET_AUTHORIZATION,
        BT_UNSET_AUTHORIZATION,