From bdb01c2c068df326f5a8328ed1492ab1bea388c5 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Wed, 20 Jan 2016 19:07:07 +0100 Subject: Renamed Akonadi2 to Sink (except for documentation). --- common/Akonadi2CommonConfig.cmake.in | 5 - common/CMakeLists.txt | 24 ++-- common/SinkCommonConfig.cmake.in | 5 + common/bufferadaptor.h | 2 +- common/bufferutils.h | 2 +- common/clientapi.cpp | 48 ++++---- common/clientapi.h | 10 +- common/commands.cpp | 4 +- common/commands.h | 14 +-- common/commands/commandcompletion.fbs | 2 +- common/commands/createentity.fbs | 2 +- common/commands/deleteentity.fbs | 2 +- common/commands/fetchentity.fbs | 2 +- common/commands/handshake.fbs | 2 +- common/commands/inspection.fbs | 2 +- common/commands/modifyentity.fbs | 2 +- common/commands/notification.fbs | 2 +- common/commands/revisionreplayed.fbs | 2 +- common/commands/revisionupdate.fbs | 2 +- common/commands/synchronize.fbs | 2 +- common/definitions.cpp | 6 +- common/definitions.h | 2 +- common/domain/applicationdomaintype.cpp | 6 +- common/domain/applicationdomaintype.h | 36 +++--- common/domain/dummy.fbs | 2 +- common/domain/event.cpp | 8 +- common/domain/event.fbs | 2 +- common/domain/event.h | 14 +-- common/domain/folder.cpp | 8 +- common/domain/folder.fbs | 2 +- common/domain/folder.h | 14 +-- common/domain/mail.cpp | 8 +- common/domain/mail.fbs | 2 +- common/domain/mail.h | 14 +-- common/domainadaptor.h | 28 ++--- common/domaintypeadaptorfactoryinterface.h | 6 +- common/entity.fbs | 2 +- common/entitybuffer.cpp | 16 +-- common/entitybuffer.h | 2 +- common/facade.cpp | 26 ++--- common/facade.h | 10 +- common/facadefactory.cpp | 6 +- common/facadefactory.h | 2 +- common/facadeinterface.h | 8 +- common/genericresource.cpp | 174 ++++++++++++++--------------- common/genericresource.h | 28 ++--- common/index.cpp | 12 +- common/index.h | 8 +- common/indexupdater.h | 28 ++--- common/inspection.h | 6 +- common/listener.cpp | 80 ++++++------- common/listener.h | 8 +- common/listmodelresult.h | 6 +- common/log.cpp | 18 +-- common/log.h | 10 +- common/messagequeue.cpp | 24 ++-- common/messagequeue.h | 4 +- common/metadata.fbs | 2 +- common/modelresult.cpp | 18 +-- common/modelresult.h | 8 +- common/notification.h | 6 +- common/pipeline.cpp | 114 +++++++++---------- common/pipeline.h | 16 +-- common/query.h | 6 +- common/queryrunner.cpp | 132 +++++++++++----------- common/queryrunner.h | 8 +- common/queuedcommand.fbs | 2 +- common/resource.cpp | 8 +- common/resource.h | 10 +- common/resourceaccess.cpp | 56 +++++----- common/resourceaccess.h | 2 +- common/resourceconfig.cpp | 4 +- common/resourcefacade.cpp | 22 ++-- common/resourcefacade.h | 12 +- common/resultprovider.h | 2 +- common/resultset.h | 6 +- common/storage.h | 24 ++-- common/storage_common.cpp | 26 ++--- common/storage_lmdb.cpp | 4 +- common/synclistresult.h | 4 +- common/typeindex.cpp | 12 +- common/typeindex.h | 8 +- 82 files changed, 642 insertions(+), 642 deletions(-) delete mode 100644 common/Akonadi2CommonConfig.cmake.in create mode 100644 common/SinkCommonConfig.cmake.in (limited to 'common') diff --git a/common/Akonadi2CommonConfig.cmake.in b/common/Akonadi2CommonConfig.cmake.in deleted file mode 100644 index ae0aefc..0000000 --- a/common/Akonadi2CommonConfig.cmake.in +++ /dev/null @@ -1,5 +0,0 @@ -@PACKAGE_INIT@ - -find_dependency(KF5Mime "@KMIME_LIB_VERSION@") - -include("${CMAKE_CURRENT_LIST_DIR}/Akonadi2CommonTargets.cmake") diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 06b2af6..e9cf78f 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -1,31 +1,31 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR}) include_directories(domain) -project(akonadi2common) +project(sinkcommon) -ecm_setup_version("0.1" VARIABLE_PREFIX Akonadi2Common - VERSION_HEADER "${CMAKE_CURRENT_BINARY_DIR}/akonadi2common_version.h" - PACKAGE_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/Akonadi2CommonConfigVersion.cmake" +ecm_setup_version("0.1" VARIABLE_PREFIX SinkCommon + VERSION_HEADER "${CMAKE_CURRENT_BINARY_DIR}/sinkcommon_version.h" + PACKAGE_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/SinkCommonConfigVersion.cmake" SOVERSION 0 ) ########### CMake Config Files ########### -set(CMAKECONFIG_INSTALL_DIR "${KDE_INSTALL_CMAKEPACKAGEDIR}/Akonadi2Common") +set(CMAKECONFIG_INSTALL_DIR "${KDE_INSTALL_CMAKEPACKAGEDIR}/SinkCommon") ecm_configure_package_config_file( - "${CMAKE_CURRENT_SOURCE_DIR}/Akonadi2CommonConfig.cmake.in" - "${CMAKE_CURRENT_BINARY_DIR}/Akonadi2CommonConfig.cmake" + "${CMAKE_CURRENT_SOURCE_DIR}/SinkCommonConfig.cmake.in" + "${CMAKE_CURRENT_BINARY_DIR}/SinkCommonConfig.cmake" INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR} ) install(FILES - "${CMAKE_CURRENT_BINARY_DIR}/Akonadi2CommonConfig.cmake" - "${CMAKE_CURRENT_BINARY_DIR}/Akonadi2CommonConfigVersion.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/SinkCommonConfig.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/SinkCommonConfigVersion.cmake" DESTINATION "${CMAKECONFIG_INSTALL_DIR}" COMPONENT Devel ) -install(EXPORT Akonadi2CommonTargets DESTINATION "${CMAKECONFIG_INSTALL_DIR}" FILE Akonadi2CommonTargets.cmake NAMESPACE KF5::) +install(EXPORT SinkCommonTargets DESTINATION "${CMAKECONFIG_INSTALL_DIR}" FILE SinkCommonTargets.cmake NAMESPACE KF5::) set(storage_SRCS storage_lmdb.cpp) set(storage_LIBS lmdb) @@ -85,7 +85,7 @@ generate_flatbuffers( queuedcommand ) -generate_export_header(${PROJECT_NAME} BASE_NAME Akonadi2Common EXPORT_FILE_NAME akonadi2common_export.h) +generate_export_header(${PROJECT_NAME} BASE_NAME SinkCommon EXPORT_FILE_NAME sinkcommon_export.h) SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE CXX VERSION "0.1" @@ -95,7 +95,7 @@ SET_TARGET_PROPERTIES(${PROJECT_NAME} qt5_use_modules(${PROJECT_NAME} Network) target_link_libraries(${PROJECT_NAME} ${storage_LIBS} KF5::Async) install(TARGETS ${PROJECT_NAME} - EXPORT Akonadi2CommonTargets ${KDE_INSTALL_TARGETS_DEFAULT_ARGS} ${LIBRARY_NAMELINK} ) + EXPORT SinkCommonTargets ${KDE_INSTALL_TARGETS_DEFAULT_ARGS} ${LIBRARY_NAMELINK} ) install(FILES clientapi.h diff --git a/common/SinkCommonConfig.cmake.in b/common/SinkCommonConfig.cmake.in new file mode 100644 index 0000000..6c2a1c2 --- /dev/null +++ b/common/SinkCommonConfig.cmake.in @@ -0,0 +1,5 @@ +@PACKAGE_INIT@ + +find_dependency(KF5Mime "@KMIME_LIB_VERSION@") + +include("${CMAKE_CURRENT_LIST_DIR}/SinkCommonTargets.cmake") diff --git a/common/bufferadaptor.h b/common/bufferadaptor.h index aaff1c2..892635f 100644 --- a/common/bufferadaptor.h +++ b/common/bufferadaptor.h @@ -23,7 +23,7 @@ #include #include -namespace Akonadi2 { +namespace Sink { namespace ApplicationDomain { diff --git a/common/bufferutils.h b/common/bufferutils.h index b0fb75a..b08b7f8 100644 --- a/common/bufferutils.h +++ b/common/bufferutils.h @@ -3,7 +3,7 @@ #include #include -namespace Akonadi2 { +namespace Sink { namespace BufferUtils { template static QByteArray extractBuffer(const T *data) diff --git a/common/clientapi.cpp b/common/clientapi.cpp index 824ef19..be9f3fd 100644 --- a/common/clientapi.cpp +++ b/common/clientapi.cpp @@ -39,23 +39,23 @@ #include "storage.h" #include "log.h" -namespace Akonadi2 +namespace Sink { QString Store::storageLocation() { - return Akonadi2::storageLocation(); + return Sink::storageLocation(); } QByteArray Store::resourceName(const QByteArray &instanceIdentifier) { - return Akonadi2::resourceName(instanceIdentifier); + return Sink::resourceName(instanceIdentifier); } static QList getResources(const QList &resourceFilter, const QByteArray &type) { //Return the global resource (signified by an empty name) for types that don't eblong to a specific resource - if (type == "akonadiresource") { + if (type == "sinkresource") { return QList() << ""; } QList resources; @@ -162,9 +162,9 @@ KAsync::Job Store::shutdown(const QByteArray &identifier) return ResourceAccess::connectToServer(identifier).then>([identifier](QSharedPointer socket, KAsync::Future &future) { //We can't currently reuse the socket socket->close(); - auto resourceAccess = QSharedPointer::create(identifier); + auto resourceAccess = QSharedPointer::create(identifier); resourceAccess->open(); - resourceAccess->sendCommand(Akonadi2::Commands::ShutdownCommand).then([&future, resourceAccess]() { + resourceAccess->sendCommand(Sink::Commands::ShutdownCommand).then([&future, resourceAccess]() { Trace() << "Shutdown complete"; future.setFinished(); }).exec(); @@ -180,9 +180,9 @@ KAsync::Job Store::shutdown(const QByteArray &identifier) KAsync::Job Store::start(const QByteArray &identifier) { Trace() << "start " << identifier; - auto resourceAccess = QSharedPointer::create(identifier); + auto resourceAccess = QSharedPointer::create(identifier); resourceAccess->open(); - return resourceAccess->sendCommand(Akonadi2::Commands::PingCommand).then([resourceAccess]() { + return resourceAccess->sendCommand(Sink::Commands::PingCommand).then([resourceAccess]() { Trace() << "Start complete"; }); } @@ -191,19 +191,19 @@ void Store::removeFromDisk(const QByteArray &identifier) { //TODO By calling the resource executable with a --remove option instead //we can ensure that no other resource process is running at the same time - QDir dir(Akonadi2::storageLocation()); + QDir dir(Sink::storageLocation()); for (const auto &folder : dir.entryList(QStringList() << identifier + "*")) { - Akonadi2::Storage(Akonadi2::storageLocation(), folder, Akonadi2::Storage::ReadWrite).removeFromDisk(); + Sink::Storage(Sink::storageLocation(), folder, Sink::Storage::ReadWrite).removeFromDisk(); } } -KAsync::Job Store::synchronize(const Akonadi2::Query &query) +KAsync::Job Store::synchronize(const Sink::Query &query) { Trace() << "synchronize" << query.resources; return KAsync::iterate(query.resources) .template each([query](const QByteArray &resource, KAsync::Future &future) { Trace() << "Synchronizing " << resource; - auto resourceAccess = QSharedPointer::create(resource); + auto resourceAccess = QSharedPointer::create(resource); resourceAccess->open(); resourceAccess->synchronizeResource(true, false).then([&future, resourceAccess]() { future.setFinished(); @@ -219,7 +219,7 @@ KAsync::Job Store::flushMessageQueue(const QByteArrayList &resourceIdentif return KAsync::iterate(resourceIdentifier) .template each([](const QByteArray &resource, KAsync::Future &future) { Trace() << "Flushing message queue " << resource; - auto resourceAccess = QSharedPointer::create(resource); + auto resourceAccess = QSharedPointer::create(resource); resourceAccess->open(); resourceAccess->synchronizeResource(false, true).then([&future, resourceAccess]() { future.setFinished(); @@ -235,7 +235,7 @@ KAsync::Job Store::flushReplayQueue(const QByteArrayList &resourceIdentifi } template -KAsync::Job Store::fetchOne(const Akonadi2::Query &query) +KAsync::Job Store::fetchOne(const Sink::Query &query) { return KAsync::start([query](KAsync::Future &future) { //FIXME We could do this more elegantly if composed jobs would have the correct type (In that case we'd simply return the value from then continuation, and could avoid the outer job entirely) @@ -251,13 +251,13 @@ KAsync::Job Store::fetchOne(const Akonadi2::Query &query) } template -KAsync::Job > Store::fetchAll(const Akonadi2::Query &query) +KAsync::Job > Store::fetchAll(const Sink::Query &query) { return fetch(query); } template -KAsync::Job > Store::fetch(const Akonadi2::Query &query, int minimumAmount) +KAsync::Job > Store::fetch(const Sink::Query &query, int minimumAmount) { auto model = loadModel(query); auto list = QSharedPointer >::create(); @@ -265,12 +265,12 @@ KAsync::Job > Store::fetch(const Akonadi2::Query return KAsync::start >([model, list, context, minimumAmount](KAsync::Future > &future) { if (model->rowCount() >= 1) { for (int i = 0; i < model->rowCount(); i++) { - list->append(model->index(i, 0, QModelIndex()).data(Akonadi2::Store::DomainObjectRole).template value()); + list->append(model->index(i, 0, QModelIndex()).data(Sink::Store::DomainObjectRole).template value()); } } else { QObject::connect(model.data(), &QAbstractItemModel::rowsInserted, context.data(), [model, &future, list](const QModelIndex &index, int start, int end) { for (int i = start; i <= end; i++) { - list->append(model->index(i, 0, QModelIndex()).data(Akonadi2::Store::DomainObjectRole).template value()); + list->append(model->index(i, 0, QModelIndex()).data(Sink::Store::DomainObjectRole).template value()); } }); QObject::connect(model.data(), &QAbstractItemModel::dataChanged, context.data(), [model, &future, list, minimumAmount](const QModelIndex &, const QModelIndex &, const QVector &roles) { @@ -301,9 +301,9 @@ KAsync::Job Resources::inspect(const Inspection &inspectionCommand) auto resource = inspectionCommand.resourceIdentifier; Trace() << "Sending inspection " << resource; - auto resourceAccess = QSharedPointer::create(resource); + auto resourceAccess = QSharedPointer::create(resource); resourceAccess->open(); - auto notifier = QSharedPointer::create(resourceAccess); + auto notifier = QSharedPointer::create(resourceAccess); auto id = QUuid::createUuid().toByteArray(); return resourceAccess->sendInspectionCommand(id, ApplicationDomain::getTypeName(), inspectionCommand.entityIdentifier, inspectionCommand.property, inspectionCommand.expectedValue) .template then([resourceAccess, notifier, id](KAsync::Future &future) { @@ -319,7 +319,7 @@ KAsync::Job Resources::inspect(const Inspection &inspectionCommand) }); } -class Akonadi2::Notifier::Private { +class Sink::Notifier::Private { public: Private() : context(new QObject) @@ -332,7 +332,7 @@ public: }; Notifier::Notifier(const QSharedPointer &resourceAccess) - : d(new Akonadi2::Notifier::Private) + : d(new Sink::Notifier::Private) { QObject::connect(resourceAccess.data(), &ResourceAccess::notification, d->context.data(), [this](const Notification ¬ification) { for (const auto &handler : d->handler) { @@ -359,7 +359,7 @@ void Notifier::registerHandler(std::function handler REGISTER_TYPE(ApplicationDomain::Event); REGISTER_TYPE(ApplicationDomain::Mail); REGISTER_TYPE(ApplicationDomain::Folder); -REGISTER_TYPE(ApplicationDomain::AkonadiResource); +REGISTER_TYPE(ApplicationDomain::SinkResource); -} // namespace Akonadi2 +} // namespace Sink diff --git a/common/clientapi.h b/common/clientapi.h index 06376c2..64c4f64 100644 --- a/common/clientapi.h +++ b/common/clientapi.h @@ -31,7 +31,7 @@ class QAbstractItemModel; -namespace Akonadi2 { +namespace Sink { class ResourceAccess; class Notification; @@ -78,7 +78,7 @@ public: /** * Synchronize data to local cache. */ - static KAsync::Job synchronize(const Akonadi2::Query &query); + static KAsync::Job synchronize(const Sink::Query &query); /** * Shutdown resource. @@ -110,13 +110,13 @@ public: static void removeFromDisk(const QByteArray &resourceIdentifier); template - static KAsync::Job fetchOne(const Akonadi2::Query &query); + static KAsync::Job fetchOne(const Sink::Query &query); template - static KAsync::Job > fetchAll(const Akonadi2::Query &query); + static KAsync::Job > fetchAll(const Sink::Query &query); template - static KAsync::Job > fetch(const Akonadi2::Query &query, int minimumAmount = 0); + static KAsync::Job > fetch(const Sink::Query &query, int minimumAmount = 0); }; namespace Resources { diff --git a/common/commands.cpp b/common/commands.cpp index 35dfb13..8b915f0 100644 --- a/common/commands.cpp +++ b/common/commands.cpp @@ -22,7 +22,7 @@ #include -namespace Akonadi2 +namespace Sink { namespace Commands @@ -102,4 +102,4 @@ void write(QIODevice *device, int messageId, int commandId, flatbuffers::FlatBuf } // namespace Commands -} // namespace Akonadi2 +} // namespace Sink diff --git a/common/commands.h b/common/commands.h index 33d5cd7..19c827e 100644 --- a/common/commands.h +++ b/common/commands.h @@ -20,13 +20,13 @@ #pragma once -#include +#include #include #include class QIODevice; -namespace Akonadi2 +namespace Sink { namespace Commands @@ -54,11 +54,11 @@ enum CommandIds { QByteArray name(int commandId); -int AKONADI2COMMON_EXPORT headerSize(); -void AKONADI2COMMON_EXPORT write(QIODevice *device, int messageId, int commandId); -void AKONADI2COMMON_EXPORT write(QIODevice *device, int messageId, int commandId, const char *buffer, uint size); -void AKONADI2COMMON_EXPORT write(QIODevice *device, int messageId, int commandId, flatbuffers::FlatBufferBuilder &fbb); +int SINKCOMMON_EXPORT headerSize(); +void SINKCOMMON_EXPORT write(QIODevice *device, int messageId, int commandId); +void SINKCOMMON_EXPORT write(QIODevice *device, int messageId, int commandId, const char *buffer, uint size); +void SINKCOMMON_EXPORT write(QIODevice *device, int messageId, int commandId, flatbuffers::FlatBufferBuilder &fbb); } -} // namespace Akonadi2 +} // namespace Sink diff --git a/common/commands/commandcompletion.fbs b/common/commands/commandcompletion.fbs index de7ec14..6d95dbc 100644 --- a/common/commands/commandcompletion.fbs +++ b/common/commands/commandcompletion.fbs @@ -1,4 +1,4 @@ -namespace Akonadi2.Commands; +namespace Sink.Commands; table CommandCompletion { id: ulong; diff --git a/common/commands/createentity.fbs b/common/commands/createentity.fbs index 5358dea..b97e8f6 100644 --- a/common/commands/createentity.fbs +++ b/common/commands/createentity.fbs @@ -1,4 +1,4 @@ -namespace Akonadi2.Commands; +namespace Sink.Commands; table CreateEntity { entityId: string; diff --git a/common/commands/deleteentity.fbs b/common/commands/deleteentity.fbs index 9f865be..c3a3fc7 100644 --- a/common/commands/deleteentity.fbs +++ b/common/commands/deleteentity.fbs @@ -1,4 +1,4 @@ -namespace Akonadi2.Commands; +namespace Sink.Commands; table DeleteEntity { revision: ulong; diff --git a/common/commands/fetchentity.fbs b/common/commands/fetchentity.fbs index 7a1d74d..bceafbd 100644 --- a/common/commands/fetchentity.fbs +++ b/common/commands/fetchentity.fbs @@ -1,4 +1,4 @@ -namespace Akonadi2.Commands; +namespace Sink.Commands; table FetchEntity { revision: ulong; diff --git a/common/commands/handshake.fbs b/common/commands/handshake.fbs index e824715..1d0b3cb 100644 --- a/common/commands/handshake.fbs +++ b/common/commands/handshake.fbs @@ -1,4 +1,4 @@ -namespace Akonadi2.Commands; +namespace Sink.Commands; table Handshake { name: string; diff --git a/common/commands/inspection.fbs b/common/commands/inspection.fbs index aaae1ae..e99fc71 100644 --- a/common/commands/inspection.fbs +++ b/common/commands/inspection.fbs @@ -1,4 +1,4 @@ -namespace Akonadi2.Commands; +namespace Sink.Commands; table Inspection { id: string; diff --git a/common/commands/modifyentity.fbs b/common/commands/modifyentity.fbs index 03b543f..efa2fa0 100644 --- a/common/commands/modifyentity.fbs +++ b/common/commands/modifyentity.fbs @@ -1,4 +1,4 @@ -namespace Akonadi2.Commands; +namespace Sink.Commands; table ModifyEntity { revision: ulong; diff --git a/common/commands/notification.fbs b/common/commands/notification.fbs index 89687cf..ff01fc5 100644 --- a/common/commands/notification.fbs +++ b/common/commands/notification.fbs @@ -1,4 +1,4 @@ -namespace Akonadi2.Commands; +namespace Sink.Commands; enum NotificationType : byte { Shutdown = 1, Status, Warning, Progress, Inspection } enum NotificationCode : byte { Success = 0, Failure = 1, UserCode } diff --git a/common/commands/revisionreplayed.fbs b/common/commands/revisionreplayed.fbs index e1b11e3..f110ff9 100644 --- a/common/commands/revisionreplayed.fbs +++ b/common/commands/revisionreplayed.fbs @@ -1,4 +1,4 @@ -namespace Akonadi2.Commands; +namespace Sink.Commands; table RevisionReplayed { revision: ulong; diff --git a/common/commands/revisionupdate.fbs b/common/commands/revisionupdate.fbs index 93fbe34..cc092e4 100644 --- a/common/commands/revisionupdate.fbs +++ b/common/commands/revisionupdate.fbs @@ -1,4 +1,4 @@ -namespace Akonadi2.Commands; +namespace Sink.Commands; table RevisionUpdate { revision: ulong; diff --git a/common/commands/synchronize.fbs b/common/commands/synchronize.fbs index 7c3ae9a..5528166 100644 --- a/common/commands/synchronize.fbs +++ b/common/commands/synchronize.fbs @@ -1,4 +1,4 @@ -namespace Akonadi2.Commands; +namespace Sink.Commands; table Synchronize { sourceSync: bool; //Synchronize with source diff --git a/common/definitions.cpp b/common/definitions.cpp index 33512ad..daf354c 100644 --- a/common/definitions.cpp +++ b/common/definitions.cpp @@ -22,12 +22,12 @@ #include -QString Akonadi2::storageLocation() +QString Sink::storageLocation() { - return QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/akonadi2/storage"; + return QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/sink/storage"; } -QByteArray Akonadi2::resourceName(const QByteArray &instanceIdentifier) +QByteArray Sink::resourceName(const QByteArray &instanceIdentifier) { auto split = instanceIdentifier.split('.'); if (split.size() <= 1) { diff --git a/common/definitions.h b/common/definitions.h index 333d106..5834f01 100644 --- a/common/definitions.h +++ b/common/definitions.h @@ -23,7 +23,7 @@ #include #include -namespace Akonadi2 { +namespace Sink { QString storageLocation(); QByteArray resourceName(const QByteArray &instanceIdentifier); } diff --git a/common/domain/applicationdomaintype.cpp b/common/domain/applicationdomaintype.cpp index c9a8bba..b0433be 100644 --- a/common/domain/applicationdomaintype.cpp +++ b/common/domain/applicationdomaintype.cpp @@ -21,7 +21,7 @@ #include "log.h" #include "../bufferadaptor.h" -namespace Akonadi2 { +namespace Sink { namespace ApplicationDomain { ApplicationDomainType::ApplicationDomainType() @@ -113,9 +113,9 @@ QByteArray getTypeName() } template<> -QByteArray getTypeName() +QByteArray getTypeName() { - return "akonadiresource"; + return "sinkresource"; } template<> diff --git a/common/domain/applicationdomaintype.h b/common/domain/applicationdomaintype.h index 44d8743..63f030c 100644 --- a/common/domain/applicationdomaintype.h +++ b/common/domain/applicationdomaintype.h @@ -24,7 +24,7 @@ #include #include "bufferadaptor.h" -namespace Akonadi2 { +namespace Sink { namespace ApplicationDomain { @@ -48,7 +48,7 @@ public: template static typename DomainType::Ptr getInMemoryRepresentation(const ApplicationDomainType &domainType, const QList properties = QList()) { - auto memoryAdaptor = QSharedPointer::create(*(domainType.mAdaptor), properties); + auto memoryAdaptor = QSharedPointer::create(*(domainType.mAdaptor), properties); //The identifier still internal refers to the memory-mapped pointer, we need to copy the memory or it will become invalid return QSharedPointer::create(domainType.mResourceInstanceIdentifier, QByteArray(domainType.mIdentifier.constData(), domainType.mIdentifier.size()), domainType.mRevision, memoryAdaptor); } @@ -113,13 +113,13 @@ struct Folder : public Entity { }; /** - * Represents an akonadi resource. + * Represents an sink resource. * * This type is used for configuration of resources, * and for creating and removing resource instances. */ -struct AkonadiResource : public ApplicationDomainType { - typedef QSharedPointer Ptr; +struct SinkResource : public ApplicationDomainType { + typedef QSharedPointer Ptr; using ApplicationDomainType::ApplicationDomainType; }; @@ -138,7 +138,7 @@ template<> QByteArray getTypeName(); template<> -QByteArray getTypeName(); +QByteArray getTypeName(); template<> QByteArray getTypeName(); @@ -158,15 +158,15 @@ class TypeImplementation; } } -Q_DECLARE_METATYPE(Akonadi2::ApplicationDomain::ApplicationDomainType) -Q_DECLARE_METATYPE(Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr) -Q_DECLARE_METATYPE(Akonadi2::ApplicationDomain::Entity) -Q_DECLARE_METATYPE(Akonadi2::ApplicationDomain::Entity::Ptr) -Q_DECLARE_METATYPE(Akonadi2::ApplicationDomain::Event) -Q_DECLARE_METATYPE(Akonadi2::ApplicationDomain::Event::Ptr) -Q_DECLARE_METATYPE(Akonadi2::ApplicationDomain::Mail) -Q_DECLARE_METATYPE(Akonadi2::ApplicationDomain::Mail::Ptr) -Q_DECLARE_METATYPE(Akonadi2::ApplicationDomain::Folder) -Q_DECLARE_METATYPE(Akonadi2::ApplicationDomain::Folder::Ptr) -Q_DECLARE_METATYPE(Akonadi2::ApplicationDomain::AkonadiResource) -Q_DECLARE_METATYPE(Akonadi2::ApplicationDomain::AkonadiResource::Ptr) +Q_DECLARE_METATYPE(Sink::ApplicationDomain::ApplicationDomainType) +Q_DECLARE_METATYPE(Sink::ApplicationDomain::ApplicationDomainType::Ptr) +Q_DECLARE_METATYPE(Sink::ApplicationDomain::Entity) +Q_DECLARE_METATYPE(Sink::ApplicationDomain::Entity::Ptr) +Q_DECLARE_METATYPE(Sink::ApplicationDomain::Event) +Q_DECLARE_METATYPE(Sink::ApplicationDomain::Event::Ptr) +Q_DECLARE_METATYPE(Sink::ApplicationDomain::Mail) +Q_DECLARE_METATYPE(Sink::ApplicationDomain::Mail::Ptr) +Q_DECLARE_METATYPE(Sink::ApplicationDomain::Folder) +Q_DECLARE_METATYPE(Sink::ApplicationDomain::Folder::Ptr) +Q_DECLARE_METATYPE(Sink::ApplicationDomain::SinkResource) +Q_DECLARE_METATYPE(Sink::ApplicationDomain::SinkResource::Ptr) diff --git a/common/domain/dummy.fbs b/common/domain/dummy.fbs index 8816b09..4b12827 100644 --- a/common/domain/dummy.fbs +++ b/common/domain/dummy.fbs @@ -1,4 +1,4 @@ -namespace Akonadi2.ApplicationDomain.Buffer; +namespace Sink.ApplicationDomain.Buffer; table Dummy { } diff --git a/common/domain/event.cpp b/common/domain/event.cpp index 18009fc..9f81eb8 100644 --- a/common/domain/event.cpp +++ b/common/domain/event.cpp @@ -37,7 +37,7 @@ static QMutex sMutex; -using namespace Akonadi2::ApplicationDomain; +using namespace Sink::ApplicationDomain; static TypeIndex &getIndex() { @@ -50,17 +50,17 @@ static TypeIndex &getIndex() return *index; } -ResultSet TypeImplementation::queryIndexes(const Akonadi2::Query &query, const QByteArray &resourceInstanceIdentifier, QSet &appliedFilters, Akonadi2::Storage::Transaction &transaction) +ResultSet TypeImplementation::queryIndexes(const Sink::Query &query, const QByteArray &resourceInstanceIdentifier, QSet &appliedFilters, Sink::Storage::Transaction &transaction) { return getIndex().query(query, appliedFilters, transaction); } -void TypeImplementation::index(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Akonadi2::Storage::Transaction &transaction) +void TypeImplementation::index(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction) { return getIndex().add(identifier, bufferAdaptor, transaction); } -void TypeImplementation::removeIndex(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Akonadi2::Storage::Transaction &transaction) +void TypeImplementation::removeIndex(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction) { return getIndex().remove(identifier, bufferAdaptor, transaction); } diff --git a/common/domain/event.fbs b/common/domain/event.fbs index 0c6628b..69148ef 100644 --- a/common/domain/event.fbs +++ b/common/domain/event.fbs @@ -1,4 +1,4 @@ -namespace Akonadi2.ApplicationDomain.Buffer; +namespace Sink.ApplicationDomain.Buffer; table Event { uid:string; diff --git a/common/domain/event.h b/common/domain/event.h index 577367b..479969d 100644 --- a/common/domain/event.h +++ b/common/domain/event.h @@ -30,7 +30,7 @@ class ReadPropertyMapper; template class WritePropertyMapper; -namespace Akonadi2 { +namespace Sink { class Query; namespace ApplicationDomain { @@ -45,19 +45,19 @@ namespace ApplicationDomain { * These are type specifiy default implementations. Theoretically a resource could implement it's own implementation. */ template<> -class TypeImplementation { +class TypeImplementation { public: - typedef Akonadi2::ApplicationDomain::Buffer::Event Buffer; - typedef Akonadi2::ApplicationDomain::Buffer::EventBuilder BufferBuilder; + typedef Sink::ApplicationDomain::Buffer::Event Buffer; + typedef Sink::ApplicationDomain::Buffer::EventBuilder BufferBuilder; static QSet indexedProperties(); /** * Returns the potential result set based on the indexes. * * An empty result set indicates that a full scan is required. */ - static ResultSet queryIndexes(const Akonadi2::Query &query, const QByteArray &resourceInstanceIdentifier, QSet &appliedFilters, Akonadi2::Storage::Transaction &transaction); - static void index(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Akonadi2::Storage::Transaction &transaction); - static void removeIndex(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Akonadi2::Storage::Transaction &transaction); + static ResultSet queryIndexes(const Sink::Query &query, const QByteArray &resourceInstanceIdentifier, QSet &appliedFilters, Sink::Storage::Transaction &transaction); + static void index(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction); + static void removeIndex(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction); static QSharedPointer > initializeReadPropertyMapper(); static QSharedPointer > initializeWritePropertyMapper(); }; diff --git a/common/domain/folder.cpp b/common/domain/folder.cpp index 7934841..16b2ec9 100644 --- a/common/domain/folder.cpp +++ b/common/domain/folder.cpp @@ -37,7 +37,7 @@ static QMutex sMutex; -using namespace Akonadi2::ApplicationDomain; +using namespace Sink::ApplicationDomain; static TypeIndex &getIndex() { @@ -51,18 +51,18 @@ static TypeIndex &getIndex() return *index; } -ResultSet TypeImplementation::queryIndexes(const Akonadi2::Query &query, const QByteArray &resourceInstanceIdentifier, QSet &appliedFilters, Akonadi2::Storage::Transaction &transaction) +ResultSet TypeImplementation::queryIndexes(const Sink::Query &query, const QByteArray &resourceInstanceIdentifier, QSet &appliedFilters, Sink::Storage::Transaction &transaction) { return getIndex().query(query, appliedFilters, transaction); } -void TypeImplementation::index(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Akonadi2::Storage::Transaction &transaction) +void TypeImplementation::index(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction) { Trace() << "Indexing " << identifier; getIndex().add(identifier, bufferAdaptor, transaction); } -void TypeImplementation::removeIndex(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Akonadi2::Storage::Transaction &transaction) +void TypeImplementation::removeIndex(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction) { getIndex().remove(identifier, bufferAdaptor, transaction); } diff --git a/common/domain/folder.fbs b/common/domain/folder.fbs index 31dc32a..b5d01ef 100644 --- a/common/domain/folder.fbs +++ b/common/domain/folder.fbs @@ -1,4 +1,4 @@ -namespace Akonadi2.ApplicationDomain.Buffer; +namespace Sink.ApplicationDomain.Buffer; table Folder { name:string; diff --git a/common/domain/folder.h b/common/domain/folder.h index 545836f..40c799c 100644 --- a/common/domain/folder.h +++ b/common/domain/folder.h @@ -30,7 +30,7 @@ class ReadPropertyMapper; template class WritePropertyMapper; -namespace Akonadi2 { +namespace Sink { class Query; namespace ApplicationDomain { @@ -40,14 +40,14 @@ namespace ApplicationDomain { } template<> -class TypeImplementation { +class TypeImplementation { public: - typedef Akonadi2::ApplicationDomain::Buffer::Folder Buffer; - typedef Akonadi2::ApplicationDomain::Buffer::FolderBuilder BufferBuilder; + typedef Sink::ApplicationDomain::Buffer::Folder Buffer; + typedef Sink::ApplicationDomain::Buffer::FolderBuilder BufferBuilder; static QSet indexedProperties(); - static ResultSet queryIndexes(const Akonadi2::Query &query, const QByteArray &resourceInstanceIdentifier, QSet &appliedFilters, Akonadi2::Storage::Transaction &transaction); - static void index(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Akonadi2::Storage::Transaction &transaction); - static void removeIndex(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Akonadi2::Storage::Transaction &transaction); + static ResultSet queryIndexes(const Sink::Query &query, const QByteArray &resourceInstanceIdentifier, QSet &appliedFilters, Sink::Storage::Transaction &transaction); + static void index(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction); + static void removeIndex(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction); static QSharedPointer > initializeReadPropertyMapper(); static QSharedPointer > initializeWritePropertyMapper(); }; diff --git a/common/domain/mail.cpp b/common/domain/mail.cpp index 8875d88..518331f 100644 --- a/common/domain/mail.cpp +++ b/common/domain/mail.cpp @@ -37,7 +37,7 @@ static QMutex sMutex; -using namespace Akonadi2::ApplicationDomain; +using namespace Sink::ApplicationDomain; static TypeIndex &getIndex() { @@ -55,18 +55,18 @@ static TypeIndex &getIndex() return *index; } -ResultSet TypeImplementation::queryIndexes(const Akonadi2::Query &query, const QByteArray &resourceInstanceIdentifier, QSet &appliedFilters, Akonadi2::Storage::Transaction &transaction) +ResultSet TypeImplementation::queryIndexes(const Sink::Query &query, const QByteArray &resourceInstanceIdentifier, QSet &appliedFilters, Sink::Storage::Transaction &transaction) { return getIndex().query(query, appliedFilters, transaction); } -void TypeImplementation::index(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Akonadi2::Storage::Transaction &transaction) +void TypeImplementation::index(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction) { Trace() << "Indexing " << identifier; getIndex().add(identifier, bufferAdaptor, transaction); } -void TypeImplementation::removeIndex(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Akonadi2::Storage::Transaction &transaction) +void TypeImplementation::removeIndex(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction) { getIndex().remove(identifier, bufferAdaptor, transaction); } diff --git a/common/domain/mail.fbs b/common/domain/mail.fbs index 17b29a0..0d11e32 100644 --- a/common/domain/mail.fbs +++ b/common/domain/mail.fbs @@ -1,4 +1,4 @@ -namespace Akonadi2.ApplicationDomain.Buffer; +namespace Sink.ApplicationDomain.Buffer; table Mail { uid:string; diff --git a/common/domain/mail.h b/common/domain/mail.h index d1ef8d6..e45d64d 100644 --- a/common/domain/mail.h +++ b/common/domain/mail.h @@ -30,7 +30,7 @@ class ReadPropertyMapper; template class WritePropertyMapper; -namespace Akonadi2 { +namespace Sink { class Query; namespace ApplicationDomain { @@ -40,19 +40,19 @@ namespace ApplicationDomain { } template<> -class TypeImplementation { +class TypeImplementation { public: - typedef Akonadi2::ApplicationDomain::Buffer::Mail Buffer; - typedef Akonadi2::ApplicationDomain::Buffer::MailBuilder BufferBuilder; + typedef Sink::ApplicationDomain::Buffer::Mail Buffer; + typedef Sink::ApplicationDomain::Buffer::MailBuilder BufferBuilder; static QSet indexedProperties(); /** * Returns the potential result set based on the indexes. * * An empty result set indicates that a full scan is required. */ - static ResultSet queryIndexes(const Akonadi2::Query &query, const QByteArray &resourceInstanceIdentifier, QSet &appliedFilters, Akonadi2::Storage::Transaction &transaction); - static void index(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Akonadi2::Storage::Transaction &transaction); - static void removeIndex(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Akonadi2::Storage::Transaction &transaction); + static ResultSet queryIndexes(const Sink::Query &query, const QByteArray &resourceInstanceIdentifier, QSet &appliedFilters, Sink::Storage::Transaction &transaction); + static void index(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction); + static void removeIndex(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction); static QSharedPointer > initializeReadPropertyMapper(); static QSharedPointer > initializeWritePropertyMapper(); }; diff --git a/common/domainadaptor.h b/common/domainadaptor.h index 39bd3b8..d43fad7 100644 --- a/common/domainadaptor.h +++ b/common/domainadaptor.h @@ -39,7 +39,7 @@ * Create a buffer from a domain object using the provided mappings */ template -flatbuffers::Offset createBufferPart(const Akonadi2::ApplicationDomain::ApplicationDomainType &domainObject, flatbuffers::FlatBufferBuilder &fbb, const WritePropertyMapper &mapper) +flatbuffers::Offset createBufferPart(const Sink::ApplicationDomain::ApplicationDomainType &domainObject, flatbuffers::FlatBufferBuilder &fbb, const WritePropertyMapper &mapper) { //First create a primitives such as strings using the mappings QList > propertiesToAddToResource; @@ -67,11 +67,11 @@ flatbuffers::Offset createBufferPart(const Akonadi2::ApplicationDomain:: * After this the buffer can be extracted from the FlatBufferBuilder object. */ template -static void createBufferPartBuffer(const Akonadi2::ApplicationDomain::ApplicationDomainType &domainObject, flatbuffers::FlatBufferBuilder &fbb, WritePropertyMapper &mapper) +static void createBufferPartBuffer(const Sink::ApplicationDomain::ApplicationDomainType &domainObject, flatbuffers::FlatBufferBuilder &fbb, WritePropertyMapper &mapper) { auto pos = createBufferPart(domainObject, fbb, mapper); // Because we cannot template the following call - // Akonadi2::ApplicationDomain::Buffer::FinishEventBuffer(fbb, pos); + // Sink::ApplicationDomain::Buffer::FinishEventBuffer(fbb, pos); // FIXME: This means all buffers in here must have the AKFB identifier fbb.Finish(pos, "AKFB"); flatbuffers::Verifier verifier(fbb.GetBufferPointer(), fbb.GetSize()); @@ -84,7 +84,7 @@ static void createBufferPartBuffer(const Akonadi2::ApplicationDomain::Applicatio * A generic adaptor implementation that uses a property mapper to read/write values. */ template -class GenericBufferAdaptor : public Akonadi2::ApplicationDomain::BufferAdaptor +class GenericBufferAdaptor : public Sink::ApplicationDomain::BufferAdaptor { public: GenericBufferAdaptor() @@ -123,13 +123,13 @@ public: template class DomainTypeAdaptorFactory : public DomainTypeAdaptorFactoryInterface { - typedef typename Akonadi2::ApplicationDomain::TypeImplementation::Buffer LocalBuffer; - typedef typename Akonadi2::ApplicationDomain::TypeImplementation::BufferBuilder LocalBuilder; + typedef typename Sink::ApplicationDomain::TypeImplementation::Buffer LocalBuffer; + typedef typename Sink::ApplicationDomain::TypeImplementation::BufferBuilder LocalBuilder; public: DomainTypeAdaptorFactory() : - mLocalMapper(Akonadi2::ApplicationDomain::TypeImplementation::initializeReadPropertyMapper()), + mLocalMapper(Sink::ApplicationDomain::TypeImplementation::initializeReadPropertyMapper()), mResourceMapper(QSharedPointer >::create()), - mLocalWriteMapper(Akonadi2::ApplicationDomain::TypeImplementation::initializeWritePropertyMapper()), + mLocalWriteMapper(Sink::ApplicationDomain::TypeImplementation::initializeWritePropertyMapper()), mResourceWriteMapper(QSharedPointer >::create()) {}; virtual ~DomainTypeAdaptorFactory() {}; @@ -139,11 +139,11 @@ public: * * This returns by default a GenericBufferAdaptor initialized with the corresponding property mappers. */ - virtual QSharedPointer createAdaptor(const Akonadi2::Entity &entity) Q_DECL_OVERRIDE + virtual QSharedPointer createAdaptor(const Sink::Entity &entity) Q_DECL_OVERRIDE { - const auto resourceBuffer = Akonadi2::EntityBuffer::readBuffer(entity.resource()); - const auto localBuffer = Akonadi2::EntityBuffer::readBuffer(entity.local()); - // const auto metadataBuffer = Akonadi2::EntityBuffer::readBuffer(entity.metadata()); + const auto resourceBuffer = Sink::EntityBuffer::readBuffer(entity.resource()); + const auto localBuffer = Sink::EntityBuffer::readBuffer(entity.local()); + // const auto metadataBuffer = Sink::EntityBuffer::readBuffer(entity.metadata()); auto adaptor = QSharedPointer >::create(); adaptor->mLocalBuffer = localBuffer; @@ -153,7 +153,7 @@ public: return adaptor; } - virtual void createBuffer(const Akonadi2::ApplicationDomain::ApplicationDomainType &domainObject, flatbuffers::FlatBufferBuilder &fbb, void const *metadataData = 0, size_t metadataSize = 0) Q_DECL_OVERRIDE + virtual void createBuffer(const Sink::ApplicationDomain::ApplicationDomainType &domainObject, flatbuffers::FlatBufferBuilder &fbb, void const *metadataData = 0, size_t metadataSize = 0) Q_DECL_OVERRIDE { flatbuffers::FlatBufferBuilder localFbb; if (mLocalWriteMapper) { @@ -167,7 +167,7 @@ public: createBufferPartBuffer(domainObject, resFbb, *mResourceWriteMapper); } - Akonadi2::EntityBuffer::assembleEntityBuffer(fbb, metadataData, metadataSize, resFbb.GetBufferPointer(), resFbb.GetSize(), localFbb.GetBufferPointer(), localFbb.GetSize()); + Sink::EntityBuffer::assembleEntityBuffer(fbb, metadataData, metadataSize, resFbb.GetBufferPointer(), resFbb.GetSize(), localFbb.GetBufferPointer(), localFbb.GetSize()); } diff --git a/common/domaintypeadaptorfactoryinterface.h b/common/domaintypeadaptorfactoryinterface.h index 8c99aa1..d974bbf 100644 --- a/common/domaintypeadaptorfactoryinterface.h +++ b/common/domaintypeadaptorfactoryinterface.h @@ -20,7 +20,7 @@ #include -namespace Akonadi2 { +namespace Sink { namespace ApplicationDomain { class BufferAdaptor; class ApplicationDomainType; @@ -37,6 +37,6 @@ class DomainTypeAdaptorFactoryInterface public: typedef QSharedPointer Ptr; virtual ~DomainTypeAdaptorFactoryInterface() {}; - virtual QSharedPointer createAdaptor(const Akonadi2::Entity &entity) = 0; - virtual void createBuffer(const Akonadi2::ApplicationDomain::ApplicationDomainType &domainType, flatbuffers::FlatBufferBuilder &fbb, void const *metadataData = 0, size_t metadataSize = 0) = 0; + virtual QSharedPointer createAdaptor(const Sink::Entity &entity) = 0; + virtual void createBuffer(const Sink::ApplicationDomain::ApplicationDomainType &domainType, flatbuffers::FlatBufferBuilder &fbb, void const *metadataData = 0, size_t metadataSize = 0) = 0; }; diff --git a/common/entity.fbs b/common/entity.fbs index 565b1a7..fe9b727 100644 --- a/common/entity.fbs +++ b/common/entity.fbs @@ -1,4 +1,4 @@ -namespace Akonadi2; +namespace Sink; table Entity { metadata: [ubyte]; diff --git a/common/entitybuffer.cpp b/common/entitybuffer.cpp index c14c86d..0e5435a 100644 --- a/common/entitybuffer.cpp +++ b/common/entitybuffer.cpp @@ -4,17 +4,17 @@ #include "metadata_generated.h" #include -using namespace Akonadi2; +using namespace Sink; EntityBuffer::EntityBuffer(const void *dataValue, int dataSize) : mEntity(nullptr) { flatbuffers::Verifier verifyer(reinterpret_cast(dataValue), dataSize); - // Q_ASSERT(Akonadi2::VerifyEntity(verifyer)); - if (!Akonadi2::VerifyEntityBuffer(verifyer)) { + // Q_ASSERT(Sink::VerifyEntity(verifyer)); + if (!Sink::VerifyEntityBuffer(verifyer)) { qWarning() << "invalid buffer"; } else { - mEntity = Akonadi2::GetEntity(dataValue); + mEntity = Sink::GetEntity(dataValue); } } @@ -23,7 +23,7 @@ bool EntityBuffer::isValid() const return mEntity; } -const Akonadi2::Entity &EntityBuffer::entity() +const Sink::Entity &EntityBuffer::entity() { return *mEntity; } @@ -55,7 +55,7 @@ const uint8_t* EntityBuffer::localBuffer() void EntityBuffer::extractResourceBuffer(void *dataValue, int dataSize, const std::function &handler) { - Akonadi2::EntityBuffer buffer(dataValue, dataSize); + Sink::EntityBuffer buffer(dataValue, dataSize); if (auto resourceData = buffer.entity().resource()) { handler(resourceData->Data(), resourceData->size()); } @@ -76,7 +76,7 @@ void EntityBuffer::assembleEntityBuffer(flatbuffers::FlatBufferBuilder &fbb, voi auto metadata = appendAsVector(fbb, metadataData, metadataSize); auto resource = appendAsVector(fbb, resourceData, resourceSize); auto local = appendAsVector(fbb, localData, localSize); - auto entity = Akonadi2::CreateEntity(fbb, metadata, resource, local); - Akonadi2::FinishEntityBuffer(fbb, entity); + auto entity = Sink::CreateEntity(fbb, metadata, resource, local); + Sink::FinishEntityBuffer(fbb, entity); } diff --git a/common/entitybuffer.h b/common/entitybuffer.h index a58aae9..c9c2453 100644 --- a/common/entitybuffer.h +++ b/common/entitybuffer.h @@ -3,7 +3,7 @@ #include #include -namespace Akonadi2 { +namespace Sink { struct Entity; class EntityBuffer { diff --git a/common/facade.cpp b/common/facade.cpp index 91021db..8cb776c 100644 --- a/common/facade.cpp +++ b/common/facade.cpp @@ -27,7 +27,7 @@ #include "queryrunner.h" #include "bufferutils.h" -using namespace Akonadi2; +using namespace Sink; class ResourceAccessFactory { public: @@ -40,7 +40,7 @@ public: return *instance; } - Akonadi2::ResourceAccess::Ptr getAccess(const QByteArray &instanceIdentifier) + Sink::ResourceAccess::Ptr getAccess(const QByteArray &instanceIdentifier) { if (!mCache.contains(instanceIdentifier)) { //Reuse the pointer if something else kept the resourceaccess alive @@ -52,8 +52,8 @@ public: } if (!mCache.contains(instanceIdentifier)) { //Create a new instance if necessary - auto sharedPointer = Akonadi2::ResourceAccess::Ptr::create(instanceIdentifier); - QObject::connect(sharedPointer.data(), &Akonadi2::ResourceAccess::ready, sharedPointer.data(), [this, instanceIdentifier](bool ready) { + auto sharedPointer = Sink::ResourceAccess::Ptr::create(instanceIdentifier); + QObject::connect(sharedPointer.data(), &Sink::ResourceAccess::ready, sharedPointer.data(), [this, instanceIdentifier](bool ready) { if (!ready) { mCache.remove(instanceIdentifier); } @@ -76,14 +76,14 @@ public: return mCache.value(instanceIdentifier); } - QHash > mWeakCache; - QHash mCache; + QHash > mWeakCache; + QHash mCache; QHash mTimer; }; template -GenericFacade::GenericFacade(const QByteArray &resourceIdentifier, const DomainTypeAdaptorFactoryInterface::Ptr &adaptorFactory , const QSharedPointer resourceAccess) - : Akonadi2::StoreFacade(), +GenericFacade::GenericFacade(const QByteArray &resourceIdentifier, const DomainTypeAdaptorFactoryInterface::Ptr &adaptorFactory , const QSharedPointer resourceAccess) + : Sink::StoreFacade(), mResourceAccess(resourceAccess), mDomainTypeAdaptorFactory(adaptorFactory), mResourceInstanceIdentifier(resourceIdentifier) @@ -102,7 +102,7 @@ template QByteArray GenericFacade::bufferTypeForDomainType() { //We happen to have a one to one mapping - return Akonadi2::ApplicationDomain::getTypeName(); + return Sink::ApplicationDomain::getTypeName(); } template @@ -136,7 +136,7 @@ KAsync::Job GenericFacade::remove(const DomainType &domainObje } template -QPair, typename ResultEmitter::Ptr> GenericFacade::load(const Akonadi2::Query &query) +QPair, typename ResultEmitter::Ptr> GenericFacade::load(const Sink::Query &query) { //The runner lives for the lifetime of the query auto runner = new QueryRunner(query, mResourceAccess, mResourceInstanceIdentifier, mDomainTypeAdaptorFactory, bufferTypeForDomainType()); @@ -144,8 +144,8 @@ QPair, typename ResultEmitter::Ptr> } -template class Akonadi2::GenericFacade; -template class Akonadi2::GenericFacade; -template class Akonadi2::GenericFacade; +template class Sink::GenericFacade; +template class Sink::GenericFacade; +template class Sink::GenericFacade; #include "facade.moc" diff --git a/common/facade.h b/common/facade.h index de67e05..c25464f 100644 --- a/common/facade.h +++ b/common/facade.h @@ -29,7 +29,7 @@ #include "domaintypeadaptorfactoryinterface.h" #include "storage.h" -namespace Akonadi2 { +namespace Sink { /** * Default facade implementation for resources that are implemented in a separate process using the ResourceAccess class. @@ -43,7 +43,7 @@ namespace Akonadi2 { * Additionally a resource only has to provide a synchronizer plugin to execute the synchronization */ template -class GenericFacade: public Akonadi2::StoreFacade +class GenericFacade: public Sink::StoreFacade { public: /** @@ -52,18 +52,18 @@ public: * @param resourceIdentifier is the identifier of the resource instance * @param adaptorFactory is the adaptor factory used to generate the mappings from domain to resource types and vice versa */ - GenericFacade(const QByteArray &resourceIdentifier, const DomainTypeAdaptorFactoryInterface::Ptr &adaptorFactory = DomainTypeAdaptorFactoryInterface::Ptr(), const QSharedPointer resourceAccess = QSharedPointer()); + GenericFacade(const QByteArray &resourceIdentifier, const DomainTypeAdaptorFactoryInterface::Ptr &adaptorFactory = DomainTypeAdaptorFactoryInterface::Ptr(), const QSharedPointer resourceAccess = QSharedPointer()); ~GenericFacade(); static QByteArray bufferTypeForDomainType(); KAsync::Job create(const DomainType &domainObject) Q_DECL_OVERRIDE; KAsync::Job modify(const DomainType &domainObject) Q_DECL_OVERRIDE; KAsync::Job remove(const DomainType &domainObject) Q_DECL_OVERRIDE; - QPair, typename ResultEmitter::Ptr> load(const Akonadi2::Query &query) Q_DECL_OVERRIDE; + QPair, typename ResultEmitter::Ptr> load(const Sink::Query &query) Q_DECL_OVERRIDE; protected: //TODO use one resource access instance per application & per resource - QSharedPointer mResourceAccess; + QSharedPointer mResourceAccess; DomainTypeAdaptorFactoryInterface::Ptr mDomainTypeAdaptorFactory; QByteArray mResourceInstanceIdentifier; }; diff --git a/common/facadefactory.cpp b/common/facadefactory.cpp index 707d9ad..d9ee5f7 100644 --- a/common/facadefactory.cpp +++ b/common/facadefactory.cpp @@ -22,7 +22,7 @@ #include "resourcefacade.h" #include "resource.h" -using namespace Akonadi2; +using namespace Sink; QMutex FacadeFactory::sMutex; @@ -54,7 +54,7 @@ void FacadeFactory::resetFactory() void FacadeFactory::registerStaticFacades() { - registerFacade(QByteArray()); + registerFacade(QByteArray()); } std::shared_ptr FacadeFactory::getFacade(const QByteArray &resource, const QByteArray &instanceIdentifier, const QByteArray &typeName) @@ -65,7 +65,7 @@ std::shared_ptr FacadeFactory::getFacade(const QByteArray &resource, const if (!mFacadeRegistry.contains(k)) { locker.unlock(); //This will call FacadeFactory::instace() internally - Akonadi2::ResourceFactory::load(QString::fromLatin1(resource)); + Sink::ResourceFactory::load(QString::fromLatin1(resource)); locker.relock(); } diff --git a/common/facadefactory.h b/common/facadefactory.h index 19d1f40..3dca63b 100644 --- a/common/facadefactory.h +++ b/common/facadefactory.h @@ -30,7 +30,7 @@ #include "applicationdomaintype.h" #include "log.h" -namespace Akonadi2 { +namespace Sink { /** * Facade factory that returns a store facade implementation, by loading a plugin and providing the relevant implementation. diff --git a/common/facadeinterface.h b/common/facadeinterface.h index 318abf3..17cba5e 100644 --- a/common/facadeinterface.h +++ b/common/facadeinterface.h @@ -27,7 +27,7 @@ #include "applicationdomaintype.h" #include "resultprovider.h" -namespace Akonadi2 { +namespace Sink { class Query; /** @@ -68,7 +68,7 @@ public: /** * Load entities from the store. */ - virtual QPair, typename Akonadi2::ResultEmitter::Ptr > load(const Query &query) = 0; + virtual QPair, typename Sink::ResultEmitter::Ptr > load(const Query &query) = 0; }; template @@ -90,9 +90,9 @@ public: return KAsync::error(-1, "Failed to create a facade"); } - QPair, typename Akonadi2::ResultEmitter::Ptr > load(const Query &query) + QPair, typename Sink::ResultEmitter::Ptr > load(const Query &query) { - return qMakePair(KAsync::null(), typename Akonadi2::ResultEmitter::Ptr()); + return qMakePair(KAsync::null(), typename Sink::ResultEmitter::Ptr()); } }; diff --git a/common/genericresource.cpp b/common/genericresource.cpp index c7f323a..c7326d3 100644 --- a/common/genericresource.cpp +++ b/common/genericresource.cpp @@ -20,7 +20,7 @@ static int sBatchSize = 100; -using namespace Akonadi2; +using namespace Sink; /** * Replays changes from the storage one by one. @@ -105,8 +105,8 @@ public Q_SLOTS: } private: - Akonadi2::Storage mStorage; - Akonadi2::Storage mChangeReplayStore; + Sink::Storage mStorage; + Sink::Storage mChangeReplayStore; ReplayFunction mReplayFunction; }; @@ -118,7 +118,7 @@ class CommandProcessor : public QObject Q_OBJECT typedef std::function(void const *, size_t)> InspectionFunction; public: - CommandProcessor(Akonadi2::Pipeline *pipeline, QList commandQueues) + CommandProcessor(Sink::Pipeline *pipeline, QList commandQueues) : QObject(), mPipeline(pipeline), mCommandQueues(commandQueues), @@ -175,18 +175,18 @@ private slots: }).exec(); } - KAsync::Job processQueuedCommand(const Akonadi2::QueuedCommand *queuedCommand) + KAsync::Job processQueuedCommand(const Sink::QueuedCommand *queuedCommand) { - Log() << "Processing command: " << Akonadi2::Commands::name(queuedCommand->commandId()); + Log() << "Processing command: " << Sink::Commands::name(queuedCommand->commandId()); //Throw command into appropriate pipeline switch (queuedCommand->commandId()) { - case Akonadi2::Commands::DeleteEntityCommand: + case Sink::Commands::DeleteEntityCommand: return mPipeline->deletedEntity(queuedCommand->command()->Data(), queuedCommand->command()->size()); - case Akonadi2::Commands::ModifyEntityCommand: + case Sink::Commands::ModifyEntityCommand: return mPipeline->modifiedEntity(queuedCommand->command()->Data(), queuedCommand->command()->size()); - case Akonadi2::Commands::CreateEntityCommand: + case Sink::Commands::CreateEntityCommand: return mPipeline->newEntity(queuedCommand->command()->Data(), queuedCommand->command()->size()); - case Akonadi2::Commands::InspectionCommand: + case Sink::Commands::InspectionCommand: if (mInspect) { return mInspect(queuedCommand->command()->Data(), queuedCommand->command()->size()).then([]() { return -1; @@ -203,16 +203,16 @@ private slots: KAsync::Job processQueuedCommand(const QByteArray &data) { flatbuffers::Verifier verifyer(reinterpret_cast(data.constData()), data.size()); - if (!Akonadi2::VerifyQueuedCommandBuffer(verifyer)) { + if (!Sink::VerifyQueuedCommandBuffer(verifyer)) { Warning() << "invalid buffer"; // return KAsync::error(1, "Invalid Buffer"); } - auto queuedCommand = Akonadi2::GetQueuedCommand(data.constData()); + auto queuedCommand = Sink::GetQueuedCommand(data.constData()); const auto commandId = queuedCommand->commandId(); - Trace() << "Dequeued Command: " << Akonadi2::Commands::name(commandId); + Trace() << "Dequeued Command: " << Sink::Commands::name(commandId); return processQueuedCommand(queuedCommand).then( [commandId](qint64 createdRevision) -> qint64 { - Trace() << "Command pipeline processed: " << Akonadi2::Commands::name(commandId); + Trace() << "Command pipeline processed: " << Sink::Commands::name(commandId); return createdRevision; } , @@ -278,7 +278,7 @@ private slots: } private: - Akonadi2::Pipeline *mPipeline; + Sink::Pipeline *mPipeline; //Ordered by priority QList mCommandQueues; bool mProcessingLock; @@ -289,19 +289,19 @@ private: GenericResource::GenericResource(const QByteArray &resourceInstanceIdentifier, const QSharedPointer &pipeline) - : Akonadi2::Resource(), - mUserQueue(Akonadi2::storageLocation(), resourceInstanceIdentifier + ".userqueue"), - mSynchronizerQueue(Akonadi2::storageLocation(), resourceInstanceIdentifier + ".synchronizerqueue"), + : Sink::Resource(), + mUserQueue(Sink::storageLocation(), resourceInstanceIdentifier + ".userqueue"), + mSynchronizerQueue(Sink::storageLocation(), resourceInstanceIdentifier + ".synchronizerqueue"), mResourceInstanceIdentifier(resourceInstanceIdentifier), - mPipeline(pipeline ? pipeline : QSharedPointer::create(resourceInstanceIdentifier)), + mPipeline(pipeline ? pipeline : QSharedPointer::create(resourceInstanceIdentifier)), mError(0), mClientLowerBoundRevision(std::numeric_limits::max()) { mProcessor = new CommandProcessor(mPipeline.data(), QList() << &mUserQueue << &mSynchronizerQueue); mProcessor->setInspectionCommand([this](void const *command, size_t size) { flatbuffers::Verifier verifier((const uint8_t *)command, size); - if (Akonadi2::Commands::VerifyInspectionBuffer(verifier)) { - auto buffer = Akonadi2::Commands::GetInspection(command); + if (Sink::Commands::VerifyInspectionBuffer(verifier)) { + auto buffer = Sink::Commands::GetInspection(command); int inspectionType = buffer->type(); QByteArray inspectionId = BufferUtils::extractBuffer(buffer->id()); @@ -313,17 +313,17 @@ GenericResource::GenericResource(const QByteArray &resourceInstanceIdentifier, c QVariant expectedValue; s >> expectedValue; inspect(inspectionType, inspectionId, domainType, entityId, property, expectedValue).then([=]() { - Akonadi2::Notification n; - n.type = Akonadi2::Commands::NotificationType_Inspection; + Sink::Notification n; + n.type = Sink::Commands::NotificationType_Inspection; n.id = inspectionId; - n.code = Akonadi2::Commands::NotificationCode_Success; + n.code = Sink::Commands::NotificationCode_Success; emit notify(n); }, [=](int code, const QString &message) { - Akonadi2::Notification n; - n.type = Akonadi2::Commands::NotificationType_Inspection; + Sink::Notification n; + n.type = Sink::Commands::NotificationType_Inspection; n.message = message; n.id = inspectionId; - n.code = Akonadi2::Commands::NotificationCode_Failure; + n.code = Sink::Commands::NotificationCode_Failure; emit notify(n); }).exec(); return KAsync::null(); @@ -334,7 +334,7 @@ GenericResource::GenericResource(const QByteArray &resourceInstanceIdentifier, c QObject::connect(mPipeline.data(), &Pipeline::revisionUpdated, this, &Resource::revisionUpdated); mSourceChangeReplay = new ChangeReplay(resourceInstanceIdentifier, [this](const QByteArray &type, const QByteArray &key, const QByteArray &value) { //This results in a deadlock when a sync is in progress and we try to create a second writing transaction (which is why we turn changereplay off during the sync) - auto synchronizationStore = QSharedPointer::create(Akonadi2::storageLocation(), mResourceInstanceIdentifier + ".synchronization", Akonadi2::Storage::ReadWrite); + auto synchronizationStore = QSharedPointer::create(Sink::storageLocation(), mResourceInstanceIdentifier + ".synchronization", Sink::Storage::ReadWrite); return this->replay(*synchronizationStore, type, key, value).then([synchronizationStore](){}); }); enableChangeReplay(true); @@ -370,13 +370,13 @@ void GenericResource::enableChangeReplay(bool enable) } } -void GenericResource::addType(const QByteArray &type, DomainTypeAdaptorFactoryInterface::Ptr factory, const QVector &preprocessors) +void GenericResource::addType(const QByteArray &type, DomainTypeAdaptorFactoryInterface::Ptr factory, const QVector &preprocessors) { mPipeline->setPreprocessors(type, preprocessors); mPipeline->setAdaptorFactory(type, factory); } -KAsync::Job GenericResource::replay(Akonadi2::Storage &synchronizationStore, const QByteArray &type, const QByteArray &key, const QByteArray &value) +KAsync::Job GenericResource::replay(Sink::Storage &synchronizationStore, const QByteArray &type, const QByteArray &key, const QByteArray &value) { return KAsync::null(); } @@ -384,18 +384,18 @@ KAsync::Job GenericResource::replay(Akonadi2::Storage &synchronizationStor void GenericResource::removeFromDisk(const QByteArray &instanceIdentifier) { Warning() << "Removing from generic resource"; - Akonadi2::Storage(Akonadi2::storageLocation(), instanceIdentifier, Akonadi2::Storage::ReadWrite).removeFromDisk(); - Akonadi2::Storage(Akonadi2::storageLocation(), instanceIdentifier + ".userqueue", Akonadi2::Storage::ReadWrite).removeFromDisk(); - Akonadi2::Storage(Akonadi2::storageLocation(), instanceIdentifier + ".synchronizerqueue", Akonadi2::Storage::ReadWrite).removeFromDisk(); - Akonadi2::Storage(Akonadi2::storageLocation(), instanceIdentifier + ".changereplay", Akonadi2::Storage::ReadWrite).removeFromDisk(); + Sink::Storage(Sink::storageLocation(), instanceIdentifier, Sink::Storage::ReadWrite).removeFromDisk(); + Sink::Storage(Sink::storageLocation(), instanceIdentifier + ".userqueue", Sink::Storage::ReadWrite).removeFromDisk(); + Sink::Storage(Sink::storageLocation(), instanceIdentifier + ".synchronizerqueue", Sink::Storage::ReadWrite).removeFromDisk(); + Sink::Storage(Sink::storageLocation(), instanceIdentifier + ".changereplay", Sink::Storage::ReadWrite).removeFromDisk(); } qint64 GenericResource::diskUsage(const QByteArray &instanceIdentifier) { - auto size = Akonadi2::Storage(Akonadi2::storageLocation(), instanceIdentifier, Akonadi2::Storage::ReadOnly).diskUsage(); - size += Akonadi2::Storage(Akonadi2::storageLocation(), instanceIdentifier + ".userqueue", Akonadi2::Storage::ReadOnly).diskUsage(); - size += Akonadi2::Storage(Akonadi2::storageLocation(), instanceIdentifier + ".synchronizerqueue", Akonadi2::Storage::ReadOnly).diskUsage(); - size += Akonadi2::Storage(Akonadi2::storageLocation(), instanceIdentifier + ".changereplay", Akonadi2::Storage::ReadOnly).diskUsage(); + auto size = Sink::Storage(Sink::storageLocation(), instanceIdentifier, Sink::Storage::ReadOnly).diskUsage(); + size += Sink::Storage(Sink::storageLocation(), instanceIdentifier + ".userqueue", Sink::Storage::ReadOnly).diskUsage(); + size += Sink::Storage(Sink::storageLocation(), instanceIdentifier + ".synchronizerqueue", Sink::Storage::ReadOnly).diskUsage(); + size += Sink::Storage(Sink::storageLocation(), instanceIdentifier + ".changereplay", Sink::Storage::ReadOnly).diskUsage(); return size; } @@ -413,9 +413,9 @@ int GenericResource::error() const void GenericResource::enqueueCommand(MessageQueue &mq, int commandId, const QByteArray &data) { flatbuffers::FlatBufferBuilder fbb; - auto commandData = Akonadi2::EntityBuffer::appendAsVector(fbb, data.constData(), data.size()); - auto buffer = Akonadi2::CreateQueuedCommand(fbb, commandId, commandData); - Akonadi2::FinishQueuedCommandBuffer(fbb, buffer); + auto commandData = Sink::EntityBuffer::appendAsVector(fbb, data.constData(), data.size()); + auto buffer = Sink::CreateQueuedCommand(fbb, commandId, commandData); + Sink::FinishQueuedCommandBuffer(fbb, buffer); mq.enqueue(fbb.GetBufferPointer(), fbb.GetSize()); } @@ -440,8 +440,8 @@ KAsync::Job GenericResource::synchronizeWithSource() Log() << " Synchronizing"; //Changereplay would deadlock otherwise when trying to open the synchronization store enableChangeReplay(false); - auto mainStore = QSharedPointer::create(Akonadi2::storageLocation(), mResourceInstanceIdentifier, Akonadi2::Storage::ReadOnly); - auto syncStore = QSharedPointer::create(Akonadi2::storageLocation(), mResourceInstanceIdentifier + ".synchronization", Akonadi2::Storage::ReadWrite); + auto mainStore = QSharedPointer::create(Sink::storageLocation(), mResourceInstanceIdentifier, Sink::Storage::ReadOnly); + auto syncStore = QSharedPointer::create(Sink::storageLocation(), mResourceInstanceIdentifier + ".synchronization", Sink::Storage::ReadWrite); synchronizeWithSource(*mainStore, *syncStore).then([this, mainStore, syncStore]() { Log() << "Done Synchronizing"; enableChangeReplay(true); @@ -449,7 +449,7 @@ KAsync::Job GenericResource::synchronizeWithSource() }); } -KAsync::Job GenericResource::synchronizeWithSource(Akonadi2::Storage &mainStore, Akonadi2::Storage &synchronizationStore) +KAsync::Job GenericResource::synchronizeWithSource(Sink::Storage &mainStore, Sink::Storage &synchronizationStore) { return KAsync::null(); } @@ -508,7 +508,7 @@ void GenericResource::setLowerBoundRevision(qint64 revision) updateLowerBoundRevision(); } -void GenericResource::createEntity(const QByteArray &akonadiId, const QByteArray &bufferType, const Akonadi2::ApplicationDomain::ApplicationDomainType &domainObject, DomainTypeAdaptorFactoryInterface &adaptorFactory, std::function callback) +void GenericResource::createEntity(const QByteArray &sinkId, const QByteArray &bufferType, const Sink::ApplicationDomain::ApplicationDomainType &domainObject, DomainTypeAdaptorFactoryInterface &adaptorFactory, std::function callback) { //These changes are coming from the source const auto replayToSource = false; @@ -516,45 +516,45 @@ void GenericResource::createEntity(const QByteArray &akonadiId, const QByteArray adaptorFactory.createBuffer(domainObject, entityFbb); flatbuffers::FlatBufferBuilder fbb; //This is the resource type and not the domain type - auto entityId = fbb.CreateString(akonadiId.toStdString()); + auto entityId = fbb.CreateString(sinkId.toStdString()); auto type = fbb.CreateString(bufferType.toStdString()); - auto delta = Akonadi2::EntityBuffer::appendAsVector(fbb, entityFbb.GetBufferPointer(), entityFbb.GetSize()); - auto location = Akonadi2::Commands::CreateCreateEntity(fbb, entityId, type, delta, replayToSource); - Akonadi2::Commands::FinishCreateEntityBuffer(fbb, location); + auto delta = Sink::EntityBuffer::appendAsVector(fbb, entityFbb.GetBufferPointer(), entityFbb.GetSize()); + auto location = Sink::Commands::CreateCreateEntity(fbb, entityId, type, delta, replayToSource); + Sink::Commands::FinishCreateEntityBuffer(fbb, location); callback(BufferUtils::extractBuffer(fbb)); } -void GenericResource::modifyEntity(const QByteArray &akonadiId, qint64 revision, const QByteArray &bufferType, const Akonadi2::ApplicationDomain::ApplicationDomainType &domainObject, DomainTypeAdaptorFactoryInterface &adaptorFactory, std::function callback) +void GenericResource::modifyEntity(const QByteArray &sinkId, qint64 revision, const QByteArray &bufferType, const Sink::ApplicationDomain::ApplicationDomainType &domainObject, DomainTypeAdaptorFactoryInterface &adaptorFactory, std::function callback) { //These changes are coming from the source const auto replayToSource = false; flatbuffers::FlatBufferBuilder entityFbb; adaptorFactory.createBuffer(domainObject, entityFbb); flatbuffers::FlatBufferBuilder fbb; - auto entityId = fbb.CreateString(akonadiId.toStdString()); + auto entityId = fbb.CreateString(sinkId.toStdString()); //This is the resource type and not the domain type auto type = fbb.CreateString(bufferType.toStdString()); - auto delta = Akonadi2::EntityBuffer::appendAsVector(fbb, entityFbb.GetBufferPointer(), entityFbb.GetSize()); + auto delta = Sink::EntityBuffer::appendAsVector(fbb, entityFbb.GetBufferPointer(), entityFbb.GetSize()); //TODO removals - auto location = Akonadi2::Commands::CreateModifyEntity(fbb, revision, entityId, 0, type, delta, replayToSource); - Akonadi2::Commands::FinishModifyEntityBuffer(fbb, location); + auto location = Sink::Commands::CreateModifyEntity(fbb, revision, entityId, 0, type, delta, replayToSource); + Sink::Commands::FinishModifyEntityBuffer(fbb, location); callback(BufferUtils::extractBuffer(fbb)); } -void GenericResource::deleteEntity(const QByteArray &akonadiId, qint64 revision, const QByteArray &bufferType, std::function callback) +void GenericResource::deleteEntity(const QByteArray &sinkId, qint64 revision, const QByteArray &bufferType, std::function callback) { //These changes are coming from the source const auto replayToSource = false; flatbuffers::FlatBufferBuilder fbb; - auto entityId = fbb.CreateString(akonadiId.toStdString()); + auto entityId = fbb.CreateString(sinkId.toStdString()); //This is the resource type and not the domain type auto type = fbb.CreateString(bufferType.toStdString()); - auto location = Akonadi2::Commands::CreateDeleteEntity(fbb, revision, entityId, type, replayToSource); - Akonadi2::Commands::FinishDeleteEntityBuffer(fbb, location); + auto location = Sink::Commands::CreateDeleteEntity(fbb, revision, entityId, type, replayToSource); + Sink::Commands::FinishDeleteEntityBuffer(fbb, location); callback(BufferUtils::extractBuffer(fbb)); } -void GenericResource::recordRemoteId(const QByteArray &bufferType, const QByteArray &localId, const QByteArray &remoteId, Akonadi2::Storage::Transaction &transaction) +void GenericResource::recordRemoteId(const QByteArray &bufferType, const QByteArray &localId, const QByteArray &remoteId, Sink::Storage::Transaction &transaction) { Index index("rid.mapping." + bufferType, transaction); Index localIndex("localid.mapping." + bufferType, transaction); @@ -562,7 +562,7 @@ void GenericResource::recordRemoteId(const QByteArray &bufferType, const QByteAr localIndex.add(localId, remoteId); } -void GenericResource::removeRemoteId(const QByteArray &bufferType, const QByteArray &localId, const QByteArray &remoteId, Akonadi2::Storage::Transaction &transaction) +void GenericResource::removeRemoteId(const QByteArray &bufferType, const QByteArray &localId, const QByteArray &remoteId, Sink::Storage::Transaction &transaction) { Index index("rid.mapping." + bufferType, transaction); Index localIndex("localid.mapping." + bufferType, transaction); @@ -570,21 +570,21 @@ void GenericResource::removeRemoteId(const QByteArray &bufferType, const QByteAr localIndex.remove(localId, remoteId); } -QByteArray GenericResource::resolveRemoteId(const QByteArray &bufferType, const QByteArray &remoteId, Akonadi2::Storage::Transaction &transaction) +QByteArray GenericResource::resolveRemoteId(const QByteArray &bufferType, const QByteArray &remoteId, Sink::Storage::Transaction &transaction) { //Lookup local id for remote id, or insert a new pair otherwise Index index("rid.mapping." + bufferType, transaction); Index localIndex("localid.mapping." + bufferType, transaction); - QByteArray akonadiId = index.lookup(remoteId); - if (akonadiId.isEmpty()) { - akonadiId = QUuid::createUuid().toString().toUtf8(); - index.add(remoteId, akonadiId); - localIndex.add(akonadiId, remoteId); + QByteArray sinkId = index.lookup(remoteId); + if (sinkId.isEmpty()) { + sinkId = QUuid::createUuid().toString().toUtf8(); + index.add(remoteId, sinkId); + localIndex.add(sinkId, remoteId); } - return akonadiId; + return sinkId; } -QByteArray GenericResource::resolveLocalId(const QByteArray &bufferType, const QByteArray &localId, Akonadi2::Storage::Transaction &transaction) +QByteArray GenericResource::resolveLocalId(const QByteArray &bufferType, const QByteArray &localId, Sink::Storage::Transaction &transaction) { Index index("localid.mapping." + bufferType, transaction); QByteArray remoteId = index.lookup(localId); @@ -595,29 +595,29 @@ QByteArray GenericResource::resolveLocalId(const QByteArray &bufferType, const Q return remoteId; } -void GenericResource::scanForRemovals(Akonadi2::Storage::Transaction &transaction, Akonadi2::Storage::Transaction &synchronizationTransaction, const QByteArray &bufferType, const std::function &callback)> &entryGenerator, std::function exists) +void GenericResource::scanForRemovals(Sink::Storage::Transaction &transaction, Sink::Storage::Transaction &synchronizationTransaction, const QByteArray &bufferType, const std::function &callback)> &entryGenerator, std::function exists) { entryGenerator([this, &transaction, bufferType, &synchronizationTransaction, &exists](const QByteArray &key) { - auto akonadiId = Akonadi2::Storage::uidFromKey(key); + auto sinkId = Sink::Storage::uidFromKey(key); Trace() << "Checking for removal " << key; - const auto remoteId = resolveLocalId(bufferType, akonadiId, synchronizationTransaction); + const auto remoteId = resolveLocalId(bufferType, sinkId, synchronizationTransaction); //If we have no remoteId, the entity hasn't been replayed to the source yet if (!remoteId.isEmpty()) { if (!exists(remoteId)) { - Trace() << "Found a removed entity: " << akonadiId; - deleteEntity(akonadiId, Akonadi2::Storage::maxRevision(transaction), bufferType, [this](const QByteArray &buffer) { - enqueueCommand(mSynchronizerQueue, Akonadi2::Commands::DeleteEntityCommand, buffer); + Trace() << "Found a removed entity: " << sinkId; + deleteEntity(sinkId, Sink::Storage::maxRevision(transaction), bufferType, [this](const QByteArray &buffer) { + enqueueCommand(mSynchronizerQueue, Sink::Commands::DeleteEntityCommand, buffer); }); } } }); } -static QSharedPointer getLatest(const Akonadi2::Storage::NamedDatabase &db, const QByteArray &uid, DomainTypeAdaptorFactoryInterface &adaptorFactory) +static QSharedPointer getLatest(const Sink::Storage::NamedDatabase &db, const QByteArray &uid, DomainTypeAdaptorFactoryInterface &adaptorFactory) { - QSharedPointer current; + QSharedPointer current; db.findLatest(uid, [¤t, &adaptorFactory](const QByteArray &key, const QByteArray &data) -> bool { - Akonadi2::EntityBuffer buffer(const_cast(data.data()), data.size()); + Sink::EntityBuffer buffer(const_cast(data.data()), data.size()); if (!buffer.isValid()) { Warning() << "Read invalid buffer from disk"; } else { @@ -625,35 +625,35 @@ static QSharedPointer getLatest(cons } return false; }, - [](const Akonadi2::Storage::Error &error) { + [](const Sink::Storage::Error &error) { Warning() << "Failed to read current value from storage: " << error.message; }); return current; } -void GenericResource::createOrModify(Akonadi2::Storage::Transaction &transaction, Akonadi2::Storage::Transaction &synchronizationTransaction, DomainTypeAdaptorFactoryInterface &adaptorFactory, const QByteArray &bufferType, const QByteArray &remoteId, const Akonadi2::ApplicationDomain::ApplicationDomainType &entity) +void GenericResource::createOrModify(Sink::Storage::Transaction &transaction, Sink::Storage::Transaction &synchronizationTransaction, DomainTypeAdaptorFactoryInterface &adaptorFactory, const QByteArray &bufferType, const QByteArray &remoteId, const Sink::ApplicationDomain::ApplicationDomainType &entity) { auto mainDatabase = transaction.openDatabase(bufferType + ".main"); - const auto akonadiId = resolveRemoteId(bufferType, remoteId, synchronizationTransaction); - const auto found = mainDatabase.contains(akonadiId); + const auto sinkId = resolveRemoteId(bufferType, remoteId, synchronizationTransaction); + const auto found = mainDatabase.contains(sinkId); if (!found) { Trace() << "Found a new entity: " << remoteId; - createEntity(akonadiId, bufferType, entity, adaptorFactory, [this](const QByteArray &buffer) { - enqueueCommand(mSynchronizerQueue, Akonadi2::Commands::CreateEntityCommand, buffer); + createEntity(sinkId, bufferType, entity, adaptorFactory, [this](const QByteArray &buffer) { + enqueueCommand(mSynchronizerQueue, Sink::Commands::CreateEntityCommand, buffer); }); } else { //modification - if (auto current = getLatest(mainDatabase, akonadiId, adaptorFactory)) { + if (auto current = getLatest(mainDatabase, sinkId, adaptorFactory)) { bool changed = false; for (const auto &property : entity.changedProperties()) { if (entity.getProperty(property) != current->getProperty(property)) { - Trace() << "Property changed " << akonadiId << property; + Trace() << "Property changed " << sinkId << property; changed = true; } } if (changed) { Trace() << "Found a modified entity: " << remoteId; - modifyEntity(akonadiId, Akonadi2::Storage::maxRevision(transaction), bufferType, entity, adaptorFactory, [this](const QByteArray &buffer) { - enqueueCommand(mSynchronizerQueue, Akonadi2::Commands::ModifyEntityCommand, buffer); + modifyEntity(sinkId, Sink::Storage::maxRevision(transaction), bufferType, entity, adaptorFactory, [this](const QByteArray &buffer) { + enqueueCommand(mSynchronizerQueue, Sink::Commands::ModifyEntityCommand, buffer); }); } } else { diff --git a/common/genericresource.h b/common/genericresource.h index d71061c..4ae2645 100644 --- a/common/genericresource.h +++ b/common/genericresource.h @@ -19,7 +19,7 @@ */ #pragma once -#include +#include #include #include #include @@ -29,7 +29,7 @@ class CommandProcessor; class ChangeReplay; -namespace Akonadi2 +namespace Sink { class Pipeline; class Preprocessor; @@ -37,7 +37,7 @@ class Preprocessor; /** * Generic Resource implementation. */ -class AKONADI2COMMON_EXPORT GenericResource : public Resource +class SINKCOMMON_EXPORT GenericResource : public Resource { public: GenericResource(const QByteArray &resourceInstanceIdentifier, const QSharedPointer &pipeline = QSharedPointer()); @@ -45,7 +45,7 @@ public: virtual void processCommand(int commandId, const QByteArray &data) Q_DECL_OVERRIDE; virtual KAsync::Job synchronizeWithSource() Q_DECL_OVERRIDE; - virtual KAsync::Job synchronizeWithSource(Akonadi2::Storage &mainStore, Akonadi2::Storage &synchronizationStore); + virtual KAsync::Job synchronizeWithSource(Sink::Storage &mainStore, Sink::Storage &synchronizationStore); virtual KAsync::Job processAllMessages() Q_DECL_OVERRIDE; virtual void setLowerBoundRevision(qint64 revision) Q_DECL_OVERRIDE; virtual KAsync::Job inspect(int inspectionType, const QByteArray &inspectionId, const QByteArray &domainType, const QByteArray &entityId, const QByteArray &property, const QVariant &expectedValue); @@ -60,34 +60,34 @@ private Q_SLOTS: protected: void enableChangeReplay(bool); - void addType(const QByteArray &type, DomainTypeAdaptorFactoryInterface::Ptr factory, const QVector &preprocessors); - virtual KAsync::Job replay(Akonadi2::Storage &synchronizationStore, const QByteArray &type, const QByteArray &key, const QByteArray &value); + void addType(const QByteArray &type, DomainTypeAdaptorFactoryInterface::Ptr factory, const QVector &preprocessors); + virtual KAsync::Job replay(Sink::Storage &synchronizationStore, const QByteArray &type, const QByteArray &key, const QByteArray &value); void onProcessorError(int errorCode, const QString &errorMessage); void enqueueCommand(MessageQueue &mq, int commandId, const QByteArray &data); - static void createEntity(const QByteArray &localId, const QByteArray &bufferType, const Akonadi2::ApplicationDomain::ApplicationDomainType &domainObject, DomainTypeAdaptorFactoryInterface &adaptorFactory, std::function callback); - static void modifyEntity(const QByteArray &localId, qint64 revision, const QByteArray &bufferType, const Akonadi2::ApplicationDomain::ApplicationDomainType &domainObject, DomainTypeAdaptorFactoryInterface &adaptorFactory, std::function callback); + static void createEntity(const QByteArray &localId, const QByteArray &bufferType, const Sink::ApplicationDomain::ApplicationDomainType &domainObject, DomainTypeAdaptorFactoryInterface &adaptorFactory, std::function callback); + static void modifyEntity(const QByteArray &localId, qint64 revision, const QByteArray &bufferType, const Sink::ApplicationDomain::ApplicationDomainType &domainObject, DomainTypeAdaptorFactoryInterface &adaptorFactory, std::function callback); static void deleteEntity(const QByteArray &localId, qint64 revision, const QByteArray &bufferType, std::function callback); /** * Records a localId to remoteId mapping */ - void recordRemoteId(const QByteArray &bufferType, const QByteArray &localId, const QByteArray &remoteId, Akonadi2::Storage::Transaction &transaction); - void removeRemoteId(const QByteArray &bufferType, const QByteArray &localId, const QByteArray &remoteId, Akonadi2::Storage::Transaction &transaction); + void recordRemoteId(const QByteArray &bufferType, const QByteArray &localId, const QByteArray &remoteId, Sink::Storage::Transaction &transaction); + void removeRemoteId(const QByteArray &bufferType, const QByteArray &localId, const QByteArray &remoteId, Sink::Storage::Transaction &transaction); /** * Tries to find a local id for the remote id, and creates a new local id otherwise. * * The new local id is recorded in the local to remote id mapping. */ - QByteArray resolveRemoteId(const QByteArray &type, const QByteArray &remoteId, Akonadi2::Storage::Transaction &transaction); + QByteArray resolveRemoteId(const QByteArray &type, const QByteArray &remoteId, Sink::Storage::Transaction &transaction); /** * Tries to find a remote id for a local id. * * This can fail if the entity hasn't been written back to the server yet. */ - QByteArray resolveLocalId(const QByteArray &bufferType, const QByteArray &localId, Akonadi2::Storage::Transaction &transaction); + QByteArray resolveLocalId(const QByteArray &bufferType, const QByteArray &localId, Sink::Storage::Transaction &transaction); /** * A synchronous algorithm to remove entities that are no longer existing. @@ -99,14 +99,14 @@ protected: * * All functions are called synchronously, and both @param entryGenerator and @param exists need to be synchronous. */ - void scanForRemovals(Akonadi2::Storage::Transaction &transaction, Akonadi2::Storage::Transaction &synchronizationTransaction, const QByteArray &bufferType, const std::function &callback)> &entryGenerator, std::function exists); + void scanForRemovals(Sink::Storage::Transaction &transaction, Sink::Storage::Transaction &synchronizationTransaction, const QByteArray &bufferType, const std::function &callback)> &entryGenerator, std::function exists); /** * An algorithm to create or modify the entity. * * Depending on whether the entity is locally available, or has changed. */ - void createOrModify(Akonadi2::Storage::Transaction &transaction, Akonadi2::Storage::Transaction &synchronizationTransaction, DomainTypeAdaptorFactoryInterface &adaptorFactory, const QByteArray &bufferType, const QByteArray &remoteId, const Akonadi2::ApplicationDomain::ApplicationDomainType &entity); + void createOrModify(Sink::Storage::Transaction &transaction, Sink::Storage::Transaction &synchronizationTransaction, DomainTypeAdaptorFactoryInterface &adaptorFactory, const QByteArray &bufferType, const QByteArray &remoteId, const Sink::ApplicationDomain::ApplicationDomainType &entity); MessageQueue mUserQueue; MessageQueue mSynchronizerQueue; diff --git a/common/index.cpp b/common/index.cpp index f4de93c..25dfb7c 100644 --- a/common/index.cpp +++ b/common/index.cpp @@ -1,15 +1,15 @@ #include "index.h" #include -Index::Index(const QString &storageRoot, const QString &name, Akonadi2::Storage::AccessMode mode) - : mTransaction(Akonadi2::Storage(storageRoot, name, mode).createTransaction(mode)), - mDb(mTransaction.openDatabase(name.toLatin1(), std::function(), true)) +Index::Index(const QString &storageRoot, const QString &name, Sink::Storage::AccessMode mode) + : mTransaction(Sink::Storage(storageRoot, name, mode).createTransaction(mode)), + mDb(mTransaction.openDatabase(name.toLatin1(), std::function(), true)) { } -Index::Index(const QByteArray &name, Akonadi2::Storage::Transaction &transaction) - : mDb(transaction.openDatabase(name, std::function(), true)) +Index::Index(const QByteArray &name, Sink::Storage::Transaction &transaction) + : mDb(transaction.openDatabase(name, std::function(), true)) { } @@ -31,7 +31,7 @@ void Index::lookup(const QByteArray &key, const std::function #include -class IndexUpdater : public Akonadi2::Preprocessor { +class IndexUpdater : public Sink::Preprocessor { public: IndexUpdater(const QByteArray &index, const QByteArray &type, const QByteArray &property) :mIndexIdentifier(index), @@ -31,31 +31,31 @@ public: } - void newEntity(const QByteArray &uid, qint64 revision, const Akonadi2::ApplicationDomain::BufferAdaptor &newEntity, Akonadi2::Storage::Transaction &transaction) Q_DECL_OVERRIDE + void newEntity(const QByteArray &uid, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &newEntity, Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE { add(newEntity.getProperty(mProperty), uid, transaction); } - void modifiedEntity(const QByteArray &uid, qint64 revision, const Akonadi2::ApplicationDomain::BufferAdaptor &oldEntity, const Akonadi2::ApplicationDomain::BufferAdaptor &newEntity, Akonadi2::Storage::Transaction &transaction) Q_DECL_OVERRIDE + void modifiedEntity(const QByteArray &uid, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &oldEntity, const Sink::ApplicationDomain::BufferAdaptor &newEntity, Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE { remove(oldEntity.getProperty(mProperty), uid, transaction); add(newEntity.getProperty(mProperty), uid, transaction); } - void deletedEntity(const QByteArray &uid, qint64 revision, const Akonadi2::ApplicationDomain::BufferAdaptor &oldEntity, Akonadi2::Storage::Transaction &transaction) Q_DECL_OVERRIDE + void deletedEntity(const QByteArray &uid, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &oldEntity, Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE { remove(oldEntity.getProperty(mProperty), uid, transaction); } private: - void add(const QVariant &value, const QByteArray &uid, Akonadi2::Storage::Transaction &transaction) + void add(const QVariant &value, const QByteArray &uid, Sink::Storage::Transaction &transaction) { if (value.isValid()) { Index(mIndexIdentifier, transaction).add(value.toByteArray(), uid); } } - void remove(const QVariant &value, const QByteArray &uid, Akonadi2::Storage::Transaction &transaction) + void remove(const QVariant &value, const QByteArray &uid, Sink::Storage::Transaction &transaction) { //TODO hide notfound error Index(mIndexIdentifier, transaction).remove(value.toByteArray(), uid); @@ -67,21 +67,21 @@ private: }; template -class DefaultIndexUpdater : public Akonadi2::Preprocessor { +class DefaultIndexUpdater : public Sink::Preprocessor { public: - void newEntity(const QByteArray &uid, qint64 revision, const Akonadi2::ApplicationDomain::BufferAdaptor &newEntity, Akonadi2::Storage::Transaction &transaction) Q_DECL_OVERRIDE + void newEntity(const QByteArray &uid, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &newEntity, Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE { - Akonadi2::ApplicationDomain::TypeImplementation::index(uid, newEntity, transaction); + Sink::ApplicationDomain::TypeImplementation::index(uid, newEntity, transaction); } - void modifiedEntity(const QByteArray &uid, qint64 revision, const Akonadi2::ApplicationDomain::BufferAdaptor &oldEntity, const Akonadi2::ApplicationDomain::BufferAdaptor &newEntity, Akonadi2::Storage::Transaction &transaction) Q_DECL_OVERRIDE + void modifiedEntity(const QByteArray &uid, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &oldEntity, const Sink::ApplicationDomain::BufferAdaptor &newEntity, Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE { - Akonadi2::ApplicationDomain::TypeImplementation::removeIndex(uid, oldEntity, transaction); - Akonadi2::ApplicationDomain::TypeImplementation::index(uid, newEntity, transaction); + Sink::ApplicationDomain::TypeImplementation::removeIndex(uid, oldEntity, transaction); + Sink::ApplicationDomain::TypeImplementation::index(uid, newEntity, transaction); } - void deletedEntity(const QByteArray &uid, qint64 revision, const Akonadi2::ApplicationDomain::BufferAdaptor &oldEntity, Akonadi2::Storage::Transaction &transaction) Q_DECL_OVERRIDE + void deletedEntity(const QByteArray &uid, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &oldEntity, Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE { - Akonadi2::ApplicationDomain::TypeImplementation::removeIndex(uid, oldEntity, transaction); + Sink::ApplicationDomain::TypeImplementation::removeIndex(uid, oldEntity, transaction); } }; diff --git a/common/inspection.h b/common/inspection.h index ecf5b3d..b9f6bf3 100644 --- a/common/inspection.h +++ b/common/inspection.h @@ -23,11 +23,11 @@ #include #include "applicationdomaintype.h" -namespace Akonadi2 { +namespace Sink { namespace Resources { struct Inspection { - static Inspection PropertyInspection(const Akonadi2::ApplicationDomain::Entity &entity, const QByteArray &property, const QVariant &expectedValue) + static Inspection PropertyInspection(const Sink::ApplicationDomain::Entity &entity, const QByteArray &property, const QVariant &expectedValue) { Inspection inspection; inspection.resourceIdentifier = entity.resourceInstanceIdentifier(); @@ -37,7 +37,7 @@ struct Inspection { return inspection; } - static Inspection ExistenceInspection(const Akonadi2::ApplicationDomain::Entity &entity, bool exists) + static Inspection ExistenceInspection(const Sink::ApplicationDomain::Entity &entity, bool exists) { Inspection inspection; inspection.resourceIdentifier = entity.resourceInstanceIdentifier(); diff --git a/common/listener.cpp b/common/listener.cpp index fa08472..13ebbbb 100644 --- a/common/listener.cpp +++ b/common/listener.cpp @@ -42,7 +42,7 @@ Listener::Listener(const QByteArray &resourceInstanceIdentifier, QObject *parent) : QObject(parent), m_server(new QLocalServer(this)), - m_resourceName(Akonadi2::resourceName(resourceInstanceIdentifier)), + m_resourceName(Sink::resourceName(resourceInstanceIdentifier)), m_resourceInstanceIdentifier(resourceInstanceIdentifier), m_resource(0), m_clientBufferProcessesTimer(new QTimer(this)), @@ -209,20 +209,20 @@ void Listener::processCommand(int commandId, uint messageId, const QByteArray &c { bool success = true; switch (commandId) { - case Akonadi2::Commands::HandshakeCommand: { + case Sink::Commands::HandshakeCommand: { flatbuffers::Verifier verifier((const uint8_t *)commandBuffer.constData(), commandBuffer.size()); - if (Akonadi2::Commands::VerifyHandshakeBuffer(verifier)) { - auto buffer = Akonadi2::Commands::GetHandshake(commandBuffer.constData()); + if (Sink::Commands::VerifyHandshakeBuffer(verifier)) { + auto buffer = Sink::Commands::GetHandshake(commandBuffer.constData()); client.name = buffer->name()->c_str(); } else { Warning() << "received invalid command"; } break; } - case Akonadi2::Commands::SynchronizeCommand: { + case Sink::Commands::SynchronizeCommand: { flatbuffers::Verifier verifier((const uint8_t *)commandBuffer.constData(), commandBuffer.size()); - if (Akonadi2::Commands::VerifySynchronizeBuffer(verifier)) { - auto buffer = Akonadi2::Commands::GetSynchronize(commandBuffer.constData()); + if (Sink::Commands::VerifySynchronizeBuffer(verifier)) { + auto buffer = Sink::Commands::GetSynchronize(commandBuffer.constData()); Log() << QString("\tSynchronize request (id %1) from %2").arg(messageId).arg(client.name); auto timer = QSharedPointer::create(); timer->start(); @@ -243,28 +243,28 @@ void Listener::processCommand(int commandId, uint messageId, const QByteArray &c } break; } - case Akonadi2::Commands::InspectionCommand: - case Akonadi2::Commands::FetchEntityCommand: - case Akonadi2::Commands::DeleteEntityCommand: - case Akonadi2::Commands::ModifyEntityCommand: - case Akonadi2::Commands::CreateEntityCommand: - Log() << "\tCommand id " << messageId << " of type \"" << Akonadi2::Commands::name(commandId) << "\" from " << client.name; + case Sink::Commands::InspectionCommand: + case Sink::Commands::FetchEntityCommand: + case Sink::Commands::DeleteEntityCommand: + case Sink::Commands::ModifyEntityCommand: + case Sink::Commands::CreateEntityCommand: + Log() << "\tCommand id " << messageId << " of type \"" << Sink::Commands::name(commandId) << "\" from " << client.name; loadResource()->processCommand(commandId, commandBuffer); break; - case Akonadi2::Commands::ShutdownCommand: + case Sink::Commands::ShutdownCommand: Log() << QString("\tReceived shutdown command from %1").arg(client.name); //Immediately reject new connections m_server->close(); QTimer::singleShot(0, this, &Listener::quit); break; - case Akonadi2::Commands::PingCommand: + case Sink::Commands::PingCommand: Log() << QString("\tReceived ping command from %1").arg(client.name); break; - case Akonadi2::Commands::RevisionReplayedCommand: { + case Sink::Commands::RevisionReplayedCommand: { Log() << QString("\tReceived revision replayed command from %1").arg(client.name); flatbuffers::Verifier verifier((const uint8_t *)commandBuffer.constData(), commandBuffer.size()); - if (Akonadi2::Commands::VerifyRevisionReplayedBuffer(verifier)) { - auto buffer = Akonadi2::Commands::GetRevisionReplayed(commandBuffer.constData()); + if (Sink::Commands::VerifyRevisionReplayedBuffer(verifier)) { + auto buffer = Sink::Commands::GetRevisionReplayed(commandBuffer.constData()); client.currentRevision = buffer->revision(); } else { Warning() << "received invalid command"; @@ -273,7 +273,7 @@ void Listener::processCommand(int commandId, uint messageId, const QByteArray &c } break; default: - if (commandId > Akonadi2::Commands::CustomCommand) { + if (commandId > Sink::Commands::CustomCommand) { Log() << QString("\tReceived custom command from %1: ").arg(client.name) << commandId; loadResource()->processCommand(commandId, commandBuffer); } else { @@ -303,11 +303,11 @@ qint64 Listener::lowerBoundRevision() void Listener::quit() { //Broadcast shutdown notifications to open clients, so they don't try to restart the resource - auto command = Akonadi2::Commands::CreateNotification(m_fbb, Akonadi2::Commands::NotificationType::NotificationType_Shutdown); - Akonadi2::Commands::FinishNotificationBuffer(m_fbb, command); + auto command = Sink::Commands::CreateNotification(m_fbb, Sink::Commands::NotificationType::NotificationType_Shutdown); + Sink::Commands::FinishNotificationBuffer(m_fbb, command); for (Client &client : m_connections) { if (client.socket && client.socket->isOpen()) { - Akonadi2::Commands::write(client.socket, ++m_messageId, Akonadi2::Commands::NotificationCommand, m_fbb); + Sink::Commands::write(client.socket, ++m_messageId, Sink::Commands::NotificationCommand, m_fbb); } } m_fbb.Clear(); @@ -318,7 +318,7 @@ void Listener::quit() bool Listener::processClientBuffer(Client &client) { - static const int headerSize = Akonadi2::Commands::headerSize(); + static const int headerSize = Sink::Commands::headerSize(); if (client.commandBuffer.size() < headerSize) { return false; } @@ -339,7 +339,7 @@ bool Listener::processClientBuffer(Client &client) const QByteArray commandBuffer = client.commandBuffer.left(size); client.commandBuffer.remove(0, size); processCommand(commandId, messageId, commandBuffer, client, [this, messageId, commandId, socket, clientName](bool success) { - Log() << QString("\tCompleted command messageid %1 of type \"%2\" from %3").arg(messageId).arg(QString(Akonadi2::Commands::name(commandId))).arg(clientName); + Log() << QString("\tCompleted command messageid %1 of type \"%2\" from %3").arg(messageId).arg(QString(Sink::Commands::name(commandId))).arg(clientName); if (socket) { sendCommandCompleted(socket.data(), messageId, success); } else { @@ -359,9 +359,9 @@ void Listener::sendCommandCompleted(QLocalSocket *socket, uint messageId, bool s return; } - auto command = Akonadi2::Commands::CreateCommandCompletion(m_fbb, messageId, success); - Akonadi2::Commands::FinishCommandCompletionBuffer(m_fbb, command); - Akonadi2::Commands::write(socket, ++m_messageId, Akonadi2::Commands::CommandCompletionCommand, m_fbb); + auto command = Sink::Commands::CreateCommandCompletion(m_fbb, messageId, success); + Sink::Commands::FinishCommandCompletionBuffer(m_fbb, command); + Sink::Commands::write(socket, ++m_messageId, Sink::Commands::CommandCompletionCommand, m_fbb); m_fbb.Clear(); } @@ -372,8 +372,8 @@ void Listener::refreshRevision(qint64 revision) void Listener::updateClientsWithRevision(qint64 revision) { - auto command = Akonadi2::Commands::CreateRevisionUpdate(m_fbb, revision); - Akonadi2::Commands::FinishRevisionUpdateBuffer(m_fbb, command); + auto command = Sink::Commands::CreateRevisionUpdate(m_fbb, revision); + Sink::Commands::FinishRevisionUpdateBuffer(m_fbb, command); for (const Client &client: m_connections) { if (!client.socket || !client.socket->isValid()) { @@ -381,44 +381,44 @@ void Listener::updateClientsWithRevision(qint64 revision) } Trace() << "Sending revision update for " << client.name << revision; - Akonadi2::Commands::write(client.socket, ++m_messageId, Akonadi2::Commands::RevisionUpdateCommand, m_fbb); + Sink::Commands::write(client.socket, ++m_messageId, Sink::Commands::RevisionUpdateCommand, m_fbb); } m_fbb.Clear(); } -void Listener::notify(const Akonadi2::Notification ¬ification) +void Listener::notify(const Sink::Notification ¬ification) { auto messageString = m_fbb.CreateString(notification.message.toUtf8().constData(), notification.message.toUtf8().size()); auto idString = m_fbb.CreateString(notification.id.constData(), notification.id.size()); - Akonadi2::Commands::NotificationBuilder builder(m_fbb); - builder.add_type(static_cast(notification.type)); + Sink::Commands::NotificationBuilder builder(m_fbb); + builder.add_type(static_cast(notification.type)); builder.add_code(notification.code); builder.add_identifier(idString); builder.add_message(messageString); auto command = builder.Finish(); - Akonadi2::Commands::FinishNotificationBuffer(m_fbb, command); + Sink::Commands::FinishNotificationBuffer(m_fbb, command); for (Client &client : m_connections) { if (client.socket && client.socket->isOpen()) { - Akonadi2::Commands::write(client.socket, ++m_messageId, Akonadi2::Commands::NotificationCommand, m_fbb); + Sink::Commands::write(client.socket, ++m_messageId, Sink::Commands::NotificationCommand, m_fbb); } } m_fbb.Clear(); } -Akonadi2::Resource *Listener::loadResource() +Sink::Resource *Listener::loadResource() { if (!m_resource) { - if (Akonadi2::ResourceFactory *resourceFactory = Akonadi2::ResourceFactory::load(m_resourceName)) { + if (Sink::ResourceFactory *resourceFactory = Sink::ResourceFactory::load(m_resourceName)) { m_resource = resourceFactory->createResource(m_resourceInstanceIdentifier); Trace() << QString("Resource factory: %1").arg((qlonglong)resourceFactory); Trace() << QString("\tResource: %1").arg((qlonglong)m_resource); - connect(m_resource, &Akonadi2::Resource::revisionUpdated, + connect(m_resource, &Sink::Resource::revisionUpdated, this, &Listener::refreshRevision); - connect(m_resource, &Akonadi2::Resource::notify, + connect(m_resource, &Sink::Resource::notify, this, &Listener::notify); } else { ErrorMsg() << "Failed to load resource " << m_resourceName; - m_resource = new Akonadi2::Resource; + m_resource = new Sink::Resource; } } return m_resource; diff --git a/common/listener.h b/common/listener.h index 4112a6a..e17f315 100644 --- a/common/listener.h +++ b/common/listener.h @@ -25,7 +25,7 @@ #include #include -namespace Akonadi2 +namespace Sink { class Resource; class Notification; @@ -77,7 +77,7 @@ private Q_SLOTS: void onDataAvailable(); void processClientBuffers(); void refreshRevision(qint64); - void notify(const Akonadi2::Notification &); + void notify(const Sink::Notification &); void quit(); private: @@ -85,7 +85,7 @@ private: bool processClientBuffer(Client &client); void sendCommandCompleted(QLocalSocket *socket, uint messageId, bool success); void updateClientsWithRevision(qint64); - Akonadi2::Resource *loadResource(); + Sink::Resource *loadResource(); void readFromSocket(QLocalSocket *socket); qint64 lowerBoundRevision(); @@ -94,7 +94,7 @@ private: flatbuffers::FlatBufferBuilder m_fbb; const QByteArray m_resourceName; const QByteArray m_resourceInstanceIdentifier; - Akonadi2::Resource *m_resource; + Sink::Resource *m_resource; QTimer *m_clientBufferProcessesTimer; QTimer *m_checkConnectionsTimer; int m_messageId; diff --git a/common/listmodelresult.h b/common/listmodelresult.h index a095c2a..71a0d09 100644 --- a/common/listmodelresult.h +++ b/common/listmodelresult.h @@ -39,14 +39,14 @@ public: { } - ListModelResult(const QSharedPointer > &emitter, const QList &propertyColumns) + ListModelResult(const QSharedPointer > &emitter, const QList &propertyColumns) :QAbstractListModel(), mPropertyColumns(propertyColumns) { setEmitter(emitter); } - void setEmitter(const QSharedPointer > &emitter) + void setEmitter(const QSharedPointer > &emitter) { beginResetModel(); mEntities.clear(); @@ -118,7 +118,7 @@ public: } private: - QSharedPointer > mEmitter; + QSharedPointer > mEmitter; QMap mEntities; QList mPropertyColumns; }; diff --git a/common/log.cpp b/common/log.cpp index 489e1bd..45bbec1 100644 --- a/common/log.cpp +++ b/common/log.cpp @@ -6,7 +6,7 @@ #include #include -using namespace Akonadi2::Log; +using namespace Sink::Log; class DebugStream: public QIODevice { @@ -96,7 +96,7 @@ static QString colorCommand(QList colorCodes) return string; } -QByteArray Akonadi2::Log::debugLevelName(DebugLevel debugLevel) +QByteArray Sink::Log::debugLevelName(DebugLevel debugLevel) { switch (debugLevel) { case DebugLevel::Trace: @@ -114,7 +114,7 @@ QByteArray Akonadi2::Log::debugLevelName(DebugLevel debugLevel) return QByteArray(); } -DebugLevel Akonadi2::Log::debugLevelFromName(const QByteArray &name) +DebugLevel Sink::Log::debugLevelFromName(const QByteArray &name) { const QByteArray lowercaseName = name.toLower(); if (lowercaseName == "trace") @@ -128,19 +128,19 @@ DebugLevel Akonadi2::Log::debugLevelFromName(const QByteArray &name) return DebugLevel::Log; } -void Akonadi2::Log::setDebugOutputLevel(DebugLevel debugLevel) +void Sink::Log::setDebugOutputLevel(DebugLevel debugLevel) { - qputenv("AKONADI2DEBUGLEVEL", debugLevelName(debugLevel)); + qputenv("SINKDEBUGLEVEL", debugLevelName(debugLevel)); } -Akonadi2::Log::DebugLevel Akonadi2::Log::debugOutputLevel() +Sink::Log::DebugLevel Sink::Log::debugOutputLevel() { - return debugLevelFromName(qgetenv("AKONADI2DEBUGLEVEL")); + return debugLevelFromName(qgetenv("SINKDEBUGLEVEL")); } -QDebug Akonadi2::Log::debugStream(DebugLevel debugLevel, int line, const char* file, const char* function, const char* debugArea) +QDebug Sink::Log::debugStream(DebugLevel debugLevel, int line, const char* file, const char* function, const char* debugArea) { - DebugLevel debugOutputLevel = debugLevelFromName(qgetenv("AKONADI2DEBUGLEVEL")); + DebugLevel debugOutputLevel = debugLevelFromName(qgetenv("SINKDEBUGLEVEL")); if (debugLevel < debugOutputLevel) { static NullStream stream; return QDebug(&stream); diff --git a/common/log.h b/common/log.h index e531348..483f16f 100644 --- a/common/log.h +++ b/common/log.h @@ -2,7 +2,7 @@ #include -namespace Akonadi2 { +namespace Sink { namespace Log { enum DebugLevel { @@ -23,8 +23,8 @@ QDebug debugStream(DebugLevel debugLevel, int line, const char* file, const char } } -#define Trace() Akonadi2::Log::debugStream(Akonadi2::Log::DebugLevel::Trace, __LINE__, __FILE__, Q_FUNC_INFO) -#define Log() Akonadi2::Log::debugStream(Akonadi2::Log::DebugLevel::Log, __LINE__, __FILE__, Q_FUNC_INFO) -#define Warning() Akonadi2::Log::debugStream(Akonadi2::Log::DebugLevel::Warning, __LINE__, __FILE__, Q_FUNC_INFO) +#define Trace() Sink::Log::debugStream(Sink::Log::DebugLevel::Trace, __LINE__, __FILE__, Q_FUNC_INFO) +#define Log() Sink::Log::debugStream(Sink::Log::DebugLevel::Log, __LINE__, __FILE__, Q_FUNC_INFO) +#define Warning() Sink::Log::debugStream(Sink::Log::DebugLevel::Warning, __LINE__, __FILE__, Q_FUNC_INFO) //FIXME Error clashes with Storage::Error and MessageQueue::Error -#define ErrorMsg() Akonadi2::Log::debugStream(Akonadi2::Log::DebugLevel::Error, __LINE__, __FILE__, Q_FUNC_INFO) +#define ErrorMsg() Sink::Log::debugStream(Sink::Log::DebugLevel::Error, __LINE__, __FILE__, Q_FUNC_INFO) diff --git a/common/messagequeue.cpp b/common/messagequeue.cpp index 8e3d7d7..1055922 100644 --- a/common/messagequeue.cpp +++ b/common/messagequeue.cpp @@ -37,7 +37,7 @@ static KAsync::Job waitForCompletion(QList > &futures } MessageQueue::MessageQueue(const QString &storageRoot, const QString &name) - : mStorage(storageRoot, name, Akonadi2::Storage::ReadWrite) + : mStorage(storageRoot, name, Sink::Storage::ReadWrite) { } @@ -56,13 +56,13 @@ void MessageQueue::startTransaction() return; } processRemovals(); - mWriteTransaction = std::move(mStorage.createTransaction(Akonadi2::Storage::ReadWrite)); + mWriteTransaction = std::move(mStorage.createTransaction(Sink::Storage::ReadWrite)); } void MessageQueue::commit() { mWriteTransaction.commit(); - mWriteTransaction = Akonadi2::Storage::Transaction(); + mWriteTransaction = Sink::Storage::Transaction(); processRemovals(); emit messageReady(); } @@ -74,10 +74,10 @@ void MessageQueue::enqueue(const QByteArray &value) implicitTransaction = true; startTransaction(); } - const qint64 revision = Akonadi2::Storage::maxRevision(mWriteTransaction) + 1; + const qint64 revision = Sink::Storage::maxRevision(mWriteTransaction) + 1; const QByteArray key = QString("%1").arg(revision).toUtf8(); mWriteTransaction.openDatabase().write(key, value); - Akonadi2::Storage::setMaxRevision(mWriteTransaction, revision); + Sink::Storage::setMaxRevision(mWriteTransaction, revision); if (implicitTransaction) { commit(); } @@ -88,7 +88,7 @@ void MessageQueue::processRemovals() if (mWriteTransaction) { return; } - auto transaction = std::move(mStorage.createTransaction(Akonadi2::Storage::ReadWrite)); + auto transaction = std::move(mStorage.createTransaction(Sink::Storage::ReadWrite)); for (const auto &key : mPendingRemoval) { transaction.openDatabase().remove(key); } @@ -117,8 +117,8 @@ KAsync::Job MessageQueue::dequeueBatch(int maxBatchSize, const std::functi return KAsync::start([this, maxBatchSize, resultHandler, resultCount](KAsync::Future &future) { int count = 0; QList > waitCondition; - mStorage.createTransaction(Akonadi2::Storage::ReadOnly).openDatabase().scan("", [this, resultHandler, resultCount, &count, maxBatchSize, &waitCondition](const QByteArray &key, const QByteArray &value) -> bool { - if (Akonadi2::Storage::isInternalKey(key) || mPendingRemoval.contains(key)) { + mStorage.createTransaction(Sink::Storage::ReadOnly).openDatabase().scan("", [this, resultHandler, resultCount, &count, maxBatchSize, &waitCondition](const QByteArray &key, const QByteArray &value) -> bool { + if (Sink::Storage::isInternalKey(key) || mPendingRemoval.contains(key)) { return true; } *resultCount += 1; @@ -133,7 +133,7 @@ KAsync::Job MessageQueue::dequeueBatch(int maxBatchSize, const std::functi } return false; }, - [](const Akonadi2::Storage::Error &error) { + [](const Sink::Storage::Error &error) { ErrorMsg() << "Error while retrieving value" << error.message; // errorHandler(Error(error.store, error.code, error.message)); }); @@ -157,17 +157,17 @@ KAsync::Job MessageQueue::dequeueBatch(int maxBatchSize, const std::functi bool MessageQueue::isEmpty() { int count = 0; - auto t = mStorage.createTransaction(Akonadi2::Storage::ReadOnly); + auto t = mStorage.createTransaction(Sink::Storage::ReadOnly); auto db = t.openDatabase(); if (db) { db.scan("", [&count, this](const QByteArray &key, const QByteArray &value) -> bool { - if (!Akonadi2::Storage::isInternalKey(key) && !mPendingRemoval.contains(key)) { + if (!Sink::Storage::isInternalKey(key) && !mPendingRemoval.contains(key)) { count++; return false; } return true; }, - [](const Akonadi2::Storage::Error &error) { + [](const Sink::Storage::Error &error) { ErrorMsg() << "Error while checking if empty" << error.message; }); } diff --git a/common/messagequeue.h b/common/messagequeue.h index a04e22f..3206388 100644 --- a/common/messagequeue.h +++ b/common/messagequeue.h @@ -54,7 +54,7 @@ private slots: private: Q_DISABLE_COPY(MessageQueue); - Akonadi2::Storage mStorage; - Akonadi2::Storage::Transaction mWriteTransaction; + Sink::Storage mStorage; + Sink::Storage::Transaction mWriteTransaction; QByteArrayList mPendingRemoval; }; diff --git a/common/metadata.fbs b/common/metadata.fbs index 0a709fe..f2f336d 100644 --- a/common/metadata.fbs +++ b/common/metadata.fbs @@ -1,4 +1,4 @@ -namespace Akonadi2; +namespace Sink; enum Operation : byte { Creation = 1, Modification, Removal } diff --git a/common/modelresult.cpp b/common/modelresult.cpp index 22798d9..3a9fb95 100644 --- a/common/modelresult.cpp +++ b/common/modelresult.cpp @@ -24,7 +24,7 @@ #include "domain/folder.h" #include "log.h" -static uint qHash(const Akonadi2::ApplicationDomain::ApplicationDomainType &type) +static uint qHash(const Sink::ApplicationDomain::ApplicationDomainType &type) { Q_ASSERT(!type.resourceInstanceIdentifier().isEmpty()); Q_ASSERT(!type.identifier().isEmpty()); @@ -32,7 +32,7 @@ static uint qHash(const Akonadi2::ApplicationDomain::ApplicationDomainType &typ } template -ModelResult::ModelResult(const Akonadi2::Query &query, const QList &propertyColumns) +ModelResult::ModelResult(const Sink::Query &query, const QList &propertyColumns) :QAbstractItemModel(), mPropertyColumns(propertyColumns), mQuery(query) @@ -53,7 +53,7 @@ qint64 ModelResult::parentId(const Ptr &value) if (!mQuery.parentProperty.isEmpty()) { const auto identifier = value->getProperty(mQuery.parentProperty).toByteArray(); if (!identifier.isEmpty()) { - return qHash(T(value->resourceInstanceIdentifier(), identifier, 0, QSharedPointer())); + return qHash(T(value->resourceInstanceIdentifier(), identifier, 0, QSharedPointer())); } } return 0; @@ -91,7 +91,7 @@ QVariant ModelResult::data(const QModelIndex &index, int role) const } if (role == DomainObjectBaseRole) { Q_ASSERT(mEntities.contains(index.internalId())); - return QVariant::fromValue(mEntities.value(index.internalId()). template staticCast()); + return QVariant::fromValue(mEntities.value(index.internalId()). template staticCast()); } if (role == ChildrenFetchedRole) { return childrenFetched(index); @@ -226,7 +226,7 @@ void ModelResult::setFetcher(const std::function -void ModelResult::setEmitter(const typename Akonadi2::ResultEmitter::Ptr &emitter) +void ModelResult::setEmitter(const typename Sink::ResultEmitter::Ptr &emitter) { setFetcher([this](const Ptr &parent) {mEmitter->fetch(parent);}); emitter->onAdded([this](const Ptr &value) { @@ -272,7 +272,7 @@ void ModelResult::modify(const Ptr &value) emit dataChanged(idx, idx); } -template class ModelResult; -template class ModelResult; -template class ModelResult; -template class ModelResult; +template class ModelResult; +template class ModelResult; +template class ModelResult; +template class ModelResult; diff --git a/common/modelresult.h b/common/modelresult.h index ec62a67..062517f 100644 --- a/common/modelresult.h +++ b/common/modelresult.h @@ -38,9 +38,9 @@ public: DomainObjectBaseRole }; - ModelResult(const Akonadi2::Query &query, const QList &propertyColumns); + ModelResult(const Sink::Query &query, const QList &propertyColumns); - void setEmitter(const typename Akonadi2::ResultEmitter::Ptr &); + void setEmitter(const typename Sink::ResultEmitter::Ptr &); int rowCount(const QModelIndex &parent = QModelIndex()) const; int columnCount(const QModelIndex &parent = QModelIndex()) const; @@ -73,8 +73,8 @@ private: QSet mEntityChildrenFetched; QSet mEntityChildrenFetchComplete; QList mPropertyColumns; - Akonadi2::Query mQuery; + Sink::Query mQuery; std::function loadEntities; - typename Akonadi2::ResultEmitter::Ptr mEmitter; + typename Sink::ResultEmitter::Ptr mEmitter; }; diff --git a/common/notification.h b/common/notification.h index e1b5bff..ae24bd2 100644 --- a/common/notification.h +++ b/common/notification.h @@ -19,16 +19,16 @@ */ #pragma once -#include +#include #include -namespace Akonadi2 +namespace Sink { /** * A notification */ -class AKONADI2COMMON_EXPORT Notification +class SINKCOMMON_EXPORT Notification { public: QByteArray id; diff --git a/common/pipeline.cpp b/common/pipeline.cpp index a087def..401c26d 100644 --- a/common/pipeline.cpp +++ b/common/pipeline.cpp @@ -36,14 +36,14 @@ #include "definitions.h" #include "bufferutils.h" -namespace Akonadi2 +namespace Sink { class Pipeline::Private { public: Private(const QString &resourceName) - : storage(Akonadi2::storageLocation(), resourceName, Storage::ReadWrite), + : storage(Sink::storageLocation(), resourceName, Storage::ReadWrite), revisionChanged(false) { } @@ -86,7 +86,7 @@ void Pipeline::startTransaction() if (d->transaction) { return; } - d->transaction = std::move(storage().createTransaction(Akonadi2::Storage::ReadWrite)); + d->transaction = std::move(storage().createTransaction(Sink::Storage::ReadWrite)); } void Pipeline::commit() @@ -96,7 +96,7 @@ void Pipeline::commit() // for (auto processor : d->processors[bufferType]) { // processor->finalize(); // } - const auto revision = Akonadi2::Storage::maxRevision(d->transaction); + const auto revision = Sink::Storage::maxRevision(d->transaction); Trace() << "Committing " << revision; if (d->transaction) { d->transaction.commit(); @@ -120,14 +120,14 @@ Storage &Pipeline::storage() const void Pipeline::storeNewRevision(qint64 newRevision, const flatbuffers::FlatBufferBuilder &fbb, const QByteArray &bufferType, const QByteArray &uid) { - d->transaction.openDatabase(bufferType + ".main").write(Akonadi2::Storage::assembleKey(uid, newRevision), BufferUtils::extractBuffer(fbb), - [](const Akonadi2::Storage::Error &error) { + d->transaction.openDatabase(bufferType + ".main").write(Sink::Storage::assembleKey(uid, newRevision), BufferUtils::extractBuffer(fbb), + [](const Sink::Storage::Error &error) { Warning() << "Failed to write entity"; } ); d->revisionChanged = true; - Akonadi2::Storage::setMaxRevision(d->transaction, newRevision); - Akonadi2::Storage::recordRevision(d->transaction, newRevision, uid, bufferType); + Sink::Storage::setMaxRevision(d->transaction, newRevision); + Sink::Storage::recordRevision(d->transaction, newRevision, uid, bufferType); } KAsync::Job Pipeline::newEntity(void const *command, size_t size) @@ -136,23 +136,23 @@ KAsync::Job Pipeline::newEntity(void const *command, size_t size) { flatbuffers::Verifier verifyer(reinterpret_cast(command), size); - if (!Akonadi2::Commands::VerifyCreateEntityBuffer(verifyer)) { + if (!Sink::Commands::VerifyCreateEntityBuffer(verifyer)) { Warning() << "invalid buffer, not a create entity buffer"; return KAsync::error(0); } } - auto createEntity = Akonadi2::Commands::GetCreateEntity(command); + auto createEntity = Sink::Commands::GetCreateEntity(command); const bool replayToSource = createEntity->replayToSource(); const QByteArray bufferType = QByteArray(reinterpret_cast(createEntity->domainType()->Data()), createEntity->domainType()->size()); { flatbuffers::Verifier verifyer(reinterpret_cast(createEntity->delta()->Data()), createEntity->delta()->size()); - if (!Akonadi2::VerifyEntityBuffer(verifyer)) { + if (!Sink::VerifyEntityBuffer(verifyer)) { Warning() << "invalid buffer, not an entity buffer"; return KAsync::error(0); } } - auto entity = Akonadi2::GetEntity(createEntity->delta()->Data()); + auto entity = Sink::GetEntity(createEntity->delta()->Data()); if (!entity->resource()->size() && !entity->local()->size()) { Warning() << "No local and no resource buffer while trying to create entity."; return KAsync::error(0); @@ -171,16 +171,16 @@ KAsync::Job Pipeline::newEntity(void const *command, size_t size) key = QUuid::createUuid().toString().toUtf8(); } Q_ASSERT(!key.isEmpty()); - const qint64 newRevision = Akonadi2::Storage::maxRevision(d->transaction) + 1; + const qint64 newRevision = Sink::Storage::maxRevision(d->transaction) + 1; //Add metadata buffer flatbuffers::FlatBufferBuilder metadataFbb; - auto metadataBuilder = Akonadi2::MetadataBuilder(metadataFbb); + auto metadataBuilder = Sink::MetadataBuilder(metadataFbb); metadataBuilder.add_revision(newRevision); - metadataBuilder.add_operation(Akonadi2::Operation_Creation); + metadataBuilder.add_operation(Sink::Operation_Creation); metadataBuilder.add_replayToSource(replayToSource); auto metadataBuffer = metadataBuilder.Finish(); - Akonadi2::FinishMetadataBuffer(metadataFbb, metadataBuffer); + Sink::FinishMetadataBuffer(metadataFbb, metadataBuffer); flatbuffers::FlatBufferBuilder fbb; EntityBuffer::assembleEntityBuffer(fbb, metadataFbb.GetBufferPointer(), metadataFbb.GetSize(), entity->resource()->Data(), entity->resource()->size(), entity->local()->Data(), entity->local()->size()); @@ -194,14 +194,14 @@ KAsync::Job Pipeline::newEntity(void const *command, size_t size) } Log() << "Pipeline: wrote entity: " << key << newRevision << bufferType; - d->transaction.openDatabase(bufferType + ".main").scan(Akonadi2::Storage::assembleKey(key, newRevision), [this, bufferType, newRevision, adaptorFactory, key](const QByteArray &, const QByteArray &value) -> bool { - auto entity = Akonadi2::GetEntity(value); + d->transaction.openDatabase(bufferType + ".main").scan(Sink::Storage::assembleKey(key, newRevision), [this, bufferType, newRevision, adaptorFactory, key](const QByteArray &, const QByteArray &value) -> bool { + auto entity = Sink::GetEntity(value); auto adaptor = adaptorFactory->createAdaptor(*entity); for (auto processor : d->processors[bufferType]) { processor->newEntity(key, newRevision, *adaptor, d->transaction); } return false; - }, [this](const Akonadi2::Storage::Error &error) { + }, [this](const Sink::Storage::Error &error) { ErrorMsg() << "Failed to find value in pipeline: " << error.message; }); return KAsync::start([newRevision](){ @@ -213,16 +213,16 @@ KAsync::Job Pipeline::modifiedEntity(void const *command, size_t size) { Trace() << "Pipeline: Modified Entity"; - const qint64 newRevision = Akonadi2::Storage::maxRevision(d->transaction) + 1; + const qint64 newRevision = Sink::Storage::maxRevision(d->transaction) + 1; { flatbuffers::Verifier verifyer(reinterpret_cast(command), size); - if (!Akonadi2::Commands::VerifyModifyEntityBuffer(verifyer)) { + if (!Sink::Commands::VerifyModifyEntityBuffer(verifyer)) { Warning() << "invalid buffer, not a modify entity buffer"; return KAsync::error(0); } } - auto modifyEntity = Akonadi2::Commands::GetModifyEntity(command); + auto modifyEntity = Sink::Commands::GetModifyEntity(command); Q_ASSERT(modifyEntity); const qint64 baseRevision = modifyEntity->revision(); @@ -236,7 +236,7 @@ KAsync::Job Pipeline::modifiedEntity(void const *command, size_t size) } { flatbuffers::Verifier verifyer(reinterpret_cast(modifyEntity->delta()->Data()), modifyEntity->delta()->size()); - if (!Akonadi2::VerifyEntityBuffer(verifyer)) { + if (!Sink::VerifyEntityBuffer(verifyer)) { Warning() << "invalid buffer, not an entity buffer"; return KAsync::error(0); } @@ -249,13 +249,13 @@ KAsync::Job Pipeline::modifiedEntity(void const *command, size_t size) return KAsync::error(0); } - auto diffEntity = Akonadi2::GetEntity(modifyEntity->delta()->Data()); + auto diffEntity = Sink::GetEntity(modifyEntity->delta()->Data()); Q_ASSERT(diffEntity); auto diff = adaptorFactory->createAdaptor(*diffEntity); - QSharedPointer current; + QSharedPointer current; d->transaction.openDatabase(bufferType + ".main").findLatest(key, [¤t, adaptorFactory](const QByteArray &key, const QByteArray &data) -> bool { - Akonadi2::EntityBuffer buffer(const_cast(data.data()), data.size()); + Sink::EntityBuffer buffer(const_cast(data.data()), data.size()); if (!buffer.isValid()) { Warning() << "Read invalid buffer from disk"; } else { @@ -273,8 +273,8 @@ KAsync::Job Pipeline::modifiedEntity(void const *command, size_t size) } //resource and uid don't matter at this point - const Akonadi2::ApplicationDomain::ApplicationDomainType existingObject("", "", newRevision, current); - auto newObject = Akonadi2::ApplicationDomain::ApplicationDomainType::getInMemoryRepresentation(existingObject); + const Sink::ApplicationDomain::ApplicationDomainType existingObject("", "", newRevision, current); + auto newObject = Sink::ApplicationDomain::ApplicationDomainType::getInMemoryRepresentation(existingObject); //Apply diff //FIXME only apply the properties that are available in the buffer @@ -292,26 +292,26 @@ KAsync::Job Pipeline::modifiedEntity(void const *command, size_t size) //Add metadata buffer flatbuffers::FlatBufferBuilder metadataFbb; - auto metadataBuilder = Akonadi2::MetadataBuilder(metadataFbb); + auto metadataBuilder = Sink::MetadataBuilder(metadataFbb); metadataBuilder.add_revision(newRevision); - metadataBuilder.add_operation(Akonadi2::Operation_Modification); + metadataBuilder.add_operation(Sink::Operation_Modification); metadataBuilder.add_replayToSource(replayToSource); auto metadataBuffer = metadataBuilder.Finish(); - Akonadi2::FinishMetadataBuffer(metadataFbb, metadataBuffer); + Sink::FinishMetadataBuffer(metadataFbb, metadataBuffer); flatbuffers::FlatBufferBuilder fbb; adaptorFactory->createBuffer(*newObject, fbb, metadataFbb.GetBufferPointer(), metadataFbb.GetSize()); storeNewRevision(newRevision, fbb, bufferType, key); Log() << "Pipeline: modified entity: " << key << newRevision << bufferType; - d->transaction.openDatabase(bufferType + ".main").scan(Akonadi2::Storage::assembleKey(key, newRevision), [this, bufferType, newRevision, adaptorFactory, current, key](const QByteArray &, const QByteArray &value) -> bool { - auto entity = Akonadi2::GetEntity(value); + d->transaction.openDatabase(bufferType + ".main").scan(Sink::Storage::assembleKey(key, newRevision), [this, bufferType, newRevision, adaptorFactory, current, key](const QByteArray &, const QByteArray &value) -> bool { + auto entity = Sink::GetEntity(value); auto newEntity = adaptorFactory->createAdaptor(*entity); for (auto processor : d->processors[bufferType]) { processor->modifiedEntity(key, newRevision, *current, *newEntity, d->transaction); } return false; - }, [this](const Akonadi2::Storage::Error &error) { + }, [this](const Sink::Storage::Error &error) { ErrorMsg() << "Failed to find value in pipeline: " << error.message; }); return KAsync::start([newRevision](){ @@ -325,12 +325,12 @@ KAsync::Job Pipeline::deletedEntity(void const *command, size_t size) { flatbuffers::Verifier verifyer(reinterpret_cast(command), size); - if (!Akonadi2::Commands::VerifyDeleteEntityBuffer(verifyer)) { + if (!Sink::Commands::VerifyDeleteEntityBuffer(verifyer)) { Warning() << "invalid buffer, not a delete entity buffer"; return KAsync::error(0); } } - auto deleteEntity = Akonadi2::Commands::GetDeleteEntity(command); + auto deleteEntity = Sink::Commands::GetDeleteEntity(command); const bool replayToSource = deleteEntity->replayToSource(); const QByteArray bufferType = QByteArray(reinterpret_cast(deleteEntity->domainType()->Data()), deleteEntity->domainType()->size()); @@ -339,12 +339,12 @@ KAsync::Job Pipeline::deletedEntity(void const *command, size_t size) bool found = false; bool alreadyRemoved = false; d->transaction.openDatabase(bufferType + ".main").findLatest(key, [&found, &alreadyRemoved](const QByteArray &key, const QByteArray &data) -> bool { - Akonadi2::EntityBuffer buffer(const_cast(data.data()), data.size()); - auto entity = Akonadi2::GetEntity(data.data()); + Sink::EntityBuffer buffer(const_cast(data.data()), data.size()); + auto entity = Sink::GetEntity(data.data()); if (entity && entity->metadata()) { - auto metadata = Akonadi2::GetMetadata(entity->metadata()->Data()); + auto metadata = Sink::GetMetadata(entity->metadata()->Data()); found = true; - if (metadata->operation() == Akonadi2::Operation_Removal) { + if (metadata->operation() == Sink::Operation_Removal) { alreadyRemoved = true; } @@ -364,16 +364,16 @@ KAsync::Job Pipeline::deletedEntity(void const *command, size_t size) return KAsync::error(0); } - const qint64 newRevision = Akonadi2::Storage::maxRevision(d->transaction) + 1; + const qint64 newRevision = Sink::Storage::maxRevision(d->transaction) + 1; //Add metadata buffer flatbuffers::FlatBufferBuilder metadataFbb; - auto metadataBuilder = Akonadi2::MetadataBuilder(metadataFbb); + auto metadataBuilder = Sink::MetadataBuilder(metadataFbb); metadataBuilder.add_revision(newRevision); - metadataBuilder.add_operation(Akonadi2::Operation_Removal); + metadataBuilder.add_operation(Sink::Operation_Removal); metadataBuilder.add_replayToSource(replayToSource); auto metadataBuffer = metadataBuilder.Finish(); - Akonadi2::FinishMetadataBuffer(metadataFbb, metadataBuffer); + Sink::FinishMetadataBuffer(metadataFbb, metadataBuffer); flatbuffers::FlatBufferBuilder fbb; EntityBuffer::assembleEntityBuffer(fbb, metadataFbb.GetBufferPointer(), metadataFbb.GetSize(), 0, 0, 0, 0); @@ -384,16 +384,16 @@ KAsync::Job Pipeline::deletedEntity(void const *command, size_t size) return KAsync::error(0); } - QSharedPointer current; + QSharedPointer current; d->transaction.openDatabase(bufferType + ".main").findLatest(key, [this, bufferType, newRevision, adaptorFactory, key, ¤t](const QByteArray &, const QByteArray &data) -> bool { - Akonadi2::EntityBuffer buffer(const_cast(data.data()), data.size()); + Sink::EntityBuffer buffer(const_cast(data.data()), data.size()); if (!buffer.isValid()) { Warning() << "Read invalid buffer from disk"; } else { current = adaptorFactory->createAdaptor(buffer.entity()); } return false; - }, [this](const Akonadi2::Storage::Error &error) { + }, [this](const Sink::Storage::Error &error) { ErrorMsg() << "Failed to find value in pipeline: " << error.message; }); @@ -411,33 +411,33 @@ KAsync::Job Pipeline::deletedEntity(void const *command, size_t size) void Pipeline::cleanupRevision(qint64 revision) { - const auto uid = Akonadi2::Storage::getUidFromRevision(d->transaction, revision); - const auto bufferType = Akonadi2::Storage::getTypeFromRevision(d->transaction, revision); + const auto uid = Sink::Storage::getUidFromRevision(d->transaction, revision); + const auto bufferType = Sink::Storage::getTypeFromRevision(d->transaction, revision); Trace() << "Cleaning up revision " << revision << uid << bufferType; d->transaction.openDatabase(bufferType + ".main").scan(uid, [&](const QByteArray &key, const QByteArray &data) -> bool { - Akonadi2::EntityBuffer buffer(const_cast(data.data()), data.size()); + Sink::EntityBuffer buffer(const_cast(data.data()), data.size()); if (!buffer.isValid()) { Warning() << "Read invalid buffer from disk"; } else { - const auto metadata = flatbuffers::GetRoot(buffer.metadataBuffer()); + const auto metadata = flatbuffers::GetRoot(buffer.metadataBuffer()); const qint64 rev = metadata->revision(); //Remove old revisions, and the current if the entity has already been removed - if (rev < revision || metadata->operation() == Akonadi2::Operation_Removal) { - Akonadi2::Storage::removeRevision(d->transaction, rev); + if (rev < revision || metadata->operation() == Sink::Operation_Removal) { + Sink::Storage::removeRevision(d->transaction, rev); d->transaction.openDatabase(bufferType + ".main").remove(key); } } return true; - }, [](const Akonadi2::Storage::Error &error) { + }, [](const Sink::Storage::Error &error) { Warning() << "Error while reading: " << error.message; }, true); - Akonadi2::Storage::setCleanedUpRevision(d->transaction, revision); + Sink::Storage::setCleanedUpRevision(d->transaction, revision); } qint64 Pipeline::cleanedUpRevision() { - return Akonadi2::Storage::cleanedUpRevision(d->transaction); + return Sink::Storage::cleanedUpRevision(d->transaction); } Preprocessor::Preprocessor() @@ -457,5 +457,5 @@ void Preprocessor::finalize() { } -} // namespace Akonadi2 +} // namespace Sink diff --git a/common/pipeline.h b/common/pipeline.h index f11d880..60a5fa5 100644 --- a/common/pipeline.h +++ b/common/pipeline.h @@ -25,19 +25,19 @@ #include #include -#include +#include #include #include #include "domainadaptor.h" -namespace Akonadi2 +namespace Sink { class Preprocessor; -class AKONADI2COMMON_EXPORT Pipeline : public QObject +class SINKCOMMON_EXPORT Pipeline : public QObject { Q_OBJECT @@ -79,16 +79,16 @@ private: Private * const d; }; -class AKONADI2COMMON_EXPORT Preprocessor +class SINKCOMMON_EXPORT Preprocessor { public: Preprocessor(); virtual ~Preprocessor(); virtual void startBatch(); - virtual void newEntity(const QByteArray &key, qint64 revision, const Akonadi2::ApplicationDomain::BufferAdaptor &newEntity, Akonadi2::Storage::Transaction &transaction) = 0; - virtual void modifiedEntity(const QByteArray &key, qint64 revision, const Akonadi2::ApplicationDomain::BufferAdaptor &oldEntity, const Akonadi2::ApplicationDomain::BufferAdaptor &newEntity, Akonadi2::Storage::Transaction &transaction) = 0; - virtual void deletedEntity(const QByteArray &key, qint64 revision, const Akonadi2::ApplicationDomain::BufferAdaptor &oldEntity, Akonadi2::Storage::Transaction &transaction) = 0; + virtual void newEntity(const QByteArray &key, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &newEntity, Sink::Storage::Transaction &transaction) = 0; + virtual void modifiedEntity(const QByteArray &key, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &oldEntity, const Sink::ApplicationDomain::BufferAdaptor &newEntity, Sink::Storage::Transaction &transaction) = 0; + virtual void deletedEntity(const QByteArray &key, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &oldEntity, Sink::Storage::Transaction &transaction) = 0; virtual void finalize(); private: @@ -96,5 +96,5 @@ private: Private * const d; }; -} // namespace Akonadi2 +} // namespace Sink diff --git a/common/query.h b/common/query.h index 1df32da..a0a50ba 100644 --- a/common/query.h +++ b/common/query.h @@ -24,7 +24,7 @@ #include #include "applicationdomaintype.h" -namespace Akonadi2 { +namespace Sink { /** * A query that matches a set of entities. @@ -64,7 +64,7 @@ public: return query; } - static Query ResourceFilter(const ApplicationDomain::AkonadiResource &entity) + static Query ResourceFilter(const ApplicationDomain::SinkResource &entity) { return ResourceFilter(entity.identifier()); } @@ -138,4 +138,4 @@ public: } -Q_DECLARE_OPERATORS_FOR_FLAGS(Akonadi2::Query::Flags) +Q_DECLARE_OPERATORS_FOR_FLAGS(Sink::Query::Flags) diff --git a/common/queryrunner.cpp b/common/queryrunner.cpp index 89610e3..25d69b1 100644 --- a/common/queryrunner.cpp +++ b/common/queryrunner.cpp @@ -26,7 +26,7 @@ #include "domainadaptor.h" #include "asyncutils.h" -using namespace Akonadi2; +using namespace Sink; /* * This class wraps the actual query implementation. @@ -38,34 +38,34 @@ template class QueryWorker : public QObject { public: - QueryWorker(const Akonadi2::Query &query, const QByteArray &instanceIdentifier, const DomainTypeAdaptorFactoryInterface::Ptr &, const QByteArray &bufferType); + QueryWorker(const Sink::Query &query, const QByteArray &instanceIdentifier, const DomainTypeAdaptorFactoryInterface::Ptr &, const QByteArray &bufferType); virtual ~QueryWorker(); - qint64 executeIncrementalQuery(const Akonadi2::Query &query, Akonadi2::ResultProviderInterface &resultProvider); - qint64 executeInitialQuery(const Akonadi2::Query &query, const typename DomainType::Ptr &parent, Akonadi2::ResultProviderInterface &resultProvider); + qint64 executeIncrementalQuery(const Sink::Query &query, Sink::ResultProviderInterface &resultProvider); + qint64 executeInitialQuery(const Sink::Query &query, const typename DomainType::Ptr &parent, Sink::ResultProviderInterface &resultProvider); private: - static void replaySet(ResultSet &resultSet, Akonadi2::ResultProviderInterface &resultProvider, const QList &properties); + static void replaySet(ResultSet &resultSet, Sink::ResultProviderInterface &resultProvider, const QList &properties); - void readEntity(const Akonadi2::Storage::NamedDatabase &db, const QByteArray &key, const std::function &resultCallback); + void readEntity(const Sink::Storage::NamedDatabase &db, const QByteArray &key, const std::function &resultCallback); - ResultSet loadInitialResultSet(const Akonadi2::Query &query, Akonadi2::Storage::Transaction &transaction, QSet &remainingFilters); - ResultSet loadIncrementalResultSet(qint64 baseRevision, const Akonadi2::Query &query, Akonadi2::Storage::Transaction &transaction, QSet &remainingFilters); + ResultSet loadInitialResultSet(const Sink::Query &query, Sink::Storage::Transaction &transaction, QSet &remainingFilters); + ResultSet loadIncrementalResultSet(qint64 baseRevision, const Sink::Query &query, Sink::Storage::Transaction &transaction, QSet &remainingFilters); - ResultSet filterSet(const ResultSet &resultSet, const std::function &filter, const Akonadi2::Storage::NamedDatabase &db, bool initialQuery); - std::function getFilter(const QSet remainingFilters, const Akonadi2::Query &query); - qint64 load(const Akonadi2::Query &query, const std::function &)> &baseSetRetriever, Akonadi2::ResultProviderInterface &resultProvider, bool initialQuery); + ResultSet filterSet(const ResultSet &resultSet, const std::function &filter, const Sink::Storage::NamedDatabase &db, bool initialQuery); + std::function getFilter(const QSet remainingFilters, const Sink::Query &query); + qint64 load(const Sink::Query &query, const std::function &)> &baseSetRetriever, Sink::ResultProviderInterface &resultProvider, bool initialQuery); private: DomainTypeAdaptorFactoryInterface::Ptr mDomainTypeAdaptorFactory; QByteArray mResourceInstanceIdentifier; QByteArray mBufferType; - Akonadi2::Query mQuery; + Sink::Query mQuery; }; template -QueryRunner::QueryRunner(const Akonadi2::Query &query, const Akonadi2::ResourceAccessInterface::Ptr &resourceAccess, const QByteArray &instanceIdentifier, const DomainTypeAdaptorFactoryInterface::Ptr &factory, const QByteArray &bufferType) +QueryRunner::QueryRunner(const Sink::Query &query, const Sink::ResourceAccessInterface::Ptr &resourceAccess, const QByteArray &instanceIdentifier, const DomainTypeAdaptorFactoryInterface::Ptr &factory, const QByteArray &bufferType) : QueryRunnerBase(), mResourceAccess(resourceAccess), mResultProvider(new ResultProvider) @@ -107,7 +107,7 @@ QueryRunner::QueryRunner(const Akonadi2::Query &query, const Akonadi //Ensure the connection is open, if it wasn't already opened //TODO If we are not connected already, we have to check for the latest revision once connected, otherwise we could miss some updates mResourceAccess->open(); - QObject::connect(mResourceAccess.data(), &Akonadi2::ResourceAccess::revisionChanged, this, &QueryRunner::revisionChanged); + QObject::connect(mResourceAccess.data(), &Sink::ResourceAccess::revisionChanged, this, &QueryRunner::revisionChanged); } } @@ -118,26 +118,26 @@ QueryRunner::~QueryRunner() } template -typename Akonadi2::ResultEmitter::Ptr QueryRunner::emitter() +typename Sink::ResultEmitter::Ptr QueryRunner::emitter() { return mResultProvider->emitter(); } -static inline ResultSet fullScan(const Akonadi2::Storage::Transaction &transaction, const QByteArray &bufferType) +static inline ResultSet fullScan(const Sink::Storage::Transaction &transaction, const QByteArray &bufferType) { //TODO use a result set with an iterator, to read values on demand QVector keys; transaction.openDatabase(bufferType + ".main").scan(QByteArray(), [&](const QByteArray &key, const QByteArray &value) -> bool { //Skip internals - if (Akonadi2::Storage::isInternalKey(key)) { + if (Sink::Storage::isInternalKey(key)) { return true; } - keys << Akonadi2::Storage::uidFromKey(key); + keys << Sink::Storage::uidFromKey(key); return true; }, - [](const Akonadi2::Storage::Error &error) { + [](const Sink::Storage::Error &error) { qWarning() << "Error during query: " << error.message; }); @@ -147,7 +147,7 @@ static inline ResultSet fullScan(const Akonadi2::Storage::Transaction &transacti template -QueryWorker::QueryWorker(const Akonadi2::Query &query, const QByteArray &instanceIdentifier, const DomainTypeAdaptorFactoryInterface::Ptr &factory, const QByteArray &bufferType) +QueryWorker::QueryWorker(const Sink::Query &query, const QByteArray &instanceIdentifier, const DomainTypeAdaptorFactoryInterface::Ptr &factory, const QByteArray &bufferType) : QObject(), mDomainTypeAdaptorFactory(factory), mResourceInstanceIdentifier(instanceIdentifier), @@ -164,23 +164,23 @@ QueryWorker::~QueryWorker() } template -void QueryWorker::replaySet(ResultSet &resultSet, Akonadi2::ResultProviderInterface &resultProvider, const QList &properties) +void QueryWorker::replaySet(ResultSet &resultSet, Sink::ResultProviderInterface &resultProvider, const QList &properties) { int counter = 0; - while (resultSet.next([&resultProvider, &counter, &properties](const Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr &value, Akonadi2::Operation operation) -> bool { + while (resultSet.next([&resultProvider, &counter, &properties](const Sink::ApplicationDomain::ApplicationDomainType::Ptr &value, Sink::Operation operation) -> bool { counter++; switch (operation) { - case Akonadi2::Operation_Creation: + case Sink::Operation_Creation: // Trace() << "Got creation"; - resultProvider.add(Akonadi2::ApplicationDomain::ApplicationDomainType::getInMemoryRepresentation(*value, properties).template staticCast()); + resultProvider.add(Sink::ApplicationDomain::ApplicationDomainType::getInMemoryRepresentation(*value, properties).template staticCast()); break; - case Akonadi2::Operation_Modification: + case Sink::Operation_Modification: // Trace() << "Got modification"; - resultProvider.modify(Akonadi2::ApplicationDomain::ApplicationDomainType::getInMemoryRepresentation(*value, properties).template staticCast()); + resultProvider.modify(Sink::ApplicationDomain::ApplicationDomainType::getInMemoryRepresentation(*value, properties).template staticCast()); break; - case Akonadi2::Operation_Removal: + case Sink::Operation_Removal: // Trace() << "Got removal"; - resultProvider.remove(Akonadi2::ApplicationDomain::ApplicationDomainType::getInMemoryRepresentation(*value, properties).template staticCast()); + resultProvider.remove(Sink::ApplicationDomain::ApplicationDomainType::getInMemoryRepresentation(*value, properties).template staticCast()); break; } return true; @@ -189,35 +189,35 @@ void QueryWorker::replaySet(ResultSet &resultSet, Akonadi2::ResultPr } template -void QueryWorker::readEntity(const Akonadi2::Storage::NamedDatabase &db, const QByteArray &key, const std::function &resultCallback) +void QueryWorker::readEntity(const Sink::Storage::NamedDatabase &db, const QByteArray &key, const std::function &resultCallback) { //This only works for a 1:1 mapping of resource to domain types. //Not i.e. for tags that are stored as flags in each entity of an imap store. //additional properties that don't have a 1:1 mapping (such as separately stored tags), //could be added to the adaptor. db.findLatest(key, [=](const QByteArray &key, const QByteArray &value) -> bool { - Akonadi2::EntityBuffer buffer(value.data(), value.size()); - const Akonadi2::Entity &entity = buffer.entity(); - const auto metadataBuffer = Akonadi2::EntityBuffer::readBuffer(entity.metadata()); + Sink::EntityBuffer buffer(value.data(), value.size()); + const Sink::Entity &entity = buffer.entity(); + const auto metadataBuffer = Sink::EntityBuffer::readBuffer(entity.metadata()); Q_ASSERT(metadataBuffer); const qint64 revision = metadataBuffer ? metadataBuffer->revision() : -1; - const auto operation = metadataBuffer ? metadataBuffer->operation() : Akonadi2::Operation_Creation; - resultCallback(DomainType::Ptr::create(mResourceInstanceIdentifier, Akonadi2::Storage::uidFromKey(key), revision, mDomainTypeAdaptorFactory->createAdaptor(entity)), operation); + const auto operation = metadataBuffer ? metadataBuffer->operation() : Sink::Operation_Creation; + resultCallback(DomainType::Ptr::create(mResourceInstanceIdentifier, Sink::Storage::uidFromKey(key), revision, mDomainTypeAdaptorFactory->createAdaptor(entity)), operation); return false; }, - [](const Akonadi2::Storage::Error &error) { + [](const Sink::Storage::Error &error) { qWarning() << "Error during query: " << error.message; }); } template -ResultSet QueryWorker::loadInitialResultSet(const Akonadi2::Query &query, Akonadi2::Storage::Transaction &transaction, QSet &remainingFilters) +ResultSet QueryWorker::loadInitialResultSet(const Sink::Query &query, Sink::Storage::Transaction &transaction, QSet &remainingFilters) { if (!query.ids.isEmpty()) { return ResultSet(query.ids.toVector()); } QSet appliedFilters; - auto resultSet = Akonadi2::ApplicationDomain::TypeImplementation::queryIndexes(query, mResourceInstanceIdentifier, appliedFilters, transaction); + auto resultSet = Sink::ApplicationDomain::TypeImplementation::queryIndexes(query, mResourceInstanceIdentifier, appliedFilters, transaction); remainingFilters = query.propertyFilter.keys().toSet() - appliedFilters; //We do a full scan if there were no indexes available to create the initial set. @@ -229,24 +229,24 @@ ResultSet QueryWorker::loadInitialResultSet(const Akonadi2::Query &q } template -ResultSet QueryWorker::loadIncrementalResultSet(qint64 baseRevision, const Akonadi2::Query &query, Akonadi2::Storage::Transaction &transaction, QSet &remainingFilters) +ResultSet QueryWorker::loadIncrementalResultSet(qint64 baseRevision, const Sink::Query &query, Sink::Storage::Transaction &transaction, QSet &remainingFilters) { const auto bufferType = mBufferType; auto revisionCounter = QSharedPointer::create(baseRevision); remainingFilters = query.propertyFilter.keys().toSet(); return ResultSet([bufferType, revisionCounter, &transaction]() -> QByteArray { - const qint64 topRevision = Akonadi2::Storage::maxRevision(transaction); + const qint64 topRevision = Sink::Storage::maxRevision(transaction); //Spit out the revision keys one by one. while (*revisionCounter <= topRevision) { - const auto uid = Akonadi2::Storage::getUidFromRevision(transaction, *revisionCounter); - const auto type = Akonadi2::Storage::getTypeFromRevision(transaction, *revisionCounter); + const auto uid = Sink::Storage::getUidFromRevision(transaction, *revisionCounter); + const auto type = Sink::Storage::getTypeFromRevision(transaction, *revisionCounter); // Trace() << "Revision" << *revisionCounter << type << uid; if (type != bufferType) { //Skip revision *revisionCounter += 1; continue; } - const auto key = Akonadi2::Storage::assembleKey(uid, *revisionCounter); + const auto key = Sink::Storage::assembleKey(uid, *revisionCounter); *revisionCounter += 1; return key; } @@ -257,21 +257,21 @@ ResultSet QueryWorker::loadIncrementalResultSet(qint64 baseRevision, } template -ResultSet QueryWorker::filterSet(const ResultSet &resultSet, const std::function &filter, const Akonadi2::Storage::NamedDatabase &db, bool initialQuery) +ResultSet QueryWorker::filterSet(const ResultSet &resultSet, const std::function &filter, const Sink::Storage::NamedDatabase &db, bool initialQuery) { auto resultSetPtr = QSharedPointer::create(resultSet); //Read through the source values and return whatever matches the filter - std::function)> generator = [this, resultSetPtr, &db, filter, initialQuery](std::function callback) -> bool { + std::function)> generator = [this, resultSetPtr, &db, filter, initialQuery](std::function callback) -> bool { if (resultSetPtr->next()) { //readEntity is only necessary if we actually want to filter or know the operation type (but not a big deal if we do it always I guess) - readEntity(db, resultSetPtr->id(), [this, filter, callback, initialQuery](const Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr &domainObject, Akonadi2::Operation operation) { + readEntity(db, resultSetPtr->id(), [this, filter, callback, initialQuery](const Sink::ApplicationDomain::ApplicationDomainType::Ptr &domainObject, Sink::Operation operation) { //Always remove removals, they probably don't match due to non-available properties - if (filter(domainObject) || operation == Akonadi2::Operation_Removal) { + if (filter(domainObject) || operation == Sink::Operation_Removal) { if (initialQuery) { //We're not interested in removals during the initial query - if (operation != Akonadi2::Operation_Removal) { - callback(domainObject, Akonadi2::Operation_Creation); + if (operation != Sink::Operation_Removal) { + callback(domainObject, Sink::Operation_Creation); } } else { callback(domainObject, operation); @@ -287,9 +287,9 @@ ResultSet QueryWorker::filterSet(const ResultSet &resultSet, const s } template -std::function QueryWorker::getFilter(const QSet remainingFilters, const Akonadi2::Query &query) +std::function QueryWorker::getFilter(const QSet remainingFilters, const Sink::Query &query) { - return [remainingFilters, query](const Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr &domainObject) -> bool { + return [remainingFilters, query](const Sink::ApplicationDomain::ApplicationDomainType::Ptr &domainObject) -> bool { if (!query.ids.isEmpty()) { if (!query.ids.contains(domainObject->identifier())) { return false; @@ -312,32 +312,32 @@ std::function -qint64 QueryWorker::load(const Akonadi2::Query &query, const std::function &)> &baseSetRetriever, Akonadi2::ResultProviderInterface &resultProvider, bool initialQuery) +qint64 QueryWorker::load(const Sink::Query &query, const std::function &)> &baseSetRetriever, Sink::ResultProviderInterface &resultProvider, bool initialQuery) { - Akonadi2::Storage storage(Akonadi2::storageLocation(), mResourceInstanceIdentifier); - storage.setDefaultErrorHandler([](const Akonadi2::Storage::Error &error) { + Sink::Storage storage(Sink::storageLocation(), mResourceInstanceIdentifier); + storage.setDefaultErrorHandler([](const Sink::Storage::Error &error) { Warning() << "Error during query: " << error.store << error.message; }); - auto transaction = storage.createTransaction(Akonadi2::Storage::ReadOnly); + auto transaction = storage.createTransaction(Sink::Storage::ReadOnly); auto db = transaction.openDatabase(mBufferType + ".main"); QSet remainingFilters; auto resultSet = baseSetRetriever(transaction, remainingFilters); auto filteredSet = filterSet(resultSet, getFilter(remainingFilters, query), db, initialQuery); replaySet(filteredSet, resultProvider, query.requestedProperties); - resultProvider.setRevision(Akonadi2::Storage::maxRevision(transaction)); - return Akonadi2::Storage::maxRevision(transaction); + resultProvider.setRevision(Sink::Storage::maxRevision(transaction)); + return Sink::Storage::maxRevision(transaction); } template -qint64 QueryWorker::executeIncrementalQuery(const Akonadi2::Query &query, Akonadi2::ResultProviderInterface &resultProvider) +qint64 QueryWorker::executeIncrementalQuery(const Sink::Query &query, Sink::ResultProviderInterface &resultProvider) { QTime time; time.start(); const qint64 baseRevision = resultProvider.revision() + 1; Trace() << "Running incremental query " << baseRevision; - auto revision = load(query, [&](Akonadi2::Storage::Transaction &transaction, QSet &remainingFilters) -> ResultSet { + auto revision = load(query, [&](Sink::Storage::Transaction &transaction, QSet &remainingFilters) -> ResultSet { return loadIncrementalResultSet(baseRevision, query, transaction, remainingFilters); }, resultProvider, false); Trace() << "Incremental query took: " << time.elapsed() << " ms"; @@ -345,7 +345,7 @@ qint64 QueryWorker::executeIncrementalQuery(const Akonadi2::Query &q } template -qint64 QueryWorker::executeInitialQuery(const Akonadi2::Query &query, const typename DomainType::Ptr &parent, Akonadi2::ResultProviderInterface &resultProvider) +qint64 QueryWorker::executeInitialQuery(const Sink::Query &query, const typename DomainType::Ptr &parent, Sink::ResultProviderInterface &resultProvider) { QTime time; time.start(); @@ -360,7 +360,7 @@ qint64 QueryWorker::executeInitialQuery(const Akonadi2::Query &query modifiedQuery.propertyFilter.insert(query.parentProperty, QVariant()); } } - auto revision = load(modifiedQuery, [&](Akonadi2::Storage::Transaction &transaction, QSet &remainingFilters) -> ResultSet { + auto revision = load(modifiedQuery, [&](Sink::Storage::Transaction &transaction, QSet &remainingFilters) -> ResultSet { return loadInitialResultSet(modifiedQuery, transaction, remainingFilters); }, resultProvider, true); Trace() << "Initial query took: " << time.elapsed() << " ms"; @@ -368,9 +368,9 @@ qint64 QueryWorker::executeInitialQuery(const Akonadi2::Query &query return revision; } -template class QueryRunner; -template class QueryRunner; -template class QueryRunner; -template class QueryWorker; -template class QueryWorker; -template class QueryWorker; +template class QueryRunner; +template class QueryRunner; +template class QueryRunner; +template class QueryWorker; +template class QueryWorker; +template class QueryWorker; diff --git a/common/queryrunner.h b/common/queryrunner.h index aba7912..0ee6a81 100644 --- a/common/queryrunner.h +++ b/common/queryrunner.h @@ -79,13 +79,13 @@ template class QueryRunner : public QueryRunnerBase { public: - QueryRunner(const Akonadi2::Query &query, const Akonadi2::ResourceAccessInterface::Ptr &, const QByteArray &instanceIdentifier, const DomainTypeAdaptorFactoryInterface::Ptr &, const QByteArray &bufferType); + QueryRunner(const Sink::Query &query, const Sink::ResourceAccessInterface::Ptr &, const QByteArray &instanceIdentifier, const DomainTypeAdaptorFactoryInterface::Ptr &, const QByteArray &bufferType); virtual ~QueryRunner(); - typename Akonadi2::ResultEmitter::Ptr emitter(); + typename Sink::ResultEmitter::Ptr emitter(); private: - QSharedPointer mResourceAccess; - QSharedPointer > mResultProvider; + QSharedPointer mResourceAccess; + QSharedPointer > mResultProvider; }; diff --git a/common/queuedcommand.fbs b/common/queuedcommand.fbs index 0ca899f..06226d3 100644 --- a/common/queuedcommand.fbs +++ b/common/queuedcommand.fbs @@ -1,4 +1,4 @@ -namespace Akonadi2; +namespace Sink; table QueuedCommand { commandId: int; diff --git a/common/resource.cpp b/common/resource.cpp index 4541726..8c448a8 100644 --- a/common/resource.cpp +++ b/common/resource.cpp @@ -27,7 +27,7 @@ #include "facadefactory.h" -namespace Akonadi2 +namespace Sink { Resource::Resource() @@ -94,8 +94,8 @@ ResourceFactory *ResourceFactory::load(const QString &resourceName) if (path.endsWith(QLatin1String("plugins"))) { QDir pluginDir(path); //TODO: centralize this so that it is easy to change centrally - // also ref'd in cmake as ${AKONADI_RESOURCE_PLUGINS_PATH} - pluginDir.cd(QStringLiteral("akonadi2")); + // also ref'd in cmake as ${SINK_RESOURCE_PLUGINS_PATH} + pluginDir.cd(QStringLiteral("sink")); pluginDir.cd(QStringLiteral("resources")); for (const QString &fileName: pluginDir.entryList(QDir::Files)) { @@ -128,4 +128,4 @@ ResourceFactory *ResourceFactory::load(const QString &resourceName) return nullptr; } -} // namespace Akonadi2 +} // namespace Sink diff --git a/common/resource.h b/common/resource.h index 2ae71a0..30d6c46 100644 --- a/common/resource.h +++ b/common/resource.h @@ -19,19 +19,19 @@ */ #pragma once -#include +#include #include #include "notification.h" -namespace Akonadi2 +namespace Sink { class FacadeFactory; /** * Resource interface */ -class AKONADI2COMMON_EXPORT Resource : public QObject +class SINKCOMMON_EXPORT Resource : public QObject { Q_OBJECT public: @@ -83,8 +83,8 @@ private: Private * const d; }; -} // namespace Akonadi2 +} // namespace Sink -Q_DECLARE_INTERFACE(Akonadi2::ResourceFactory, "org.kde.akonadi2.resourcefactory") +Q_DECLARE_INTERFACE(Sink::ResourceFactory, "org.kde.sink.resourcefactory") diff --git a/common/resourceaccess.cpp b/common/resourceaccess.cpp index 6592699..0c435c9 100644 --- a/common/resourceaccess.cpp +++ b/common/resourceaccess.cpp @@ -43,9 +43,9 @@ #include #undef Trace -#define Trace() Akonadi2::Log::debugStream(Akonadi2::Log::DebugLevel::Trace, __LINE__, __FILE__, Q_FUNC_INFO, "ResourceAccess") +#define Trace() Sink::Log::debugStream(Sink::Log::DebugLevel::Trace, __LINE__, __FILE__, Q_FUNC_INFO, "ResourceAccess") #undef Log -#define Log(IDENTIFIER) Akonadi2::Log::debugStream(Akonadi2::Log::DebugLevel::Log, __LINE__, __FILE__, Q_FUNC_INFO, "ResourceAccess("+IDENTIFIER+")") +#define Log(IDENTIFIER) Sink::Log::debugStream(Sink::Log::DebugLevel::Log, __LINE__, __FILE__, Q_FUNC_INFO, "ResourceAccess("+IDENTIFIER+")") static void queuedInvoke(const std::function &f, QObject *context = 0) { @@ -57,7 +57,7 @@ static void queuedInvoke(const std::function &f, QObject *context = 0) timer->start(0); } -namespace Akonadi2 +namespace Sink { struct QueuedCommand @@ -205,7 +205,7 @@ KAsync::Job ResourceAccess::Private::initializeSocket() QStringList args; args << resourceInstanceIdentifier; qint64 pid = 0; - if (QProcess::startDetached("akonadi2_synchronizer", args, QDir::homePath(), &pid)) { + if (QProcess::startDetached("sink_synchronizer", args, QDir::homePath(), &pid)) { Trace() << "Started resource " << pid; tryToConnect() .then([&future]() { @@ -298,8 +298,8 @@ KAsync::Job ResourceAccess::synchronizeResource(bool sourceSync, bool loca { Trace() << "Sending synchronize command: " << sourceSync << localSync; flatbuffers::FlatBufferBuilder fbb; - auto command = Akonadi2::Commands::CreateSynchronize(fbb, sourceSync, localSync); - Akonadi2::Commands::FinishSynchronizeBuffer(fbb, command); + auto command = Sink::Commands::CreateSynchronize(fbb, sourceSync, localSync); + Sink::Commands::FinishSynchronizeBuffer(fbb, command); open(); return sendCommand(Commands::SynchronizeCommand, fbb); } @@ -309,11 +309,11 @@ KAsync::Job ResourceAccess::sendCreateCommand(const QByteArray &resourceBu flatbuffers::FlatBufferBuilder fbb; //This is the resource buffer type and not the domain type auto type = fbb.CreateString(resourceBufferType.constData()); - auto delta = Akonadi2::EntityBuffer::appendAsVector(fbb, buffer.constData(), buffer.size()); - auto location = Akonadi2::Commands::CreateCreateEntity(fbb, 0, type, delta); - Akonadi2::Commands::FinishCreateEntityBuffer(fbb, location); + auto delta = Sink::EntityBuffer::appendAsVector(fbb, buffer.constData(), buffer.size()); + auto location = Sink::Commands::CreateCreateEntity(fbb, 0, type, delta); + Sink::Commands::FinishCreateEntityBuffer(fbb, location); open(); - return sendCommand(Akonadi2::Commands::CreateEntityCommand, fbb); + return sendCommand(Sink::Commands::CreateEntityCommand, fbb); } KAsync::Job ResourceAccess::sendModifyCommand(const QByteArray &uid, qint64 revision, const QByteArray &resourceBufferType, const QByteArrayList &deletedProperties, const QByteArray &buffer) @@ -324,11 +324,11 @@ KAsync::Job ResourceAccess::sendModifyCommand(const QByteArray &uid, qint6 auto type = fbb.CreateString(resourceBufferType.constData()); //FIXME auto deletions = 0; - auto delta = Akonadi2::EntityBuffer::appendAsVector(fbb, buffer.constData(), buffer.size()); - auto location = Akonadi2::Commands::CreateModifyEntity(fbb, revision, entityId, deletions, type, delta); - Akonadi2::Commands::FinishModifyEntityBuffer(fbb, location); + auto delta = Sink::EntityBuffer::appendAsVector(fbb, buffer.constData(), buffer.size()); + auto location = Sink::Commands::CreateModifyEntity(fbb, revision, entityId, deletions, type, delta); + Sink::Commands::FinishModifyEntityBuffer(fbb, location); open(); - return sendCommand(Akonadi2::Commands::ModifyEntityCommand, fbb); + return sendCommand(Sink::Commands::ModifyEntityCommand, fbb); } KAsync::Job ResourceAccess::sendDeleteCommand(const QByteArray &uid, qint64 revision, const QByteArray &resourceBufferType) @@ -337,19 +337,19 @@ KAsync::Job ResourceAccess::sendDeleteCommand(const QByteArray &uid, qint6 auto entityId = fbb.CreateString(uid.constData()); //This is the resource buffer type and not the domain type auto type = fbb.CreateString(resourceBufferType.constData()); - auto location = Akonadi2::Commands::CreateDeleteEntity(fbb, revision, entityId, type); - Akonadi2::Commands::FinishDeleteEntityBuffer(fbb, location); + auto location = Sink::Commands::CreateDeleteEntity(fbb, revision, entityId, type); + Sink::Commands::FinishDeleteEntityBuffer(fbb, location); open(); - return sendCommand(Akonadi2::Commands::DeleteEntityCommand, fbb); + return sendCommand(Sink::Commands::DeleteEntityCommand, fbb); } KAsync::Job ResourceAccess::sendRevisionReplayedCommand(qint64 revision) { flatbuffers::FlatBufferBuilder fbb; - auto location = Akonadi2::Commands::CreateRevisionReplayed(fbb, revision); - Akonadi2::Commands::FinishRevisionReplayedBuffer(fbb, location); + auto location = Sink::Commands::CreateRevisionReplayed(fbb, revision); + Sink::Commands::FinishRevisionReplayedBuffer(fbb, location); open(); - return sendCommand(Akonadi2::Commands::RevisionReplayedCommand, fbb); + return sendCommand(Sink::Commands::RevisionReplayedCommand, fbb); } KAsync::Job ResourceAccess::sendInspectionCommand(const QByteArray &inspectionId, const QByteArray &domainType, const QByteArray &entityId, const QByteArray &property, const QVariant &expectedValue) @@ -365,10 +365,10 @@ KAsync::Job ResourceAccess::sendInspectionCommand(const QByteArray &inspec s << expectedValue; auto expected = fbb.CreateString(array.toStdString()); - auto location = Akonadi2::Commands::CreateInspection (fbb, id, 0, entity, domain, prop, expected); - Akonadi2::Commands::FinishInspectionBuffer(fbb, location); + auto location = Sink::Commands::CreateInspection (fbb, id, 0, entity, domain, prop, expected); + Sink::Commands::FinishInspectionBuffer(fbb, location); open(); - return sendCommand(Akonadi2::Commands::InspectionCommand, fbb); + return sendCommand(Sink::Commands::InspectionCommand, fbb); } void ResourceAccess::open() @@ -412,7 +412,7 @@ void ResourceAccess::sendCommand(const QSharedPointer &command) //TODO: we should have a timeout for commands d->messageId++; const auto messageId = d->messageId; - log(QString("Sending command \"%1\" with messageId %2").arg(QString(Akonadi2::Commands::name(command->commandId))).arg(d->messageId)); + log(QString("Sending command \"%1\" with messageId %2").arg(QString(Sink::Commands::name(command->commandId))).arg(d->messageId)); Q_ASSERT(command->callback); registerCallback(d->messageId, [this, messageId, command](int errorCode, QString errorMessage) { Trace() << "Command complete " << messageId; @@ -457,8 +457,8 @@ void ResourceAccess::connected() { flatbuffers::FlatBufferBuilder fbb; auto name = fbb.CreateString(QString("PID: %1 ResourceAccess: %2").arg(QCoreApplication::applicationPid()).arg(reinterpret_cast(this)).toLatin1()); - auto command = Akonadi2::Commands::CreateHandshake(fbb, name); - Akonadi2::Commands::FinishHandshakeBuffer(fbb, command); + auto command = Sink::Commands::CreateHandshake(fbb, name); + Sink::Commands::FinishHandshakeBuffer(fbb, command); Commands::write(d->socket.data(), ++d->messageId, Commands::HandshakeCommand, fbb); } @@ -543,11 +543,11 @@ bool ResourceAccess::processMessageBuffer() case Commands::NotificationCommand: { auto buffer = Commands::GetNotification(d->partialMessageBuffer.constData() + headerSize); switch (buffer->type()) { - case Akonadi2::Commands::NotificationType::NotificationType_Shutdown: + case Sink::Commands::NotificationType::NotificationType_Shutdown: Log(d->resourceInstanceIdentifier) << "Received shutdown notification."; close(); break; - case Akonadi2::Commands::NotificationType::NotificationType_Inspection: { + case Sink::Commands::NotificationType::NotificationType_Inspection: { Log(d->resourceInstanceIdentifier) << "Received inspection notification."; Notification n; if (buffer->identifier()) { diff --git a/common/resourceaccess.h b/common/resourceaccess.h index 2fe83ed..73b676b 100644 --- a/common/resourceaccess.h +++ b/common/resourceaccess.h @@ -29,7 +29,7 @@ #include #include "notification.h" -namespace Akonadi2 +namespace Sink { struct QueuedCommand; diff --git a/common/resourceconfig.cpp b/common/resourceconfig.cpp index a0f39a8..a34340b 100644 --- a/common/resourceconfig.cpp +++ b/common/resourceconfig.cpp @@ -25,12 +25,12 @@ static QSharedPointer getSettings() { - return QSharedPointer::create(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/akonadi2/resources.ini", QSettings::IniFormat); + return QSharedPointer::create(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/sink/resources.ini", QSettings::IniFormat); } static QSharedPointer getResourceConfig(const QByteArray &identifier) { - return QSharedPointer::create(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/akonadi2/" + identifier, QSettings::IniFormat); + return QSharedPointer::create(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/sink/" + identifier, QSettings::IniFormat); } QByteArray ResourceConfig::newIdentifier(const QByteArray &type) diff --git a/common/resourcefacade.cpp b/common/resourcefacade.cpp index 20d9a7c..414e390 100644 --- a/common/resourcefacade.cpp +++ b/common/resourcefacade.cpp @@ -25,7 +25,7 @@ #include ResourceFacade::ResourceFacade(const QByteArray &) - : Akonadi2::StoreFacade() + : Sink::StoreFacade() { } @@ -35,7 +35,7 @@ ResourceFacade::~ResourceFacade() } -KAsync::Job ResourceFacade::create(const Akonadi2::ApplicationDomain::AkonadiResource &resource) +KAsync::Job ResourceFacade::create(const Sink::ApplicationDomain::SinkResource &resource) { return KAsync::start([resource, this]() { const QByteArray type = resource.getProperty("type").toByteArray(); @@ -57,7 +57,7 @@ KAsync::Job ResourceFacade::create(const Akonadi2::ApplicationDomain::Akon }); } -KAsync::Job ResourceFacade::modify(const Akonadi2::ApplicationDomain::AkonadiResource &resource) +KAsync::Job ResourceFacade::modify(const Sink::ApplicationDomain::SinkResource &resource) { return KAsync::start([resource, this]() { const QByteArray identifier = resource.identifier(); @@ -79,7 +79,7 @@ KAsync::Job ResourceFacade::modify(const Akonadi2::ApplicationDomain::Akon }); } -KAsync::Job ResourceFacade::remove(const Akonadi2::ApplicationDomain::AkonadiResource &resource) +KAsync::Job ResourceFacade::remove(const Sink::ApplicationDomain::SinkResource &resource) { return KAsync::start([resource, this]() { const QByteArray identifier = resource.identifier(); @@ -89,18 +89,18 @@ KAsync::Job ResourceFacade::remove(const Akonadi2::ApplicationDomain::Akon } ResourceConfig::removeResource(identifier); //TODO shutdown resource, or use the resource process with a --remove option to cleanup (so we can take advantage of the file locking) - QDir dir(Akonadi2::storageLocation()); + QDir dir(Sink::storageLocation()); for (const auto &folder : dir.entryList(QStringList() << identifier + "*")) { - Akonadi2::Storage(Akonadi2::storageLocation(), folder, Akonadi2::Storage::ReadWrite).removeFromDisk(); + Sink::Storage(Sink::storageLocation(), folder, Sink::Storage::ReadWrite).removeFromDisk(); } }); } -QPair, typename Akonadi2::ResultEmitter::Ptr > ResourceFacade::load(const Akonadi2::Query &query) +QPair, typename Sink::ResultEmitter::Ptr > ResourceFacade::load(const Sink::Query &query) { - auto resultProvider = new Akonadi2::ResultProvider(); + auto resultProvider = new Sink::ResultProvider(); auto emitter = resultProvider->emitter(); - resultProvider->setFetcher([](const QSharedPointer &) {}); + resultProvider->setFetcher([](const QSharedPointer &) {}); resultProvider->onDone([resultProvider]() { delete resultProvider; }); @@ -109,13 +109,13 @@ QPair, typename Akonadi2::ResultEmitter::create()); + auto resource = Sink::ApplicationDomain::SinkResource::Ptr::create("", res, 0, QSharedPointer::create()); resource->setProperty("type", type); resultProvider->add(resource); } } //TODO initialResultSetComplete should be implicit - resultProvider->initialResultSetComplete(Akonadi2::ApplicationDomain::AkonadiResource::Ptr()); + resultProvider->initialResultSetComplete(Sink::ApplicationDomain::SinkResource::Ptr()); resultProvider->complete(); }); return qMakePair(job, emitter); diff --git a/common/resourcefacade.h b/common/resourcefacade.h index 99ec632..5ddaa79 100644 --- a/common/resourcefacade.h +++ b/common/resourcefacade.h @@ -25,19 +25,19 @@ #include "common/resultprovider.h" #include "common/domain/applicationdomaintype.h" -namespace Akonadi2 { +namespace Sink { class Query; class Inspection; } -class ResourceFacade : public Akonadi2::StoreFacade +class ResourceFacade : public Sink::StoreFacade { public: ResourceFacade(const QByteArray &instanceIdentifier); virtual ~ResourceFacade(); - KAsync::Job create(const Akonadi2::ApplicationDomain::AkonadiResource &resource) Q_DECL_OVERRIDE; - KAsync::Job modify(const Akonadi2::ApplicationDomain::AkonadiResource &resource) Q_DECL_OVERRIDE; - KAsync::Job remove(const Akonadi2::ApplicationDomain::AkonadiResource &resource) Q_DECL_OVERRIDE; - QPair, typename Akonadi2::ResultEmitter::Ptr > load(const Akonadi2::Query &query) Q_DECL_OVERRIDE; + KAsync::Job create(const Sink::ApplicationDomain::SinkResource &resource) Q_DECL_OVERRIDE; + KAsync::Job modify(const Sink::ApplicationDomain::SinkResource &resource) Q_DECL_OVERRIDE; + KAsync::Job remove(const Sink::ApplicationDomain::SinkResource &resource) Q_DECL_OVERRIDE; + QPair, typename Sink::ResultEmitter::Ptr > load(const Sink::Query &query) Q_DECL_OVERRIDE; }; diff --git a/common/resultprovider.h b/common/resultprovider.h index a064ab5..6958dbf 100644 --- a/common/resultprovider.h +++ b/common/resultprovider.h @@ -29,7 +29,7 @@ using namespace async; -namespace Akonadi2 { +namespace Sink { /** * Query result set diff --git a/common/resultset.h b/common/resultset.h index 746b94b..ec399fc 100644 --- a/common/resultset.h +++ b/common/resultset.h @@ -37,7 +37,7 @@ class ResultSet { } - ResultSet(const std::function)> &generator) + ResultSet(const std::function)> &generator) : mIt(nullptr), mValueGenerator(generator) { @@ -76,7 +76,7 @@ class ResultSet { return false; } - bool next(std::function callback) + bool next(std::function callback) { Q_ASSERT(mValueGenerator); return mValueGenerator(callback); @@ -116,6 +116,6 @@ class ResultSet { QVector::ConstIterator mIt; QByteArray mCurrentValue; std::function mGenerator; - std::function)> mValueGenerator; + std::function)> mValueGenerator; }; diff --git a/common/storage.h b/common/storage.h index daeace8..2d34f1f 100644 --- a/common/storage.h +++ b/common/storage.h @@ -21,15 +21,15 @@ #pragma once -#include +#include #include #include #include -namespace Akonadi2 +namespace Sink { -class AKONADI2COMMON_EXPORT Storage { +class SINKCOMMON_EXPORT Storage { public: enum AccessMode { ReadOnly, ReadWrite }; @@ -180,16 +180,16 @@ public: qint64 diskUsage() const; void removeFromDisk() const; - static qint64 maxRevision(const Akonadi2::Storage::Transaction &); - static void setMaxRevision(Akonadi2::Storage::Transaction &, qint64 revision); + static qint64 maxRevision(const Sink::Storage::Transaction &); + static void setMaxRevision(Sink::Storage::Transaction &, qint64 revision); - static qint64 cleanedUpRevision(const Akonadi2::Storage::Transaction &); - static void setCleanedUpRevision(Akonadi2::Storage::Transaction &, qint64 revision); + static qint64 cleanedUpRevision(const Sink::Storage::Transaction &); + static void setCleanedUpRevision(Sink::Storage::Transaction &, qint64 revision); - static QByteArray getUidFromRevision(const Akonadi2::Storage::Transaction &, qint64 revision); - static QByteArray getTypeFromRevision(const Akonadi2::Storage::Transaction &, qint64 revision); - static void recordRevision(Akonadi2::Storage::Transaction &, qint64 revision, const QByteArray &uid, const QByteArray &type); - static void removeRevision(Akonadi2::Storage::Transaction &, qint64 revision); + static QByteArray getUidFromRevision(const Sink::Storage::Transaction &, qint64 revision); + static QByteArray getTypeFromRevision(const Sink::Storage::Transaction &, qint64 revision); + static void recordRevision(Sink::Storage::Transaction &, qint64 revision, const QByteArray &uid, const QByteArray &type); + static void removeRevision(Sink::Storage::Transaction &, qint64 revision); bool exists() const; @@ -208,5 +208,5 @@ private: Private * const d; }; -} // namespace Akonadi2 +} // namespace Sink diff --git a/common/storage_common.cpp b/common/storage_common.cpp index e534bc1..ea97ac2 100644 --- a/common/storage_common.cpp +++ b/common/storage_common.cpp @@ -23,7 +23,7 @@ #include "log.h" -namespace Akonadi2 +namespace Sink { static const char *s_internalPrefix = "__internal"; @@ -52,45 +52,45 @@ std::function Storage::defaultErrorHandler() return basicErrorHandler(); } -void Storage::setMaxRevision(Akonadi2::Storage::Transaction &transaction, qint64 revision) +void Storage::setMaxRevision(Sink::Storage::Transaction &transaction, qint64 revision) { transaction.openDatabase().write("__internal_maxRevision", QByteArray::number(revision)); } -qint64 Storage::maxRevision(const Akonadi2::Storage::Transaction &transaction) +qint64 Storage::maxRevision(const Sink::Storage::Transaction &transaction) { qint64 r = 0; transaction.openDatabase().scan("__internal_maxRevision", [&](const QByteArray &, const QByteArray &revision) -> bool { r = revision.toLongLong(); return false; }, [](const Error &error){ - if (error.code != Akonadi2::Storage::NotFound) { + if (error.code != Sink::Storage::NotFound) { Warning() << "Coultn'd find the maximum revision."; } }); return r; } -void Storage::setCleanedUpRevision(Akonadi2::Storage::Transaction &transaction, qint64 revision) +void Storage::setCleanedUpRevision(Sink::Storage::Transaction &transaction, qint64 revision) { transaction.openDatabase().write("__internal_cleanedUpRevision", QByteArray::number(revision)); } -qint64 Storage::cleanedUpRevision(const Akonadi2::Storage::Transaction &transaction) +qint64 Storage::cleanedUpRevision(const Sink::Storage::Transaction &transaction) { qint64 r = 0; transaction.openDatabase().scan("__internal_cleanedUpRevision", [&](const QByteArray &, const QByteArray &revision) -> bool { r = revision.toLongLong(); return false; }, [](const Error &error){ - if (error.code != Akonadi2::Storage::NotFound) { + if (error.code != Sink::Storage::NotFound) { Warning() << "Coultn'd find the maximum revision."; } }); return r; } -QByteArray Storage::getUidFromRevision(const Akonadi2::Storage::Transaction &transaction, qint64 revision) +QByteArray Storage::getUidFromRevision(const Sink::Storage::Transaction &transaction, qint64 revision) { QByteArray uid; transaction.openDatabase("revisions").scan(QByteArray::number(revision), [&](const QByteArray &, const QByteArray &value) -> bool { @@ -102,7 +102,7 @@ QByteArray Storage::getUidFromRevision(const Akonadi2::Storage::Transaction &tra return uid; } -QByteArray Storage::getTypeFromRevision(const Akonadi2::Storage::Transaction &transaction, qint64 revision) +QByteArray Storage::getTypeFromRevision(const Sink::Storage::Transaction &transaction, qint64 revision) { QByteArray type; transaction.openDatabase("revisionType").scan(QByteArray::number(revision), [&](const QByteArray &, const QByteArray &value) -> bool { @@ -114,14 +114,14 @@ QByteArray Storage::getTypeFromRevision(const Akonadi2::Storage::Transaction &tr return type; } -void Storage::recordRevision(Akonadi2::Storage::Transaction &transaction, qint64 revision, const QByteArray &uid, const QByteArray &type) +void Storage::recordRevision(Sink::Storage::Transaction &transaction, qint64 revision, const QByteArray &uid, const QByteArray &type) { //TODO use integerkeys transaction.openDatabase("revisions").write(QByteArray::number(revision), uid); transaction.openDatabase("revisionType").write(QByteArray::number(revision), type); } -void Storage::removeRevision(Akonadi2::Storage::Transaction &transaction, qint64 revision) +void Storage::removeRevision(Sink::Storage::Transaction &transaction, qint64 revision) { transaction.openDatabase("revisions").remove(QByteArray::number(revision)); } @@ -162,9 +162,9 @@ bool Storage::NamedDatabase::contains(const QByteArray &uid) scan(uid, [&found](const QByteArray &, const QByteArray &) -> bool { found = true; return false; - }, [this](const Akonadi2::Storage::Error &error) { + }, [this](const Sink::Storage::Error &error) { }, true); return found; } -} // namespace Akonadi2 +} // namespace Sink diff --git a/common/storage_lmdb.cpp b/common/storage_lmdb.cpp index 79f32ba..6539eb0 100644 --- a/common/storage_lmdb.cpp +++ b/common/storage_lmdb.cpp @@ -33,7 +33,7 @@ #include -namespace Akonadi2 +namespace Sink { int getErrorCode(int e) @@ -615,4 +615,4 @@ void Storage::removeFromDisk() const mdb_env_close(env); } -} // namespace Akonadi2 +} // namespace Sink diff --git a/common/synclistresult.h b/common/synclistresult.h index 3ae2bed..055714f 100644 --- a/common/synclistresult.h +++ b/common/synclistresult.h @@ -19,7 +19,7 @@ namespace async { template class SyncListResult : public QList { public: - SyncListResult(const QSharedPointer > &emitter) + SyncListResult(const QSharedPointer > &emitter) :QList(), mEmitter(emitter) { @@ -66,7 +66,7 @@ public: } private: - QSharedPointer > mEmitter; + QSharedPointer > mEmitter; std::function eventLoopAborter; }; diff --git a/common/typeindex.cpp b/common/typeindex.cpp index 19e0507..03ad8f7 100644 --- a/common/typeindex.cpp +++ b/common/typeindex.cpp @@ -31,7 +31,7 @@ TypeIndex::TypeIndex(const QByteArray &type) template<> void TypeIndex::addProperty(const QByteArray &property) { - auto indexer = [this, property](const QByteArray &identifier, const QVariant &value, Akonadi2::Storage::Transaction &transaction) { + auto indexer = [this, property](const QByteArray &identifier, const QVariant &value, Sink::Storage::Transaction &transaction) { // Trace() << "Indexing " << mType + ".index." + property << value.toByteArray(); if (value.isValid()) { Index(mType + ".index." + property, transaction).add(value.toByteArray(), identifier); @@ -46,7 +46,7 @@ void TypeIndex::addProperty(const QByteArray &property) template<> void TypeIndex::addProperty(const QByteArray &property) { - auto indexer = [this, property](const QByteArray &identifier, const QVariant &value, Akonadi2::Storage::Transaction &transaction) { + auto indexer = [this, property](const QByteArray &identifier, const QVariant &value, Sink::Storage::Transaction &transaction) { // Trace() << "Indexing " << mType + ".index." + property << value.toByteArray(); if (value.isValid()) { Index(mType + ".index." + property, transaction).add(value.toByteArray(), identifier); @@ -61,7 +61,7 @@ void TypeIndex::addProperty(const QByteArray &property) template<> void TypeIndex::addProperty(const QByteArray &property) { - auto indexer = [this, property](const QByteArray &identifier, const QVariant &value, Akonadi2::Storage::Transaction &transaction) { + auto indexer = [this, property](const QByteArray &identifier, const QVariant &value, Sink::Storage::Transaction &transaction) { const auto date = value.toDateTime(); // Trace() << "Indexing " << mType + ".index." + property << date.toString(); if (date.isValid()) { @@ -72,7 +72,7 @@ void TypeIndex::addProperty(const QByteArray &property) mProperties << property; } -void TypeIndex::add(const QByteArray &identifier, const Akonadi2::ApplicationDomain::BufferAdaptor &bufferAdaptor, Akonadi2::Storage::Transaction &transaction) +void TypeIndex::add(const QByteArray &identifier, const Sink::ApplicationDomain::BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction) { for (const auto &property : mProperties) { const auto value = bufferAdaptor.getProperty(property); @@ -81,7 +81,7 @@ void TypeIndex::add(const QByteArray &identifier, const Akonadi2::ApplicationDom } } -void TypeIndex::remove(const QByteArray &identifier, const Akonadi2::ApplicationDomain::BufferAdaptor &bufferAdaptor, Akonadi2::Storage::Transaction &transaction) +void TypeIndex::remove(const QByteArray &identifier, const Sink::ApplicationDomain::BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction) { for (const auto &property : mProperties) { const auto value = bufferAdaptor.getProperty(property); @@ -94,7 +94,7 @@ void TypeIndex::remove(const QByteArray &identifier, const Akonadi2::Application } } -ResultSet TypeIndex::query(const Akonadi2::Query &query, QSet &appliedFilters, Akonadi2::Storage::Transaction &transaction) +ResultSet TypeIndex::query(const Sink::Query &query, QSet &appliedFilters, Sink::Storage::Transaction &transaction) { QVector keys; for (const auto &property : mProperties) { diff --git a/common/typeindex.h b/common/typeindex.h index fb66c2c..b8a6e39 100644 --- a/common/typeindex.h +++ b/common/typeindex.h @@ -32,14 +32,14 @@ public: template void addProperty(const QByteArray &property); - void add(const QByteArray &identifier, const Akonadi2::ApplicationDomain::BufferAdaptor &bufferAdaptor, Akonadi2::Storage::Transaction &transaction); - void remove(const QByteArray &identifier, const Akonadi2::ApplicationDomain::BufferAdaptor &bufferAdaptor, Akonadi2::Storage::Transaction &transaction); + void add(const QByteArray &identifier, const Sink::ApplicationDomain::BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction); + void remove(const QByteArray &identifier, const Sink::ApplicationDomain::BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction); - ResultSet query(const Akonadi2::Query &query, QSet &appliedFilters, Akonadi2::Storage::Transaction &transaction); + ResultSet query(const Sink::Query &query, QSet &appliedFilters, Sink::Storage::Transaction &transaction); private: QByteArray mType; QByteArrayList mProperties; - QHash > mIndexer; + QHash > mIndexer; }; -- cgit v1.2.3