diff options
Diffstat (limited to 'src/bluetooth/osx/osxbtobexsession.mm')
-rw-r--r-- | src/bluetooth/osx/osxbtobexsession.mm | 90 |
1 files changed, 40 insertions, 50 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 <QtCore/qdebug.h> #include <QtCore/qlist.h> -// Import, since it's Obj-C headers: -#import <IOBluetooth/objc/IOBluetoothOBEXSession.h> -#import <IOBluetooth/objc/IOBluetoothDevice.h> - #include <algorithm> #include <cstddef> #include <limits> @@ -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<uint8_t *>(&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<uint8_t *>(&value)); @@ -140,8 +136,8 @@ QList<OBEXHeader> 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<OBEXHeader> 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<NSMutableData> 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<NSMutableData> 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<uint32_t>::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<NSMutableData> 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<NSMutableData> 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. |