sdbconnector.h 3.1 KB

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