This file is indexed.

/usr/share/qt5/doc/qtbluetooth/qtbluetooth-lowenergyscanner-device-cpp.html is in qtconnectivity5-doc-html 5.5.1-2build1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>device.cpp Example File | Qt Bluetooth 5.5</title>
  <link rel="stylesheet" type="text/css" href="style/offline.css" />
</head>
<body>
<div class="header" id="qtdocheader">
    <div class="main">
    <div class="main-rounded">
        <div class="navigationbar">
        <ul>
<li>Qt 5.5</li>
<li><a href="qtbluetooth-index.html">Qt Bluetooth</a></li>
<li><a href="qtbluetooth-lowenergyscanner-example.html">Bluetooth Low Energy Scanner Example</a></li>
<li>device.cpp Example File</li>
<li id="buildversion">Qt 5.5.1 Reference Documentation</li>
    </ul>
    </div>
</div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar"><div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">device.cpp Example File</h1>
<span class="subtitle">lowenergyscanner/device.cpp</span>
<!-- $$$lowenergyscanner/device.cpp-description -->
<div class="descr"> <a name="details"></a>
<pre class="cpp"><span class="comment">/***************************************************************************
**
** Copyright (C) 2013 BlackBerry Limited. All rights reserved.
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the QtBluetooth module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** You may use this file under the terms of the BSD license as follows:
**
** &quot;Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
**   * Redistributions of source code must retain the above copyright
**     notice, this list of conditions and the following disclaimer.
**   * Redistributions in binary form must reproduce the above copyright
**     notice, this list of conditions and the following disclaimer in
**     the documentation and/or other materials provided with the
**     distribution.
**   * Neither the name of The Qt Company Ltd nor the names of its
**     contributors may be used to endorse or promote products derived
**     from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** &quot;AS IS&quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.&quot;
**
** $QT_END_LICENSE$
**
****************************************************************************/</span>

<span class="preprocessor">#include &quot;device.h&quot;</span>
<span class="preprocessor">#include &lt;qbluetoothaddress.h&gt;</span>
<span class="preprocessor">#include &lt;qbluetoothdevicediscoveryagent.h&gt;</span>
<span class="preprocessor">#include &lt;qbluetoothlocaldevice.h&gt;</span>
<span class="preprocessor">#include &lt;qbluetoothdeviceinfo.h&gt;</span>
<span class="preprocessor">#include &lt;qbluetoothservicediscoveryagent.h&gt;</span>
<span class="preprocessor">#include &lt;QDebug&gt;</span>
<span class="preprocessor">#include &lt;QList&gt;</span>
<span class="preprocessor">#include &lt;QTimer&gt;</span>

Device<span class="operator">::</span>Device():
    connected(<span class="keyword">false</span>)<span class="operator">,</span> controller(<span class="number">0</span>)<span class="operator">,</span> m_deviceScanState(<span class="keyword">false</span>)<span class="operator">,</span> randomAddress(<span class="keyword">false</span>)
{
    discoveryAgent <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qbluetoothdevicediscoveryagent.html">QBluetoothDeviceDiscoveryAgent</a></span>();
    connect(discoveryAgent<span class="operator">,</span> SIGNAL(deviceDiscovered(<span class="keyword">const</span> <span class="type"><a href="qbluetoothdeviceinfo.html">QBluetoothDeviceInfo</a></span><span class="operator">&amp;</span>))<span class="operator">,</span>
            <span class="keyword">this</span><span class="operator">,</span> SLOT(addDevice(<span class="keyword">const</span> <span class="type"><a href="qbluetoothdeviceinfo.html">QBluetoothDeviceInfo</a></span><span class="operator">&amp;</span>)));
    connect(discoveryAgent<span class="operator">,</span> SIGNAL(error(<span class="type"><a href="qbluetoothdevicediscoveryagent.html">QBluetoothDeviceDiscoveryAgent</a></span><span class="operator">::</span>Error))<span class="operator">,</span>
            <span class="keyword">this</span><span class="operator">,</span> SLOT(deviceScanError(<span class="type"><a href="qbluetoothdevicediscoveryagent.html">QBluetoothDeviceDiscoveryAgent</a></span><span class="operator">::</span>Error)));
    connect(discoveryAgent<span class="operator">,</span> SIGNAL(finished())<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> SLOT(deviceScanFinished()));

    setUpdate(<span class="string">&quot;Search&quot;</span>);
}

Device<span class="operator">::</span><span class="operator">~</span>Device()
{
    <span class="keyword">delete</span> discoveryAgent;
    <span class="keyword">delete</span> controller;
    <a href="../qtcore/qtalgorithms.html#qDeleteAll">qDeleteAll</a>(devices);
    <a href="../qtcore/qtalgorithms.html#qDeleteAll">qDeleteAll</a>(m_services);
    <a href="../qtcore/qtalgorithms.html#qDeleteAll">qDeleteAll</a>(m_characteristics);
    devices<span class="operator">.</span>clear();
    m_services<span class="operator">.</span>clear();
    m_characteristics<span class="operator">.</span>clear();
}

<span class="type">void</span> Device<span class="operator">::</span>startDeviceDiscovery()
{
    <a href="../qtcore/qtalgorithms.html#qDeleteAll">qDeleteAll</a>(devices);
    devices<span class="operator">.</span>clear();
    <span class="keyword">emit</span> devicesUpdated();

    setUpdate(<span class="string">&quot;Scanning for devices ...&quot;</span>);
    discoveryAgent<span class="operator">-</span><span class="operator">&gt;</span>start();

    <span class="keyword">if</span> (discoveryAgent<span class="operator">-</span><span class="operator">&gt;</span>isActive()) {
        m_deviceScanState <span class="operator">=</span> <span class="keyword">true</span>;
        Q_EMIT stateChanged();
    }
}

<span class="type">void</span> Device<span class="operator">::</span>addDevice(<span class="keyword">const</span> <span class="type"><a href="qbluetoothdeviceinfo.html">QBluetoothDeviceInfo</a></span> <span class="operator">&amp;</span>info)
{
    <span class="keyword">if</span> (info<span class="operator">.</span>coreConfigurations() <span class="operator">&amp;</span> <span class="type"><a href="qbluetoothdeviceinfo.html">QBluetoothDeviceInfo</a></span><span class="operator">::</span>LowEnergyCoreConfiguration) {
        DeviceInfo <span class="operator">*</span>d <span class="operator">=</span> <span class="keyword">new</span> DeviceInfo(info);
        devices<span class="operator">.</span>append(d);
        setUpdate(<span class="string">&quot;Last device added: &quot;</span> <span class="operator">+</span> d<span class="operator">-</span><span class="operator">&gt;</span>getName());
    }
}

<span class="type">void</span> Device<span class="operator">::</span>deviceScanFinished()
{
    <span class="keyword">emit</span> devicesUpdated();
    m_deviceScanState <span class="operator">=</span> <span class="keyword">false</span>;
    <span class="keyword">emit</span> stateChanged();
    <span class="keyword">if</span> (devices<span class="operator">.</span>isEmpty())
        setUpdate(<span class="string">&quot;No Low Energy devices found...&quot;</span>);
    <span class="keyword">else</span>
        setUpdate(<span class="string">&quot;Done! Scan Again!&quot;</span>);
}

<span class="type"><a href="../qtcore/qvariant.html">QVariant</a></span> Device<span class="operator">::</span>getDevices()
{
    <span class="keyword">return</span> <span class="type"><a href="../qtcore/qvariant.html">QVariant</a></span><span class="operator">::</span>fromValue(devices);
}

<span class="type"><a href="../qtcore/qvariant.html">QVariant</a></span> Device<span class="operator">::</span>getServices()
{
    <span class="keyword">return</span> <span class="type"><a href="../qtcore/qvariant.html">QVariant</a></span><span class="operator">::</span>fromValue(m_services);
}

<span class="type"><a href="../qtcore/qvariant.html">QVariant</a></span> Device<span class="operator">::</span>getCharacteristics()
{
    <span class="keyword">return</span> <span class="type"><a href="../qtcore/qvariant.html">QVariant</a></span><span class="operator">::</span>fromValue(m_characteristics);
}

<span class="type"><a href="../qtcore/qstring.html">QString</a></span> Device<span class="operator">::</span>getUpdate()
{
    <span class="keyword">return</span> m_message;
}

<span class="type">void</span> Device<span class="operator">::</span>scanServices(<span class="keyword">const</span> <span class="type"><a href="../qtcore/qstring.html">QString</a></span> <span class="operator">&amp;</span>address)
{
    <span class="comment">// We need the current device for service discovery.</span>

    <span class="keyword">for</span> (<span class="type">int</span> i <span class="operator">=</span> <span class="number">0</span>; i <span class="operator">&lt;</span> devices<span class="operator">.</span>size(); i<span class="operator">+</span><span class="operator">+</span>) {
        <span class="keyword">if</span> (((DeviceInfo<span class="operator">*</span>)devices<span class="operator">.</span>at(i))<span class="operator">-</span><span class="operator">&gt;</span>getAddress() <span class="operator">=</span><span class="operator">=</span> address )
            currentDevice<span class="operator">.</span>setDevice(((DeviceInfo<span class="operator">*</span>)devices<span class="operator">.</span>at(i))<span class="operator">-</span><span class="operator">&gt;</span>getDevice());
    }

    <span class="keyword">if</span> (<span class="operator">!</span>currentDevice<span class="operator">.</span>getDevice()<span class="operator">.</span>isValid()) {
        <a href="../qtcore/qtglobal.html#qWarning">qWarning</a>() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;Not a valid device&quot;</span>;
        <span class="keyword">return</span>;
    }

    <a href="../qtcore/qtalgorithms.html#qDeleteAll">qDeleteAll</a>(m_characteristics);
    m_characteristics<span class="operator">.</span>clear();
    <span class="keyword">emit</span> characteristicsUpdated();
    <a href="../qtcore/qtalgorithms.html#qDeleteAll">qDeleteAll</a>(m_services);
    m_services<span class="operator">.</span>clear();
    <span class="keyword">emit</span> servicesUpdated();

    setUpdate(<span class="string">&quot;Back\n(Connecting to device...)&quot;</span>);

    <span class="keyword">if</span> (controller <span class="operator">&amp;</span><span class="operator">&amp;</span> m_previousAddress <span class="operator">!</span><span class="operator">=</span> currentDevice<span class="operator">.</span>getAddress()) {
        controller<span class="operator">-</span><span class="operator">&gt;</span>disconnectFromDevice();
        <span class="keyword">delete</span> controller;
        controller <span class="operator">=</span> <span class="number">0</span>;
    }

    <span class="keyword">if</span> (<span class="operator">!</span>controller) {
        <span class="comment">// Connecting signals and slots for connecting to LE services.</span>
        controller <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlowenergycontroller.html">QLowEnergyController</a></span>(currentDevice<span class="operator">.</span>getDevice());
        connect(controller<span class="operator">,</span> SIGNAL(connected())<span class="operator">,</span>
                <span class="keyword">this</span><span class="operator">,</span> SLOT(deviceConnected()));
        connect(controller<span class="operator">,</span> SIGNAL(error(<span class="type"><a href="qlowenergycontroller.html">QLowEnergyController</a></span><span class="operator">::</span>Error))<span class="operator">,</span>
                <span class="keyword">this</span><span class="operator">,</span> SLOT(errorReceived(<span class="type"><a href="qlowenergycontroller.html">QLowEnergyController</a></span><span class="operator">::</span>Error)));
        connect(controller<span class="operator">,</span> SIGNAL(disconnected())<span class="operator">,</span>
                <span class="keyword">this</span><span class="operator">,</span> SLOT(deviceDisconnected()));
        connect(controller<span class="operator">,</span> SIGNAL(serviceDiscovered(<span class="type"><a href="qbluetoothuuid.html">QBluetoothUuid</a></span>))<span class="operator">,</span>
                <span class="keyword">this</span><span class="operator">,</span> SLOT(addLowEnergyService(<span class="type"><a href="qbluetoothuuid.html">QBluetoothUuid</a></span>)));
        connect(controller<span class="operator">,</span> SIGNAL(discoveryFinished())<span class="operator">,</span>
                <span class="keyword">this</span><span class="operator">,</span> SLOT(serviceScanDone()));
    }

    <span class="keyword">if</span> (isRandomAddress())
        controller<span class="operator">-</span><span class="operator">&gt;</span>setRemoteAddressType(<span class="type"><a href="qlowenergycontroller.html">QLowEnergyController</a></span><span class="operator">::</span>RandomAddress);
    <span class="keyword">else</span>
        controller<span class="operator">-</span><span class="operator">&gt;</span>setRemoteAddressType(<span class="type"><a href="qlowenergycontroller.html">QLowEnergyController</a></span><span class="operator">::</span>PublicAddress);
    controller<span class="operator">-</span><span class="operator">&gt;</span>connectToDevice();

    m_previousAddress <span class="operator">=</span> currentDevice<span class="operator">.</span>getAddress();
}

<span class="type">void</span> Device<span class="operator">::</span>addLowEnergyService(<span class="keyword">const</span> <span class="type"><a href="qbluetoothuuid.html">QBluetoothUuid</a></span> <span class="operator">&amp;</span>serviceUuid)
{
    <span class="type"><a href="qlowenergyservice.html">QLowEnergyService</a></span> <span class="operator">*</span>service <span class="operator">=</span> controller<span class="operator">-</span><span class="operator">&gt;</span>createServiceObject(serviceUuid);
    <span class="keyword">if</span> (<span class="operator">!</span>service) {
        <a href="../qtcore/qtglobal.html#qWarning">qWarning</a>() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;Cannot create service for uuid&quot;</span>;
        <span class="keyword">return</span>;
    }
    ServiceInfo <span class="operator">*</span>serv <span class="operator">=</span> <span class="keyword">new</span> ServiceInfo(service);
    m_services<span class="operator">.</span>append(serv);

    <span class="keyword">emit</span> servicesUpdated();
}

<span class="type">void</span> Device<span class="operator">::</span>serviceScanDone()
{
    setUpdate(<span class="string">&quot;Back\n(Service scan done!)&quot;</span>);
    <span class="comment">// force UI in case we didn't find anything</span>
    <span class="keyword">if</span> (m_services<span class="operator">.</span>isEmpty())
        <span class="keyword">emit</span> servicesUpdated();
}

<span class="type">void</span> Device<span class="operator">::</span>connectToService(<span class="keyword">const</span> <span class="type"><a href="../qtcore/qstring.html">QString</a></span> <span class="operator">&amp;</span>uuid)
{
    <span class="type"><a href="qlowenergyservice.html">QLowEnergyService</a></span> <span class="operator">*</span>service <span class="operator">=</span> <span class="number">0</span>;
    <span class="keyword">for</span> (<span class="type">int</span> i <span class="operator">=</span> <span class="number">0</span>; i <span class="operator">&lt;</span> m_services<span class="operator">.</span>size(); i<span class="operator">+</span><span class="operator">+</span>) {
        ServiceInfo <span class="operator">*</span>serviceInfo <span class="operator">=</span> (ServiceInfo<span class="operator">*</span>)m_services<span class="operator">.</span>at(i);
        <span class="keyword">if</span> (serviceInfo<span class="operator">-</span><span class="operator">&gt;</span>getUuid() <span class="operator">=</span><span class="operator">=</span> uuid) {
            service <span class="operator">=</span> serviceInfo<span class="operator">-</span><span class="operator">&gt;</span>service();
            <span class="keyword">break</span>;
        }
    }

    <span class="keyword">if</span> (<span class="operator">!</span>service)
        <span class="keyword">return</span>;

    <a href="../qtcore/qtalgorithms.html#qDeleteAll">qDeleteAll</a>(m_characteristics);
    m_characteristics<span class="operator">.</span>clear();
    <span class="keyword">emit</span> characteristicsUpdated();

    <span class="keyword">if</span> (service<span class="operator">-</span><span class="operator">&gt;</span>state() <span class="operator">=</span><span class="operator">=</span> <span class="type"><a href="qlowenergyservice.html">QLowEnergyService</a></span><span class="operator">::</span>DiscoveryRequired) {
        connect(service<span class="operator">,</span> SIGNAL(stateChanged(<span class="type"><a href="qlowenergyservice.html">QLowEnergyService</a></span><span class="operator">::</span>ServiceState))<span class="operator">,</span>
                <span class="keyword">this</span><span class="operator">,</span> SLOT(serviceDetailsDiscovered(<span class="type"><a href="qlowenergyservice.html">QLowEnergyService</a></span><span class="operator">::</span>ServiceState)));
        service<span class="operator">-</span><span class="operator">&gt;</span>discoverDetails();
        setUpdate(<span class="string">&quot;Back\n(Discovering details...)&quot;</span>);
        <span class="keyword">return</span>;
    }

    <span class="comment">//discovery already done</span>
    <span class="keyword">const</span> <span class="type"><a href="../qtcore/qlist.html">QList</a></span><span class="operator">&lt;</span><span class="type"><a href="qlowenergycharacteristic.html">QLowEnergyCharacteristic</a></span><span class="operator">&gt;</span> chars <span class="operator">=</span> service<span class="operator">-</span><span class="operator">&gt;</span>characteristics();
    foreach (<span class="keyword">const</span> <span class="type"><a href="qlowenergycharacteristic.html">QLowEnergyCharacteristic</a></span> <span class="operator">&amp;</span>ch<span class="operator">,</span> chars) {
        CharacteristicInfo <span class="operator">*</span>cInfo <span class="operator">=</span> <span class="keyword">new</span> CharacteristicInfo(ch);
        m_characteristics<span class="operator">.</span>append(cInfo);
    }

    <span class="type"><a href="../qtcore/qtimer.html">QTimer</a></span><span class="operator">::</span>singleShot(<span class="number">0</span><span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> SIGNAL(characteristicsUpdated()));
}

<span class="type">void</span> Device<span class="operator">::</span>deviceConnected()
{
    setUpdate(<span class="string">&quot;Back\n(Discovering services...)&quot;</span>);
    connected <span class="operator">=</span> <span class="keyword">true</span>;
    controller<span class="operator">-</span><span class="operator">&gt;</span>discoverServices();
}

<span class="type">void</span> Device<span class="operator">::</span>errorReceived(<span class="type"><a href="qlowenergycontroller.html">QLowEnergyController</a></span><span class="operator">::</span>Error <span class="comment">/*error*/</span>)
{
    <a href="../qtcore/qtglobal.html#qWarning">qWarning</a>() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;Error: &quot;</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> controller<span class="operator">-</span><span class="operator">&gt;</span>errorString();
    setUpdate(<span class="type"><a href="../qtcore/qstring.html">QString</a></span>(<span class="string">&quot;Back\n(%1)&quot;</span>)<span class="operator">.</span>arg(controller<span class="operator">-</span><span class="operator">&gt;</span>errorString()));
}

<span class="type">void</span> Device<span class="operator">::</span>setUpdate(<span class="type"><a href="../qtcore/qstring.html">QString</a></span> message)
{
    m_message <span class="operator">=</span> message;
    <span class="keyword">emit</span> updateChanged();
}

<span class="type">void</span> Device<span class="operator">::</span>disconnectFromDevice()
{
    <span class="comment">// UI always expects disconnect() signal when calling this signal</span>
    <span class="comment">// TODO what is really needed is to extend state() to a multi value</span>
    <span class="comment">// and thus allowing UI to keep track of controller progress in addition to</span>
    <span class="comment">// device scan progress</span>

    <span class="keyword">if</span> (controller<span class="operator">-</span><span class="operator">&gt;</span>state() <span class="operator">!</span><span class="operator">=</span> <span class="type"><a href="qlowenergycontroller.html">QLowEnergyController</a></span><span class="operator">::</span>UnconnectedState)
        controller<span class="operator">-</span><span class="operator">&gt;</span>disconnectFromDevice();
    <span class="keyword">else</span>
        deviceDisconnected();
}

<span class="type">void</span> Device<span class="operator">::</span>deviceDisconnected()
{
    <a href="../qtcore/qtglobal.html#qWarning">qWarning</a>() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;Disconnect from device&quot;</span>;
    <span class="keyword">emit</span> disconnected();
}

<span class="type">void</span> Device<span class="operator">::</span>serviceDetailsDiscovered(<span class="type"><a href="qlowenergyservice.html">QLowEnergyService</a></span><span class="operator">::</span>ServiceState newState)
{
    <span class="keyword">if</span> (newState <span class="operator">!</span><span class="operator">=</span> <span class="type"><a href="qlowenergyservice.html">QLowEnergyService</a></span><span class="operator">::</span>ServiceDiscovered) {
        <span class="comment">// do not hang in &quot;Scanning for characteristics&quot; mode forever</span>
        <span class="comment">// in case the service discovery failed</span>
        <span class="comment">// We have to queue the signal up to give UI time to even enter</span>
        <span class="comment">// the above mode</span>
        <span class="keyword">if</span> (newState <span class="operator">!</span><span class="operator">=</span> <span class="type"><a href="qlowenergyservice.html">QLowEnergyService</a></span><span class="operator">::</span>DiscoveringServices) {
            <span class="type"><a href="../qtcore/qmetaobject.html">QMetaObject</a></span><span class="operator">::</span>invokeMethod(<span class="keyword">this</span><span class="operator">,</span> <span class="string">&quot;characteristicsUpdated&quot;</span><span class="operator">,</span>
                                      <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>QueuedConnection);
        }
        <span class="keyword">return</span>;
    }

    <span class="type"><a href="qlowenergyservice.html">QLowEnergyService</a></span> <span class="operator">*</span>service <span class="operator">=</span> qobject_cast<span class="operator">&lt;</span><span class="type"><a href="qlowenergyservice.html">QLowEnergyService</a></span> <span class="operator">*</span><span class="operator">&gt;</span>(sender());
    <span class="keyword">if</span> (<span class="operator">!</span>service)
        <span class="keyword">return</span>;

    <span class="keyword">const</span> <span class="type"><a href="../qtcore/qlist.html">QList</a></span><span class="operator">&lt;</span><span class="type"><a href="qlowenergycharacteristic.html">QLowEnergyCharacteristic</a></span><span class="operator">&gt;</span> chars <span class="operator">=</span> service<span class="operator">-</span><span class="operator">&gt;</span>characteristics();
    foreach (<span class="keyword">const</span> <span class="type"><a href="qlowenergycharacteristic.html">QLowEnergyCharacteristic</a></span> <span class="operator">&amp;</span>ch<span class="operator">,</span> chars) {
        CharacteristicInfo <span class="operator">*</span>cInfo <span class="operator">=</span> <span class="keyword">new</span> CharacteristicInfo(ch);
        m_characteristics<span class="operator">.</span>append(cInfo);
    }

    <span class="keyword">emit</span> characteristicsUpdated();
}

<span class="type">void</span> Device<span class="operator">::</span>deviceScanError(<span class="type"><a href="qbluetoothdevicediscoveryagent.html">QBluetoothDeviceDiscoveryAgent</a></span><span class="operator">::</span>Error error)
{
    <span class="keyword">if</span> (error <span class="operator">=</span><span class="operator">=</span> <span class="type"><a href="qbluetoothdevicediscoveryagent.html">QBluetoothDeviceDiscoveryAgent</a></span><span class="operator">::</span>PoweredOffError)
        setUpdate(<span class="string">&quot;The Bluetooth adaptor is powered off, power it on before doing discovery.&quot;</span>);
    <span class="keyword">else</span> <span class="keyword">if</span> (error <span class="operator">=</span><span class="operator">=</span> <span class="type"><a href="qbluetoothdevicediscoveryagent.html">QBluetoothDeviceDiscoveryAgent</a></span><span class="operator">::</span>InputOutputError)
        setUpdate(<span class="string">&quot;Writing or reading from the device resulted in an error.&quot;</span>);
    <span class="keyword">else</span>
        setUpdate(<span class="string">&quot;An unknown error has occurred.&quot;</span>);

    m_deviceScanState <span class="operator">=</span> <span class="keyword">false</span>;
    <span class="keyword">emit</span> devicesUpdated();
    <span class="keyword">emit</span> stateChanged();
}

bool Device<span class="operator">::</span>state()
{
    <span class="keyword">return</span> m_deviceScanState;
}

bool Device<span class="operator">::</span>hasControllerError() <span class="keyword">const</span>
{
    <span class="keyword">if</span> (controller <span class="operator">&amp;</span><span class="operator">&amp;</span> controller<span class="operator">-</span><span class="operator">&gt;</span>error() <span class="operator">!</span><span class="operator">=</span> <span class="type"><a href="qlowenergycontroller.html">QLowEnergyController</a></span><span class="operator">::</span>NoError)
        <span class="keyword">return</span> <span class="keyword">true</span>;
    <span class="keyword">return</span> <span class="keyword">false</span>;
}

bool Device<span class="operator">::</span>isRandomAddress() <span class="keyword">const</span>
{
    <span class="keyword">return</span> randomAddress;
}

<span class="type">void</span> Device<span class="operator">::</span>setRandomAddress(bool newValue)
{
    randomAddress <span class="operator">=</span> newValue;
    <span class="keyword">emit</span> randomAddressChanged();
}</pre>
</div>
<!-- @@@lowenergyscanner/device.cpp -->
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2015 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>