Implement close function for GATT plugin 48/261148/2
authorSeonah Moon <seonah1.moon@samsung.com>
Mon, 12 Jul 2021 10:38:11 +0000 (19:38 +0900)
committerSeonah Moon <seonah1.moon@samsung.com>
Mon, 12 Jul 2021 10:40:25 +0000 (19:40 +0900)
Change-Id: I87a9ba031d8e02166b22eb4aebdd1c6b7f31f92f

plugins/ble-gatt/ble-gatt-plugin.cpp
src/vine-data-path.cpp
tool/tool_run.cpp

index 45a1793..09f5792 100755 (executable)
@@ -267,8 +267,15 @@ void __gatt_server_noti_sent_cb(int result,
 static void __gatt_client_service_changed_cb(bt_gatt_client_h client,
                bt_gatt_client_service_change_type_e type, const char *uuid, void *user_data)
 {
-       VINE_LOGI("gatt[%p] service[%s] is %s",
-                       type == BT_GATT_CLIENT_SERVICE_ADDED ? "added." : "removed." );
+       VINE_LOGI("gatt[%p] service uuid[%s] is %s",
+                       user_data, uuid, type == BT_GATT_CLIENT_SERVICE_ADDED ? "added." : "removed." );
+
+       RET_IF(user_data == NULL, "user_data is NULL");
+       // Should added state be handled?
+       RET_IF(type == BT_GATT_CLIENT_SERVICE_ADDED, "service is added.");
+
+       vine_gatt_s *gatt = (vine_gatt_s *)user_data;
+       __invoke_terminated_cb(gatt->user);
 }
 
 void __gatt_client_write_complete_cb(int result, bt_gatt_h gatt_handle, void *user_data)
@@ -772,7 +779,19 @@ int gatt_write(vine_dp_plugin_h handle, unsigned char *buf, size_t len)
 
 int gatt_close(vine_dp_plugin_h handle)
 {
-       return VINE_DATA_PATH_ERROR_NONE;
+       RET_VAL_IF(handle == NULL, VINE_DATA_PATH_ERROR_INVALID_PARAMETER, "handle is NULL");
+
+       vine_gatt_s *gatt = (vine_gatt_s *)handle;
+       int ret;
+
+       if (gatt->type == VINE_GATT_ROLE_SERVER && gatt->role.server) {
+               ret = bt_gatt_server_unregister_service(gatt->role.server->server, gatt->service);
+               VINE_LOGI("Unregister service[%p]", gatt->service);
+       } else if (gatt->type == VINE_GATT_ROLE_CLIENT) {
+               ret = bt_gatt_disconnect(gatt->remote_address);
+               VINE_LOGI("Disconnect from %s", gatt->remote_address);
+       }
+       return __convert_bt_error_to_data_path_error(ret);
 }
 
 int gatt_get_local_address_info(vine_dp_plugin_h handle,
index c0aac6e..5dce302 100755 (executable)
@@ -484,7 +484,7 @@ int vine_data_path_close(vine_data_path_h datapath)
        RET_VAL_IF(datapath == NULL, VINE_ERROR_INVALID_PARAMETER, "datapath is NULL");
 
        vine_data_path_s *dp = (vine_data_path_s *)datapath;
-       RET_VAL_IF(!dp->plugin_fn || dp->plugin_fn->close,
+       RET_VAL_IF(!dp->plugin_fn || !dp->plugin_fn->close,
                        VINE_ERROR_INVALID_PARAMETER, "plugin_fn is NULL");
        dp->plugin_fn->close(dp->plugin_handle);
 
index c74933b..12df100 100755 (executable)
@@ -141,7 +141,7 @@ static void __received_cb(vine_dp_h dp, size_t received_len, void *user_data)
 
 static void __terminated_cb(vine_dp_h dp, void *user_data)
 {
-       printf("peer is terminated.\n");
+       printf("peer[%p] is terminated.\n", dp);
        _stop_message_timer(dp);
 }