diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/clientapi.h | 59 | ||||
-rw-r--r-- | common/domain/applicationdomaintype.h | 7 | ||||
-rw-r--r-- | common/facadeinterface.h | 25 |
3 files changed, 61 insertions, 30 deletions
diff --git a/common/clientapi.h b/common/clientapi.h index e467b8f..6237cfb 100644 --- a/common/clientapi.h +++ b/common/clientapi.h | |||
@@ -134,20 +134,25 @@ public: | |||
134 | // { | 134 | // { |
135 | 135 | ||
136 | // } | 136 | // } |
137 | template <class DomainType> | ||
138 | static std::shared_ptr<StoreFacade<DomainType> > getFacade(const QByteArray &resourceInstanceIdentifier) | ||
139 | { | ||
140 | if (auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceName(resourceInstanceIdentifier), resourceInstanceIdentifier)) { | ||
141 | return facade; | ||
142 | } | ||
143 | return std::make_shared<NullFacade<DomainType> >(); | ||
144 | } | ||
137 | 145 | ||
138 | /** | 146 | /** |
139 | * Create a new entity. | 147 | * Create a new entity. |
140 | */ | 148 | */ |
141 | template <class DomainType> | 149 | template <class DomainType> |
142 | static KAsync::Job<void> create(const DomainType &domainObject, const QByteArray &resourceIdentifier) { | 150 | static KAsync::Job<void> create(const DomainType &domainObject) { |
143 | //Potentially move to separate thread as well | 151 | //Potentially move to separate thread as well |
144 | auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceName(resourceIdentifier), resourceIdentifier); | 152 | auto facade = getFacade<DomainType>(domainObject.resourceInstanceIdentifier()); |
145 | if (facade) { | 153 | return facade->create(domainObject).template then<void>([facade](){}, [](int errorCode, const QString &error) { |
146 | return facade->create(domainObject).template then<void>([facade](){}, [](int errorCode, const QString &error) { | 154 | Warning() << "Failed to create"; |
147 | Warning() << "Failed to create"; | 155 | }); |
148 | }); | ||
149 | } | ||
150 | return KAsync::error<void>(-1, "Failed to create a facade"); | ||
151 | } | 156 | } |
152 | 157 | ||
153 | /** | 158 | /** |
@@ -156,30 +161,24 @@ public: | |||
156 | * This includes moving etc. since these are also simple settings on a property. | 161 | * This includes moving etc. since these are also simple settings on a property. |
157 | */ | 162 | */ |
158 | template <class DomainType> | 163 | template <class DomainType> |
159 | static KAsync::Job<void> modify(const DomainType &domainObject, const QByteArray &resourceIdentifier) { | 164 | static KAsync::Job<void> modify(const DomainType &domainObject) { |
160 | //Potentially move to separate thread as well | 165 | //Potentially move to separate thread as well |
161 | auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceName(resourceIdentifier), resourceIdentifier); | 166 | auto facade = getFacade<DomainType>(domainObject.resourceInstanceIdentifier()); |
162 | if (facade) { | 167 | return facade->modify(domainObject).template then<void>([facade](){}, [](int errorCode, const QString &error) { |
163 | return facade->modify(domainObject).template then<void>([facade](){}, [](int errorCode, const QString &error) { | 168 | Warning() << "Failed to modify"; |
164 | Warning() << "Failed to modify"; | 169 | }); |
165 | }); | ||
166 | } | ||
167 | return KAsync::error<void>(-1, "Failed to create a facade"); | ||
168 | } | 170 | } |
169 | 171 | ||
170 | /** | 172 | /** |
171 | * Remove an entity. | 173 | * Remove an entity. |
172 | */ | 174 | */ |
173 | template <class DomainType> | 175 | template <class DomainType> |
174 | static KAsync::Job<void> remove(const DomainType &domainObject, const QByteArray &resourceIdentifier) { | 176 | static KAsync::Job<void> remove(const DomainType &domainObject) { |
175 | //Potentially move to separate thread as well | 177 | //Potentially move to separate thread as well |
176 | auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceName(resourceIdentifier), resourceIdentifier); | 178 | auto facade = getFacade<DomainType>(domainObject.resourceInstanceIdentifier()); |
177 | if (facade) { | 179 | return facade->remove(domainObject).template then<void>([facade](){}, [](int errorCode, const QString &error) { |
178 | return facade->remove(domainObject).template then<void>([facade](){}, [](int errorCode, const QString &error) { | 180 | Warning() << "Failed to remove"; |
179 | Warning() << "Failed to remove"; | 181 | }); |
180 | }); | ||
181 | } | ||
182 | return KAsync::error<void>(-1, "Failed to create a facade"); | ||
183 | } | 182 | } |
184 | 183 | ||
185 | static void shutdown(const QByteArray &resourceIdentifier); | 184 | static void shutdown(const QByteArray &resourceIdentifier); |
@@ -213,20 +212,20 @@ public: | |||
213 | return ApplicationDomain::AkonadiResource::Ptr::create(); | 212 | return ApplicationDomain::AkonadiResource::Ptr::create(); |
214 | } | 213 | } |
215 | 214 | ||
216 | static void setConfiguration(const ApplicationDomain::AkonadiResource &resource, const QByteArray &resourceIdentifier) | 215 | static void setConfiguration(const ApplicationDomain::AkonadiResource &resource) |
217 | { | 216 | { |
218 | Store::modify<ApplicationDomain::AkonadiResource>(resource, resourceIdentifier); | 217 | Store::modify<ApplicationDomain::AkonadiResource>(resource); |
219 | } | 218 | } |
220 | 219 | ||
221 | static void createResource(const ApplicationDomain::AkonadiResource &resource, const QByteArray &resourceIdentifier) | 220 | static void createResource(const ApplicationDomain::AkonadiResource &resource) |
222 | { | 221 | { |
223 | Store::create<ApplicationDomain::AkonadiResource>(resource, resourceIdentifier); | 222 | Store::create<ApplicationDomain::AkonadiResource>(resource); |
224 | } | 223 | } |
225 | 224 | ||
226 | static void removeResource(const QByteArray &resourceIdentifier) | 225 | static void removeResource(const QByteArray &resourceIdentifier) |
227 | { | 226 | { |
228 | ApplicationDomain::AkonadiResource resource; | 227 | ApplicationDomain::AkonadiResource resource(resourceIdentifier); |
229 | Store::remove<ApplicationDomain::AkonadiResource>(resource, resourceIdentifier); | 228 | Store::remove<ApplicationDomain::AkonadiResource>(resource); |
230 | } | 229 | } |
231 | }; | 230 | }; |
232 | 231 | ||
diff --git a/common/domain/applicationdomaintype.h b/common/domain/applicationdomaintype.h index 3cc34ec..bd7ff65 100644 --- a/common/domain/applicationdomaintype.h +++ b/common/domain/applicationdomaintype.h | |||
@@ -45,6 +45,13 @@ public: | |||
45 | 45 | ||
46 | } | 46 | } |
47 | 47 | ||
48 | ApplicationDomainType(const QByteArray &resourceInstanceIdentifier) | ||
49 | :mAdaptor(new MemoryBufferAdaptor()), | ||
50 | mResourceInstanceIdentifier(resourceInstanceIdentifier) | ||
51 | { | ||
52 | |||
53 | } | ||
54 | |||
48 | ApplicationDomainType(const QByteArray &resourceInstanceIdentifier, const QByteArray &identifier, qint64 revision, const QSharedPointer<BufferAdaptor> &adaptor) | 55 | ApplicationDomainType(const QByteArray &resourceInstanceIdentifier, const QByteArray &identifier, qint64 revision, const QSharedPointer<BufferAdaptor> &adaptor) |
49 | : mAdaptor(adaptor), | 56 | : mAdaptor(adaptor), |
50 | mResourceInstanceIdentifier(resourceInstanceIdentifier), | 57 | mResourceInstanceIdentifier(resourceInstanceIdentifier), |
diff --git a/common/facadeinterface.h b/common/facadeinterface.h index ac60ae4..cd43fa1 100644 --- a/common/facadeinterface.h +++ b/common/facadeinterface.h | |||
@@ -48,4 +48,29 @@ public: | |||
48 | virtual KAsync::Job<void> load(const Query &query, const QSharedPointer<Akonadi2::ResultProvider<typename DomainType::Ptr> > &resultProvider) = 0; | 48 | virtual KAsync::Job<void> load(const Query &query, const QSharedPointer<Akonadi2::ResultProvider<typename DomainType::Ptr> > &resultProvider) = 0; |
49 | }; | 49 | }; |
50 | 50 | ||
51 | template<class DomainType> | ||
52 | class NullFacade : public StoreFacade<DomainType> { | ||
53 | public: | ||
54 | virtual ~NullFacade(){}; | ||
55 | KAsync::Job<void> create(const DomainType &domainObject) | ||
56 | { | ||
57 | return KAsync::error<void>(-1, "Failed to create a facade"); | ||
58 | } | ||
59 | |||
60 | KAsync::Job<void> modify(const DomainType &domainObject) | ||
61 | { | ||
62 | return KAsync::error<void>(-1, "Failed to create a facade"); | ||
63 | } | ||
64 | |||
65 | KAsync::Job<void> remove(const DomainType &domainObject) | ||
66 | { | ||
67 | return KAsync::error<void>(-1, "Failed to create a facade"); | ||
68 | } | ||
69 | |||
70 | KAsync::Job<void> load(const Query &query, const QSharedPointer<Akonadi2::ResultProvider<typename DomainType::Ptr> > &resultProvider) | ||
71 | { | ||
72 | return KAsync::error<void>(-1, "Failed to create a facade"); | ||
73 | } | ||
74 | }; | ||
75 | |||
51 | } | 76 | } |