#ifndef PLATFORM_IMPL_LINUX_BLUETOOTH_CLASSIC_DEVICE_H_ #define PLATFORM_IMPL_LINUX_BLUETOOTH_CLASSIC_DEVICE_H_ #include #include #include #include #include #include "absl/functional/any_invocable.h" #include "absl/strings/string_view.h" #include "internal/base/observer_list.h" #include "internal/platform/implementation/bluetooth_classic.h" #include "internal/platform/implementation/linux/bluez_device_client_glue.h" namespace nearby { namespace linux { // https://developer.android.com/reference/android/bluetooth/BluetoothDevice.html. class BluetoothDevice : public api::BluetoothDevice, public sdbus::ProxyInterfaces { public: BluetoothDevice(sdbus::IConnection &system_bus, const sdbus::ObjectPath &); ~BluetoothDevice() = default; // https://developer.android.com/reference/android/bluetooth/BluetoothDevice.html#getName() std::string GetName() const override; // Returns BT MAC address assigned to this device. std::string GetMacAddress() const override; bool ConnectToProfile(absl::string_view service_uuid); void set_pair_reply_callback(absl::AnyInvocable cb) { absl::MutexLock l(&pair_callback_lock_); on_pair_reply_cb_ = std::move(cb); } void reset_pair_reply_callback() { absl::MutexLock l(&pair_callback_lock_); on_pair_reply_cb_ = DefaultCallback(); } protected: void onConnectProfileReply(const sdbus::Error *error) override; void onPairReply(const sdbus::Error *error) override { absl::ReaderMutexLock l(&pair_callback_lock_); on_pair_reply_cb_(error); }; private: absl::Mutex pair_callback_lock_; absl::AnyInvocable on_pair_reply_cb_ = DefaultCallback(); }; class MonitoredBluetoothDevice : public BluetoothDevice, public sdbus::ProxyInterfaces { public: using sdbus::ProxyInterfaces::registerProxy; using sdbus::ProxyInterfaces::unregisterProxy; using sdbus::ProxyInterfaces::getObjectPath; MonitoredBluetoothDevice( sdbus::IConnection &system_bus, const sdbus::ObjectPath &, ObserverList &observers); ~MonitoredBluetoothDevice() { unregisterProxy(); } protected: void onPropertiesChanged( const std::string &interfaceName, const std::map &changedProperties, const std::vector &invalidatedProperties) override; private: ObserverList &observers_; }; } // namespace linux } // namespace nearby #endif