File indexing completed on 2024-09-08 06:47:58
0001 /* 0002 SPDX-FileCopyrightText: 2007 Paolo Capriotti <p.capriotti@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef KBATTLESHIP_PROTOCOL_H 0008 #define KBATTLESHIP_PROTOCOL_H 0009 0010 #include <QString> 0011 #include <QTimer> 0012 #include <QQueue> 0013 0014 #include "message.h" 0015 0016 class QTcpSocket; 0017 0018 class Protocol : public QObject 0019 { 0020 Q_OBJECT 0021 QTcpSocket* m_device; 0022 QString m_buffer; 0023 QQueue<MessagePtr> m_message_queue; 0024 QTimer m_timer; 0025 0026 MessagePtr parseMessage(const QString& xmlMessage); 0027 public: 0028 explicit Protocol(QTcpSocket* device); 0029 0030 void send(const MessagePtr& msg); 0031 private Q_SLOTS: 0032 void readMore(); 0033 void sendNext(); 0034 void processDisconnection(); 0035 Q_SIGNALS: 0036 void received(const MessagePtr&); 0037 void parseError(const QString&); 0038 void disconnected(); 0039 }; 0040 0041 #endif // KBATTLESHIP_PROTOCOL_H