SolidModules
bluez-bluetoothmanager.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-bluetoothmanager.h"
00024
00025 #include <QtDBus>
00026
00027 #include <kdebug.h>
00028
00029 #include "bluez-bluetoothinterface.h"
00030 #include "bluez-bluetoothinputdevice.h"
00031 #include "bluez-bluetoothsecurity.h"
00032 #include "bluez-bluetoothsecurityadaptor.h"
00033 #include "bluezcalljob.h"
00034
00035 class BluezBluetoothManagerPrivate
00036 {
00037 public:
00038
00039
00040 BluezBluetoothManagerPrivate() : manager("org.bluez", "/", "org.bluez.Manager", QDBusConnection::systemBus())
00041 {}
00042
00043 QDBusInterface manager;
00044
00045
00046 QMap<QString, BluezBluetoothInterface *> interfaces;
00047
00048
00049 };
00050
00051 BluezBluetoothManager::BluezBluetoothManager(QObject * parent, const QStringList & )
00052 : BluetoothManager(parent), d(new BluezBluetoothManagerPrivate)
00053 {
00054 #define connectManagerToThis(signal, slot) \
00055 d->manager.connection().connect("org.bluez", \
00056 "/", \
00057 "org.bluez.Manager", \
00058 signal, this, SLOT(slot));
00059 connectManagerToThis("AdapterAdded", slotDeviceAdded(const QDBusObjectPath &));
00060 connectManagerToThis("AdapterRemoved", slotDeviceRemoved(const QDBusObjectPath &));
00061 connectManagerToThis("DefaultAdapterChanged", slotDefaultDeviceChanged(const QDBusObjectPath &));
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083 }
00084
00085 BluezBluetoothManager::~BluezBluetoothManager()
00086 {
00087
00088 delete d;
00089 }
00090
00091 QStringList BluezBluetoothManager::bluetoothInterfaces() const
00092 {
00093 QStringList bluetoothInterfaces;
00094
00095 QDBusReply< QList<QDBusObjectPath> > deviceList = d->manager.call("ListAdapters");
00096 if (deviceList.isValid()) {
00097 QList<QDBusObjectPath> devices = deviceList.value();
00098 foreach (const QDBusObjectPath& path, devices) {
00099 bluetoothInterfaces.append(path.path());
00100 }
00101 }
00102 return bluetoothInterfaces;
00103 }
00104
00105 QString BluezBluetoothManager::defaultInterface() const
00106 {
00107 kDebug() << "Calling Backend Default Interface";
00108 QDBusReply< QDBusObjectPath > path = d->manager.call("DefaultAdapter");
00109 if (!path.isValid())
00110 return QString();
00111
00112 return path.value().path();
00113 }
00114
00115 QString BluezBluetoothManager::findInterface(const QString &adapterName) const
00116 {
00117 QDBusReply< QDBusObjectPath > devicePath = d->manager.call("FindAdapter",adapterName);
00118 if (!devicePath.isValid())
00119 return QString();
00120
00121 return devicePath.value().path();
00122 }
00123
00124 QObject * BluezBluetoothManager::createInterface(const QString & ubi)
00125 {
00126 BluezBluetoothInterface * bluetoothInterface;
00127 if (d->interfaces.contains(ubi)) {
00128 bluetoothInterface = d->interfaces[ubi];
00129 } else {
00130 bluetoothInterface = new BluezBluetoothInterface(ubi);
00131 d->interfaces.insert(ubi, bluetoothInterface);
00132 }
00133 return bluetoothInterface;
00134 }
00135
00136 void BluezBluetoothManager::removeInterface(const QString& ubi)
00137 {
00138
00139 if (d->interfaces.contains(ubi)) {
00140 kDebug() << "Removing Interface" << ubi;
00141 BluezBluetoothInterface * bluetoothInterface = d->interfaces.take(ubi);
00142 bluetoothInterface = 0;
00143 }
00144 }
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192 void BluezBluetoothManager::slotDeviceAdded(const QDBusObjectPath &adapter)
00193 {
00194
00195 kDebug() << "interfaceAdded " << adapter.path();
00196 emit interfaceAdded(adapter.path());
00197 }
00198
00199 void BluezBluetoothManager::slotDeviceRemoved(const QDBusObjectPath &adapter)
00200 {
00201 kDebug() << "interfaceRemoved " << adapter.path();
00202 emit interfaceRemoved(adapter.path());
00203 }
00204
00205 void BluezBluetoothManager::slotDefaultDeviceChanged(const QDBusObjectPath &adapter)
00206 {
00207 kDebug() << "defaultDeviceChanged " << adapter.path();
00208 emit defaultInterfaceChanged(adapter.path());
00209 }
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238 #include "bluez-bluetoothmanager.moc"
00239
00240