diff options
author | Timur Pocheptsov <timur.pocheptsov@qt.io> | 2019-04-26 14:18:26 +0200 |
---|---|---|
committer | Timur Pocheptsov <timur.pocheptsov@qt.io> | 2019-06-14 14:21:53 +0200 |
commit | 722fde4664b8b3f5f661e37d212c32ba0fb2bbad (patch) | |
tree | bc00af5f01f15ed0b74c2d8a9cf2c93405eef6f7 /src/bluetooth/osx | |
parent | 50b589b85f1caa68846316e8b3dbe4f8c416775b (diff) |
De-duplicate device discovery code (Darwin)
- use the shared *._p.h file/class declaration for the private class
- use the shared *.cpp with the public class implementation
- get rid of *_ios.mm - iOS/tvOS/watchOS specific implementation
and use the shared (by macOS, iOS, tvOS, watchOS) *_darwin.mm source.
- get rid of somewhat weird 'isValid' in the private class, it is
is not taken care of in the public API anyway and today its
whole concept/usage looks (quite) buggy to me. I only have to
check that the default controller is not nil and has the
state 'ON'.
Task-number: QTBUG-75348
Change-Id: I5383e4f8df02ac12f069c2f59e252cb8a200800b
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Diffstat (limited to 'src/bluetooth/osx')
-rw-r--r-- | src/bluetooth/osx/btdelegates.cpp | 4 | ||||
-rw-r--r-- | src/bluetooth/osx/btdelegates_p.h | 16 | ||||
-rw-r--r-- | src/bluetooth/osx/btraii_p.h | 5 | ||||
-rw-r--r-- | src/bluetooth/osx/osxbt.pri | 21 | ||||
-rw-r--r-- | src/bluetooth/osx/osxbtdeviceinquiry.mm | 24 | ||||
-rw-r--r-- | src/bluetooth/osx/osxbtdeviceinquiry_p.h | 24 |
6 files changed, 33 insertions, 61 deletions
diff --git a/src/bluetooth/osx/btdelegates.cpp b/src/bluetooth/osx/btdelegates.cpp index c86516f9..531ca1df 100644 --- a/src/bluetooth/osx/btdelegates.cpp +++ b/src/bluetooth/osx/btdelegates.cpp @@ -39,6 +39,8 @@ #include "btdelegates_p.h" +#if defined(Q_OS_MACOS) + QT_BEGIN_NAMESPACE namespace DarwinBluetooth { @@ -70,3 +72,5 @@ SocketListener::~SocketListener() } // namespace DarwinBluetooth QT_END_NAMESPACE + +#endif diff --git a/src/bluetooth/osx/btdelegates_p.h b/src/bluetooth/osx/btdelegates_p.h index cb29b87e..11fbcc28 100644 --- a/src/bluetooth/osx/btdelegates_p.h +++ b/src/bluetooth/osx/btdelegates_p.h @@ -58,9 +58,9 @@ #include <QtCore/qsharedpointer.h> #include <QtCore/qglobal.h> -#if defined(Q_OS_MACOS) || defined(Q_OS_IOS) +#if defined(Q_OS_MACOS) + #include <IOKit/IOReturn.h> -#endif #include <cstdint> @@ -72,8 +72,6 @@ class QByteArray; namespace DarwinBluetooth { -#if defined(Q_OS_MACOS) - class DeviceInquiryDelegate { public: @@ -81,7 +79,7 @@ public: virtual void inquiryFinished() = 0; virtual void error(IOReturn error) = 0; - virtual void deviceFound(void *ioBluetoothDevice) = 0; + virtual void classicDeviceFound(void *ioBluetoothDevice) = 0; }; class PairingDelegate @@ -141,15 +139,11 @@ public: virtual void openNotifyL2CAP(void *l2capChannel) = 0; }; -#else - -#error "This header is only for macOS (Bluetooth Classic only)" - -#endif // Q_OS_MACOS - } // namespace DarwinBluetooth QT_END_NAMESPACE +#endif // Q_OS_MACOS + #endif // DARWINBTDELEGATES_P_H diff --git a/src/bluetooth/osx/btraii_p.h b/src/bluetooth/osx/btraii_p.h index b64defb6..6053d63b 100644 --- a/src/bluetooth/osx/btraii_p.h +++ b/src/bluetooth/osx/btraii_p.h @@ -107,6 +107,11 @@ public: return static_cast<ObjCType *>(objCInstance); } + operator bool() const + { + return !!objCInstance; + } + private: void *objCInstance = nullptr; }; diff --git a/src/bluetooth/osx/osxbt.pri b/src/bluetooth/osx/osxbt.pri index ae6111ee..89276310 100644 --- a/src/bluetooth/osx/osxbt.pri +++ b/src/bluetooth/osx/osxbt.pri @@ -1,8 +1,15 @@ -SOURCES += osx/uistrings.cpp osx/osxbtnotifier.cpp +SOURCES += osx/uistrings.cpp \ + osx/osxbtnotifier.cpp \ + osx/btdelegates.cpp + PRIVATE_HEADERS += osx/uistrings_p.h \ - osx/osxbtgcdtimer_p.h + osx/osxbtgcdtimer_p.h \ + osx/btraii_p.h \ + osx/btdelegates_p.h + -OBJECTIVE_SOURCES += osx/osxbtgcdtimer.mm +OBJECTIVE_SOURCES += osx/osxbtgcdtimer.mm \ + osx/btraii.mm #QMAKE_CXXFLAGS_WARN_ON += -Wno-nullability-completeness CONFIG(osx) { @@ -21,9 +28,7 @@ CONFIG(osx) { osx/osxbluetooth_p.h \ osx/osxbtcentralmanager_p.h \ osx/osxbtnotifier_p.h \ - osx/osxbtperipheralmanager_p.h \ - osx/btraii_p.h \ - osx/btdelegates_p.h + osx/osxbtperipheralmanager_p.h OBJECTIVE_SOURCES += osx/osxbtutility.mm \ osx/osxbtdevicepair.mm \ @@ -38,9 +43,7 @@ CONFIG(osx) { osx/osxbtobexsession.mm \ osx/osxbtledeviceinquiry.mm \ osx/osxbtcentralmanager.mm \ - osx/osxbtperipheralmanager.mm \ - osx/btraii.mm - SOURCES += osx/btdelegates.cpp + osx/osxbtperipheralmanager.mm } else { PRIVATE_HEADERS += osx/osxbtutility_p.h \ osx/osxbtledeviceinquiry_p.h \ diff --git a/src/bluetooth/osx/osxbtdeviceinquiry.mm b/src/bluetooth/osx/osxbtdeviceinquiry.mm index 57cd73e1..3a77c1f7 100644 --- a/src/bluetooth/osx/osxbtdeviceinquiry.mm +++ b/src/bluetooth/osx/osxbtdeviceinquiry.mm @@ -43,30 +43,16 @@ #include <QtCore/qloggingcategory.h> #include <QtCore/qdebug.h> -QT_BEGIN_NAMESPACE - -namespace OSXBluetooth { - -DeviceInquiryDelegate::~DeviceInquiryDelegate() -{ -} - -} - - -QT_END_NAMESPACE - QT_USE_NAMESPACE - @implementation QT_MANGLE_NAMESPACE(OSXBTDeviceInquiry) { IOBluetoothDeviceInquiry *m_inquiry; bool m_active; - QT_PREPEND_NAMESPACE(OSXBluetooth::DeviceInquiryDelegate) *m_delegate;//C++ "delegate" + DarwinBluetooth::DeviceInquiryDelegate *m_delegate;//C++ "delegate" } -- (id)initWithDelegate:(OSXBluetooth::DeviceInquiryDelegate *)delegate +- (id)initWithDelegate:(DarwinBluetooth::DeviceInquiryDelegate *)delegate { if (self = [super init]) { Q_ASSERT_X(delegate, Q_FUNC_INFO, "invalid device inquiry delegate (null)"); @@ -158,9 +144,9 @@ QT_USE_NAMESPACE // QtBluetooth has not too many error codes, 'UnknownError' is not really // useful, report the actual error code here: qCWarning(QT_BT_OSX) << "IOKit error code: " << error; - m_delegate->error(sender, error); + m_delegate->error(error); } else { - m_delegate->inquiryFinished(sender); + m_delegate->inquiryFinished(); } } @@ -171,7 +157,7 @@ QT_USE_NAMESPACE return; Q_ASSERT_X(m_delegate, Q_FUNC_INFO, "invalid device inquiry delegate (null)"); - m_delegate->deviceFound(sender, device); + m_delegate->classicDeviceFound(device); } - (void)deviceInquiryStarted:(IOBluetoothDeviceInquiry *)sender diff --git a/src/bluetooth/osx/osxbtdeviceinquiry_p.h b/src/bluetooth/osx/osxbtdeviceinquiry_p.h index 0fec2db2..86ed3fdf 100644 --- a/src/bluetooth/osx/osxbtdeviceinquiry_p.h +++ b/src/bluetooth/osx/osxbtdeviceinquiry_p.h @@ -52,36 +52,16 @@ // #include "osxbluetooth_p.h" +#include "btdelegates_p.h" #include <QtCore/qglobal.h> #include <Foundation/Foundation.h> #include <IOKit/IOReturn.h> -@class QT_MANGLE_NAMESPACE(OSXBTDeviceInquiry); - -QT_BEGIN_NAMESPACE - -namespace OSXBluetooth { - -class DeviceInquiryDelegate { -public: - typedef QT_MANGLE_NAMESPACE(OSXBTDeviceInquiry) DeviceInquiryObjC; - - virtual ~DeviceInquiryDelegate(); - - virtual void inquiryFinished(IOBluetoothDeviceInquiry *inq) = 0; - virtual void error(IOBluetoothDeviceInquiry *inq, IOReturn error) = 0; - virtual void deviceFound(IOBluetoothDeviceInquiry *inq, IOBluetoothDevice *device) = 0; -}; - -} - -QT_END_NAMESPACE - @interface QT_MANGLE_NAMESPACE(OSXBTDeviceInquiry) : NSObject<IOBluetoothDeviceInquiryDelegate> -- (id)initWithDelegate:(QT_PREPEND_NAMESPACE(OSXBluetooth::DeviceInquiryDelegate) *)delegate; +- (id)initWithDelegate:(QT_PREPEND_NAMESPACE(DarwinBluetooth::DeviceInquiryDelegate) *)delegate; - (void)dealloc; - (bool)isActive; |