[Adapt] Handle Advertising App abnormal termination scenario 12/119912/2
authorAnupam Roy <anupam.r@samsung.com>
Mon, 20 Mar 2017 12:38:57 +0000 (18:08 +0530)
committerPyun DoHyun <dh79.pyun@samsung.com>
Tue, 21 Mar 2017 00:07:27 +0000 (17:07 -0700)
If Advertising application is abnormally terminated
(caught by "NameOwnerChanged" signal), then disable
advertising on all adv instances that were used by the app.
Also, unregister the server instance that was allocated with stack
for advertising

Change-Id: I36298850e2e99c13b472c50d32a7ece2b565c5d7
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
bt-service-adaptation/services/bt-request-handler.c
bt-service-adaptation/services/bt-service-gatt.h
bt-service-adaptation/services/gatt/bt-service-gatt.c

index 37a1fd2..e6ad7bb 100644 (file)
@@ -35,6 +35,7 @@
 #include "bt-service-audio-common.h"
 #include "bt-service-avrcp-tg.h"
 #include "bt-service-avrcp-ctrl.h"
+#include "bt-service-gatt.h"
 
 #ifdef TIZEN_DPM_ENABLE
 #include "bt-service-dpm.h"
@@ -2166,6 +2167,9 @@ static void __name_owner_changed(GDBusConnection *connection,
                return;
 
        _bt_check_hdp_app_termination(name);
+
+       /* Advertising App Termination */
+       _bt_check_adv_app_termination(name);
 }
 
 int _bt_service_register(void)
index 7f7eab4..b3db770 100644 (file)
@@ -56,6 +56,8 @@ void _bt_get_previous_scan_rsp_data(bluetooth_scan_resp_data_t *scan, int *len,
 
 int _bt_is_sender_gatt_server_with_no_adv(const char *sender, int adv_handle);
 
+void _bt_check_adv_app_termination(const char *name);
+
 #if 0
 int _bt_gatt_server_register(char *sender);
 
index 51a1870..e596c95 100644 (file)
@@ -91,6 +91,41 @@ static void __bt_handle_server_instance_registered(event_gatts_register_t *data)
 
 static void __bt_gatt_event_handler(int event_type, gpointer event_data);
 
+void _bt_check_adv_app_termination(const char *name)
+{
+       bt_service_app_info_t *app = NULL;
+       int k;
+       int result = OAL_STATUS_SUCCESS;
+
+       BT_DBG("Adv app name [%s]", name);
+
+       ret_if(NULL == name);
+
+       for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
+               app = &numapps[k];
+
+               /* Search for a app which has same sender */
+               if (!strncasecmp(app->sender, name, strlen(name)) && app->is_initialized == TRUE) {
+                       BT_DBG("Match found, name: %s", name);
+
+                       /* If Advertising is enabled, stop it */
+                       if (app->adv_handle > 0) {
+                               BT_INFO("Stop advertising on instance ID [%d]", app->instance_id);
+                               result = adapter_ble_multi_adv_disable(app->instance_id);
+                               if (result != OAL_STATUS_SUCCESS) {
+                                       BT_ERR("OAL API adapter_ble_multi_adv_enable Fail %d", result);
+                               }
+                       }
+                       /* TODO: Cleanup all Services, chars and Descriptors of the associated GATT server */
+
+                       /* Unregister the server instance */
+                       _bt_unregister_server_instance(name, app->adv_handle);
+               }
+       }
+
+       BT_DBG("-");
+}
+
 void _bt_get_adv_handle_from_instance(int server_inst, int *adv_handle)
 {
        BT_DBG("+");