~ubuntu-branches/ubuntu/wily/qtconnectivity-opensource-src/wily

« back to all changes in this revision

Viewing changes to src/bluetooth/qbluetoothservicediscoveryagent.cpp

  • Committer: Package Import Robot
  • Author(s): Lisandro Damián Nicanor Pérez Meyer, Timo Jyrinki
  • Date: 2014-02-23 00:01:49 UTC
  • mfrom: (0.1.3 experimental) (1.1.1)
  • Revision ID: package-import@ubuntu.com-20140223000149-ht3k3x21dr5n5dol
Tags: 5.2.1-1
[ Timo Jyrinki ]
* New upstream release
* Move mkspecs to the new location
* Make private headers cleaning non version specific
* Add examples package
* Add dependencies to build against the 5.2.1 versions

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
 
45
45
#include "qbluetoothdevicediscoveryagent.h"
46
46
 
47
 
QT_BEGIN_NAMESPACE_BLUETOOTH
 
47
QT_BEGIN_NAMESPACE
48
48
 
49
49
/*!
50
50
    \class QBluetoothServiceDiscoveryAgent
74
74
 
75
75
    This enum describes errors that can occur during service discovery.
76
76
 
77
 
    \value NoError              No error.
78
 
    \value DeviceDiscoveryError Error occurred during device discovery.
79
 
    \value UnknownError         An unidentified error occurred.
 
77
    \value NoError          No error has occurred.
 
78
    \value PoweredOffError  The Bluetooth adaptor is powered off, power it on before doing discovery.
 
79
    \value InputOutputError    Writing or reading from the device resulted in an error.
 
80
    \value UnknownError     An unknown error has occurred.
80
81
*/
81
82
 
82
83
/*!
98
99
/*!
99
100
    \fn QBluetoothServiceDiscoveryAgent::finished()
100
101
 
101
 
    This signal is emitted when Bluetooth service discovery completes.
 
102
    This signal is emitted when Bluetooth service discovery completes. This signal will even
 
103
    be emitted when an error occurred during the service discovery.
102
104
*/
103
105
 
104
106
/*!
119
121
}
120
122
 
121
123
/*!
122
 
    Constructs a new QBluetoothServiceDiscoveryAgent for \a remoteAddress and with \a parent.
 
124
    Constructs a new QBluetoothServiceDiscoveryAgent for \a deviceAdapter and with \a parent.
123
125
 
124
 
    If \a remoteAddress is null, services will be discovred on all contactable Bluetooth
125
 
    devices.
 
126
    If \a deviceAdapter is null, the default adapter will be used.
126
127
*/
127
 
QBluetoothServiceDiscoveryAgent::QBluetoothServiceDiscoveryAgent(const QBluetoothAddress &remoteAddress, QObject *parent)
128
 
: QObject(parent), d_ptr(new QBluetoothServiceDiscoveryAgentPrivate(remoteAddress))
 
128
QBluetoothServiceDiscoveryAgent::QBluetoothServiceDiscoveryAgent(const QBluetoothAddress &deviceAdapter, QObject *parent)
 
129
: QObject(parent), d_ptr(new QBluetoothServiceDiscoveryAgentPrivate(deviceAdapter))
129
130
{
130
131
    d_ptr->q_ptr = this;
131
 
    if (!remoteAddress.isNull()) {
132
 
        d_ptr->singleDevice = true;
133
 
    }
134
132
}
135
133
 
136
134
/*!
196
194
}
197
195
 
198
196
/*!
 
197
    Sets remote device address to \a address. If \a address is null, services will be discovered
 
198
    on all contactable Bluetooth devices. A new remote address can only be set while there is
 
199
    no service discovery in progress; otherwise this function returns false.
 
200
 
 
201
*/
 
202
bool QBluetoothServiceDiscoveryAgent::setRemoteAddress(const QBluetoothAddress &address)
 
203
{
 
204
    if (isActive())
 
205
        return false;
 
206
    if (!address.isNull())
 
207
        d_ptr->singleDevice = true;
 
208
    d_ptr->deviceAddress = address;
 
209
 
 
210
    return true;
 
211
}
 
212
 
 
213
/*!
 
214
    Returns the remote device address. If setRemoteAddress is not called, the function
 
215
    will return default QBluetoothAddress.
 
216
 
 
217
*/
 
218
QBluetoothAddress QBluetoothServiceDiscoveryAgent::remoteAddress() const
 
219
{
 
220
    if (d_ptr->singleDevice == true)
 
221
        return d_ptr->deviceAddress;
 
222
    else
 
223
        return QBluetoothAddress();
 
224
}
 
225
 
 
226
/*!
199
227
    Starts service discovery. \a mode specifies the type of service discovery to perform.
200
228
 
201
 
    On Blackberry devices device discovery may lead to pairing requests.
 
229
    On BlackBerry devices, device discovery may lead to pairing requests.
202
230
 
203
231
    \sa DiscoveryMode
204
232
*/
302
330
    Q_Q(QBluetoothServiceDiscoveryAgent);
303
331
 
304
332
    if (!deviceDiscoveryAgent) {
305
 
        deviceDiscoveryAgent = new QBluetoothDeviceDiscoveryAgent;
 
333
#ifdef QT_BLUEZ_BLUETOOTH
 
334
        deviceDiscoveryAgent = new QBluetoothDeviceDiscoveryAgent(m_deviceAdapterAddress, q);
 
335
#else
 
336
        deviceDiscoveryAgent = new QBluetoothDeviceDiscoveryAgent(q);
 
337
#endif
306
338
        QObject::connect(deviceDiscoveryAgent, SIGNAL(finished()),
307
339
                         q, SLOT(_q_deviceDiscoveryFinished()));
308
340
        QObject::connect(deviceDiscoveryAgent, SIGNAL(deviceDiscovered(QBluetoothDeviceInfo)),
309
341
                         q, SLOT(_q_deviceDiscovered(QBluetoothDeviceInfo)));
 
342
        QObject::connect(deviceDiscoveryAgent, SIGNAL(error(QBluetoothDeviceDiscoveryAgent::Error)),
 
343
                         q, SLOT(_q_deviceDiscoveryError(QBluetoothDeviceDiscoveryAgent::Error)));
310
344
 
311
345
    }
312
346
 
336
370
void QBluetoothServiceDiscoveryAgentPrivate::_q_deviceDiscoveryFinished()
337
371
{
338
372
    if (deviceDiscoveryAgent->error() != QBluetoothDeviceDiscoveryAgent::NoError) {
339
 
        error = QBluetoothServiceDiscoveryAgent::DeviceDiscoveryError;
340
 
 
 
373
        //Forward the device discovery error
 
374
        error = static_cast<QBluetoothServiceDiscoveryAgent::Error>(deviceDiscoveryAgent->error());
 
375
        errorString = deviceDiscoveryAgent->errorString();
341
376
        setDiscoveryState(Inactive);
342
377
        Q_Q(QBluetoothServiceDiscoveryAgent);
 
378
        emit q->error(error);
343
379
        emit q->finished();
344
380
        return;
345
381
    }
373
409
    }
374
410
}
375
411
 
 
412
void QBluetoothServiceDiscoveryAgentPrivate::_q_deviceDiscoveryError(QBluetoothDeviceDiscoveryAgent::Error newError)
 
413
{
 
414
    error = static_cast<QBluetoothServiceDiscoveryAgent::Error>(newError);
 
415
    errorString = deviceDiscoveryAgent->errorString();
 
416
 
 
417
    deviceDiscoveryAgent->stop();
 
418
    delete deviceDiscoveryAgent;
 
419
    deviceDiscoveryAgent = 0;
 
420
 
 
421
    setDiscoveryState(Inactive);
 
422
    Q_Q(QBluetoothServiceDiscoveryAgent);
 
423
    emit q->error(error);
 
424
    emit q->finished();
 
425
}
 
426
 
376
427
/*!
377
428
    Starts service discovery for the next device.
378
429
*/
380
431
{
381
432
    Q_Q(QBluetoothServiceDiscoveryAgent);
382
433
 
383
 
    setDiscoveryState(ServiceDiscovery);
384
 
 
385
434
    if (discoveredDevices.isEmpty()) {
386
435
        setDiscoveryState(Inactive);
387
436
        emit q->finished();
413
462
 
414
463
#include "moc_qbluetoothservicediscoveryagent.cpp"
415
464
 
416
 
QT_END_NAMESPACE_BLUETOOTH
 
465
QT_END_NAMESPACE