diff options
author | Kari Oikarinen <kari.oikarinen@qt.io> | 2016-12-08 13:11:36 +0200 |
---|---|---|
committer | Kari Oikarinen <kari.oikarinen@qt.io> | 2016-12-22 08:43:03 +0000 |
commit | 7e1e1889736a5c0f6f6324d0ad8173ff0a8679a8 (patch) | |
tree | cf36d5a059dd76444daa801bcf0df93cf3809054 /libqdb | |
parent | db61153547cb8aafaf374f43932047ea400bd482 (diff) |
Handle host-device version mismatches forward-compatibly
There is no support for multiple versions, but the behavior changes in
this commit should allow adding that in the future. Device responds with
a new Refuse message, if it does not support the requested version.
Change-Id: I8a747654edb1c6efab485808b2692cd9689bd100
Reviewed-by: Samuli Piippo <samuli.piippo@qt.io>
Diffstat (limited to 'libqdb')
-rw-r--r-- | libqdb/protocol/protocol.h | 12 | ||||
-rw-r--r-- | libqdb/protocol/qdbmessage.cpp | 5 | ||||
-rw-r--r-- | libqdb/protocol/qdbmessage.h | 2 |
3 files changed, 18 insertions, 1 deletions
diff --git a/libqdb/protocol/protocol.h b/libqdb/protocol/protocol.h index 4f50ab2..c42c17f 100644 --- a/libqdb/protocol/protocol.h +++ b/libqdb/protocol/protocol.h @@ -21,11 +21,21 @@ #ifndef PROTOCOL_H #define PROTOCOL_H +#include <QtCore/qbytearray.h> +#include <QtCore/qdatastream.h> + #include <cstdint> const int qdbHeaderSize = 4*sizeof(uint32_t); const int qdbMessageSize = 16*1024; const int qdbMaxPayloadSize = qdbMessageSize - qdbHeaderSize; -const uint32_t qdbProtocolVersion = 0; +const uint32_t qdbProtocolVersion = 1; + +enum class RefuseReason : uint32_t +{ + Invalid = 0, // Never used except for deserialization failure + NotConnected, + UnknownVersion, +}; #endif diff --git a/libqdb/protocol/qdbmessage.cpp b/libqdb/protocol/qdbmessage.cpp index 7f30808..42e48da 100644 --- a/libqdb/protocol/qdbmessage.cpp +++ b/libqdb/protocol/qdbmessage.cpp @@ -114,6 +114,8 @@ QdbMessage::CommandType toCommandType(uint32_t command) switch (command) { case static_cast<uint32_t>(QdbMessage::Connect): return QdbMessage::Connect; + case static_cast<uint32_t>(QdbMessage::Refuse): + return QdbMessage::Refuse; case static_cast<uint32_t>(QdbMessage::Open): return QdbMessage::Open; case static_cast<uint32_t>(QdbMessage::Write): @@ -167,6 +169,9 @@ QDebug &operator<<(QDebug &stream, ::QdbMessage::CommandType command) case QdbMessage::Connect: stream << "Connect"; break; + case QdbMessage::Refuse: + stream << "Refuse"; + break; case QdbMessage::Open: stream << "Open"; break; diff --git a/libqdb/protocol/qdbmessage.h b/libqdb/protocol/qdbmessage.h index 99c57bb..56e6dd9 100644 --- a/libqdb/protocol/qdbmessage.h +++ b/libqdb/protocol/qdbmessage.h @@ -42,6 +42,7 @@ public: { Invalid = 0, // never sent Connect = 0x434e584e, // CNXN + Refuse = 0x52465345, // RFSE Open = 0x4f50454e, // OPEN Write = 0x57525445, // WRTE Close = 0x434c5345, // CLSE @@ -75,6 +76,7 @@ private: Q_DECLARE_METATYPE(QdbMessage::CommandType) QT_BEGIN_NAMESPACE +QDebug &operator<<(QDebug &stream, ::QdbMessage::CommandType command); QDebug &operator<<(QDebug &stream, const ::QdbMessage &message); QDataStream &operator<<(QDataStream &stream, const ::QdbMessage &message); |