diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-07-07 03:22:23 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-07-07 03:22:23 +0200 |
commit | 61ab9866fa8ea5e26e5ce7d7cc265f5d8d65b277 (patch) | |
tree | d7f498ad2e3f4082fdeb67ffe7f91150e3b1a668 | |
parent | 9e967283190d36510fbcf73a79cc239dc696ec85 (diff) | |
download | sink-61ab9866fa8ea5e26e5ce7d7cc265f5d8d65b277.tar.gz sink-61ab9866fa8ea5e26e5ce7d7cc265f5d8d65b277.zip |
Pass instanceIdentifier to facade
-rw-r--r-- | common/clientapi.h | 16 | ||||
-rw-r--r-- | examples/dummyresource/facade.cpp | 4 | ||||
-rw-r--r-- | examples/dummyresource/facade.h | 2 | ||||
-rw-r--r-- | tests/clientapitest.cpp | 6 |
4 files changed, 14 insertions, 14 deletions
diff --git a/common/clientapi.h b/common/clientapi.h index 748baa6..2d926fd 100644 --- a/common/clientapi.h +++ b/common/clientapi.h | |||
@@ -108,7 +108,7 @@ public: | |||
108 | 108 | ||
109 | class FacadeFactory { | 109 | class FacadeFactory { |
110 | public: | 110 | public: |
111 | typedef std::function<std::shared_ptr<void>()> FactoryFunction; | 111 | typedef std::function<std::shared_ptr<void>(const QByteArray &)> FactoryFunction; |
112 | 112 | ||
113 | //FIXME: proper singleton implementation | 113 | //FIXME: proper singleton implementation |
114 | static FacadeFactory &instance() | 114 | static FacadeFactory &instance() |
@@ -126,7 +126,7 @@ public: | |||
126 | void registerFacade(const QByteArray &resource) | 126 | void registerFacade(const QByteArray &resource) |
127 | { | 127 | { |
128 | const QByteArray typeName = ApplicationDomain::getTypeName<DomainType>(); | 128 | const QByteArray typeName = ApplicationDomain::getTypeName<DomainType>(); |
129 | mFacadeRegistry.insert(key(resource, typeName), [](){ return std::shared_ptr<Facade>(new Facade); }); | 129 | mFacadeRegistry.insert(key(resource, typeName), [](const QByteArray &instanceIdentifier){ return std::make_shared<Facade>(instanceIdentifier); }); |
130 | } | 130 | } |
131 | 131 | ||
132 | /* | 132 | /* |
@@ -152,11 +152,11 @@ public: | |||
152 | } | 152 | } |
153 | 153 | ||
154 | template<class DomainType> | 154 | template<class DomainType> |
155 | std::shared_ptr<StoreFacade<DomainType> > getFacade(const QByteArray &resource) | 155 | std::shared_ptr<StoreFacade<DomainType> > getFacade(const QByteArray &resource, const QByteArray &instanceIdentifier) |
156 | { | 156 | { |
157 | const QByteArray typeName = ApplicationDomain::getTypeName<DomainType>(); | 157 | const QByteArray typeName = ApplicationDomain::getTypeName<DomainType>(); |
158 | if (auto factoryFunction = mFacadeRegistry.value(key(resource, typeName))) { | 158 | if (auto factoryFunction = mFacadeRegistry.value(key(resource, typeName))) { |
159 | return std::static_pointer_cast<StoreFacade<DomainType> >(factoryFunction()); | 159 | return std::static_pointer_cast<StoreFacade<DomainType> >(factoryFunction(instanceIdentifier)); |
160 | } | 160 | } |
161 | qWarning() << "Failed to find facade for resource: " << resource << " and type: " << typeName; | 161 | qWarning() << "Failed to find facade for resource: " << resource << " and type: " << typeName; |
162 | return std::shared_ptr<StoreFacade<DomainType> >(); | 162 | return std::shared_ptr<StoreFacade<DomainType> >(); |
@@ -199,7 +199,7 @@ public: | |||
199 | KAsync::iterate(query.resources) | 199 | KAsync::iterate(query.resources) |
200 | .template each<void, QByteArray>([query, resultSet](const QByteArray &resource, KAsync::Future<void> &future) { | 200 | .template each<void, QByteArray>([query, resultSet](const QByteArray &resource, KAsync::Future<void> &future) { |
201 | //TODO pass resource identifier to factory | 201 | //TODO pass resource identifier to factory |
202 | auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceName(resource)); | 202 | auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceName(resource), resource); |
203 | if (facade) { | 203 | if (facade) { |
204 | facade->load(query, resultSet).template then<void>([&future](){future.setFinished();}).exec(); | 204 | facade->load(query, resultSet).template then<void>([&future](){future.setFinished();}).exec(); |
205 | //Keep the facade alive for the lifetime of the resultSet. | 205 | //Keep the facade alive for the lifetime of the resultSet. |
@@ -244,7 +244,7 @@ public: | |||
244 | template <class DomainType> | 244 | template <class DomainType> |
245 | static void create(const DomainType &domainObject, const QByteArray &resourceIdentifier) { | 245 | static void create(const DomainType &domainObject, const QByteArray &resourceIdentifier) { |
246 | //Potentially move to separate thread as well | 246 | //Potentially move to separate thread as well |
247 | auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceName(resourceIdentifier)); | 247 | auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceName(resourceIdentifier), resourceIdentifier); |
248 | facade->create(domainObject).exec().waitForFinished(); | 248 | facade->create(domainObject).exec().waitForFinished(); |
249 | //TODO return job? | 249 | //TODO return job? |
250 | } | 250 | } |
@@ -257,7 +257,7 @@ public: | |||
257 | template <class DomainType> | 257 | template <class DomainType> |
258 | static void modify(const DomainType &domainObject, const QByteArray &resourceIdentifier) { | 258 | static void modify(const DomainType &domainObject, const QByteArray &resourceIdentifier) { |
259 | //Potentially move to separate thread as well | 259 | //Potentially move to separate thread as well |
260 | auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceName(resourceIdentifier)); | 260 | auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceName(resourceIdentifier), resourceIdentifier); |
261 | facade->modify(domainObject).exec().waitForFinished(); | 261 | facade->modify(domainObject).exec().waitForFinished(); |
262 | //TODO return job? | 262 | //TODO return job? |
263 | } | 263 | } |
@@ -268,7 +268,7 @@ public: | |||
268 | template <class DomainType> | 268 | template <class DomainType> |
269 | static void remove(const DomainType &domainObject, const QByteArray &resourceIdentifier) { | 269 | static void remove(const DomainType &domainObject, const QByteArray &resourceIdentifier) { |
270 | //Potentially move to separate thread as well | 270 | //Potentially move to separate thread as well |
271 | auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceName(resourceIdentifier)); | 271 | auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceName(resourceIdentifier), resourceIdentifier); |
272 | facade->remove(domainObject).exec().waitForFinished(); | 272 | facade->remove(domainObject).exec().waitForFinished(); |
273 | //TODO return job? | 273 | //TODO return job? |
274 | } | 274 | } |
diff --git a/examples/dummyresource/facade.cpp b/examples/dummyresource/facade.cpp index d6e9286..d20d12d 100644 --- a/examples/dummyresource/facade.cpp +++ b/examples/dummyresource/facade.cpp | |||
@@ -21,8 +21,8 @@ | |||
21 | 21 | ||
22 | #include "domainadaptor.h" | 22 | #include "domainadaptor.h" |
23 | 23 | ||
24 | DummyResourceFacade::DummyResourceFacade() | 24 | DummyResourceFacade::DummyResourceFacade(const QByteArray &instanceIdentifier) |
25 | : Akonadi2::GenericFacade<Akonadi2::ApplicationDomain::Event>("org.kde.dummy.instance1", QSharedPointer<DummyEventAdaptorFactory>::create()) | 25 | : Akonadi2::GenericFacade<Akonadi2::ApplicationDomain::Event>(instanceIdentifier, QSharedPointer<DummyEventAdaptorFactory>::create()) |
26 | { | 26 | { |
27 | } | 27 | } |
28 | 28 | ||
diff --git a/examples/dummyresource/facade.h b/examples/dummyresource/facade.h index 441dc38..dde0dc2 100644 --- a/examples/dummyresource/facade.h +++ b/examples/dummyresource/facade.h | |||
@@ -25,6 +25,6 @@ | |||
25 | class DummyResourceFacade : public Akonadi2::GenericFacade<Akonadi2::ApplicationDomain::Event> | 25 | class DummyResourceFacade : public Akonadi2::GenericFacade<Akonadi2::ApplicationDomain::Event> |
26 | { | 26 | { |
27 | public: | 27 | public: |
28 | DummyResourceFacade(); | 28 | DummyResourceFacade(const QByteArray &instanceIdentifier); |
29 | virtual ~DummyResourceFacade(); | 29 | virtual ~DummyResourceFacade(); |
30 | }; | 30 | }; |
diff --git a/tests/clientapitest.cpp b/tests/clientapitest.cpp index 081e6ad..a874dd7 100644 --- a/tests/clientapitest.cpp +++ b/tests/clientapitest.cpp | |||
@@ -110,7 +110,7 @@ private Q_SLOTS: | |||
110 | facade->results << QSharedPointer<Akonadi2::ApplicationDomain::Event>::create("resource", "id", 0, QSharedPointer<Akonadi2::ApplicationDomain::BufferAdaptor>()); | 110 | facade->results << QSharedPointer<Akonadi2::ApplicationDomain::Event>::create("resource", "id", 0, QSharedPointer<Akonadi2::ApplicationDomain::BufferAdaptor>()); |
111 | 111 | ||
112 | Akonadi2::FacadeFactory::instance().registerFacade<Akonadi2::ApplicationDomain::Event, DummyResourceFacade>("dummyresource", | 112 | Akonadi2::FacadeFactory::instance().registerFacade<Akonadi2::ApplicationDomain::Event, DummyResourceFacade>("dummyresource", |
113 | [facade]() { | 113 | [facade](const QByteArray &instanceIdentifier) { |
114 | return facade; | 114 | return facade; |
115 | } | 115 | } |
116 | ); | 116 | ); |
@@ -130,7 +130,7 @@ private Q_SLOTS: | |||
130 | facade->results << QSharedPointer<Akonadi2::ApplicationDomain::Event>::create("resource", "id", 0, QSharedPointer<Akonadi2::ApplicationDomain::BufferAdaptor>()); | 130 | facade->results << QSharedPointer<Akonadi2::ApplicationDomain::Event>::create("resource", "id", 0, QSharedPointer<Akonadi2::ApplicationDomain::BufferAdaptor>()); |
131 | 131 | ||
132 | Akonadi2::FacadeFactory::instance().registerFacade<Akonadi2::ApplicationDomain::Event, DummyResourceFacade>("dummyresource", | 132 | Akonadi2::FacadeFactory::instance().registerFacade<Akonadi2::ApplicationDomain::Event, DummyResourceFacade>("dummyresource", |
133 | [facade](){ | 133 | [facade](const QByteArray &instanceIdentifier){ |
134 | return facade; | 134 | return facade; |
135 | } | 135 | } |
136 | ); | 136 | ); |
@@ -156,7 +156,7 @@ private Q_SLOTS: | |||
156 | facade->results << QSharedPointer<Akonadi2::ApplicationDomain::Event>::create("resource", "id", 0, QSharedPointer<Akonadi2::ApplicationDomain::BufferAdaptor>()); | 156 | facade->results << QSharedPointer<Akonadi2::ApplicationDomain::Event>::create("resource", "id", 0, QSharedPointer<Akonadi2::ApplicationDomain::BufferAdaptor>()); |
157 | 157 | ||
158 | Akonadi2::FacadeFactory::instance().registerFacade<Akonadi2::ApplicationDomain::Event, DummyResourceFacade>("dummyresource", | 158 | Akonadi2::FacadeFactory::instance().registerFacade<Akonadi2::ApplicationDomain::Event, DummyResourceFacade>("dummyresource", |
159 | [facade](){ | 159 | [facade](const QByteArray &instanceIdentifier){ |
160 | return facade; | 160 | return facade; |
161 | } | 161 | } |
162 | ); | 162 | ); |