sdbconnector.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2013 Jarek Pelczar <jpelczar@gmail.com>
  4. ** Copyright (C) 2014 Tomasz Olszak <olszak.tomasz@gmail.com>
  5. **
  6. ** This file is part of Qt Creator.
  7. **
  8. ** Commercial License Usage
  9. ** Licensees holding valid commercial Qt licenses may use this file in
  10. ** accordance with the commercial license agreement provided with the
  11. ** Software or, alternatively, in accordance with the terms contained in
  12. ** a written agreement between you and Digia. For licensing terms and
  13. ** conditions see http://qt.digia.com/licensing. For further information
  14. ** use the contact form at http://qt.digia.com/contact-us.
  15. **
  16. ** GNU Lesser General Public License Usage
  17. ** Alternatively, this file may be used under the terms of the GNU Lesser
  18. ** General Public License version 2.1 as published by the Free Software
  19. ** Foundation and appearing in the file LICENSE.LGPL included in the
  20. ** packaging of this file. Please review the following information to
  21. ** ensure the GNU Lesser General Public License version 2.1 requirements
  22. ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
  23. **
  24. ** In addition, as a special exception, Digia gives you certain additional
  25. ** rights. These rights are described in the Digia Qt LGPL Exception
  26. ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
  27. **
  28. ****************************************************************************/
  29. #ifndef SDBCONNECTOR_H
  30. #define SDBCONNECTOR_H
  31. #include "sdbpacketutils.h"
  32. #include <QProcess>
  33. #include <QTcpSocket>
  34. #include <QTimer>
  35. #include <QLoggingCategory>
  36. namespace Tizen {
  37. namespace Internal {
  38. enum SdbState {
  39. SdbDisconnected,
  40. SdbConnecting,
  41. SdbConnected,
  42. SdbDisconnecting,
  43. SdbRestarting,
  44. SdbError
  45. };
  46. class SdbDevice
  47. {
  48. public:
  49. enum State {
  50. Offline,
  51. Device,
  52. Unknown
  53. };
  54. QByteArray serialNumber;
  55. QString name;
  56. State state;
  57. };
  58. typedef QList<SdbDevice> SdbDeviceList;
  59. class SdbConnector : public QObject
  60. {
  61. Q_OBJECT
  62. public:
  63. explicit SdbConnector(QObject *parent = 0);
  64. virtual ~SdbConnector();
  65. int serverPort() const;
  66. void setServerPort(int port);
  67. QString sdbPath() const;
  68. void setSdbPath(const QString& path);
  69. SdbState state() const;
  70. QTcpSocket * createChannel(QObject * parent = 0);
  71. public slots:
  72. void startConnector();
  73. void stopConnector();
  74. signals:
  75. void stateChanged(SdbState state);
  76. void deviceListUpdated(SdbDeviceList);
  77. private slots:
  78. void startConnecting();
  79. void _q_tcpConnected();
  80. void _q_readyRead();
  81. void _q_tcpDisconnected();
  82. void _q_socketError(QAbstractSocket::SocketError);
  83. void _q_finished(int exitCode, QProcess::ExitStatus exitStatus);
  84. void _q_startWaitTimeout();
  85. void _q_commandTimeout();
  86. private:
  87. QTcpSocket *m_socket;
  88. QProcess *m_sdbProcess;
  89. SdbState m_state;
  90. QString m_sdbPath;
  91. int m_sdbPort;
  92. QTimer *m_startWait;
  93. int m_retry;
  94. enum ProtoState {
  95. WaitingForDeviceListResp,
  96. WaitingForDeviceListHeader,
  97. WaitingForDeviceListData
  98. };
  99. ProtoState m_protoState;
  100. int m_packetLength;
  101. QTimer *m_commandResponseTimer;
  102. };
  103. } // namespace Internal
  104. } // namespace Tizen
  105. #endif // SDBCONNECTOR_H