From 6f4fb557610beccb225a6bf3d46c0118b221bd99 Mon Sep 17 00:00:00 2001 From: sr Date: Tue, 5 Feb 2013 17:28:19 +0100 Subject: [SERVER] Implement all four VNC projection modes --- src/shared/networkmessage.h | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'src/shared/networkmessage.h') diff --git a/src/shared/networkmessage.h b/src/shared/networkmessage.h index 5a8b2c2..0df51df 100644 --- a/src/shared/networkmessage.h +++ b/src/shared/networkmessage.h @@ -13,8 +13,8 @@ class QAbstractSocket; class QUdpSocket; -// define qstrings for message ids. this prevents implicit instanciation of the same qstrings over and over again -#define MSGTYPE(name) static const QString _ ## name ( #name ) +// define QByteArrays for message ids. this prevents implicit instantiation of the same QByteArray over and over again +#define MSGTYPE(name) static const QByteArray _ ## name ( #name ) MSGTYPE(ID); MSGTYPE(IMG); MSGTYPE(LOGIN); @@ -31,14 +31,21 @@ MSGTYPE(IPLIST); MSGTYPE(PORT); MSGTYPE(CERT); MSGTYPE(CHALLENGE); +MSGTYPE(ENABLE); MSGTYPE(ERROR); +MSGTYPE(TUTOR); + + +static const QByteArray __TRUE("1"); +static const QByteArray __FALSE("0"); +static const inline QByteArray& _BOOL(bool val) { if (val) return __TRUE; return __FALSE; } class NetworkMessage { private: char *_buffer; quint32 _bufferSize, _bufferPos, _lastBufferSize; - QHash _fields; + QHash _fields; int _mode; // 0 = none, 1 = reading, 2 = writing, 3 = read complete, 4 = write complete void allocBuffer(); @@ -56,11 +63,11 @@ public: void reset() { _fields.clear(); _bufferSize = 0; _mode = 0; } const bool readComplete() const { return _mode == 3; } const bool writeComplete() const { return _mode == 4; } - const bool hasField(const QString& key) const { return _fields.contains(key); } - const QString getFieldString(const QString& key) const { return QString::fromUtf8(_fields.value(key)); } - const QByteArray getFieldBytes(const QString& key) const { return _fields.value(key); } - void setField(const QString& key, const QByteArray& value) { if (_mode == 1 || _mode == 2) qFatal("setField called in bad state."); _fields.insert(key, value); _mode = 0; } - void setField(const QString& key, const QString& value) { setField(key, value.toUtf8()); } + const bool hasField(const QByteArray& key) const { return _fields.contains(key); } + const QString getFieldString(const QByteArray& key) const { return QString::fromUtf8(_fields.value(key)); } + const QByteArray getFieldBytes(const QByteArray& key) const { return _fields.value(key); } + void setField(const QByteArray& key, const QByteArray& value) { if (_mode == 1 || _mode == 2) qFatal("setField called in bad state."); _fields.insert(key, value); _mode = 0; } + void setField(const QByteArray& key, const QString& value) { setField(key, value.toUtf8()); } // Convenience void buildErrorMessage(const QString& error); void buildErrorMessage(const char* error); -- cgit v1.2.3-55-g7522