aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/GattCharacteristic.cpp3
-rw-r--r--src/GattCharacteristic.h11
-rw-r--r--src/HciAdapter.cpp11
3 files changed, 18 insertions, 7 deletions
diff --git a/src/GattCharacteristic.cpp b/src/GattCharacteristic.cpp
index a10c04d..85d411c 100644
--- a/src/GattCharacteristic.cpp
+++ b/src/GattCharacteristic.cpp
@@ -209,6 +209,9 @@ GattDescriptor &GattCharacteristic::gattDescriptorBegin(const std::string &pathE
//
// This is a generalized method that accepts a `GVariant *`. A templated version is available that supports common types called
// `sendChangeNotificationValue()`.
+//
+// The caller may choose to consult HciAdapter::getInstance().getActiveConnectionCount() in order to determine if there are any
+// active connections before sending a change notification.
void GattCharacteristic::sendChangeNotificationVariant(GDBusConnection *pBusConnection, GVariant *pNewValue) const
{
g_auto(GVariantBuilder) builder;
diff --git a/src/GattCharacteristic.h b/src/GattCharacteristic.h
index 7284631..97322cc 100644
--- a/src/GattCharacteristic.h
+++ b/src/GattCharacteristic.h
@@ -202,6 +202,9 @@ struct GattCharacteristic : GattInterface
//
// This is a generalized method that accepts a `GVariant *`. A templated version is available that supports common types called
// `sendChangeNotificationValue()`.
+ //
+ // The caller may choose to consult HciAdapter::getInstance().getActiveConnectionCount() in order to determine if there are any
+ // active connections before sending a change notification.
void sendChangeNotificationVariant(GDBusConnection *pBusConnection, GVariant *pNewValue) const;
// Sends a change notification to subscribers to this characteristic
@@ -209,15 +212,11 @@ struct GattCharacteristic : GattInterface
// This is a helper method that accepts common types. For custom types, there is a form that accepts a `GVariant *`, called
// `sendChangeNotificationVariant()`.
//
- // If there are no connections, this method returns doing nothing.
+ // The caller may choose to consult HciAdapter::getInstance().getActiveConnectionCount() in order to determine if there are any
+ // active connections before sending a change notification.
template<typename T>
void sendChangeNotificationValue(GDBusConnection *pBusConnection, T value) const
{
- if (HciAdapter::getInstance().getActiveConnectionCount() == 0)
- {
- return;
- }
-
GVariant *pVariant = Utils::gvariantFromByteArray(value);
sendChangeNotificationVariant(pBusConnection, pVariant);
}
diff --git a/src/HciAdapter.cpp b/src/HciAdapter.cpp
index ad27ce0..eb1990f 100644
--- a/src/HciAdapter.cpp
+++ b/src/HciAdapter.cpp
@@ -346,13 +346,22 @@ void HciAdapter::runEventThread()
{
DeviceConnectedEvent event(responsePacket);
activeConnections += 1;
+ Logger::debug(SSTR << " > Connection count incremented to " << activeConnections);
break;
}
// Command status event
case Mgmt::EDeviceDisconnectedEvent:
{
DeviceDisconnectedEvent event(responsePacket);
- activeConnections -= 1;
+ if (activeConnections > 0)
+ {
+ activeConnections -= 1;
+ Logger::debug(SSTR << " > Connection count decremented to " << activeConnections);
+ }
+ else
+ {
+ Logger::debug(SSTR << " > Connection count already at zero, ignoring non-connected disconnect event");
+ }
break;
}
// Unsupported