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
qohosbluetoothsocket_p.h
Go to the documentation of this file.
1// Copyright (C) 2026 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 QOHOSBLUETOOTHSOCKET_P_H
5#define QOHOSBLUETOOTHSOCKET_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 <QtBluetooth/private/qohosbluetoothcommon_p.h>
19
20#include <QtCore/qbytearray.h>
21#include <QtCore/qobject.h>
22#include <QtCore/qstring.h>
23#include <QtCore/qtconfigmacros.h>
24#include <QtCore/qtypes.h>
25
26#include <cstdint>
27#include <memory>
28#include <optional>
29#include <string>
30#include <unordered_map>
31
32QT_BEGIN_NAMESPACE
33
34namespace QtOhosBluetooth {
35
36constexpr int invalidSocketDescriptor = -1;
37
38std::shared_ptr<int> makeSppClientSocketHandle(int socketDescriptor);
39std::shared_ptr<int> makeSppServerSocketHandle(int socketDescriptor);
40
42{
44public:
46
47 bool connect(const QString &deviceId, const QString &uuid, bool secure);
48 bool takeOverSocket(std::shared_ptr<int> socketHandle);
49 bool write(const char *data, qint64 maxSize);
50 void close();
51
54
55 static bool registerPendingSocketHandle(std::shared_ptr<int> socketHandle);
56 static void dropPendingSocketHandle(int socketDescriptor);
57 static std::shared_ptr<int> takePendingSocketHandle(int socketDescriptor);
58
62 void dataReceived(const QByteArray &data);
63 void errorOccurred(QOhosBluetoothErrorCode errorCode);
64
65private:
66 void onSocketConnected(std::uint64_t connectRequestId, std::shared_ptr<int> socketHandle);
67 void onConnectFailed(std::uint64_t connectRequestId, QOhosBluetoothErrorCode errorCode);
68 void reportError(QOhosBluetoothErrorCode errorCode);
69
70 struct JsScopeData
71 {
72 std::shared_ptr<int> socketHandle;
73 std::shared_ptr<void> sppReadHandlerHandle;
74 };
75
76 std::shared_ptr<JsScopeData> m_jsScopeData;
77 std::optional<std::string> m_deviceId;
78 std::uint64_t m_connectRequestsCounter = 0;
79 std::optional<std::uint64_t> m_pendingConnectRequestId;
80
81 static std::unordered_map<int, std::shared_ptr<int>> &pendingSocketHandles();
82};
83
84}
85
86QT_END_NAMESPACE
87
88#endif // QOHOSBLUETOOTHSOCKET_P_H
bool connect(const QString &deviceId, const QString &uuid, bool secure)
void dataReceived(const QByteArray &data)
std::optional< QString > tryGetPeerDeviceAddress() const
bool write(const char *data, qint64 maxSize)
static void dropPendingSocketHandle(int socketDescriptor)
void errorOccurred(QOhosBluetoothErrorCode errorCode)
static std::shared_ptr< int > takePendingSocketHandle(int socketDescriptor)
std::optional< QString > tryGetPeerDeviceName() const
bool takeOverSocket(std::shared_ptr< int > socketHandle)
static bool registerPendingSocketHandle(std::shared_ptr< int > socketHandle)
constexpr int invalidSocketDescriptor
std::shared_ptr< int > makeSppClientSocketHandle(int socketDescriptor)
std::shared_ptr< int > makeSppServerSocketHandle(int socketDescriptor)
QT_BEGIN_NAMESPACE Q_DECLARE_LOGGING_CATEGORY(lcQIORing)