diff options
author | Sven Gothel <[email protected]> | 2020-05-27 05:42:03 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2020-05-27 05:42:03 +0200 |
commit | f39fe119896d43435d408cd1d3582d3ed3d77745 (patch) | |
tree | 156f621b00d7412248dfe4c9127dd2d94b1c009d | |
parent | f78fad20a0e8ea7b864af645ec2caa7f936fce08 (diff) |
DBTDevice.cpp: Use openHCI() instead of getHCI(), i.e. implicit open if required - soothing API usage and JNI binding as well
-rw-r--r-- | examples/direct_bt_scanner00/dbt_scanner00.cpp | 9 | ||||
-rw-r--r-- | examples/direct_bt_scanner10/dbt_scanner10.cpp | 7 | ||||
-rw-r--r-- | src/direct_bt/DBTDevice.cpp | 8 |
3 files changed, 4 insertions, 20 deletions
diff --git a/examples/direct_bt_scanner00/dbt_scanner00.cpp b/examples/direct_bt_scanner00/dbt_scanner00.cpp index 1773097d..65d39c46 100644 --- a/examples/direct_bt_scanner00/dbt_scanner00.cpp +++ b/examples/direct_bt_scanner00/dbt_scanner00.cpp @@ -184,14 +184,6 @@ int main(int argc, char *argv[]) const int64_t t0 = getCurrentMilliseconds(); - 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 ) ) { ok = adapter.startDiscovery(true /* keepAlive */); if( !ok) { @@ -293,7 +285,6 @@ int main(int argc, char *argv[]) } out: - adapter.closeHCI(); return 0; } diff --git a/examples/direct_bt_scanner10/dbt_scanner10.cpp b/examples/direct_bt_scanner10/dbt_scanner10.cpp index 2bc99027..3c268c5d 100644 --- a/examples/direct_bt_scanner10/dbt_scanner10.cpp +++ b/examples/direct_bt_scanner10/dbt_scanner10.cpp @@ -395,12 +395,6 @@ int main(int argc, char *argv[]) adapter.addStatusListener(std::shared_ptr<AdapterStatusListener>(new MyAdapterStatusListener())); - 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( USE_WHITELIST ) { for (auto it = whitelist.begin(); it != whitelist.end(); ++it) { std::shared_ptr<EUI48> wlmac = *it; @@ -430,7 +424,6 @@ int main(int argc, char *argv[]) } while( !done ); out: - adapter.closeHCI(); return 0; } diff --git a/src/direct_bt/DBTDevice.cpp b/src/direct_bt/DBTDevice.cpp index 94031294..b20d32c5 100644 --- a/src/direct_bt/DBTDevice.cpp +++ b/src/direct_bt/DBTDevice.cpp @@ -252,9 +252,9 @@ uint16_t DBTDevice::connectLE(HCIAddressType peer_mac_type, HCIAddressType own_m throw InternalError("DBTDevice::connectLE: Device unknown to adapter and not tracked: "+toString(), E_FILE_LINE); } const std::lock_guard<std::recursive_mutex> lock(adapter.mtx_hci); // RAII-style acquire and relinquish via destructor - std::shared_ptr<HCIComm> hciComm = adapter.getHCI(); + std::shared_ptr<HCIComm> hciComm = adapter.openHCI(); if( nullptr == hciComm || !hciComm->isOpen() ) { - ERR_PRINT("DBTDevice::le_connect: Adapter's HCIComm not opened: %s", toString().c_str()); + ERR_PRINT("DBTDevice::connectLE: Opening adapter's HCIComm failed: %s", toString().c_str()); return 0; } if( !isLEAddressType() ) { @@ -292,9 +292,9 @@ uint16_t DBTDevice::connectBREDR(const uint16_t pkt_type, const uint16_t clock_o throw InternalError("DBTDevice::connectBREDR: Device unknown to adapter and not tracked: "+toString(), E_FILE_LINE); } const std::lock_guard<std::recursive_mutex> lock(adapter.mtx_hci); // RAII-style acquire and relinquish via destructor - std::shared_ptr<HCIComm> hciComm = adapter.getHCI(); + std::shared_ptr<HCIComm> hciComm = adapter.openHCI(); if( nullptr == hciComm || !hciComm->isOpen() ) { - ERR_PRINT("DBTDevice::le_connect: Adapter's HCIComm not opened: %s", toString().c_str()); + ERR_PRINT("DBTDevice::connectBREDR: Opening adapter's HCIComm failed: %s", toString().c_str()); return 0; } if( !isBREDRAddressType() ) { |