aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2021-01-15 12:39:02 +0100
committerSven Gothel <[email protected]>2021-01-15 12:39:02 +0100
commita93f3bd05b075095eebe44ec7784c1664dc68700 (patch)
tree3bad1531e2d95de0e418fc80dd21aa8d52b065aa
parent5d8555e54521724a423f93b85b00e7d96ec3679d (diff)
DBTAdapter: USe pre-incr, use typedef device_list_t (shorten shared device darray)
-rw-r--r--api/direct_bt/DBTAdapter.hpp11
-rw-r--r--src/direct_bt/DBTAdapter.cpp14
2 files changed, 13 insertions, 12 deletions
diff --git a/api/direct_bt/DBTAdapter.hpp b/api/direct_bt/DBTAdapter.hpp
index 32aed98e..c23d3809 100644
--- a/api/direct_bt/DBTAdapter.hpp
+++ b/api/direct_bt/DBTAdapter.hpp
@@ -220,9 +220,10 @@ namespace direct_bt {
std::mutex mtx_single_conn_device;
std::condition_variable cv_single_conn_device;
- jau::darray<std::shared_ptr<DBTDevice>> connectedDevices;
- jau::darray<std::shared_ptr<DBTDevice>> discoveredDevices; // all discovered devices
- jau::darray<std::shared_ptr<DBTDevice>> sharedDevices; // All active shared devices. Final holder of DBTDevice lifecycle!
+ typedef jau::darray<std::shared_ptr<DBTDevice>> device_list_t;
+ device_list_t connectedDevices;
+ device_list_t discoveredDevices; // all discovered devices
+ device_list_t sharedDevices; // All active shared devices. Final holder of DBTDevice lifecycle!
typedef jau::cow_darray<std::shared_ptr<AdapterStatusListener>> statusListenerList_t;
statusListenerList_t statusListenerList;
std::mutex mtx_discoveredDevices;
@@ -232,8 +233,8 @@ namespace direct_bt {
bool validateDevInfo() noexcept;
- static std::shared_ptr<DBTDevice> findDevice(jau::darray<std::shared_ptr<DBTDevice>> & devices, const EUI48 & address, const BDAddressType addressType) noexcept;
- std::shared_ptr<DBTDevice> findDevice(jau::darray<std::shared_ptr<DBTDevice>> & devices, DBTDevice const & device) noexcept;
+ static std::shared_ptr<DBTDevice> findDevice(device_list_t & devices, const EUI48 & address, const BDAddressType addressType) noexcept;
+ static std::shared_ptr<DBTDevice> findDevice(device_list_t & devices, DBTDevice const & device) noexcept;
/**
* Closes all device connections, stops discovery and cleans up all references.
diff --git a/src/direct_bt/DBTAdapter.cpp b/src/direct_bt/DBTAdapter.cpp
index 443d5f3b..49a67a0d 100644
--- a/src/direct_bt/DBTAdapter.cpp
+++ b/src/direct_bt/DBTAdapter.cpp
@@ -49,9 +49,9 @@ extern "C" {
using namespace direct_bt;
-std::shared_ptr<DBTDevice> DBTAdapter::findDevice(jau::darray<std::shared_ptr<DBTDevice>> & devices, const EUI48 & address, const BDAddressType addressType) noexcept {
+std::shared_ptr<DBTDevice> DBTAdapter::findDevice(device_list_t & devices, const EUI48 & address, const BDAddressType addressType) noexcept {
const jau::nsize_t size = devices.size();
- for (jau::nsize_t i = 0; i < size; i++) {
+ for (jau::nsize_t i = 0; i < size; ++i) {
std::shared_ptr<DBTDevice> & e = devices[i];
if ( nullptr != e && address == e->getAddressAndType().address && addressType == e->getAddressAndType().type) {
return e;
@@ -60,9 +60,9 @@ std::shared_ptr<DBTDevice> DBTAdapter::findDevice(jau::darray<std::shared_ptr<DB
return nullptr;
}
-std::shared_ptr<DBTDevice> DBTAdapter::findDevice(jau::darray<std::shared_ptr<DBTDevice>> & devices, DBTDevice const & device) noexcept {
+std::shared_ptr<DBTDevice> DBTAdapter::findDevice(device_list_t & devices, DBTDevice const & device) noexcept {
const jau::nsize_t size = devices.size();
- for (jau::nsize_t i = 0; i < size; i++) {
+ for (jau::nsize_t i = 0; i < size; ++i) {
std::shared_ptr<DBTDevice> & e = devices[i];
if ( nullptr != e && device == *e ) {
return e;
@@ -93,7 +93,7 @@ bool DBTAdapter::removeConnectedDevice(const DBTDevice & device) noexcept {
}
int DBTAdapter::disconnectAllDevices(const HCIStatusCode reason) noexcept {
- jau::darray<std::shared_ptr<DBTDevice>> devices;
+ device_list_t devices;
{
const std::lock_guard<std::mutex> lock(mtx_connectedDevices); // RAII-style acquire and relinquish via destructor
devices = connectedDevices; // copy!
@@ -782,7 +782,7 @@ int DBTAdapter::removeDiscoveredDevices() noexcept {
jau::darray<std::shared_ptr<DBTDevice>> DBTAdapter::getDiscoveredDevices() const noexcept {
const std::lock_guard<std::mutex> lock(const_cast<DBTAdapter*>(this)->mtx_discoveredDevices); // RAII-style acquire and relinquish via destructor
- jau::darray<std::shared_ptr<DBTDevice>> res = discoveredDevices;
+ device_list_t res = discoveredDevices;
return res;
}
@@ -835,7 +835,7 @@ std::string DBTAdapter::toString(bool includeDiscoveredDevices) const noexcept {
", scanType[native "+getScanTypeString(hci.getCurrentScanType())+", meta "+getScanTypeString(currentMetaScanType)+"]"
", valid "+std::to_string(isValid())+", open[mgmt, "+std::to_string(mgmt.isOpen())+", hci "+std::to_string(hci.isOpen())+
"], "+javaObjectToString()+"]");
- jau::darray<std::shared_ptr<DBTDevice>> devices = getDiscoveredDevices();
+ device_list_t devices = getDiscoveredDevices();
if( includeDiscoveredDevices && devices.size() > 0 ) {
out.append("\n");
for(auto it = devices.begin(); it != devices.end(); it++) {