Add new internal API to disconnect device 87/197187/1
authorDeokhyun Kim <dukan.kim@samsung.com>
Thu, 10 Jan 2019 07:19:41 +0000 (16:19 +0900)
committerDeokhyun Kim <dukan.kim@samsung.com>
Thu, 10 Jan 2019 07:19:48 +0000 (16:19 +0900)
  - int bt_device_disconnect(const char *remote_address)

Change-Id: Ic5cfbff9428beb6320887e94e967076d760bf2c0
Signed-off-by: Deokhyun Kim <dukan.kim@samsung.com>
include/bluetooth_internal.h
src/bluetooth-device.c
test/bt_unit_test.c
test/bt_unit_test.h

index 42cc10c..e9a3286 100644 (file)
@@ -815,6 +815,29 @@ int bt_adapter_foreach_profile_connected_devices(const char *profile_uuid,
 /**
  * @internal
  * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE
+ * @brief Disconnects a remote Bluetooth device.
+ * @since_tizen 4.0
+ * @privlevel platform
+ * @privilege %http://tizen.org/privilege/bluetooth.admin
+ *
+ * @param[in] remote_address The address of the remote Bluetooth device
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #BT_ERROR_NONE  Successful
+ * @retval #BT_ERROR_NOT_INITIALIZED  Not initialized
+ * @retval #BT_ERROR_INVALID_PARAMETER  Invalid parameter
+ * @retval #BT_ERROR_NOT_ENABLED  Not enabled
+ * @retval #BT_ERROR_OPERATION_FAILED  Operation failed
+ * @retval #BT_ERROR_PERMISSION_DENIED  Permission denied
+ * @retval #BT_ERROR_NOT_SUPPORTED  Not supported
+ *
+ * @see bt_device_set_connection_state_changed_cb()
+ */
+int bt_device_disconnect(const char *remote_address);
+
+/**
+ * @internal
+ * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE
  * @brief Gets a connection state
  * @since_tizen @if WEARABLE @else 2.4 @endif
  *
index 9c33d09..18f5392 100644 (file)
@@ -69,6 +69,23 @@ static bt_uuid2svc_table_t uuid2svc_mask[] = {
 };
 
 
+int bt_device_disconnect(const char *remote_address)
+{
+       bluetooth_device_address_t addr_hex = { {0,} };
+       int error_code = BT_ERROR_NONE;
+
+       BT_CHECK_SUPPORTED_FEATURE(BT_FEATURE_COMMON);
+       BT_CHECK_INIT_STATUS();
+       BT_CHECK_INPUT_PARAMETER(remote_address);
+
+       _bt_convert_address_to_hex(&addr_hex, remote_address); /* LCOV_EXCL_START */
+       error_code = _bt_get_error_code(bluetooth_disconnect_device(&addr_hex));
+       if (error_code != BT_ERROR_NONE)
+               BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), error_code);
+
+       return error_code;
+}
+
 int bt_device_create_bond(const char *device_address)
 {
        bluetooth_device_address_t addr_hex = { {0,} };
index 7041e89..5653af8 100644 (file)
@@ -370,6 +370,8 @@ tc_table_t tc_device[] = {
                , BT_UNIT_TEST_FUNCTION_DEVICE_SET_BOND_CREATED_CB},
        {"bt_device_set_bond_destroyed_cb"
                , BT_UNIT_TEST_FUNCTION_DEVICE_SET_BOND_DESTROYED_CB},
+       {"bt_device_disconnect"
+               , BT_UNIT_TEST_FUNCTION_DEVICE_DISCONNECT},
        {"bt_device_create_bond"
                , BT_UNIT_TEST_FUNCTION_DEVICE_CREATE_BOND},
        {"bt_device_create_bond_by_type"
@@ -5139,6 +5141,12 @@ int test_input_callback(void *data)
                        break;
                }
 
+               case BT_UNIT_TEST_FUNCTION_DEVICE_DISCONNECT: {
+                       ret = bt_device_disconnect(remote_addr);
+                       TC_PRT("returns %s\n", __bt_get_error_message(ret));
+                       break;
+               }
+
                case BT_UNIT_TEST_FUNCTION_DEVICE_CREATE_BOND: {
                        ret = bt_device_create_bond(remote_addr);
                        TC_PRT("returns %s\n", __bt_get_error_message(ret));
index 753b7bd..b096d50 100644 (file)
@@ -148,6 +148,7 @@ typedef enum {
        BT_UNIT_TEST_FUNCTION_DEVICE_IS_PROFILE_CONNECTED,
        BT_UNIT_TEST_FUNCTION_DEVICE_SET_BOND_CREATED_CB,
        BT_UNIT_TEST_FUNCTION_DEVICE_SET_BOND_DESTROYED_CB,
+       BT_UNIT_TEST_FUNCTION_DEVICE_DISCONNECT,
        BT_UNIT_TEST_FUNCTION_DEVICE_CREATE_BOND,
        BT_UNIT_TEST_FUNCTION_DEVICE_CREATE_BOND_BY_TYPE,
        BT_UNIT_TEST_FUNCTION_DEVICE_DESTROY_BOND,