mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-15 07:06:11 -04:00
78 lines
2.4 KiB
C++
78 lines
2.4 KiB
C++
#ifndef PLATFORM_IMPL_LINUX_BLUETOOTH_ADAPTER_H_
|
|
#define PLATFORM_IMPL_LINUX_BLUETOOTH_ADAPTER_H_
|
|
#include <sdbus-c++/IConnection.h>
|
|
#include <sdbus-c++/ProxyInterfaces.h>
|
|
|
|
#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/bluez_adapter_client_glue.h"
|
|
#include "internal/platform/implementation/linux/dbus.h"
|
|
|
|
namespace nearby {
|
|
namespace linux {
|
|
class BluezAdapter : public sdbus::ProxyInterfaces<org::bluez::Adapter1_proxy> {
|
|
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(sdbus::IConnection &system_bus,
|
|
const sdbus::ObjectPath &adapter_object_path)
|
|
: bluez_adapter_(
|
|
std::make_unique<BluezAdapter>(system_bus, adapter_object_path)) {}
|
|
|
|
~BluetoothAdapter() override {
|
|
if (!persist_name_) {
|
|
NEARBY_LOGS(INFO) << __func__ << "Resetting adapter Alias";
|
|
try {
|
|
bluez_adapter_->Alias("");
|
|
} catch (const sdbus::Error &e) {
|
|
DBUS_LOG_PROPERTY_SET_ERROR(bluez_adapter_, "Alias", e);
|
|
}
|
|
}
|
|
}
|
|
|
|
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::unique_ptr<BluezAdapter> bluez_adapter_;
|
|
bool persist_name_;
|
|
};
|
|
} // namespace linux
|
|
} // namespace nearby
|
|
|
|
#endif // PLATFORM_IMPL_LINUX_BLUETOOTH_ADAPTER_H_
|