summaryrefslogtreecommitdiffstats
path: root/common/facade.h
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2015-04-09 14:23:16 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2015-04-09 14:23:16 +0200
commit855e3d7d0e3779e76e5af55bbf4c851acbd76e56 (patch)
tree11f93ef8661b1e39b9c66ddb395ddb84204c849c /common/facade.h
parent3062983d075761c457249b8c3c1248aa0d45e46a (diff)
downloadsink-855e3d7d0e3779e76e5af55bbf4c851acbd76e56.tar.gz
sink-855e3d7d0e3779e76e5af55bbf4c851acbd76e56.zip
Started a facade base implementation.
Diffstat (limited to 'common/facade.h')
-rw-r--r--common/facade.h88
1 files changed, 88 insertions, 0 deletions
diff --git a/common/facade.h b/common/facade.h
new file mode 100644
index 0000000..98bcb38
--- /dev/null
+++ b/common/facade.h
@@ -0,0 +1,88 @@
1/*
2 * Copyright (C) 2014 Christian Mollekopf <chrigi_1@fastmail.fm>
3 *
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
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the
16 * Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20#pragma once
21
22#include "clientapi.h"
23
24#include <QByteArray>
25
26#include "async/src/async.h"
27#include "resourceaccess.h"
28#include "commands.h"
29#include "createentity_generated.h"
30#include "domainadaptor.h"
31#include "entitybuffer.h"
32
33namespace Akonadi2 {
34 class ResourceAccess;
35/**
36 * Default facade implementation for resources that are implemented in a separate process using the ResourceAccess class.
37 */
38template <typename DomainType>
39class GenericFacade: public Akonadi2::StoreFacade<DomainType>
40{
41public:
42 GenericFacade(const QByteArray &resourceIdentifier)
43 : Akonadi2::StoreFacade<DomainType>(),
44 mResourceAccess(new ResourceAccess(resourceIdentifier))
45 {
46 }
47
48 ~GenericFacade()
49 {
50 }
51
52protected:
53 Async::Job<void> sendCreateCommand(const QByteArray &t, const QByteArray &buffer)
54 {
55 flatbuffers::FlatBufferBuilder fbb;
56 //This is the resource buffer type and not the domain type
57 auto type = fbb.CreateString(t.constData());
58 auto delta = Akonadi2::EntityBuffer::appendAsVector(fbb, buffer.constData(), buffer.size());
59 auto location = Akonadi2::Commands::CreateCreateEntity(fbb, type, delta);
60 Akonadi2::Commands::FinishCreateEntityBuffer(fbb, location);
61 mResourceAccess->open();
62 return mResourceAccess->sendCommand(Akonadi2::Commands::CreateEntityCommand, fbb);
63 }
64
65 Async::Job<void> synchronizeResource(bool sync, bool processAll)
66 {
67 //TODO check if a sync is necessary
68 //TODO Only sync what was requested
69 //TODO timeout
70 //TODO the synchronization should normally not be necessary: We just return what is already available.
71
72 if (sync || processAll) {
73 return Async::start<void>([=](Async::Future<void> &future) {
74 mResourceAccess->open();
75 mResourceAccess->synchronizeResource(sync, processAll).then<void>([&future]() {
76 future.setFinished();
77 }).exec();
78 });
79 }
80 return Async::null<void>();
81 }
82
83private:
84 //TODO use one resource access instance per application => make static
85 QSharedPointer<Akonadi2::ResourceAccess> mResourceAccess;
86};
87
88}