From 3c34a10ade0db18d75205c44d439c92db6ff06c8 Mon Sep 17 00:00:00 2001 From: lasan Date: Sat, 26 Oct 2024 18:06:50 +0530 Subject: [PATCH] Removed stray bluetooth_adapter files again --- .../implementation/linux/bluetooth_adapter.cc | 121 ------------------ .../implementation/linux/bluetooth_adapter.h | 86 ------------- 2 files changed, 207 deletions(-) delete mode 100644 internal/platform/implementation/linux/bluetooth_adapter.cc delete mode 100644 internal/platform/implementation/linux/bluetooth_adapter.h diff --git a/internal/platform/implementation/linux/bluetooth_adapter.cc b/internal/platform/implementation/linux/bluetooth_adapter.cc deleted file mode 100644 index 99f1bb0f..00000000 --- a/internal/platform/implementation/linux/bluetooth_adapter.cc +++ /dev/null @@ -1,121 +0,0 @@ -// Copyright 2023 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include -#include - -#include "internal/platform/implementation/bluetooth_adapter.h" -#include "internal/platform/implementation/linux/bluetooth_adapter.h" -#include "internal/platform/implementation/linux/dbus.h" -#include "internal/platform/implementation/linux/generated/dbus/bluez/adapter_client.h" -#include "internal/platform/logging.h" - -namespace nearby { -namespace linux { - -bool BluetoothAdapter::SetStatus(Status status) { - try { - bool val = status == api::BluetoothAdapter::Status::kEnabled; - bluez_adapter_->Powered(val); - return true; - } catch (const sdbus::Error &e) { - DBUS_LOG_PROPERTY_SET_ERROR(bluez_adapter_, "Powered", e); - return false; - } -} - -bool BluetoothAdapter::IsEnabled() const { - try { - return bluez_adapter_->Powered(); - } catch (const sdbus::Error &e) { - DBUS_LOG_PROPERTY_GET_ERROR(bluez_adapter_, "Powered", e); - return false; - } -} - -BluetoothAdapter::ScanMode BluetoothAdapter::GetScanMode() const { - bool powered = IsEnabled(); - if (!powered) { - return ScanMode::kNone; - } - - try { - bool discoverable = bluez_adapter_->Discoverable(); - return discoverable ? ScanMode::kConnectableDiscoverable - : ScanMode::kConnectable; - } catch (const sdbus::Error &e) { - DBUS_LOG_PROPERTY_GET_ERROR(bluez_adapter_, "Discoverable", e); - return ScanMode::kUnknown; - } -} - -bool BluetoothAdapter::SetScanMode(ScanMode scan_mode) { - switch (scan_mode) { - case ScanMode::kConnectable: - return SetStatus(Status::kEnabled); - case ScanMode::kConnectableDiscoverable: { - if (!SetStatus(Status::kEnabled)) { - return false; - } - - try { - bluez_adapter_->Discoverable(true); - } catch (const sdbus::Error &e) { - DBUS_LOG_PROPERTY_SET_ERROR(bluez_adapter_, "Discoverable", e); - return false; - } - - return true; - } - case ScanMode::kNone: - return SetStatus(Status::kDisabled); - default: - return false; - } -} - -std::string BluetoothAdapter::GetName() const { - try { - return bluez_adapter_->Alias(); - } catch (const sdbus::Error &e) { - DBUS_LOG_PROPERTY_GET_ERROR(bluez_adapter_, "Alias", e); - return {}; - } -} - -bool BluetoothAdapter::SetName(absl::string_view name, bool /*persist*/) { - return SetName(name); -} - -bool BluetoothAdapter::SetName(absl::string_view name) { - try { - bluez_adapter_->Alias(std::string(name)); - return true; - } catch (const sdbus::Error &e) { - DBUS_LOG_PROPERTY_SET_ERROR(bluez_adapter_, "Alias", e); - return false; - } -} - -std::string BluetoothAdapter::GetMacAddress() const { - try { - return bluez_adapter_->Address(); - } catch (const sdbus::Error &e) { - DBUS_LOG_PROPERTY_GET_ERROR(bluez_adapter_, "Address", e); - return {}; - } -} - -} // namespace linux -} // namespace nearby diff --git a/internal/platform/implementation/linux/bluetooth_adapter.h b/internal/platform/implementation/linux/bluetooth_adapter.h deleted file mode 100644 index 3d2bc900..00000000 --- a/internal/platform/implementation/linux/bluetooth_adapter.h +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright 2023 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef PLATFORM_IMPL_LINUX_BLUETOOTH_ADAPTER_H_ -#define PLATFORM_IMPL_LINUX_BLUETOOTH_ADAPTER_H_ -#include -#include - -#include "absl/strings/string_view.h" -#include "internal/platform/implementation/bluetooth_adapter.h" -#include "internal/platform/implementation/linux/bluez.h" -#include "internal/platform/implementation/linux/dbus.h" -#include "internal/platform/implementation/linux/generated/dbus/bluez/adapter_client.h" - -namespace nearby { -namespace linux { -class BluezAdapter : public sdbus::ProxyInterfaces { - public: - BluezAdapter(sdbus::IConnection &system_bus, - const sdbus::ObjectPath &adapter_object_path) - : ProxyInterfaces(system_bus, bluez::SERVICE_DEST, adapter_object_path) { - registerProxy(); - } - ~BluezAdapter() { unregisterProxy(); } -}; - -class BluetoothAdapter : public api::BluetoothAdapter { - public: - BluetoothAdapter(const BluetoothAdapter &) = default; - BluetoothAdapter(BluetoothAdapter &&) = delete; - BluetoothAdapter &operator=(const BluetoothAdapter &) = default; - BluetoothAdapter &operator=(BluetoothAdapter &&) = delete; - - BluetoothAdapter(sdbus::IConnection &system_bus, - const sdbus::ObjectPath &adapter_object_path) - : bluez_adapter_( - std::make_shared(system_bus, adapter_object_path)) {} - - ~BluetoothAdapter() override = default; - - bool SetStatus(Status status) override; - bool IsEnabled() const override; - - ScanMode GetScanMode() const override; - - bool SetScanMode(ScanMode scan_mode) override; - std::string GetName() const override; - - bool SetName(absl::string_view name) override; - bool SetName(absl::string_view name, bool persist) override; - std::string GetMacAddress() const override; - - bool RemoveDeviceByObjectPath(const sdbus::ObjectPath &device_object_path) { - try { - bluez_adapter_->RemoveDevice(device_object_path); - return true; - } catch (const sdbus::Error &e) { - DBUS_LOG_METHOD_CALL_ERROR(bluez_adapter_, "RemoveDevice", e); - return false; - } - } - - sdbus::ObjectPath GetObjectPath() const { - return bluez_adapter_->getObjectPath(); - } - - BluezAdapter &GetBluezAdapterObject() { return *bluez_adapter_; } - - private: - std::shared_ptr bluez_adapter_; -}; -} // namespace linux -} // namespace nearby - -#endif // PLATFORM_IMPL_LINUX_BLUETOOTH_ADAPTER_H_