diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/direct_bt/BTTypes.cpp | 6 | ||||
-rw-r--r-- | src/direct_bt/DBTAdapter.cpp | 75 | ||||
-rw-r--r-- | src/direct_bt/DBTDevice.cpp | 13 | ||||
-rw-r--r-- | src/direct_bt/DBTManager.cpp | 183 | ||||
-rw-r--r-- | src/direct_bt/GATTCharacteristic.cpp | 4 | ||||
-rw-r--r-- | src/direct_bt/GATTHandler.cpp | 54 | ||||
-rw-r--r-- | src/direct_bt/GATTNumbers.cpp | 4 | ||||
-rw-r--r-- | src/direct_bt/HCIHandler.cpp | 40 | ||||
-rw-r--r-- | src/direct_bt/SMPHandler.cpp | 2 |
9 files changed, 169 insertions, 212 deletions
diff --git a/src/direct_bt/BTTypes.cpp b/src/direct_bt/BTTypes.cpp index 1e8e7daf..ad6b0695 100644 --- a/src/direct_bt/BTTypes.cpp +++ b/src/direct_bt/BTTypes.cpp @@ -27,12 +27,12 @@ #include <string> #include <memory> #include <cstdint> -#include <vector> #include <cstdio> #include <algorithm> #include <jau/debug.hpp> +#include <jau/darray.hpp> #include "BTTypes.hpp" @@ -706,9 +706,9 @@ int EInfoReport::read_data(uint8_t const * data, uint8_t const data_length) noex return count; } -std::vector<std::shared_ptr<EInfoReport>> EInfoReport::read_ad_reports(uint8_t const * data, jau::nsize_t const data_length) noexcept { +jau::darray<std::shared_ptr<EInfoReport>> EInfoReport::read_ad_reports(uint8_t const * data, jau::nsize_t const data_length) noexcept { jau::nsize_t const num_reports = (jau::nsize_t) data[0]; - std::vector<std::shared_ptr<EInfoReport>> ad_reports; + jau::darray<std::shared_ptr<EInfoReport>> ad_reports; if( 0 == num_reports || num_reports > 0x19 ) { DBG_PRINT("AD-Reports: Invalid reports count: %d", num_reports); diff --git a/src/direct_bt/DBTAdapter.cpp b/src/direct_bt/DBTAdapter.cpp index 937c430c..443d5f3b 100644 --- a/src/direct_bt/DBTAdapter.cpp +++ b/src/direct_bt/DBTAdapter.cpp @@ -27,7 +27,6 @@ #include <string> #include <memory> #include <cstdint> -#include <vector> #include <cstdio> #include <algorithm> @@ -50,9 +49,9 @@ extern "C" { using namespace direct_bt; -std::shared_ptr<DBTDevice> DBTAdapter::findDevice(std::vector<std::shared_ptr<DBTDevice>> & devices, const EUI48 & address, const BDAddressType addressType) noexcept { - const size_t size = devices.size(); - for (size_t i = 0; i < size; i++) { +std::shared_ptr<DBTDevice> DBTAdapter::findDevice(jau::darray<std::shared_ptr<DBTDevice>> & devices, const EUI48 & address, const BDAddressType addressType) noexcept { + const jau::nsize_t size = devices.size(); + 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; @@ -61,9 +60,9 @@ std::shared_ptr<DBTDevice> DBTAdapter::findDevice(std::vector<std::shared_ptr<DB return nullptr; } -std::shared_ptr<DBTDevice> DBTAdapter::findDevice(std::vector<std::shared_ptr<DBTDevice>> & devices, DBTDevice const & device) noexcept { - const size_t size = devices.size(); - for (size_t i = 0; i < size; i++) { +std::shared_ptr<DBTDevice> DBTAdapter::findDevice(jau::darray<std::shared_ptr<DBTDevice>> & devices, DBTDevice const & device) noexcept { + const jau::nsize_t size = devices.size(); + for (jau::nsize_t i = 0; i < size; i++) { std::shared_ptr<DBTDevice> & e = devices[i]; if ( nullptr != e && device == *e ) { return e; @@ -83,25 +82,25 @@ bool DBTAdapter::addConnectedDevice(const std::shared_ptr<DBTDevice> & device) n bool DBTAdapter::removeConnectedDevice(const DBTDevice & device) noexcept { const std::lock_guard<std::mutex> lock(mtx_connectedDevices); // RAII-style acquire and relinquish via destructor - for (auto it = connectedDevices.begin(); it != connectedDevices.end(); ) { + auto end = connectedDevices.end(); + for (auto it = connectedDevices.begin(); it != end; ++it) { if ( nullptr != *it && device == **it ) { - it = connectedDevices.erase(it); + connectedDevices.erase(it); return true; - } else { - ++it; } } return false; } int DBTAdapter::disconnectAllDevices(const HCIStatusCode reason) noexcept { - std::vector<std::shared_ptr<DBTDevice>> devices; + jau::darray<std::shared_ptr<DBTDevice>> devices; { const std::lock_guard<std::mutex> lock(mtx_connectedDevices); // RAII-style acquire and relinquish via destructor devices = connectedDevices; // copy! } const int count = devices.size(); - for (auto it = devices.begin(); it != devices.end(); ++it) { + auto end = devices.end(); + for (auto it = devices.begin(); it != end; ++it) { if( nullptr != *it ) { (*it)->disconnect(reason); // will erase device from list via removeConnectedDevice(..) above } @@ -550,22 +549,18 @@ bool DBTAdapter::removeStatusListener(const AdapterStatusListener * l) { if( nullptr == l ) { throw jau::IllegalArgumentException("DBTAdapterStatusListener ref is null", E_FILE_LINE); } - const std::lock_guard<std::recursive_mutex> lock(statusListenerList.get_write_mutex()); - std::shared_ptr<jau::darray<std::shared_ptr<AdapterStatusListener>>> store = statusListenerList.copy_store(); - int count = 0; - for(auto it = store->begin(); it != store->end(); ) { - if ( **it == *l ) { - it = store->erase(it); - count++; - break; - } else { - ++it; + { + auto begin = statusListenerList.begin(); // lock mutex and copy_store + while ( !begin.is_end() ) { + if ( **begin == *l ) { + begin.erase(); + begin.write_back(); + return true; + } else { + ++begin; + } } } - if( 0 < count ) { - statusListenerList.set_store(std::move(store)); - return true; - } return false; } @@ -785,9 +780,9 @@ int DBTAdapter::removeDiscoveredDevices() noexcept { return res; } -std::vector<std::shared_ptr<DBTDevice>> DBTAdapter::getDiscoveredDevices() const 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 - std::vector<std::shared_ptr<DBTDevice>> res = discoveredDevices; + jau::darray<std::shared_ptr<DBTDevice>> res = discoveredDevices; return res; } @@ -840,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()+"]"); - std::vector<std::shared_ptr<DBTDevice>> devices = getDiscoveredDevices(); + jau::darray<std::shared_ptr<DBTDevice>> devices = getDiscoveredDevices(); if( includeDiscoveredDevices && devices.size() > 0 ) { out.append("\n"); for(auto it = devices.begin(); it != devices.end(); it++) { @@ -859,7 +854,7 @@ void DBTAdapter::sendAdapterSettingsChanged(const AdapterSetting old_settings_, const uint64_t timestampMS) noexcept { int i=0; - jau::for_each_fidelity(statusListenerList.cbegin(), statusListenerList.cend(), [&](std::shared_ptr<AdapterStatusListener> &l) { + jau::for_each_fidelity(statusListenerList, [&](std::shared_ptr<AdapterStatusListener> &l) { try { l->adapterSettingsChanged(*this, old_settings_, current_settings, changes, timestampMS); } catch (std::exception &e) { @@ -886,7 +881,7 @@ void DBTAdapter::sendAdapterSettingsInitial(AdapterStatusListener & asl, const u void DBTAdapter::sendDeviceUpdated(std::string cause, std::shared_ptr<DBTDevice> device, uint64_t timestamp, EIRDataType updateMask) noexcept { int i=0; - jau::for_each_fidelity(statusListenerList.cbegin(), statusListenerList.cend(), [&](std::shared_ptr<AdapterStatusListener> &l) { + jau::for_each_fidelity(statusListenerList, [&](std::shared_ptr<AdapterStatusListener> &l) { try { if( l->matchDevice(*device) ) { l->deviceUpdated(device, updateMask, timestamp); @@ -958,7 +953,7 @@ bool DBTAdapter::mgmtEvDeviceDiscoveringAny(const MgmtEvent& e, const bool hciSo checkDiscoveryState(); int i=0; - jau::for_each_fidelity(statusListenerList.cbegin(), statusListenerList.cend(), [&](std::shared_ptr<AdapterStatusListener> &l) { + jau::for_each_fidelity(statusListenerList, [&](std::shared_ptr<AdapterStatusListener> &l) { try { l->discoveringChanged(*this, currentMetaScanType, eventScanType, eventEnabled, keep_le_scan_alive, event.getTimestamp()); } catch (std::exception &except) { @@ -1100,7 +1095,7 @@ bool DBTAdapter::mgmtEvDeviceConnectedHCI(const MgmtEvent& e) noexcept { device->notifyConnected(device, event.getHCIHandle(), io_cap_conn); int i=0; - jau::for_each_fidelity(statusListenerList.cbegin(), statusListenerList.cend(), [&](std::shared_ptr<AdapterStatusListener> &l) { + jau::for_each_fidelity(statusListenerList, [&](std::shared_ptr<AdapterStatusListener> &l) { try { if( l->matchDevice(*device) ) { if( EIRDataType::NONE != updateMask ) { @@ -1136,7 +1131,7 @@ bool DBTAdapter::mgmtEvConnectFailedHCI(const MgmtEvent& e) noexcept { removeConnectedDevice(*device); int i=0; - jau::for_each_fidelity(statusListenerList.cbegin(), statusListenerList.cend(), [&](std::shared_ptr<AdapterStatusListener> &l) { + jau::for_each_fidelity(statusListenerList, [&](std::shared_ptr<AdapterStatusListener> &l) { try { if( l->matchDevice(*device) ) { l->deviceDisconnected(device, event.getHCIStatus(), handle, event.getTimestamp()); @@ -1226,7 +1221,7 @@ bool DBTAdapter::mgmtEvDeviceDisconnectedHCI(const MgmtEvent& e) noexcept { removeConnectedDevice(*device); int i=0; - jau::for_each_fidelity(statusListenerList.cbegin(), statusListenerList.cend(), [&](std::shared_ptr<AdapterStatusListener> &l) { + jau::for_each_fidelity(statusListenerList, [&](std::shared_ptr<AdapterStatusListener> &l) { try { if( l->matchDevice(*device) ) { l->deviceDisconnected(device, event.getHCIReason(), event.getHCIHandle(), event.getTimestamp()); @@ -1334,7 +1329,7 @@ bool DBTAdapter::mgmtEvDeviceFoundHCI(const MgmtEvent& e) noexcept { dev->getAddressAndType().toString().c_str(), eir->toString().c_str()); int i=0; - jau::for_each_fidelity(statusListenerList.cbegin(), statusListenerList.cend(), [&](std::shared_ptr<AdapterStatusListener> &l) { + jau::for_each_fidelity(statusListenerList, [&](std::shared_ptr<AdapterStatusListener> &l) { try { if( l->matchDevice(*dev) ) { l->deviceFound(dev, eir->getTimestamp()); @@ -1363,7 +1358,7 @@ bool DBTAdapter::mgmtEvDeviceFoundHCI(const MgmtEvent& e) noexcept { dev->getAddressAndType().toString().c_str(), eir->toString().c_str()); int i=0; - jau::for_each_fidelity(statusListenerList.cbegin(), statusListenerList.cend(), [&](std::shared_ptr<AdapterStatusListener> &l) { + jau::for_each_fidelity(statusListenerList, [&](std::shared_ptr<AdapterStatusListener> &l) { try { if( l->matchDevice(*dev) ) { l->deviceFound(dev, eir->getTimestamp()); @@ -1455,7 +1450,7 @@ bool DBTAdapter::hciSMPMsgCallback(const BDAddressAndType & addressAndType, void DBTAdapter::sendDevicePairingState(std::shared_ptr<DBTDevice> device, const SMPPairingState state, const PairingMode mode, uint64_t timestamp) noexcept { int i=0; - jau::for_each_fidelity(statusListenerList.cbegin(), statusListenerList.cend(), [&](std::shared_ptr<AdapterStatusListener> &l) { + jau::for_each_fidelity(statusListenerList, [&](std::shared_ptr<AdapterStatusListener> &l) { try { if( l->matchDevice(*device) ) { l->devicePairingState(device, state, mode, timestamp); @@ -1471,7 +1466,7 @@ void DBTAdapter::sendDevicePairingState(std::shared_ptr<DBTDevice> device, const void DBTAdapter::sendDeviceReady(std::shared_ptr<DBTDevice> device, uint64_t timestamp) noexcept { int i=0; - jau::for_each_fidelity(statusListenerList.cbegin(), statusListenerList.cend(), [&](std::shared_ptr<AdapterStatusListener> &l) { + jau::for_each_fidelity(statusListenerList, [&](std::shared_ptr<AdapterStatusListener> &l) { try { // Only issue if valid && received connected confirmation (HCI) && not have called disconnect yet. if( device->isValid() && device->getConnected() && device->allowDisconnect ) { diff --git a/src/direct_bt/DBTDevice.cpp b/src/direct_bt/DBTDevice.cpp index 5a558751..c0b1fbea 100644 --- a/src/direct_bt/DBTDevice.cpp +++ b/src/direct_bt/DBTDevice.cpp @@ -27,7 +27,6 @@ #include <string> #include <memory> #include <cstdint> -#include <vector> #include <cstdio> #include <algorithm> @@ -95,7 +94,7 @@ bool DBTDevice::addAdvService(std::shared_ptr<uuid_t> const &uuid) noexcept } return false; } -bool DBTDevice::addAdvServices(std::vector<std::shared_ptr<uuid_t>> const & services) noexcept +bool DBTDevice::addAdvServices(jau::darray<std::shared_ptr<uuid_t>> const & services) noexcept { bool res = false; for(size_t j=0; j<services.size(); j++) { @@ -127,7 +126,7 @@ std::shared_ptr<ManufactureSpecificData> const DBTDevice::getManufactureSpecific return advMSD; } -std::vector<std::shared_ptr<uuid_t>> DBTDevice::getAdvertisedServices() const noexcept { +jau::darray<std::shared_ptr<uuid_t>> DBTDevice::getAdvertisedServices() const noexcept { const std::lock_guard<std::recursive_mutex> lock(const_cast<DBTDevice*>(this)->mtx_data); // RAII-style acquire and relinquish via destructor return advServices; } @@ -1311,13 +1310,13 @@ std::shared_ptr<GATTHandler> DBTDevice::getGATTHandler() noexcept { return gattHandler; } -std::vector<std::shared_ptr<GATTService>> DBTDevice::getGATTServices() noexcept { +jau::darray<std::shared_ptr<GATTService>> DBTDevice::getGATTServices() noexcept { std::shared_ptr<GATTHandler> gh = getGATTHandler(); if( nullptr == gh ) { ERR_PRINT("DBTDevice::getGATTServices: GATTHandler nullptr"); - return std::vector<std::shared_ptr<GATTService>>(); + return jau::darray<std::shared_ptr<GATTService>>(); } - std::vector<std::shared_ptr<GATTService>> & gattServices = gh->getServices(); // reference of the GATTHandler's list + jau::darray<std::shared_ptr<GATTService>> gattServices = gh->getServices(); if( gattServices.size() > 0 ) { // reuse previous discovery result return gattServices; } @@ -1350,7 +1349,7 @@ std::vector<std::shared_ptr<GATTService>> DBTDevice::getGATTServices() noexcept } std::shared_ptr<GATTService> DBTDevice::findGATTService(std::shared_ptr<uuid_t> const &uuid) { - const std::vector<std::shared_ptr<GATTService>> & gattServices = getGATTServices(); // reference of the GATTHandler's list + const jau::darray<std::shared_ptr<GATTService>> & gattServices = getGATTServices(); // reference of the GATTHandler's list const size_t size = gattServices.size(); for (size_t i = 0; i < size; i++) { const std::shared_ptr<GATTService> & e = gattServices[i]; diff --git a/src/direct_bt/DBTManager.cpp b/src/direct_bt/DBTManager.cpp index aa996c33..bbfaab89 100644 --- a/src/direct_bt/DBTManager.cpp +++ b/src/direct_bt/DBTManager.cpp @@ -27,7 +27,6 @@ #include <string> #include <memory> #include <cstdint> -#include <vector> #include <cstdio> #include <algorithm> @@ -156,7 +155,7 @@ void DBTManager::sendMgmtEvent(const MgmtEvent& event) noexcept { MgmtAdapterEventCallbackList & mgmtEventCallbackList = mgmtAdapterEventCallbackLists[static_cast<uint16_t>(event.getOpcode())]; int invokeCount = 0; - jau::for_each_fidelity(mgmtEventCallbackList.cbegin(), mgmtEventCallbackList.cend(), [&](MgmtAdapterEventCallback &cb) { + jau::for_each_fidelity(mgmtEventCallbackList, [&](MgmtAdapterEventCallback &cb) { if( 0 > cb.getDevID() || dev_id == cb.getDevID() ) { try { cb.getCallback().invoke(event); @@ -478,15 +477,11 @@ next1: goto fail; } { - // Not required: CTOR: const std::lock_guard<std::recursive_mutex> lock(adapterInfos.get_write_mutex()); - // Not required: CTOR: std::shared_ptr<std::vector<std::shared_ptr<AdapterInfo>>> store = adapterInfos.copy_store(); - std::shared_ptr<jau::darray<std::shared_ptr<AdapterInfo>>> snapshot = adapterInfos.get_snapshot(); - for(int i=0; i < num_adapter; i++) { const uint16_t dev_id = jau::get_uint16(data, 2+i*2, true /* littleEndian */); std::shared_ptr<AdapterInfo> adapterInfo = initAdapter(dev_id, defaultBTMode); if( nullptr != adapterInfo ) { - snapshot->push_back(adapterInfo); + adapterInfos.push_back(adapterInfo); adapterIOCapability.push_back(defaultIOCapability); DBG_PRINT("DBTManager::adapters %d/%d: dev_id %d: %s", i, num_adapter, dev_id, adapterInfo->toString().c_str()); } else { @@ -561,7 +556,7 @@ void DBTManager::close() noexcept { removeAllDevicesFromWhitelist(); clearAllCallbacks(); - jau::for_each(adapterInfos.cbegin(), adapterInfos.cend(), [&](const std::shared_ptr<AdapterInfo> & a) { + jau::for_each_const(adapterInfos, [&](const std::shared_ptr<AdapterInfo> & a) { shutdownAdapter(a->dev_id); }); adapterInfos.clear(); @@ -611,81 +606,63 @@ void DBTManager::close() noexcept { } int DBTManager::findAdapterInfoIndex(const uint16_t dev_id) const noexcept { - std::shared_ptr<jau::darray<std::shared_ptr<AdapterInfo>>> snapshot = adapterInfos.get_snapshot(); - auto begin = snapshot->begin(); - auto it = std::find_if(begin, snapshot->end(), [&](std::shared_ptr<AdapterInfo> const& p) -> bool { - return p->dev_id == dev_id; - }); - if ( it == std::end(*snapshot) ) { - return -1; - } else { - return it - begin; + auto it = adapterInfos.cbegin(); + for (; !it.is_end(); ++it) { + if ( (*it)->dev_id == dev_id ) { + return it - it.cend(); + } } + return -1; } int DBTManager::findAdapterInfoDevId(const EUI48 &mac) const noexcept { - std::shared_ptr<jau::darray<std::shared_ptr<AdapterInfo>>> snapshot = adapterInfos.get_snapshot(); - auto begin = snapshot->begin(); - auto it = std::find_if(begin, snapshot->end(), [&](std::shared_ptr<AdapterInfo> const& p) -> bool { - return p->address == mac; - }); - if ( it == std::end(*snapshot) ) { - return -1; - } else { - return (*it)->dev_id; + auto it = adapterInfos.cbegin(); + for (; !it.is_end(); ++it) { + if ( (*it)->address == mac ) { + return (*it)->dev_id; + } } + return -1; } std::shared_ptr<AdapterInfo> DBTManager::findAdapterInfo(const EUI48 &mac) const noexcept { - std::shared_ptr<jau::darray<std::shared_ptr<AdapterInfo>>> snapshot = adapterInfos.get_snapshot(); - auto begin = snapshot->begin(); - auto it = std::find_if(begin, snapshot->end(), [&](std::shared_ptr<AdapterInfo> const& p) -> bool { - return p->address == mac; - }); - if ( it == std::end(*snapshot) ) { - return nullptr; - } else { - return *it; + auto it = adapterInfos.cbegin(); + for (; !it.is_end(); ++it) { + if ( (*it)->address == mac ) { + return *it; + } } + return nullptr; } std::shared_ptr<AdapterInfo> DBTManager::getAdapterInfo(const uint16_t dev_id) const noexcept { - std::shared_ptr<jau::darray<std::shared_ptr<AdapterInfo>>> snapshot = adapterInfos.get_snapshot(); - auto begin = snapshot->begin(); - auto it = std::find_if(begin, snapshot->end(), [&](std::shared_ptr<AdapterInfo> const& p) -> bool { - return p->dev_id == dev_id; - }); - if ( it == std::end(*snapshot) ) { - return nullptr; - } else { - return *it; + auto it = adapterInfos.cbegin(); + for (; !it.is_end(); ++it) { + if ( (*it)->dev_id == dev_id ) { + return *it; + } } + return nullptr; } bool DBTManager::addAdapterInfo(std::shared_ptr<AdapterInfo> ai) noexcept { - const std::lock_guard<std::recursive_mutex> lock(adapterInfos.get_write_mutex()); - std::shared_ptr<jau::darray<std::shared_ptr<AdapterInfo>>> store = adapterInfos.copy_store(); - - auto begin = store->begin(); - auto it = std::find_if(begin, store->end(), [&](std::shared_ptr<AdapterInfo> const& p) -> bool { - return p->dev_id == ai->dev_id; - }); - if ( it != std::end(*store) ) { - // already existing - return false; + auto it = adapterInfos.begin(); // lock mutex and copy_store + for (; !it.is_end(); ++it) { + if ( (*it)->dev_id == ai->dev_id ) { + it.push_back(ai); + it.write_back(); + adapterIOCapability.push_back(defaultIOCapability); + return true; + } } - store->push_back(ai); - adapterInfos.set_store(std::move(store)); - adapterIOCapability.push_back(defaultIOCapability); - return true; + // already existing + return false; } std::shared_ptr<AdapterInfo> DBTManager::removeAdapterInfo(const uint16_t dev_id) noexcept { - const std::lock_guard<std::recursive_mutex> lock(adapterInfos.get_write_mutex()); - std::shared_ptr<jau::darray<std::shared_ptr<AdapterInfo>>> store = adapterInfos.copy_store(); - - for(auto it = store->begin(); it != store->end(); ) { + typename adapterInfos_t::iterator it = adapterInfos.begin(); // lock mutex and copy_store + while ( !it.is_end() ) { std::shared_ptr<AdapterInfo> & ai = *it; if( ai->dev_id == dev_id ) { - adapterIOCapability.erase( adapterIOCapability.begin() + ( it - store->begin() ) ); - std::shared_ptr<AdapterInfo> res = ai; - it = store->erase(it); - adapterInfos.set_store(std::move(store)); + adapterIOCapability.erase( adapterIOCapability.begin() + ( it - it.begin() ) ); + std::shared_ptr<AdapterInfo> res = ai; // copy + it.erase(); + it.write_back(); return res; } else { ++it; @@ -704,16 +681,13 @@ BTMode DBTManager::getCurrentBTMode(uint16_t dev_id) const noexcept { } std::shared_ptr<AdapterInfo> DBTManager::getDefaultAdapterInfo() const noexcept { - std::shared_ptr<jau::darray<std::shared_ptr<AdapterInfo>>> snapshot = adapterInfos.get_snapshot(); - auto begin = snapshot->begin(); - auto it = std::find_if(begin, snapshot->end(), [](std::shared_ptr<AdapterInfo> const& p) -> bool { - return p->isCurrentSettingBitSet(AdapterSetting::POWERED); - }); - if ( it == std::end(*snapshot) ) { - return nullptr; - } else { - return *it; + auto it = adapterInfos.cbegin(); + for (; !it.is_end(); ++it) { + if( (*it)->isCurrentSettingBitSet(AdapterSetting::POWERED) ) { + return *it; + } } + return nullptr; } int DBTManager::getDefaultAdapterDevID() const noexcept { @@ -727,15 +701,17 @@ int DBTManager::getDefaultAdapterDevID() const noexcept { bool DBTManager::setIOCapability(const uint16_t dev_id, const SMPIOCapability io_cap, SMPIOCapability& pre_io_cap) noexcept { if( SMPIOCapability::UNSET != io_cap ) { #if USE_LINUX_BT_SECURITY - const std::lock_guard<std::recursive_mutex> lock( adapterInfos.get_write_mutex() ); - const int index = findAdapterInfoIndex(dev_id); - if( 0 <= index ) { - const SMPIOCapability o = adapterIOCapability.at(index); - AdapterSetting current_settings { AdapterSetting::NONE }; // throw away return value, unchanged on SET_IO_CAPABILITY - if( setMode(dev_id, MgmtCommand::Opcode::SET_IO_CAPABILITY, direct_bt::number(io_cap), current_settings) ) { - adapterIOCapability.at(index) = io_cap; - pre_io_cap = o; - return true; + auto it = adapterInfos.cbegin(); + for (; !it.is_end(); ++it) { + if( (*it)->dev_id == dev_id ) { + const typename adapterInfos_t::difference_type index = it-it.cbegin(); + const SMPIOCapability o = adapterIOCapability.at(index); + AdapterSetting current_settings { AdapterSetting::NONE }; // throw away return value, unchanged on SET_IO_CAPABILITY + if( setMode(dev_id, MgmtCommand::Opcode::SET_IO_CAPABILITY, direct_bt::number(io_cap), current_settings) ) { + adapterIOCapability.at(index) = io_cap; + pre_io_cap = o; + return true; + } } } #endif @@ -744,10 +720,11 @@ bool DBTManager::setIOCapability(const uint16_t dev_id, const SMPIOCapability io } SMPIOCapability DBTManager::getIOCapability(const uint16_t dev_id) const noexcept { - const std::lock_guard<std::recursive_mutex> lock( const_cast<DBTManager *>(this)->adapterInfos.get_write_mutex() ); - const int index = findAdapterInfoIndex(dev_id); - if( 0 <= index ) { - return adapterIOCapability.at(index); + auto it = adapterInfos.cbegin(); + for (; !it.is_end(); ++it) { + if( (*it)->dev_id == dev_id ) { + return adapterIOCapability.at(it-it.cbegin()); + } } return SMPIOCapability::UNSET; } @@ -958,12 +935,11 @@ MgmtStatus DBTManager::unpairDevice(const uint16_t dev_id, const BDAddressAndTyp } bool DBTManager::isDeviceWhitelisted(const uint16_t dev_id, const BDAddressAndType & addressAndType) noexcept { - for(auto it = whitelist.begin(); it != whitelist.end(); ) { + auto it = whitelist.cbegin(); + for( auto end = whitelist.cend(); it != end; ++it) { std::shared_ptr<WhitelistElem> wle = *it; if( wle->dev_id == dev_id && wle->address_and_type == addressAndType ) { return true; - } else { - ++it; } } return false; @@ -990,21 +966,23 @@ bool DBTManager::addDeviceToWhitelist(const uint16_t dev_id, const BDAddressAndT int DBTManager::removeAllDevicesFromWhitelist() noexcept { #if 0 - std::vector<std::shared_ptr<WhitelistElem>> whitelist_copy = whitelist; + jau::darray<std::shared_ptr<WhitelistElem>> whitelist_copy = whitelist; int count = 0; DBG_PRINT("DBTManager::removeAllDevicesFromWhitelist.A: Start %zd elements", whitelist_copy.size()); - for(auto it = whitelist_copy.begin(); it != whitelist_copy.end(); ++it) { + for(auto it = whitelist_copy.cbegin(); it != whitelist_copy.cend(); ++it) { std::shared_ptr<WhitelistElem> wle = *it; removeDeviceFromWhitelist(wle->dev_id, wle->address, wle->address_type); - count++; + ++count; } #else - int count = whitelist.size(); + int count = 0; DBG_PRINT("DBTManager::removeAllDevicesFromWhitelist.B: Start %d elements", count); whitelist.clear(); - jau::for_each(adapterInfos.cbegin(), adapterInfos.cend(), [&](const std::shared_ptr<AdapterInfo> & a) { - removeDeviceFromWhitelist(a->dev_id, BDAddressAndType::ANY_BREDR_DEVICE); // flush whitelist! + jau::for_each_const(adapterInfos, [&](const std::shared_ptr<AdapterInfo> & a) { + if( removeDeviceFromWhitelist(a->dev_id, BDAddressAndType::ANY_BREDR_DEVICE) ) { // flush whitelist! + ++count; + } }); #endif @@ -1016,7 +994,8 @@ int DBTManager::removeAllDevicesFromWhitelist() noexcept { bool DBTManager::removeDeviceFromWhitelist(const uint16_t dev_id, const BDAddressAndType & addressAndType) noexcept { // Remove from our local whitelist first { - for(auto it = whitelist.begin(); it != whitelist.end(); ) { + auto it = whitelist.cbegin(); + for( auto end = whitelist.cend(); it != end; ) { std::shared_ptr<WhitelistElem> wle = *it; if( wle->dev_id == dev_id && wle->address_and_type == addressAndType ) { it = whitelist.erase(it); @@ -1163,7 +1142,7 @@ void DBTManager::processAdapterAdded(std::unique_ptr<MgmtEvent> e) noexcept { DBG_PRINT("DBTManager::Adapter[%d] Added: Start %s, added %d", dev_id, ai->toString().c_str(), added); sendMgmtEvent(*e); DBG_PRINT("DBTManager::Adapter[%d] Added: User_ %s", dev_id, ai->toString().c_str()); - jau::for_each_fidelity(mgmtChangedAdapterSetCallbackList.cbegin(), mgmtChangedAdapterSetCallbackList.cend(), [&](ChangedAdapterSetCallback &cb) { + jau::for_each_fidelity(mgmtChangedAdapterSetCallbackList, [&](ChangedAdapterSetCallback &cb) { cb.invoke(true /* added */, *ai); }); DBG_PRINT("DBTManager::Adapter[%d] Added: End__ %s", dev_id, ai->toString().c_str()); @@ -1178,7 +1157,7 @@ void DBTManager::processAdapterRemoved(std::unique_ptr<MgmtEvent> e) noexcept { DBG_PRINT("DBTManager::Adapter[%d] Removed: Start: %s", dev_id, ai->toString().c_str()); sendMgmtEvent(*e); DBG_PRINT("DBTManager::Adapter[%d] Removed: User_: %s", dev_id, ai->toString().c_str()); - jau::for_each_fidelity(mgmtChangedAdapterSetCallbackList.cbegin(), mgmtChangedAdapterSetCallbackList.cend(), [&](ChangedAdapterSetCallback &cb) { + jau::for_each_fidelity(mgmtChangedAdapterSetCallbackList, [&](ChangedAdapterSetCallback &cb) { cb.invoke(false /* added */, *ai); }); DBG_PRINT("DBTManager::Adapter[%d] Removed: End__: %s", dev_id, ai->toString().c_str()); @@ -1223,8 +1202,8 @@ static ChangedAdapterSetCallbackList::equal_comparator _changedAdapterSetCallbac void DBTManager::addChangedAdapterSetCallback(const ChangedAdapterSetCallback & l) { mgmtChangedAdapterSetCallbackList.push_back(l); - jau::for_each(adapterInfos.cbegin(), adapterInfos.cend(), [&](const std::shared_ptr<AdapterInfo>& ai) { - jau::for_each_fidelity(mgmtChangedAdapterSetCallbackList.cbegin(), mgmtChangedAdapterSetCallbackList.cend(), [&](ChangedAdapterSetCallback &cb) { + jau::for_each_const(adapterInfos, [&](const std::shared_ptr<AdapterInfo>& ai) { + jau::for_each_fidelity(mgmtChangedAdapterSetCallbackList, [&](ChangedAdapterSetCallback &cb) { cb.invoke(true /* added */, *ai); }); }); diff --git a/src/direct_bt/GATTCharacteristic.cpp b/src/direct_bt/GATTCharacteristic.cpp index f67a1f1c..4e200204 100644 --- a/src/direct_bt/GATTCharacteristic.cpp +++ b/src/direct_bt/GATTCharacteristic.cpp @@ -90,8 +90,8 @@ std::string GATTCharacteristic::getPropertiesString(const PropertyBitVal propert return out; } -std::vector<std::unique_ptr<std::string>> GATTCharacteristic::getPropertiesStringList(const PropertyBitVal properties) noexcept { - std::vector<std::unique_ptr<std::string>> out; +jau::darray<std::unique_ptr<std::string>> GATTCharacteristic::getPropertiesStringList(const PropertyBitVal properties) noexcept { + jau::darray<std::unique_ptr<std::string>> out; const PropertyBitVal none = static_cast<PropertyBitVal>(0); const uint8_t one = 1; for(int i=0; i<8; i++) { diff --git a/src/direct_bt/GATTHandler.cpp b/src/direct_bt/GATTHandler.cpp index 253ff2e1..374176f3 100644 --- a/src/direct_bt/GATTHandler.cpp +++ b/src/direct_bt/GATTHandler.cpp @@ -27,7 +27,6 @@ #include <string> #include <memory> #include <cstdint> -#include <vector> #include <cstdio> #include <algorithm> @@ -123,22 +122,14 @@ bool GATTHandler::removeCharacteristicListener(const GATTCharacteristicListener ERR_PRINT("Given GATTCharacteristicListener ref is null"); return false; } - const std::lock_guard<std::recursive_mutex> lock(characteristicListenerList.get_write_mutex()); - std::shared_ptr<jau::darray<std::shared_ptr<GATTCharacteristicListener>>> store = characteristicListenerList.copy_store(); - int count = 0; - for(auto it = store->begin(); it != store->end(); ) { + auto it = characteristicListenerList.begin(); // lock mutex and copy_store + for (; !it.is_end(); ++it ) { if ( **it == *l ) { - it = store->erase(it); - count++; - break; - } else { - ++it; + it.erase(); + it.write_back(); + return true; } } - if( 0 < count ) { - characteristicListenerList.set_store(std::move(store)); - return true; - } return false; } @@ -155,23 +146,20 @@ int GATTHandler::removeAllAssociatedCharacteristicListener(const GATTCharacteris ERR_PRINT("Given GATTCharacteristic ref is null"); return false; } - const std::lock_guard<std::recursive_mutex> lock(characteristicListenerList.get_write_mutex()); - std::shared_ptr<jau::darray<std::shared_ptr<GATTCharacteristicListener>>> store = characteristicListenerList.copy_store(); int count = 0; - for(auto it = store->begin(); it != store->end(); ) { + auto it = characteristicListenerList.begin(); // lock mutex and copy_store + while( !it.is_end() ) { if ( (*it)->match(*associatedCharacteristic) ) { - it = store->erase(it); - count++; - break; + it.erase(); + ++count; } else { ++it; } } if( 0 < count ) { - characteristicListenerList.set_store(std::move(store)); - return true; + it.write_back(); } - return false; + return count; } int GATTHandler::removeAllCharacteristicListener() noexcept { @@ -223,7 +211,7 @@ void GATTHandler::l2capReaderThreadImpl() { // const std::shared_ptr<TROOctets> data( std::make_shared<POctets>(a->getValue()) ); const uint64_t timestamp = a->ts_creation; int i=0; - jau::for_each_fidelity(characteristicListenerList.cbegin(), characteristicListenerList.cend(), [&](std::shared_ptr<GATTCharacteristicListener> &l) { + jau::for_each_fidelity(characteristicListenerList, [&](std::shared_ptr<GATTCharacteristicListener> &l) { try { if( l->match(*decl) ) { l->notificationReceived(decl, data_view, timestamp); @@ -251,7 +239,7 @@ void GATTHandler::l2capReaderThreadImpl() { // const std::shared_ptr<TROOctets> data( std::make_shared<POctets>(a->getValue()) ); const uint64_t timestamp = a->ts_creation; int i=0; - jau::for_each_fidelity(characteristicListenerList.cbegin(), characteristicListenerList.cend(), [&](std::shared_ptr<GATTCharacteristicListener> &l) { + jau::for_each_fidelity(characteristicListenerList, [&](std::shared_ptr<GATTCharacteristicListener> &l) { try { if( l->match(*decl) ) { l->indicationReceived(decl, data_view, timestamp, cfmSent); @@ -501,7 +489,7 @@ GATTCharacteristicRef GATTHandler::findCharacterisicsByValueHandle(const uint16_ return findCharacterisicsByValueHandle(charValueHandle, services); } -GATTCharacteristicRef GATTHandler::findCharacterisicsByValueHandle(const uint16_t charValueHandle, std::vector<GATTServiceRef> &services_) noexcept { +GATTCharacteristicRef GATTHandler::findCharacterisicsByValueHandle(const uint16_t charValueHandle, jau::darray<GATTServiceRef> &services_) noexcept { for(auto it = services_.begin(); it != services_.end(); it++) { GATTCharacteristicRef decl = findCharacterisicsByValueHandle(charValueHandle, *it); if( nullptr != decl ) { @@ -521,7 +509,7 @@ GATTCharacteristicRef GATTHandler::findCharacterisicsByValueHandle(const uint16_ return nullptr; } -std::vector<GATTServiceRef> & GATTHandler::discoverCompletePrimaryServices(std::shared_ptr<GATTHandler> shared_this) { +jau::darray<GATTServiceRef> & GATTHandler::discoverCompletePrimaryServices(std::shared_ptr<GATTHandler> shared_this) { const std::lock_guard<std::recursive_mutex> lock(mtx_command); // RAII-style acquire and relinquish via destructor if( !discoverPrimaryServices(shared_this, services) ) { return services; @@ -536,7 +524,7 @@ std::vector<GATTServiceRef> & GATTHandler::discoverCompletePrimaryServices(std:: return services; } -bool GATTHandler::discoverPrimaryServices(std::shared_ptr<GATTHandler> shared_this, std::vector<GATTServiceRef> & result) { +bool GATTHandler::discoverPrimaryServices(std::shared_ptr<GATTHandler> shared_this, jau::darray<GATTServiceRef> & result) { { // validate shared_this first! GATTHandler *given_this = shared_this.get(); @@ -958,7 +946,7 @@ static const uuid16_t _MANUFACTURER_NAME_STRING(GattCharacteristicType::MANUFACT static const uuid16_t _REGULATORY_CERT_DATA_LIST(GattCharacteristicType::REGULATORY_CERT_DATA_LIST); static const uuid16_t _PNP_ID(GattCharacteristicType::PNP_ID); -std::shared_ptr<GattGenericAccessSvc> GATTHandler::getGenericAccess(std::vector<GATTCharacteristicRef> & genericAccessCharDeclList) { +std::shared_ptr<GattGenericAccessSvc> GATTHandler::getGenericAccess(jau::darray<GATTCharacteristicRef> & genericAccessCharDeclList) { std::shared_ptr<GattGenericAccessSvc> res = nullptr; POctets value(number(Defaults::MAX_ATT_MTU), 0); std::string deviceName = ""; @@ -993,7 +981,7 @@ std::shared_ptr<GattGenericAccessSvc> GATTHandler::getGenericAccess(std::vector< return res; } -std::shared_ptr<GattGenericAccessSvc> GATTHandler::getGenericAccess(std::vector<GATTServiceRef> & primServices) { +std::shared_ptr<GattGenericAccessSvc> GATTHandler::getGenericAccess(jau::darray<GATTServiceRef> & primServices) { std::shared_ptr<GattGenericAccessSvc> res = nullptr; for(size_t i=0; i<primServices.size() && nullptr == res; i++) { res = getGenericAccess(primServices.at(i)->characteristicList); @@ -1006,7 +994,7 @@ bool GATTHandler::ping() { bool isOK = true; for(size_t i=0; isOK && i<services.size(); i++) { - std::vector<GATTCharacteristicRef> & genericAccessCharDeclList = services.at(i)->characteristicList; + jau::darray<GATTCharacteristicRef> & genericAccessCharDeclList = services.at(i)->characteristicList; POctets value(32, 0); for(size_t j=0; isOK && j<genericAccessCharDeclList.size(); j++) { @@ -1033,7 +1021,7 @@ bool GATTHandler::ping() { return false; } -std::shared_ptr<GattDeviceInformationSvc> GATTHandler::getDeviceInformation(std::vector<GATTCharacteristicRef> & characteristicDeclList) { +std::shared_ptr<GattDeviceInformationSvc> GATTHandler::getDeviceInformation(jau::darray<GATTCharacteristicRef> & characteristicDeclList) { std::shared_ptr<GattDeviceInformationSvc> res = nullptr; POctets value(number(Defaults::MAX_ATT_MTU), 0); @@ -1103,7 +1091,7 @@ std::shared_ptr<GattDeviceInformationSvc> GATTHandler::getDeviceInformation(std: return res; } -std::shared_ptr<GattDeviceInformationSvc> GATTHandler::getDeviceInformation(std::vector<GATTServiceRef> & primServices) { +std::shared_ptr<GattDeviceInformationSvc> GATTHandler::getDeviceInformation(jau::darray<GATTServiceRef> & primServices) { std::shared_ptr<GattDeviceInformationSvc> res = nullptr; for(size_t i=0; i<primServices.size() && nullptr == res; i++) { res = getDeviceInformation(primServices.at(i)->characteristicList); diff --git a/src/direct_bt/GATTNumbers.cpp b/src/direct_bt/GATTNumbers.cpp index b34e3514..85696f2b 100644 --- a/src/direct_bt/GATTNumbers.cpp +++ b/src/direct_bt/GATTNumbers.cpp @@ -27,11 +27,11 @@ #include <string> #include <memory> #include <cstdint> -#include <vector> #include <cstdio> #include <algorithm> +#include <jau/darray.hpp> #include <jau/debug.hpp> #include "GATTNumbers.hpp" @@ -193,7 +193,7 @@ const GattServiceCharacteristic direct_bt::GATT_DEVICE_INFORMATION_SRVC = { DEVI } } }; -const std::vector<const GattServiceCharacteristic*> direct_bt::GATT_SERVICES = { +const jau::darray<const GattServiceCharacteristic*> direct_bt::GATT_SERVICES = { &direct_bt::GATT_GENERIC_ACCESS_SRVC, &direct_bt::GATT_HEALTH_THERMOMETER_SRVC, &direct_bt::GATT_DEVICE_INFORMATION_SRVC }; #define CASE_TO_STRING(V) case V: return #V; diff --git a/src/direct_bt/HCIHandler.cpp b/src/direct_bt/HCIHandler.cpp index 235bfc2a..2d500068 100644 --- a/src/direct_bt/HCIHandler.cpp +++ b/src/direct_bt/HCIHandler.cpp @@ -27,7 +27,6 @@ #include <string> #include <memory> #include <cstdint> -#include <vector> #include <cstdio> #include <algorithm> @@ -76,11 +75,12 @@ __pack( struct hci_rp_status { __u8 status; } ); -HCIHandler::HCIConnectionRef HCIHandler::addOrUpdateHCIConnection(std::vector<HCIConnectionRef> &list, +HCIHandler::HCIConnectionRef HCIHandler::addOrUpdateHCIConnection(jau::darray<HCIConnectionRef> &list, const BDAddressAndType& addressAndType, const uint16_t handle) noexcept { const std::lock_guard<std::recursive_mutex> lock(mtx_connectionList); // RAII-style acquire and relinquish via destructor // remove all old entry with given address first - for (auto it = list.begin(); it != list.end(); ) { + auto end = list.end(); + for (auto it = list.begin(); it != end; ++it) { HCIConnectionRef conn = *it; if ( conn->equals(addressAndType) ) { // reuse same entry @@ -97,8 +97,6 @@ HCIHandler::HCIConnectionRef HCIHandler::addOrUpdateHCIConnection(std::vector<HC conn->setHandle( handle ); } return conn; // done - } else { - ++it; } } HCIConnectionRef res( new HCIConnection(addressAndType, handle) ); @@ -106,10 +104,10 @@ HCIHandler::HCIConnectionRef HCIHandler::addOrUpdateHCIConnection(std::vector<HC return res; } -HCIHandler::HCIConnectionRef HCIHandler::findHCIConnection(std::vector<HCIConnectionRef> &list, const BDAddressAndType& addressAndType) noexcept { +HCIHandler::HCIConnectionRef HCIHandler::findHCIConnection(jau::darray<HCIConnectionRef> &list, const BDAddressAndType& addressAndType) noexcept { const std::lock_guard<std::recursive_mutex> lock(mtx_connectionList); // RAII-style acquire and relinquish via destructor - const size_t size = list.size(); - for (size_t i = 0; i < size; i++) { + const jau::nsize_t size = list.size(); + for (jau::nsize_t i = 0; i < size; i++) { HCIConnectionRef & e = list[i]; if( e->equals(addressAndType) ) { return e; @@ -120,8 +118,8 @@ HCIHandler::HCIConnectionRef HCIHandler::findHCIConnection(std::vector<HCIConnec HCIHandler::HCIConnectionRef HCIHandler::findTrackerConnection(const uint16_t handle) noexcept { const std::lock_guard<std::recursive_mutex> lock(mtx_connectionList); // RAII-style acquire and relinquish via destructor - const size_t size = connectionList.size(); - for (size_t i = 0; i < size; i++) { + const jau::nsize_t size = connectionList.size(); + for (jau::nsize_t i = 0; i < size; i++) { HCIConnectionRef & e = connectionList[i]; if ( handle == e->getHandle() ) { return e; @@ -132,13 +130,12 @@ HCIHandler::HCIConnectionRef HCIHandler::findTrackerConnection(const uint16_t ha HCIHandler::HCIConnectionRef HCIHandler::removeTrackerConnection(const HCIConnectionRef conn) noexcept { const std::lock_guard<std::recursive_mutex> lock(mtx_connectionList); // RAII-style acquire and relinquish via destructor - for (auto it = connectionList.begin(); it != connectionList.end(); ) { + auto end = connectionList.end(); + for (auto it = connectionList.begin(); it != end; ++it) { HCIConnectionRef e = *it; if ( *e == *conn ) { - it = connectionList.erase(it); + connectionList.erase(it); return e; // done - } else { - ++it; } } return nullptr; @@ -154,15 +151,14 @@ int HCIHandler::countPendingTrackerConnections() noexcept { } return count; } -HCIHandler::HCIConnectionRef HCIHandler::removeHCIConnection(std::vector<HCIConnectionRef> &list, const uint16_t handle) noexcept { +HCIHandler::HCIConnectionRef HCIHandler::removeHCIConnection(jau::darray<HCIConnectionRef> &list, const uint16_t handle) noexcept { const std::lock_guard<std::recursive_mutex> lock(mtx_connectionList); // RAII-style acquire and relinquish via destructor - for (auto it = list.begin(); it != list.end(); ) { + auto end = list.end(); + for (auto it = list.begin(); it != end; ++it) { HCIConnectionRef e = *it; if ( e->getHandle() == handle ) { - it = list.erase(it); + list.erase(it); return e; // done - } else { - ++it; } } return nullptr; @@ -380,7 +376,7 @@ void HCIHandler::hciReaderThreadImpl() noexcept { if( nullptr != conn ) { COND_PRINT(env.DEBUG_EVENT, "HCIHandler-IO RECV (ACL.SMP) %s for %s", smpPDU->toString().c_str(), conn->toString().c_str()); - jau::for_each_fidelity(hciSMPMsgCallbackList.cbegin(), hciSMPMsgCallbackList.cend(), [&](HCISMPMsgCallback &cb) { + jau::for_each_fidelity(hciSMPMsgCallbackList, [&](HCISMPMsgCallback &cb) { cb.invoke(conn->getAddressAndType(), *smpPDU, l2cap); }); } else { @@ -428,7 +424,7 @@ void HCIHandler::hciReaderThreadImpl() noexcept { hciEventRing.putBlocking( std::move( event ) ); } else if( event->isMetaEvent(HCIMetaEventType::LE_ADVERTISING_REPORT) ) { // issue callbacks for the translated AD events - std::vector<std::shared_ptr<EInfoReport>> eirlist = EInfoReport::read_ad_reports(event->getParam(), event->getParamSize()); + jau::darray<std::shared_ptr<EInfoReport>> eirlist = EInfoReport::read_ad_reports(event->getParam(), event->getParamSize()); jau::for_each_idx(eirlist, [&](std::shared_ptr<EInfoReport> & eir) { // COND_PRINT(env.DEBUG_EVENT, "HCIHandler-IO RECV (AD EIR) %s", eir->toString().c_str()); const MgmtEvtDeviceFound e(dev_id, eir); @@ -461,7 +457,7 @@ void HCIHandler::sendMgmtEvent(const MgmtEvent& event) noexcept { MgmtEventCallbackList & mgmtEventCallbackList = mgmtEventCallbackLists[static_cast<uint16_t>(event.getOpcode())]; int invokeCount = 0; - jau::for_each_fidelity(mgmtEventCallbackList.cbegin(), mgmtEventCallbackList.cend(), [&](MgmtEventCallback &cb) { + jau::for_each_fidelity(mgmtEventCallbackList, [&](MgmtEventCallback &cb) { try { cb.invoke(event); } catch (std::exception &e) { diff --git a/src/direct_bt/SMPHandler.cpp b/src/direct_bt/SMPHandler.cpp index f366cd35..cc4e97ff 100644 --- a/src/direct_bt/SMPHandler.cpp +++ b/src/direct_bt/SMPHandler.cpp @@ -127,7 +127,7 @@ void SMPHandler::l2capReaderThreadImpl() { if( SMPPDUMsg::Opcode::SECURITY_REQUEST == opc ) { COND_PRINT(env.DEBUG_DATA, "SMPHandler-IO RECV (SEC_REQ) %s", smpPDU->toString().c_str()); - jau::for_each_fidelity(smpSecurityReqCallbackList.cbegin(), smpSecurityReqCallbackList.cend(), [&](SMPSecurityReqCallback &cb) { + jau::for_each_fidelity(smpSecurityReqCallbackList, [&](SMPSecurityReqCallback &cb) { cb.invoke(*smpPDU); }); } else { |