Merge branch '5.4' into btle

Change-Id: Ic2a30e766dee8096e2b58ad229d974a9fbf77fd5
Port QBluetoothLocalDevice and QBluetoothDeviceDiscoveryAgent to OS X.

QBluetoothLocalDevice and QBluetoothDeviceDiscoveryAgent for OS X -
Bluetooth Classic (the implementation based on IOBluetooth).
+ a very simple non-gui test (requires QApplication to work though).

Update 0: style issues reported by Qt-Bot + fix a test.
Update 1: QBluetoothLocalDevice - display confirmation
Update 2: Device discovery agent - follow the expected logic
          and apply suggested fixes.
Update 3: started/finished delegate methods seems to be synchronous and immediately follow
          start/stop calls on an inquiry.
Update 4: remove unused function and redundant error message.
Update 5: the first attempt to fix pairingStatus/requestPairing on a local device.
Update 6: on OS X it's impossible (with a given public API) to request 'Unpaired'.
          I was only able to find some quite terrible hacks with private APIs or
          even worse - playing with SystemConfiguration frameworks and changing
          System Preferencies programmatically (requires authorization and looks like a
          total hack, since it has nothing to do with Bluetooth framework).
Update 7: A very limited support for deviceConnected and connectedDevices.
Update 8: Fix an invalid invokeMethod's argument.
Update 9: Subject changed.
Update 10: fixes in a documentation.
Update 11: asserts in a coding convetion/style.
Update 12: "fix" asserts + emit errors if a start/stop failed.
Update 13: deviceDisconnected implemented.
Update 14: use not only paired && connected devices (QBluetoothLocalDevice::connectedDevices),
           but also devices discovered by the connection monitor.
Update 15: remove a test, not required (there are 'auto' tests).
Update 16: fix private headers - they MUST have _p suffix :(
Update 17: tests are known to fail (at the moment) - IOBluetooth
           requires adjustment (QApplication instead of QCoreApplication,
           lack of ability to power on/off a device (not possible on Mac) +
           other things).

Change-Id: Iea1c8a98f1fd719f4560ec8920d00cc07eaa8146
Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
Reviewed-by: Timur Pocheptsov <Timur.Pocheptsov@digia.com>
Port QBluetoothServiceInfo and QBluetoothServiceDiscoveryAgent to OS X.

QBluetoothServiceInfo and QBluetoothServiceDiscoveryAgent - version for
OS X (IOBluetooth-based).

Update 0: initial dummy version + mods to enable this new classes to be built
          with qtconnectivity.
Update 1: SDP query + initial implementation of a services discovery agent.
Update 2: aux functions to "parse" a service records once I got it.
Update 3: extract services UUIDs on a discovered device, if any.
Update 4: refactor
Update 5: "fix" asserts
Update 6: more asserts fixed.
Update 7: add the ability to stop SDP query (to be tested!!!)
Update 8: mods as suggested in review.
Update 9: no reason to check the size of discoveredDevices after 'clear' call.
Update 10: set an error and error description only if it's a 'singleDevice'.
Update 11: fix private header (_p suffix).
Update 12: on 10.7 (with quite old clang) there is no 'subscript operator'
           syntax for NSDictionary.

Change-Id: Ib3b07b49e3ed6381af75fb8b1e29cdf1e7a11237
Reviewed-by: Timur Pocheptsov <Timur.Pocheptsov@digia.com>
Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
Merge branch '5.4' into btle

Change-Id: Ic5f6b510e43afbebc9bb76aa7bcd68a27d4a4a9b
Port QBluetoothSocket to OS X.

Implement QBluetoothSocket using IOBluetooth framework on OS X
(will implement Qt's API as close  as possible with a given Apple's API).

Update 0: add (empty for now) delegate classes (L2CAP/RFCOMM).
Update 1: add service discovery (called doDeviceDiscovery though).
Update 2: implement the public class' logic (QBluetoothSocket, connectToService).
Update 3: more public logic implemented (since it's easy :) )
Update 4: L2CAP delegate - initial logic.
Update 5: connectToService - L2CAP "socket".
Update 6: fix pivate header files.
Update 7: fix dependency after the previous patch was merged.
Update 8: writeData - initial version for L2CAP.
Update 9: since RFCOM/L2CAP delegates have the same interface,
          no need in duplicating the same class - add a "generic"
          ChannelDelegate instead.
Update 10: more RFCOMM logic.
Update 11: function to build a service description from
           QBluetoothServiceInfo (to be registered on SDP server).
Update 12: QBluetoothSocket::close/abort.
Update 13: Create a dictioinary out of QBluetoothServiceInfo to register a service.
Update 14: Add service registration.
Update 15: Convert attributes (sequences and 'scalars') from QBluetoothServiceInfor
           into NSDictionary.
Update 16: Update QBluetoothServiceInfo with a real PSM/ChannelID
           after a service was registered.
Update 17: Move a private class (bluetooth socket) into the separate private
           header file (to make it visible for bluetooth_server_osx)
Update 18: Add an interface to create a bluetooth socket (private class)
           from a channel, reported by a notification (found by a listening
           server).
Update 19: Fix an invalid assert - any state (Inactive/ServiceDiscovery/DeviceDiscovery)
           is possible, not only Inactive.
           Implement the missing 'readData' and 'writeData' for RFCOMM.
           Set SDP query as non-active after query finished.
           Temporary (!) workaround - can not invokeMethod on a private socket (d_ptr).
Update 20: When creating a socket wrapper from an incoming notification/channel, set:
           socket type + channel's delegate.
Change-Id: Idd6d5478597206ed759f49e282baed948d105ddf
Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
Port QBluetoothServer to OS X.

Implement QBluetoothServer using IOBluetooth framework.
- Add empty (for now) implementation + modify .pro file.
- Add a 'socket listener'. Actually, there are no sockets,
  no 'listen' but I still have to emulate this to make a server work.
- Implement (to some degree) QBluetoothServer::listen member functions:
  on OS X QBluetoothServer::listen(address, port) does not really create
  a listening socket, it just checks that this port is not busy yet
  (IOBluetooth can either listen on a port you provide, or can
  listen on any port, but it can not select some port and listen on it.
  Only after service registered (with 'invalid' port first) - we have a real
  channelID or PSM.
- Server port - either a "fake" port assigned by QBluetoothServer::listen,
  or a real port as registered by IOBluetooth.
- Update a dependency.
- Implement nextPendingConnection.
- Implement fake server ports (something similar to Android version), but
  on OS X these fake ports can later be replaced with real ports.
- Service info updates PSM/ChannelID with a real port and also starts a listener.
- Unregister a server (dtor, close, etc.)
- Do not update a 'fake' port with a real one: it can happen, that a real port
  is already taken by some 'fake' port and this will break the whole idea of
  fake ports. Let them be always fake, the real is required only when starting
  a 'listener'.
- With 'fake' server ports '0' is not valid anymore (use serverPort() instead).
Change-Id: I44537a35891c6806e58ec874a18bd938d4b41c53
Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
QtBluetooth - service discovery test.

Run service discovery in 'FullDiscovery' mode (to make
sure something is found at all on platforms where MinimalDiscovery
works with cached results only).

Change-Id: I33441dcba942ec3778b3d071ff90f64d483e497c
Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
QBluetoothLocalDevice - bug fix for OS X.

It was a very stupid idea to compare a string from IOBluetooth with
QString, representing Bluetooth address - IOBluetooth uses '-' as a separator
+ the hex digits can be in lower case :) - making strings not equal :)
Compare two QBluetoothAddresses instead.

Change-Id: If4a43d254f766efd9f935a7633a4274aa6708e59
Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
QBluetoothServiceInfo - bugfix for OS X.

1. Register service even if there is not server listening for a given PSM/channel -
   this works with IOBluetooth and we can return true as success.
2. In unregisterService - reset 'registered' data-member to false (found by auto/tests).

Change-Id: Iecdb0dd3725cedb1411c49be77faa02b8e85d872
Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
QBluetoothServiceDiscoveryAgent - bugfix for OS X.

startServiceDiscovery should set a state into inactive, if all devices were
scanned already, otherwise, it's not possible to start a discovery again
after it's finished once. performMinimalDiscovery should apply a filter
(if any)

Change-Id: I5bb635a381be6e612c80ce14cb9ceeb509439fdb
Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
QBluetoothSocket - bugfix and mods for OS X.

- Emit disconnected if a channel was closed by IOBluetooth (== closed externally,
  not by Qt).
- Trick to enable invokeMethod to work with a private class (not parseable by moc).
- Fix inclusion guards _OSX_P_H, not _P_H (already in use).
- QBluetoothServer - update include + reset a port to 0 in 'close'.

Change-Id: Iaa35d6ca3ae1e8013b74d93a238d1afa4292a583
Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
Merge branch '5.4' into btle

Change-Id: I3c00855a33c1015d159a67e5548fd29164668929
QtBluetooth - enable auto tests on OS X.

The first patch to enable tests - does not require any modifications
in tests, just enabling the test.

Add fix for publishedRecordWithDictioinary - this function is new in 10.9,
deprecating withSDPRe..., but it crashed the test on 10.7 (and the same must happen
on 10.8).

Change-Id: I38e92cbc6f72fcaf8034824ef734148111139e0a
Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
QBluetoothLocalDevice - enable auto test on OS X.

The patch enables this test, but has to skip several test like
powerOn/Off and setHostMode - which is noop on OS X.

Change-Id: I6ef5e76294e61808668e46ad53ceaadfd855c9c3
Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
QBluetoothServer - enable auto test on OS X.

Enable test and skip the part, that tries to set host mode and check
the success (setHostMode is a noop on OS X).

Change-Id: Ib2583b9d0990c38445aaa44d62e778f5ac820141
Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
QtBluetooth - device discovery test on OS X.

- Enable this auto test on OS X, requires a modification: 'stop' is synchronous
  and so cancelSpy.isEmpty() == false (the last QVERIFY fails.

- Fix several problems with SDK versions (workarounds for non-existing methods in SDK < 10.9).
- Change error handling: we set an error in a ctor _only_ if QBluetoothAddress parameter was
  not null (!isNull()) and we failed to find a local device with such an address. This is the
  only case documented/expected, all others _do_ _not_ set an error, even if a local adapter
  is off or does not exits. This fixes a failing (to integrate) auto-test.

Change-Id: I9902211078330f296775f1c3249da166c19001a4
Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
Merge remote-tracking branch 'gerrit/5.4' into HEAD

Change-Id: Ic6549b3d728fbc9ad2425d0d6902aeac8c81e6be
Port QBluetoothTransferReply to OS X.

Implement file transfer using IOBluetoothOBEXSession.
- Add OBEX session class and session delegate.
- Implement OBEX connect operation.
- Aux. function to convert OBEX data into Qt's data types.
- Start implementing OBEX put.
- Extract a connection ID from response headers (if any?).
- OBEX Put (without response/event handler yet).
- OBEX Put completed - send the remaining chunks of data (if any).
  Change the unicode string encoding - byte order.
- OBEX change error handling - there can be real errors (OBEX event type == error_type)
  but also response code can be not something good - handle them both.
- Emit all signals and make Qt' btfiletransfer really working now.
- Protect a service discovery against the early stop (can be a result of emit serviceDiscovered).
- After a file transfer finished (either success or a failure) - disconnect (if connected)
  OBEX session - to make it possible to send more files.
- Implement OBEXPutError + isFinished/isRunning and signals on error.
- Add proper 'abort' and 'start' slots. Also emit finished on errors.
- If we do not have a file, but just an input stream, generate
  a _really_ random and unique name, not 'XXXXX' template.

Change-Id: Ib6fb35d8e0eb07d71ccd2d7b565bba226bef119c
Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
QtBluetooth - fix QBluetoothServer (OS X)

isListening on OS X should work with 'fake ports', not
real notifications, so even if all services unregister,
server is still listening.

Change-Id: I70bce4612c2fdb0bbe94e72f2f6d12feeb427fee
Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
Merge "Merge remote-tracking branch 'gerrit/5.4' into HEAD" into refs/staging/btle