diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-04-17 15:01:51 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-04-17 15:01:51 +0200 |
commit | bf75a2b6b184a3504cdee4b88a6db4a82c6da150 (patch) | |
tree | 841434e105e89e6a5ef1b6bbe3c1b43a5dd2e499 | |
parent | c3040251dd4d9e8d00cbccdeb693b11a72077c73 (diff) | |
download | sink-bf75a2b6b184a3504cdee4b88a6db4a82c6da150.tar.gz sink-bf75a2b6b184a3504cdee4b88a6db4a82c6da150.zip |
Don't encode the resource type into the identifier
-rw-r--r-- | common/definitions.cpp | 10 | ||||
-rw-r--r-- | common/definitions.h | 1 | ||||
-rw-r--r-- | common/facade.cpp | 3 | ||||
-rw-r--r-- | common/listener.cpp | 4 | ||||
-rw-r--r-- | common/listener.h | 2 | ||||
-rw-r--r-- | common/notifier.cpp | 4 | ||||
-rw-r--r-- | common/notifier.h | 2 | ||||
-rw-r--r-- | common/resourceaccess.cpp | 17 | ||||
-rw-r--r-- | common/resourceaccess.h | 4 | ||||
-rw-r--r-- | common/resourceconfig.cpp | 5 | ||||
-rw-r--r-- | common/resourceconfig.h | 1 | ||||
-rw-r--r-- | common/resourcecontrol.cpp | 9 | ||||
-rw-r--r-- | common/store.cpp | 34 | ||||
-rw-r--r-- | synchronizer/main.cpp | 5 | ||||
-rw-r--r-- | tests/dummyresourcebenchmark.cpp | 2 | ||||
-rw-r--r-- | tests/resourcecommunicationtest.cpp | 16 |
16 files changed, 57 insertions, 62 deletions
diff --git a/common/definitions.cpp b/common/definitions.cpp index 101279e..26e23ed 100644 --- a/common/definitions.cpp +++ b/common/definitions.cpp | |||
@@ -36,13 +36,3 @@ QString Sink::temporaryFileLocation() | |||
36 | dir.mkpath(path); | 36 | dir.mkpath(path); |
37 | return path; | 37 | return path; |
38 | } | 38 | } |
39 | |||
40 | QByteArray Sink::resourceName(const QByteArray &instanceIdentifier) | ||
41 | { | ||
42 | auto split = instanceIdentifier.split('.'); | ||
43 | if (split.size() <= 1) { | ||
44 | return instanceIdentifier; | ||
45 | } | ||
46 | split.removeLast(); | ||
47 | return split.join('.'); | ||
48 | } | ||
diff --git a/common/definitions.h b/common/definitions.h index a90b15a..6a6796e 100644 --- a/common/definitions.h +++ b/common/definitions.h | |||
@@ -27,5 +27,4 @@ | |||
27 | namespace Sink { | 27 | namespace Sink { |
28 | QString SINK_EXPORT storageLocation(); | 28 | QString SINK_EXPORT storageLocation(); |
29 | QString SINK_EXPORT temporaryFileLocation(); | 29 | QString SINK_EXPORT temporaryFileLocation(); |
30 | QByteArray SINK_EXPORT resourceName(const QByteArray &instanceIdentifier); | ||
31 | } | 30 | } |
diff --git a/common/facade.cpp b/common/facade.cpp index 803f85c..cdd06f9 100644 --- a/common/facade.cpp +++ b/common/facade.cpp | |||
@@ -26,6 +26,7 @@ | |||
26 | #include "domainadaptor.h" | 26 | #include "domainadaptor.h" |
27 | #include "queryrunner.h" | 27 | #include "queryrunner.h" |
28 | #include "bufferutils.h" | 28 | #include "bufferutils.h" |
29 | #include "resourceconfig.h" | ||
29 | 30 | ||
30 | using namespace Sink; | 31 | using namespace Sink; |
31 | 32 | ||
@@ -38,7 +39,7 @@ GenericFacade<DomainType>::GenericFacade( | |||
38 | : Sink::StoreFacade<DomainType>(), mResourceAccess(resourceAccess), mDomainTypeAdaptorFactory(adaptorFactory), mResourceInstanceIdentifier(resourceIdentifier) | 39 | : Sink::StoreFacade<DomainType>(), mResourceAccess(resourceAccess), mDomainTypeAdaptorFactory(adaptorFactory), mResourceInstanceIdentifier(resourceIdentifier) |
39 | { | 40 | { |
40 | if (!mResourceAccess) { | 41 | if (!mResourceAccess) { |
41 | mResourceAccess = ResourceAccessFactory::instance().getAccess(resourceIdentifier); | 42 | mResourceAccess = ResourceAccessFactory::instance().getAccess(resourceIdentifier, ResourceConfig::getResourceType(resourceIdentifier)); |
42 | } | 43 | } |
43 | } | 44 | } |
44 | 45 | ||
diff --git a/common/listener.cpp b/common/listener.cpp index 145267a..828a917 100644 --- a/common/listener.cpp +++ b/common/listener.cpp | |||
@@ -42,10 +42,10 @@ | |||
42 | #undef DEBUG_AREA | 42 | #undef DEBUG_AREA |
43 | #define DEBUG_AREA "resource.communication" | 43 | #define DEBUG_AREA "resource.communication" |
44 | 44 | ||
45 | Listener::Listener(const QByteArray &resourceInstanceIdentifier, QObject *parent) | 45 | Listener::Listener(const QByteArray &resourceInstanceIdentifier, const QByteArray &resourceType, QObject *parent) |
46 | : QObject(parent), | 46 | : QObject(parent), |
47 | m_server(new QLocalServer(this)), | 47 | m_server(new QLocalServer(this)), |
48 | m_resourceName(Sink::resourceName(resourceInstanceIdentifier)), | 48 | m_resourceName(resourceType), |
49 | m_resourceInstanceIdentifier(resourceInstanceIdentifier), | 49 | m_resourceInstanceIdentifier(resourceInstanceIdentifier), |
50 | m_resource(0), | 50 | m_resource(0), |
51 | m_clientBufferProcessesTimer(new QTimer(this)), | 51 | m_clientBufferProcessesTimer(new QTimer(this)), |
diff --git a/common/listener.h b/common/listener.h index aca7c50..cd1a7f6 100644 --- a/common/listener.h +++ b/common/listener.h | |||
@@ -56,7 +56,7 @@ class SINK_EXPORT Listener : public QObject | |||
56 | Q_OBJECT | 56 | Q_OBJECT |
57 | 57 | ||
58 | public: | 58 | public: |
59 | Listener(const QByteArray &resourceName, QObject *parent = 0); | 59 | Listener(const QByteArray &resourceName, const QByteArray &resourceType, QObject *parent = 0); |
60 | ~Listener(); | 60 | ~Listener(); |
61 | 61 | ||
62 | signals: | 62 | signals: |
diff --git a/common/notifier.cpp b/common/notifier.cpp index 25d0b85..94ac84e 100644 --- a/common/notifier.cpp +++ b/common/notifier.cpp | |||
@@ -48,9 +48,9 @@ Notifier::Notifier(const QSharedPointer<ResourceAccess> &resourceAccess) : d(new | |||
48 | d->resourceAccess << resourceAccess; | 48 | d->resourceAccess << resourceAccess; |
49 | } | 49 | } |
50 | 50 | ||
51 | Notifier::Notifier(const QByteArray &instanceIdentifier) : d(new Sink::Notifier::Private) | 51 | Notifier::Notifier(const QByteArray &instanceIdentifier, const QByteArray &resourceType) : d(new Sink::Notifier::Private) |
52 | { | 52 | { |
53 | auto resourceAccess = Sink::ResourceAccess::Ptr::create(instanceIdentifier); | 53 | auto resourceAccess = Sink::ResourceAccess::Ptr::create(instanceIdentifier, resourceType); |
54 | resourceAccess->open(); | 54 | resourceAccess->open(); |
55 | QObject::connect(resourceAccess.data(), &ResourceAccess::notification, d->context.data(), [this](const Notification ¬ification) { | 55 | QObject::connect(resourceAccess.data(), &ResourceAccess::notification, d->context.data(), [this](const Notification ¬ification) { |
56 | for (const auto &handler : d->handler) { | 56 | for (const auto &handler : d->handler) { |
diff --git a/common/notifier.h b/common/notifier.h index 9e75dde..3d61e95 100644 --- a/common/notifier.h +++ b/common/notifier.h | |||
@@ -36,7 +36,7 @@ class SINK_EXPORT Notifier | |||
36 | { | 36 | { |
37 | public: | 37 | public: |
38 | Notifier(const QSharedPointer<ResourceAccess> &resourceAccess); | 38 | Notifier(const QSharedPointer<ResourceAccess> &resourceAccess); |
39 | Notifier(const QByteArray &resourceInstanceIdentifier); | 39 | Notifier(const QByteArray &resourceInstanceIdentifier, const QByteArray &resourceType); |
40 | void registerHandler(std::function<void(const Notification &)>); | 40 | void registerHandler(std::function<void(const Notification &)>); |
41 | 41 | ||
42 | private: | 42 | private: |
diff --git a/common/resourceaccess.cpp b/common/resourceaccess.cpp index c8c8189..33820af 100644 --- a/common/resourceaccess.cpp +++ b/common/resourceaccess.cpp | |||
@@ -199,7 +199,7 @@ KAsync::Job<void> ResourceAccess::Private::initializeSocket() | |||
199 | TracePrivate() << "Failed to connect, starting resource"; | 199 | TracePrivate() << "Failed to connect, starting resource"; |
200 | // We failed to connect, so let's start the resource | 200 | // We failed to connect, so let's start the resource |
201 | QStringList args; | 201 | QStringList args; |
202 | args << resourceInstanceIdentifier; | 202 | args << resourceInstanceIdentifier << resourceName; |
203 | qint64 pid = 0; | 203 | qint64 pid = 0; |
204 | if (QProcess::startDetached("sink_synchronizer", args, QDir::homePath(), &pid)) { | 204 | if (QProcess::startDetached("sink_synchronizer", args, QDir::homePath(), &pid)) { |
205 | TracePrivate() << "Started resource " << pid; | 205 | TracePrivate() << "Started resource " << pid; |
@@ -218,15 +218,8 @@ KAsync::Job<void> ResourceAccess::Private::initializeSocket() | |||
218 | }); | 218 | }); |
219 | } | 219 | } |
220 | 220 | ||
221 | static QByteArray getResourceName(const QByteArray &instanceIdentifier) | 221 | ResourceAccess::ResourceAccess(const QByteArray &resourceInstanceIdentifier, const QByteArray &resourceType) |
222 | { | 222 | : ResourceAccessInterface(), d(new Private(resourceType, resourceInstanceIdentifier, this)) |
223 | auto split = instanceIdentifier.split('.'); | ||
224 | split.removeLast(); | ||
225 | return split.join('.'); | ||
226 | } | ||
227 | |||
228 | ResourceAccess::ResourceAccess(const QByteArray &resourceInstanceIdentifier) | ||
229 | : ResourceAccessInterface(), d(new Private(getResourceName(resourceInstanceIdentifier), resourceInstanceIdentifier, this)) | ||
230 | { | 223 | { |
231 | Log() << "Starting access"; | 224 | Log() << "Starting access"; |
232 | } | 225 | } |
@@ -593,7 +586,7 @@ ResourceAccessFactory &ResourceAccessFactory::instance() | |||
593 | return *instance; | 586 | return *instance; |
594 | } | 587 | } |
595 | 588 | ||
596 | Sink::ResourceAccess::Ptr ResourceAccessFactory::getAccess(const QByteArray &instanceIdentifier) | 589 | Sink::ResourceAccess::Ptr ResourceAccessFactory::getAccess(const QByteArray &instanceIdentifier, const QByteArray resourceType) |
597 | { | 590 | { |
598 | if (!mCache.contains(instanceIdentifier)) { | 591 | if (!mCache.contains(instanceIdentifier)) { |
599 | // Reuse the pointer if something else kept the resourceaccess alive | 592 | // Reuse the pointer if something else kept the resourceaccess alive |
@@ -605,7 +598,7 @@ Sink::ResourceAccess::Ptr ResourceAccessFactory::getAccess(const QByteArray &ins | |||
605 | } | 598 | } |
606 | if (!mCache.contains(instanceIdentifier)) { | 599 | if (!mCache.contains(instanceIdentifier)) { |
607 | // Create a new instance if necessary | 600 | // Create a new instance if necessary |
608 | auto sharedPointer = Sink::ResourceAccess::Ptr::create(instanceIdentifier); | 601 | auto sharedPointer = Sink::ResourceAccess::Ptr::create(instanceIdentifier, resourceType); |
609 | QObject::connect(sharedPointer.data(), &Sink::ResourceAccess::ready, sharedPointer.data(), [this, instanceIdentifier](bool ready) { | 602 | QObject::connect(sharedPointer.data(), &Sink::ResourceAccess::ready, sharedPointer.data(), [this, instanceIdentifier](bool ready) { |
610 | if (!ready) { | 603 | if (!ready) { |
611 | mCache.remove(instanceIdentifier); | 604 | mCache.remove(instanceIdentifier); |
diff --git a/common/resourceaccess.h b/common/resourceaccess.h index bd9af65..60f29e9 100644 --- a/common/resourceaccess.h +++ b/common/resourceaccess.h | |||
@@ -88,7 +88,7 @@ class SINK_EXPORT ResourceAccess : public ResourceAccessInterface | |||
88 | public: | 88 | public: |
89 | typedef QSharedPointer<ResourceAccess> Ptr; | 89 | typedef QSharedPointer<ResourceAccess> Ptr; |
90 | 90 | ||
91 | ResourceAccess(const QByteArray &resourceName); | 91 | ResourceAccess(const QByteArray &resourceInstanceIdentifier, const QByteArray &resourceType); |
92 | ~ResourceAccess(); | 92 | ~ResourceAccess(); |
93 | 93 | ||
94 | QByteArray resourceName() const; | 94 | QByteArray resourceName() const; |
@@ -141,7 +141,7 @@ class ResourceAccessFactory | |||
141 | { | 141 | { |
142 | public: | 142 | public: |
143 | static ResourceAccessFactory &instance(); | 143 | static ResourceAccessFactory &instance(); |
144 | Sink::ResourceAccess::Ptr getAccess(const QByteArray &instanceIdentifier); | 144 | Sink::ResourceAccess::Ptr getAccess(const QByteArray &instanceIdentifier, const QByteArray resourceType); |
145 | 145 | ||
146 | QHash<QByteArray, QWeakPointer<Sink::ResourceAccess>> mWeakCache; | 146 | QHash<QByteArray, QWeakPointer<Sink::ResourceAccess>> mWeakCache; |
147 | QHash<QByteArray, Sink::ResourceAccess::Ptr> mCache; | 147 | QHash<QByteArray, Sink::ResourceAccess::Ptr> mCache; |
diff --git a/common/resourceconfig.cpp b/common/resourceconfig.cpp index cfde4e9..a4e5fc5 100644 --- a/common/resourceconfig.cpp +++ b/common/resourceconfig.cpp | |||
@@ -71,6 +71,11 @@ QMap<QByteArray, QByteArray> ResourceConfig::getResources() | |||
71 | return resources; | 71 | return resources; |
72 | } | 72 | } |
73 | 73 | ||
74 | QByteArray ResourceConfig::getResourceType(const QByteArray &identifier) | ||
75 | { | ||
76 | return getResources().value(identifier); | ||
77 | } | ||
78 | |||
74 | void ResourceConfig::clear() | 79 | void ResourceConfig::clear() |
75 | { | 80 | { |
76 | auto settings = getConfig("resources"); | 81 | auto settings = getConfig("resources"); |
diff --git a/common/resourceconfig.h b/common/resourceconfig.h index 2108caa..fb74249 100644 --- a/common/resourceconfig.h +++ b/common/resourceconfig.h | |||
@@ -29,6 +29,7 @@ class SINK_EXPORT ResourceConfig | |||
29 | { | 29 | { |
30 | public: | 30 | public: |
31 | static QMap<QByteArray, QByteArray> getResources(); | 31 | static QMap<QByteArray, QByteArray> getResources(); |
32 | static QByteArray getResourceType(const QByteArray &identifier); | ||
32 | static QByteArray newIdentifier(const QByteArray &type); | 33 | static QByteArray newIdentifier(const QByteArray &type); |
33 | static void addResource(const QByteArray &identifier, const QByteArray &type); | 34 | static void addResource(const QByteArray &identifier, const QByteArray &type); |
34 | static void removeResource(const QByteArray &identifier); | 35 | static void removeResource(const QByteArray &identifier); |
diff --git a/common/resourcecontrol.cpp b/common/resourcecontrol.cpp index d8b0972..ac6ddba 100644 --- a/common/resourcecontrol.cpp +++ b/common/resourcecontrol.cpp | |||
@@ -25,6 +25,7 @@ | |||
25 | #include <functional> | 25 | #include <functional> |
26 | 26 | ||
27 | #include "resourceaccess.h" | 27 | #include "resourceaccess.h" |
28 | #include "resourceconfig.h" | ||
28 | #include "commands.h" | 29 | #include "commands.h" |
29 | #include "log.h" | 30 | #include "log.h" |
30 | #include "notifier.h" | 31 | #include "notifier.h" |
@@ -44,7 +45,7 @@ KAsync::Job<void> ResourceControl::shutdown(const QByteArray &identifier) | |||
44 | [identifier, time](QSharedPointer<QLocalSocket> socket, KAsync::Future<void> &future) { | 45 | [identifier, time](QSharedPointer<QLocalSocket> socket, KAsync::Future<void> &future) { |
45 | // We can't currently reuse the socket | 46 | // We can't currently reuse the socket |
46 | socket->close(); | 47 | socket->close(); |
47 | auto resourceAccess = ResourceAccessFactory::instance().getAccess(identifier); | 48 | auto resourceAccess = ResourceAccessFactory::instance().getAccess(identifier, ResourceConfig::getResourceType(identifier)); |
48 | resourceAccess->open(); | 49 | resourceAccess->open(); |
49 | resourceAccess->sendCommand(Sink::Commands::ShutdownCommand) | 50 | resourceAccess->sendCommand(Sink::Commands::ShutdownCommand) |
50 | .then<void>([&future, resourceAccess, time]() { | 51 | .then<void>([&future, resourceAccess, time]() { |
@@ -64,7 +65,7 @@ KAsync::Job<void> ResourceControl::start(const QByteArray &identifier) | |||
64 | Trace() << "start " << identifier; | 65 | Trace() << "start " << identifier; |
65 | auto time = QSharedPointer<QTime>::create(); | 66 | auto time = QSharedPointer<QTime>::create(); |
66 | time->start(); | 67 | time->start(); |
67 | auto resourceAccess = ResourceAccessFactory::instance().getAccess(identifier); | 68 | auto resourceAccess = ResourceAccessFactory::instance().getAccess(identifier, ResourceConfig::getResourceType(identifier)); |
68 | resourceAccess->open(); | 69 | resourceAccess->open(); |
69 | return resourceAccess->sendCommand(Sink::Commands::PingCommand).then<void>([resourceAccess, time]() { Trace() << "Start complete." << Log::TraceTime(time->elapsed()); }); | 70 | return resourceAccess->sendCommand(Sink::Commands::PingCommand).then<void>([resourceAccess, time]() { Trace() << "Start complete." << Log::TraceTime(time->elapsed()); }); |
70 | } | 71 | } |
@@ -75,7 +76,7 @@ KAsync::Job<void> ResourceControl::flushMessageQueue(const QByteArrayList &resou | |||
75 | return KAsync::iterate(resourceIdentifier) | 76 | return KAsync::iterate(resourceIdentifier) |
76 | .template each<void, QByteArray>([](const QByteArray &resource, KAsync::Future<void> &future) { | 77 | .template each<void, QByteArray>([](const QByteArray &resource, KAsync::Future<void> &future) { |
77 | Trace() << "Flushing message queue " << resource; | 78 | Trace() << "Flushing message queue " << resource; |
78 | auto resourceAccess = ResourceAccessFactory::instance().getAccess(resource); | 79 | auto resourceAccess = ResourceAccessFactory::instance().getAccess(resource, ResourceConfig::getResourceType(resource)); |
79 | resourceAccess->open(); | 80 | resourceAccess->open(); |
80 | resourceAccess->synchronizeResource(false, true).then<void>([&future, resourceAccess]() { future.setFinished(); }).exec(); | 81 | resourceAccess->synchronizeResource(false, true).then<void>([&future, resourceAccess]() { future.setFinished(); }).exec(); |
81 | }); | 82 | }); |
@@ -94,7 +95,7 @@ KAsync::Job<void> ResourceControl::inspect(const Inspection &inspectionCommand) | |||
94 | auto time = QSharedPointer<QTime>::create(); | 95 | auto time = QSharedPointer<QTime>::create(); |
95 | time->start(); | 96 | time->start(); |
96 | Trace() << "Sending inspection " << resource; | 97 | Trace() << "Sending inspection " << resource; |
97 | auto resourceAccess = ResourceAccessFactory::instance().getAccess(resource); | 98 | auto resourceAccess = ResourceAccessFactory::instance().getAccess(resource, ResourceConfig::getResourceType(resource)); |
98 | resourceAccess->open(); | 99 | resourceAccess->open(); |
99 | auto notifier = QSharedPointer<Sink::Notifier>::create(resourceAccess); | 100 | auto notifier = QSharedPointer<Sink::Notifier>::create(resourceAccess); |
100 | auto id = QUuid::createUuid().toByteArray(); | 101 | auto id = QUuid::createUuid().toByteArray(); |
diff --git a/common/store.cpp b/common/store.cpp index 0321583..b89e08c 100644 --- a/common/store.cpp +++ b/common/store.cpp | |||
@@ -51,23 +51,27 @@ QString Store::getTemporaryFilePath() | |||
51 | return Sink::temporaryFileLocation() + "/" + QUuid::createUuid().toString(); | 51 | return Sink::temporaryFileLocation() + "/" + QUuid::createUuid().toString(); |
52 | } | 52 | } |
53 | 53 | ||
54 | static QList<QByteArray> getResources(const QList<QByteArray> &resourceFilter, const QByteArray &type = QByteArray()) | 54 | /* |
55 | * Returns a map of resource instance identifiers and resource type | ||
56 | */ | ||
57 | static QMap<QByteArray, QByteArray> getResources(const QList<QByteArray> &resourceFilter, const QByteArray &type = QByteArray()) | ||
55 | { | 58 | { |
59 | QMap<QByteArray, QByteArray> resources; | ||
56 | // Return the global resource (signified by an empty name) for types that don't belong to a specific resource | 60 | // Return the global resource (signified by an empty name) for types that don't belong to a specific resource |
57 | if (type == "sinkresource" || type == "sinkaccount" || type == "identity") { | 61 | if (type == "sinkresource" || type == "sinkaccount" || type == "identity") { |
58 | return QList<QByteArray>() << ""; | 62 | resources.insert("", ""); |
63 | return resources; | ||
59 | } | 64 | } |
60 | QList<QByteArray> resources; | ||
61 | const auto configuredResources = ResourceConfig::getResources(); | 65 | const auto configuredResources = ResourceConfig::getResources(); |
62 | if (resourceFilter.isEmpty()) { | 66 | if (resourceFilter.isEmpty()) { |
63 | for (const auto &res : configuredResources.keys()) { | 67 | for (const auto &res : configuredResources.keys()) { |
64 | // TODO filter by entity type | 68 | // TODO filter by entity type |
65 | resources << res; | 69 | resources.insert(res, configuredResources.value(res)); |
66 | } | 70 | } |
67 | } else { | 71 | } else { |
68 | for (const auto &res : resourceFilter) { | 72 | for (const auto &res : resourceFilter) { |
69 | if (configuredResources.contains(res)) { | 73 | if (configuredResources.contains(res)) { |
70 | resources << res; | 74 | resources.insert(res, configuredResources.value(res)); |
71 | } else { | 75 | } else { |
72 | qWarning() << "Resource is not existing: " << res; | 76 | qWarning() << "Resource is not existing: " << res; |
73 | } | 77 | } |
@@ -99,16 +103,17 @@ QSharedPointer<QAbstractItemModel> Store::loadModel(Query query) | |||
99 | auto resources = getResources(query.resources, ApplicationDomain::getTypeName<DomainType>()); | 103 | auto resources = getResources(query.resources, ApplicationDomain::getTypeName<DomainType>()); |
100 | auto aggregatingEmitter = AggregatingResultEmitter<typename DomainType::Ptr>::Ptr::create(); | 104 | auto aggregatingEmitter = AggregatingResultEmitter<typename DomainType::Ptr>::Ptr::create(); |
101 | model->setEmitter(aggregatingEmitter); | 105 | model->setEmitter(aggregatingEmitter); |
102 | KAsync::iterate(resources) | 106 | KAsync::iterate(resources.keys()) |
103 | .template each<void, QByteArray>([query, aggregatingEmitter](const QByteArray &resource, KAsync::Future<void> &future) { | 107 | .template each<void, QByteArray>([query, aggregatingEmitter, resources](const QByteArray &resourceInstanceIdentifier, KAsync::Future<void> &future) { |
104 | auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceName(resource), resource); | 108 | const auto resourceType = resources.value(resourceInstanceIdentifier); |
109 | auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceType, resourceInstanceIdentifier); | ||
105 | if (facade) { | 110 | if (facade) { |
106 | Trace() << "Trying to fetch from resource " << resource; | 111 | Trace() << "Trying to fetch from resource " << resourceInstanceIdentifier; |
107 | auto result = facade->load(query); | 112 | auto result = facade->load(query); |
108 | aggregatingEmitter->addEmitter(result.second); | 113 | aggregatingEmitter->addEmitter(result.second); |
109 | result.first.template then<void>([&future]() { future.setFinished(); }).exec(); | 114 | result.first.template then<void>([&future]() { future.setFinished(); }).exec(); |
110 | } else { | 115 | } else { |
111 | Trace() << "Couldn' find a facade for " << resource; | 116 | Trace() << "Couldn' find a facade for " << resourceInstanceIdentifier; |
112 | // Ignore the error and carry on | 117 | // Ignore the error and carry on |
113 | future.setFinished(); | 118 | future.setFinished(); |
114 | } | 119 | } |
@@ -129,8 +134,7 @@ static std::shared_ptr<StoreFacade<DomainType>> getFacade(const QByteArray &reso | |||
129 | return facade; | 134 | return facade; |
130 | } | 135 | } |
131 | } | 136 | } |
132 | const auto resourceType = resourceName(resourceInstanceIdentifier); | 137 | if (auto facade = FacadeFactory::instance().getFacade<DomainType>(ResourceConfig::getResourceType(resourceInstanceIdentifier), resourceInstanceIdentifier)) { |
133 | if (auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceType, resourceInstanceIdentifier)) { | ||
134 | return facade; | 138 | return facade; |
135 | } | 139 | } |
136 | return std::make_shared<NullFacade<DomainType>>(); | 140 | return std::make_shared<NullFacade<DomainType>>(); |
@@ -168,7 +172,7 @@ KAsync::Job<void> Store::removeDataFromDisk(const QByteArray &identifier) | |||
168 | Trace() << "Remove data from disk " << identifier; | 172 | Trace() << "Remove data from disk " << identifier; |
169 | auto time = QSharedPointer<QTime>::create(); | 173 | auto time = QSharedPointer<QTime>::create(); |
170 | time->start(); | 174 | time->start(); |
171 | auto resourceAccess = ResourceAccessFactory::instance().getAccess(identifier); | 175 | auto resourceAccess = ResourceAccessFactory::instance().getAccess(identifier, ResourceConfig::getResourceType(identifier)); |
172 | resourceAccess->open(); | 176 | resourceAccess->open(); |
173 | return resourceAccess->sendCommand(Sink::Commands::RemoveFromDiskCommand) | 177 | return resourceAccess->sendCommand(Sink::Commands::RemoveFromDiskCommand) |
174 | .then<void>([resourceAccess, time]() { Trace() << "Remove from disk complete." << Log::TraceTime(time->elapsed()); }); | 178 | .then<void>([resourceAccess, time]() { Trace() << "Remove from disk complete." << Log::TraceTime(time->elapsed()); }); |
@@ -177,11 +181,11 @@ KAsync::Job<void> Store::removeDataFromDisk(const QByteArray &identifier) | |||
177 | KAsync::Job<void> Store::synchronize(const Sink::Query &query) | 181 | KAsync::Job<void> Store::synchronize(const Sink::Query &query) |
178 | { | 182 | { |
179 | Trace() << "synchronize" << query.resources; | 183 | Trace() << "synchronize" << query.resources; |
180 | auto resources = getResources(query.resources); | 184 | auto resources = getResources(query.resources).keys(); |
181 | return KAsync::iterate(resources) | 185 | return KAsync::iterate(resources) |
182 | .template each<void, QByteArray>([query](const QByteArray &resource, KAsync::Future<void> &future) { | 186 | .template each<void, QByteArray>([query](const QByteArray &resource, KAsync::Future<void> &future) { |
183 | Trace() << "Synchronizing " << resource; | 187 | Trace() << "Synchronizing " << resource; |
184 | auto resourceAccess = ResourceAccessFactory::instance().getAccess(resource); | 188 | auto resourceAccess = ResourceAccessFactory::instance().getAccess(resource, ResourceConfig::getResourceType(resource)); |
185 | resourceAccess->open(); | 189 | resourceAccess->open(); |
186 | resourceAccess->synchronizeResource(true, false).then<void>([&future, resourceAccess]() { future.setFinished(); }).exec(); | 190 | resourceAccess->synchronizeResource(true, false).then<void>([&future, resourceAccess]() { future.setFinished(); }).exec(); |
187 | }); | 191 | }); |
diff --git a/synchronizer/main.cpp b/synchronizer/main.cpp index 02cf365..179fbf5 100644 --- a/synchronizer/main.cpp +++ b/synchronizer/main.cpp | |||
@@ -65,12 +65,13 @@ int main(int argc, char *argv[]) | |||
65 | signal(SIGSEGV, crashHandler); | 65 | signal(SIGSEGV, crashHandler); |
66 | QCoreApplication app(argc, argv); | 66 | QCoreApplication app(argc, argv); |
67 | 67 | ||
68 | if (argc < 2) { | 68 | if (argc < 3) { |
69 | Warning() << "Not enough args passed, no resource loaded."; | 69 | Warning() << "Not enough args passed, no resource loaded."; |
70 | return app.exec(); | 70 | return app.exec(); |
71 | } | 71 | } |
72 | 72 | ||
73 | const QByteArray instanceIdentifier = argv[1]; | 73 | const QByteArray instanceIdentifier = argv[1]; |
74 | const QByteArray resourceType = argv[2]; | ||
74 | app.setApplicationName(instanceIdentifier); | 75 | app.setApplicationName(instanceIdentifier); |
75 | 76 | ||
76 | QLockFile lockfile(instanceIdentifier + ".lock"); | 77 | QLockFile lockfile(instanceIdentifier + ".lock"); |
@@ -80,7 +81,7 @@ int main(int argc, char *argv[]) | |||
80 | return -1; | 81 | return -1; |
81 | } | 82 | } |
82 | 83 | ||
83 | Listener *listener = new Listener(instanceIdentifier, &app); | 84 | Listener *listener = new Listener(instanceIdentifier, resourceType, &app); |
84 | 85 | ||
85 | QObject::connect(&app, &QCoreApplication::aboutToQuit, listener, &Listener::closeAllConnections); | 86 | QObject::connect(&app, &QCoreApplication::aboutToQuit, listener, &Listener::closeAllConnections); |
86 | QObject::connect(listener, &Listener::noClients, &app, &QCoreApplication::quit); | 87 | QObject::connect(listener, &Listener::noClients, &app, &QCoreApplication::quit); |
diff --git a/tests/dummyresourcebenchmark.cpp b/tests/dummyresourcebenchmark.cpp index 124abc1..1e71fc2 100644 --- a/tests/dummyresourcebenchmark.cpp +++ b/tests/dummyresourcebenchmark.cpp | |||
@@ -86,7 +86,7 @@ private slots: | |||
86 | QCOMPARE(event.getProperty("uid").toByteArray(), QByteArray("testuid")); | 86 | QCOMPARE(event.getProperty("uid").toByteArray(), QByteArray("testuid")); |
87 | event.setProperty("summary", "summaryValue"); | 87 | event.setProperty("summary", "summaryValue"); |
88 | 88 | ||
89 | auto notifier = QSharedPointer<Sink::Notifier>::create("org.kde.dummy.instance1"); | 89 | auto notifier = QSharedPointer<Sink::Notifier>::create("org.kde.dummy.instance1", "org.kde.dummy"); |
90 | bool gotNotification = false; | 90 | bool gotNotification = false; |
91 | int duration = 0; | 91 | int duration = 0; |
92 | notifier->registerHandler([&gotNotification, &duration, &time](const Sink::Notification ¬ification) { | 92 | notifier->registerHandler([&gotNotification, &duration, &time](const Sink::Notification ¬ification) { |
diff --git a/tests/resourcecommunicationtest.cpp b/tests/resourcecommunicationtest.cpp index 2daf372..2874457 100644 --- a/tests/resourcecommunicationtest.cpp +++ b/tests/resourcecommunicationtest.cpp | |||
@@ -15,8 +15,8 @@ private slots: | |||
15 | void testConnect() | 15 | void testConnect() |
16 | { | 16 | { |
17 | const QByteArray resourceIdentifier("test"); | 17 | const QByteArray resourceIdentifier("test"); |
18 | Listener listener(resourceIdentifier); | 18 | Listener listener(resourceIdentifier, ""); |
19 | Sink::ResourceAccess resourceAccess(resourceIdentifier); | 19 | Sink::ResourceAccess resourceAccess(resourceIdentifier, ""); |
20 | 20 | ||
21 | QSignalSpy spy(&resourceAccess, &Sink::ResourceAccess::ready); | 21 | QSignalSpy spy(&resourceAccess, &Sink::ResourceAccess::ready); |
22 | resourceAccess.open(); | 22 | resourceAccess.open(); |
@@ -26,8 +26,8 @@ private slots: | |||
26 | void testHandshake() | 26 | void testHandshake() |
27 | { | 27 | { |
28 | const QByteArray resourceIdentifier("test"); | 28 | const QByteArray resourceIdentifier("test"); |
29 | Listener listener(resourceIdentifier); | 29 | Listener listener(resourceIdentifier, ""); |
30 | Sink::ResourceAccess resourceAccess(resourceIdentifier); | 30 | Sink::ResourceAccess resourceAccess(resourceIdentifier, ""); |
31 | resourceAccess.open(); | 31 | resourceAccess.open(); |
32 | 32 | ||
33 | flatbuffers::FlatBufferBuilder fbb; | 33 | flatbuffers::FlatBufferBuilder fbb; |
@@ -42,8 +42,8 @@ private slots: | |||
42 | void testCommandLoop() | 42 | void testCommandLoop() |
43 | { | 43 | { |
44 | const QByteArray resourceIdentifier("test"); | 44 | const QByteArray resourceIdentifier("test"); |
45 | Listener listener(resourceIdentifier); | 45 | Listener listener(resourceIdentifier, ""); |
46 | Sink::ResourceAccess resourceAccess(resourceIdentifier); | 46 | Sink::ResourceAccess resourceAccess(resourceIdentifier, ""); |
47 | resourceAccess.open(); | 47 | resourceAccess.open(); |
48 | 48 | ||
49 | const int count = 500; | 49 | const int count = 500; |
@@ -67,8 +67,8 @@ private slots: | |||
67 | { | 67 | { |
68 | qDebug(); | 68 | qDebug(); |
69 | const QByteArray resourceIdentifier("test"); | 69 | const QByteArray resourceIdentifier("test"); |
70 | Listener listener(resourceIdentifier); | 70 | Listener listener(resourceIdentifier, ""); |
71 | Sink::ResourceAccess resourceAccess(resourceIdentifier); | 71 | Sink::ResourceAccess resourceAccess(resourceIdentifier, ""); |
72 | resourceAccess.open(); | 72 | resourceAccess.open(); |
73 | 73 | ||
74 | const int count = 10; | 74 | const int count = 10; |