static void __bt_free_service_info(bt_gatt_service_info_t *service_info);
-static int __bt_do_unregister_gatt_instance(int instance_id);
+static int __bt_unregister_gatt_client_instance(int client_if);
+
static void __bt_service_reset_gatt_data(void);
#ifdef TIZEN_GATT_CLIENT
static void __bt_gatt_event_handler(int event_type, gpointer event_data);
+typedef enum {
+ BT_GATT_SERVER = 1,
+ BT_GATT_CLIENT,
+} bt_gatt_type_e;
+
void _bt_check_adv_app_termination(const char *name)
{
bt_service_app_info_t *app = NULL;
int k;
- int apps[MAX_APPS_SUPPORTED];
+ int apps[MAX_APPS_SUPPORTED] = { 0, };
ret_if(NULL == name);
if (!strncasecmp(app->sender, name, strlen(name)) && app->is_initialized == TRUE) {
BT_DBG("Match found, name: %s", name);
- /* TODO 1: If App has both GATT client / server role? */
/* TODO 2: Need to manage app info as list, not array.
This loop always run for MAX count if any apps are terminated.
*/
_bt_set_advertising(app->sender, app->adv_handle, FALSE, FALSE);
}
- apps[app->instance_id] = 1; /* App holds a GATT client Instance */
+ apps[app->instance_id] = BT_GATT_SERVER; /* App holds a GATT server Instance */
} else if (app->client_id != -1) {
/* GATT client */
- apps[app->client_id] = 1; /* App holds a GATT server Instance */
+ apps[app->client_id] = BT_GATT_CLIENT; /* App holds a GATT client Instance */
}
}
}
/* Unregister all apps one by one */
for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
- if (apps[k] == 1) {
- BT_INFO("Unregister app[%d]", k);
- /* Unregister client or server instance */
- __bt_do_unregister_gatt_instance(k);
+ if (apps[k] == BT_GATT_SERVER) {
+ BT_INFO("Unregister server app[%d]", k);
+ /* Unregister server instance */
+ __bt_unregister_gatt_server_instance(k);
+ } else if (apps[k] == BT_GATT_CLIENT) {
+ BT_INFO("Unregister client app[%d]", k);
+ /* Unregister client instance */
+ __bt_unregister_gatt_client_instance(k);
}
}
}
}
}
-static int __bt_do_unregister_gatt_instance(int instance_id)
+static int __bt_unregister_gatt_client_instance(int client_if)
{
int ret = OAL_STATUS_SUCCESS;
int k;
- BT_INFO("DeAllocate server or client instance ID [%d]", instance_id);
+ BT_INFO("DeAllocate client instance ID [%d]", client_if);
/* Reset data: instance_id parameter could be either for GATT Server or for GATT client */
for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
- if (numapps[k].instance_id == instance_id) {
- BT_INFO("This is a GATT server app, unregister: Slot [%d] vacant", k);
- numapps[k].is_initialized = FALSE;
- numapps[k].instance_id = -1;
- numapps[k].adv_handle = 0;
- numapps[k].adv_instance = -1;
- memset(numapps[k].sender, 0x00, sizeof(numapps[k].sender));
- memset(numapps[k].uuid, 0x00, sizeof(numapps[k].uuid));
- memset(numapps[k].adv_data.data, 0x00, BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX);
- memset(numapps[k].scan_rsp.data, 0x00, BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX);
- numapps[k].adv_data_len = 0;
- numapps[k].scan_rsp_len = 0;
-
- /* Its a GATT Server Instance */
- ret = gatts_unregister(instance_id);
- if (ret != OAL_STATUS_SUCCESS) {
- BT_ERR("DeAllocate server instance with stack Fail ret: %d", ret);
- return BLUETOOTH_ERROR_INTERNAL;
- }
- break;
- } else if (numapps[k].client_id == instance_id) {
+ if (numapps[k].client_id == client_if) {
BT_INFO("This is a GATT client app, unregister: Slot [%d] vacant", k);
numapps[k].client_id = -1;
numapps[k].is_initialized = FALSE;
memset(&numapps[k].address.addr, 0x00, sizeof(bluetooth_device_address_t));
/* Its a GATT Client Instance */
- ret = gattc_deregister(instance_id);
+ ret = gattc_deregister(client_if);
if (ret != OAL_STATUS_SUCCESS) {
BT_ERR("DeAllocate GATT Client instance with stack Fail ret: %d", ret);
return BLUETOOTH_ERROR_INTERNAL;