diff options
Diffstat (limited to 'dummyresource/resourcefactory.cpp')
-rw-r--r-- | dummyresource/resourcefactory.cpp | 48 |
1 files changed, 20 insertions, 28 deletions
diff --git a/dummyresource/resourcefactory.cpp b/dummyresource/resourcefactory.cpp index dda34ef..8f0a2bd 100644 --- a/dummyresource/resourcefactory.cpp +++ b/dummyresource/resourcefactory.cpp | |||
@@ -191,7 +191,7 @@ private slots: | |||
191 | return; | 191 | return; |
192 | } | 192 | } |
193 | auto queuedCommand = Akonadi2::GetQueuedCommand(ptr); | 193 | auto queuedCommand = Akonadi2::GetQueuedCommand(ptr); |
194 | qDebug() << "Dequeued: " << queuedCommand->commandId(); | 194 | Trace() << "Dequeued: " << queuedCommand->commandId(); |
195 | //TODO JOBAPI: job lifetime management | 195 | //TODO JOBAPI: job lifetime management |
196 | //Right now we're just leaking jobs. In this case we'd like jobs that are heap allocated and delete | 196 | //Right now we're just leaking jobs. In this case we'd like jobs that are heap allocated and delete |
197 | //themselves once done. In other cases we'd like jobs that only live as long as their handle though. | 197 | //themselves once done. In other cases we'd like jobs that only live as long as their handle though. |
@@ -256,29 +256,18 @@ void DummyResource::configurePipeline(Akonadi2::Pipeline *pipeline) | |||
256 | //Eventually the order should be self configuring, for now it's hardcoded. | 256 | //Eventually the order should be self configuring, for now it's hardcoded. |
257 | auto eventIndexer = new SimpleProcessor("summaryprocessor", [eventFactory](const Akonadi2::PipelineState &state, const Akonadi2::Entity &entity) { | 257 | auto eventIndexer = new SimpleProcessor("summaryprocessor", [eventFactory](const Akonadi2::PipelineState &state, const Akonadi2::Entity &entity) { |
258 | auto adaptor = eventFactory->createAdaptor(entity); | 258 | auto adaptor = eventFactory->createAdaptor(entity); |
259 | // qDebug() << "Summary preprocessor: " << adaptor->getProperty("summary").toString(); | 259 | // Log() << "Summary preprocessor: " << adaptor->getProperty("summary").toString(); |
260 | }); | 260 | }); |
261 | 261 | ||
262 | auto uidIndexer = new SimpleProcessor("uidIndexer", [eventFactory](const Akonadi2::PipelineState &state, const Akonadi2::Entity &entity) { | 262 | auto uidIndexer = new SimpleProcessor("uidIndexer", [eventFactory](const Akonadi2::PipelineState &state, const Akonadi2::Entity &entity) { |
263 | static Index uidIndex(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/akonadi2/storage", "org.kde.dummy.index.uid", Akonadi2::Storage::ReadWrite); | 263 | static Index uidIndex(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/akonadi2/storage", "org.kde.dummy.index.uid", Akonadi2::Storage::ReadWrite); |
264 | 264 | ||
265 | //TODO: Benchmark if this is performance wise acceptable, or if we have to access the buffer directly | ||
265 | auto adaptor = eventFactory->createAdaptor(entity); | 266 | auto adaptor = eventFactory->createAdaptor(entity); |
266 | const auto uid = adaptor->getProperty("uid"); | 267 | const auto uid = adaptor->getProperty("uid"); |
267 | if (uid.isValid()) { | 268 | if (uid.isValid()) { |
268 | uidIndex.add(uid.toByteArray(), state.key()); | 269 | uidIndex.add(uid.toByteArray(), state.key()); |
269 | } | 270 | } |
270 | |||
271 | //TODO would this be worthwhile for performance reasons? | ||
272 | // flatbuffers::Verifier verifyer(entity.local()->Data(), entity.local()->size()); | ||
273 | // if (!Akonadi2::Domain::Buffer::VerifyEventBuffer(verifyer)) { | ||
274 | // qWarning() << "invalid local buffer"; | ||
275 | // return; | ||
276 | // } | ||
277 | // auto localEvent = Akonadi2::Domain::Buffer::GetEvent(entity.local()->Data()); | ||
278 | // if (localEvent && localEvent->uid()) { | ||
279 | // qDebug() << "got uid: " << QByteArray::fromRawData(reinterpret_cast<const char *>(localEvent->uid()->Data()), localEvent->uid()->size()); | ||
280 | // uidIndex.add(QByteArray::fromRawData(reinterpret_cast<const char *>(localEvent->uid()->Data()), localEvent->uid()->size()), state.key()); | ||
281 | // } | ||
282 | }); | 271 | }); |
283 | 272 | ||
284 | //event is the entitytype and not the domain type | 273 | //event is the entitytype and not the domain type |
@@ -289,7 +278,7 @@ void DummyResource::configurePipeline(Akonadi2::Pipeline *pipeline) | |||
289 | 278 | ||
290 | void DummyResource::onProcessorError(int errorCode, const QString &errorMessage) | 279 | void DummyResource::onProcessorError(int errorCode, const QString &errorMessage) |
291 | { | 280 | { |
292 | qWarning() << "Received error from Processor: " << errorCode << errorMessage; | 281 | Warning() << "Received error from Processor: " << errorCode << errorMessage; |
293 | mError = errorCode; | 282 | mError = errorCode; |
294 | } | 283 | } |
295 | 284 | ||
@@ -325,11 +314,8 @@ void findByRemoteId(QSharedPointer<Akonadi2::Storage> storage, const QString &ri | |||
325 | void DummyResource::enqueueCommand(MessageQueue &mq, int commandId, const QByteArray &data) | 314 | void DummyResource::enqueueCommand(MessageQueue &mq, int commandId, const QByteArray &data) |
326 | { | 315 | { |
327 | m_fbb.Clear(); | 316 | m_fbb.Clear(); |
328 | auto commandData = m_fbb.CreateVector(reinterpret_cast<uint8_t const *>(data.data()), data.size()); | 317 | auto commandData = Akonadi2::EntityBuffer::appendAsVector(m_fbb, data.constData(), data.size()); |
329 | auto builder = Akonadi2::QueuedCommandBuilder(m_fbb); | 318 | auto buffer = Akonadi2::CreateQueuedCommand(m_fbb, commandId, commandData); |
330 | builder.add_commandId(commandId); | ||
331 | builder.add_command(commandData); | ||
332 | auto buffer = builder.Finish(); | ||
333 | Akonadi2::FinishQueuedCommandBuffer(m_fbb, buffer); | 319 | Akonadi2::FinishQueuedCommandBuffer(m_fbb, buffer); |
334 | mq.enqueue(m_fbb.GetBufferPointer(), m_fbb.GetSize()); | 320 | mq.enqueue(m_fbb.GetBufferPointer(), m_fbb.GetSize()); |
335 | } | 321 | } |
@@ -357,7 +343,7 @@ Async::Job<void> DummyResource::synchronizeWithSource(Akonadi2::Pipeline *pipeli | |||
357 | auto rid = m_fbb.CreateString(it.key().toStdString().c_str()); | 343 | auto rid = m_fbb.CreateString(it.key().toStdString().c_str()); |
358 | auto description = m_fbb.CreateString(it.key().toStdString().c_str()); | 344 | auto description = m_fbb.CreateString(it.key().toStdString().c_str()); |
359 | static uint8_t rawData[100]; | 345 | static uint8_t rawData[100]; |
360 | auto attachment = m_fbb.CreateVector(rawData, 100); | 346 | auto attachment = Akonadi2::EntityBuffer::appendAsVector(m_fbb, rawData, 100); |
361 | 347 | ||
362 | auto builder = DummyCalendar::DummyEventBuilder(m_fbb); | 348 | auto builder = DummyCalendar::DummyEventBuilder(m_fbb); |
363 | builder.add_summary(summary); | 349 | builder.add_summary(summary); |
@@ -372,7 +358,7 @@ Async::Job<void> DummyResource::synchronizeWithSource(Akonadi2::Pipeline *pipeli | |||
372 | flatbuffers::FlatBufferBuilder fbb; | 358 | flatbuffers::FlatBufferBuilder fbb; |
373 | //This is the resource type and not the domain type | 359 | //This is the resource type and not the domain type |
374 | auto type = fbb.CreateString("event"); | 360 | auto type = fbb.CreateString("event"); |
375 | auto delta = fbb.CreateVector<uint8_t>(entityFbb.GetBufferPointer(), entityFbb.GetSize()); | 361 | auto delta = Akonadi2::EntityBuffer::appendAsVector(fbb, entityFbb.GetBufferPointer(), entityFbb.GetSize()); |
376 | auto location = Akonadi2::Commands::CreateCreateEntity(fbb, type, delta); | 362 | auto location = Akonadi2::Commands::CreateCreateEntity(fbb, type, delta); |
377 | Akonadi2::Commands::FinishCreateEntityBuffer(fbb, location); | 363 | Akonadi2::Commands::FinishCreateEntityBuffer(fbb, location); |
378 | 364 | ||
@@ -388,16 +374,22 @@ Async::Job<void> DummyResource::synchronizeWithSource(Akonadi2::Pipeline *pipeli | |||
388 | 374 | ||
389 | Async::Job<void> DummyResource::processAllMessages() | 375 | Async::Job<void> DummyResource::processAllMessages() |
390 | { | 376 | { |
377 | //We have to wait for all items to be processed to ensure the synced items are available when a query gets executed. | ||
378 | //TODO: report errors while processing sync? | ||
379 | //TODO JOBAPI: A helper that waits for n events and then continues? | ||
391 | return Async::start<void>([this](Async::Future<void> &f) { | 380 | return Async::start<void>([this](Async::Future<void> &f) { |
392 | //We have to wait for all items to be processed to ensure the synced items are available when a query gets executed. | ||
393 | //TODO: report errors while processing sync? | ||
394 | //TODO: also check user-queue? | ||
395 | if (mSynchronizerQueue.isEmpty()) { | 381 | if (mSynchronizerQueue.isEmpty()) { |
396 | qDebug() << "synchronizer queue is empty"; | ||
397 | f.setFinished(); | 382 | f.setFinished(); |
398 | } else { | 383 | } else { |
399 | QObject::connect(&mSynchronizerQueue, &MessageQueue::drained, [&f]() { | 384 | QObject::connect(&mSynchronizerQueue, &MessageQueue::drained, [&f]() { |
400 | qDebug() << "synchronizer queue drained"; | 385 | f.setFinished(); |
386 | }); | ||
387 | } | ||
388 | }).then<void>([this](Async::Future<void> &f) { | ||
389 | if (mUserQueue.isEmpty()) { | ||
390 | f.setFinished(); | ||
391 | } else { | ||
392 | QObject::connect(&mUserQueue, &MessageQueue::drained, [&f]() { | ||
401 | f.setFinished(); | 393 | f.setFinished(); |
402 | }); | 394 | }); |
403 | } | 395 | } |
@@ -425,7 +417,7 @@ Akonadi2::Resource *DummyResourceFactory::createResource() | |||
425 | 417 | ||
426 | void DummyResourceFactory::registerFacades(Akonadi2::FacadeFactory &factory) | 418 | void DummyResourceFactory::registerFacades(Akonadi2::FacadeFactory &factory) |
427 | { | 419 | { |
428 | factory.registerFacade<Akonadi2::Domain::Event, DummyResourceFacade>(PLUGIN_NAME); | 420 | factory.registerFacade<Akonadi2::ApplicationDomain::Event, DummyResourceFacade>(PLUGIN_NAME); |
429 | } | 421 | } |
430 | 422 | ||
431 | #include "resourcefactory.moc" | 423 | #include "resourcefactory.moc" |