From 9fb535b4cdd6af360e3bbc5ce914e9a2c11ba047 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Thu, 9 Jul 2015 22:36:30 +0200 Subject: Moved the dummy backend to a separate file. --- examples/dummyresource/CMakeLists.txt | 2 +- examples/dummyresource/dummystore.cpp | 62 ++++++++++++++++++++++++++++++ examples/dummyresource/dummystore.h | 34 ++++++++++++++++ examples/dummyresource/resourcefactory.cpp | 41 ++------------------ 4 files changed, 101 insertions(+), 38 deletions(-) create mode 100644 examples/dummyresource/dummystore.cpp create mode 100644 examples/dummyresource/dummystore.h (limited to 'examples/dummyresource') diff --git a/examples/dummyresource/CMakeLists.txt b/examples/dummyresource/CMakeLists.txt index 36b8e54..e4b51dd 100644 --- a/examples/dummyresource/CMakeLists.txt +++ b/examples/dummyresource/CMakeLists.txt @@ -4,7 +4,7 @@ add_definitions(-DQT_PLUGIN) include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) -add_library(${PROJECT_NAME} SHARED facade.cpp resourcefactory.cpp domainadaptor.cpp resourcefacade.cpp) +add_library(${PROJECT_NAME} SHARED facade.cpp resourcefactory.cpp domainadaptor.cpp resourcefacade.cpp dummystore.cpp) generate_flatbuffers(${PROJECT_NAME} dummycalendar) qt5_use_modules(${PROJECT_NAME} Core Network) target_link_libraries(${PROJECT_NAME} akonadi2common) diff --git a/examples/dummyresource/dummystore.cpp b/examples/dummyresource/dummystore.cpp new file mode 100644 index 0000000..44bea5c --- /dev/null +++ b/examples/dummyresource/dummystore.cpp @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2015 Christian Mollekopf + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ +#include "dummystore.h" + +#include + +#include "dummycalendar_generated.h" + +static std::string createEvent() +{ + static const size_t attachmentSize = 1024*2; // 2KB + static uint8_t rawData[attachmentSize]; + static flatbuffers::FlatBufferBuilder fbb; + fbb.Clear(); + { + uint8_t *rawDataPtr = nullptr; + auto summary = fbb.CreateString("summary"); + auto data = fbb.CreateUninitializedVector(attachmentSize, &rawDataPtr); + DummyCalendar::DummyEventBuilder eventBuilder(fbb); + eventBuilder.add_summary(summary); + eventBuilder.add_attachment(data); + auto eventLocation = eventBuilder.Finish(); + DummyCalendar::FinishDummyEventBuffer(fbb, eventLocation); + memcpy((void*)rawDataPtr, rawData, attachmentSize); + } + + return std::string(reinterpret_cast(fbb.GetBufferPointer()), fbb.GetSize()); +} + +QMap populate() +{ + QMap content; + for (int i = 0; i < 2; i++) { + auto event = createEvent(); + content.insert(QString("key%1").arg(i), QString::fromStdString(event)); + } + return content; +} + +static QMap s_dataSource = populate(); + + +QMap DummyStore::data() const +{ + return s_dataSource; +} diff --git a/examples/dummyresource/dummystore.h b/examples/dummyresource/dummystore.h new file mode 100644 index 0000000..6a404ae --- /dev/null +++ b/examples/dummyresource/dummystore.h @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2015 Christian Mollekopf + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ +#pragma once +#include + +class DummyStore +{ +public: + //TODO proper singleton + static DummyStore &instance() + { + static DummyStore instance; + return instance; + } + + QMap data() const; + +}; diff --git a/examples/dummyresource/resourcefactory.cpp b/examples/dummyresource/resourcefactory.cpp index de13aa9..3596a82 100644 --- a/examples/dummyresource/resourcefactory.cpp +++ b/examples/dummyresource/resourcefactory.cpp @@ -31,6 +31,7 @@ #include "index.h" #include "log.h" #include "domain/event.h" +#include "dummystore.h" #include #include @@ -70,41 +71,6 @@ protected: }; - -static std::string createEvent() -{ - static const size_t attachmentSize = 1024*2; // 2KB - static uint8_t rawData[attachmentSize]; - static flatbuffers::FlatBufferBuilder fbb; - fbb.Clear(); - { - uint8_t *rawDataPtr = Q_NULLPTR; - auto summary = fbb.CreateString("summary"); - auto data = fbb.CreateUninitializedVector(attachmentSize, &rawDataPtr); - DummyCalendar::DummyEventBuilder eventBuilder(fbb); - eventBuilder.add_summary(summary); - eventBuilder.add_attachment(data); - auto eventLocation = eventBuilder.Finish(); - DummyCalendar::FinishDummyEventBuffer(fbb, eventLocation); - memcpy((void*)rawDataPtr, rawData, attachmentSize); - } - - return std::string(reinterpret_cast(fbb.GetBufferPointer()), fbb.GetSize()); -} - -QMap populate() -{ - QMap content; - for (int i = 0; i < 2; i++) { - auto event = createEvent(); - content.insert(QString("key%1").arg(i), QString::fromStdString(event)); - } - return content; -} - -static QMap s_dataSource = populate(); - - DummyResource::DummyResource(const QByteArray &instanceIdentifier) : Akonadi2::GenericResource(instanceIdentifier) { @@ -157,8 +123,9 @@ KAsync::Job DummyResource::synchronizeWithSource(Akonadi2::Pipeline *pipel { return KAsync::start([this, pipeline](KAsync::Future &f) { //TODO use a read-only transaction during the complete sync to sync against a defined revision - auto storage = QSharedPointer::create(Akonadi2::Store::storageLocation(), "org.kde.dummy.instance1"); - for (auto it = s_dataSource.constBegin(); it != s_dataSource.constEnd(); it++) { + auto storage = QSharedPointer::create(Akonadi2::Store::storageLocation(), mResourceInstanceIdentifier); + const auto data = DummyStore::instance().data(); + for (auto it = data.constBegin(); it != data.constEnd(); it++) { bool isNew = true; if (storage->exists()) { findByRemoteId(storage, it.key(), [&](void *keyValue, int keySize, void *dataValue, int dataSize) { -- cgit v1.2.3