Integrate list of client/server info to conn info list 72/233872/2
authorWootak Jung <wootak.jung@samsung.com>
Wed, 20 May 2020 01:16:35 +0000 (10:16 +0900)
committerWootak Jung <wootak.jung@samsung.com>
Wed, 20 May 2020 02:44:53 +0000 (11:44 +0900)
Change-Id: I999a6ab8d82d1d5908315f6d296f78a28471ea29
Signed-off-by: Wootak Jung <wootak.jung@samsung.com>
bt-oal/bluez_hal/src/bt-hal-gatt-client.c

index 7f9954c..7c5d837 100644 (file)
@@ -129,9 +129,6 @@ typedef struct {
        GSList *gatt_list_services;
 } hal_gattc_server_info_t;
 
-/* Linked List of connected GATT server */
-static GSList *hal_gattc_server_info_list = NULL;
-
 typedef struct {
        int client_if;
        bt_bdaddr_t bd_addr;    /*remote server address*/
@@ -140,8 +137,33 @@ typedef struct {
        gboolean is_gatt_connected;             /*status for GattConnected signal*/
 } hal_gattc_client_info_t;
 
+typedef struct {
+       bt_bdaddr_t bd_addr;        /* remote server address */
+       int conn_id;                /* connection id */
+       int inst_id;                /* server instance id */
+       gboolean is_gatt_connected; /* status for GattConnected signal */
+       int client_if;              /* client id */
+       GSList *gatt_list_services;
+} hal_gattc_conn_info_t;
+
+/* TODO:
+ * Remove this feature after verified.
+ * Remove hal_gattc_client/server_info_t and use hal_gattc_conn_info_t
+ * Remove hal_gattc_client/server_info_list and use hal_gattc_conn_info_list
+ */
+#define __INTEGRATE_HAL_GATT_INFO__
+#ifndef __INTEGRATE_HAL_GATT_INFO__
+/* Linked List of connected GATT server */
+static GSList *hal_gattc_server_info_list = NULL;
 /* Linked list of connected GATT client connection */
-static GSList * hal_gattc_client_info_list = NULL;
+static GSList *hal_gattc_client_info_list = NULL;
+#else
+static GSList *hal_gattc_conn_info_list = NULL;
+#define hal_gattc_server_info_t hal_gattc_conn_info_t
+#define hal_gattc_client_info_t hal_gattc_conn_info_t
+#define hal_gattc_server_info_list hal_gattc_conn_info_list
+#define hal_gattc_client_info_list hal_gattc_conn_info_list
+#endif
 
 static bt_pending_le_conn_info_s *pending_le_conn_info = NULL;
 static guint pending_le_conn_timer_id = 0;
@@ -343,9 +365,12 @@ bt_status_t btif_gattc_register_client(bt_uuid_t *uuid)
 
 bt_status_t btif_gattc_add_connection_info(const bt_bdaddr_t *bd_addr, int conn_id, int server_inst_id)
 {
+#ifndef __INTEGRATE_HAL_GATT_INFO__
        hal_gattc_client_info_t *client_info = NULL;
+#endif
        hal_gattc_server_info_t *server_info = NULL;
 
+#ifndef __INTEGRATE_HAL_GATT_INFO__
        /* Add client connection info in list */
        client_info = g_malloc0(sizeof(hal_gattc_client_info_t));
        client_info->client_if = -1;
@@ -354,6 +379,7 @@ bt_status_t btif_gattc_add_connection_info(const bt_bdaddr_t *bd_addr, int conn_
        client_info->inst_id = server_inst_id;
        hal_gattc_client_info_list = g_slist_append(hal_gattc_client_info_list, client_info);
        DBG("Added client connection info in list");
+#endif
 
        /* Add server connection info in list */
        server_info = __bt_find_gatt_conn_info(bd_addr);
@@ -363,6 +389,9 @@ bt_status_t btif_gattc_add_connection_info(const bt_bdaddr_t *bd_addr, int conn_
                server_info->conn_id = conn_id;
                server_info->inst_id = server_inst_id;
                server_info->is_gatt_connected = TRUE;
+#ifdef __INTEGRATE_HAL_GATT_INFO__
+               server_info->client_if = -1;
+#endif
                hal_gattc_server_info_list = g_slist_append(hal_gattc_server_info_list, server_info);
                DBG("Added server connection info in list");
        }
@@ -3682,13 +3711,18 @@ static void __le_connection_req_cb(GDBusProxy *proxy, GAsyncResult *res,
        gattc_data->conn_id = __hal_generate_conn_id() ;
        gattc_data->inst_id = __hal_generate_server_instance_id();
 
+#ifndef __INTEGRATE_HAL_GATT_INFO__
        hal_gattc_client_info_list = g_slist_append(hal_gattc_client_info_list, gattc_data);
+#endif
 
        /*add gatt server connection info*/
        gatt_conn_info = g_malloc0(sizeof(hal_gattc_server_info_t));
        memcpy(gatt_conn_info->bd_addr.address, gattc_data->bd_addr.address, BT_HAL_ADDRESS_LENGTH_MAX);
        gatt_conn_info->conn_id = gattc_data->conn_id;
        gatt_conn_info->inst_id = gattc_data->inst_id;
+#ifdef __INTEGRATE_HAL_GATT_INFO__
+       gatt_conn_info->client_if = gattc_data->client_if;
+#endif
        hal_gattc_server_info_list = g_slist_append(hal_gattc_server_info_list, gatt_conn_info);
 
        return;
@@ -3779,7 +3813,9 @@ int _bt_hal_handle_gattc_connected_event(char* address, gboolean gatt_connected)
        bt_bdaddr_t bd_addr;
        int event;
        hal_gattc_client_info_t *gattc_client = NULL;
+#ifndef __INTEGRATE_HAL_GATT_INFO__
        int inst_id = -1;
+#endif
 
        event = gatt_connected ? HAL_EV_GATT_CLIENT_CONNECTED :
                                HAL_EV_GATT_CLIENT_DISCONNECTED;
@@ -3809,11 +3845,13 @@ int _bt_hal_handle_gattc_connected_event(char* address, gboolean gatt_connected)
        }
 
        if (!gatt_connected) {
+#ifndef __INTEGRATE_HAL_GATT_INFO__
                inst_id = gattc_client->inst_id;
 
                /* remove the gatt client info from the client list also*/
                hal_gattc_client_info_list = g_slist_remove(hal_gattc_client_info_list, gattc_client);
                g_free(gattc_client);
+#endif
 
                //find the connected server info
                conn_info = __bt_find_gatt_conn_info(&bd_addr);
@@ -3822,10 +3860,12 @@ int _bt_hal_handle_gattc_connected_event(char* address, gboolean gatt_connected)
                        return -1;
                }
 
+#ifndef __INTEGRATE_HAL_GATT_INFO__
                if (inst_id != conn_info->inst_id) {
                        ERR("server instance is different");
                        return -1;
                }
+#endif
 
                //remove gatt conn info from the server list
                DBG("remove the server conn_info from list after gatt disconnection");