diff options
Diffstat (limited to 'common/facade.cpp')
-rw-r--r-- | common/facade.cpp | 81 |
1 files changed, 80 insertions, 1 deletions
diff --git a/common/facade.cpp b/common/facade.cpp index e51b32a..1d6b9a7 100644 --- a/common/facade.cpp +++ b/common/facade.cpp | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (C) 2015 Christian Mollekopf <chrigi_1@fastmail.fm> | 2 | * Copyright (C) 2015 Christian Mollekopf <chrigi_1@fastmail.fm> |
3 | * | 3 | * |
4 | * This program is free software; you can redistribute it and/or modify | 4 | * This program is free software; you can redistribute it and/or modify |
5 | * it under the terms of the GNU General Public License as published by | 5 | * it under the terms of the GNU General Public License as published by |
@@ -18,3 +18,82 @@ | |||
18 | */ | 18 | */ |
19 | 19 | ||
20 | #include "facade.h" | 20 | #include "facade.h" |
21 | |||
22 | #include "commands.h" | ||
23 | #include "log.h" | ||
24 | #include "storage.h" | ||
25 | #include "definitions.h" | ||
26 | #include "domainadaptor.h" | ||
27 | #include "queryrunner.h" | ||
28 | |||
29 | using namespace Akonadi2; | ||
30 | |||
31 | |||
32 | template<class DomainType> | ||
33 | GenericFacade<DomainType>::GenericFacade(const QByteArray &resourceIdentifier, const DomainTypeAdaptorFactoryInterface::Ptr &adaptorFactory , const QSharedPointer<Akonadi2::ResourceAccessInterface> resourceAccess) | ||
34 | : Akonadi2::StoreFacade<DomainType>(), | ||
35 | mResourceAccess(resourceAccess), | ||
36 | mDomainTypeAdaptorFactory(adaptorFactory), | ||
37 | mResourceInstanceIdentifier(resourceIdentifier) | ||
38 | { | ||
39 | if (!mResourceAccess) { | ||
40 | mResourceAccess = QSharedPointer<Akonadi2::ResourceAccess>::create(resourceIdentifier); | ||
41 | } | ||
42 | } | ||
43 | |||
44 | template<class DomainType> | ||
45 | GenericFacade<DomainType>::~GenericFacade() | ||
46 | { | ||
47 | } | ||
48 | |||
49 | template<class DomainType> | ||
50 | QByteArray GenericFacade<DomainType>::bufferTypeForDomainType() | ||
51 | { | ||
52 | //We happen to have a one to one mapping | ||
53 | return Akonadi2::ApplicationDomain::getTypeName<DomainType>(); | ||
54 | } | ||
55 | |||
56 | template<class DomainType> | ||
57 | KAsync::Job<void> GenericFacade<DomainType>::create(const DomainType &domainObject) | ||
58 | { | ||
59 | if (!mDomainTypeAdaptorFactory) { | ||
60 | Warning() << "No domain type adaptor factory available"; | ||
61 | return KAsync::error<void>(); | ||
62 | } | ||
63 | flatbuffers::FlatBufferBuilder entityFbb; | ||
64 | mDomainTypeAdaptorFactory->createBuffer(domainObject, entityFbb); | ||
65 | return mResourceAccess->sendCreateCommand(bufferTypeForDomainType(), QByteArray::fromRawData(reinterpret_cast<const char*>(entityFbb.GetBufferPointer()), entityFbb.GetSize())); | ||
66 | } | ||
67 | |||
68 | template<class DomainType> | ||
69 | KAsync::Job<void> GenericFacade<DomainType>::modify(const DomainType &domainObject) | ||
70 | { | ||
71 | if (!mDomainTypeAdaptorFactory) { | ||
72 | Warning() << "No domain type adaptor factory available"; | ||
73 | return KAsync::error<void>(); | ||
74 | } | ||
75 | flatbuffers::FlatBufferBuilder entityFbb; | ||
76 | mDomainTypeAdaptorFactory->createBuffer(domainObject, entityFbb); | ||
77 | return mResourceAccess->sendModifyCommand(domainObject.identifier(), domainObject.revision(), bufferTypeForDomainType(), QByteArrayList(), QByteArray::fromRawData(reinterpret_cast<const char*>(entityFbb.GetBufferPointer()), entityFbb.GetSize())); | ||
78 | } | ||
79 | |||
80 | template<class DomainType> | ||
81 | KAsync::Job<void> GenericFacade<DomainType>::remove(const DomainType &domainObject) | ||
82 | { | ||
83 | return mResourceAccess->sendDeleteCommand(domainObject.identifier(), domainObject.revision(), bufferTypeForDomainType()); | ||
84 | } | ||
85 | |||
86 | template<class DomainType> | ||
87 | QPair<KAsync::Job<void>, typename ResultEmitter<typename DomainType::Ptr>::Ptr> GenericFacade<DomainType>::load(const Akonadi2::Query &query) | ||
88 | { | ||
89 | //The runner lives for the lifetime of the query | ||
90 | auto runner = new QueryRunner<DomainType>(query, mResourceAccess, mResourceInstanceIdentifier, mDomainTypeAdaptorFactory, bufferTypeForDomainType()); | ||
91 | return qMakePair(KAsync::null<void>(), runner->emitter()); | ||
92 | } | ||
93 | |||
94 | |||
95 | template class Akonadi2::GenericFacade<Akonadi2::ApplicationDomain::Folder>; | ||
96 | template class Akonadi2::GenericFacade<Akonadi2::ApplicationDomain::Mail>; | ||
97 | template class Akonadi2::GenericFacade<Akonadi2::ApplicationDomain::Event>; | ||
98 | |||
99 | #include "facade.moc" | ||