btserialportclient.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /**********************************************************************
  2. ** Copyright (C) 2009 Nokia Corporation.
  3. ** All rights reserved.
  4. **
  5. ** $LICENSE_TEXT$
  6. **********************************************************************/
  7. #ifndef BTSERIALPORTCLIENT_H
  8. #define BTSERIALPORTCLIENT_H
  9. #include <QObject>
  10. class QIODevice;
  11. class QDBusMessage;
  12. class QDBusPendingCallWatcher;
  13. /**
  14. * @brief The BtSerialPortClient class configures a serial bluetooth connection.
  15. *
  16. * It uses Bluez D-Bus interface to bind a serial rfcomm device and provides a QIODevice to encapsulate
  17. * the communication with the device.
  18. */
  19. class BtSerialPortClient: public QObject
  20. {
  21. Q_OBJECT
  22. public:
  23. /**
  24. * Constructs a BtSerialPortClient object with the given parent.
  25. *
  26. * @param parent Parent.
  27. */
  28. explicit BtSerialPortClient(QObject *parent = 0);
  29. /**
  30. * Destructs the BtSerialPortClient object.
  31. */
  32. ~BtSerialPortClient();
  33. /**
  34. * Disconnects bluetooth device.
  35. */
  36. void disconnect();
  37. private:
  38. /**
  39. * Retrieves first argument from QDBusMessage and tries to extract the QDBusObjectPath.
  40. * @param message Return from D-Bus call.
  41. * @return QString with object path.
  42. */
  43. QString firstArgumentToObjectPath(QDBusMessage message);
  44. /**
  45. * Test if errorTest is an error and emits error() signal.
  46. * @param errorTest Boolean indicating if it is an error.
  47. * @return Boolean indicating if it is an error.
  48. */
  49. bool isError(bool errorTest);
  50. /**
  51. * Test if message is a QDBusMessage error and emits error() signal.
  52. * @param message QDBusMessage to be tested.
  53. * @return Boolean indicating if it is an error message.
  54. */
  55. bool isErrorMessage(QDBusMessage message);
  56. signals:
  57. /**
  58. * Signal emitted after serial interface is bounded.
  59. */
  60. void interfaceBounded(QIODevice *serialPort);
  61. /**
  62. * Signal emitted after serial has been disconnected.
  63. */
  64. void disconnected();
  65. /**
  66. * Signal emitted when an error occurs.
  67. */
  68. void error();
  69. private slots:
  70. /**
  71. * Tries to bind a serial connection device and emits an error() signal if unsuccessfull.
  72. */
  73. void setupInterface(QString address);
  74. /**
  75. * Called by D-Bus device connection observer when connection state changes.
  76. *
  77. * In case of disconnection, it disconnects the bluez serial device and emit the disconnected() signal.
  78. * @param message Connection status message.
  79. */
  80. void updateConnectionStatus(const QDBusMessage& message);
  81. /**
  82. * Called after async call to connect DBus method.
  83. * @param watcher Watcher to monitor DBus call.
  84. */
  85. void connectionCallFinishedSlot(QDBusPendingCallWatcher* watcher);
  86. private:
  87. QString m_devicePath;
  88. bool m_isConnected;
  89. };
  90. #endif // BTSERIALPORTCLIENT_H