diff options
author | Timur Pocheptsov <Timur.Pocheptsov@digia.com> | 2014-12-17 11:15:24 +0100 |
---|---|---|
committer | Timur Pocheptsov <Timur.Pocheptsov@digia.com> | 2014-12-18 11:54:19 +0100 |
commit | 95d7d8f941866f980c495ad906731b396f24c55a (patch) | |
tree | ae866fb71da3c32d6766d0b43c2259b1cf4e475c /src | |
parent | e5e5b853d6326952305b2471877a47bc083202b3 (diff) |
QBluetoothServiceInfo - cleanup (OS X)
Use Q_FUNC_INFO in asserts/messages.
Change-Id: Ie766016a36c3cc47d4561a74ed8bf179357a19df
Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/bluetooth/osx/osxbtservicerecord.mm | 50 | ||||
-rw-r--r-- | src/bluetooth/qbluetoothserviceinfo_osx.mm | 28 |
2 files changed, 28 insertions, 50 deletions
diff --git a/src/bluetooth/osx/osxbtservicerecord.mm b/src/bluetooth/osx/osxbtservicerecord.mm index 84e60f75..a0930ae9 100644 --- a/src/bluetooth/osx/osxbtservicerecord.mm +++ b/src/bluetooth/osx/osxbtservicerecord.mm @@ -47,10 +47,7 @@ #include <QtCore/qmap.h> #include <QtCore/qurl.h> -#include <IOBluetooth/BluetoothAssignedNumbers.h> - -// Import, since it's Objective-C header (no inclusion guards). -#import <IOBluetooth/objc/IOBluetoothSDPUUID.h> +#include "corebluetoothwrapper_p.h" QT_BEGIN_NAMESPACE @@ -146,7 +143,7 @@ Number variant_to_nsnumber<int>(const QVariant &var) template<class ValueType> void add_attribute(const QVariant &var, AttributeId key, Dictionary dict) { - Q_ASSERT_X(dict, "add_attribute", "invalid dictionary (nil)"); + Q_ASSERT_X(dict, Q_FUNC_INFO, "invalid dictionary (nil)"); if (!var.canConvert<ValueType>()) return; @@ -158,7 +155,7 @@ void add_attribute(const QVariant &var, AttributeId key, Dictionary dict) template<> void add_attribute<QString>(const QVariant &var, AttributeId key, Dictionary dict) { - Q_ASSERT_X(dict, "add_attribute", "invalid dictionary (nil)"); + Q_ASSERT_X(dict, Q_FUNC_INFO, "invalid dictionary (nil)"); if (!var.canConvert<QString>()) return; @@ -173,7 +170,7 @@ void add_attribute<QString>(const QVariant &var, AttributeId key, Dictionary dic template<> void add_attribute<QBluetoothUuid>(const QVariant &var, AttributeId key, Dictionary dict) { - Q_ASSERT_X(dict, "add_attribute", "invalid dictionary (nil)"); + Q_ASSERT_X(dict, Q_FUNC_INFO, "invalid dictionary (nil)"); if (!var.canConvert<QBluetoothUuid>()) return; @@ -185,7 +182,7 @@ void add_attribute<QBluetoothUuid>(const QVariant &var, AttributeId key, Diction template<> void add_attribute<QUrl>(const QVariant &var, AttributeId key, Dictionary dict) { - Q_ASSERT_X(dict, "add_attribute", "invalid dictionary (nil)"); + Q_ASSERT_X(dict, Q_FUNC_INFO, "invalid dictionary (nil)"); if (!var.canConvert<QUrl>()) return; @@ -203,7 +200,7 @@ void add_attribute(const QVariant &var, NSMutableArray *list); template<class ValueType> void add_attribute(const QVariant &var, NSMutableArray *list) { - Q_ASSERT_X(list, "add_attribute", "invalid list (nil)"); + Q_ASSERT_X(list, Q_FUNC_INFO, "invalid list (nil)"); if (!var.canConvert<ValueType>()) return; @@ -215,7 +212,7 @@ void add_attribute(const QVariant &var, NSMutableArray *list) template<> void add_attribute<QString>(const QVariant &var, NSMutableArray *list) { - Q_ASSERT_X(list, "add_attribute", "invalid list (nil)"); + Q_ASSERT_X(list, Q_FUNC_INFO, "invalid list (nil)"); if (!var.canConvert<QString>()) return; @@ -230,7 +227,7 @@ void add_attribute<QString>(const QVariant &var, NSMutableArray *list) template<> void add_attribute<QBluetoothUuid>(const QVariant &var, NSMutableArray *list) { - Q_ASSERT_X(list, "add_attribute", "invalid list (nil)"); + Q_ASSERT_X(list, Q_FUNC_INFO, "invalid list (nil)"); if (!var.canConvert<QBluetoothUuid>()) return; @@ -242,7 +239,7 @@ void add_attribute<QBluetoothUuid>(const QVariant &var, NSMutableArray *list) template<> void add_attribute<QUrl>(const QVariant &var, NSMutableArray *list) { - Q_ASSERT_X(list, "add_attribute", "invalid list (nil)"); + Q_ASSERT_X(list, Q_FUNC_INFO, "invalid list (nil)"); if (!var.canConvert<QUrl>()) return; @@ -254,13 +251,10 @@ void add_attribute<QUrl>(const QVariant &var, NSMutableArray *list) void add_rfcomm_protocol_descriptor_list(uint16 channelID, Dictionary dict) { - Q_ASSERT_X(dict, "add_rfcomm_protocol_descriptor_list", - "invalid dictionary (nil)"); + Q_ASSERT_X(dict, Q_FUNC_INFO, "invalid dictionary (nil)"); QT_BT_MAC_AUTORELEASEPOOL; - // TODO: error handling? - // Objective-C has literals (for arrays and dictionaries), but it will not compile // on 10.7 or below, so quite a lot of code here. @@ -288,13 +282,10 @@ void add_rfcomm_protocol_descriptor_list(uint16 channelID, Dictionary dict) void add_l2cap_protocol_descriptor_list(uint16 psm, Dictionary dict) { - Q_ASSERT_X(dict, "add_l2cap_protocol_descriptor_list", - "invalid dictionary (nil)"); + Q_ASSERT_X(dict, Q_FUNC_INFO, "invalid dictionary (nil)"); QT_BT_MAC_AUTORELEASEPOOL; - // TODO: error handling? - // Objective-C has literals (for arrays and dictionaries), but it will not compile // on 10.7 or below, so quite a lot of code here. @@ -317,10 +308,7 @@ void add_l2cap_protocol_descriptor_list(uint16 psm, Dictionary dict) bool add_attribute(const QVariant &var, AttributeId key, NSMutableArray *list) { - Q_ASSERT_X(list, "add_attribute", "invalid list (nil)"); - - // TODO: test if it works at all - add an attribute - // (some NSObject) into the sequence. + Q_ASSERT_X(list, Q_FUNC_INFO, "invalid list (nil)"); if (var.canConvert<Sequence>()) return false; @@ -333,7 +321,7 @@ bool add_attribute(const QVariant &var, AttributeId key, NSMutableArray *list) } else { // Here we need 'key' to understand the type. // We can have different integer types actually, so I have to check - // the 'key' to be sure conversion is reasonable. + // the 'key' to be sure the conversion is reasonable. switch (key) { case QSInfo::ServiceRecordHandle: case QSInfo::ServiceRecordState: @@ -357,7 +345,7 @@ bool add_attribute(const QVariant &var, AttributeId key, NSMutableArray *list) bool add_attribute(const QBluetoothServiceInfo &serviceInfo, AttributeId key, Dictionary dict) { - Q_ASSERT_X(dict, "add_attribute", "invalid dict (nil)"); + Q_ASSERT_X(dict, Q_FUNC_INFO, "invalid dict (nil)"); const QVariant var(serviceInfo.attribute(key)); if (var.canConvert<Sequence>()) @@ -370,7 +358,7 @@ bool add_attribute(const QBluetoothServiceInfo &serviceInfo, AttributeId key, Di add_attribute<QBluetoothUuid>(serviceInfo.attribute(key), key, dict); } else { // We can have different integer types actually, so I have to check - // the 'key' to be sure conversion is reasonable. + // the 'key' to be sure the conversion is reasonable. switch (key) { case QSInfo::ServiceRecordHandle: case QSInfo::ServiceRecordState: @@ -395,7 +383,7 @@ bool add_attribute(const QBluetoothServiceInfo &serviceInfo, AttributeId key, Di bool add_sequence_attribute(const QVariant &var, AttributeId key, NSMutableArray *list) { // Add a "nested" sequence. - Q_ASSERT_X(list, "add_sequence_attribute", "invalid list (nil)"); + Q_ASSERT_X(list, Q_FUNC_INFO, "invalid list (nil)"); if (var.isNull() || !var.canConvert<Sequence>()) return false; @@ -416,7 +404,7 @@ bool add_sequence_attribute(const QVariant &var, AttributeId key, NSMutableArray bool add_sequence_attribute(const QBluetoothServiceInfo &serviceInfo, AttributeId key, Dictionary dict) { - Q_ASSERT_X(dict, "add_sequence_attribute", "invalid dictionary (nil)"); + Q_ASSERT_X(dict, Q_FUNC_INFO, "invalid dictionary (nil)"); const QVariant &var(serviceInfo.attribute(key)); if (var.isNull() || !var.canConvert<Sequence>()) @@ -451,8 +439,6 @@ Dictionary iobluetooth_service_dictionary(const QBluetoothServiceInfo &serviceIn foreach (quint16 key, attributeIds) { if (key == QSInfo::ProtocolDescriptorList) // We handle it in a special way. continue; - //if (key == QSInfo::BluetoothProfileDescriptorList) - // continue; // TODO: check if non-sequence QVariant still must be // converted into NSArray for some attribute ID. if (!add_sequence_attribute(serviceInfo, AttributeId(key), dict)) @@ -466,8 +452,6 @@ Dictionary iobluetooth_service_dictionary(const QBluetoothServiceInfo &serviceIn add_rfcomm_protocol_descriptor_list(serviceInfo.serverChannel(), dict); } - // BluetoothProfileDescriptorList. - return dict; } diff --git a/src/bluetooth/qbluetoothserviceinfo_osx.mm b/src/bluetooth/qbluetoothserviceinfo_osx.mm index ae88b4e7..1240df18 100644 --- a/src/bluetooth/qbluetoothserviceinfo_osx.mm +++ b/src/bluetooth/qbluetoothserviceinfo_osx.mm @@ -52,8 +52,9 @@ #include <QtCore/qmap.h> #include <QtCore/qurl.h> -// Import, it's Objective-C header (no inclusion guards). -#import <IOBluetooth/objc/IOBluetoothSDPServiceRecord.h> +#include <Foundation/Foundation.h> +// Only after Foundation.h: +#include "osx/corebluetoothwrapper_p.h" QT_BEGIN_NAMESPACE @@ -115,7 +116,7 @@ QBluetoothServiceInfoPrivate::QBluetoothServiceInfoPrivate(QBluetoothServiceInfo registered(false), serviceRecordHandle(0) { - Q_ASSERT_X(q, "QBluetoothServiceInfoPrivate()", "invalid q_ptr (null)"); + Q_ASSERT_X(q, Q_FUNC_INFO, "invalid q_ptr (null)"); } bool QBluetoothServiceInfoPrivate::registerService(const QBluetoothAddress &localAdapter) @@ -125,8 +126,7 @@ bool QBluetoothServiceInfoPrivate::registerService(const QBluetoothAddress &loca if (registered) return false; - Q_ASSERT_X(!serviceRecord, "QBluetoothServiceInfoPrivate::registerService()", - "not registered, but serviceRecord is not nil"); + Q_ASSERT_X(!serviceRecord, Q_FUNC_INFO, "not registered, but serviceRecord is not nil"); using namespace OSXBluetooth; @@ -134,8 +134,7 @@ bool QBluetoothServiceInfoPrivate::registerService(const QBluetoothAddress &loca serviceDict(iobluetooth_service_dictionary(*q_ptr)); if (!serviceDict) { - qCWarning(QT_BT_OSX) << "QBluetoothServiceInfoPrivate::registerService(), " - "failed to create a service dictionary"; + qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "failed to create a service dictionary"; return false; } @@ -148,8 +147,7 @@ bool QBluetoothServiceInfoPrivate::registerService(const QBluetoothAddress &loca // With ARC this will require a different cast? const IOReturn status = IOBluetoothAddServiceDict((CFDictionaryRef)serviceDict.data(), &recordRef); if (status != kIOReturnSuccess) { - qCWarning(QT_BT_OSX) << "QBluetoothServiceInfoPrivate::registerService(), " - "failed to register a service record"; + qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "failed to register a service record"; return false; } @@ -159,8 +157,7 @@ bool QBluetoothServiceInfoPrivate::registerService(const QBluetoothAddress &loca #endif if (!newRecord) { - qCWarning(QT_BT_OSX) << "QBluetoothServiceInfoPrivate::registerService(), " - "failed to register a service record"; + qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "failed to register a service record"; // In case of SDK < 10.9 it's not possible to remove a service record ... // no way to obtain record handle yet. return false; @@ -168,8 +165,7 @@ bool QBluetoothServiceInfoPrivate::registerService(const QBluetoothAddress &loca BluetoothSDPServiceRecordHandle newRecordHandle = 0; if ([newRecord getServiceRecordHandle:&newRecordHandle] != kIOReturnSuccess) { - qCWarning(QT_BT_OSX) << "QBluetoothServiceInfoPrivate::registerService(), " - "failed to register a service record"; + qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "failed to register a service record"; #if QT_MAC_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_9, __IPHONE_NA) [newRecord removeServiceRecord]; #endif @@ -204,8 +200,7 @@ bool QBluetoothServiceInfoPrivate::registerService(const QBluetoothAddress &loca #else IOBluetoothRemoveServiceWithRecordHandle(newRecordHandle); #endif - qCWarning(QT_BT_OSX) << "QBluetoothServiceInfoPrivate::registerService(), " - "failed to register a service record"; + qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "failed to register a service record"; return false; } @@ -229,8 +224,7 @@ bool QBluetoothServiceInfoPrivate::unregisterService() if (!registered) return false; - Q_ASSERT_X(serviceRecord, "QBluetoothServiceInfoPrivate::unregisterService()", - "service registered, but serviceRecord is nil"); + Q_ASSERT_X(serviceRecord, Q_FUNC_INFO, "service registered, but serviceRecord is nil"); #if QT_MAC_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_9, __IPHONE_NA) [serviceRecord removeServiceRecord]; |