From b6d5d206de4d02149c6530236154283bf834087a Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Thu, 13 Aug 2015 01:27:21 +0200 Subject: Untangled the include dependencies a bit. We no longer depend on clientapi.h from everywhere. --- common/CMakeLists.txt | 1 + common/clientapi.cpp | 1 + common/clientapi.h | 50 +++---------------------------------- common/definitions.cpp | 38 ++++++++++++++++++++++++++++ common/definitions.h | 29 ++++++++++++++++++++++ common/domain/event.cpp | 6 +++-- common/domain/event.h | 2 +- common/domainadaptor.h | 5 ++-- common/entitystorage.h | 7 +++--- common/facade.h | 3 ++- common/facadeinterface.h | 2 +- common/genericresource.cpp | 6 ++--- common/listener.cpp | 5 ++-- common/listener.h | 7 +++--- common/pipeline.cpp | 4 +-- common/pipeline.h | 1 - common/query.h | 62 ++++++++++++++++++++++++++++++++++++++++++++++ common/resource.cpp | 2 ++ common/resource.h | 2 +- common/resourcefacade.cpp | 1 + common/resourcefacade.h | 9 ++++++- common/resultprovider.h | 4 ++- common/synclistresult.h | 7 +++--- 23 files changed, 179 insertions(+), 75 deletions(-) create mode 100644 common/definitions.cpp create mode 100644 common/definitions.h create mode 100644 common/query.h (limited to 'common') diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 7778955..2f779b5 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -11,6 +11,7 @@ else (STORAGE_unqlite) endif (STORAGE_unqlite) set(command_SRCS + definitions.cpp log.cpp entitybuffer.cpp entitystorage.cpp diff --git a/common/clientapi.cpp b/common/clientapi.cpp index 8bb244c..5edab97 100644 --- a/common/clientapi.cpp +++ b/common/clientapi.cpp @@ -4,6 +4,7 @@ #include "commands.h" #include "resourcefacade.h" #include "log.h" +#include "definitions.h" #include #include diff --git a/common/clientapi.h b/common/clientapi.h index 6294863..04433f8 100644 --- a/common/clientapi.h +++ b/common/clientapi.h @@ -21,22 +21,21 @@ #pragma once #include -#include #include -#include -#include #include #include #include #include +#include "query.h" #include "threadboundary.h" #include "resultprovider.h" #include "domain/applicationdomaintype.h" #include "resourceconfig.h" #include "facadefactory.h" #include "log.h" +#include "definitions.h" namespace async { //This should abstract if we execute from eventloop or in thread. @@ -48,42 +47,6 @@ namespace Akonadi2 { using namespace async; -/** - * A query that matches a set of objects - * - * The query will have to be updated regularly similary to the domain objects. - * It probably also makes sense to have a domain specific part of the query, - * such as what properties we're interested in (necessary information for on-demand - * loading of data). - * - * The query defines: - * * what resources to search - * * filters on various properties (parent collection, startDate range, ....) - * * properties we need (for on-demand querying) - * - * syncOnDemand: Execute a source sync before executing the query - * processAll: Ensure all local messages are processed before querying to guarantee an up-to date dataset. - */ -class Query -{ -public: - Query() : syncOnDemand(true), processAll(false), liveQuery(false) {} - //Could also be a propertyFilter - QByteArrayList resources; - //Could also be a propertyFilter - QByteArrayList ids; - //Filters to apply - QHash propertyFilter; - //Properties to retrieve - QSet requestedProperties; - bool syncOnDemand; - bool processAll; - //If live query is false, this query will not continuously be updated - bool liveQuery; -}; - - - /** * Store interface used in the client API. */ @@ -91,17 +54,12 @@ class Store { public: static QString storageLocation() { - return QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/akonadi2/storage"; + return Akonadi2::storageLocation(); } static QByteArray resourceName(const QByteArray &instanceIdentifier) { - auto split = instanceIdentifier.split('.'); - if (split.size() <= 1) { - return instanceIdentifier; - } - split.removeLast(); - return split.join('.'); + return Akonadi2::resourceName(instanceIdentifier); } static QList getResources(const QList &resourceFilter) diff --git a/common/definitions.cpp b/common/definitions.cpp new file mode 100644 index 0000000..33512ad --- /dev/null +++ b/common/definitions.cpp @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2014 Christian Mollekopf + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) version 3, or any + * later version accepted by the membership of KDE e.V. (or its + * successor approved by the membership of KDE e.V.), which shall + * act as a proxy defined in Section 6 of version 3 of the license. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + */ + +#include "definitions.h" + +#include + +QString Akonadi2::storageLocation() +{ + return QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/akonadi2/storage"; +} + +QByteArray Akonadi2::resourceName(const QByteArray &instanceIdentifier) +{ + auto split = instanceIdentifier.split('.'); + if (split.size() <= 1) { + return instanceIdentifier; + } + split.removeLast(); + return split.join('.'); +} diff --git a/common/definitions.h b/common/definitions.h new file mode 100644 index 0000000..333d106 --- /dev/null +++ b/common/definitions.h @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2014 Christian Mollekopf + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) version 3, or any + * later version accepted by the membership of KDE e.V. (or its + * successor approved by the membership of KDE e.V.), which shall + * act as a proxy defined in Section 6 of version 3 of the license. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + */ + +#pragma once + +#include +#include + +namespace Akonadi2 { + QString storageLocation(); + QByteArray resourceName(const QByteArray &instanceIdentifier); +} diff --git a/common/domain/event.cpp b/common/domain/event.cpp index d86ac16..15f5d11 100644 --- a/common/domain/event.cpp +++ b/common/domain/event.cpp @@ -27,6 +27,8 @@ #include "../storage.h" #include "../log.h" #include "../propertymapper.h" +#include "../query.h" +#include "../definitions.h" #include "event_generated.h" @@ -36,7 +38,7 @@ ResultSet TypeImplementation::queryIndexes(const Akonadi2::Query &query, { QVector keys; if (query.propertyFilter.contains("uid")) { - Index uidIndex(Akonadi2::Store::storageLocation(), resourceInstanceIdentifier + ".index.uid", Akonadi2::Storage::ReadOnly); + Index uidIndex(Akonadi2::storageLocation(), resourceInstanceIdentifier + ".index.uid", Akonadi2::Storage::ReadOnly); uidIndex.lookup(query.propertyFilter.value("uid").toByteArray(), [&](const QByteArray &value) { keys << value; }, @@ -50,7 +52,7 @@ ResultSet TypeImplementation::queryIndexes(const Akonadi2::Query &query, void TypeImplementation::index(const Event &type) { - Index uidIndex(Akonadi2::Store::storageLocation(), type.resourceInstanceIdentifier() + ".index.uid", Akonadi2::Storage::ReadWrite); + Index uidIndex(Akonadi2::storageLocation(), type.resourceInstanceIdentifier() + ".index.uid", Akonadi2::Storage::ReadWrite); const auto uid = type.getProperty("uid"); if (uid.isValid()) { uidIndex.add(uid.toByteArray(), type.identifier()); diff --git a/common/domain/event.h b/common/domain/event.h index 38020f8..13cfc6e 100644 --- a/common/domain/event.h +++ b/common/domain/event.h @@ -18,7 +18,7 @@ */ #pragma once -#include "../clientapi.h" +#include "applicationdomaintype.h" class ResultSet; class QByteArray; diff --git a/common/domainadaptor.h b/common/domainadaptor.h index 7e9b171..f9dcc79 100644 --- a/common/domainadaptor.h +++ b/common/domainadaptor.h @@ -19,17 +19,16 @@ #pragma once -#include "entity_generated.h" #include #include #include -#include "clientapi.h" //for domain parts +#include "domain/applicationdomaintype.h" +#include "domain/event.h" #include "entity_generated.h" #include "metadata_generated.h" #include "entitybuffer.h" #include "propertymapper.h" -#include "domain/event.h" #include "log.h" /** diff --git a/common/entitystorage.h b/common/entitystorage.h index 516a889..2fce880 100644 --- a/common/entitystorage.h +++ b/common/entitystorage.h @@ -18,15 +18,16 @@ */ #pragma once -#include "clientapi.h" - #include +#include "query.h" #include "domainadaptor.h" #include "entitybuffer.h" #include "log.h" #include "storage.h" #include "resultset.h" +#include "resultprovider.h" +#include "definitions.h" /** * Wraps storage, entity adaptor factory and indexes into one. @@ -85,7 +86,7 @@ public: virtual void read(const Akonadi2::Query &query, const QPair &revisionRange, const QSharedPointer > &resultProvider) { - Akonadi2::Storage storage(Akonadi2::Store::storageLocation(), mResourceInstanceIdentifier); + Akonadi2::Storage storage(Akonadi2::storageLocation(), mResourceInstanceIdentifier); storage.setDefaultErrorHandler([](const Akonadi2::Storage::Error &error) { Warning() << "Error during query: " << error.store << error.message; }); diff --git a/common/facade.h b/common/facade.h index 1715a7f..be053f6 100644 --- a/common/facade.h +++ b/common/facade.h @@ -19,8 +19,9 @@ #pragma once -#include +#include "facadeinterface.h" +#include #include #include "resourceaccess.h" diff --git a/common/facadeinterface.h b/common/facadeinterface.h index a88c104..ac60ae4 100644 --- a/common/facadeinterface.h +++ b/common/facadeinterface.h @@ -45,7 +45,7 @@ public: virtual KAsync::Job create(const DomainType &domainObject) = 0; virtual KAsync::Job modify(const DomainType &domainObject) = 0; virtual KAsync::Job remove(const DomainType &domainObject) = 0; - virtual KAsync::Job load(const Query &query, const QSharedPointer > &resultProvider) = 0; + virtual KAsync::Job load(const Query &query, const QSharedPointer > &resultProvider) = 0; }; } diff --git a/common/genericresource.cpp b/common/genericresource.cpp index 734c1b5..a86b518 100644 --- a/common/genericresource.cpp +++ b/common/genericresource.cpp @@ -6,9 +6,9 @@ #include "createentity_generated.h" #include "domainadaptor.h" #include "commands.h" -#include "clientapi.h" #include "index.h" #include "log.h" +#include "definitions.h" using namespace Akonadi2; @@ -154,8 +154,8 @@ private: GenericResource::GenericResource(const QByteArray &resourceInstanceIdentifier, const QSharedPointer &pipeline) : Akonadi2::Resource(), - mUserQueue(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/akonadi2/storage", resourceInstanceIdentifier + ".userqueue"), - mSynchronizerQueue(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/akonadi2/storage", resourceInstanceIdentifier + ".synchronizerqueue"), + mUserQueue(Akonadi2::storageLocation(), resourceInstanceIdentifier + ".userqueue"), + mSynchronizerQueue(Akonadi2::storageLocation(), resourceInstanceIdentifier + ".synchronizerqueue"), mResourceInstanceIdentifier(resourceInstanceIdentifier), mPipeline(pipeline ? pipeline : QSharedPointer::create(resourceInstanceIdentifier)), mError(0) diff --git a/common/listener.cpp b/common/listener.cpp index 1159252..9773835 100644 --- a/common/listener.cpp +++ b/common/listener.cpp @@ -19,10 +19,10 @@ #include "listener.h" -#include "common/clientapi.h" #include "common/commands.h" #include "common/resource.h" #include "common/log.h" +#include "common/definitions.h" // commands #include "common/commandcompletion_generated.h" @@ -31,13 +31,14 @@ #include "common/synchronize_generated.h" #include "common/notification_generated.h" +#include #include #include Listener::Listener(const QByteArray &resourceInstanceIdentifier, QObject *parent) : QObject(parent), m_server(new QLocalServer(this)), - m_resourceName(Akonadi2::Store::resourceName(resourceInstanceIdentifier)), + m_resourceName(Akonadi2::resourceName(resourceInstanceIdentifier)), m_resourceInstanceIdentifier(resourceInstanceIdentifier), m_resource(0), m_clientBufferProcessesTimer(new QTimer(this)), diff --git a/common/listener.h b/common/listener.h index 2d69c35..30807d7 100644 --- a/common/listener.h +++ b/common/listener.h @@ -19,20 +19,19 @@ #pragma once -#include -#include #include +#include +#include #include -#include "common/pipeline.h" - namespace Akonadi2 { class Resource; } class QTimer; +class QLocalServer; class Client { diff --git a/common/pipeline.cpp b/common/pipeline.cpp index 0231631..207cc5e 100644 --- a/common/pipeline.cpp +++ b/common/pipeline.cpp @@ -21,7 +21,6 @@ #include "pipeline.h" #include -#include #include #include #include @@ -33,6 +32,7 @@ #include "entitybuffer.h" #include "log.h" #include "domain/applicationdomaintype.h" +#include "definitions.h" namespace Akonadi2 { @@ -41,7 +41,7 @@ class Pipeline::Private { public: Private(const QString &resourceName) - : storage(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/akonadi2/storage", resourceName, Storage::ReadWrite), + : storage(Akonadi2::storageLocation(), resourceName, Storage::ReadWrite), stepScheduled(false) { } diff --git a/common/pipeline.h b/common/pipeline.h index 9c3e7a1..1a33f9a 100644 --- a/common/pipeline.h +++ b/common/pipeline.h @@ -30,7 +30,6 @@ #include -#include "entity_generated.h" #include "domainadaptor.h" namespace Akonadi2 diff --git a/common/query.h b/common/query.h new file mode 100644 index 0000000..0cad9fb --- /dev/null +++ b/common/query.h @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2014 Christian Mollekopf + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) version 3, or any + * later version accepted by the membership of KDE e.V. (or its + * successor approved by the membership of KDE e.V.), which shall + * act as a proxy defined in Section 6 of version 3 of the license. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + */ +#pragma once + +#include +#include +#include + +namespace Akonadi2 { + +/** + * A query that matches a set of objects + * + * The query will have to be updated regularly similary to the domain objects. + * It probably also makes sense to have a domain specific part of the query, + * such as what properties we're interested in (necessary information for on-demand + * loading of data). + * + * The query defines: + * * what resources to search + * * filters on various properties (parent collection, startDate range, ....) + * * properties we need (for on-demand querying) + * + * syncOnDemand: Execute a source sync before executing the query + * processAll: Ensure all local messages are processed before querying to guarantee an up-to date dataset. + */ +class Query +{ +public: + Query() : syncOnDemand(true), processAll(false), liveQuery(false) {} + //Could also be a propertyFilter + QByteArrayList resources; + //Could also be a propertyFilter + QByteArrayList ids; + //Filters to apply + QHash propertyFilter; + //Properties to retrieve + QSet requestedProperties; + bool syncOnDemand; + bool processAll; + //If live query is false, this query will not continuously be updated + bool liveQuery; +}; + +} diff --git a/common/resource.cpp b/common/resource.cpp index 2a86df5..58ba82f 100644 --- a/common/resource.cpp +++ b/common/resource.cpp @@ -25,6 +25,8 @@ #include #include +#include "facadefactory.h" + namespace Akonadi2 { diff --git a/common/resource.h b/common/resource.h index a51e12d..6563c09 100644 --- a/common/resource.h +++ b/common/resource.h @@ -19,13 +19,13 @@ */ #include -#include #include namespace Akonadi2 { class Pipeline; +class FacadeFactory; /** * Resource interface diff --git a/common/resourcefacade.cpp b/common/resourcefacade.cpp index 9792934..54185f8 100644 --- a/common/resourcefacade.cpp +++ b/common/resourcefacade.cpp @@ -19,6 +19,7 @@ #include "resourcefacade.h" #include "resourceconfig.h" +#include "query.h" ResourceFacade::ResourceFacade(const QByteArray &) : Akonadi2::StoreFacade() diff --git a/common/resourcefacade.h b/common/resourcefacade.h index 2b36f21..437ff75 100644 --- a/common/resourcefacade.h +++ b/common/resourcefacade.h @@ -19,8 +19,15 @@ #pragma once -#include "common/clientapi.h" +#include "common/facadeinterface.h" + +#include #include "common/resultprovider.h" +#include "common/domain/applicationdomaintype.h" + +namespace Akonadi2 { + class Query; +} class ResourceFacade : public Akonadi2::StoreFacade { diff --git a/common/resultprovider.h b/common/resultprovider.h index a375815..841fd01 100644 --- a/common/resultprovider.h +++ b/common/resultprovider.h @@ -24,7 +24,9 @@ #include #include "threadboundary.h" -namespace async { +using namespace async; + +namespace Akonadi2 { /** * Query result set diff --git a/common/synclistresult.h b/common/synclistresult.h index 0a86f8c..865d3e0 100644 --- a/common/synclistresult.h +++ b/common/synclistresult.h @@ -3,7 +3,8 @@ #include #include #include -#include +#include +#include "resultprovider.h" namespace async { @@ -17,7 +18,7 @@ namespace async { template class SyncListResult : public QList { public: - SyncListResult(const QSharedPointer > &emitter) + SyncListResult(const QSharedPointer > &emitter) :QList(), mEmitter(emitter) { @@ -47,7 +48,7 @@ public: } private: - QSharedPointer > mEmitter; + QSharedPointer > mEmitter; std::function eventLoopAborter; }; -- cgit v1.2.3