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