diff options
author | Sven Gothel <[email protected]> | 2020-08-24 22:02:00 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2020-08-24 22:02:00 +0200 |
commit | f80a628ef4279b9bf237981fc7aa2e9dbbae2915 (patch) | |
tree | 7e9650fb606a5d2b9286ab088b0f686770dc5b90 /src | |
parent | ab8676ae3fd865c89ab04c12861da388dbaebb46 (diff) |
Adopt to exploding DEBUG value, implement 'hci.event,manager.event,adapter.event,gatt.data' for 'direct_bt.debug'
Explosion of 'hci.event,manager.event,adapter.event,gatt.data' will lead to
- 'direct_bt.debug.hci.event'
- 'direct_bt.debug.manager.event'
- 'direct_bt.debug.adapter.event'
- 'direct_bt.debug.gatt.data'
and is being used in their respective modules using COND_PRINT(debug_state, ...).
Diffstat (limited to 'src')
-rw-r--r-- | src/direct_bt/DBTAdapter.cpp | 44 | ||||
-rw-r--r-- | src/direct_bt/DBTManager.cpp | 78 | ||||
-rw-r--r-- | src/direct_bt/GATTHandler.cpp | 63 | ||||
-rw-r--r-- | src/direct_bt/HCIHandler.cpp | 30 |
4 files changed, 107 insertions, 108 deletions
diff --git a/src/direct_bt/DBTAdapter.cpp b/src/direct_bt/DBTAdapter.cpp index c9d478df..1157ee2d 100644 --- a/src/direct_bt/DBTAdapter.cpp +++ b/src/direct_bt/DBTAdapter.cpp @@ -32,7 +32,6 @@ #include <algorithm> -// #define VERBOSE_ON 1 #include <dbt_debug.hpp> #include "BasicAlgos.hpp" @@ -49,12 +48,6 @@ extern "C" { #include <poll.h> } -// #define EVENT_PRINT_ON 1 -#ifdef EVENT_PRINT_ON - #define EVENT_PRINT(...) PLAIN_PRINT(__VA_ARGS__) -#else - #define EVENT_PRINT(...) -#endif using namespace direct_bt; @@ -198,19 +191,22 @@ bool DBTAdapter::validateDevInfo() { } DBTAdapter::DBTAdapter() -: mgmt(DBTManager::get(BTMode::LE)), btMode(mgmt.getBTMode()), dev_id(nullptr != mgmt.getDefaultAdapterInfo() ? 0 : -1) +: debug_event(DBTEnv::getBooleanProperty("direct_bt.debug.adapter.event", false)), + mgmt(DBTManager::get(BTMode::LE)), btMode(mgmt.getBTMode()), dev_id(nullptr != mgmt.getDefaultAdapterInfo() ? 0 : -1) { valid = validateDevInfo(); } DBTAdapter::DBTAdapter(EUI48 &mac) -: mgmt(DBTManager::get(BTMode::LE)), btMode(mgmt.getBTMode()), dev_id(mgmt.findAdapterInfoIdx(mac)) +: debug_event(DBTEnv::getBooleanProperty("direct_bt.debug.adapter.event", false)), + mgmt(DBTManager::get(BTMode::LE)), btMode(mgmt.getBTMode()), dev_id(mgmt.findAdapterInfoIdx(mac)) { valid = validateDevInfo(); } DBTAdapter::DBTAdapter(const int dev_id) -: mgmt(DBTManager::get(BTMode::LE)), btMode(mgmt.getBTMode()), dev_id(dev_id) +: debug_event(DBTEnv::getBooleanProperty("direct_bt.debug.adapter.event", false)), + mgmt(DBTManager::get(BTMode::LE)), btMode(mgmt.getBTMode()), dev_id(dev_id) { valid = validateDevInfo(); } @@ -639,7 +635,7 @@ bool DBTAdapter::mgmtEvDeviceDiscoveringMgmt(std::shared_ptr<MgmtEvent> e) { currentMetaScanType = ScanType::NONE; } } - EVENT_PRINT("DBTAdapter::EventCB:DeviceDiscovering(dev_id %d, keepDiscoveringAlive %d, currentScanType[native %s, meta %s]): %s", + COND_PRINT(debug_event, "DBTAdapter::EventCB:DeviceDiscovering(dev_id %d, keepDiscoveringAlive %d, currentScanType[native %s, meta %s]): %s", dev_id, keepDiscoveringAlive.load(), getScanTypeString(currentNativeScanType).c_str(), getScanTypeString(currentMetaScanType).c_str(), e->toString().c_str()); @@ -664,11 +660,11 @@ bool DBTAdapter::mgmtEvDeviceDiscoveringMgmt(std::shared_ptr<MgmtEvent> e) { } bool DBTAdapter::mgmtEvNewSettingsMgmt(std::shared_ptr<MgmtEvent> e) { - EVENT_PRINT("DBTAdapter::EventCB:NewSettings: %s", e->toString().c_str()); + COND_PRINT(debug_event, "DBTAdapter::EventCB:NewSettings: %s", e->toString().c_str()); const MgmtEvtNewSettings &event = *static_cast<const MgmtEvtNewSettings *>(e.get()); AdapterSetting old_setting = adapterInfo->getCurrentSetting(); AdapterSetting changes = adapterInfo->setCurrentSetting(event.getSettings()); - EVENT_PRINT("DBTAdapter::EventCB:NewSettings: %s -> %s, changes %s", + COND_PRINT(debug_event, "DBTAdapter::EventCB:NewSettings: %s -> %s, changes %s", getAdapterSettingsString(old_setting).c_str(), getAdapterSettingsString(adapterInfo->getCurrentSetting()).c_str(), getAdapterSettingsString(changes).c_str() ); @@ -689,7 +685,7 @@ bool DBTAdapter::mgmtEvNewSettingsMgmt(std::shared_ptr<MgmtEvent> e) { } bool DBTAdapter::mgmtEvLocalNameChangedMgmt(std::shared_ptr<MgmtEvent> e) { - EVENT_PRINT("DBTAdapter::EventCB:LocalNameChanged: %s", e->toString().c_str()); + COND_PRINT(debug_event, "DBTAdapter::EventCB:LocalNameChanged: %s", e->toString().c_str()); const MgmtEvtLocalNameChanged &event = *static_cast<const MgmtEvtLocalNameChanged *>(e.get()); std::string old_name = localName.getName(); std::string old_shortName = localName.getShortName(); @@ -701,7 +697,7 @@ bool DBTAdapter::mgmtEvLocalNameChangedMgmt(std::shared_ptr<MgmtEvent> e) { if( shortNameChanged ) { localName.setShortName(event.getShortName()); } - EVENT_PRINT("DBTAdapter::EventCB:LocalNameChanged: Local name: %d: '%s' -> '%s'; short_name: %d: '%s' -> '%s'", + COND_PRINT(debug_event, "DBTAdapter::EventCB:LocalNameChanged: Local name: %d: '%s' -> '%s'; short_name: %d: '%s' -> '%s'", nameChanged, old_name.c_str(), localName.getName().c_str(), shortNameChanged, old_shortName.c_str(), localName.getShortName().c_str()); (void)nameChanged; @@ -772,7 +768,7 @@ bool DBTAdapter::mgmtEvDeviceConnectedHCI(std::shared_ptr<MgmtEvent> e) { ad_report.toString().c_str(), device->toString().c_str()); } else { - EVENT_PRINT("DBTAdapter::EventHCI:DeviceConnected(dev_id %d, new_connect %d, updated %s): %s, handle %s -> %s,\n %s,\n -> %s", + COND_PRINT(debug_event, "DBTAdapter::EventHCI:DeviceConnected(dev_id %d, new_connect %d, updated %s): %s, handle %s -> %s,\n %s,\n -> %s", dev_id, new_connect, getEIRDataMaskString(updateMask).c_str(), event.toString().c_str(), uint16HexString(device->getConnectionHandle()).c_str(), uint16HexString(event.getHCIHandle()).c_str(), ad_report.toString().c_str(), @@ -803,12 +799,12 @@ bool DBTAdapter::mgmtEvDeviceConnectedHCI(std::shared_ptr<MgmtEvent> e) { } bool DBTAdapter::mgmtEvConnectFailedHCI(std::shared_ptr<MgmtEvent> e) { - EVENT_PRINT("DBTAdapter::EventHCI:ConnectFailed: %s", e->toString().c_str()); + COND_PRINT(debug_event, "DBTAdapter::EventHCI:ConnectFailed: %s", e->toString().c_str()); const MgmtEvtDeviceConnectFailed &event = *static_cast<const MgmtEvtDeviceConnectFailed *>(e.get()); std::shared_ptr<DBTDevice> device = findConnectedDevice(event.getAddress(), event.getAddressType()); if( nullptr != device ) { const uint16_t handle = device->getConnectionHandle(); - EVENT_PRINT("DBTAdapter::EventHCI:ConnectFailed(dev_id %d): %s, handle %s -> zero,\n -> %s", + COND_PRINT(debug_event, "DBTAdapter::EventHCI:ConnectFailed(dev_id %d): %s, handle %s -> zero,\n -> %s", dev_id, event.toString().c_str(), uint16HexString(handle).c_str(), device->toString().c_str()); @@ -845,7 +841,7 @@ bool DBTAdapter::mgmtEvDeviceDisconnectedHCI(std::shared_ptr<MgmtEvent> e) { dev_id, event.toString().c_str(), device->toString().c_str()); return true; } - EVENT_PRINT("DBTAdapter::EventHCI:DeviceDisconnected(dev_id %d): %s, handle %s -> zero,\n -> %s", + COND_PRINT(debug_event, "DBTAdapter::EventHCI:DeviceDisconnected(dev_id %d): %s, handle %s -> zero,\n -> %s", dev_id, event.toString().c_str(), uint16HexString(event.getHCIHandle()).c_str(), device->toString().c_str()); @@ -874,14 +870,14 @@ bool DBTAdapter::mgmtEvDeviceDisconnectedHCI(std::shared_ptr<MgmtEvent> e) { } bool DBTAdapter::mgmtEvDeviceDisconnectedMgmt(std::shared_ptr<MgmtEvent> e) { - EVENT_PRINT("DBTAdapter::EventCB:DeviceDisconnected: %s", e->toString().c_str()); + COND_PRINT(debug_event, "DBTAdapter::EventCB:DeviceDisconnected: %s", e->toString().c_str()); const MgmtEvtDeviceDisconnected &event = *static_cast<const MgmtEvtDeviceDisconnected *>(e.get()); (void)event; return true; } bool DBTAdapter::mgmtEvDeviceFoundHCI(std::shared_ptr<MgmtEvent> e) { - EVENT_PRINT("DBTAdapter::EventCB:DeviceFound(dev_id %d): %s", dev_id, e->toString().c_str()); + COND_PRINT(debug_event, "DBTAdapter::EventCB:DeviceFound(dev_id %d): %s", dev_id, e->toString().c_str()); const MgmtEvtDeviceFound &deviceFoundEvent = *static_cast<const MgmtEvtDeviceFound *>(e.get()); std::shared_ptr<EInfoReport> eir = deviceFoundEvent.getEIR(); @@ -908,7 +904,7 @@ bool DBTAdapter::mgmtEvDeviceFoundHCI(std::shared_ptr<MgmtEvent> e) { // drop existing device // EIRDataType updateMask = dev->update(*eir); - EVENT_PRINT("DBTAdapter::EventCB:DeviceFound: Drop already discovered %s, %s", + COND_PRINT(debug_event, "DBTAdapter::EventCB:DeviceFound: Drop already discovered %s, %s", dev->getAddressString().c_str(), eir->toString().c_str()); if( EIRDataType::NONE != updateMask ) { sendDeviceUpdated("DiscoveredDeviceFound", dev, eir->getTimestamp(), updateMask); @@ -927,7 +923,7 @@ bool DBTAdapter::mgmtEvDeviceFoundHCI(std::shared_ptr<MgmtEvent> e) { EIRDataType updateMask = dev->update(*eir); addDiscoveredDevice(dev); // re-add to discovered devices! dev->ts_last_discovery = eir->getTimestamp(); - EVENT_PRINT("DBTAdapter::EventCB:DeviceFound: Use already shared %s, %s", + COND_PRINT(debug_event, "DBTAdapter::EventCB:DeviceFound: Use already shared %s, %s", dev->getAddressString().c_str(), eir->toString().c_str()); int i=0; @@ -955,7 +951,7 @@ bool DBTAdapter::mgmtEvDeviceFoundHCI(std::shared_ptr<MgmtEvent> e) { dev = std::shared_ptr<DBTDevice>(new DBTDevice(*this, *eir)); addDiscoveredDevice(dev); addSharedDevice(dev); - EVENT_PRINT("DBTAdapter::EventCB:DeviceFound: Use new %s, %s", + COND_PRINT(debug_event, "DBTAdapter::EventCB:DeviceFound: Use new %s, %s", dev->getAddressString().c_str(), eir->toString().c_str()); int i=0; diff --git a/src/direct_bt/DBTManager.cpp b/src/direct_bt/DBTManager.cpp index 19bfae6e..e7e83022 100644 --- a/src/direct_bt/DBTManager.cpp +++ b/src/direct_bt/DBTManager.cpp @@ -33,7 +33,6 @@ #include <algorithm> // #define PERF_PRINT_ON 1 -// #define VERBOSE_ON 1 #include <dbt_debug.hpp> #include "BTIoctl.hpp" @@ -83,9 +82,16 @@ void DBTManager::mgmtReaderThreadImpl() { std::shared_ptr<MgmtEvent> event( MgmtEvent::getSpecialized(rbuffer.get_ptr(), len) ); const MgmtEvent::Opcode opc = event->getOpcode(); if( MgmtEvent::Opcode::CMD_COMPLETE == opc || MgmtEvent::Opcode::CMD_STATUS == opc ) { + COND_PRINT(debug_event, "DBTManager-IO RECV (CMD) %s", event->toString().c_str()); + if( mgmtEventRing.isFull() ) { + const int dropCount = mgmtEventRing.capacity()/4; + mgmtEventRing.drop(dropCount); + WARN_PRINT("DBTManager-IO RECV Drop (%d oldest elements of %d capacity, ring full)", dropCount, mgmtEventRing.capacity()); + } mgmtEventRing.putBlocking( event ); } else { // issue a callback + COND_PRINT(debug_event, "DBTManager-IO RECV (CB) %s", event->toString().c_str()); sendMgmtEvent(event); } } else if( ETIMEDOUT != errno && !mgmtReaderShallStop ) { // expected exits @@ -115,7 +121,7 @@ void DBTManager::sendMgmtEvent(std::shared_ptr<MgmtEvent> event) { invokeCount++; } } - // DBG_PRINT("DBTManager::sendMgmtEvent: Event %s -> %d/%zd callbacks", event->toString().c_str(), invokeCount, mgmtEventCallbackList.size()); + COND_PRINT(debug_event, "DBTManager::sendMgmtEvent: Event %s -> %d/%zd callbacks", event->toString().c_str(), invokeCount, mgmtEventCallbackList.size()); (void)invokeCount; } @@ -150,6 +156,7 @@ std::shared_ptr<MgmtEvent> DBTManager::sendWithReply(MgmtCommand &req) { const std::lock_guard<std::recursive_mutex> lock(mtx_sendReply); // RAII-style acquire and relinquish via destructor { const std::lock_guard<std::recursive_mutex> lock(comm.mutex()); // RAII-style acquire and relinquish via destructor + COND_PRINT(debug_event, "DBTManager-IO SENT %s", req.toString().c_str()); TROOctets & pdu = req.getPDU(); if ( comm.write( pdu.get_ptr(), pdu.getSize() ) < 0 ) { ERR_PRINT("DBTManager::sendWithReply: HCIComm write error, req %s", req.toString().c_str()); @@ -172,6 +179,7 @@ std::shared_ptr<MgmtEvent> DBTManager::sendWithReply(MgmtCommand &req) { retry, res->toString().c_str(), req.toString().c_str()); retry--; } else { + COND_PRINT(debug_event, "DBTManager::sendWithReply: res %s; req %s", res->toString().c_str(), req.toString().c_str()); return res; } } @@ -234,8 +242,10 @@ void DBTManager::shutdownAdapter(const uint16_t dev_id) { } DBTManager::DBTManager(const BTMode btMode) -:btMode(btMode), rbuffer(ClientMaxMTU), comm(HCI_DEV_NONE, HCI_CHANNEL_CONTROL, Defaults::MGMT_READER_THREAD_POLL_TIMEOUT), - mgmtEventRing(MGMTEVT_RING_CAPACITY), mgmtReaderRunning(false), mgmtReaderShallStop(false) +: debug_global(DBTEnv::get().DEBUG), + debug_event(DBTEnv::getBooleanProperty("direct_bt.debug.manager.event", false)), + btMode(btMode), rbuffer(ClientMaxMTU), comm(HCI_DEV_NONE, HCI_CHANNEL_CONTROL, Defaults::MGMT_READER_THREAD_POLL_TIMEOUT), + mgmtEventRing(MGMTEVT_RING_CAPACITY), mgmtReaderRunning(false), mgmtReaderShallStop(false) { INFO_PRINT("DBTManager.ctor: pid %d", DBTManager::pidSelf); if( !comm.isOpen() ) { @@ -355,22 +365,22 @@ next1: } if( ok ) { -#ifdef VERBOSE_ON - addMgmtEventCallback(-1, MgmtEvent::Opcode::CLASS_OF_DEV_CHANGED, bindMemberFunc(this, &DBTManager::mgmtEvClassOfDeviceChangedCB)); - addMgmtEventCallback(-1, MgmtEvent::Opcode::DISCOVERING, bindMemberFunc(this, &DBTManager::mgmtEvDeviceDiscoveringCB)); - addMgmtEventCallback(-1, MgmtEvent::Opcode::DEVICE_FOUND, bindMemberFunc(this, &DBTManager::mgmtEvDeviceFoundCB)); - addMgmtEventCallback(-1, MgmtEvent::Opcode::DEVICE_DISCONNECTED, bindMemberFunc(this, &DBTManager::mgmtEvDeviceDisconnectedCB)); - addMgmtEventCallback(-1, MgmtEvent::Opcode::DEVICE_CONNECTED, bindMemberFunc(this, &DBTManager::mgmtEvDeviceConnectedCB)); - addMgmtEventCallback(-1, MgmtEvent::Opcode::CONNECT_FAILED, bindMemberFunc(this, &DBTManager::mgmtEvConnectFailedCB)); - addMgmtEventCallback(-1, MgmtEvent::Opcode::DEVICE_BLOCKED, bindMemberFunc(this, &DBTManager::mgmtEvDeviceBlockedCB)); - addMgmtEventCallback(-1, MgmtEvent::Opcode::DEVICE_UNBLOCKED, bindMemberFunc(this, &DBTManager::mgmtEvDeviceUnblockedCB)); - addMgmtEventCallback(-1, MgmtEvent::Opcode::DEVICE_UNPAIRED, bindMemberFunc(this, &DBTManager::mgmtEvDeviceUnpairedCB)); - addMgmtEventCallback(-1, MgmtEvent::Opcode::NEW_CONN_PARAM, bindMemberFunc(this, &DBTManager::mgmtEvNewConnectionParamCB)); - addMgmtEventCallback(-1, MgmtEvent::Opcode::DEVICE_WHITELIST_ADDED, bindMemberFunc(this, &DBTManager::mgmtEvDeviceWhitelistAddedCB)); - addMgmtEventCallback(-1, MgmtEvent::Opcode::DEVICE_WHITELIST_REMOVED, bindMemberFunc(this, &DBTManager::mgmtEvDeviceWhilelistRemovedCB)); - addMgmtEventCallback(-1, MgmtEvent::Opcode::PIN_CODE_REQUEST, bindMemberFunc(this, &DBTManager::mgmtEvPinCodeRequestCB)); - addMgmtEventCallback(-1, MgmtEvent::Opcode::USER_PASSKEY_REQUEST, bindMemberFunc(this, &DBTManager::mgmtEvUserPasskeyRequestCB)); -#endif + if( debug_event ) { + addMgmtEventCallback(-1, MgmtEvent::Opcode::CLASS_OF_DEV_CHANGED, bindMemberFunc(this, &DBTManager::mgmtEvClassOfDeviceChangedCB)); + addMgmtEventCallback(-1, MgmtEvent::Opcode::DISCOVERING, bindMemberFunc(this, &DBTManager::mgmtEvDeviceDiscoveringCB)); + addMgmtEventCallback(-1, MgmtEvent::Opcode::DEVICE_FOUND, bindMemberFunc(this, &DBTManager::mgmtEvDeviceFoundCB)); + addMgmtEventCallback(-1, MgmtEvent::Opcode::DEVICE_DISCONNECTED, bindMemberFunc(this, &DBTManager::mgmtEvDeviceDisconnectedCB)); + addMgmtEventCallback(-1, MgmtEvent::Opcode::DEVICE_CONNECTED, bindMemberFunc(this, &DBTManager::mgmtEvDeviceConnectedCB)); + addMgmtEventCallback(-1, MgmtEvent::Opcode::CONNECT_FAILED, bindMemberFunc(this, &DBTManager::mgmtEvConnectFailedCB)); + addMgmtEventCallback(-1, MgmtEvent::Opcode::DEVICE_BLOCKED, bindMemberFunc(this, &DBTManager::mgmtEvDeviceBlockedCB)); + addMgmtEventCallback(-1, MgmtEvent::Opcode::DEVICE_UNBLOCKED, bindMemberFunc(this, &DBTManager::mgmtEvDeviceUnblockedCB)); + addMgmtEventCallback(-1, MgmtEvent::Opcode::DEVICE_UNPAIRED, bindMemberFunc(this, &DBTManager::mgmtEvDeviceUnpairedCB)); + addMgmtEventCallback(-1, MgmtEvent::Opcode::NEW_CONN_PARAM, bindMemberFunc(this, &DBTManager::mgmtEvNewConnectionParamCB)); + addMgmtEventCallback(-1, MgmtEvent::Opcode::DEVICE_WHITELIST_ADDED, bindMemberFunc(this, &DBTManager::mgmtEvDeviceWhitelistAddedCB)); + addMgmtEventCallback(-1, MgmtEvent::Opcode::DEVICE_WHITELIST_REMOVED, bindMemberFunc(this, &DBTManager::mgmtEvDeviceWhilelistRemovedCB)); + addMgmtEventCallback(-1, MgmtEvent::Opcode::PIN_CODE_REQUEST, bindMemberFunc(this, &DBTManager::mgmtEvPinCodeRequestCB)); + addMgmtEventCallback(-1, MgmtEvent::Opcode::USER_PASSKEY_REQUEST, bindMemberFunc(this, &DBTManager::mgmtEvUserPasskeyRequestCB)); + } PERF_TS_TD("DBTManager::open.ok"); return; } @@ -699,84 +709,84 @@ void DBTManager::clearAllMgmtEventCallbacks() { } bool DBTManager::mgmtEvClassOfDeviceChangedCB(std::shared_ptr<MgmtEvent> e) { - DBG_PRINT("DBTManager::EventCB:ClassOfDeviceChanged: %s", e->toString().c_str()); + PLAIN_PRINT("DBTManager::EventCB:ClassOfDeviceChanged: %s", e->toString().c_str()); (void)e; return true; } bool DBTManager::mgmtEvDeviceDiscoveringCB(std::shared_ptr<MgmtEvent> e) { - DBG_PRINT("DBTManager::EventCB:DeviceDiscovering: %s", e->toString().c_str()); + PLAIN_PRINT("DBTManager::EventCB:DeviceDiscovering: %s", e->toString().c_str()); const MgmtEvtDiscovering &event = *static_cast<const MgmtEvtDiscovering *>(e.get()); (void)event; return true; } bool DBTManager::mgmtEvDeviceFoundCB(std::shared_ptr<MgmtEvent> e) { - DBG_PRINT("DBTManager::EventCB:DeviceFound: %s", e->toString().c_str()); + PLAIN_PRINT("DBTManager::EventCB:DeviceFound: %s", e->toString().c_str()); const MgmtEvtDeviceFound &event = *static_cast<const MgmtEvtDeviceFound *>(e.get()); (void)event; return true; } bool DBTManager::mgmtEvDeviceDisconnectedCB(std::shared_ptr<MgmtEvent> e) { - DBG_PRINT("DBTManager::EventCB:DeviceDisconnected: %s", e->toString().c_str()); + PLAIN_PRINT("DBTManager::EventCB:DeviceDisconnected: %s", e->toString().c_str()); const MgmtEvtDeviceDisconnected &event = *static_cast<const MgmtEvtDeviceDisconnected *>(e.get()); (void)event; return true; } bool DBTManager::mgmtEvDeviceConnectedCB(std::shared_ptr<MgmtEvent> e) { - DBG_PRINT("DBTManager::EventCB:DeviceConnected: %s", e->toString().c_str()); + PLAIN_PRINT("DBTManager::EventCB:DeviceConnected: %s", e->toString().c_str()); const MgmtEvtDeviceConnected &event = *static_cast<const MgmtEvtDeviceConnected *>(e.get()); (void)event; return true; } bool DBTManager::mgmtEvConnectFailedCB(std::shared_ptr<MgmtEvent> e) { - DBG_PRINT("DBTManager::EventCB:ConnectFailed: %s", e->toString().c_str()); + PLAIN_PRINT("DBTManager::EventCB:ConnectFailed: %s", e->toString().c_str()); const MgmtEvtDeviceConnectFailed &event = *static_cast<const MgmtEvtDeviceConnectFailed *>(e.get()); (void)event; return true; } bool DBTManager::mgmtEvDeviceBlockedCB(std::shared_ptr<MgmtEvent> e) { - DBG_PRINT("DBTManager::EventCB:DeviceBlocked: %s", e->toString().c_str()); + PLAIN_PRINT("DBTManager::EventCB:DeviceBlocked: %s", e->toString().c_str()); const MgmtEvtDeviceBlocked &event = *static_cast<const MgmtEvtDeviceBlocked *>(e.get()); (void)event; return true; } bool DBTManager::mgmtEvDeviceUnblockedCB(std::shared_ptr<MgmtEvent> e) { - DBG_PRINT("DBTManager::EventCB:DeviceUnblocked: %s", e->toString().c_str()); + PLAIN_PRINT("DBTManager::EventCB:DeviceUnblocked: %s", e->toString().c_str()); const MgmtEvtDeviceUnblocked &event = *static_cast<const MgmtEvtDeviceUnblocked *>(e.get()); (void)event; return true; } bool DBTManager::mgmtEvDeviceUnpairedCB(std::shared_ptr<MgmtEvent> e) { - DBG_PRINT("DBTManager::EventCB:DeviceUnpaired: %s", e->toString().c_str()); + PLAIN_PRINT("DBTManager::EventCB:DeviceUnpaired: %s", e->toString().c_str()); const MgmtEvtDeviceUnpaired &event = *static_cast<const MgmtEvtDeviceUnpaired *>(e.get()); (void)event; return true; } bool DBTManager::mgmtEvNewConnectionParamCB(std::shared_ptr<MgmtEvent> e) { - DBG_PRINT("DBTManager::EventCB:NewConnectionParam: %s", e->toString().c_str()); + PLAIN_PRINT("DBTManager::EventCB:NewConnectionParam: %s", e->toString().c_str()); const MgmtEvtNewConnectionParam &event = *static_cast<const MgmtEvtNewConnectionParam *>(e.get()); (void)event; return true; } bool DBTManager::mgmtEvDeviceWhitelistAddedCB(std::shared_ptr<MgmtEvent> e) { - DBG_PRINT("DBTManager::EventCB:DeviceWhitelistAdded: %s", e->toString().c_str()); + PLAIN_PRINT("DBTManager::EventCB:DeviceWhitelistAdded: %s", e->toString().c_str()); const MgmtEvtDeviceWhitelistAdded &event = *static_cast<const MgmtEvtDeviceWhitelistAdded *>(e.get()); (void)event; return true; } bool DBTManager::mgmtEvDeviceWhilelistRemovedCB(std::shared_ptr<MgmtEvent> e) { - DBG_PRINT("DBTManager::EventCB:DeviceWhitelistRemoved: %s", e->toString().c_str()); + PLAIN_PRINT("DBTManager::EventCB:DeviceWhitelistRemoved: %s", e->toString().c_str()); const MgmtEvtDeviceWhitelistRemoved &event = *static_cast<const MgmtEvtDeviceWhitelistRemoved *>(e.get()); (void)event; return true; } bool DBTManager::mgmtEvPinCodeRequestCB(std::shared_ptr<MgmtEvent> e) { - DBG_PRINT("DBTManager::EventCB:PinCodeRequest: %s", e->toString().c_str()); + PLAIN_PRINT("DBTManager::EventCB:PinCodeRequest: %s", e->toString().c_str()); const MgmtEvtPinCodeRequest &event = *static_cast<const MgmtEvtPinCodeRequest *>(e.get()); (void)event; return true; } bool DBTManager::mgmtEvUserPasskeyRequestCB(std::shared_ptr<MgmtEvent> e) { - DBG_PRINT("DBTManager::EventCB:UserPasskeyRequest: %s", e->toString().c_str()); + PLAIN_PRINT("DBTManager::EventCB:UserPasskeyRequest: %s", e->toString().c_str()); const MgmtEvtUserPasskeyRequest &event = *static_cast<const MgmtEvtUserPasskeyRequest *>(e.get()); (void)event; return true; diff --git a/src/direct_bt/GATTHandler.cpp b/src/direct_bt/GATTHandler.cpp index bfd24530..83d54a56 100644 --- a/src/direct_bt/GATTHandler.cpp +++ b/src/direct_bt/GATTHandler.cpp @@ -41,7 +41,6 @@ extern "C" { // #define PERF_PRINT_ON 1 // #define PERF2_PRINT_ON 1 -// #define VERBOSE_ON 1 #include <dbt_debug.hpp> // PERF2_PRINT_ON for read/write single values @@ -53,13 +52,6 @@ extern "C" { #define PERF2_TS_TD(m) #endif -// #define GATT_PRINT_ON 1 -#ifdef GATT_PRINT_ON - #define GATT_PRINT(...) PLAIN_PRINT(__VA_ARGS__) -#else - #define GATT_PRINT(...) -#endif - #include "BasicAlgos.hpp" #include "L2CAPIoctl.hpp" @@ -197,7 +189,7 @@ void GATTHandler::l2capReaderThreadImpl() { if( AttPDUMsg::Opcode::ATT_HANDLE_VALUE_NTF == opc ) { const AttHandleValueRcv * a = static_cast<const AttHandleValueRcv*>(attPDU); - GATT_PRINT("GATTHandler: NTF: %s, listener %zd", a->toString().c_str(), characteristicListenerList.size()); + COND_PRINT(debug_data, "GATTHandler: NTF: %s, listener %zd", a->toString().c_str(), characteristicListenerList.size()); GATTCharacteristicRef decl = findCharacterisicsByValueHandle(a->getHandle()); const std::shared_ptr<TROOctets> data(new POctets(a->getValue())); const uint64_t timestamp = a->ts_creation; @@ -217,7 +209,7 @@ void GATTHandler::l2capReaderThreadImpl() { attPDU = nullptr; } else if( AttPDUMsg::Opcode::ATT_HANDLE_VALUE_IND == opc ) { const AttHandleValueRcv * a = static_cast<const AttHandleValueRcv*>(attPDU); - GATT_PRINT("GATTHandler: IND: %s, sendIndicationConfirmation %d, listener %zd", a->toString().c_str(), sendIndicationConfirmation, characteristicListenerList.size()); + COND_PRINT(debug_data, "GATTHandler: IND: %s, sendIndicationConfirmation %d, listener %zd", a->toString().c_str(), sendIndicationConfirmation, characteristicListenerList.size()); bool cfmSent = false; if( sendIndicationConfirmation ) { AttHandleValueCfm cfm; @@ -265,7 +257,8 @@ void GATTHandler::l2capReaderThreadImpl() { } GATTHandler::GATTHandler(const std::shared_ptr<DBTDevice> &device, const int replyTimeoutMS) -: wbr_device(device), deviceString(device->getAddressString()), rbuffer(number(Defaults::MAX_ATT_MTU)), +: debug_data(DBTEnv::getBooleanProperty("direct_bt.debug.gatt.data", false)), + wbr_device(device), deviceString(device->getAddressString()), rbuffer(number(Defaults::MAX_ATT_MTU)), l2cap(device, L2CAP_PSM_UNDEF, L2CAP_CID_ATT), replyTimeoutMS(replyTimeoutMS), isConnected(false), hasIOError(false), attPDURing(number(Defaults::ATTPDU_RING_CAPACITY)), @@ -511,11 +504,11 @@ bool GATTHandler::discoverPrimaryServices(std::vector<GATTServiceRef> & result) result.clear(); while(!done) { const AttReadByNTypeReq req(true /* group */, startHandle, 0xffff, groupType); - GATT_PRINT("GATT PRIM SRV discover send: %s", req.toString().c_str()); + COND_PRINT(debug_data, "GATT PRIM SRV discover send: %s", req.toString().c_str()); std::shared_ptr<const AttPDUMsg> pdu = sendWithReply(req, replyTimeoutMS); if( nullptr != pdu ) { - GATT_PRINT("GATT PRIM SRV discover recv: %s", pdu->toString().c_str()); + COND_PRINT(debug_data, "GATT PRIM SRV discover recv: %s", pdu->toString().c_str()); if( pdu->getOpcode() == AttPDUMsg::ATT_READ_BY_GROUP_TYPE_RSP ) { const AttReadByGroupTypeRsp * p = static_cast<const AttReadByGroupTypeRsp*>(pdu.get()); const int count = p->getElementCount(); @@ -528,7 +521,7 @@ bool GATTHandler::discoverPrimaryServices(std::vector<GATTServiceRef> & result) p->pdu.get_uint16(ePDUOffset + 2), // end-handle p->pdu.get_uuid( ePDUOffset + 2 + 2, uuid_t::toTypeSize(esz-2-2) ) // uuid ) ) ); - GATT_PRINT("GATT PRIM SRV discovered[%d/%d]: %s", i, count, result.at(result.size()-1)->toString().c_str()); + COND_PRINT(debug_data, "GATT PRIM SRV discovered[%d/%d]: %s", i, count, result.at(result.size()-1)->toString().c_str()); } startHandle = p->getElementEndHandle(count-1); if( startHandle < 0xffff ) { @@ -564,7 +557,7 @@ bool GATTHandler::discoverCharacteristics(GATTServiceRef & service) { */ const uuid16_t characteristicTypeReq = uuid16_t(GattAttributeType::CHARACTERISTIC); const std::lock_guard<std::recursive_mutex> lock(mtx_command); // RAII-style acquire and relinquish via destructor - GATT_PRINT("GATT discoverCharacteristics Service: %s", service->toString().c_str()); + COND_PRINT(debug_data, "GATT discoverCharacteristics Service: %s", service->toString().c_str()); PERF_TS_T0(); @@ -573,11 +566,11 @@ bool GATTHandler::discoverCharacteristics(GATTServiceRef & service) { service->characteristicList.clear(); while(!done) { const AttReadByNTypeReq req(false /* group */, handle, service->endHandle, characteristicTypeReq); - GATT_PRINT("GATT C discover send: %s", req.toString().c_str()); + COND_PRINT(debug_data, "GATT C discover send: %s", req.toString().c_str()); std::shared_ptr<const AttPDUMsg> pdu = sendWithReply(req, replyTimeoutMS); if( nullptr != pdu ) { - GATT_PRINT("GATT C discover recv: %s", pdu->toString().c_str()); + COND_PRINT(debug_data, "GATT C discover recv: %s", pdu->toString().c_str()); if( pdu->getOpcode() == AttPDUMsg::ATT_READ_BY_TYPE_RSP ) { const AttReadByTypeRsp * p = static_cast<const AttReadByTypeRsp*>(pdu.get()); const int e_count = p->getElementCount(); @@ -594,7 +587,7 @@ bool GATTHandler::discoverCharacteristics(GATTServiceRef & service) { static_cast<GATTCharacteristic::PropertyBitVal>(p->pdu.get_uint8(ePDUOffset + 2)), // Characteristics Property p->pdu.get_uint16(ePDUOffset + 2 + 1), // Characteristics Value Handle p->pdu.get_uuid(ePDUOffset + 2 + 1 + 2, uuid_t::toTypeSize(esz-2-1-2) ) ) ) ); // Characteristics Value Type UUID - GATT_PRINT("GATT C discovered[%d/%d]: %s", e_iter, e_count, service->characteristicList.at(service->characteristicList.size()-1)->toString().c_str()); + COND_PRINT(debug_data, "GATT C discovered[%d/%d]: %s", e_iter, e_count, service->characteristicList.at(service->characteristicList.size()-1)->toString().c_str()); } handle = p->getElementHandle(e_count-1); // Last Characteristic Handle if( handle < service->endHandle ) { @@ -627,7 +620,7 @@ bool GATTHandler::discoverDescriptors(GATTServiceRef & service) { * BT Core Spec v5.2: Vol 3, Part G GATT: 3.3.1 Characteristic Declaration Attribute Value * </p> */ - GATT_PRINT("GATT discoverDescriptors Service: %s", service->toString().c_str()); + COND_PRINT(debug_data, "GATT discoverDescriptors Service: %s", service->toString().c_str()); const std::lock_guard<std::recursive_mutex> lock(mtx_command); // RAII-style acquire and relinquish via destructor PERF_TS_T0(); @@ -636,7 +629,7 @@ bool GATTHandler::discoverDescriptors(GATTServiceRef & service) { for(int charIter=0; !done && charIter < charCount; charIter++ ) { GATTCharacteristicRef charDecl = service->characteristicList[charIter]; charDecl->clearDescriptors(); - GATT_PRINT("GATT discoverDescriptors Characteristic[%d/%d]: %s", charIter, charCount, charDecl->toString().c_str()); + COND_PRINT(debug_data, "GATT discoverDescriptors Characteristic[%d/%d]: %s", charIter, charCount, charDecl->toString().c_str()); uint16_t cd_handle_iter = charDecl->value_handle + 1; // Start @ Characteristic Value Handle + 1 uint16_t cd_handle_end; @@ -648,7 +641,7 @@ bool GATTHandler::discoverDescriptors(GATTServiceRef & service) { while( !done && cd_handle_iter <= cd_handle_end ) { const AttFindInfoReq req(cd_handle_iter, cd_handle_end); - GATT_PRINT("GATT CD discover send: %s", req.toString().c_str()); + COND_PRINT(debug_data, "GATT CD discover send: %s", req.toString().c_str()); std::shared_ptr<const AttPDUMsg> pdu = sendWithReply(req, replyTimeoutMS); if( nullptr == pdu ) { @@ -656,7 +649,7 @@ bool GATTHandler::discoverDescriptors(GATTServiceRef & service) { done = true; break; } - GATT_PRINT("GATT CD discover recv: %s", pdu->toString().c_str()); + COND_PRINT(debug_data, "GATT CD discover recv: %s", pdu->toString().c_str()); if( pdu->getOpcode() == AttPDUMsg::ATT_FIND_INFORMATION_RSP ) { const AttFindInfoRsp * p = static_cast<const AttFindInfoRsp*>(pdu.get()); @@ -688,7 +681,7 @@ bool GATTHandler::discoverDescriptors(GATTServiceRef & service) { charDecl->clientCharacteristicsConfigIndex = charDecl->descriptorList.size(); } charDecl->descriptorList.push_back(cd); - GATT_PRINT("GATT CD discovered[%d/%d]: %s", e_iter, e_count, cd->toString().c_str()); + COND_PRINT(debug_data, "GATT CD discovered[%d/%d]: %s", e_iter, e_count, cd->toString().c_str()); } cd_handle_iter = p->getElementHandle(e_count-1); // Last Descriptor Handle if( cd_handle_iter < cd_handle_end ) { @@ -710,12 +703,12 @@ bool GATTHandler::discoverDescriptors(GATTServiceRef & service) { } bool GATTHandler::readDescriptorValue(GATTDescriptor & desc, int expectedLength) { - GATT_PRINT("GATTHandler::readDescriptorValue expLen %d, desc %s", expectedLength, desc.toString().c_str()); + COND_PRINT(debug_data, "GATTHandler::readDescriptorValue expLen %d, desc %s", expectedLength, desc.toString().c_str()); return readValue(desc.handle, desc.value, expectedLength); } bool GATTHandler::readCharacteristicValue(const GATTCharacteristic & decl, POctets & res, int expectedLength) { - GATT_PRINT("GATTHandler::readCharacteristicValue expLen %d, decl %s", expectedLength, decl.toString().c_str()); + COND_PRINT(debug_data, "GATTHandler::readCharacteristicValue expLen %d, decl %s", expectedLength, decl.toString().c_str()); return readValue(decl.value_handle, res, expectedLength); } @@ -728,7 +721,7 @@ bool GATTHandler::readValue(const uint16_t handle, POctets & res, int expectedLe bool done=false; int offset=0; - GATT_PRINT("GATTHandler::readValue expLen %d, handle %s", expectedLength, uint16HexString(handle).c_str()); + COND_PRINT(debug_data, "GATTHandler::readValue expLen %d, handle %s", expectedLength, uint16HexString(handle).c_str()); while(!done) { if( 0 < expectedLength && expectedLength <= offset ) { @@ -741,16 +734,16 @@ bool GATTHandler::readValue(const uint16_t handle, POctets & res, int expectedLe if( 0 == offset ) { const AttReadReq req (handle); - GATT_PRINT("GATT RV send: %s", req.toString().c_str()); + COND_PRINT(debug_data, "GATT RV send: %s", req.toString().c_str()); pdu = sendWithReply(req, replyTimeoutMS); } else { const AttReadBlobReq req (handle, offset); - GATT_PRINT("GATT RV send: %s", req.toString().c_str()); + COND_PRINT(debug_data, "GATT RV send: %s", req.toString().c_str()); pdu = sendWithReply(req, replyTimeoutMS); } if( nullptr != pdu ) { - GATT_PRINT("GATT RV recv: %s", pdu->toString().c_str()); + COND_PRINT(debug_data, "GATT RV recv: %s", pdu->toString().c_str()); if( pdu->getOpcode() == AttPDUMsg::ATT_READ_RSP ) { const AttReadRsp * p = static_cast<const AttReadRsp*>(pdu.get()); const TOctetSlice & v = p->getValue(); @@ -806,18 +799,18 @@ bool GATTHandler::writeDescriptorValue(const GATTDescriptor & cd) { /* BT Core Spec v5.2: Vol 3, Part G GATT: 4.9.3 Write Characteristic Value */ /* BT Core Spec v5.2: Vol 3, Part G GATT: 4.11 Characteristic Value Indication */ /* BT Core Spec v5.2: Vol 3, Part G GATT: 4.12.3 Write Characteristic Descriptor */ - GATT_PRINT("GATTHandler::writeDesccriptorValue desc %s", cd.toString().c_str()); + COND_PRINT(debug_data, "GATTHandler::writeDesccriptorValue desc %s", cd.toString().c_str()); return writeValue(cd.handle, cd.value, true); } bool GATTHandler::writeCharacteristicValue(const GATTCharacteristic & c, const TROOctets & value) { /* BT Core Spec v5.2: Vol 3, Part G GATT: 4.9.3 Write Characteristic Value */ - GATT_PRINT("GATTHandler::writeCharacteristicValue desc %s, value %s", c.toString().c_str(), value.toString().c_str()); + COND_PRINT(debug_data, "GATTHandler::writeCharacteristicValue desc %s, value %s", c.toString().c_str(), value.toString().c_str()); return writeValue(c.value_handle, value, true); } bool GATTHandler::writeCharacteristicValueNoResp(const GATTCharacteristic & c, const TROOctets & value) { - GATT_PRINT("GATT writeCharacteristicValueNoResp decl %s, value %s", c.toString().c_str(), value.toString().c_str()); + COND_PRINT(debug_data, "GATT writeCharacteristicValueNoResp decl %s, value %s", c.toString().c_str(), value.toString().c_str()); return writeValue(c.value_handle, value, false); } @@ -837,7 +830,7 @@ bool GATTHandler::writeValue(const uint16_t handle, const TROOctets & value, con PERF2_TS_T0(); AttWriteReq req(handle, value); - GATT_PRINT("GATT WV send(resp %d): %s", expResponse, req.toString().c_str()); + COND_PRINT(debug_data, "GATT WV send(resp %d): %s", expResponse, req.toString().c_str()); if( !expResponse ) { send( req ); @@ -847,7 +840,7 @@ bool GATTHandler::writeValue(const uint16_t handle, const TROOctets & value, con bool res = false; std::shared_ptr<const AttPDUMsg> pdu = sendWithReply(req, replyTimeoutMS); if( nullptr != pdu ) { - GATT_PRINT("GATT WV recv: %s", pdu->toString().c_str()); + COND_PRINT(debug_data, "GATT WV recv: %s", pdu->toString().c_str()); if( pdu->getOpcode() == AttPDUMsg::ATT_WRITE_RSP ) { // OK res = true; @@ -870,7 +863,7 @@ bool GATTHandler::configNotificationIndication(GATTDescriptor & cccd, const bool } /* BT Core Spec v5.2: Vol 3, Part G GATT: 3.3.3.3 Client Characteristic Configuration */ const uint16_t ccc_value = enableNotification | ( enableIndication << 1 ); - GATT_PRINT("GATTHandler::configNotificationIndication decl %s, enableNotification %d, enableIndication %d", + COND_PRINT(debug_data, "GATTHandler::configNotificationIndication decl %s, enableNotification %d, enableIndication %d", cccd.toString().c_str(), enableNotification, enableIndication); cccd.value.resize(2, 2); cccd.value.put_uint16(0, ccc_value); diff --git a/src/direct_bt/HCIHandler.cpp b/src/direct_bt/HCIHandler.cpp index 48b7d08c..30e85408 100644 --- a/src/direct_bt/HCIHandler.cpp +++ b/src/direct_bt/HCIHandler.cpp @@ -33,7 +33,6 @@ #include <algorithm> // #define PERF_PRINT_ON 1 -// #define VERBOSE_ON 1 #include <dbt_debug.hpp> #include "DBTEnv.hpp" @@ -265,17 +264,17 @@ void HCIHandler::hciReaderThreadImpl() { const HCIMetaEventType mec = event->getMetaEventType(); if( HCIMetaEventType::INVALID != mec && !filter_test_metaev(mec) ) { // DROP - DBG_PRINT("HCIHandler-IO RECV Drop (meta filter) %s", event->toString().c_str()); + COND_PRINT(debug_event, "HCIHandler-IO RECV Drop (meta filter) %s", event->toString().c_str()); continue; // next packet } if( event->isEvent(HCIEventType::CMD_STATUS) || event->isEvent(HCIEventType::CMD_COMPLETE) ) { - DBG_PRINT("HCIHandler-IO RECV (CMD) %s", event->toString().c_str()); + COND_PRINT(debug_event, "HCIHandler-IO RECV (CMD) %s", event->toString().c_str()); if( hciEventRing.isFull() ) { - const int dropCount = hciEventRing.capacity()/2; + const int dropCount = hciEventRing.capacity()/4; hciEventRing.drop(dropCount); - INFO_PRINT("HCIHandler-IO RECV Drop (%d oldest elements of %d capacity, ring full)", dropCount, hciEventRing.capacity()); + WARN_PRINT("HCIHandler-IO RECV Drop (%d oldest elements of %d capacity, ring full)", dropCount, hciEventRing.capacity()); } hciEventRing.putBlocking( event ); } else if( event->isMetaEvent(HCIMetaEventType::LE_ADVERTISING_REPORT) ) { @@ -283,7 +282,7 @@ void HCIHandler::hciReaderThreadImpl() { std::vector<std::shared_ptr<EInfoReport>> eirlist = EInfoReport::read_ad_reports(event->getParam(), event->getParamSize()); int i=0; for_each_idx(eirlist, [&](std::shared_ptr<EInfoReport> &eir) { - // DBG_PRINT("HCIHandler-IO RECV (AD EIR) %s", eir->toString().c_str()); + // COND_PRINT(debug_event, "HCIHandler-IO RECV (AD EIR) %s", eir->toString().c_str()); std::shared_ptr<MgmtEvent> mevent( new MgmtEvtDeviceFound(dev_id, eir) ); sendMgmtEvent( mevent ); i++; @@ -292,10 +291,10 @@ void HCIHandler::hciReaderThreadImpl() { // issue a callback for the translated event std::shared_ptr<MgmtEvent> mevent = translate(event); if( nullptr != mevent ) { - DBG_PRINT("HCIHandler-IO RECV (CB) %s", event->toString().c_str()); + COND_PRINT(debug_event, "HCIHandler-IO RECV (CB) %s", event->toString().c_str()); sendMgmtEvent( mevent ); } else { - DBG_PRINT("HCIHandler-IO RECV Drop (no translation) %s", event->toString().c_str()); + COND_PRINT(debug_event, "HCIHandler-IO RECV Drop (no translation) %s", event->toString().c_str()); } } } else if( ETIMEDOUT != errno && !hciReaderShallStop ) { // expected exits @@ -323,14 +322,14 @@ void HCIHandler::sendMgmtEvent(std::shared_ptr<MgmtEvent> event) { invokeCount++; } } - // DBG_PRINT("HCIHandler::sendMgmtEvent: Event %s -> %d/%zd callbacks", event->toString().c_str(), invokeCount, mgmtEventCallbackList.size()); + COND_PRINT(debug_event, "HCIHandler::sendMgmtEvent: Event %s -> %d/%zd callbacks", event->toString().c_str(), invokeCount, mgmtEventCallbackList.size()); (void)invokeCount; } bool HCIHandler::sendCommand(HCICommand &req) { const std::lock_guard<std::recursive_mutex> lock(comm.mutex()); // RAII-style acquire and relinquish via destructor - DBG_PRINT("HCIHandler-IO SENT %s", req.toString().c_str()); + COND_PRINT(debug_event, "HCIHandler-IO SENT %s", req.toString().c_str()); TROOctets & pdu = req.getPDU(); if ( comm.write( pdu.get_ptr(), pdu.getSize() ) < 0 ) { @@ -413,11 +412,12 @@ exit: HCIHandler::HCIHandler(const BTMode btMode, const uint16_t dev_id, const int cmdStatusReplyTimeoutMS, const int cmdCompleteReplyTimeoutMS) -:btMode(btMode), dev_id(dev_id), rbuffer(HCI_MAX_MTU), - comm(dev_id, HCI_CHANNEL_RAW, Defaults::HCI_READER_THREAD_POLL_TIMEOUT), - cmdStatusReplyTimeoutMS(cmdStatusReplyTimeoutMS), - cmdCompleteReplyTimeoutMS(cmdCompleteReplyTimeoutMS), - hciEventRing(HCI_EVT_RING_CAPACITY), hciReaderRunning(false), hciReaderShallStop(false) +: debug_event(DBTEnv::getBooleanProperty("direct_bt.debug.hci.event", false)), + btMode(btMode), dev_id(dev_id), rbuffer(HCI_MAX_MTU), + comm(dev_id, HCI_CHANNEL_RAW, Defaults::HCI_READER_THREAD_POLL_TIMEOUT), + cmdStatusReplyTimeoutMS(cmdStatusReplyTimeoutMS), + cmdCompleteReplyTimeoutMS(cmdCompleteReplyTimeoutMS), + hciEventRing(HCI_EVT_RING_CAPACITY), hciReaderRunning(false), hciReaderShallStop(false) { INFO_PRINT("HCIHandler.ctor: pid %d", HCIHandler::pidSelf); if( !comm.isOpen() ) { |