From 0d1f5cd0b9aee3f61a894a6884dda9dec00f91a4 Mon Sep 17 00:00:00 2001 From: Rafal Walczyna Date: Fri, 18 Sep 2020 15:10:28 +0200 Subject: [PATCH] [Bluetooth] Stop server after unregistering last service GATTServer has to be stopped in case of last service unregistration. [ACR] https://code.sec.samsung.net/jira/browse/TWDAPI-263 [TASK] https://code.sec.samsung.net/jira/browse/XWALK-2163 [Verification] Build successful. Tested in Chrome Console. Server stops when last service is unregistered. Change-Id: I756bf9d944937e03f7e808c929e31140f4145add Signed-off-by: Rafal Walczyna --- src/bluetooth/bluetooth_gatt_server.cc | 8 ++++++++ src/bluetooth/bluetooth_gatt_server_service.cc | 5 +++++ src/bluetooth/bluetooth_gatt_server_service.h | 2 ++ 3 files changed, 15 insertions(+) diff --git a/src/bluetooth/bluetooth_gatt_server.cc b/src/bluetooth/bluetooth_gatt_server.cc index c73e911b..d75cb0de 100644 --- a/src/bluetooth/bluetooth_gatt_server.cc +++ b/src/bluetooth/bluetooth_gatt_server.cc @@ -199,6 +199,14 @@ void BluetoothGATTServer::UnregisterService(const picojson::value& args, picojso return; } + if (false == service_.IsAnyServiceRegistered()) { + // Last service unregistered, stop GATTServer + // All native objects should be already freed, so just Deinitialize and notify + // JS layer about server's state change + Deinitialize(); + SetRunningState(false); + } + ReportSuccess(out); } diff --git a/src/bluetooth/bluetooth_gatt_server_service.cc b/src/bluetooth/bluetooth_gatt_server_service.cc index fe05c028..17488bc9 100644 --- a/src/bluetooth/bluetooth_gatt_server_service.cc +++ b/src/bluetooth/bluetooth_gatt_server_service.cc @@ -709,5 +709,10 @@ void BluetoothGATTServerService::ClearGATTData() { callback_names_.clear(); } +bool BluetoothGATTServerService::IsAnyServiceRegistered() { + ScopeLogger(); + return 0 != gatt_objects_.size(); +} + } // namespace bluetooth } // namespace extension diff --git a/src/bluetooth/bluetooth_gatt_server_service.h b/src/bluetooth/bluetooth_gatt_server_service.h index 74b25dd4..3d7579e7 100644 --- a/src/bluetooth/bluetooth_gatt_server_service.h +++ b/src/bluetooth/bluetooth_gatt_server_service.h @@ -53,6 +53,8 @@ class BluetoothGATTServerService { static bool DestroyCharacteristic(int total, int index, bt_gatt_h handle, void* user_data); static bool DestroyDescriptor(int total, int index, bt_gatt_h handle, void* user_data); + bool IsAnyServiceRegistered(); + private: BluetoothInstance& instance_; std::map gatt_objects_; -- 2.34.1