aboutsummaryrefslogtreecommitdiffstats
path: root/api
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2021-11-29 16:16:34 +0100
committerSven Gothel <[email protected]>2021-11-29 16:16:34 +0100
commite725e4f0b382d948cdfae5c5aaab8a5881e34034 (patch)
tree389e30eec30c7c2f5062fcf2d285b6da4a3f7175 /api
parent4a1456402ecbf07cf16e02aa31788f1f66567890 (diff)
BTAdapter::pausing_discovery_devices: Use std::weak_ptr<BTDevice> list; Add BTAdapter::removeDevicePausingDiscovery() and getCurrentDiscoveryPolicy()
Using a weak_ptr<BTDevice> list avoid stopping BTDevice destruction. BTAdapter::removeDevicePausingDiscovery() allows manual DiscoveryPolicy intervention point, allowing user to remove the ready device from the queue of pausing-discovery devices. Manual intervention might be desired, if using DiscoveryPolicy::PAUSE_CONNECTED_UNTIL_DISCONNECTED, but allowing discovery at an earlier processing step from AdapterStatusListener::deviceReady(). +++ Further added removeDevicePausingDiscovery() call in BTAdapter::removeDevice() as a last resort.
Diffstat (limited to 'api')
-rw-r--r--api/direct_bt/BTAdapter.hpp30
1 files changed, 29 insertions, 1 deletions
diff --git a/api/direct_bt/BTAdapter.hpp b/api/direct_bt/BTAdapter.hpp
index a8bb08c7..6c5d3a90 100644
--- a/api/direct_bt/BTAdapter.hpp
+++ b/api/direct_bt/BTAdapter.hpp
@@ -374,6 +374,8 @@ namespace direct_bt {
std::condition_variable cv_single_conn_device;
typedef jau::darray<BTDeviceRef> device_list_t;
+ typedef jau::darray<std::weak_ptr<BTDevice>> weak_device_list_t;
+
/** All discovered devices: Transient until removeDiscoveredDevices(), startDiscovery(). */
device_list_t discoveredDevices;
/** All connected devices: Transient until disconnect or removal. */
@@ -381,7 +383,7 @@ namespace direct_bt {
/** All active shared devices: Persistent until removal. Final holder of BTDevice lifecycle! */
device_list_t sharedDevices;
/** All connected devices for which discovery has been paused. */
- device_list_t pausing_discovery_devices;
+ weak_device_list_t pausing_discovery_devices;
typedef jau::cow_darray<impl::StatusListenerPair> statusListenerList_t;
statusListenerList_t statusListenerList;
@@ -409,7 +411,10 @@ namespace direct_bt {
static BTDeviceRef findDevice(device_list_t & devices, const EUI48 & address, const BDAddressType addressType) noexcept;
static BTDeviceRef findDevice(device_list_t & devices, BTDevice const & device) noexcept;
+ static BTDeviceRef findWeakDevice(weak_device_list_t & devices, const EUI48 & address, const BDAddressType addressType) noexcept;
+ static BTDeviceRef findWeakDevice(weak_device_list_t & devices, BTDevice const & device) noexcept;
static void printDeviceList(const std::string& prefix, const BTAdapter::device_list_t& list) noexcept;
+ static void printWeakDeviceList(const std::string& prefix, BTAdapter::weak_device_list_t& list) noexcept;
/** Private class only for private make_shared(). */
class ctor_cookie { friend BTAdapter; ctor_cookie(const uint16_t secret) { (void)secret; } };
@@ -998,6 +1003,29 @@ namespace direct_bt {
HCIStatusCode stopDiscovery() noexcept;
/**
+ * Return the current DiscoveryPolicy, set via startDiscovery().
+ * @since 2.5.1
+ */
+ DiscoveryPolicy getCurrentDiscoveryPolicy() const noexcept { return discovery_policy; }
+
+ /**
+ * Manual DiscoveryPolicy intervention point, allowing user to remove the ready device from
+ * the queue of pausing-discovery devices.
+ *
+ * Manual intervention might be desired, if using DiscoveryPolicy::PAUSE_CONNECTED_UNTIL_DISCONNECTED,
+ * but allowing discovery at an earlier processing step from AdapterStatusListener::deviceReady().
+ *
+ * Re-enabling discovery is performed on the current thread.
+ *
+ * @param device the BTDevice to remove from the pausing-discovery queue
+ * @return true if this was the last BTDevice, re-enabling discovery. Otherwise false.
+ * @since 2.5.1
+ */
+ bool removeDevicePausingDiscovery(const BTDevice & device) noexcept {
+ return removeDevicePausingDiscovery(device, false /* off_thread_enable */);
+ }
+
+ /**
* Returns the current meta discovering ScanType. It can be modified through startDiscovery(..) and stopDiscovery().
* <p>
* Note that if startDiscovery(..) has been issued with keepAlive==true,