1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtBluetooth module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 as published by the Free Software
20** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21** included in the packaging of this file. Please review the following
22** information to ensure the GNU General Public License requirements will
23** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24**
25** $QT_END_LICENSE$
26**
27****************************************************************************/
28
29#ifndef BTLOCALDEVICE_H
30#define BTLOCALDEVICE_H
31
32#include <QtCore/QObject>
33#include <QtBluetooth/QBluetoothDeviceDiscoveryAgent>
34#include <QtBluetooth/QBluetoothLocalDevice>
35#include <QtBluetooth/QBluetoothServer>
36#include <QtBluetooth/QBluetoothServiceDiscoveryAgent>
37#include <QtBluetooth/QBluetoothSocket>
38
39class BtLocalDevice : public QObject
40{
41 Q_OBJECT
42public:
43 explicit BtLocalDevice(QObject *parent = 0);
44 ~BtLocalDevice();
45 Q_PROPERTY(QString hostMode READ hostMode NOTIFY hostModeStateChanged)
46 Q_PROPERTY(int secFlags READ secFlags WRITE setSecFlags
47 NOTIFY secFlagsChanged)
48
49 int secFlags() const;
50 void setSecFlags(int);
51 QString hostMode() const;
52
53signals:
54 void error(QBluetoothLocalDevice::Error error);
55 void hostModeStateChanged();
56 void socketStateUpdate(int foobar);
57 void secFlagsChanged();
58
59public slots:
60 //QBluetoothLocalDevice
61 void dumpInformation();
62 void powerOn();
63 void reset();
64 void setHostMode(int newMode);
65 void requestPairingUpdate(bool isPairing);
66 void pairingFinished(const QBluetoothAddress &address, QBluetoothLocalDevice::Pairing pairing);
67 void connected(const QBluetoothAddress &addr);
68 void disconnected(const QBluetoothAddress &addr);
69 void pairingDisplayConfirmation(const QBluetoothAddress &address, const QString &pin);
70 void pairingDisplayPinCode(const QBluetoothAddress &address, const QString &pin);
71 void confirmPairing();
72 void cycleSecurityFlags();
73
74 //QBluetoothDeviceDiscoveryAgent
75 void deviceDiscovered(const QBluetoothDeviceInfo &info);
76 void discoveryFinished();
77 void discoveryCanceled();
78 void discoveryError(QBluetoothDeviceDiscoveryAgent::Error error);
79 void startDiscovery();
80 void stopDiscovery();
81
82 //QBluetoothServiceDiscoveryAgent
83 void startServiceDiscovery(bool isMinimalDiscovery);
84 void startTargettedServiceDiscovery();
85 void stopServiceDiscovery();
86 void serviceDiscovered(const QBluetoothServiceInfo &info);
87 void serviceDiscoveryFinished();
88 void serviceDiscoveryCanceled();
89 void serviceDiscoveryError(QBluetoothServiceDiscoveryAgent::Error error);
90 void dumpServiceDiscovery();
91
92 //QBluetoothSocket
93 void connectToService();
94 void connectToServiceViaSearch();
95 void disconnectToService();
96 void closeSocket();
97 void abortSocket();
98 void socketConnected();
99 void socketDisconnected();
100 void socketError(QBluetoothSocket::SocketError error);
101 void socketStateChanged(QBluetoothSocket::SocketState);
102 void dumpSocketInformation();
103 void writeData();
104 void readData();
105
106 //QBluetoothServer
107 void serverError(QBluetoothServer::Error error);
108 void serverListenPort();
109 void serverListenUuid();
110 void serverClose();
111 void serverNewConnection();
112 void clientSocketDisconnected();
113 void clientSocketReadyRead();
114 void dumpServerInformation();
115
116private:
117 void dumpLocalDevice(QBluetoothLocalDevice *dev);
118
119 QBluetoothLocalDevice *localDevice;
120 QBluetoothDeviceDiscoveryAgent *deviceAgent;
121 QBluetoothServiceDiscoveryAgent *serviceAgent;
122 QBluetoothSocket *socket;
123 QBluetoothServer *server;
124 QList<QBluetoothSocket *> serverSockets;
125 QBluetoothServiceInfo serviceInfo;
126
127 QList<QBluetoothServiceInfo> foundTestServers;
128 QBluetooth::SecurityFlags securityFlags;
129};
130
131#endif // BTLOCALDEVICE_H
132

source code of qtconnectivity/tests/bttestui/btlocaldevice.h