diff options
author | Timur Pocheptsov <Timur.Pocheptsov@digia.com> | 2014-10-03 17:05:00 +0200 |
---|---|---|
committer | Alex Blasche <alexander.blasche@digia.com> | 2014-10-16 16:59:15 +0200 |
commit | 038e0e38f96246848a6b7976690376cedb48140a (patch) | |
tree | 3f05f7bb2b506bffaea4b7214405ab08b27d53d4 /src/bluetooth/osx/osxbtobexsession_p.h | |
parent | e417b7036e35744daa1978cd236798e3ee1693c0 (diff) |
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>
Diffstat (limited to 'src/bluetooth/osx/osxbtobexsession_p.h')
-rw-r--r-- | src/bluetooth/osx/osxbtobexsession_p.h | 147 |
1 files changed, 147 insertions, 0 deletions
diff --git a/src/bluetooth/osx/osxbtobexsession_p.h b/src/bluetooth/osx/osxbtobexsession_p.h new file mode 100644 index 00000000..aa142b5a --- /dev/null +++ b/src/bluetooth/osx/osxbtobexsession_p.h @@ -0,0 +1,147 @@ +/**************************************************************************** +** +** 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:LGPL$ +** 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 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: 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. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtCore/qvariant.h> +#include <QtCore/qglobal.h> + +#include <Foundation/Foundation.h> + +// Import - Obj-C headers do not have inclusion guards: +#import <IOBluetooth/objc/OBEXSession.h> + +@class IOBluetoothOBEXSession; +@class IOBluetoothDevice; + +@class QT_MANGLE_NAMESPACE(OSXBTOBEXSession); + +QT_BEGIN_NAMESPACE + +class QBluetoothAddress; +class QIODevice; +class QString; + +namespace OSXBluetooth +{ + +class OBEXSessionDelegate +{ +public: + typedef QT_MANGLE_NAMESPACE(OSXBTOBEXSession) ObjCOBEXSession; + + virtual ~OBEXSessionDelegate(); + + virtual void OBEXConnectError(OBEXError error, OBEXOpCode responseCode) = 0; + virtual void OBEXConnectSuccess() = 0; + + virtual void OBEXAbortSuccess() = 0; + + virtual void OBEXPutDataSent(quint32 current, quint32 total) = 0; + virtual void OBEXPutSuccess() = 0; + virtual void OBEXPutError(OBEXError error, OBEXOpCode responseCode) = 0; +}; + +enum OBEXRequest { + OBEXNoop, + OBEXConnect, + OBEXDisconnect, + OBEXPut, + OBEXGet, + OBEXSetPath, + OBEXAbort +}; + +} + +QT_END_NAMESPACE + +// OBEX Session, it's a "single-shot" operation as our QBluetoothTransferReply is +// (it does not have an interface to re-send data or re-use the same transfer reply). +// It either succeeds or fails and tries to cleanup in any case. +@interface QT_MANGLE_NAMESPACE(OSXBTOBEXSession) : NSObject +{ + QT_PREPEND_NAMESPACE(OSXBluetooth::OBEXSessionDelegate) *delegate; + IOBluetoothDevice *device; + quint16 channelID; + IOBluetoothOBEXSession *session; + + QT_PREPEND_NAMESPACE(OSXBluetooth)::OBEXRequest currentRequest; + + bool connected; + bool connectionIDFound; + quint32 connectionID; + + QT_PREPEND_NAMESPACE(QIODevice) *inputStream; + + // TODO: switch to scoped pointers or strong reference objects instead. + NSMutableData *headersData; + NSMutableData *bodyData; + + quint32 bytesSent; + bool pendingAbort; +} + +- (id)initWithDelegate:(QT_PREPEND_NAMESPACE(OSXBluetooth::OBEXSessionDelegate) *)aDelegate + remoteDevice:(const QBluetoothAddress &)deviceAddress channelID:(quint16)port; + +- (void)dealloc; + +// Below I have pairs: OBEX operation and its callback method. +- (OBEXError)OBEXConnect; +- (void)OBEXConnectHandler:(const OBEXSessionEvent*)event; + +- (OBEXError)OBEXAbort; +- (void)OBEXAbortHandler:(const OBEXSessionEvent*)event; + +- (OBEXError)OBEXPutFile:(QT_PREPEND_NAMESPACE(QIODevice) *)inputStream withName:(const QString &)name; +- (void)OBEXPutHandler:(const OBEXSessionEvent*)event; + +// Aux. methods. +- (bool)isConnected; + +// To be called from C++ destructors. OBEXSession is not +// valid anymore after this call (no more OBEX operations +// can be executed). It's an ABORT/DISCONNECT sequence. +// It also resets a delegate to null. +- (void)closeSession; +// +- (bool)hasActiveRequest; + +@end |