summaryrefslogtreecommitdiffstats
path: root/common/resourceaccess.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'common/resourceaccess.cpp')
-rw-r--r--common/resourceaccess.cpp20
1 files changed, 18 insertions, 2 deletions
diff --git a/common/resourceaccess.cpp b/common/resourceaccess.cpp
index a7e14f5..1706ac4 100644
--- a/common/resourceaccess.cpp
+++ b/common/resourceaccess.cpp
@@ -58,7 +58,7 @@ public:
58 58
59 void write(QIODevice *device, uint messageId) 59 void write(QIODevice *device, uint messageId)
60 { 60 {
61 Console::main()->log(QString("\tSending queued command %1").arg(m_commandId)); 61 // Console::main()->log(QString("\tSending queued command %1").arg(m_commandId));
62 Commands::write(device, messageId, m_commandId, m_buffer, m_bufferSize); 62 Commands::write(device, messageId, m_commandId, m_buffer, m_bufferSize);
63 } 63 }
64 64
@@ -82,6 +82,7 @@ public:
82 QByteArray partialMessageBuffer; 82 QByteArray partialMessageBuffer;
83 flatbuffers::FlatBufferBuilder fbb; 83 flatbuffers::FlatBufferBuilder fbb;
84 QVector<QueuedCommand *> commandQueue; 84 QVector<QueuedCommand *> commandQueue;
85 QVector<std::function<void()> > synchronizeResultHandler;
85 uint messageId; 86 uint messageId;
86}; 87};
87 88
@@ -149,6 +150,13 @@ void ResourceAccess::sendCommand(int commandId, flatbuffers::FlatBufferBuilder &
149 } 150 }
150} 151}
151 152
153void ResourceAccess::synchronizeResource(const std::function<void()> &resultHandler)
154{
155 sendCommand(Commands::SynchronizeCommand);
156 //TODO: this should be implemented as a job, so we don't need to store the result handler as member
157 d->synchronizeResultHandler << resultHandler;
158}
159
152void ResourceAccess::open() 160void ResourceAccess::open()
153{ 161{
154 if (d->socket->isValid()) { 162 if (d->socket->isValid()) {
@@ -262,6 +270,13 @@ bool ResourceAccess::processMessageBuffer()
262 auto buffer = GetRevisionUpdate(d->partialMessageBuffer.constData() + headerSize); 270 auto buffer = GetRevisionUpdate(d->partialMessageBuffer.constData() + headerSize);
263 log(QString("Revision updated to: %1").arg(buffer->revision())); 271 log(QString("Revision updated to: %1").arg(buffer->revision()));
264 emit revisionChanged(buffer->revision()); 272 emit revisionChanged(buffer->revision());
273
274 //FIXME: The result handler should be called on completion of the synchronize command, and not upon arbitrary revision updates.
275 for(auto handler : d->synchronizeResultHandler) {
276 //FIXME: we should associate the handler with a buffer->id() to avoid prematurely triggering the result handler from a delayed synchronized response (this is relevant for on-demand syncing).
277 handler();
278 }
279 d->synchronizeResultHandler.clear();
265 break; 280 break;
266 } 281 }
267 case Commands::CommandCompletion: { 282 case Commands::CommandCompletion: {
@@ -280,7 +295,8 @@ bool ResourceAccess::processMessageBuffer()
280 295
281void ResourceAccess::log(const QString &message) 296void ResourceAccess::log(const QString &message)
282{ 297{
283 Console::main()->log(d->resourceName + ": " + message); 298 qDebug() << d->resourceName + ": " + message;
299 // Console::main()->log(d->resourceName + ": " + message);
284} 300}
285 301
286} 302}