From a547d10f3d36e7c820d913d22798ca051c6e3df3 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 28 Jul 2015 16:50:01 +0200 Subject: Allow to inject a fake ResourceInstance --- common/facade.h | 10 ++++++---- common/resourceaccess.cpp | 4 ++-- common/resourceaccess.h | 37 +++++++++++++++++++++++++------------ 3 files changed, 33 insertions(+), 18 deletions(-) (limited to 'common') diff --git a/common/facade.h b/common/facade.h index 254f671..52b2134 100644 --- a/common/facade.h +++ b/common/facade.h @@ -90,7 +90,6 @@ private: }; namespace Akonadi2 { - class ResourceAccess; /** * Default facade implementation for resources that are implemented in a separate process using the ResourceAccess class. * @@ -112,13 +111,16 @@ 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 > storage = QSharedPointer >()) + GenericFacade(const QByteArray &resourceIdentifier, const DomainTypeAdaptorFactoryInterface::Ptr &adaptorFactory = DomainTypeAdaptorFactoryInterface::Ptr(), const QSharedPointer > storage = QSharedPointer >(), const QSharedPointer resourceAccess = QSharedPointer()) : Akonadi2::StoreFacade(), - mResourceAccess(new ResourceAccess(resourceIdentifier)), + mResourceAccess(resourceAccess), mStorage(storage ? storage : QSharedPointer >::create(resourceIdentifier, adaptorFactory)), mDomainTypeAdaptorFactory(adaptorFactory), mResourceInstanceIdentifier(resourceIdentifier) { + if (!mResourceAccess) { + mResourceAccess = QSharedPointer::create(resourceIdentifier); + } } ~GenericFacade() @@ -269,7 +271,7 @@ private: protected: //TODO use one resource access instance per application & per resource - QSharedPointer mResourceAccess; + QSharedPointer mResourceAccess; QSharedPointer > mStorage; DomainTypeAdaptorFactoryInterface::Ptr mDomainTypeAdaptorFactory; QByteArray mResourceInstanceIdentifier; diff --git a/common/resourceaccess.cpp b/common/resourceaccess.cpp index bdebd56..a4a5795 100644 --- a/common/resourceaccess.cpp +++ b/common/resourceaccess.cpp @@ -208,8 +208,8 @@ static QByteArray getResourceName(const QByteArray &instanceIdentifier) return split.join('.'); } -ResourceAccess::ResourceAccess(const QByteArray &resourceInstanceIdentifier, QObject *parent) - : QObject(parent), +ResourceAccess::ResourceAccess(const QByteArray &resourceInstanceIdentifier) + : ResourceAccessInterface(), d(new Private(getResourceName(resourceInstanceIdentifier), resourceInstanceIdentifier, this)) { log("Starting access"); diff --git a/common/resourceaccess.h b/common/resourceaccess.h index e873d8e..55379f3 100644 --- a/common/resourceaccess.h +++ b/common/resourceaccess.h @@ -33,33 +33,46 @@ namespace Akonadi2 struct QueuedCommand; -class ResourceAccess : public QObject +class ResourceAccessInterface : public QObject { Q_OBJECT +public: + ResourceAccessInterface() {} + virtual ~ResourceAccessInterface() {} + virtual KAsync::Job sendCommand(int commandId) = 0; + virtual KAsync::Job sendCommand(int commandId, flatbuffers::FlatBufferBuilder &fbb) = 0; + virtual KAsync::Job synchronizeResource(bool remoteSync, bool localSync) = 0; + +Q_SIGNALS: + void ready(bool isReady); + void revisionChanged(unsigned long long revision); + +public Q_SLOTS: + virtual void open() = 0; + virtual void close() = 0; +}; +class ResourceAccess : public ResourceAccessInterface +{ + Q_OBJECT public: - ResourceAccess(const QByteArray &resourceName, QObject *parent = 0); + ResourceAccess(const QByteArray &resourceName); ~ResourceAccess(); QByteArray resourceName() const; bool isReady() const; - KAsync::Job sendCommand(int commandId); - KAsync::Job sendCommand(int commandId, flatbuffers::FlatBufferBuilder &fbb); - KAsync::Job synchronizeResource(bool remoteSync, bool localSync); + KAsync::Job sendCommand(int commandId) Q_DECL_OVERRIDE; + KAsync::Job sendCommand(int commandId, flatbuffers::FlatBufferBuilder &fbb) Q_DECL_OVERRIDE; + KAsync::Job synchronizeResource(bool remoteSync, bool localSync) Q_DECL_OVERRIDE; /** * Tries to connect to server, and returns a connected socket on success. */ static KAsync::Job > connectToServer(const QByteArray &identifier); public Q_SLOTS: - void open(); - void close(); - -Q_SIGNALS: - void ready(bool isReady); - void revisionChanged(unsigned long long revision); - void commandCompleted(); + void open() Q_DECL_OVERRIDE; + void close() Q_DECL_OVERRIDE; private Q_SLOTS: //TODO: move these to the Private class -- cgit v1.2.3