diff options
author | Sven Gothel <[email protected]> | 2020-10-24 04:26:22 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2020-10-24 04:26:22 +0200 |
commit | 27d0b2381fe32a3cee9ce19200e42d749cbe8a76 (patch) | |
tree | 631b80734b6daaa85d101e986b9da61180c22bb5 | |
parent | 4a6d3ed80095045f72d7024362801e94b866549a (diff) |
DBTAdapter::toString(): Add valid and open states; Reorder some methods
-rw-r--r-- | src/direct_bt/DBTAdapter.cpp | 117 |
1 files changed, 61 insertions, 56 deletions
diff --git a/src/direct_bt/DBTAdapter.cpp b/src/direct_bt/DBTAdapter.cpp index 70bc3711..17204570 100644 --- a/src/direct_bt/DBTAdapter.cpp +++ b/src/direct_bt/DBTAdapter.cpp @@ -186,7 +186,7 @@ bool DBTAdapter::validateDevInfo() noexcept { return false; } -#ifdef VERBOSE_ON +#if 0 mgmt.addMgmtEventCallback(dev_id, MgmtEvent::Opcode::DEVICE_DISCONNECTED, bindMemberFunc(this, &DBTAdapter::mgmtEvDeviceDisconnectedMgmt)); #endif @@ -596,6 +596,8 @@ exit: return status; } +// ************************************************* + std::shared_ptr<DBTDevice> DBTAdapter::findDiscoveredDevice (EUI48 const & mac, const BDAddressType macType) noexcept { const std::lock_guard<std::mutex> lock(const_cast<DBTAdapter*>(this)->mtx_discoveredDevices); // RAII-style acquire and relinquish via destructor return findDevice(discoveredDevices, mac, macType); @@ -684,7 +686,8 @@ std::string DBTAdapter::toString(bool includeDiscoveredDevices) const noexcept { std::string out("Adapter[BTMode "+getBTModeString(btMode)+", "+getAddressString()+", '"+getName()+"', id "+std::to_string(dev_id)+ ", curSettings"+getAdapterSettingMaskString(adapterInfo->getCurrentSettingMask())+ ", scanType[native "+getScanTypeString(hci.getCurrentScanType())+", meta "+getScanTypeString(currentMetaScanType)+"]" - ", "+javaObjectToString()+"]"); + ", 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(); if( includeDiscoveredDevices && devices.size() > 0 ) { out.append("\n"); @@ -700,6 +703,62 @@ std::string DBTAdapter::toString(bool includeDiscoveredDevices) const noexcept { // ************************************************* +void DBTAdapter::sendAdapterSettingsChanged(const AdapterSetting old_settings, const AdapterSetting current_settings, + const uint64_t timestampMS) noexcept +{ + AdapterSetting changes = getAdapterSettingMaskDiff(current_settings, old_settings); + COND_PRINT(debug_event, "DBTAdapter::sendAdapterSettingsChanged: %s -> %s, changes %s: %s", + getAdapterSettingMaskString(old_settings).c_str(), + getAdapterSettingMaskString(current_settings).c_str(), + getAdapterSettingMaskString(changes).c_str(), toString(false).c_str() ); + int i=0; + jau::for_each_cow(statusListenerList, [&](std::shared_ptr<AdapterStatusListener> &l) { + try { + l->adapterSettingsChanged(*this, old_settings, current_settings, changes, timestampMS); + } catch (std::exception &e) { + ERR_PRINT("DBTAdapter:CB:NewSettings-CBs %d/%zd: %s of %s: Caught exception %s", + i+1, statusListenerList.size(), + l->toString().c_str(), toString(false).c_str(), e.what()); + } + i++; + }); +} + +void DBTAdapter::sendAdapterSettingsChanged(AdapterStatusListener & asl, + const AdapterSetting old_settings, const AdapterSetting current_settings, + const uint64_t timestampMS) noexcept +{ + AdapterSetting changes = getAdapterSettingMaskDiff(current_settings, old_settings); + COND_PRINT(debug_event, "DBTAdapter::sendAdapterSettingsChanged: %s -> %s, changes %s: %s", + getAdapterSettingMaskString(old_settings).c_str(), + getAdapterSettingMaskString(current_settings).c_str(), + getAdapterSettingMaskString(changes).c_str(), toString(false).c_str() ); + try { + asl.adapterSettingsChanged(*this, old_settings, current_settings, changes, timestampMS); + } catch (std::exception &e) { + ERR_PRINT("DBTAdapter::sendAdapterSettingsChanged-CB: %s of %s: Caught exception %s", + asl.toString().c_str(), toString(false).c_str(), e.what()); + } +} + +void DBTAdapter::sendDeviceUpdated(std::string cause, std::shared_ptr<DBTDevice> device, uint64_t timestamp, EIRDataType updateMask) noexcept { + int i=0; + jau::for_each_cow(statusListenerList, [&](std::shared_ptr<AdapterStatusListener> &l) { + try { + if( l->matchDevice(*device) ) { + l->deviceUpdated(device, updateMask, timestamp); + } + } catch (std::exception &e) { + ERR_PRINT("DBTAdapter::sendDeviceUpdated-CBs (%s) %d/%zd: %s of %s: Caught exception %s", + cause.c_str(), i+1, statusListenerList.size(), + l->toString().c_str(), device->toString().c_str(), e.what()); + } + i++; + }); +} + +// ************************************************* + bool DBTAdapter::mgmtEvDeviceDiscoveringHCI(std::shared_ptr<MgmtEvent> e) noexcept { return mgmtEvDeviceDiscoveringAny(e, true /* hciSourced */ ); } @@ -796,44 +855,6 @@ bool DBTAdapter::mgmtEvNewSettingsMgmt(std::shared_ptr<MgmtEvent> e) noexcept { return true; } -void DBTAdapter::sendAdapterSettingsChanged(const AdapterSetting old_settings, const AdapterSetting current_settings, - const uint64_t timestampMS) noexcept -{ - AdapterSetting changes = getAdapterSettingMaskDiff(current_settings, old_settings); - COND_PRINT(debug_event, "DBTAdapter::sendAdapterSettingsChanged: %s -> %s, changes %s: %s", - getAdapterSettingMaskString(old_settings).c_str(), - getAdapterSettingMaskString(current_settings).c_str(), - getAdapterSettingMaskString(changes).c_str(), toString(false).c_str() ); - int i=0; - jau::for_each_cow(statusListenerList, [&](std::shared_ptr<AdapterStatusListener> &l) { - try { - l->adapterSettingsChanged(*this, old_settings, current_settings, changes, timestampMS); - } catch (std::exception &e) { - ERR_PRINT("DBTAdapter::EventCB:NewSettings-CBs %d/%zd: %s of %s: Caught exception %s", - i+1, statusListenerList.size(), - l->toString().c_str(), toString(false).c_str(), e.what()); - } - i++; - }); -} - -void DBTAdapter::sendAdapterSettingsChanged(AdapterStatusListener & asl, - const AdapterSetting old_settings, const AdapterSetting current_settings, - const uint64_t timestampMS) noexcept -{ - AdapterSetting changes = getAdapterSettingMaskDiff(current_settings, old_settings); - COND_PRINT(debug_event, "DBTAdapter::sendAdapterSettingsChanged: %s -> %s, changes %s: %s", - getAdapterSettingMaskString(old_settings).c_str(), - getAdapterSettingMaskString(current_settings).c_str(), - getAdapterSettingMaskString(changes).c_str(), toString(false).c_str() ); - try { - asl.adapterSettingsChanged(*this, old_settings, current_settings, changes, timestampMS); - } catch (std::exception &e) { - ERR_PRINT("DBTAdapter::sendAdapterSettingsChanged-CB: %s of %s: Caught exception %s", - asl.toString().c_str(), toString(false).c_str(), e.what()); - } -} - bool DBTAdapter::mgmtEvLocalNameChangedMgmt(std::shared_ptr<MgmtEvent> e) noexcept { COND_PRINT(debug_event, "DBTAdapter:mgmt:LocalNameChanged: %s", e->toString().c_str()); const MgmtEvtLocalNameChanged &event = *static_cast<const MgmtEvtLocalNameChanged *>(e.get()); @@ -855,22 +876,6 @@ bool DBTAdapter::mgmtEvLocalNameChangedMgmt(std::shared_ptr<MgmtEvent> e) noexce return true; } -void DBTAdapter::sendDeviceUpdated(std::string cause, std::shared_ptr<DBTDevice> device, uint64_t timestamp, EIRDataType updateMask) noexcept { - int i=0; - jau::for_each_cow(statusListenerList, [&](std::shared_ptr<AdapterStatusListener> &l) { - try { - if( l->matchDevice(*device) ) { - l->deviceUpdated(device, updateMask, timestamp); - } - } catch (std::exception &e) { - ERR_PRINT("DBTAdapter::sendDeviceUpdated-CBs (%s) %d/%zd: %s of %s: Caught exception %s", - cause.c_str(), i+1, statusListenerList.size(), - l->toString().c_str(), device->toString().c_str(), e.what()); - } - i++; - }); -} - bool DBTAdapter::mgmtEvDeviceConnectedHCI(std::shared_ptr<MgmtEvent> e) noexcept { COND_PRINT(debug_event, "DBTAdapter:hci:DeviceConnected(dev_id %d): %s", dev_id, e->toString().c_str()); const MgmtEvtDeviceConnected &event = *static_cast<const MgmtEvtDeviceConnected *>(e.get()); |