bluetoothmanager.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /**********************************************************************
  2. ** Copyright (C) 2009 Nokia Corporation.
  3. ** All rights reserved.
  4. **
  5. ** $LICENSE_TEXT$
  6. **********************************************************************/
  7. #ifndef BLUETOOTHMANAGER_H
  8. #define BLUETOOTHMANAGER_H
  9. #include <QObject>
  10. #include <QString>
  11. class QDBusInterface;
  12. class QDBusMessage;
  13. class QIODevice;
  14. class BtSingleDeviceSelector;
  15. class BtSerialPortClient;
  16. /**
  17. * @brief The BluetoothManager class manages steps necessary to provide a Bluetooth connection.
  18. *
  19. * This class initially tries to connect to a default device and, if no success, calls an interface to
  20. * select a new bluetooth device using a BtSingleDeviceSelector. After that, it configures a serial port connection using a BtSerialPortClient.
  21. * @see BtSerialPortClient, BtSingleDeviceSelector
  22. */
  23. class BluetoothManager: public QObject
  24. {
  25. Q_OBJECT
  26. public:
  27. /**
  28. * Constructs a BluetoothManager object with the given parent.
  29. *
  30. * @param parent Parent.
  31. */
  32. explicit BluetoothManager(QObject *parent = 0);
  33. /**
  34. * BluetoothManager destructor
  35. */
  36. ~BluetoothManager();
  37. private:
  38. /**
  39. * Setup QObject connections between this class, a BtSingleDeviceSelector and a BtSerialPortClient.
  40. */
  41. void setupConnections();
  42. signals:
  43. /**
  44. * This signal is emitted after connect() has been called and a connection has been successfully established.
  45. */
  46. void connected();
  47. /**
  48. * This signal is emitted when the bluetooth device has been disconnected.
  49. */
  50. void disconnected();
  51. /**
  52. * This signal is emitted once every time new data is available from the device.
  53. * It will only be emitted again once new data is available.
  54. * @param data Data received from device.
  55. */
  56. void dataReceived(QByteArray data);
  57. /**
  58. * This signal is emitted after a device is defined and the serial connection has to be configured.
  59. */
  60. void deviceDefined(QString device);
  61. public slots:
  62. /**
  63. * Connects to the default device. If it is unavailable, initiates a device selector dialog.
  64. */
  65. void connect();
  66. /**
  67. * Disconnects from the current device.
  68. */
  69. void disconnect();
  70. /**
  71. * Writes the content of data to the device.
  72. * @param data Data to be sent.
  73. */
  74. void sendData(QString data);
  75. private slots:
  76. /**
  77. * Configures a serial connection on device with MAC serialDevice.
  78. * @param serialDevice
  79. */
  80. void setupSerialConnection(QString serialDevice);
  81. /**
  82. * Configures IODevice socket.
  83. * @param device
  84. */
  85. void setupIODevice(QIODevice* device);
  86. /**
  87. * Reads data from IODevice when available, process it, and emits the dataReceived(QString data) signal
  88. * with processed data as a QString.
  89. */
  90. void processNewData();
  91. /**
  92. * Process errors from bluetooth connection.
  93. */
  94. void processError();
  95. /**
  96. * Process disconnection of bluetooth device.
  97. */
  98. void processDisconnected();
  99. private:
  100. BtSingleDeviceSelector *mp_deviceSelector;
  101. BtSerialPortClient *mp_serialClient;
  102. QIODevice *mp_ioDevice;
  103. bool m_isTryingDefault;
  104. };
  105. #endif // BLUETOOTHMANAGER_H