summaryrefslogtreecommitdiffstats
path: root/src/bluetooth/qbluetoothserver_osx_p.h
diff options
context:
space:
mode:
authorTimur Pocheptsov <Timur.Pocheptsov@digia.com>2014-09-23 17:18:05 +0200
committerTimur Pocheptsov <Timur.Pocheptsov@digia.com>2014-09-26 18:19:54 +0200
commitd66c466a135e4bebc293256f6ca361b287fd9bdb (patch)
tree503ba3d58787adfcc6dca6b3cab16b47bd0c32ae /src/bluetooth/qbluetoothserver_osx_p.h
parentd1d77c8210ecf7a89a81dad69d21b91e06bf129e (diff)
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>
Diffstat (limited to 'src/bluetooth/qbluetoothserver_osx_p.h')
-rw-r--r--src/bluetooth/qbluetoothserver_osx_p.h110
1 files changed, 110 insertions, 0 deletions
diff --git a/src/bluetooth/qbluetoothserver_osx_p.h b/src/bluetooth/qbluetoothserver_osx_p.h
new file mode 100644
index 00000000..d501743c
--- /dev/null
+++ b/src/bluetooth/qbluetoothserver_osx_p.h
@@ -0,0 +1,110 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtBluetooth module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL21$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QBLUETOOTHSERVER_OSX_P_H
+#define QBLUETOOTHSERVER_OSX_P_H
+
+#ifdef QT_OSX_BLUETOOTH
+
+#include "osx/osxbtsocketlistener_p.h"
+#include "qbluetoothserviceinfo.h"
+#include "osx/osxbtutility_p.h"
+#include "qbluetoothserver.h"
+
+#include <QtCore/qglobal.h>
+#include <QtCore/qlist.h>
+
+QT_BEGIN_NAMESPACE
+
+class QMutex;
+
+class QBluetoothServerPrivate : public OSXBluetooth::SocketListener
+{
+ friend class QBluetoothServer;
+ friend class QBluetoothServiceInfoPrivate;
+
+public:
+ QBluetoothServerPrivate(QBluetoothServiceInfo::Protocol type, QBluetoothServer *q);
+ ~QBluetoothServerPrivate();
+
+ void _q_newConnection();
+private:
+ bool startListener(quint16 realPort);
+ void stopListener();
+
+ // SocketListener (delegate):
+ void openNotify(IOBluetoothRFCOMMChannel *channel) Q_DECL_OVERRIDE;
+ void openNotify(IOBluetoothL2CAPChannel *channel) Q_DECL_OVERRIDE;
+
+ QBluetoothServiceInfo::Protocol serverType;
+ QBluetoothServer *q_ptr;
+ QBluetoothServer::Error lastError;
+
+ // Either a "temporary" channelID/PSM assigned by QBluetoothServer::listen,
+ // or a real channelID/PSM returned by IOBluetooth after we've registered
+ // a service.
+ quint16 port;
+
+ typedef OSXBluetooth::ObjCScopedPointer<ObjCListener> Listener;
+ Listener listener;
+
+ int maxPendingConnections;
+
+ // These static functions below
+ // deal with differences between bluetooth sockets
+ // (bluez and QtBluetooth's API) and IOBluetooth, where it's not possible
+ // to have a real PSM/channelID _before_ a service is registered,
+ // the solution - "fake" ports.
+ // These functions require external locking - using channelMapMutex.
+ static QMutex &channelMapMutex();
+
+ static bool channelIsBusy(quint16 channelID);
+ static quint16 findFreeChannel();
+
+ static bool psmIsBusy(quint16 psm);
+ static quint16 findFreePSM();
+
+ static void registerServer(QBluetoothServerPrivate *server, quint16 port);
+ static QBluetoothServerPrivate *registeredServer(quint16 port, QBluetoothServiceInfo::Protocol protocol);
+ static void unregisterServer(QBluetoothServerPrivate *server);
+
+ typedef OSXBluetooth::ObjCStrongReference<NSObject> PendingConnection;
+ QList<PendingConnection> pendingConnections;
+
+};
+
+QT_END_NAMESPACE
+
+#endif //QT_OSX_BLUETOOTH
+
+#endif