diff options
author | Sven Gothel <[email protected]> | 2020-05-24 00:14:11 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2020-05-24 00:14:11 +0200 |
commit | c14827e615c53f1c091cc0f04f4bf0550dcdb4d2 (patch) | |
tree | 0b84c1c4ed3120109ee09d31672a0af0dc8fcc5f /examples/direct_bt_scanner01 | |
parent | 6291468795a915d5fc7e2ec896711c849cded452 (diff) |
C++ multithreading fixes and example
DBTAdapter:
- Add HCI mutex
- openHCI() returns already open HCIComm
- Notify device on disconnected
DBTDevice:
- Add data mutex, covering race-condition on data update(..) and data usage
- notifyDisconnected(): Clear hciConnHandle
- getServices() -> getGATTServices() to differenciate from scan-result
+++
Java/JNI DBTAdapter:
- Remove open/openImpl() in favor of implicit openHCI() @ connect call.
+++
Added multithreading example dbt_scanner10.cpp
Diffstat (limited to 'examples/direct_bt_scanner01')
-rw-r--r-- | examples/direct_bt_scanner01/dbt_scanner01.cpp | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/examples/direct_bt_scanner01/dbt_scanner01.cpp b/examples/direct_bt_scanner01/dbt_scanner01.cpp index 9844ee30..7eb50d62 100644 --- a/examples/direct_bt_scanner01/dbt_scanner01.cpp +++ b/examples/direct_bt_scanner01/dbt_scanner01.cpp @@ -183,10 +183,12 @@ int main(int argc, char *argv[]) const int64_t t0 = getCurrentMilliseconds(); - std::shared_ptr<HCIComm> hci = adapter.openHCI(); - if( nullptr == hci || !hci->isOpen() ) { - fprintf(stderr, "Couldn't open HCI from %s\n", adapter.toString().c_str()); - exit(1); + if( doHCI_Connect ) { + std::shared_ptr<HCIComm> hci = adapter.openHCI(); + if( nullptr == hci || !hci->isOpen() ) { + fprintf(stderr, "Couldn't open HCI from %s\n", adapter.toString().c_str()); + exit(1); + } } while( ok && ( forever || !foundDevice ) ) { @@ -219,17 +221,14 @@ int main(int argc, char *argv[]) // HCI LE-Connect // (Without: Overall communication takes ~twice as long!!!) // - uint16_t hciConnHandle; if( doHCI_Connect ) { - hciConnHandle = device->connectHCIDefault(); - if( 0 == hciConnHandle ) { + if( 0 == device->connectHCIDefault() ) { fprintf(stderr, "Connect: Failed %s\n", device->toString().c_str()); } else { fprintf(stderr, "Connect: Success\n"); } } else { fprintf(stderr, "Connect: Skipped %s\n", device->toString().c_str()); - hciConnHandle = 0; } const uint64_t t3 = getCurrentMilliseconds(); const uint64_t td03 = t3 - t0; @@ -238,9 +237,8 @@ int main(int argc, char *argv[]) fprintf(stderr, " discovery-only %" PRIu64 " ms,\n" " connect-only %" PRIu64 " ms,\n" " discovered to hci-connected %" PRIu64 " ms,\n" - " total %" PRIu64 " ms,\n" - " handle 0x%X\n", - td01, td13, (t3 - device->getCreationTimestamp()), td03, hciConnHandle); + " total %" PRIu64 " ms,\n", + td01, td13, (t3 - device->getCreationTimestamp()), td03); // // GATT Processing |