diff options
Diffstat (limited to 'common/commands.cpp')
-rw-r--r-- | common/commands.cpp | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/common/commands.cpp b/common/commands.cpp index ce83d03..eeb7f08 100644 --- a/common/commands.cpp +++ b/common/commands.cpp | |||
@@ -21,6 +21,7 @@ | |||
21 | #include "commands.h" | 21 | #include "commands.h" |
22 | 22 | ||
23 | #include <QIODevice> | 23 | #include <QIODevice> |
24 | #include <log.h> | ||
24 | 25 | ||
25 | namespace Sink { | 26 | namespace Sink { |
26 | 27 | ||
@@ -77,27 +78,34 @@ void write(QIODevice *device, int messageId, int commandId) | |||
77 | write(device, messageId, commandId, 0, 0); | 78 | write(device, messageId, commandId, 0, 0); |
78 | } | 79 | } |
79 | 80 | ||
81 | static void write(QIODevice *device, const char *buffer, uint size) | ||
82 | { | ||
83 | if (device->write(buffer, size) < 0) { | ||
84 | SinkWarningCtx(Sink::Log::Context{"commands"}) << "Error while writing " << device->errorString(); | ||
85 | } | ||
86 | } | ||
87 | |||
80 | void write(QIODevice *device, int messageId, int commandId, const char *buffer, uint size) | 88 | void write(QIODevice *device, int messageId, int commandId, const char *buffer, uint size) |
81 | { | 89 | { |
82 | if (size > 0 && !buffer) { | 90 | if (size > 0 && !buffer) { |
83 | size = 0; | 91 | size = 0; |
84 | } | 92 | } |
85 | 93 | ||
86 | device->write((const char *)&messageId, sizeof(int)); | 94 | write(device, (const char *)&messageId, sizeof(int)); |
87 | device->write((const char *)&commandId, sizeof(int)); | 95 | write(device, (const char *)&commandId, sizeof(int)); |
88 | device->write((const char *)&size, sizeof(uint)); | 96 | write(device, (const char *)&size, sizeof(uint)); |
89 | if (buffer) { | 97 | if (buffer) { |
90 | device->write(buffer, size); | 98 | write(device, buffer, size); |
91 | } | 99 | } |
92 | } | 100 | } |
93 | 101 | ||
94 | void write(QIODevice *device, int messageId, int commandId, flatbuffers::FlatBufferBuilder &fbb) | 102 | void write(QIODevice *device, int messageId, int commandId, flatbuffers::FlatBufferBuilder &fbb) |
95 | { | 103 | { |
96 | const int dataSize = fbb.GetSize(); | 104 | const int dataSize = fbb.GetSize(); |
97 | device->write((const char *)&messageId, sizeof(int)); | 105 | write(device, (const char *)&messageId, sizeof(int)); |
98 | device->write((const char *)&commandId, sizeof(int)); | 106 | write(device, (const char *)&commandId, sizeof(int)); |
99 | device->write((const char *)&dataSize, sizeof(int)); | 107 | write(device, (const char *)&dataSize, sizeof(int)); |
100 | device->write((const char *)fbb.GetBufferPointer(), dataSize); | 108 | write(device, (const char *)fbb.GetBufferPointer(), dataSize); |
101 | } | 109 | } |
102 | 110 | ||
103 | } // namespace Commands | 111 | } // namespace Commands |