Add rfcomm socket disconnected event sending 60/134060/2
authorAtul Rai <a.rai@samsung.com>
Wed, 14 Jun 2017 09:59:27 +0000 (15:29 +0530)
committerAtul Rai <a.rai@samsung.com>
Wed, 14 Jun 2017 10:56:35 +0000 (16:26 +0530)
This patch adds implementation to send RFCOMM client disconnection event
if an incomming client (Local device: RFCOMM Server) is disconnected.

Change-Id: I7e5f680329608a9d90cd54e02b3feaeddb7af018
Signed-off-by: Atul Rai <a.rai@samsung.com>
bt-api/bt-rfcomm-server.c

index 16f0fa4..38f593d 100644 (file)
@@ -666,6 +666,34 @@ static void __remove_remote_client_info(rfcomm_remote_client_info_t *rem_client)
        BT_DBG("-");
 }
 
+static void __handle_rfcomm_client_disconnected(rfcomm_server_info_t *server_info,
+               rfcomm_remote_client_info_t *rem_client)
+{
+       bluetooth_rfcomm_disconnection_t disconn_info;
+       bt_event_info_t *event_info;
+
+       BT_DBG("+");
+
+       if (rem_client == NULL || server_info == NULL)
+               return;
+
+       event_info = _bt_event_get_cb_data(BT_RFCOMM_SERVER_EVENT);
+       if (event_info == NULL) {
+               return;
+       }
+
+       memset(&disconn_info, 0x00, sizeof(bluetooth_rfcomm_disconnection_t));
+       disconn_info.device_role = RFCOMM_ROLE_SERVER;
+       g_strlcpy(disconn_info.uuid, server_info->uuid, BLUETOOTH_UUID_STRING_MAX);
+       _bt_convert_addr_string_to_type(disconn_info.device_addr.addr, rem_client->addr);
+       BT_DBG("Disconnected FD [%d]", rem_client->sock_fd);
+       disconn_info.socket_fd = rem_client->sock_fd;
+
+       _bt_common_event_cb(BLUETOOTH_EVENT_RFCOMM_DISCONNECTED,
+                       BLUETOOTH_ERROR_NONE, &disconn_info,
+                       event_info->cb, event_info->user_data);
+}
+
 static void __remove_rfcomm_server(rfcomm_server_info_t *info)
 {
        rfcomm_remote_client_info_t *client_info;
@@ -683,6 +711,7 @@ static void __remove_rfcomm_server(rfcomm_server_info_t *info)
                                break;
 
                        info->conn_list = g_slist_remove(info->conn_list, client_info);
+                       __handle_rfcomm_client_disconnected(info, client_info);
                        __remove_remote_client_info(client_info);
                } while(info->conn_list);
        }
@@ -877,6 +906,7 @@ fail:
        BT_ERR("Failure occured, remove client connection");
        server_info->conn_list = g_slist_remove(
                        server_info->conn_list, client_info);
+       __handle_rfcomm_client_disconnected(server_info, client_info);
        __remove_remote_client_info(client_info);
        return FALSE;
 }