qserialsocket.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /****************************************************************************
  2. **
  3. ** This file is part of the Qt Extended Opensource Package.
  4. **
  5. ** Copyright (C) 2009 Trolltech ASA.
  6. **
  7. ** Contact: Qt Extended Information (info@qtextended.org)
  8. **
  9. ** This file may be used under the terms of the GNU General Public License
  10. ** version 2.0 as published by the Free Software Foundation and appearing
  11. ** in the file LICENSE.GPL included in the packaging of this file.
  12. **
  13. ** Please review the following information to ensure GNU General Public
  14. ** Licensing requirements will be met:
  15. ** http://www.fsf.org/licensing/licenses/info/GPLv2.html.
  16. **
  17. **
  18. ****************************************************************************/
  19. #ifndef QSERIALSOCKET_H
  20. #define QSERIALSOCKET_H
  21. #include "qserialiodevice.h"
  22. class QTcpSocket;
  23. class QTcpServer;
  24. class QSerialSocketPrivate;
  25. class QSerialSocket : public QSerialIODevice
  26. {
  27. Q_OBJECT
  28. friend class QSerialSocketServer;
  29. private:
  30. QSerialSocket( QTcpSocket *socket );
  31. public:
  32. QSerialSocket( const QString& host, quint16 port, QObject *parent = 0 );
  33. ~QSerialSocket();
  34. bool open( OpenMode mode );
  35. void close();
  36. bool waitForReadyRead(int msecs);
  37. qint64 bytesAvailable() const;
  38. bool dtr() const;
  39. void setDtr( bool value );
  40. bool dsr() const;
  41. bool carrier() const;
  42. bool setCarrier( bool value );
  43. bool rts() const;
  44. void setRts( bool value );
  45. bool cts() const;
  46. void discard();
  47. bool isValid() const;
  48. signals:
  49. void closed();
  50. protected:
  51. qint64 readData( char *data, qint64 maxlen );
  52. qint64 writeData( const char *data, qint64 len );
  53. private slots:
  54. void socketReadyRead();
  55. void socketClosed();
  56. private:
  57. QSerialSocketPrivate *d;
  58. void init();
  59. void sendModemSignal( int ch );
  60. void sendCommand( const char *buf, int len );
  61. void sendDo( int option );
  62. void sendDont( int option );
  63. void sendWill( int option );
  64. void sendWont( int option );
  65. void sendSubOption( int option, const char *buf, int len );
  66. void initTelnet();
  67. void receiveModemSignal( int ch );
  68. void receiveDo( int option );
  69. void receiveDont( int option );
  70. void receiveWill( int option );
  71. void receiveWont( int option );
  72. void receiveSubOption( int option, const char *buf, int len );
  73. };
  74. class QSerialSocketServer : public QObject
  75. {
  76. Q_OBJECT
  77. public:
  78. explicit QSerialSocketServer( quint16 port, bool localHostOnly = true,
  79. QObject *parent = 0 );
  80. ~QSerialSocketServer();
  81. bool isListening() const;
  82. quint16 port() const;
  83. signals:
  84. void incoming( QSerialSocket *socket );
  85. private slots:
  86. void newConnection();
  87. private:
  88. QTcpServer *server;
  89. };
  90. #endif