summaryrefslogtreecommitdiffstats
path: root/src/bluetooth/osx/osxbtutility_p.h
diff options
context:
space:
mode:
authorTimur Pocheptsov <Timur.Pocheptsov@digia.com>2014-10-29 10:15:54 +0100
committerTimur Pocheptsov <Timur.Pocheptsov@digia.com>2014-11-10 10:01:52 +0100
commite0dc61db4af89cce14ade3582ac92e4b713c7982 (patch)
treedbdeffaf2648da1532144367953ce0d72ff86d50 /src/bluetooth/osx/osxbtutility_p.h
parentf1372ef9a1c4ad5bb7c7bbd94116ec1203fc4243 (diff)
Bluetooth - device (LE) discovery for iOS
Add a QBluetoothDeviceDiscoveryAgent for iOS, implementation is based on Core Bluetooth framework. Low Energy devices scan only. - Ctor with address: set error as invalid bluetooth adapter error, Core Bluetooth framework does not provide access to the local adapter's address. - Adjust a test - we do not have access to the 'local device' information on iOS (no address, no number of devices etc.) - skip the last test in tst_deviceDiscovery. Change-Id: I49080d021c340016aebc548cc8ed758777c66397 Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Diffstat (limited to 'src/bluetooth/osx/osxbtutility_p.h')
-rw-r--r--src/bluetooth/osx/osxbtutility_p.h110
1 files changed, 98 insertions, 12 deletions
diff --git a/src/bluetooth/osx/osxbtutility_p.h b/src/bluetooth/osx/osxbtutility_p.h
index c2a48e5f..8c4083d9 100644
--- a/src/bluetooth/osx/osxbtutility_p.h
+++ b/src/bluetooth/osx/osxbtutility_p.h
@@ -47,19 +47,10 @@
#include <QtCore/qglobal.h>
#include <Foundation/Foundation.h>
+// Only after Foundation.h!
+#include "corebluetoothwrapper_p.h"
-#ifndef QT_IOS_BLUETOOTH
-
-#include <IOBluetooth/Bluetooth.h>
-#include <IOKit/IOReturn.h>
-
-@class IOBluetoothSDPUUID;
-
-#else
-
-#include <CoreBluetooth/CoreBluetooth.h>
-
-#endif
+@class CBUUID;
QT_BEGIN_NAMESPACE
@@ -179,6 +170,97 @@ private:
T *m_ptr;
};
+// The type 'T' is some XXXRef from CoreFoundation and co.
+// In principle, we can do a trick removing a pointer from a type
+// when template is instantiated, but it's quite a lot of ugly pp-tokens
+// like OSXBluetooth::CFStrongReference<OSXBluetooth::remove_pointer<CFUUIDRref> > strongReference;
+// so instead we use 'T' everywhere, not 'T *' as can expected
+// from a smart pointer.
+template<class T>
+class CFStrongReference {
+public:
+ CFStrongReference()
+ : m_ptr(Q_NULLPTR)
+ {
+ }
+
+ CFStrongReference(T obj, bool retain)
+ : m_ptr(obj)
+ {
+ if (m_ptr && retain)
+ CFRetain(m_ptr);
+ }
+
+ CFStrongReference(const CFStrongReference &rhs)
+ {
+ if ((m_ptr = rhs.m_ptr))
+ CFRetain(m_ptr);
+ }
+
+ CFStrongReference &operator = (const CFStrongReference &rhs)
+ {
+ // "Old-style" implementation:
+ if (this != &rhs && m_ptr != rhs.m_ptr) {
+ if (m_ptr)
+ CFRelease(m_ptr);
+ if ((m_ptr = rhs.m_ptr))
+ CFRetain(m_ptr);
+ }
+
+ return *this;
+ }
+
+#ifdef Q_COMPILER_RVALUE_REFS
+ CFStrongReference(CFStrongReference &&xval)
+ {
+ m_ptr = xval.m_ptr;
+ xval.m_ptr = Q_NULLPTR;
+ }
+
+ CFStrongReference &operator = (CFStrongReference &&xval)
+ {
+ m_ptr = xval.m_ptr;
+ xval.m_ptr = Q_NULLPTR;
+ return *this;
+ }
+#endif
+
+ ~CFStrongReference()
+ {
+ if (m_ptr)
+ CFRelease(m_ptr);
+ }
+
+ void reset(T newVal)
+ {
+ if (m_ptr != newVal) {
+ if (m_ptr)
+ CFRelease(m_ptr);
+ if ((m_ptr = newVal))
+ CFRetain(m_ptr);
+ }
+ }
+
+ operator T() const
+ {
+ return m_ptr;
+ }
+
+ T data() const
+ {
+ return m_ptr;
+ }
+
+ T take()
+ {
+ T p = m_ptr;
+ m_ptr = Q_NULLPTR;
+ return p;
+ }
+private:
+ T m_ptr;
+};
+
QString qt_address(NSString *address);
#ifndef QT_IOS_BLUETOOTH
@@ -192,6 +274,10 @@ QString qt_error_string(IOReturn errorCode);
#endif
+QBluetoothUuid qt_uuid(CBUUID *uuid);
+CFStrongReference<CFUUIDRef> cf_uuid(const QBluetoothUuid &qtUuid);
+ObjCStrongReference<CBUUID> cb_uuid(const QBluetoothUuid &qtUuid);
+
} // namespace OSXBluetooth
// Logging category for both OS X and iOS.