1 /* This file is part of the KDE project
2 Copyright (C) 2006 Will Stephenson <wstephenson@kde.org>
3 Copyright (C) 2007 Daniel Gollub <dgollub@suse.de>
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License version 2 as published by the Free Software Foundation.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
22 #ifndef SOLID_CONTROL_BLUETOOTHINTERFACE_H
23 #define SOLID_CONTROL_BLUETOOTHINTERFACE_H
25 #include <QtCore/QDateTime>
26 #include <QtCore/QPair>
27 #include <QtCore/QObject>
28 #include <QtCore/QMap>
30 #include "bluetoothremotedevice.h"
31 #include "bluetoothinputdevice.h"
32 #include "ifaces/bluetoothremotedevice.h"
33 #include "ifaces/bluetoothinputdevice.h"
41 class BluetoothRemoteDevice
;
42 typedef QList
<BluetoothRemoteDevice
*> BluetoothRemoteDeviceList
;
43 class BluetoothInterfacePrivate
;
46 * Represents a bluetooth interface as seen by the bluetooth subsystem.
48 class SOLIDCONTROL_EXPORT BluetoothInterface
: public QObject
55 * Describes the operating mode of a bluetooth interface
57 * - Off : The interface's transceiver is turned off
58 * - Discoverable : The interface may be discovered by other devices and connected to
59 * - Connectable : The interface may only be connected to but not discovered
61 //enum Mode { Off, Discoverable, Connectable };
65 * Constructs an invalid bluetooth interface
72 * Constructs a bluetooth interface for a given Unique Bluetooth Identifier (UBI).
73 * This object will be auto deleted, DON'T delete it.
74 * @param ubi the ubi of the bluetooth interface to create
76 explicit BluetoothInterface(const QString
&ubi
);
79 * Constructs a new bluetooth interface taking its data from a backend.
81 * @param backendObject the object given by the backend
83 explicit BluetoothInterface(QObject
*backendObject
);
86 * Constructs a copy of a bluetooth interface.
88 * @param device the bluetooth interface to copy
90 BluetoothInterface(const BluetoothInterface
&device
);
93 * Destroys the device.
95 ~BluetoothInterface();
99 * Assigns a bluetooth interface to this bluetooth interface and returns a reference to it.
101 * @param device the bluetooth interface to assign
102 * @return a reference to the bluetooth interface
104 BluetoothInterface
&operator=(const BluetoothInterface
&device
);
107 * Retrieves the Unique Bluetooth Identifier (UBI) of the BluetoothInterface.
108 * This identifier is ubique for each bluetooth and bluetooth interface in the system.
110 * @returns the Unique Bluetooth Identifier of the current bluetooth interface
115 * Create new BluetoothRemoteDevice object from this interface given its address.
117 * @param ubi the identifier of the bluetooth device to instantiate
118 * @returns a bluetooth object, if a bluetooth device having the given UBI, for this interface exists, 0 otherwise
120 //Solid::Control::BluetoothRemoteDevice* createBluetoothRemoteDevice(const QString &address);
121 void createBluetoothRemoteDevice(const QString
&address
);
124 * Finds a BluetoothRemoteDevice object given its UBI.
126 * @param ubi the identifier of the bluetooth remote device to find from this bluetooth interface
127 * @returns a valid BluetoothRemoteDevice object if a remote device having the given UBI for this interface exists, an invalid BluetoothRemoteDevice object otherwise.
129 const QString
getBluetoothRemoteDeviceUBI(const QString
&address
) const;
131 Solid::Control::BluetoothRemoteDevice
findBluetoothRemoteDeviceAddr(const QString
&addr
) const;
133 Solid::Control::BluetoothRemoteDevice
* findBluetoothRemoteDeviceUBI(const QString
&ubi
) const;
135 Solid::Control::BluetoothInputDevice
* findBluetoothInputDeviceUBI(const QString
&ubi
) const;
138 * Retrieves the MAC address of the bluetooth interface/adapter.
140 * @returns MAC address of bluetooth interface
142 QString
address() const;
145 * Retrieves the version of the chip of the bluetooth interface/adapter.
146 * Example: "Bluetooth 2.0 + EDR"
148 * @returns bluetooth chip version
150 //QString version() const;
153 * Retrieves the revision of the chip of the bluetooth interface/adapter.
154 * Example: "HCI 19.2"
156 * @returns bluetooth chip revision
158 //QString revision() const;
161 * Retrieves the name of the bluetooth chip manufacturer.
162 * Example: "Boston Silicon Radio"
164 * @returns manufacturer string of bluetooth interface/adapter
166 //QString manufacturer() const;
169 * Retrieves the name of the manufacturer of the bluetooth interface,
170 * using the chip supplied by BluetoothInterface::manufacterer()
171 * Based on device address.
173 * @returns company string of bluetooth interface/adapter
175 //QString company() const;
178 * Retrieves the discoverable timeout of the bluetooth interface/adapter.
179 * Discoverable timeout of 0 means never disappear.
181 * @returns current discoverable timeout in seconds
183 int discoverableTimeout() const;
186 * Retrieves the current discoverable staut of the bluetooth interface/adapter.
188 * @returns current discoverable status of bluetooth interface/adapter
190 bool isDiscoverable() const;
193 * Retrieves the current status of a discovering session for the adapter.
195 * @returns true if a discovering session is running for the adapter
197 bool isDiscovering() const;
201 * List all UBIs of connected remote bluetooth devices of this handled bluetooth
204 * @returns list UBIs of connected bluetooth remote devices
206 //BluetoothRemoteDeviceList listConnections() const;
209 * Retrieves major class of the bluetooth interface/adapter.
211 * @returns current major class of the bluetooth interface/adapter
213 //QString majorClass() const;
216 * List supported minor classes of the bluetooth interface/adapter.
219 * @returns list of supported minor classes by bluetooth interface/adapter
221 //QStringList listAvailableMinorClasses() const;
224 * Retrieves minor class of the bluetooth interface/adapter.
225 * Valid classes, see listAvailableMinorClasses()
228 * @returns minor class of the bluetooth interface/adapter.
230 //QString minorClass() const;
233 * List services class of the bluetooth interface/adapter.
236 * @returns list of service classes or empty list if no services registered
238 //QStringList serviceClasses() const;
241 * Retrieves name of bluetooth interface/adapter.
244 * @returns name of bluetooth interface/adapter
246 QString
name() const;
249 * Returns the name of the remote device, given its mac address (mac).
251 * @return the name of the remote device
253 //QString getRemoteName(const QString & mac);
256 * List UBIs of bonded/paired remote bluetooth devices with this bluetooth
259 * @returns UBIs of bonded/paired bluetooth remote devices
261 //QStringList listBondings() const;
264 * Periodic discovery status of this bluetooth interface/adapter.
266 * @returns true if periodic discovery is already active otherwise false
268 // bool isPeriodicDiscoveryActive() const;
271 * Name resolving status of periodic discovery routing.
273 * @returns true if name got resolved while periodic discovery of this bluetooth
276 //bool isPeriodicDiscoveryNameResolvingActive() const;
279 * List the Unique Bluetooth Identifier (UBI) of all known remote devices,
280 * whether they are seen, used or paired/bonded.
282 * See listConnections()
284 * @returns a QStringList of UBIs of all known remote bluetooth devices
286 //QStringList listRemoteDevices() const;
289 * List the Unique Bluetooth Identifier (UBI) of all known remote devices since a specific
290 * datestamp. Known remote devices means remote bluetooth which are seen, used or
293 * See listConnections(), listRemoteDevices()
295 * @param date the datestamp of the beginning of recent used devices
296 * @returns a QStringList of UBIs of all known remote bluetooth devices
298 // QStringList listRecentRemoteDevices(const QDateTime &date) const;
301 * Returns true if the remote bluetooth device is trusted otherwise false.
303 * @param mac the address of the remote device
305 // bool isTrusted(const QString &);
308 void createPairedDevice(const QString
&, const QString
&, const QString
&) const;
310 QMap
< QString
, QVariant
> getProperties() const;
312 BluetoothRemoteDeviceList
listDevices() const;
319 * Set the discoverable state of the interface/adapter.
321 * @param status the discoverable state of the bluetooth interface/adapter
323 void setDiscoverable(bool status
);
326 * Set discoverable timeout of bluetooth interface/adapter.
328 * @param timeout timeout in seconds
330 void setDiscoverableTimeout(int timeout
);
333 * Set minor class of bluetooth interface/adapter.
335 * @param minor set minor class. Valid mode see listAvaliableMinorClasses()
337 //void setMinorClass(const QString &minor);
340 * Set name of bluetooth interface/adapter.
342 * @param name the name of bluetooth interface/adapter
344 void setName(const QString
&name
);
347 * Start discovery of remote bluetooth devices with device name resolving.
349 //void discoverDevices();
351 * Start discovery of remote bluetooth devices without device name resolving.
353 //void discoverDevicesWithoutNameResolving();
355 * Cancel discovery of remote bluetooth devices.
357 //void cancelDiscovery();
360 * Start periodic discovery of remote bluetooth devices.
361 * See stopPeriodicDiscovery()
363 //void startPeriodicDiscovery();
366 * Stop periodic discovery of remote bluetooth devices.
368 //void stopPeriodicDiscovery();
371 * Enable/Disable name resolving of remote bluetooth devices in periodic discovery.
373 * @param resolveName true to enable name resolving otherwise false
375 //void setPeriodicDiscoveryNameResolving(bool resolveNames);
378 * Marks the device as trusted.
380 * @param mac the address of the remote device
382 //void setTrusted(const QString &);
385 * Marks the device as not trusted.
387 * @param mac the address of the remote device
389 //void removeTrust(const QString &);
391 void registerAgent(const QString
&,const QString
&) const;
393 void releaseSession() const;
395 void removeDevice(const QString
&) const;
397 void requestSession() const;
399 void setProperty(const QString
&, const QVariant
&) const;
401 void startDiscovery() const;
403 void stopDiscovery() const;
405 void unregisterAgent(const QString
&) const;
407 void cancelDeviceCreation(const QString
&) const;
413 * This signal is emitted if the mode of the bluetooth interface/adapter has changed.
414 * See mode() for valid modes.
416 * @param mode the changed mode
418 //void modeChanged(Solid::Control::BluetoothInterface::Mode);
421 * The signal is emitted if the discoverable timeout of the bluetooth interface/adapter
424 * @param timeout the changed timeout in seconds
426 //void discoverableTimeoutChanged(int timeout);
429 * The signal is emitted if the minor class of the bluetooth interface/adapter has changed.
431 * @param minor the new minor class
433 //void minorClassChanged(const QString &minor);
436 * The signal is emitted if the name of the bluetooth interface/adapter has changed.
438 * @param name the new name of the device
440 //void nameChanged(const QString &name);
443 * This signal is emitted if a discovery has started.
445 //void discoveryStarted();
448 * This signal is emitted if a discovery has completed.
450 //void discoveryCompleted();
453 * This signal is emitted if the bluetooth interface/adapter detects a new remote bluetooth device.
455 * @todo change arguments types of deviceClass (uint32) and rssi (int16)
457 * @param ubi the new bluetooth identifier
458 * @param deviceClass the device class of the remote device
459 * @param rssi the Received Signal Strength Information (RSSI) of the remote device
461 //void remoteDeviceFound(const QString &ubi, int deviceClass, int rssi);
464 * This signal is emitted if the bluetooth interface/adapter detectes a bluetooth device
467 * @param ubi the ubi of the disappering bluetooth remote device
469 //void remoteDeviceDisappeared(const QString &ubi);
472 * This signal is emitted if the bluetooth interface/adapter detectes a new name for a
475 * @param address the address of the bluetooth remote device
476 * @param name the name of the bluetooth remote device
478 //void remoteNameUpdated(const QString &address, const QString &name);
481 * This signal is emitted if a bluetooth connection has been created.
483 * @param address the address of the connected bluetooth remote device
485 //void remoteDeviceConnected(const QString &address);
488 * This signal is emitted if a bluetooth connection has been terminated.
490 * @param address the address of the disconnected bluetooth remote device
492 //void remoteDeviceDisconnected(const QString &address);
495 * This signal is emitted if a bluetooth device was set trusted.
497 * @param address the address of the trusted bluetooth remote device
499 //void trustAdded(const QString &address);
502 * This signal is emitted if the trust to the bluetooth device was removed.
504 * @param address the address of the bluetooth remote device
506 //void trustRemoved(const QString &address);
509 * This signal is emitted if a successful bonding has been created.
511 * @param address the address of the bluetooth remote device
513 //void bondingCreated(const QString &address);
516 * This signal is emitted if the bonding to a bluetooth device has been removed.
518 * @param address the address of the bluetooth remote device
520 //void bondingRemoved(const QString &address);
522 * This signal is emitted when a remote device is created.
524 * @param ubi the object path of the device on the system bus
526 void deviceCreated(const QString
&ubi
);
529 * This signal is emitted when an inquiry session for a periodic discovery finishes and previously found
530 * devices are no longer in range or visible.
532 * @param address the address of the remote device
534 void deviceDisappeared(const QString
&address
);
537 * This signal will be emitted every time an inquiry result has been found by the service daemon.
538 * In general they only appear during a device discovery.
540 * @param address the address of the remote device
541 * @param properties the properties of the remote device
543 void deviceFound(const QString
&address
, const QMap
< QString
, QVariant
> &properties
);
546 * This signal is emitted when a remote device is removed from the system bus.
548 * @param ubi the object path on the system bus from the remote device
550 void deviceRemoved(const QString
&ubi
);
553 * This signal is emitted when a property of the adapter is set to a new value.
555 * @param property the named property of the adapter
556 * @value the new value for the property
558 void propertyChanged(const QString
&property
, const QVariant
&value
);
564 Q_PRIVATE_SLOT(d
, void _k_destroyed(QObject
*))
566 QVariant
getProperty(const QString
&) const;
567 BluetoothInterfacePrivate
* const d
;
570 void slotDeviceCreated(const QString
& ubi
);