From 14547aa1c8877a620521cee088f832a93805562d Mon Sep 17 00:00:00 2001 From: Timur Pocheptsov Date: Wed, 17 Dec 2014 12:44:53 +0100 Subject: QBluetoothTransferReply - cleanup (OS X) Q_FUNC_INFO in messages/(Q)asserts. Change-Id: I12285bf97ac766964b656090980858f3fd5de2da Reviewed-by: Alex Blasche --- src/bluetooth/osx/osxbtobexsession.mm | 90 +++++++++++++--------------- src/bluetooth/osx/osxbtobexsession_p.h | 7 +-- src/bluetooth/qbluetoothtransferreply_osx.mm | 37 +++++------- 3 files changed, 58 insertions(+), 76 deletions(-) diff --git a/src/bluetooth/osx/osxbtobexsession.mm b/src/bluetooth/osx/osxbtobexsession.mm index 8a5feb32..0bed6af2 100644 --- a/src/bluetooth/osx/osxbtobexsession.mm +++ b/src/bluetooth/osx/osxbtobexsession.mm @@ -48,10 +48,6 @@ #include #include -// Import, since it's Obj-C headers: -#import -#import - #include #include #include @@ -91,7 +87,7 @@ enum { quint32 extract_uint32(const uint8_t *bytes) { // Four byte value, high byte first. - Q_ASSERT_X(bytes, "extract_uint32", "invalid input data (null)"); + Q_ASSERT_X(bytes, Q_FUNC_INFO, "invalid input data (null)"); uint32_t value = uint32_t(); std::copy(bytes, bytes + sizeof value, reinterpret_cast(&value)); @@ -102,7 +98,7 @@ quint32 extract_uint32(const uint8_t *bytes) quint16 extract_uint16(const uint8_t *bytes) { // Two byte value, high byte first. - Q_ASSERT_X(bytes, "extract_uint16", "invalid input data (null)"); + Q_ASSERT_X(bytes, Q_FUNC_INFO, "invalid input data (null)"); uint16_t value = uint16_t(); std::copy(bytes, bytes + sizeof value, reinterpret_cast(&value)); @@ -140,8 +136,8 @@ QList qt_bluetooth_headers(const uint8_t *data, std::size_t length) // 3. 10 A single byte value. // 4. 11 A four byte value, sent high byte first. - Q_ASSERT_X(data, "qt_bluetooth_headers", "invalid data (null)"); - Q_ASSERT_X(length >= 2, "qt_bluetooth_headers", "invalid data length"); + Q_ASSERT_X(data, Q_FUNC_INFO, "invalid data (null)"); + Q_ASSERT_X(length >= 2, Q_FUNC_INFO, "invalid data length"); Q_UNUSED(data) Q_UNUSED(length) @@ -209,7 +205,7 @@ QList qt_bluetooth_headers(const uint8_t *data, std::size_t length) break; } default: - qCWarning(QT_BT_OSX) << "qt_bluetooth_headers(), invalid header format"; + qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "invalid header format"; return empty; } @@ -315,7 +311,7 @@ ObjCStrongReference next_data_chunk(QIODevice &inputStream, IOBlu NSUInteger headersLength, bool &isLast) { // Work only for OBEX put (we request a specific payload length). - Q_ASSERT_X(session, "next_data_chunk", "invalid OBEX session (nil)"); + Q_ASSERT_X(session, Q_FUNC_INFO, "invalid OBEX session (nil)"); const OBEXMaxPacketLength packetSize = [session getAvailableCommandPayloadLength:kOBEXOpCodePut]; if (!packetSize || headersLength >= packetSize) @@ -345,7 +341,7 @@ ObjCStrongReference next_data_chunk(QIODevice &inputStream, IOBlu bool check_connect_event(const OBEXSessionEvent *e, OBEXError &error, OBEXOpCode &response) { - Q_ASSERT_X(e, "check_connect_event", "invalid event (null)"); + Q_ASSERT_X(e, Q_FUNC_INFO, "invalid event (null)"); // This function tries to extract either an error code or a // server response code. "Good" event has type connect command respond @@ -364,7 +360,7 @@ bool check_connect_event(const OBEXSessionEvent *e, OBEXError &error, OBEXOpCode response = e->u.connectCommandResponseData.serverResponseOpCode; return response == kOBEXResponseCodeSuccessWithFinalBit; } else { - qCWarning(QT_BT_OSX) << "check_connect_event, unexpected event type"; + qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "unexpected event type"; error = kOBEXGeneralError; return false; } @@ -372,7 +368,7 @@ bool check_connect_event(const OBEXSessionEvent *e, OBEXError &error, OBEXOpCode bool check_put_event(const OBEXSessionEvent *e, OBEXError &error, OBEXOpCode &response) { - Q_ASSERT_X(e, "check_put_event", "invalid event (null)"); + Q_ASSERT_X(e, Q_FUNC_INFO, "invalid event (null)"); // See the comments above. @@ -384,7 +380,7 @@ bool check_put_event(const OBEXSessionEvent *e, OBEXError &error, OBEXOpCode &re return response == kOBEXResponseCodeContinueWithFinalBit || response == kOBEXResponseCodeSuccessWithFinalBit; } else { - qCWarning(QT_BT_OSX) << "check_put_event, unexpected event type"; + qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "unexpected event type"; error = kOBEXGeneralError; return false; } @@ -392,7 +388,7 @@ bool check_put_event(const OBEXSessionEvent *e, OBEXError &error, OBEXOpCode &re bool check_abort_event(const OBEXSessionEvent *e, OBEXError &error, OBEXOpCode &response) { - Q_ASSERT_X(e, "check_abort_event", "invalid event (null)"); + Q_ASSERT_X(e, Q_FUNC_INFO, "invalid event (null)"); if (e->type == kOBEXSessionEventTypeError) { error = e->u.errorData.error; @@ -401,7 +397,7 @@ bool check_abort_event(const OBEXSessionEvent *e, OBEXError &error, OBEXOpCode & response = e->u.abortCommandResponseData.serverResponseOpCode; return response == kOBEXResponseCodeSuccessWithFinalBit; } else { - qCWarning(QT_BT_OSX) << "check_abort_event, unexpected event type"; + qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "unexpected event type"; return false; } } @@ -440,12 +436,9 @@ using namespace QT_NAMESPACE; - (id)initWithDelegate:(QT_PREPEND_NAMESPACE(OSXBluetooth::OBEXSessionDelegate) *)aDelegate remoteDevice:(const QBluetoothAddress &)deviceAddress channelID:(quint16)port { - Q_ASSERT_X(aDelegate, "-initWithDelegate:remoteDevice:channelID:", - "invalid delegate (null)"); - Q_ASSERT_X(!deviceAddress.isNull(), "-initWithDelegate:remoteDevice:channelID:", - "invalid remote device address"); - Q_ASSERT_X(port, "-initWithDelegate:remoteDevice:channelID:", - "invalid port (0)"); + Q_ASSERT_X(aDelegate, Q_FUNC_INFO, "invalid delegate (null)"); + Q_ASSERT_X(!deviceAddress.isNull(), Q_FUNC_INFO, "invalid remote device address"); + Q_ASSERT_X(port, Q_FUNC_INFO, "invalid port (0)"); if (self = [super init]) { connected = false; @@ -456,15 +449,13 @@ using namespace QT_NAMESPACE; const BluetoothDeviceAddress addr(OSXBluetooth::iobluetooth_address(deviceAddress)); device = [[IOBluetoothDevice deviceWithAddress:&addr] retain]; if (!device) { - qCWarning(QT_BT_OSX) << "-initWithDelegate:remoteDevice:channelID:, " - "failed to create an IOBluetoothDevice"; + qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "failed to create an IOBluetoothDevice"; return self; } session = [[IOBluetoothOBEXSession alloc] initWithDevice:device channelID:port]; if (!session) { - qCWarning(QT_BT_OSX) << "-initWithDelegate:remoteDevice:channelID:, " - "failed to create an OBEX session"; + qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "failed to create an OBEX session"; return self; } @@ -489,12 +480,12 @@ using namespace QT_NAMESPACE; - (OBEXError)OBEXConnect { if (!session) { - qCWarning(QT_BT_OSX) << "-OBEXConnect, invalid session (nil)"; + qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "invalid session (nil)"; return kOBEXGeneralError; } // That's a "single-shot" operation: - Q_ASSERT_X(currentRequest == OSXBluetooth::OBEXNoop, "-connect", + Q_ASSERT_X(currentRequest == OSXBluetooth::OBEXNoop, Q_FUNC_INFO, "can not connect in this state (another request is active)"); connected = false; @@ -523,7 +514,7 @@ using namespace QT_NAMESPACE; { using namespace OSXBluetooth; - Q_ASSERT_X(session, "-OBEXConnectHandler:", "invalid session (nil)"); + Q_ASSERT_X(session, Q_FUNC_INFO, "invalid session (nil)"); if (pendingAbort) { currentRequest = OBEXNoop; @@ -532,7 +523,7 @@ using namespace QT_NAMESPACE; } if (currentRequest != OBEXConnect) { - qCWarning(QT_BT_OSX) << "-OBEXConnectHandler:, called while there is no" + qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "called while there is no " "active connect request"; return; } @@ -578,7 +569,7 @@ using namespace QT_NAMESPACE; { using namespace OSXBluetooth; - Q_ASSERT_X(session, "-OBEXAbort", "invalid OBEX session (nil)"); + Q_ASSERT_X(session, Q_FUNC_INFO, "invalid OBEX session (nil)"); if (currentRequest == OBEXNoop) { pendingAbort = false; @@ -608,10 +599,10 @@ using namespace QT_NAMESPACE; { using namespace OSXBluetooth; - Q_ASSERT_X(session, "-OBEXAbortHandler:", "invalid OBEX session (nil)"); + Q_ASSERT_X(session, Q_FUNC_INFO, "invalid OBEX session (nil)"); if (currentRequest != OBEXAbort) { - qCWarning(QT_BT_OSX) << "-OBEXAbortHandler:, called while there " + qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "called while there " "is no ABORT request"; return; } @@ -634,23 +625,22 @@ using namespace QT_NAMESPACE; if (!session || ![self isConnected]) return kOBEXSessionNotConnectedError; - Q_ASSERT_X(currentRequest == OBEXNoop, "-OBEXPutFile:withName:", + Q_ASSERT_X(currentRequest == OBEXNoop, Q_FUNC_INFO, "the current session has an active request already"); - Q_ASSERT_X(input, "-OBEXPutFile:withName:", "invalid input stream (null)"); - Q_ASSERT_X(input->isReadable(), "-OBEXPutFile:withName:", - "invalid input stream (not readable)"); + Q_ASSERT_X(input, Q_FUNC_INFO, "invalid input stream (null)"); + Q_ASSERT_X(input->isReadable(), Q_FUNC_INFO, "invalid input stream (not readable)"); // We send a put request with a couple of headers (size/file name/may be connection ID) + // a payload. const qint64 fileSize = input->size(); if (fileSize <= 0 || fileSize >= std::numeric_limits::max()) { - qCWarning(QT_BT_OSX) << "-OBEXPutFile:withName:, invalid input file size"; + qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "invalid input file size"; return kOBEXBadArgumentError; } ObjCStrongReference headers([[NSMutableData alloc] init], false); if (!headers) { - qCWarning(QT_BT_OSX) << "-OBEXPutFile:withName:, failed to allocate headers"; + qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "failed to allocate headers"; return kOBEXNoResourcesError; } @@ -660,16 +650,16 @@ using namespace QT_NAMESPACE; if (connectionIDFound) { if (!append_four_byte_header(headers, kOBEXHeaderIDConnectionID, connectionID)) { - qCWarning(QT_BT_OSX) << "-OBEXPutFile:withName:, " - "failed to append connection ID header"; + qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "failed to " + "append connection ID header"; return kOBEXNoResourcesError; } } if (name.length()) { if (!append_unicode_header(headers, kOBEXHeaderIDName, name)) { - qCWarning(QT_BT_OSX) << "-OBEXPutFile:withName:, " - "failed to append a unicode string"; + qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "failed to append " + "a unicode string"; return kOBEXNoResourcesError; } } @@ -682,7 +672,7 @@ using namespace QT_NAMESPACE; if (!chunk || ![chunk length]) { // We do not support PUT-DELETE (?) // At least the first chunk is expected to be non-empty. - qCWarning(QT_BT_OSX) << "-OBEXPutFile:withName:, invalid input stream"; + qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "invalid input stream"; return kOBEXBadArgumentError; } @@ -720,7 +710,7 @@ using namespace QT_NAMESPACE; { using namespace OSXBluetooth; - Q_ASSERT_X(session, "-OBEXPutHandler:", "invalid OBEX session (nil)"); + Q_ASSERT_X(session, Q_FUNC_INFO, "invalid OBEX session (nil)"); if (pendingAbort) { currentRequest = OBEXNoop; @@ -729,7 +719,7 @@ using namespace QT_NAMESPACE; } if (currentRequest != OBEXPut) { - qCWarning(QT_BT_OSX) << "-OBEXPutHandler:, called while the current " + qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "called while the current " "request is not a put request"; return; } @@ -751,7 +741,7 @@ using namespace QT_NAMESPACE; // 0 for the headers length, no more headers. ObjCStrongReference chunk(next_data_chunk(*inputStream, session, 0, lastChunk)); if (!chunk && !lastChunk) { - qCWarning(QT_BT_OSX) << "-OBEXPutHandler:, failed to " + qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "failed to " "allocate the next memory chunk"; return; } @@ -768,7 +758,7 @@ using namespace QT_NAMESPACE; refCon:Q_NULLPTR]; if (status != kOBEXSuccess) { - qCWarning(QT_BT_OSX) << "-OBEXPutHandler:, failed to " + qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "failed to " "send the next memory chunk"; currentRequest = OBEXNoop; if (delegate) // Response code is not important here. @@ -794,7 +784,7 @@ using namespace QT_NAMESPACE; - (void)OBEXDisconnect { - Q_ASSERT_X(session, "-OBEXDisconnect", "invalid session (nil)"); + Q_ASSERT_X(session, Q_FUNC_INFO, "invalid session (nil)"); currentRequest = OSXBluetooth::OBEXDisconnect; @@ -809,7 +799,7 @@ using namespace QT_NAMESPACE; { Q_UNUSED(event) - Q_ASSERT_X(session, "-OBEXDisconnectHandler:", "invalid session (nil)"); + Q_ASSERT_X(session, Q_FUNC_INFO, "invalid session (nil)"); // Event can have an error type, but there's nothing // we can do - even "cleanup" failed. diff --git a/src/bluetooth/osx/osxbtobexsession_p.h b/src/bluetooth/osx/osxbtobexsession_p.h index aa142b5a..9449ebf0 100644 --- a/src/bluetooth/osx/osxbtobexsession_p.h +++ b/src/bluetooth/osx/osxbtobexsession_p.h @@ -43,9 +43,8 @@ #include #include - -// Import - Obj-C headers do not have inclusion guards: -#import +// Only after Foundation.h: +#include "corebluetoothwrapper_p.h" @class IOBluetoothOBEXSession; @class IOBluetoothDevice; @@ -97,7 +96,7 @@ QT_END_NAMESPACE // It either succeeds or fails and tries to cleanup in any case. @interface QT_MANGLE_NAMESPACE(OSXBTOBEXSession) : NSObject { - QT_PREPEND_NAMESPACE(OSXBluetooth::OBEXSessionDelegate) *delegate; + QT_PREPEND_NAMESPACE(OSXBluetooth)::OBEXSessionDelegate *delegate; IOBluetoothDevice *device; quint16 channelID; IOBluetoothOBEXSession *session; diff --git a/src/bluetooth/qbluetoothtransferreply_osx.mm b/src/bluetooth/qbluetoothtransferreply_osx.mm index 3204e7b6..37d73a56 100644 --- a/src/bluetooth/qbluetoothtransferreply_osx.mm +++ b/src/bluetooth/qbluetoothtransferreply_osx.mm @@ -120,7 +120,7 @@ QBluetoothTransferReplyOSXPrivate::QBluetoothTransferReplyOSXPrivate(QBluetoothT minimalScan(true), requestComplete(false) { - Q_ASSERT_X(q, "QBluetoothTransferReplyOSXPrivate", "invalid q_ptr (null)"); + Q_ASSERT_X(q, Q_FUNC_INFO, "invalid q_ptr (null)"); } QBluetoothTransferReplyOSXPrivate::~QBluetoothTransferReplyOSXPrivate() @@ -140,8 +140,8 @@ bool QBluetoothTransferReplyOSXPrivate::isActive() const bool QBluetoothTransferReplyOSXPrivate::startOPP(const QBluetoothAddress &device) { - Q_ASSERT_X(!isActive(), "startOPP", "already started"); - Q_ASSERT_X(!device.isNull(), "startOPP", "invalid device address"); + Q_ASSERT_X(!isActive(), Q_FUNC_INFO, "already started"); + Q_ASSERT_X(!device.isNull(), Q_FUNC_INFO, "invalid device address"); errorString.clear(); error = QBluetoothTransferReply::NoError; @@ -164,15 +164,13 @@ bool QBluetoothTransferReplyOSXPrivate::startOPP(const QBluetoothAddress &device void QBluetoothTransferReplyOSXPrivate::sendConnect(const QBluetoothAddress &device, quint16 channelID) { - Q_ASSERT_X(!session, "sendConnect", "session is already active"); + Q_ASSERT_X(!session, Q_FUNC_INFO, "session is already active"); error = QBluetoothTransferReply::NoError; errorString.clear(); if (device.isNull() || !channelID) { - qCWarning(QT_BT_OSX) << "QBluetoothTransferReplyOSXPrivate::sendConnect(), " - "invalid device address or port"; - + qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "invalid device address or port"; setReplyError(QBluetoothTransferReply::HostNotFoundError, QObject::tr("Invalid target address")); return; @@ -181,8 +179,7 @@ void QBluetoothTransferReplyOSXPrivate::sendConnect(const QBluetoothAddress &dev OBEXSession newSession([[ObjCOBEXSession alloc] initWithDelegate:this remoteDevice:device channelID:channelID]); if (!newSession) { - qCWarning(QT_BT_OSX) << "QBluetoothTransferReplyOSXPrivate::sendConnect(), " - "failed to allocate OSXBTOBEXSession object"; + qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "failed to allocate OSXBTOBEXSession object"; setReplyError(QBluetoothTransferReply::UnknownError, QObject::tr("Failed to create an OBEX session")); @@ -197,8 +194,7 @@ void QBluetoothTransferReplyOSXPrivate::sendConnect(const QBluetoothAddress &dev if ([session isConnected]) sendPut();// Connected, send a PUT request. } else { - qCWarning(QT_BT_OSX) << "QBluetoothTransferReplyOSXPrivate::sendConnect(), " - "OBEXConnect failed"; + qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "OBEXConnect failed"; if (error == QBluetoothTransferReply::NoError) { // The error is not set yet. @@ -214,10 +210,10 @@ void QBluetoothTransferReplyOSXPrivate::sendConnect(const QBluetoothAddress &dev void QBluetoothTransferReplyOSXPrivate::sendPut() { - Q_ASSERT_X(inputStream, "sendPut", "invalid input stream (null)"); - Q_ASSERT_X(session, "sendPut", "invalid OBEX session (nil)"); - Q_ASSERT_X([session isConnected], "sendPut", "not connected"); - Q_ASSERT_X(![session hasActiveRequest], "sendPut", + Q_ASSERT_X(inputStream, Q_FUNC_INFO, "invalid input stream (null)"); + Q_ASSERT_X(session, Q_FUNC_INFO, "invalid OBEX session (nil)"); + Q_ASSERT_X([session isConnected], Q_FUNC_INFO, "not connected"); + Q_ASSERT_X(![session hasActiveRequest], Q_FUNC_INFO, "session already has an active request"); QString fileName; @@ -354,9 +350,7 @@ QBluetoothTransferReplyOSX::QBluetoothTransferReplyOSX(QIODevice *input, if (input) { QMetaObject::invokeMethod(this, "start", Qt::QueuedConnection); } else { - qCWarning(QT_BT_OSX) << "QBluetoothTransferReplyOSX::QBluetoothTransferReplyOSX(), " - "invalid input stream (null)"; - + qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "invalid input stream (null)"; osx_d_ptr->requestComplete = true; osx_d_ptr->errorString = tr("Invalid input file (null)"); osx_d_ptr->error = FileNotFoundError; @@ -417,8 +411,7 @@ bool QBluetoothTransferReplyOSX::start() if (!osx_d_ptr->isActive()) { // Step 0: find a channelID. if (request().address().isNull()) { - qCWarning(QT_BT_OSX) << "QBluetoothTransferReplyOSX::start(), " - "invalid device address"; + qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "invalid device address"; osx_d_ptr->setReplyError(HostNotFoundError, tr("Invalid target address")); return false; } @@ -432,7 +425,7 @@ bool QBluetoothTransferReplyOSX::start() void QBluetoothTransferReplyOSX::serviceDiscoveryFinished() { - Q_ASSERT_X(osx_d_ptr->agent.data(), "serviceDiscoveryFinished", + Q_ASSERT_X(osx_d_ptr->agent.data(), Q_FUNC_INFO, "invalid service discovery agent (null)"); const QList services = osx_d_ptr->agent->discoveredServices(); @@ -454,7 +447,7 @@ void QBluetoothTransferReplyOSX::serviceDiscoveryFinished() void QBluetoothTransferReplyOSX::serviceDiscoveryError(QBluetoothServiceDiscoveryAgent::Error errorCode) { - Q_ASSERT_X(osx_d_ptr->agent.data(), "serviceDiscoveryError", "invalid service discovery agent (null)"); + Q_ASSERT_X(osx_d_ptr->agent.data(), Q_FUNC_INFO, "invalid service discovery agent (null)"); if (errorCode == QBluetoothServiceDiscoveryAgent::PoweredOffError) { // There's nothing else we can do. -- cgit v1.2.3