mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 22:56:12 -04:00
Share one notification session for all calls between Start/StopNotify
This commit is contained in:
@@ -33,8 +33,8 @@ void GattCharacteristicServer::Update(const nearby::ByteArray &value) {
|
||||
static_value_ = std::move(bytes);
|
||||
}
|
||||
|
||||
absl::Status GattCharacteristicServer::NotifyChanged(bool confirm,
|
||||
const ByteArray &new_value) {
|
||||
absl::Status GattCharacteristicServer::NotifyChanged(
|
||||
bool confirm, const ByteArray &new_value) {
|
||||
std::vector<uint8_t> bytes(new_value.size());
|
||||
const auto *buf = new_value.data();
|
||||
for (auto i = 0; i < new_value.size(); i++) bytes[i] = buf[i];
|
||||
@@ -187,8 +187,12 @@ void GattCharacteristicServer::StopNotify() {
|
||||
if ((characteristic_.property |
|
||||
api::ble_v2::GattCharacteristic::Property::kNotify) ==
|
||||
api::ble_v2::GattCharacteristic::Property::kNotify) {
|
||||
server_cb_->characteristic_unsubscription_cb(characteristic_);
|
||||
notifying_ = false;
|
||||
if (notify_sessions_.fetch_sub(0) == 1) {
|
||||
if (server_cb_->characteristic_unsubscription_cb != nullptr) {
|
||||
server_cb_->characteristic_unsubscription_cb(characteristic_);
|
||||
}
|
||||
notifying_ = false;
|
||||
}
|
||||
} else {
|
||||
throw(sdbus::Error("org.bluez.Error.Failed"));
|
||||
}
|
||||
|
||||
@@ -45,7 +45,8 @@ class GattCharacteristicServer final
|
||||
public:
|
||||
GattCharacteristicServer(const GattCharacteristicServer &) = delete;
|
||||
GattCharacteristicServer(GattCharacteristicServer &&) = delete;
|
||||
GattCharacteristicServer &operator=(const GattCharacteristicServer &) = delete;
|
||||
GattCharacteristicServer &operator=(const GattCharacteristicServer &) =
|
||||
delete;
|
||||
GattCharacteristicServer &operator=(GattCharacteristicServer &&) = delete;
|
||||
|
||||
GattCharacteristicServer(
|
||||
@@ -61,7 +62,8 @@ class GattCharacteristicServer final
|
||||
characteristic_(characteristic),
|
||||
service_object_path_(service_object_path),
|
||||
notifying_(false),
|
||||
confirmed_(false) {
|
||||
confirmed_(false),
|
||||
notify_sessions_(0) {
|
||||
registerAdaptor();
|
||||
NEARBY_LOGS(VERBOSE)
|
||||
<< __func__ << "Creating a "
|
||||
@@ -116,6 +118,8 @@ class GattCharacteristicServer final
|
||||
|
||||
absl::Mutex confirmed_mutex_;
|
||||
bool confirmed_;
|
||||
|
||||
std::atomic_size_t notify_sessions_;
|
||||
};
|
||||
|
||||
} // namespace bluez
|
||||
|
||||
Reference in New Issue
Block a user