diff options
Diffstat (limited to 'common/resourceaccess.cpp')
-rw-r--r-- | common/resourceaccess.cpp | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/common/resourceaccess.cpp b/common/resourceaccess.cpp index a4f3c94..2f7d207 100644 --- a/common/resourceaccess.cpp +++ b/common/resourceaccess.cpp | |||
@@ -22,6 +22,7 @@ | |||
22 | 22 | ||
23 | #include "common/console.h" | 23 | #include "common/console.h" |
24 | #include "common/commands.h" | 24 | #include "common/commands.h" |
25 | #include "common/commandcompletion_generated.h" | ||
25 | #include "common/handshake_generated.h" | 26 | #include "common/handshake_generated.h" |
26 | #include "common/revisionupdate_generated.h" | 27 | #include "common/revisionupdate_generated.h" |
27 | 28 | ||
@@ -54,10 +55,10 @@ public: | |||
54 | delete[] m_buffer; | 55 | delete[] m_buffer; |
55 | } | 56 | } |
56 | 57 | ||
57 | void write(QIODevice *device) | 58 | void write(QIODevice *device, uint messageId) |
58 | { | 59 | { |
59 | Console::main()->log(QString("\tSending queued command %1").arg(m_commandId)); | 60 | Console::main()->log(QString("\tSending queued command %1").arg(m_commandId)); |
60 | Commands::write(device, m_commandId, m_buffer, m_bufferSize); | 61 | Commands::write(device, messageId, m_commandId, m_buffer, m_bufferSize); |
61 | } | 62 | } |
62 | 63 | ||
63 | private: | 64 | private: |
@@ -80,13 +81,15 @@ public: | |||
80 | QByteArray partialMessageBuffer; | 81 | QByteArray partialMessageBuffer; |
81 | flatbuffers::FlatBufferBuilder fbb; | 82 | flatbuffers::FlatBufferBuilder fbb; |
82 | QVector<QueuedCommand *> commandQueue; | 83 | QVector<QueuedCommand *> commandQueue; |
84 | uint messageId; | ||
83 | }; | 85 | }; |
84 | 86 | ||
85 | ResourceAccess::Private::Private(const QString &name, ResourceAccess *q) | 87 | ResourceAccess::Private::Private(const QString &name, ResourceAccess *q) |
86 | : resourceName(name), | 88 | : resourceName(name), |
87 | socket(new QLocalSocket(q)), | 89 | socket(new QLocalSocket(q)), |
88 | tryOpenTimer(new QTimer(q)), | 90 | tryOpenTimer(new QTimer(q)), |
89 | startingProcess(false) | 91 | startingProcess(false), |
92 | messageId(0) | ||
90 | { | 93 | { |
91 | } | 94 | } |
92 | 95 | ||
@@ -129,7 +132,7 @@ void ResourceAccess::sendCommand(int commandId) | |||
129 | { | 132 | { |
130 | if (isReady()) { | 133 | if (isReady()) { |
131 | log(QString("Sending command %1").arg(commandId)); | 134 | log(QString("Sending command %1").arg(commandId)); |
132 | Commands::write(d->socket, commandId); | 135 | Commands::write(d->socket, ++d->messageId, commandId); |
133 | } else { | 136 | } else { |
134 | d->commandQueue << new QueuedCommand(commandId); | 137 | d->commandQueue << new QueuedCommand(commandId); |
135 | } | 138 | } |
@@ -139,7 +142,7 @@ void ResourceAccess::sendCommand(int commandId, flatbuffers::FlatBufferBuilder & | |||
139 | { | 142 | { |
140 | if (isReady()) { | 143 | if (isReady()) { |
141 | log(QString("Sending command %1").arg(commandId)); | 144 | log(QString("Sending command %1").arg(commandId)); |
142 | Commands::write(d->socket, commandId, fbb); | 145 | Commands::write(d->socket, ++d->messageId, commandId, fbb); |
143 | } else { | 146 | } else { |
144 | d->commandQueue << new QueuedCommand(commandId, fbb); | 147 | d->commandQueue << new QueuedCommand(commandId, fbb); |
145 | } | 148 | } |
@@ -180,7 +183,7 @@ void ResourceAccess::connected() | |||
180 | auto name = d->fbb.CreateString(QString::number((long long)this).toLatin1()); | 183 | auto name = d->fbb.CreateString(QString::number((long long)this).toLatin1()); |
181 | auto command = Akonadi2::CreateHandshake(d->fbb, name); | 184 | auto command = Akonadi2::CreateHandshake(d->fbb, name); |
182 | Akonadi2::FinishHandshakeBuffer(d->fbb, command); | 185 | Akonadi2::FinishHandshakeBuffer(d->fbb, command); |
183 | Commands::write(d->socket, Commands::HandshakeCommand, d->fbb); | 186 | Commands::write(d->socket, ++d->messageId, Commands::HandshakeCommand, d->fbb); |
184 | d->fbb.Clear(); | 187 | d->fbb.Clear(); |
185 | } | 188 | } |
186 | 189 | ||
@@ -188,7 +191,7 @@ void ResourceAccess::connected() | |||
188 | //TODO: serialize instead of blast them all through the socket? | 191 | //TODO: serialize instead of blast them all through the socket? |
189 | log(QString("We have %1 queued commands").arg(d->commandQueue.size())); | 192 | log(QString("We have %1 queued commands").arg(d->commandQueue.size())); |
190 | for (QueuedCommand *command: d->commandQueue) { | 193 | for (QueuedCommand *command: d->commandQueue) { |
191 | command->write(d->socket); | 194 | command->write(d->socket, ++d->messageId); |
192 | delete command; | 195 | delete command; |
193 | } | 196 | } |
194 | d->commandQueue.clear(); | 197 | d->commandQueue.clear(); |
@@ -239,25 +242,33 @@ void ResourceAccess::readResourceMessage() | |||
239 | 242 | ||
240 | bool ResourceAccess::processMessageBuffer() | 243 | bool ResourceAccess::processMessageBuffer() |
241 | { | 244 | { |
242 | static const int headerSize = (sizeof(int) * 2); | 245 | static const int headerSize = Commands::headerSize(); |
243 | if (d->partialMessageBuffer.size() < headerSize) { | 246 | if (d->partialMessageBuffer.size() < headerSize) { |
244 | return false; | 247 | return false; |
245 | } | 248 | } |
246 | 249 | ||
247 | const int commandId = *(int*)d->partialMessageBuffer.constData(); | 250 | //messageId is unused, so commented out |
248 | const int size = *(int*)(d->partialMessageBuffer.constData() + sizeof(int)); | 251 | //const uint messageId = *(int*)(d->partialMessageBuffer.constData()); |
252 | const int commandId = *(int*)(d->partialMessageBuffer.constData() + sizeof(uint)); | ||
253 | const uint size = *(int*)(d->partialMessageBuffer.constData() + sizeof(int) + sizeof(uint)); | ||
249 | 254 | ||
250 | if (size > d->partialMessageBuffer.size() - headerSize) { | 255 | if (size > (uint)(d->partialMessageBuffer.size() - headerSize)) { |
251 | return false; | 256 | return false; |
252 | } | 257 | } |
253 | 258 | ||
254 | switch (commandId) { | 259 | switch (commandId) { |
255 | case Commands::RevisionUpdateCommand: { | 260 | case Commands::RevisionUpdateCommand: { |
256 | auto buffer = Akonadi2::GetRevisionUpdate(d->partialMessageBuffer.constData() + headerSize); | 261 | auto buffer = GetRevisionUpdate(d->partialMessageBuffer.constData() + headerSize); |
257 | log(QString("Revision updated to: %1").arg(buffer->revision())); | 262 | log(QString("Revision updated to: %1").arg(buffer->revision())); |
258 | emit revisionChanged(buffer->revision()); | 263 | emit revisionChanged(buffer->revision()); |
259 | break; | 264 | break; |
260 | } | 265 | } |
266 | case Commands::CommandCompletion: { | ||
267 | auto buffer = GetCommandCompletion(d->partialMessageBuffer.constData() + headerSize); | ||
268 | log(QString("Command %1 completed %2").arg(buffer->id()).arg(buffer->success() ? "sucessfully" : "unsuccessfully")); | ||
269 | //TODO: if a queued command, get it out of the queue ... pass on completion ot the relevant objects .. etc | ||
270 | break; | ||
271 | } | ||
261 | default: | 272 | default: |
262 | break; | 273 | break; |
263 | } | 274 | } |