diff options
author | Sven Gothel <[email protected]> | 2020-09-18 23:55:25 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2020-09-18 23:55:25 +0200 |
commit | 55f384a73bf6872cd10ed7bd2355c33bb22eb268 (patch) | |
tree | d264120a0eb2f770b17c770e4e872b331d87685d /src | |
parent | 13da0b2decc31da1a7b4b9081230623e89057e8c (diff) |
dbt_debug: INFO_PRINT(..) -> WORDY_PRINT(..) cond DBTEnv::VERBOSE, add uncond INFO_PRINT(..)
Turns out INFO_PRINT(..) is confusing, as it was not clear that it is conditional on DBTEnv::VERBOSE.
Hence rename it to the short English from for Latin 'verbosus',
and hence hinting it is conditional on DBTEnv::VERBOSE.
INFO_PRINT(..) renamed to WORDY_PRINT(..), using prefix 'Wordy:' (Verbose is just too long)
Add unconditional INFO_PRINT(..) for plain informal messages.
Hope this clears up the confusion.
Hint: I was looking for an INFO_PRINT(..) ouput myself ;-)
Diffstat (limited to 'src')
-rw-r--r-- | src/direct_bt/DBTAdapter.cpp | 6 | ||||
-rw-r--r-- | src/direct_bt/DBTDevice.cpp | 8 | ||||
-rw-r--r-- | src/direct_bt/DBTManager.cpp | 12 | ||||
-rw-r--r-- | src/direct_bt/GATTHandler.cpp | 4 | ||||
-rw-r--r-- | src/direct_bt/HCIHandler.cpp | 16 | ||||
-rw-r--r-- | src/direct_bt/L2CAPComm.cpp | 2 | ||||
-rw-r--r-- | src/direct_bt/dbt_debug.cpp | 14 |
7 files changed, 36 insertions, 26 deletions
diff --git a/src/direct_bt/DBTAdapter.cpp b/src/direct_bt/DBTAdapter.cpp index f38682e8..08c78ed0 100644 --- a/src/direct_bt/DBTAdapter.cpp +++ b/src/direct_bt/DBTAdapter.cpp @@ -862,7 +862,7 @@ bool DBTAdapter::mgmtEvConnectFailedHCI(std::shared_ptr<MgmtEvent> e) { }); removeDiscoveredDevice(*device); // ensure device will cause a deviceFound event after disconnect } else { - INFO_PRINT("DBTAdapter::EventHCI:DeviceDisconnected(dev_id %d): %s\n -> Device not tracked", + WORDY_PRINT("DBTAdapter::EventHCI:DeviceDisconnected(dev_id %d): %s\n -> Device not tracked", dev_id, event.toString().c_str()); } return true; @@ -875,7 +875,7 @@ bool DBTAdapter::mgmtEvDeviceDisconnectedHCI(std::shared_ptr<MgmtEvent> e) { std::shared_ptr<DBTDevice> device = findConnectedDevice(event.getAddress(), event.getAddressType()); if( nullptr != device ) { if( device->getConnectionHandle() != event.getHCIHandle() ) { - INFO_PRINT("DBTAdapter::EventHCI:DeviceDisconnected(dev_id %d): ConnHandle mismatch %s\n -> %s", + WORDY_PRINT("DBTAdapter::EventHCI:DeviceDisconnected(dev_id %d): ConnHandle mismatch %s\n -> %s", dev_id, event.toString().c_str(), device->toString().c_str()); return true; } @@ -901,7 +901,7 @@ bool DBTAdapter::mgmtEvDeviceDisconnectedHCI(std::shared_ptr<MgmtEvent> e) { }); removeDiscoveredDevice(*device); // ensure device will cause a deviceFound event after disconnect } else { - INFO_PRINT("DBTAdapter::EventHCI:DeviceDisconnected(dev_id %d): %s\n -> Device not tracked", + WORDY_PRINT("DBTAdapter::EventHCI:DeviceDisconnected(dev_id %d): %s\n -> Device not tracked", dev_id, event.toString().c_str()); } return true; diff --git a/src/direct_bt/DBTDevice.cpp b/src/direct_bt/DBTDevice.cpp index 6753914e..523b5040 100644 --- a/src/direct_bt/DBTDevice.cpp +++ b/src/direct_bt/DBTDevice.cpp @@ -323,7 +323,7 @@ HCIStatusCode DBTDevice::connectLE(uint16_t le_scan_interval, uint16_t le_scan_w allowDisconnect = true; #if 0 if( HCIStatusCode::CONNECTION_ALREADY_EXISTS == status ) { - INFO_PRINT("DBTDevice::connectLE: Connection already exists: status 0x%2.2X (%s) on %s", + WORDY_PRINT("DBTDevice::connectLE: Connection already exists: status 0x%2.2X (%s) on %s", static_cast<uint8_t>(status), getHCIStatusCodeString(status).c_str(), toString().c_str()); std::shared_ptr<DBTDevice> sharedInstance = getSharedInstance(); if( nullptr == sharedInstance ) { @@ -428,7 +428,7 @@ HCIStatusCode DBTDevice::disconnect(const bool fromDisconnectCB, const bool ioEr // Lock to avoid other threads connecting while disconnecting const std::lock_guard<std::recursive_mutex> lock_conn(mtx_connect); // RAII-style acquire and relinquish via destructor - INFO_PRINT("DBTDevice::disconnect: Start: isConnected %d/%d, fromDisconnectCB %d, ioError %d, reason 0x%X (%s), gattHandler %d, hciConnHandle %s", + WORDY_PRINT("DBTDevice::disconnect: Start: isConnected %d/%d, fromDisconnectCB %d, ioError %d, reason 0x%X (%s), gattHandler %d, hciConnHandle %s", allowDisconnect.load(), isConnected.load(), fromDisconnectCB, ioErrorCause, static_cast<uint8_t>(reason), getHCIStatusCodeString(reason).c_str(), (nullptr != gattHandler), uint16HexString(hciConnHandle).c_str()); @@ -472,7 +472,7 @@ HCIStatusCode DBTDevice::disconnect(const bool fromDisconnectCB, const bool ioEr } exit: - INFO_PRINT("DBTDevice::disconnect: End: status %s, handle 0x%X, isConnected %d/%d, fromDisconnectCB %d, ioError %d on %s", + WORDY_PRINT("DBTDevice::disconnect: End: status %s, handle 0x%X, isConnected %d/%d, fromDisconnectCB %d, ioError %d on %s", getHCIStatusCodeString(res).c_str(), hciConnHandle.load(), allowDisconnect.load(), isConnected.load(), fromDisconnectCB, ioErrorCause, toString(false).c_str()); @@ -513,7 +513,7 @@ std::shared_ptr<GATTHandler> DBTDevice::getGATTHandler() { return gattHandler; } -std::vector<std::shared_ptr<GATTService>> DBTDevice::getGATTServices() { +std::vector<std::shared_ptr<GATTService>> DBTDevice::getGATTServices() noexcept { const std::lock_guard<std::recursive_mutex> lock_conn(mtx_connect); // covers gattHandler dtor via disconnect(..) try { if( nullptr == connectGATT() ) { diff --git a/src/direct_bt/DBTManager.cpp b/src/direct_bt/DBTManager.cpp index 268ebacf..67e63cd2 100644 --- a/src/direct_bt/DBTManager.cpp +++ b/src/direct_bt/DBTManager.cpp @@ -110,7 +110,7 @@ void DBTManager::mgmtReaderThreadImpl() noexcept { } } - INFO_PRINT("DBTManager::reader: Ended. Ring has %d entries flushed", mgmtEventRing.getSize()); + WORDY_PRINT("DBTManager::reader: Ended. Ring has %d entries flushed", mgmtEventRing.getSize()); mgmtReaderRunning = false; mgmtEventRing.clear(); } @@ -138,7 +138,7 @@ void DBTManager::sendMgmtEvent(std::shared_ptr<MgmtEvent> event) noexcept { static void mgmthandler_sigaction(int sig, siginfo_t *info, void *ucontext) noexcept { bool pidMatch = info->si_pid == DBTManager::pidSelf; - INFO_PRINT("DBTManager.sigaction: sig %d, info[code %d, errno %d, signo %d, pid %d, uid %d, fd %d], pid-self %d (match %d)", + WORDY_PRINT("DBTManager.sigaction: sig %d, info[code %d, errno %d, signo %d, pid %d, uid %d, fd %d], pid-self %d (match %d)", sig, info->si_code, info->si_errno, info->si_signo, info->si_pid, info->si_uid, info->si_fd, DBTManager::pidSelf, pidMatch); @@ -293,7 +293,7 @@ DBTManager::DBTManager(const BTMode _defaultBTMode) noexcept rbuffer(ClientMaxMTU), comm(HCI_DEV_NONE, HCI_CHANNEL_CONTROL), mgmtEventRing(env.MGMT_EVT_RING_CAPACITY), mgmtReaderRunning(false), mgmtReaderShallStop(false) { - INFO_PRINT("DBTManager.ctor: pid %d", DBTManager::pidSelf); + WORDY_PRINT("DBTManager.ctor: pid %d", DBTManager::pidSelf); if( !comm.isOpen() ) { ERR_PRINT("DBTManager::open: Could not open mgmt control channel"); return; @@ -334,7 +334,7 @@ DBTManager::DBTManager(const BTMode _defaultBTMode) noexcept const uint8_t *data = res->getData(); const uint8_t version = data[0]; const uint16_t revision = get_uint16(data, 1, true /* littleEndian */); - INFO_PRINT("Bluetooth version %d.%d", version, revision); + WORDY_PRINT("Bluetooth version %d.%d", version, revision); if( version < 1 ) { ERR_PRINT("Bluetooth version >= 1.0 required"); goto fail; @@ -351,7 +351,7 @@ DBTManager::DBTManager(const BTMode _defaultBTMode) noexcept const uint8_t *data = res->getData(); const uint16_t num_commands = get_uint16(data, 0, true /* littleEndian */); const uint16_t num_events = get_uint16(data, 2, true /* littleEndian */); - INFO_PRINT("Bluetooth %d commands, %d events", num_commands, num_events); + WORDY_PRINT("Bluetooth %d commands, %d events", num_commands, num_events); #ifdef VERBOSE_ON const int expDataSize = 4 + num_commands * 2 + num_events * 2; if( res->getDataSize() >= expDataSize ) { @@ -382,7 +382,7 @@ next1: } const uint8_t *data = res->getData(); const uint16_t num_adapter = get_uint16(data, 0, true /* littleEndian */); - INFO_PRINT("Bluetooth %d adapter", num_adapter); + WORDY_PRINT("Bluetooth %d adapter", num_adapter); const int expDataSize = 2 + num_adapter * 2; if( res->getDataSize() < expDataSize ) { diff --git a/src/direct_bt/GATTHandler.cpp b/src/direct_bt/GATTHandler.cpp index 0f374cec..44bf7867 100644 --- a/src/direct_bt/GATTHandler.cpp +++ b/src/direct_bt/GATTHandler.cpp @@ -261,7 +261,7 @@ void GATTHandler::l2capReaderThreadImpl() { } } - INFO_PRINT("l2capReaderThreadImpl Ended. Ring has %d entries flushed", attPDURing.getSize()); + WORDY_PRINT("l2capReaderThreadImpl Ended. Ring has %d entries flushed", attPDURing.getSize()); l2capReaderRunning = false; attPDURing.clear(); disconnect(true /* disconnectDevice */, ioErrorCause); @@ -882,7 +882,7 @@ bool GATTHandler::configNotificationIndication(GATTDescriptor & cccd, const bool } catch (BluetoothException & bte) { if( !enableNotification && !enableIndication ) { // OK to have lost connection @ disable - INFO_PRINT("GATTHandler::configNotificationIndication(disable) on %s caught exception: %s", deviceString.c_str(), bte.what()); + WORDY_PRINT("GATTHandler::configNotificationIndication(disable) on %s caught exception: %s", deviceString.c_str(), bte.what()); return false; } else { throw; // re-throw current exception diff --git a/src/direct_bt/HCIHandler.cpp b/src/direct_bt/HCIHandler.cpp index 16ca8133..4dceda1e 100644 --- a/src/direct_bt/HCIHandler.cpp +++ b/src/direct_bt/HCIHandler.cpp @@ -78,7 +78,7 @@ HCIConnectionRef HCIHandler::addOrUpdateTrackerConnection(const EUI48 & address, HCIConnectionRef conn = *it; if ( conn->equals(address, addrType) ) { // reuse same entry - INFO_PRINT("HCIHandler::addTrackerConnection: address[%s, %s], handle %s: reuse entry %s", + WORDY_PRINT("HCIHandler::addTrackerConnection: address[%s, %s], handle %s: reuse entry %s", address.toString().c_str(), getBDAddressTypeString(addrType).c_str(), uint16HexString(handle).c_str(), conn->toString().c_str()); // Overwrite tracked connection handle with given _valid_ handle only, i.e. non zero! if( 0 != handle ) { @@ -220,7 +220,7 @@ std::shared_ptr<MgmtEvent> HCIHandler::translate(std::shared_ptr<HCIEvent> ev) n } HCIConnectionRef conn = removeTrackerConnection(ev_cc->handle); if( nullptr == conn ) { - INFO_PRINT("HCIHandler::translate(reader): DISCONN_COMPLETE: Not tracked handle %s: %s", + WORDY_PRINT("HCIHandler::translate(reader): DISCONN_COMPLETE: Not tracked handle %s: %s", uint16HexString(ev_cc->handle).c_str(), ev->toString().c_str()); return nullptr; } else { @@ -259,9 +259,9 @@ void HCIHandler::hciReaderThreadImpl() noexcept { len = comm.read(rbuffer.get_wptr(), rbuffer.getSize(), env.HCI_READER_THREAD_POLL_TIMEOUT); if( 0 < len ) { - const uint16_t paramSize = len >= 3 ? rbuffer.get_uint8(2) : 0; + const uint16_t paramSize = len >= number(HCIConstU8::EVENT_HDR_SIZE) ? rbuffer.get_uint8(2) : 0; if( len < number(HCIConstU8::EVENT_HDR_SIZE) + paramSize ) { - WARN_PRINT("HCIHandler::reader: length mismatch %d < %d + %d", + WARN_PRINT("HCIHandler::reader: length mismatch %d < EVENT_HDR_SIZE(%d) + %d", len, number(HCIConstU8::EVENT_HDR_SIZE), paramSize); continue; // discard data } @@ -312,7 +312,7 @@ void HCIHandler::hciReaderThreadImpl() noexcept { ERR_PRINT("HCIHandler::reader: HCIComm read error"); } } - INFO_PRINT("HCIHandler::reader: Ended. Ring has %d entries flushed", hciEventRing.getSize()); + WORDY_PRINT("HCIHandler::reader: Ended. Ring has %d entries flushed", hciEventRing.getSize()); hciReaderRunning = false; hciEventRing.clear(); } @@ -426,7 +426,7 @@ HCIHandler::HCIHandler(const BTMode btMode, const uint16_t dev_id) noexcept comm(dev_id, HCI_CHANNEL_RAW), hciEventRing(env.HCI_EVT_RING_CAPACITY), hciReaderRunning(false), hciReaderShallStop(false) { - INFO_PRINT("HCIHandler.ctor: pid %d", HCIHandler::pidSelf); + WORDY_PRINT("HCIHandler.ctor: pid %d", HCIHandler::pidSelf); if( !comm.isOpen() ) { ERR_PRINT("HCIHandler::ctor: Could not open hci control channel"); return; @@ -510,7 +510,7 @@ HCIHandler::HCIHandler(const BTMode btMode, const uint16_t dev_id) noexcept ERR_PRINT("HCIHandler::ctor: failed READ_LOCAL_VERSION: 0x%x (%s)", number(status), getHCIStatusCodeString(status).c_str()); goto fail; } - INFO_PRINT("HCIHandler: LOCAL_VERSION: %d (rev %d), manuf 0x%x, lmp %d (subver %d)", + WORDY_PRINT("HCIHandler: LOCAL_VERSION: %d (rev %d), manuf 0x%x, lmp %d (subver %d)", ev_lv->hci_ver, le_to_cpu(ev_lv->hci_rev), le_to_cpu(ev_lv->manufacturer), ev_lv->lmp_ver, le_to_cpu(ev_lv->lmp_subver)); } @@ -689,7 +689,7 @@ HCIStatusCode HCIHandler::disconnect(const bool ioErrorCause, if( nullptr == conn ) { // disconnect called w/o being connected through this HCIHandler conn = addOrUpdateTrackerConnection(peer_bdaddr, peer_mac_type, conn_handle); - INFO_PRINT("HCIHandler::disconnect: Not tracked address[%s, %s], added %s", + WORDY_PRINT("HCIHandler::disconnect: Not tracked address[%s, %s], added %s", peer_bdaddr.toString().c_str(), getBDAddressTypeString(peer_mac_type).c_str(), conn->toString().c_str()); } else if( !conn->equals(peer_bdaddr, peer_mac_type) ) { diff --git a/src/direct_bt/L2CAPComm.cpp b/src/direct_bt/L2CAPComm.cpp index a28d04a9..86367408 100644 --- a/src/direct_bt/L2CAPComm.cpp +++ b/src/direct_bt/L2CAPComm.cpp @@ -135,7 +135,7 @@ L2CAPComm::L2CAPComm(std::shared_ptr<DBTDevice> device, const uint16_t psm, cons } else if( ETIMEDOUT == errno ) { to_retry_count++; if( to_retry_count < number(Defaults::L2CAP_CONNECT_MAX_RETRY) ) { - INFO_PRINT("L2CAPComm::ctor: Connect timeout, retry %d", to_retry_count); + WORDY_PRINT("L2CAPComm::ctor: Connect timeout, retry %d", to_retry_count); continue; } else { ERR_PRINT("L2CAPComm::ctor: Connect timeout, retried %d", to_retry_count); diff --git a/src/direct_bt/dbt_debug.cpp b/src/direct_bt/dbt_debug.cpp index 62e08cb1..cc16d354 100644 --- a/src/direct_bt/dbt_debug.cpp +++ b/src/direct_bt/dbt_debug.cpp @@ -41,9 +41,9 @@ void direct_bt::DBG_PRINT(const char * format, ...) noexcept { } } -void direct_bt::INFO_PRINT(const char * format, ...) noexcept { +void direct_bt::WORDY_PRINT(const char * format, ...) noexcept { if(direct_bt::DBTEnv::get().VERBOSE) { - fprintf(stderr, "[%'9" PRIu64 "] Info: ", DBTEnv::getElapsedMillisecond()); + fprintf(stderr, "[%'9" PRIu64 "] Wordy: ", DBTEnv::getElapsedMillisecond()); va_list args; va_start (args, format); vfprintf(stderr, format, args); @@ -87,6 +87,16 @@ void direct_bt::WARN_PRINT2(const char *file, const int line, const char * forma fflush(stderr); } +void direct_bt::INFO_PRINT(const char * format, ...) noexcept { + fprintf(stderr, "[%'9" PRIu64 "] Info: ", DBTEnv::getElapsedMillisecond()); + va_list args; + va_start (args, format); + vfprintf(stderr, format, args); + va_end (args); + fprintf(stderr, "\n"); + fflush(stderr); +} + void direct_bt::PLAIN_PRINT(const char * format, ...) noexcept { fprintf(stderr, "[%'9" PRIu64 "] ", DBTEnv::getElapsedMillisecond()); va_list args; |