Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
btraii_p.h
Go to the documentation of this file.
1// Copyright (C) 2022 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef BTRAII_P_H
5#define BTRAII_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtCore/private/qglobal_p.h>
19
20#include <utility>
21
22QT_BEGIN_NAMESPACE
23
24namespace DarwinBluetooth {
25
31
32// The class StrongReference and its descendant ScopedGuard
33// are RAII classes dealing with raw pointers to NSObject class
34// and its descendants (and thus hiding Objective-C's retain/
35// release semantics). The header itself is meant to be included
36// into *.cpp files so it's a pure C++ code without any Objective-C
37// syntax. Thus it's a bit clunky - the type information is 'erased'
38// and has to be enforced by the code using these smart pointers.
39// That's because these types are Objective-C classes - thus require
40// Objective-C compiler to work. Member-function template 'getAs' is
41// a convenience shortcut giving the desired pointer type in
42// Objective-C++ files (*.mm).
44{
45public:
46 StrongReference() = default;
47 StrongReference(void *object, RetainPolicy policy);
48 StrongReference(const StrongReference &other);
50
52
53 StrongReference &operator = (const StrongReference &other) noexcept;
54 StrongReference &operator = (StrongReference &&other) noexcept;
55
56 void swap(StrongReference &other) noexcept
57 {
58 std::swap(objCInstance, other.objCInstance);
59 }
60
61 void *release();
62
63 void reset();
64 void reset(void *newInstance, RetainPolicy policy);
65
66 template<class ObjCType>
67 ObjCType *getAs() const
68 {
69 return static_cast<ObjCType *>(objCInstance);
70 }
71
72 operator bool() const
73 {
74 return !!objCInstance;
75 }
76
77private:
78 void *objCInstance = nullptr;
79};
80
81class ScopedPointer final : public StrongReference
82{
83public:
84 ScopedPointer() = default;
85 ScopedPointer(void *instance, RetainPolicy policy)
86 : StrongReference(instance, policy)
87 {
88 }
89
90private:
91 Q_DISABLE_COPY_MOVE(ScopedPointer)
92};
93
94} // namespace DarwinBluetooth
95
96QT_END_NAMESPACE
97
98#endif // BTRAII_P_H
#define QT_BT_MAC_AUTORELEASEPOOL
Definition btutility_p.h:78
ObjCScopedPointer(T *ptr, RetainPolicy policy)
Definition btutility_p.h:47
void reset(T *ptr, RetainPolicy policy)
Definition btutility_p.h:59
void swap(ObjCScopedPointer &other)
Definition btutility_p.h:51
ScopedPointer(void *instance, RetainPolicy policy)
Definition btraii_p.h:85
ObjCType * getAs() const
Definition btraii_p.h:67
StrongReference & operator=(StrongReference &&other) noexcept
Definition btraii.mm:49
StrongReference & operator=(const StrongReference &other) noexcept
Definition btraii.mm:39
StrongReference(void *object, RetainPolicy policy)
Definition btraii.mm:16
void reset(void *newInstance, RetainPolicy policy)
Definition btraii.mm:70
StrongReference(StrongReference &&other)
Definition btraii.mm:29
void swap(StrongReference &other) noexcept
Definition btraii_p.h:56
StrongReference(const StrongReference &other)
Definition btraii.mm:23
\inmodule QtBluetooth
\inmodule QtBluetooth
void characteristicWritten(const QLowEnergyCharacteristic &characteristic, const QByteArray &newValue)
QList< QBluetoothUuid > includedServices
void setController(QLowEnergyControllerPrivate *control)
void characteristicChanged(const QLowEnergyCharacteristic &characteristic, const QByteArray &newValue)
void characteristicRead(const QLowEnergyCharacteristic &info, const QByteArray &value)
QLowEnergyService::DiscoveryMode mode
void descriptorWritten(const QLowEnergyDescriptor &descriptor, const QByteArray &newValue)
void descriptorRead(const QLowEnergyDescriptor &info, const QByteArray &value)
QLowEnergyService::ServiceError lastError
void setError(QLowEnergyService::ServiceError newError)
QLowEnergyService::ServiceTypes type
QPointer< QLowEnergyControllerPrivate > controller
void errorOccurred(QLowEnergyService::ServiceError error)
void setState(QLowEnergyService::ServiceState newState)
QLowEnergyService::ServiceState state
QHash< QLowEnergyHandle, CharData > characteristicList
ObjCStrongReference< NSError > qt_timeoutNSError(OperationTimeout type)
QQueue< LERequest > RequestQueue
ObjCStrongReference< CBUUID > cb_uuid(const QBluetoothUuid &qtUuid)
Definition btutility.mm:174
QHash< NSObject *, QByteArray > ValueHash
const int defaultLEScanTimeoutMS
Definition btutility.mm:30
bool equal_uuids(const QBluetoothUuid &qtUuid, CBUUID *cbUuid)
Definition btutility.mm:190
ObjCStrongReference< NSMutableData > mutable_data_from_bytearray(const QByteArray &qtData)
Definition btutility.mm:281
auto qt_find_watchdog(const std::vector< GCDTimer > &watchdogs, id object, OperationTimeout type)
QByteArray qt_bytearray(NSData *data)
Definition btutility.mm:201
QHash< QLowEnergyHandle, CBDescriptor * > DescHash
QString qt_address(NSString *address)
Definition btutility.mm:36
QHash< QLowEnergyHandle, CBService * > ServiceHash
void qt_test_iobluetooth_runloop()
Definition btutility.mm:125
BluetoothDeviceAddress iobluetooth_address(const QBluetoothAddress &address)
Definition btutility.mm:65
NSUInteger qt_countGATTEntries(CBService *service)
QString qt_error_string(IOReturn errorCode)
Definition btutility.mm:104
const int maxValueLength
Definition btutility.mm:32
ObjCStrongReference< NSData > data_from_bytearray(const QByteArray &qtData)
Definition btutility.mm:272
QBluetoothAddress qt_address(const BluetoothDeviceAddress *address)
Definition btutility.mm:49
ObjCStrongReference< IOBluetoothSDPUUID > iobluetooth_uuid(const QBluetoothUuid &uuid)
Definition btutility.mm:81
dispatch_queue_t qt_LE_queue()
Definition btutility.mm:324
QBluetoothUuid qt_uuid(IOBluetoothSDPUUID *uuid)
Definition btutility.mm:91
const int defaultMtu
Definition btutility.mm:34
QHash< QLowEnergyHandle, CBCharacteristic * > CharHash
bool equal_uuids(CBUUID *cbUuid, const QBluetoothUuid &qtUuid)
Definition btutility.mm:196
Combined button and popup list for selecting options.
QHash< QLowEnergyHandle, QLowEnergyServicePrivate::CharData > CharacteristicDataMap
QHash< QLowEnergyHandle, QLowEnergyServicePrivate::DescData > DescriptorDataMap
QDataStream & operator<<(QDataStream &out, const MyClass &myObj)
[4]
QDataStream & operator>>(QDataStream &in, MyClass &myObj)
QHash< QLowEnergyHandle, DescData > descriptorList
QLowEnergyCharacteristic::PropertyTypes properties