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)
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,
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);