summaryrefslogtreecommitdiffstats
path: root/synchronizer
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2015-07-20 16:15:49 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2015-07-23 17:37:53 +0200
commitb187b95672fe0d8b16ba80bedd9022f1cda3a051 (patch)
treec86bf63c73eb91aca83a3d0c22be95b7a7515f0b /synchronizer
parent4a71e5b06506af6e3ab7a7715705e76b6d6e9bb7 (diff)
downloadsink-b187b95672fe0d8b16ba80bedd9022f1cda3a051.tar.gz
sink-b187b95672fe0d8b16ba80bedd9022f1cda3a051.zip
Pass command around as QByteArray
Simpler api, GenericResource didn't honor size anyways, and we copy the command for now to avoid sideeffects of data coming in in the meantime (although that should generally work since data is always appended).
Diffstat (limited to 'synchronizer')
-rw-r--r--synchronizer/listener.cpp19
-rw-r--r--synchronizer/listener.h2
2 files changed, 11 insertions, 10 deletions
diff --git a/synchronizer/listener.cpp b/synchronizer/listener.cpp
index 1553f7d..2559664 100644
--- a/synchronizer/listener.cpp
+++ b/synchronizer/listener.cpp
@@ -203,13 +203,13 @@ void Listener::processClientBuffers()
203 } 203 }
204} 204}
205 205
206void Listener::processCommand(int commandId, uint messageId, Client &client, uint size, const std::function<void()> &callback) 206void Listener::processCommand(int commandId, uint messageId, const QByteArray &commandBuffer, Client &client, const std::function<void()> &callback)
207{ 207{
208 switch (commandId) { 208 switch (commandId) {
209 case Akonadi2::Commands::HandshakeCommand: { 209 case Akonadi2::Commands::HandshakeCommand: {
210 flatbuffers::Verifier verifier((const uint8_t *)client.commandBuffer.constData(), size); 210 flatbuffers::Verifier verifier((const uint8_t *)commandBuffer.constData(), commandBuffer.size());
211 if (Akonadi2::VerifyHandshakeBuffer(verifier)) { 211 if (Akonadi2::VerifyHandshakeBuffer(verifier)) {
212 auto buffer = Akonadi2::GetHandshake(client.commandBuffer.constData()); 212 auto buffer = Akonadi2::GetHandshake(commandBuffer.constData());
213 client.name = buffer->name()->c_str(); 213 client.name = buffer->name()->c_str();
214 sendCurrentRevision(client); 214 sendCurrentRevision(client);
215 } else { 215 } else {
@@ -218,9 +218,9 @@ void Listener::processCommand(int commandId, uint messageId, Client &client, uin
218 break; 218 break;
219 } 219 }
220 case Akonadi2::Commands::SynchronizeCommand: { 220 case Akonadi2::Commands::SynchronizeCommand: {
221 flatbuffers::Verifier verifier((const uint8_t *)client.commandBuffer.constData(), size); 221 flatbuffers::Verifier verifier((const uint8_t *)commandBuffer.constData(), commandBuffer.size());
222 if (Akonadi2::VerifySynchronizeBuffer(verifier)) { 222 if (Akonadi2::VerifySynchronizeBuffer(verifier)) {
223 auto buffer = Akonadi2::GetSynchronize(client.commandBuffer.constData()); 223 auto buffer = Akonadi2::GetSynchronize(commandBuffer.constData());
224 Log() << QString("\tSynchronize request (id %1) from %2").arg(messageId).arg(client.name); 224 Log() << QString("\tSynchronize request (id %1) from %2").arg(messageId).arg(client.name);
225 loadResource(); 225 loadResource();
226 if (!m_resource) { 226 if (!m_resource) {
@@ -250,7 +250,7 @@ void Listener::processCommand(int commandId, uint messageId, Client &client, uin
250 Log() << "\tCommand id " << messageId << " of type \"" << Akonadi2::Commands::name(commandId) << "\" from " << client.name; 250 Log() << "\tCommand id " << messageId << " of type \"" << Akonadi2::Commands::name(commandId) << "\" from " << client.name;
251 loadResource(); 251 loadResource();
252 if (m_resource) { 252 if (m_resource) {
253 m_resource->processCommand(commandId, client.commandBuffer, size, m_pipeline); 253 m_resource->processCommand(commandId, commandBuffer, m_pipeline);
254 } 254 }
255 break; 255 break;
256 case Akonadi2::Commands::ShutdownCommand: 256 case Akonadi2::Commands::ShutdownCommand:
@@ -262,7 +262,7 @@ void Listener::processCommand(int commandId, uint messageId, Client &client, uin
262 Log() << QString("\tReceived custom command from %1: ").arg(client.name) << commandId; 262 Log() << QString("\tReceived custom command from %1: ").arg(client.name) << commandId;
263 loadResource(); 263 loadResource();
264 if (m_resource) { 264 if (m_resource) {
265 m_resource->processCommand(commandId, client.commandBuffer, size, m_pipeline); 265 m_resource->processCommand(commandId, commandBuffer, m_pipeline);
266 } 266 }
267 } else { 267 } else {
268 Warning() << QString("\tReceived invalid command from %1: ").arg(client.name) << commandId; 268 Warning() << QString("\tReceived invalid command from %1: ").arg(client.name) << commandId;
@@ -307,7 +307,9 @@ bool Listener::processClientBuffer(Client &client)
307 307
308 auto socket = QPointer<QLocalSocket>(client.socket); 308 auto socket = QPointer<QLocalSocket>(client.socket);
309 auto clientName = client.name; 309 auto clientName = client.name;
310 processCommand(commandId, messageId, client, size, [this, messageId, commandId, socket, clientName]() { 310 const QByteArray commandBuffer = client.commandBuffer.left(size);
311 client.commandBuffer.remove(0, size);
312 processCommand(commandId, messageId, commandBuffer, client, [this, messageId, commandId, socket, clientName]() {
311 Log() << QString("\tCompleted command messageid %1 of type \"%2\" from %3").arg(messageId).arg(QString(Akonadi2::Commands::name(commandId))).arg(clientName); 313 Log() << QString("\tCompleted command messageid %1 of type \"%2\" from %3").arg(messageId).arg(QString(Akonadi2::Commands::name(commandId))).arg(clientName);
312 if (socket) { 314 if (socket) {
313 sendCommandCompleted(socket.data(), messageId); 315 sendCommandCompleted(socket.data(), messageId);
@@ -315,7 +317,6 @@ bool Listener::processClientBuffer(Client &client)
315 Log() << QString("Socket became invalid before we could send a response. client: %1").arg(clientName); 317 Log() << QString("Socket became invalid before we could send a response. client: %1").arg(clientName);
316 } 318 }
317 }); 319 });
318 client.commandBuffer.remove(0, size);
319 320
320 return client.commandBuffer.size() >= headerSize; 321 return client.commandBuffer.size() >= headerSize;
321 } 322 }
diff --git a/synchronizer/listener.h b/synchronizer/listener.h
index e03c310..560f052 100644
--- a/synchronizer/listener.h
+++ b/synchronizer/listener.h
@@ -79,7 +79,7 @@ private Q_SLOTS:
79 void quit(); 79 void quit();
80 80
81private: 81private:
82 void processCommand(int commandId, uint messageId, Client &client, uint size, const std::function<void()> &callback); 82 void processCommand(int commandId, uint messageId, const QByteArray &commandBuffer, Client &client, const std::function<void()> &callback);
83 bool processClientBuffer(Client &client); 83 bool processClientBuffer(Client &client);
84 void sendCurrentRevision(Client &client); 84 void sendCurrentRevision(Client &client);
85 void sendCommandCompleted(QLocalSocket *socket, uint messageId); 85 void sendCommandCompleted(QLocalSocket *socket, uint messageId);