summaryrefslogtreecommitdiffstats
path: root/common/domain
diff options
context:
space:
mode:
Diffstat (limited to 'common/domain')
-rw-r--r--common/domain/applicationdomaintype.h134
1 files changed, 134 insertions, 0 deletions
diff --git a/common/domain/applicationdomaintype.h b/common/domain/applicationdomaintype.h
new file mode 100644
index 0000000..2de1460
--- /dev/null
+++ b/common/domain/applicationdomaintype.h
@@ -0,0 +1,134 @@
1/*
2 * Copyright (C) 2014 Christian Mollekopf <chrigi_1@fastmail.fm>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) version 3, or any
8 * later version accepted by the membership of KDE e.V. (or its
9 * successor approved by the membership of KDE e.V.), which shall
10 * act as a proxy defined in Section 6 of version 3 of the license.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
19 */
20#pragma once
21
22#include <QSharedPointer>
23#include <QVariant>
24#include <QByteArray>
25#include "../bufferadaptor.h"
26
27namespace Akonadi2 {
28
29namespace ApplicationDomain {
30
31/**
32 * The domain type interface has two purposes:
33 * * provide a unified interface to read buffers (for zero-copy reading)
34 * * record changes to generate changesets for modifications
35 *
36 * ApplicationDomainTypes don't adhere to any standard and are meant to be extended frequently (hence the non-typesafe interface).
37 */
38class ApplicationDomainType {
39public:
40 typedef QSharedPointer<ApplicationDomainType> Ptr;
41
42 ApplicationDomainType()
43 :mAdaptor(new MemoryBufferAdaptor())
44 {
45
46 }
47
48 ApplicationDomainType(const QByteArray &resourceInstanceIdentifier, const QByteArray &identifier, qint64 revision, const QSharedPointer<BufferAdaptor> &adaptor)
49 : mAdaptor(adaptor),
50 mResourceInstanceIdentifier(resourceInstanceIdentifier),
51 mIdentifier(identifier),
52 mRevision(revision)
53 {
54 }
55
56 template <typename DomainType>
57 static typename DomainType::Ptr getInMemoryRepresentation(const ApplicationDomainType::Ptr &domainType)
58 {
59 //TODO only copy requested properties
60 auto memoryAdaptor = QSharedPointer<Akonadi2::ApplicationDomain::MemoryBufferAdaptor>::create(*(domainType->mAdaptor));
61 return QSharedPointer<DomainType>::create(domainType->mResourceInstanceIdentifier, domainType->mIdentifier, domainType->mRevision, memoryAdaptor);
62 }
63
64 virtual ~ApplicationDomainType() {}
65
66 virtual QVariant getProperty(const QByteArray &key) const { return mAdaptor->getProperty(key); }
67 virtual void setProperty(const QByteArray &key, const QVariant &value){ mChangeSet.insert(key, value); mAdaptor->setProperty(key, value); }
68 virtual QByteArrayList changedProperties() const { return mChangeSet.keys(); }
69 qint64 revision() const { return mRevision; }
70 QByteArray resourceInstanceIdentifier() const { return mResourceInstanceIdentifier; }
71 QByteArray identifier() const { return mIdentifier; }
72
73private:
74 QSharedPointer<BufferAdaptor> mAdaptor;
75 QHash<QByteArray, QVariant> mChangeSet;
76 /*
77 * Each domain object needs to store the resource, identifier, revision triple so we can link back to the storage location.
78 */
79 QByteArray mResourceInstanceIdentifier;
80 QByteArray mIdentifier;
81 qint64 mRevision;
82};
83
84struct Event : public ApplicationDomainType {
85 typedef QSharedPointer<Event> Ptr;
86 using ApplicationDomainType::ApplicationDomainType;
87};
88
89struct Todo : public ApplicationDomainType {
90 typedef QSharedPointer<Todo> Ptr;
91 using ApplicationDomainType::ApplicationDomainType;
92};
93
94struct Calendar : public ApplicationDomainType {
95 typedef QSharedPointer<Calendar> Ptr;
96 using ApplicationDomainType::ApplicationDomainType;
97};
98
99class Mail : public ApplicationDomainType {
100};
101
102class Folder : public ApplicationDomainType {
103};
104
105/**
106 * Represents an akonadi resource.
107 *
108 * This type is used for configuration of resources,
109 * and for creating and removing resource instances.
110 */
111struct AkonadiResource : public ApplicationDomainType {
112 typedef QSharedPointer<AkonadiResource> Ptr;
113 using ApplicationDomainType::ApplicationDomainType;
114};
115
116/**
117 * All types need to be registered here an MUST return a different name.
118 *
119 * Do not store these types to disk, they may change over time.
120 */
121template<class DomainType>
122QByteArray getTypeName();
123
124template<>
125QByteArray getTypeName<Event>();
126
127template<>
128QByteArray getTypeName<Todo>();
129
130template<>
131QByteArray getTypeName<AkonadiResource>();
132
133}
134}