diff options
author | Sven Gothel <[email protected]> | 2020-06-27 12:38:00 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2020-06-27 12:38:00 +0200 |
commit | 406c56e2ebe96358ffd6000b033e0f99f87c66ac (patch) | |
tree | 49f52b1a69a9c2b9de674c2372958386ff7eebf6 /api/direct_bt | |
parent | aeb0f54cc1e622324ce06edff342180500e4ccd1 (diff) |
Use HCIHandler *connect*/disconnect; Enhance native + java test
Use HCIHandler *connect*/disconnect incl related events (Drop DBTManager in this regard)
> Add CONNECT_FAILED HCI listener mgmtEvConnectFailedHCI
-- Issuing a DISCONNECT event
> DBTAdapter: mgmtEvDeviceConnectedHCI
-- Always pass through, just issue WARNING if not a new_connect (TBD)
> DBTAdapter: mgmtEvDeviceDisconnectedHCI + mgmtEvDeviceConnectedHCI
-- removeConnectedDevice pre event issuing
-- removeDiscoveredDevice post event issuing
> DBTDevice:
-- Add isConnectIssued to differentiate isConnected on event
-- Only use HCIHandler's *connect*/disconnect
-- disconnect(..) no more issues removeConnectedDevice, rely ion correct event issuing/handling,
as performed in time @ mgmtEvDeviceDisconnectedHCI...
-- remove() issues removeConnectedDevice and removeDiscoveredDevice pre releaseSharedInstance
to ensure a clean tracking state. The whole purpose of this command.
+++
Enhance native + java test
After disconnect() wait (poll) until no more connected, before issuing remove(),
this shall ensure proper workflow pre remove() - validation of disconnect command.
Diffstat (limited to 'api/direct_bt')
-rw-r--r-- | api/direct_bt/DBTAdapter.hpp | 16 | ||||
-rw-r--r-- | api/direct_bt/DBTDevice.hpp | 21 | ||||
-rw-r--r-- | api/direct_bt/DBTManager.hpp | 8 |
3 files changed, 26 insertions, 19 deletions
diff --git a/api/direct_bt/DBTAdapter.hpp b/api/direct_bt/DBTAdapter.hpp index 238bdcdb..e21216f6 100644 --- a/api/direct_bt/DBTAdapter.hpp +++ b/api/direct_bt/DBTAdapter.hpp @@ -178,6 +178,7 @@ namespace direct_bt { friend void DBTDevice::releaseSharedInstance() const; friend std::shared_ptr<ConnectionInfo> DBTDevice::getConnectionInfo(); friend bool DBTDevice::disconnect(const bool sentFromManager, const bool ioErrorCause,const HCIStatusCode reason); + friend void DBTDevice::remove(); friend bool DBTDevice::connectLE(HCIAddressType peer_mac_type, HCIAddressType own_mac_type, uint16_t interval, uint16_t window, uint16_t min_interval, uint16_t max_interval, @@ -198,12 +199,15 @@ namespace direct_bt { void removeSharedDevice(const DBTDevice & device); std::shared_ptr<DBTDevice> findSharedDevice (EUI48 const & mac); - bool mgmtEvDeviceDiscoveringCB(std::shared_ptr<MgmtEvent> e); - bool mgmtEvNewSettingsCB(std::shared_ptr<MgmtEvent> e); - bool mgmtEvLocalNameChangedCB(std::shared_ptr<MgmtEvent> e); - bool mgmtEvDeviceFoundCB(std::shared_ptr<MgmtEvent> e); - bool mgmtEvDeviceConnectedCB(std::shared_ptr<MgmtEvent> e); - bool mgmtEvDeviceDisconnectedCB(std::shared_ptr<MgmtEvent> e); + bool mgmtEvDeviceDiscoveringMgmt(std::shared_ptr<MgmtEvent> e); + bool mgmtEvNewSettingsMgmt(std::shared_ptr<MgmtEvent> e); + bool mgmtEvLocalNameChangedMgmt(std::shared_ptr<MgmtEvent> e); + bool mgmtEvDeviceFoundMgmt(std::shared_ptr<MgmtEvent> e); + bool mgmtEvDeviceDisconnectedMgmt(std::shared_ptr<MgmtEvent> e); + + bool mgmtEvDeviceConnectedHCI(std::shared_ptr<MgmtEvent> e); + bool mgmtEvConnectFailedHCI(std::shared_ptr<MgmtEvent> e); + bool mgmtEvDeviceDisconnectedHCI(std::shared_ptr<MgmtEvent> e); void startDiscoveryBackground(); diff --git a/api/direct_bt/DBTDevice.hpp b/api/direct_bt/DBTDevice.hpp index 5dc1a614..9683e987 100644 --- a/api/direct_bt/DBTDevice.hpp +++ b/api/direct_bt/DBTDevice.hpp @@ -71,6 +71,7 @@ namespace direct_bt { std::recursive_mutex mtx_data; std::recursive_mutex mtx_gatt; std::atomic<bool> isConnected; + std::atomic<bool> isConnectIssued; DBTDevice(DBTAdapter & adapter, EInfoReport const & r); bool addService(std::shared_ptr<uuid_t> const &uuid); @@ -83,7 +84,7 @@ namespace direct_bt { void notifyDisconnected(); void notifyConnected(const uint16_t handle); - bool disconnect(const bool sentFromManager, const bool ioErrorCause, + bool disconnect(const bool fromDisconnectCB, const bool ioErrorCause, const HCIStatusCode reason=HCIStatusCode::REMOTE_USER_TERMINATED_CONNECTION ); public: @@ -183,6 +184,11 @@ namespace direct_bt { std::shared_ptr<ConnectionInfo> getConnectionInfo(); /** + * Return true if the device has been successfully connected, otherwise false. + */ + bool getConnected() { return isConnected.load(); } + + /** * Establish a HCI BDADDR_LE_PUBLIC or BDADDR_LE_RANDOM connection to this device. * <p> * If this device's addressType is not BDADDR_LE_PUBLIC or BDADDR_LE_RANDOM, 0 is being returned. @@ -281,20 +287,25 @@ namespace direct_bt { * </p> */ bool disconnect(const HCIStatusCode reason=HCIStatusCode::REMOTE_USER_TERMINATED_CONNECTION ) { - return disconnect(false /* sentFromManager */, false /* ioErrorCause */, reason); + return disconnect(false /* fromDisconnectCB */, false /* ioErrorCause */, reason); } /** * Disconnects this device via disconnect(..) and - * removes its shared reference from the Adapter, not the discovered devices. + * removes its shared reference from the Adapter altogether, + * i.e. shared-devices, discovered-devices and connected-devices. * <p> * This method shall be issued to ensure no device reference will - * be leaked in a long lived adapter, as only the discovered devices - * are being flushed with a new discovery. + * be leaked in a long lived adapter, + * as only the connected-devices are removed at disconnect + * and the discovered-devices removed with a new discovery. * </p> * <p> * After calling this method, the device shall no more being used. * </p> + * <p> + * This method is automatically called @ destructor. + * </p> */ void remove(); diff --git a/api/direct_bt/DBTManager.hpp b/api/direct_bt/DBTManager.hpp index 0a6acac4..7a363bae 100644 --- a/api/direct_bt/DBTManager.hpp +++ b/api/direct_bt/DBTManager.hpp @@ -254,14 +254,6 @@ namespace direct_bt { /** Remove all previously added devices from the autoconnect whitelist. Returns number of removed devices. */ int removeAllDevicesFromWhitelist(); - uint16_t create_connection(const int dev_id, - const EUI48 &peer_bdaddr, - const BDAddressType peer_mac_type, - const BDAddressType own_mac_type=BDADDR_LE_PUBLIC, - const uint16_t interval=0x0004, const uint16_t window=0x0004, - const uint16_t min_interval=0x000F, const uint16_t max_interval=0x000F, - const uint16_t latency=0x0000, const uint16_t supervision_timeout=number(HCIConstInt::LE_CONN_TIMEOUT_MS)/10); - bool disconnect(const bool ioErrorCause, const int dev_id, const EUI48 &peer_bdaddr, const BDAddressType peer_mac_type, const HCIStatusCode reason=HCIStatusCode::REMOTE_USER_TERMINATED_CONNECTION ); |