SolidModules
bluez-bluetoothremotedevice.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "bluez-bluetoothremotedevice.h"
00024
00025 #include <QQueue>
00026 #include <QTimer>
00027
00028 #include <kdebug.h>
00029
00030 #include <solid/control/bluetoothremotedevice.h>
00031
00032 #include "bluezcalljob.h"
00033
00034 Q_DECLARE_METATYPE(QList<uint>)
00035
00036 BluezBluetoothRemoteDevice::BluezBluetoothRemoteDevice(const QString &objectPath)
00037 : BluetoothRemoteDevice(0), m_objectPath(objectPath)
00038 {
00039
00040
00041
00042 m_adapter = m_objectPath.left(objectPath.size() - 18);
00043 m_address = m_objectPath.right(17);
00044
00045 kdDebug() << "Connecting to ObjectPath: " << objectPath;
00046
00047 device = new QDBusInterface("org.bluez", objectPath,
00048 "org.bluez.Device", QDBusConnection::systemBus());
00049 #define connectDeviceToThis(signal, slot) \
00050 device->connection().connect("org.bluez", \
00051 objectPath, \
00052 "org.bluez.Device", \
00053 signal, this, SLOT(slot))
00054 connectDeviceToThis("PropertyChanged",slotPropertyChanged(const QString &,const QDBusVariant &));
00055 connectDeviceToThis("DisconnectRequested",slotDisconnectRequested());
00056 connectDeviceToThis("NodeCreated",slotNodeCreated(const QDBusObjectPath &));
00057 connectDeviceToThis("NodeRemoved",slotNodeRemoved(const QDBusObjectPath &));
00058
00059
00060 }
00061
00062 BluezBluetoothRemoteDevice::~BluezBluetoothRemoteDevice()
00063 {
00064 delete device;
00065 }
00066
00067 QString BluezBluetoothRemoteDevice::ubi() const
00068 {
00069 return device->path();
00070 }
00071
00072 QMap<QString,QVariant> BluezBluetoothRemoteDevice::getProperties() const
00073 {
00074 QDBusReply< QMap<QString,QVariant> > path = device->call("GetProperties");
00075 if (!path.isValid())
00076 return QMap<QString,QVariant>();
00077
00078 return path.value();
00079 }
00080
00081 void BluezBluetoothRemoteDevice::setProperty(const QString &name, const QVariant &value)
00082 {
00083 device->call("SetProperty",name,qVariantFromValue(QDBusVariant(value)));
00084 }
00085
00086 void BluezBluetoothRemoteDevice::discoverServices(const QString& pattern) const
00087 {
00088 QList<QVariant> args;
00089 args << pattern;
00090 device->callWithCallback("DiscoverServices",
00091 args,
00092 (QObject*)this,
00093 SLOT(slotServiceDiscover(const QMap<uint,QString> &)),
00094 SLOT(dbusErrorServiceDiscover(const QDBusError &)));
00095
00096 }
00097
00098 void BluezBluetoothRemoteDevice::cancelDiscovery()
00099 {
00100 device->call("CancelDiscovery");
00101 }
00102
00103 void BluezBluetoothRemoteDevice::disconnect()
00104 {
00105 device->call("Disconnect");
00106 }
00107
00108 QStringList BluezBluetoothRemoteDevice::listNodes() const
00109 {
00110 QStringList list;
00111 QDBusReply< QList<QDBusObjectPath> > path = device->call("ListNodes");
00112 if (path.isValid()) {
00113 foreach(QDBusObjectPath objectPath, path.value()) {
00114 list.append(objectPath.path());
00115 }
00116 return list;
00117 }
00118
00119 return QStringList();
00120 }
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161 void BluezBluetoothRemoteDevice::slotServiceDiscover(const QMap< uint,QString > & handles)
00162 {
00163 emit serviceDiscoverAvailable("success",handles);
00164 }
00165
00166
00167
00168
00169 QStringList BluezBluetoothRemoteDevice::listReply(const QString &method) const
00170 {
00171 QDBusReply< QStringList > reply = device->call(method, m_address);
00172 if (!reply.isValid())
00173 return QStringList();
00174
00175 return reply.value();
00176 }
00177
00178 QString BluezBluetoothRemoteDevice::stringReply(const QString &method) const
00179 {
00180 QDBusReply< QString > reply = device->call(method, m_address);
00181 if (!reply.isValid())
00182 return QString();
00183
00184 return reply.value();
00185 }
00186
00187 bool BluezBluetoothRemoteDevice::boolReply(const QString &method) const
00188 {
00189 QDBusReply< bool > reply = device->call(method, m_address);
00190 if (!reply.isValid())
00191 return false;
00192
00193 return reply.value();
00194 }
00195
00196 void BluezBluetoothRemoteDevice::dbusErrorServiceDiscover(const QDBusError &error)
00197 {
00198 kDebug() << "Error on dbus call for DiscoverServices: " << error.message();
00199 emit serviceDiscoverAvailable("failed",QMap<uint,QString>());
00200 }
00201
00202 void BluezBluetoothRemoteDevice::slotPropertyChanged(const QString &prop, const QDBusVariant &value)
00203 {
00204 emit propertyChanged(prop, value.variant());
00205 }
00206
00207 void BluezBluetoothRemoteDevice::slotDisconnectRequested()
00208 {
00209 emit disconnectRequested();
00210 }
00211
00212 void BluezBluetoothRemoteDevice::slotNodeCreated(const QDBusObjectPath &path)
00213 {
00214 emit nodeCreated(path.path());
00215 }
00216
00217 void BluezBluetoothRemoteDevice::slotNodeRemoved(const QDBusObjectPath &path)
00218 {
00219 emit nodeRemoved(path.path());
00220 }
00221
00222
00223 #include "bluez-bluetoothremotedevice.moc"