aboutsummaryrefslogtreecommitdiffstats
path: root/api/direct_bt/GATTHandler.hpp
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2020-09-18 02:30:53 +0200
committerSven Gothel <[email protected]>2020-09-18 02:30:53 +0200
commit55282d659427f3167d141062eb5b03ae3e2ba2b7 (patch)
tree36255581da8c08b1f69b15f9918c731a1a235ae9 /api/direct_bt/GATTHandler.hpp
parent2ae1ba72a8d0e5dd06d075fd06dae287b44f8bf6 (diff)
Open [& Connect] @ ctor (RAII): HCIComm, L2CAPComm, GATTHandler, simplifying 'connect' lifecycle
Further: - L2CAPComm -- disconnect(): Only lock mtw_write if connected and mark noexcept -- Added '~L2CAPComm() noexcept' for RAII -- Removed unsued accessors - GATTHandler -- Similar treatment as L2CAPComm - DBTDevice -- Remove mtx_gatt and its locks, they were not consistent. Rely on mtx_connect (connectGATT/getGATTServices/disconnect) and atomic local GATTHandler copy when using. -- disconnect GATTHandler directly in disconnect, remove explicit method. -- pingGATT uses local gattHandler copy to avoid parallel disconnect nullptr, however, it will fail immediately due to disconnection.
Diffstat (limited to 'api/direct_bt/GATTHandler.hpp')
-rw-r--r--api/direct_bt/GATTHandler.hpp20
1 files changed, 10 insertions, 10 deletions
diff --git a/api/direct_bt/GATTHandler.hpp b/api/direct_bt/GATTHandler.hpp
index 829deec2..246732ad 100644
--- a/api/direct_bt/GATTHandler.hpp
+++ b/api/direct_bt/GATTHandler.hpp
@@ -203,21 +203,23 @@ namespace direct_bt {
uint16_t exchangeMTU(const uint16_t clientMaxMTU);
public:
+ /**
+ * Constructing a new GATTHandler instance with its opened and connected L2CAP channel.
+ * <p>
+ * After successful l2cap connection, the MTU will be exchanged.
+ * See getServerMTU() and getUsedMTU(), the latter is in use.
+ * </p>
+ */
GATTHandler(const std::shared_ptr<DBTDevice> & device) noexcept;
- ~GATTHandler();
+ /** Destructor closing this instance including L2CAP channel, see {@link #disconnect()}. */
+ ~GATTHandler() noexcept;
- bool getIsConnected() const noexcept { return isConnected; }
+ bool getIsConnected() const noexcept { return isConnected ; }
bool getHasIOError() const noexcept { return hasIOError; }
std::string getStateString() const noexcept { return L2CAPComm::getStateString(isConnected, hasIOError); }
/**
- * After successful l2cap connection, the MTU will be exchanged.
- * See getServerMTU() and getUsedMTU(), the latter is in use.
- */
- bool connect() noexcept;
-
- /**
* Disconnect this GATTHandler and optionally the associated device
* @param disconnectDevice if true, associated device will also be disconnected, otherwise not.
* @param ioErrorCause if true, reason for disconnection is an IO error
@@ -225,8 +227,6 @@ namespace direct_bt {
*/
bool disconnect(const bool disconnectDevice, const bool ioErrorCause) noexcept;
- bool isOpen() const noexcept { return isConnected && l2cap.isOpen(); }
-
inline uint16_t getServerMTU() const noexcept { return serverMTU; }
inline uint16_t getUsedMTU() const noexcept { return usedMTU; }