mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 15:36:12 -04:00
Add GattClient#SetCharacteristicNotification for subscribing to a GATT characteristic
PiperOrigin-RevId: 511862183
This commit is contained in:
committed by
Copybara-Service
parent
d260feced5
commit
f3ebf77ed2
@@ -184,6 +184,9 @@ class BleMedium : public api::ble_v2::BleMedium {
|
||||
bool WriteCharacteristic(const api::ble_v2::GattCharacteristic &characteristic,
|
||||
const ByteArray &value) override;
|
||||
|
||||
bool SetCharacteristicNotification(const api::ble_v2::GattCharacteristic &characteristic,
|
||||
bool enable) override;
|
||||
|
||||
void Disconnect() override;
|
||||
|
||||
private:
|
||||
|
||||
@@ -585,6 +585,12 @@ bool BleMedium::GattClient::WriteCharacteristic(
|
||||
return false;
|
||||
}
|
||||
|
||||
bool BleMedium::GattClient::SetCharacteristicNotification(
|
||||
const api::ble_v2::GattCharacteristic& characteristic, bool enable) {
|
||||
// No op since we can't write characteristics.
|
||||
return false;
|
||||
}
|
||||
|
||||
void BleMedium::GattClient::Disconnect() {
|
||||
[central_ disconnectGattServiceWithPeripheralID:ObjCStringFromCppString(peripheral_id_)];
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "absl/container/flat_hash_map.h"
|
||||
#include "absl/functional/any_invocable.h"
|
||||
#include "absl/status/status.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "internal/platform/byte_array.h"
|
||||
@@ -180,6 +181,12 @@ class GattClient {
|
||||
virtual bool WriteCharacteristic(const GattCharacteristic& characteristic,
|
||||
const ByteArray& value) = 0;
|
||||
|
||||
// https://developer.android.com/reference/android/bluetooth/BluetoothGatt.html#setCharacteristicNotification(android.bluetooth.BluetoothGattCharacteristic,%20boolean)
|
||||
//
|
||||
// Enable or disable notifications/indications for a given characteristic.
|
||||
virtual bool SetCharacteristicNotification(
|
||||
const GattCharacteristic& characteristic, bool enable) = 0;
|
||||
|
||||
// https://developer.android.com/reference/android/bluetooth/BluetoothGatt.html#disconnect()
|
||||
virtual void Disconnect() = 0;
|
||||
};
|
||||
@@ -223,6 +230,10 @@ class GattServer {
|
||||
// Callback for asynchronous events on the client side of a GATT connection.
|
||||
struct ClientGattConnectionCallback {
|
||||
public:
|
||||
// Called when the characteristic is changed
|
||||
absl::AnyInvocable<void(const GattCharacteristic& characteristic)>
|
||||
on_characteristic_changed_cb = [](const GattCharacteristic&) {};
|
||||
|
||||
// Called when the client is disconnected from the GATT server.
|
||||
absl::AnyInvocable<void()> disconnected_cb = []() {};
|
||||
};
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/status/status.h"
|
||||
#include "absl/strings/escaping.h"
|
||||
@@ -452,6 +453,12 @@ bool BleV2Medium::GattClient::WriteCharacteristic(
|
||||
return false;
|
||||
}
|
||||
|
||||
bool BleV2Medium::GattClient::SetCharacteristicNotification(
|
||||
const api::ble_v2::GattCharacteristic& characteristic, bool enable) {
|
||||
// No op since we can't write characteristics.
|
||||
return false;
|
||||
}
|
||||
|
||||
void BleV2Medium::GattClient::Disconnect() {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
NEARBY_LOGS(INFO) << "G3 Ble GattClient Disconnect";
|
||||
|
||||
@@ -240,6 +240,10 @@ class BleV2Medium : public api::ble_v2::BleMedium {
|
||||
const api::ble_v2::GattCharacteristic& characteristic,
|
||||
const ByteArray& value) override;
|
||||
|
||||
bool SetCharacteristicNotification(
|
||||
const api::ble_v2::GattCharacteristic& characteristic,
|
||||
bool enable) override;
|
||||
|
||||
void Disconnect() override;
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user