sdbcommandexecutor.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 TIZENUTILS_SDBCOMMANDEXECUTOR_H
  29. #define TIZENUTILS_SDBCOMMANDEXECUTOR_H
  30. #include "tizenutils_global.h"
  31. #include "sdbconnector.h"
  32. #include <QPointer>
  33. #include <QIODevice>
  34. namespace Tizen {
  35. class TIZENUTILS_EXPORT SdbCommandExecutor : public QIODevice
  36. {
  37. Q_OBJECT
  38. public:
  39. SdbCommandExecutor(SdbConnector * connector, QObject * parent = 0);
  40. virtual ~SdbCommandExecutor();
  41. virtual bool atEnd() const;
  42. virtual qint64 bytesAvailable() const;
  43. virtual bool canReadLine() const;
  44. virtual void close();
  45. virtual bool isSequential() const;
  46. signals:
  47. void started();
  48. void finished();
  49. void failed();
  50. public slots:
  51. void start(const QString& deviceId, const QString& command);
  52. protected:
  53. virtual qint64 readData(char *data, qint64 maxlen);
  54. virtual qint64 writeData(const char *data, qint64 len);
  55. private slots:
  56. void socketReadyRead();
  57. void socketConnected();
  58. void socketDisconnected();
  59. void socketError(QAbstractSocket::SocketError error);
  60. private:
  61. enum State {
  62. Disconnected,
  63. Connecting,
  64. WaitForInitResponse,
  65. WaitForExecResponse,
  66. Disconnecting,
  67. Running
  68. };
  69. QPointer<SdbConnector> m_connector;
  70. QTcpSocket * m_socket;
  71. QByteArray m_buffer;
  72. State m_state;
  73. QString m_command;
  74. QString m_deviceId;
  75. QByteArray m_cmdBuffer;
  76. };
  77. } // namespace Tizen
  78. #endif // TIZENUTILS_SDBCOMMANDEXECUTOR_H