Seperate GATT unregister instance function
[platform/core/connectivity/bluetooth-frwk.git] / bt-service / bt-service-headset-connection.c
old mode 100755 (executable)
new mode 100644 (file)
index 422f9ba..e489422
@@ -1,11 +1,5 @@
 /*
- * Bluetooth-frwk
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact:  Hocheol Seo <hocheol.seo@samsung.com>
- *              Girishashok Joshi <girish.joshi@samsung.com>
- *              Chanyeol Park <chanyeol.park@samsung.com>
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -21,9 +15,6 @@
  *
  */
 
-#include <dbus/dbus-glib.h>
-#include <dbus/dbus-glib-lowlevel.h>
-#include <dbus/dbus.h>
 #include <glib.h>
 #include <string.h>
 #include <dlog.h>
@@ -97,6 +88,7 @@ gboolean connect_remote_media_audio(gpointer user_data)
        _bt_convert_addr_type_to_string(remote_address, conn_info->dev_info.device_address.addr);
        if (p_connection_list == NULL) {
                BT_INFO("None of device connected and this hasbeen triggered");
+               g_free(conn_info);
                return FALSE;
        }
        if (conn_info->connection_type == BT_AUDIO_A2DP) {
@@ -106,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 {
@@ -119,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,20 +126,24 @@ gboolean connect_remote_media_audio(gpointer user_data)
 void _bt_get_bluetooth_device_info(char *remote_address, bluetooth_device_info_t *device)
 {
        GArray *dev_list = NULL;
-       int size,i=0;
-       bluetooth_device_info_t info;
+       int size = 0;
+       int i = 0;
+       bluetooth_device_info_t *info;
        char bond_address[BT_ADDRESS_STRING_SIZE] = { 0 };
-       dev_list = g_array_new (FALSE, FALSE, sizeof(gchar));
+
        if (device == NULL)
                return;
+
+       dev_list = g_array_new(FALSE, FALSE, sizeof(gchar));
+
        _bt_get_bonded_devices(&dev_list);
        size = (dev_list->len) / sizeof(bluetooth_device_info_t);
-       for (i=0; i < size; i++) {
-               info = g_array_index(dev_list, bluetooth_device_info_t, i);
-               _bt_convert_addr_type_to_string(bond_address, info.device_address.addr);
+       for (i = 0; i < size; i++) {
+               info = &g_array_index(dev_list, bluetooth_device_info_t, i);
+               _bt_convert_addr_type_to_string(bond_address, info->device_address.addr);
                if (strcmp(bond_address, remote_address) == 0) {
                        BT_INFO("Match found");
-                       memcpy(device, &info, sizeof(bluetooth_device_info_t));
+                       memcpy(device, info, sizeof(bluetooth_device_info_t));
                        g_array_free(dev_list, TRUE);
                        return;
                }
@@ -173,34 +171,36 @@ void _bt_headset_add_timer_function(int connection_type, bluetooth_device_info_t
 void _bt_start_timer_for_connection(char *remote_address, int connection_type)
 {
        GArray *dev_list = NULL;
-       int size,i=0,j;
-       bluetooth_device_info_t info;
+       int size;
+       int i;
+       int j;
+       bluetooth_device_info_t *info;
        char bond_address[BT_ADDRESS_STRING_SIZE] = { 0 };
-       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);
 
-       for (i=0; i < size; i++) {
-               info = g_array_index(dev_list, bluetooth_device_info_t, i);
+       for (i = 0; i < size; i++) {
+               info = &g_array_index(dev_list, bluetooth_device_info_t, i);
                j = 0;
                _bt_convert_addr_type_to_string(bond_address,
-                               info.device_address.addr);
+                               info->device_address.addr);
                if (strcmp(bond_address, remote_address) != 0)
                        continue;
                BT_INFO("Device address Matched");
 
-               while (j != info.service_index) {
-                       BT_INFO("UUID %s", info.uuids[j]);
+               while (j != info->service_index) {
+                       BT_INFO("UUID %s", info->uuids[j]);
                        if (connection_type == BT_AUDIO_A2DP) {
-                               if (strcmp(info.uuids[j], A2DP_SINK_UUID) == 0) {
+                               if (strcmp(info->uuids[j], A2DP_SINK_UUID) == 0) {
                                        BT_INFO("Remote Device has A2DP Sink Support start timer");
-                                       _bt_headset_add_timer_function(BT_AUDIO_A2DP, &info);
+                                       _bt_headset_add_timer_function(BT_AUDIO_A2DP, info);
                                        goto end;
                                }
                        } else {
-                               if (strcmp(info.uuids[j], HFP_HS_UUID) == 0) {
+                               if (strcmp(info->uuids[j], HFP_HS_UUID) == 0) {
                                        BT_INFO("Remote Device has HFP Sink Support start timer");
-                                       _bt_headset_add_timer_function(BT_AUDIO_HSP, &info);
+                                       _bt_headset_add_timer_function(BT_AUDIO_HSP, info);
                                        goto end;
                                }
                        }
@@ -213,18 +213,18 @@ end:
 
 void __bt_connection_manager_set_state(char *remote_address, int event)
 {
-       bt_connection_node_info_t *info = g_new0(bt_connection_node_info_t, 1);
+       bt_connection_node_info_t *info;
 
        char bond_address[BT_ADDRESS_STRING_SIZE] = { 0 };
        if (event == BLUETOOTH_EVENT_AG_CONNECTED) {
+               info = g_new0(bt_connection_node_info_t, 1);
                info->state = BLUETOOTH_HFP_CONNECTED;
                _bt_get_bluetooth_device_info(remote_address, &info->dev_info);
                _bt_convert_addr_type_to_string(bond_address,
                                info->dev_info.device_address.addr);
                BT_INFO("Adding HFP Connected device to list");
                p_connection_list = g_list_append(p_connection_list, info);
-       }
-       else if (event == BLUETOOTH_EVENT_AG_DISCONNECTED) {
+       } else if (event == BLUETOOTH_EVENT_AG_DISCONNECTED) {
                /* Delete coresponding node */
                BT_INFO("Deleting HFP Connected device from list");
                GList *list = NULL;
@@ -241,6 +241,7 @@ void __bt_connection_manager_set_state(char *remote_address, int event)
                p_connection_list = g_list_remove(p_connection_list, h_conn);
                g_free(h_conn);
        } else if (event == BLUETOOTH_EVENT_AV_CONNECTED) {
+               info = g_new0(bt_connection_node_info_t, 1);
                info->state = BLUETOOTH_A2DP_CONNECTED;
                _bt_get_bluetooth_device_info(remote_address, &info->dev_info);
                _bt_convert_addr_type_to_string(bond_address,