From 63919d3040295415306267df7b66e7a5e2c9395f Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Mon, 8 Jun 2015 10:47:57 +0200 Subject: Differentiate between resource name and instance identifier --- common/clientapi.h | 15 +++++++++++---- common/domain/event.cpp | 4 ++-- common/resourceaccess.cpp | 29 +++++++++++++++++++---------- 3 files changed, 32 insertions(+), 16 deletions(-) (limited to 'common') diff --git a/common/clientapi.h b/common/clientapi.h index 38ec1ee..4948c59 100644 --- a/common/clientapi.h +++ b/common/clientapi.h @@ -193,6 +193,13 @@ public: return QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/akonadi2/storage"; } + static QByteArray resourceName(const QByteArray &instanceIdentifier) + { + auto split = instanceIdentifier.split('.'); + split.removeLast(); + return split.join('.'); + } + /** * Asynchronusly load a dataset */ @@ -209,7 +216,7 @@ public: KAsync::iterate(query.resources) .template each([query, resultSet](const QByteArray &resource, KAsync::Future &future) { //TODO pass resource identifier to factory - auto facade = FacadeFactory::instance().getFacade(resource); + auto facade = FacadeFactory::instance().getFacade(resourceName(resource)); if (facade) { facade->load(query, resultSet).template then([&future](){future.setFinished();}).exec(); //Keep the facade alive for the lifetime of the resultSet. @@ -254,7 +261,7 @@ public: template static void create(const DomainType &domainObject, const QByteArray &resourceIdentifier) { //Potentially move to separate thread as well - auto facade = FacadeFactory::instance().getFacade(resourceIdentifier); + auto facade = FacadeFactory::instance().getFacade(resourceName(resourceIdentifier)); facade->create(domainObject).exec().waitForFinished(); //TODO return job? } @@ -267,7 +274,7 @@ public: template static void modify(const DomainType &domainObject, const QByteArray &resourceIdentifier) { //Potentially move to separate thread as well - auto facade = FacadeFactory::instance().getFacade(resourceIdentifier); + auto facade = FacadeFactory::instance().getFacade(resourceName(resourceIdentifier)); facade->modify(domainObject).exec().waitForFinished(); //TODO return job? } @@ -278,7 +285,7 @@ public: template static void remove(const DomainType &domainObject, const QByteArray &resourceIdentifier) { //Potentially move to separate thread as well - auto facade = FacadeFactory::instance().getFacade(resourceIdentifier); + auto facade = FacadeFactory::instance().getFacade(resourceName(resourceIdentifier)); facade->remove(domainObject).exec().waitForFinished(); //TODO return job? } diff --git a/common/domain/event.cpp b/common/domain/event.cpp index c435c6b..08ce698 100644 --- a/common/domain/event.cpp +++ b/common/domain/event.cpp @@ -36,7 +36,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::Store::storageLocation(), resourceInstanceIdentifier + ".index.uid", Akonadi2::Storage::ReadOnly); uidIndex.lookup(query.propertyFilter.value("uid").toByteArray(), [&](const QByteArray &value) { keys << value; }, @@ -50,7 +50,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::Store::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/resourceaccess.cpp b/common/resourceaccess.cpp index feffcf4..249dd55 100644 --- a/common/resourceaccess.cpp +++ b/common/resourceaccess.cpp @@ -69,10 +69,11 @@ public: class ResourceAccess::Private { public: - Private(const QByteArray &name, ResourceAccess *ra); + Private(const QByteArray &name, const QByteArray &instanceIdentifier, ResourceAccess *ra); KAsync::Job tryToConnect(); KAsync::Job initializeSocket(); QByteArray resourceName; + QByteArray resourceInstanceIdentifier; QSharedPointer socket; QByteArray partialMessageBuffer; flatbuffers::FlatBufferBuilder fbb; @@ -82,8 +83,9 @@ public: uint messageId; }; -ResourceAccess::Private::Private(const QByteArray &name, ResourceAccess *q) +ResourceAccess::Private::Private(const QByteArray &name, const QByteArray &instanceIdentifier, ResourceAccess *q) : resourceName(name), + resourceInstanceIdentifier(instanceIdentifier), messageId(0) { } @@ -118,7 +120,7 @@ KAsync::Job ResourceAccess::Private::tryToConnect() [this](KAsync::Future &future) { Trace() << "Loop"; KAsync::wait(50) - .then(connectToServer(resourceName)) + .then(connectToServer(resourceInstanceIdentifier)) .then >([this, &future](const QSharedPointer &s) { Q_ASSERT(s); socket = s; @@ -134,7 +136,7 @@ KAsync::Job ResourceAccess::Private::initializeSocket() { return KAsync::start([this](KAsync::Future &future) { Trace() << "Trying to connect"; - connectToServer(resourceName).then >([this, &future](const QSharedPointer &s) { + connectToServer(resourceInstanceIdentifier).then >([this, &future](const QSharedPointer &s) { Trace() << "Connected to resource, without having to start it."; Q_ASSERT(s); socket = s; @@ -144,7 +146,7 @@ KAsync::Job ResourceAccess::Private::initializeSocket() Trace() << "Failed to connect, starting resource"; //We failed to connect, so let's start the resource QStringList args; - args << resourceName; + args << resourceInstanceIdentifier; qint64 pid = 0; if (QProcess::startDetached("akonadi2_synchronizer", args, QDir::homePath(), &pid)) { Trace() << "Started resource " << pid; @@ -159,9 +161,16 @@ KAsync::Job ResourceAccess::Private::initializeSocket() }); } -ResourceAccess::ResourceAccess(const QByteArray &resourceName, QObject *parent) +static QByteArray getResourceName(const QByteArray &instanceIdentifier) +{ + auto split = instanceIdentifier.split('.'); + split.removeLast(); + return split.join('.'); +} + +ResourceAccess::ResourceAccess(const QByteArray &resourceInstanceIdentifier, QObject *parent) : QObject(parent), - d(new Private(resourceName, this)) + d(new Private(getResourceName(resourceInstanceIdentifier), resourceInstanceIdentifier, this)) { log("Starting access"); } @@ -316,7 +325,7 @@ void ResourceAccess::disconnected() void ResourceAccess::connectionError(QLocalSocket::LocalSocketError error) { if (error == QLocalSocket::PeerClosedError) { - Log(d->resourceName) << "The resource closed the connection."; + Log(d->resourceInstanceIdentifier) << "The resource closed the connection."; } else { Warning() << QString("Connection error: %1 : %2").arg(error).arg(d->socket->errorString()); } @@ -379,7 +388,7 @@ bool ResourceAccess::processMessageBuffer() auto buffer = GetNotification(d->partialMessageBuffer.constData() + headerSize); switch (buffer->type()) { case Akonadi2::NotificationType::NotificationType_Shutdown: - Log(d->resourceName) << "Received shutdown notification."; + Log(d->resourceInstanceIdentifier) << "Received shutdown notification."; close(); break; default: @@ -406,7 +415,7 @@ void ResourceAccess::callCallbacks(int id) void ResourceAccess::log(const QString &message) { - Log(d->resourceName) << this << message; + Log(d->resourceInstanceIdentifier) << this << message; } } -- cgit v1.2.3