diff options
Diffstat (limited to 'common/clientapi.h')
-rw-r--r-- | common/clientapi.h | 59 |
1 files changed, 29 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 | ||