diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2014-12-21 22:20:31 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2014-12-21 22:20:31 +0100 |
commit | d80ff84c28c0be626c1df4528741cddf5a55f547 (patch) | |
tree | dfa1a3771f52970bfaf7b9e56d8675aeabfc65ef /common/resourceaccess.cpp | |
parent | d21aa4e35fb96fa3b07888f710cbc3440af8bdd3 (diff) | |
download | sink-d80ff84c28c0be626c1df4528741cddf5a55f547.tar.gz sink-d80ff84c28c0be626c1df4528741cddf5a55f547.zip |
Write-Read loop from clientside.
It's a huge hack but starts to show results.
Most urgently we need:
* reliable command results
* the 3 buffers instead of the 1
* A way to implement storage as preprocessor (or a place to impelement it after the preprocessors).
Diffstat (limited to 'common/resourceaccess.cpp')
-rw-r--r-- | common/resourceaccess.cpp | 20 |
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 | ||
153 | void 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 | |||
152 | void ResourceAccess::open() | 160 | void 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 | ||
281 | void ResourceAccess::log(const QString &message) | 296 | void 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 | } |