diff options
author | Sven Gothel <[email protected]> | 2020-09-18 02:30:53 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2020-09-18 02:30:53 +0200 |
commit | 55282d659427f3167d141062eb5b03ae3e2ba2b7 (patch) | |
tree | 36255581da8c08b1f69b15f9918c731a1a235ae9 /examples | |
parent | 2ae1ba72a8d0e5dd06d075fd06dae287b44f8bf6 (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 'examples')
-rw-r--r-- | examples/direct_bt_scanner00/dbt_scanner00.cpp | 2 | ||||
-rw-r--r-- | examples/direct_bt_scanner01/dbt_scanner01.cpp | 7 | ||||
-rw-r--r-- | examples/direct_bt_scanner10/dbt_scanner10.cpp | 2 |
3 files changed, 5 insertions, 6 deletions
diff --git a/examples/direct_bt_scanner00/dbt_scanner00.cpp b/examples/direct_bt_scanner00/dbt_scanner00.cpp index 63eb61c4..5cf9f996 100644 --- a/examples/direct_bt_scanner00/dbt_scanner00.cpp +++ b/examples/direct_bt_scanner00/dbt_scanner00.cpp @@ -267,7 +267,7 @@ int main(int argc, char *argv[]) } { std::shared_ptr<GATTHandler> gatt = device->getGATTHandler(); - if( nullptr != gatt && gatt->isOpen() ) { + if( nullptr != gatt && gatt->getIsConnected() ) { std::shared_ptr<DeviceInformation> di = gatt->getDeviceInformation(primServices); if( nullptr != di ) { fprintf(stderr, " DeviceInformation: %s\n\n", di->toString().c_str()); diff --git a/examples/direct_bt_scanner01/dbt_scanner01.cpp b/examples/direct_bt_scanner01/dbt_scanner01.cpp index 653e5eab..4d791050 100644 --- a/examples/direct_bt_scanner01/dbt_scanner01.cpp +++ b/examples/direct_bt_scanner01/dbt_scanner01.cpp @@ -277,19 +277,19 @@ int main(int argc, char *argv[]) if( nullptr != ga ) { fprintf(stderr, " GenericAccess: %s\n\n", ga->toString().c_str()); } - if( nullptr != gatt && gatt->isOpen() ) { + if( nullptr != gatt && gatt->getIsConnected() ) { std::shared_ptr<DeviceInformation> di = gatt->getDeviceInformation(primServices); if( nullptr != di ) { fprintf(stderr, " DeviceInformation: %s\n\n", di->toString().c_str()); } } - for(size_t i=0; i<primServices.size() && gatt->isOpen(); i++) { + for(size_t i=0; i<primServices.size() && gatt->getIsConnected(); i++) { GATTService & primService = *primServices.at(i); fprintf(stderr, " [%2.2d] Service %s\n", (int)i, primService.toString().c_str()); fprintf(stderr, " [%2.2d] Service Characteristics\n", (int)i); std::vector<GATTCharacteristicRef> & serviceCharacteristics = primService.characteristicList; - for(size_t j=0; j<serviceCharacteristics.size() && gatt->isOpen(); j++) { + for(size_t j=0; j<serviceCharacteristics.size() && gatt->getIsConnected(); j++) { GATTCharacteristic & serviceChar = *serviceCharacteristics.at(j); fprintf(stderr, " [%2.2d.%2.2d] Decla: %s\n", (int)i, (int)j, serviceChar.toString().c_str()); if( serviceChar.hasProperties(GATTCharacteristic::PropertyBitVal::Read) ) { @@ -312,7 +312,6 @@ int main(int argc, char *argv[]) } // FIXME sleep 1s for potential callbacks .. sleep(1); - device->disconnectGATT(); // redundant: also done at gatt->disconnect() } else { fprintf(stderr, "GATT connect failed: %s\n", gatt->getStateString().c_str()); } diff --git a/examples/direct_bt_scanner10/dbt_scanner10.cpp b/examples/direct_bt_scanner10/dbt_scanner10.cpp index 1a0bbf5a..20a0c7ee 100644 --- a/examples/direct_bt_scanner10/dbt_scanner10.cpp +++ b/examples/direct_bt_scanner10/dbt_scanner10.cpp @@ -307,7 +307,7 @@ static void processConnectedDevice(std::shared_ptr<DBTDevice> device) { } { std::shared_ptr<GATTHandler> gatt = device->getGATTHandler(); - if( nullptr != gatt && gatt->isOpen() ) { + if( nullptr != gatt && gatt->getIsConnected() ) { std::shared_ptr<DeviceInformation> di = gatt->getDeviceInformation(primServices); if( nullptr != di && !SILENT_GATT ) { fprintf(stderr, " DeviceInformation: %s\n\n", di->toString().c_str()); |