summaryrefslogtreecommitdiff
path: root/sapbtlistener.cc
diff options
context:
space:
mode:
authorJavier <dev.git@javispedro.com>2015-12-13 03:18:09 +0100
committerJavier <dev.git@javispedro.com>2015-12-13 03:18:09 +0100
commit3340aa0ef68eb735c36185959c8dbd11178575bf (patch)
treecf424e206eb60b7ca9f99bf135ed8dae54d25259 /sapbtlistener.cc
parentf45294559f976258831821ada062c73965201150 (diff)
downloadsapd-3340aa0ef68eb735c36185959c8dbd11178575bf.tar.gz
sapd-3340aa0ef68eb735c36185959c8dbd11178575bf.zip
Bump min Qt requirement to 5.2, bump libwatchfish version
Diffstat (limited to 'sapbtlistener.cc')
-rw-r--r--sapbtlistener.cc98
1 files changed, 15 insertions, 83 deletions
diff --git a/sapbtlistener.cc b/sapbtlistener.cc
index 76ecb94..40c7ac6 100644
--- a/sapbtlistener.cc
+++ b/sapbtlistener.cc
@@ -1,10 +1,5 @@
#include <QtCore/QDebug>
-#ifdef MANUAL_SDP
-#include <bluetooth/sdp.h>
-#include <bluetooth/sdp_lib.h>
-#endif
-
#include "saprotocol.h"
#include "sapbtlistener.h"
#include "sapbtpeer.h"
@@ -13,67 +8,6 @@
#include "hfpag.h"
#endif
-namespace
-{
-
-#ifdef MANUAL_SDP
-// Basically, QBluetoothServiceInfo is not yet compatible with Bluez5,
-// so we hack around it by doing our own SDP connection.
-void add_sdp_record(sdp_session_t *session, const QBluetoothUuid &btuuid, quint16 port)
-{
- sdp_list_t *svclass_id, *apseq, *root;
- uuid_t root_uuid, svclass_uuid, l2cap_uuid, rfcomm_uuid;
- sdp_list_t *aproto, *proto[2];
- sdp_data_t *chan;
-
- sdp_record_t *record = sdp_record_alloc();
-
- sdp_set_info_attr(record, "SAP", "gearbttest", "Samsung Accessory Protocol");
-
- sdp_uuid16_create(&root_uuid, PUBLIC_BROWSE_GROUP);
- root = sdp_list_append(0, &root_uuid);
- sdp_set_browse_groups(record, root);
-
- QByteArray uuid = btuuid.toRfc4122();
- sdp_uuid128_create(&svclass_uuid, uuid.constData());
- svclass_id = sdp_list_append(0, &svclass_uuid);
- sdp_set_service_classes(record, svclass_id);
-
- sdp_uuid16_create(&l2cap_uuid, L2CAP_UUID);
- proto[0] = sdp_list_append(0, &l2cap_uuid);
- apseq = sdp_list_append(0, proto[0]);
-
- sdp_uuid16_create(&rfcomm_uuid, RFCOMM_UUID);
- proto[1] = sdp_list_append(0, &rfcomm_uuid);
- chan = sdp_data_alloc(SDP_UINT8, &port);
- proto[1] = sdp_list_append(proto[1], chan);
- apseq = sdp_list_append(apseq, proto[1]);
-
- aproto = sdp_list_append(0, apseq);
- sdp_set_access_protos(record, aproto);
-
- if (sdp_record_register(session, record, 0) < 0) {
- qWarning() << "sdp_record_register failed";
- }
-}
-
-void add_sdp_records(quint16 port)
-{
- bdaddr_t addr_any = {{0, 0, 0, 0, 0, 0}};
- bdaddr_t addr_local = {{0, 0, 0, 0xFF, 0xFF, 0xFF}};
-
- sdp_session_t *sess = sdp_connect(&addr_any, &addr_local, 0);
- if (!sess) {
- qWarning() << "sdp_connect failed";
- return;
- }
-
- add_sdp_record(sess, SAProtocol::dataServiceUuid, port);
-}
-#endif
-
-}
-
SAPBTListener::SAPBTListener(QObject *parent) :
QObject(parent), _server(0)
{
@@ -87,14 +21,11 @@ SAPBTListener::~SAPBTListener()
void SAPBTListener::start()
{
if (_server) {
+ qWarning() << "Already started";
return;
}
-#if QT_VERSION >= QT_VERSION_CHECK(5,2,0)
_server = new QBluetoothServer(QBluetoothServiceInfo::RfcommProtocol, this);
-#else
- _server = new QRfcommServer(this);
-#endif
connect(_server, SIGNAL(newConnection()), this, SLOT(acceptConnection()));
if (!_server->listen(QBluetoothAddress(), 0)) {
qWarning() << "Failed to start Bluetooth listener socket";
@@ -104,12 +35,6 @@ void SAPBTListener::start()
quint8 serverPort = _server->serverPort();
-#if MANUAL_SDP
- // Basically, QBluetoothServiceInfo is not yet compatible with Bluez5,
- // so we hack around it by doing our own SDP connection.
- add_sdp_records(serverPort);
-#else
-
/*
Service Name: SAP
Service RecHandle: 0x1000b
@@ -160,7 +85,6 @@ void SAPBTListener::start()
if (!_service.registerService()) {
qWarning() << "Failed to register the SAP service";
}
-#endif
}
void SAPBTListener::stop()
@@ -179,19 +103,20 @@ void SAPBTListener::stop()
void SAPBTListener::nudge(const QBluetoothAddress &address)
{
-#if QT_VERSION >= QT_VERSION_CHECK(5,2,0)
QBluetoothSocket *socket = new QBluetoothSocket(QBluetoothServiceInfo::RfcommProtocol, this);
-#else
- QBluetoothSocket *socket = new QBluetoothSocket(QBluetoothSocket::RfcommSocket, this);
-#endif
- connect(socket, SIGNAL(connected()), socket, SLOT(deleteLater()));
+ connect(socket, SIGNAL(connected()), this, SLOT(handleNudgeConnected()));
connect(socket, SIGNAL(error(QBluetoothSocket::SocketError)),
this, SLOT(handleNudgeError(QBluetoothSocket::SocketError)));
qDebug() << "Nudging" << address.toString();
- socket->connectToService(address, 2); //SAPProtocol::nudgeServiceUuid);
+#if SAILFISH
+ // For some reason, using UUIDs here fails on SailfishOS
+ socket->connectToService(address, 1);
+#else
+ socket->connectToService(address, SAProtocol::nudgeServiceUuid);
+#endif
#if DESKTOP
// At the same time set up and HFP connection to the watch.
@@ -214,6 +139,13 @@ void SAPBTListener::acceptConnection()
new SAPBTPeer(SAProtocol::ClientRole, socket, this);
}
+void SAPBTListener::handleNudgeConnected()
+{
+ QBluetoothSocket *socket = static_cast<QBluetoothSocket*>(sender());
+ qDebug() << "Nudge connected:" << socket->peerAddress().toString();
+ new SAPBTPeer(SAProtocol::ClientRole, socket, this);
+}
+
void SAPBTListener::handleNudgeError(QBluetoothSocket::SocketError error)
{
QBluetoothSocket *socket = static_cast<QBluetoothSocket*>(sender());