[Bluetooth] Stop server after unregistering last service 70/244470/3
authorRafal Walczyna <r.walczyna@samsung.com>
Fri, 18 Sep 2020 13:10:28 +0000 (15:10 +0200)
committerRafal Walczyna <r.walczyna@samsung.com>
Mon, 21 Sep 2020 11:15:51 +0000 (13:15 +0200)
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 <r.walczyna@samsung.com>
src/bluetooth/bluetooth_gatt_server.cc
src/bluetooth/bluetooth_gatt_server_service.cc
src/bluetooth/bluetooth_gatt_server_service.h

index c73e911..d75cb0d 100644 (file)
@@ -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);
 }
 
index fe05c02..17488bc 100644 (file)
@@ -709,5 +709,10 @@ void BluetoothGATTServerService::ClearGATTData() {
   callback_names_.clear();
 }
 
+bool BluetoothGATTServerService::IsAnyServiceRegistered() {
+  ScopeLogger();
+  return 0 != gatt_objects_.size();
+}
+
 }  // namespace bluetooth
 }  // namespace extension
index 74b25dd..3d7579e 100644 (file)
@@ -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<int, bt_gatt_h> gatt_objects_;