1// Copyright (C) 2016 The Qt Company Ltd.
2// Copyright (C) 2016 BlackBerry Limited. All rights reserved.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
5#ifndef QBLUETOOTHSERVER_H
6#define QBLUETOOTHSERVER_H
7
8#include <QtBluetooth/qtbluetoothglobal.h>
9
10#include <QtCore/QObject>
11
12#include <QtBluetooth/QBluetoothAddress>
13#include <QtBluetooth/qbluetooth.h>
14#include <QtBluetooth/QBluetoothSocket>
15#include <QtBluetooth/QBluetoothServiceInfo>
16
17QT_BEGIN_NAMESPACE
18
19class QBluetoothServerPrivate;
20class QBluetoothSocket;
21
22class Q_BLUETOOTH_EXPORT QBluetoothServer : public QObject
23{
24 Q_OBJECT
25
26public:
27 enum Error {
28 NoError,
29 UnknownError,
30 PoweredOffError,
31 InputOutputError,
32 ServiceAlreadyRegisteredError,
33 UnsupportedProtocolError,
34 MissingPermissionsError
35 };
36 Q_ENUM(Error)
37
38 explicit QBluetoothServer(QBluetoothServiceInfo::Protocol serverType, QObject *parent = nullptr);
39 ~QBluetoothServer();
40
41 void close();
42
43 bool listen(const QBluetoothAddress &address = QBluetoothAddress(), quint16 port = 0);
44 [[nodiscard]] QBluetoothServiceInfo listen(const QBluetoothUuid &uuid,
45 const QString &serviceName = QString());
46 bool isListening() const;
47
48 void setMaxPendingConnections(int numConnections);
49 int maxPendingConnections() const;
50
51 bool hasPendingConnections() const;
52 QBluetoothSocket *nextPendingConnection();
53
54 QBluetoothAddress serverAddress() const;
55 quint16 serverPort() const;
56
57 void setSecurityFlags(QBluetooth::SecurityFlags security);
58 QBluetooth::SecurityFlags securityFlags() const;
59
60 QBluetoothServiceInfo::Protocol serverType() const;
61
62 Error error() const;
63
64Q_SIGNALS:
65 void newConnection();
66 void errorOccurred(QBluetoothServer::Error error);
67
68protected:
69 QBluetoothServerPrivate *d_ptr;
70
71private:
72 Q_DECLARE_PRIVATE(QBluetoothServer)
73};
74
75QT_END_NAMESPACE
76
77#endif
78

source code of qtconnectivity/src/bluetooth/qbluetoothserver.h