2 Copyright (C) 2012 Intel Corporation
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 #include "bluetoothplugin.h"
20 #include "timestamp.h"
21 #include "listplusplus.h"
24 #include <boost/assert.hpp>
25 #include <boost/lexical_cast.hpp>
28 #include <QDBusConnection>
29 #include <QDBusInterface>
36 BluetoothSinkPlugin::BluetoothSinkPlugin(AbstractRoutingEngine* re, map<string, string> config)
37 :AbstractSink(re, config)
39 new BtProfileAdaptor(this);
41 QDBusConnection::systemBus().registerObject("/org/bluez/spp", this);
46 extern "C" AbstractSink * create(AbstractRoutingEngine* routingengine, map<string, string> config)
48 return new BluetoothSinkPlugin(routingengine, config);
52 const string BluetoothSinkPlugin::uuid()
54 return "47ec4ed0-dc45-11e3-9c1a-0800200c9a66";
57 void BluetoothSinkPlugin::propertyChanged(AbstractPropertyType *value)
62 void BluetoothSinkPlugin::release()
64 DebugOut()<<"release called."<<endl;
67 void BluetoothSinkPlugin::newConnection(string path, int fd, QVariantMap props)
69 DebugOut()<<"new Connection! Path: "<<path<<endl;
71 socket.setSocketDescriptor(fd);
73 connect(&socket, &QTcpSocket::readyRead, this, &BluetoothSinkPlugin::canHasData);
76 void BluetoothSinkPlugin::requestDisconnection(string path)
78 DebugOut()<<"requestDisconnection called. Path: "<<path<<endl;
82 void BluetoothSinkPlugin::canHasData()
84 QByteArray data = socket.readAll();
86 DebugOut()<<"data read: "<<data.constData()<<endl;
89 BtProfileAdaptor::BtProfileAdaptor(BluetoothSinkPlugin *parent)
90 :QDBusAbstractAdaptor(parent), mParent(parent)
92 QDBusInterface profileManagerIface("org.bluez", "/org/bluez", "org.bluez.ProfileManager1", QDBusConnection::systemBus());
95 options["Name"] = "spp";
96 options["Role"] = "server";
98 QDBusReply<void> reply = profileManagerIface.call("RegisterProfile", "/org/bluez/spp", "00001101-0000-1000-8000-00805F9B34FB", options);
102 DebugOut(DebugOut::Error)<<"RegisterProfile call failed: "<<reply.error().message().toStdString()<<endl;
106 void BtProfileAdaptor::Release()
111 void BtProfileAdaptor::NewConnection(QDBusObjectPath device, int fd, QVariantMap fd_properties)
113 mParent->newConnection(device.path().toStdString(), fd, fd_properties);
116 void BtProfileAdaptor::RequestDisconnection(QDBusObjectPath device)
118 mParent->requestDisconnection(device.path().toStdString());