[Bluetooth] BLEAdapter isScanning and BLEDevice new functions.
[platform/core/api/webapi-plugins.git] / src / bluetooth / bluetooth_le_adapter.cc
index 2a0fcd6..27fd38f 100644 (file)
@@ -119,7 +119,7 @@ class BluetoothLEServiceData : public ParsedDataHolder {
 
  private:
   BluetoothLEServiceData(UUID&& uuid, const std::string& data_str) : uuid_{std::move(uuid)} {
-    ScopeLogger("UUID: %s, data_str: %s", uuid.uuid_128_bit.c_str(), data_str.c_str());
+    ScopeLogger("UUID: %s, data_str: %s", uuid_.uuid_128_bit.c_str(), data_str.c_str());
 
     data_.Parse(data_str);
 
@@ -325,7 +325,7 @@ class BluetoothLEAdvertiseData : public ParsedDataHolder {
     const auto& service_data_obj = obj.get(kServiceData);
     if (service_data_obj.is<picojson::null>()) {
       return true;
-    } else if (!service_data_obj.is<picojson::value>()) {
+    } else if (!service_data_obj.is<picojson::object>()) {
       return false;
     }
 
@@ -465,6 +465,22 @@ void BluetoothLEAdapter::StopScan(const picojson::value& data, picojson::object&
   }
 }
 
+void BluetoothLEAdapter::IsScanning(picojson::object& out) {
+  ScopeLogger();
+
+  bool is_scanning;
+  int ret = bt_adapter_le_is_discovering(&is_scanning);
+
+  if (BT_ERROR_NONE != ret) {
+    LogAndReportError(
+        PlatformResult(ErrorCode::UNKNOWN_ERR, "Failed to check for scanning in progress"), &out,
+        ("Failed to check for scanning in progress: %d (%s)", ret, get_error_message(ret)));
+  } else {
+    scanning_ = is_scanning;
+    ReportSuccess(picojson::value(is_scanning), out);
+  }
+}
+
 void BluetoothLEAdapter::StartAdvertise(const picojson::value& data, picojson::object& out) {
   ScopeLogger();
   CHECK_BACKWARD_COMPABILITY_PRIVILEGE_ACCESS(Privilege::kBluetooth, Privilege::kBluetoothAdmin,