summaryrefslogtreecommitdiffstats
path: root/src/bluetooth
diff options
context:
space:
mode:
authorFabian Bumberger <fbumberger@rim.com>2013-05-17 16:10:42 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-08-01 11:28:07 +0200
commit2011c3f63d5283b34bc1999ad35404cf93e286c9 (patch)
tree220e89e4b876ec1085c5d8b7f4ac5e492792cdda /src/bluetooth
parenta7d01a4f0d5bdd56749e674e71d32caaa3a065b3 (diff)
QNX Bluetooth adding OPP
Makes it possible to send QFiles over OPP. Other QIODevices do not work yet. Change-Id: I3a85a1f4a95c9059143f20d01c20ac27961e4a09 Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
Diffstat (limited to 'src/bluetooth')
-rw-r--r--src/bluetooth/bluetooth.pro8
-rw-r--r--src/bluetooth/qbluetoothtransfermanager_qnx.cpp58
-rw-r--r--src/bluetooth/qbluetoothtransferreply_qnx.cpp223
-rw-r--r--src/bluetooth/qbluetoothtransferreply_qnx_p.h102
-rw-r--r--src/bluetooth/qnx/ppshelpers.cpp15
-rw-r--r--src/bluetooth/qnx/ppshelpers_p.h4
6 files changed, 409 insertions, 1 deletions
diff --git a/src/bluetooth/bluetooth.pro b/src/bluetooth/bluetooth.pro
index 588a5580..c090d7e1 100644
--- a/src/bluetooth/bluetooth.pro
+++ b/src/bluetooth/bluetooth.pro
@@ -82,6 +82,9 @@ config_bluez:qtHaveModule(dbus) {
include(qnx/qnx.pri)
+ PRIVATE_HEADERS += \
+ qbluetoothtransferreply_qnx_p.h
+
SOURCES += \
qbluetoothdevicediscoveryagent_qnx.cpp \
qbluetoothlocaldevice_qnx.cpp \
@@ -90,7 +93,8 @@ config_bluez:qtHaveModule(dbus) {
qbluetoothsocket_qnx.cpp \
ql2capserver_p.cpp \
qrfcommserver_qnx.cpp \
- qbluetoothtransfermanager_p.cpp
+ qbluetoothtransfermanager_qnx.cpp \
+ qbluetoothtransferreply_qnx.cpp
} else {
message("Unsupported bluetooth platform, will not build a working QBluetooth library")
@@ -110,3 +114,5 @@ config_bluez:qtHaveModule(dbus) {
OTHER_FILES +=
HEADERS += $$PUBLIC_HEADERS $$PRIVATE_HEADERS
+
+
diff --git a/src/bluetooth/qbluetoothtransfermanager_qnx.cpp b/src/bluetooth/qbluetoothtransfermanager_qnx.cpp
new file mode 100644
index 00000000..26502fcc
--- /dev/null
+++ b/src/bluetooth/qbluetoothtransfermanager_qnx.cpp
@@ -0,0 +1,58 @@
+/***************************************************************************
+**
+** Copyright (C) 2013 Research In Motion
+** 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 "qbluetoothtransferreply_qnx_p.h"
+#include <QDebug>
+
+QT_BEGIN_NAMESPACE_BLUETOOTH
+
+QBluetoothTransferReply *QBluetoothTransferManager::put(const QBluetoothTransferRequest &request,
+ QIODevice *data)
+{
+
+ QBluetoothTransferReplyQnx *reply = new QBluetoothTransferReplyQnx(data, request);
+
+ connect(reply, SIGNAL(finished(QBluetoothTransferReply*)), this, SIGNAL(finished(QBluetoothTransferReply*)));
+
+ return reply;
+}
+
+QT_END_NAMESPACE_BLUETOOTH
diff --git a/src/bluetooth/qbluetoothtransferreply_qnx.cpp b/src/bluetooth/qbluetoothtransferreply_qnx.cpp
new file mode 100644
index 00000000..af5c28f0
--- /dev/null
+++ b/src/bluetooth/qbluetoothtransferreply_qnx.cpp
@@ -0,0 +1,223 @@
+/***************************************************************************
+**
+** Copyright (C) 2013 Research In Motion
+** 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 "qbluetoothtransferreply_qnx_p.h"
+#include "qbluetoothaddress.h"
+
+#include "qbluetoothtransferreply.h"
+
+#include <QFuture>
+#include <QFutureWatcher>
+#include <QtConcurrentRun>
+
+#include "qnx/ppshelpers_p.h"
+#include <QSocketNotifier>
+
+#include <QtCore/private/qcore_unix_p.h>
+
+#include <QTime>
+
+//static const QLatin1String agentPath("/shared/tmp/opp");
+
+QT_BEGIN_NAMESPACE_BLUETOOTH
+
+QBluetoothTransferReplyQnx::QBluetoothTransferReplyQnx(QIODevice *input, const QBluetoothTransferRequest &request,
+ QObject *parent)
+: QBluetoothTransferReply(parent), tempfile(0), source(input),
+ m_running(false), m_finished(false),
+ m_error(QBluetoothTransferReply::NoError), m_errorStr()
+{
+ ppsRegisterControl();
+ //qsrand(QTime::currentTime().msec());
+ //m_agent_path = agentPath;
+ //m_agent_path.append(QString::fromLatin1("/%1").arg(qrand()));
+ ppsRegisterForEvent("opp_update", this);
+ ppsRegisterForEvent("opp_complete", this);
+ ppsRegisterForEvent("opp_cancelled", this);
+
+ QMetaObject::invokeMethod(this, "start", Qt::QueuedConnection);
+}
+
+/*!
+ Destroys the QBluetoothTransferReply object.
+*/
+QBluetoothTransferReplyQnx::~QBluetoothTransferReplyQnx()
+{
+ ppsUnregisterControl(this);
+}
+
+bool QBluetoothTransferReplyQnx::start()
+{
+ m_running = true;
+ m_error = QBluetoothTransferReply::NoError;
+ m_errorStr = QString();
+
+ QFile *file = qobject_cast<QFile *>(source);
+
+ if (!file){
+// tempfile = new QTemporaryFile(this );
+// tempfile->open();
+
+// QFutureWatcher<bool> *watcher = new QFutureWatcher<bool>();
+// QObject::connect(watcher, SIGNAL(finished()), this, SLOT(copyDone()));
+
+// QFuture<bool> results = QtConcurrent::run(QBluetoothTransferReplyQnx::copyToTempFile, tempfile, source);
+// watcher->setFuture(results);
+ //QTemporaryFile does not work properly yet
+ m_error = QBluetoothTransferReply::UnknownError;
+ m_finished = true;
+ m_running = false;
+ Q_EMIT finished(this);
+
+ } else {
+ startOPP(file->fileName());
+ }
+ return true;
+}
+
+bool QBluetoothTransferReplyQnx::copyToTempFile(QIODevice *to, QIODevice *from)
+{
+ char *block = new char[4096];
+ int size;
+
+ while ((size = from->read(block, 4096))) {
+ if (size != to->write(block, size))
+ return false;
+ }
+
+ delete[] block;
+ return true;
+}
+
+void QBluetoothTransferReplyQnx::copyDone()
+{
+ qBBBluetoothDebug() << "Copy done";
+ startOPP(tempfile->fileName());
+ QObject::sender()->deleteLater();
+}
+
+void QBluetoothTransferReplyQnx::startOPP(QString filename)
+{
+ qBBBluetoothDebug() << "Sending Push object command";
+ ppsSendOpp("push_object", filename.toUtf8(), m_address, this);
+}
+
+QBluetoothTransferReply::TransferError QBluetoothTransferReplyQnx::error() const
+{
+ return m_error;
+}
+
+QString QBluetoothTransferReplyQnx::errorString() const
+{
+ return m_errorStr;
+}
+
+void QBluetoothTransferReplyQnx::controlReply(ppsResult result)
+{
+ if (!result.errorMsg.isEmpty()) {
+ m_errorStr = result.errorMsg;
+ m_error = QBluetoothTransferReply::UnknownError;
+ }
+}
+
+void QBluetoothTransferReplyQnx::controlEvent(ppsResult result)
+{
+ if (result.msg == QStringLiteral("opp_cancelled")) {
+ qBBBluetoothDebug() << "opp cancelled" << result.errorMsg << result.error;
+ if (m_running)
+ return;
+ m_finished = true;
+ m_running = false;
+// bool ok;
+// int reason = result.dat.at(result.dat.indexOf(QStringLiteral("reason")) + 1).toInt(&ok);
+// if (ok) {
+// switch (reason) {
+// case 1: m_error = QBluetoothTransferReply::UserCanceledTransferError;
+// case 3: m_error = QBluetoothTransferReply::UserCanceledTransferError;
+// }
+// } else {
+ m_errorStr = result.errorMsg;
+ m_error = QBluetoothTransferReply::UnknownError;
+// }
+ Q_EMIT finished(this);
+ } else if (result.msg == QStringLiteral("opp_update")) {
+ bool ok;
+ int sentBytes = result.dat.at(result.dat.indexOf(QStringLiteral("sent")) + 1).toInt(&ok);
+ if (!ok)
+ return;
+ int totalBytes = result.dat.at(result.dat.indexOf(QStringLiteral("total")) + 1).toInt(&ok);
+ if (!ok)
+ return;
+ qBBBluetoothDebug() << "opp update" << sentBytes << totalBytes;
+ Q_EMIT uploadProgress(sentBytes, totalBytes);
+ } else if (result.msg == QStringLiteral("opp_complete")) {
+ qBBBluetoothDebug() << "opp complete";
+ m_finished = true;
+ m_running = false;
+ Q_EMIT finished(this);
+ }
+}
+
+/*!
+ Returns true if this reply has finished; otherwise returns false.
+*/
+bool QBluetoothTransferReplyQnx::isFinished() const
+{
+ return m_finished;
+}
+
+/*!
+ Returns true if this reply is running; otherwise returns false.
+*/
+bool QBluetoothTransferReplyQnx::isRunning() const
+{
+ return m_running;
+}
+
+void QBluetoothTransferReplyQnx::abort()
+{
+ //not supported yet
+}
+
+#include "moc_qbluetoothtransferreply_qnx_p.cpp"
+
+QT_END_NAMESPACE_BLUETOOTH
diff --git a/src/bluetooth/qbluetoothtransferreply_qnx_p.h b/src/bluetooth/qbluetoothtransferreply_qnx_p.h
new file mode 100644
index 00000000..5add8d6a
--- /dev/null
+++ b/src/bluetooth/qbluetoothtransferreply_qnx_p.h
@@ -0,0 +1,102 @@
+/***************************************************************************
+**
+** Copyright (C) 2013 Research In Motion
+** 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$
+**
+****************************************************************************/
+
+
+#ifndef QBLUETOOTHTRANSFERREPLY_QNX_P_H
+#define QBLUETOOTHTRANSFERREPLY_QNX_P_H
+
+#include <QtCore/QIODevice>
+
+#include <qbluetoothtransferrequest.h>
+#include <qbluetoothtransfermanager.h>
+
+#include "qbluetoothtransferreply.h"
+
+#include <QTemporaryFile>
+#include <QSocketNotifier>
+
+#include "qnx/ppshelpers_p.h"
+
+QT_BEGIN_NAMESPACE_BLUETOOTH
+
+class Q_BLUETOOTH_EXPORT QBluetoothTransferReplyQnx : public QBluetoothTransferReply
+{
+ Q_OBJECT
+
+public:
+ explicit QBluetoothTransferReplyQnx(QIODevice *input, const QBluetoothTransferRequest &request,
+ QObject *parent = 0);
+ ~QBluetoothTransferReplyQnx();
+
+ bool isFinished() const;
+ bool isRunning() const;
+
+ QBluetoothTransferReply::TransferError error() const;
+ QString errorString() const;
+
+private Q_SLOTS:
+ void controlReply(ppsResult result);
+ void controlEvent(ppsResult result);
+ void copyDone();
+ bool start();
+
+private:
+ void startOPP(QString filename);
+ QTemporaryFile *tempfile;
+ QIODevice *source;
+
+ bool m_running;
+ bool m_finished;
+
+ QBluetoothTransferReply::TransferError m_error;
+ QString m_errorStr;
+
+ //QString m_agent_path;
+
+ static bool copyToTempFile(QIODevice *to, QIODevice *from);
+
+public slots:
+ void abort();
+};
+
+QT_END_NAMESPACE_BLUETOOTH
+
+#endif // QBLUETOOTHTRANSFERREPLY_QNX_P_H
diff --git a/src/bluetooth/qnx/ppshelpers.cpp b/src/bluetooth/qnx/ppshelpers.cpp
index 9524fbe3..6225ef0d 100644
--- a/src/bluetooth/qnx/ppshelpers.cpp
+++ b/src/bluetooth/qnx/ppshelpers.cpp
@@ -55,6 +55,7 @@ static QSocketNotifier *ppsCtrlNotifier = 0;
static const char btControlFDPath[] = "/pps/services/bluetooth/public/control";
static const char btSettingsFDPath[] = "/pps/services/bluetooth/settings";
static const char btRemoteDevFDPath[] = "/pps/services/bluetooth/remote_devices/";
+static const char btMediaFDPath[] = "/pps/services/bluetooth/media/control";
static const int ppsBufferSize = 1024;
@@ -267,6 +268,20 @@ void ppsDecodeControlResponse()
}
}
+void ppsSendOpp(const char *msg, const QByteArray &url, const QBluetoothAddress &address, QObject *sender)
+{
+ pps_encoder_t *encoder = beginCtrlMessage(msg, sender);
+
+ pps_encoder_start_object(encoder, "dat");
+ pps_encoder_add_string(encoder, "address", address.toString().toUtf8().constData());
+ pps_encoder_start_array(encoder, "urls");
+ pps_encoder_add_string(encoder, 0, url.constData());
+ pps_encoder_end_array(encoder);
+ pps_encoder_end_object(encoder);
+
+ endCtrlMessage(encoder);
+}
+
QVariant ppsReadSetting(const char *property)
{
int settingsFD;
diff --git a/src/bluetooth/qnx/ppshelpers_p.h b/src/bluetooth/qnx/ppshelpers_p.h
index f4c5a7ce..2809cb28 100644
--- a/src/bluetooth/qnx/ppshelpers_p.h
+++ b/src/bluetooth/qnx/ppshelpers_p.h
@@ -116,6 +116,10 @@ bool ppsSendControlMessage(const char *msg, QObject *sender=0);
void ppsDecodeControlResponse();
+int openOPPControl();
+
+void ppsSendOpp(const char *msg, const QByteArray &filename, const QBluetoothAddress &address, QObject *sender);
+
QVariant ppsReadSetting(const char *property);
QVariant ppsRemoteDeviceStatus(const QByteArray &address, const char *property);