diff options
-rw-r--r-- | common/CMakeLists.txt | 5 | ||||
-rw-r--r-- | common/clientapi.h | 65 | ||||
-rw-r--r-- | common/notifier.cpp | 69 | ||||
-rw-r--r-- | common/notifier.h | 46 | ||||
-rw-r--r-- | common/resourcecontrol.cpp (renamed from common/clientapi.cpp) | 60 | ||||
-rw-r--r-- | common/resourcecontrol.h | 62 |
6 files changed, 187 insertions, 120 deletions
diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 02335ad..0becad6 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt | |||
@@ -34,11 +34,12 @@ set(storage_LIBS lmdb) | |||
34 | 34 | ||
35 | set(command_SRCS | 35 | set(command_SRCS |
36 | store.cpp | 36 | store.cpp |
37 | notifier.cpp | ||
38 | resourcecontrol.cpp | ||
37 | modelresult.cpp | 39 | modelresult.cpp |
38 | definitions.cpp | 40 | definitions.cpp |
39 | log.cpp | 41 | log.cpp |
40 | entitybuffer.cpp | 42 | entitybuffer.cpp |
41 | clientapi.cpp | ||
42 | facadefactory.cpp | 43 | facadefactory.cpp |
43 | commands.cpp | 44 | commands.cpp |
44 | facade.cpp | 45 | facade.cpp |
@@ -104,6 +105,8 @@ add_clang_static_analysis(${PROJECT_NAME}) | |||
104 | 105 | ||
105 | install(FILES | 106 | install(FILES |
106 | store.h | 107 | store.h |
108 | notifier.h | ||
109 | resourcecontrol.h | ||
107 | clientapi.h | 110 | clientapi.h |
108 | domain/applicationdomaintype.h | 111 | domain/applicationdomaintype.h |
109 | query.h | 112 | query.h |
diff --git a/common/clientapi.h b/common/clientapi.h index a1d2469..8333987 100644 --- a/common/clientapi.h +++ b/common/clientapi.h | |||
@@ -20,67 +20,6 @@ | |||
20 | 20 | ||
21 | #pragma once | 21 | #pragma once |
22 | 22 | ||
23 | #include "sink_export.h" | ||
24 | #include <QString> | ||
25 | #include <QSharedPointer> | ||
26 | |||
27 | #include <Async/Async> | ||
28 | |||
29 | #include "store.h" | 23 | #include "store.h" |
30 | 24 | #include "notifier.h" | |
31 | #include "query.h" | 25 | #include "resourcecontrol.h" |
32 | #include "inspection.h" | ||
33 | #include "applicationdomaintype.h" | ||
34 | |||
35 | class QAbstractItemModel; | ||
36 | |||
37 | namespace Sink { | ||
38 | class ResourceAccess; | ||
39 | class Notification; | ||
40 | |||
41 | class SINK_EXPORT Notifier { | ||
42 | public: | ||
43 | Notifier(const QSharedPointer<ResourceAccess> &resourceAccess); | ||
44 | Notifier(const QByteArray &resourceInstanceIdentifier); | ||
45 | // Notifier(const QByteArrayList &resource); | ||
46 | void registerHandler(std::function<void(const Notification &)>); | ||
47 | |||
48 | private: | ||
49 | class Private; | ||
50 | QSharedPointer<Private> d; | ||
51 | }; | ||
52 | |||
53 | |||
54 | namespace ResourceControl { | ||
55 | |||
56 | template <class DomainType> | ||
57 | KAsync::Job<void> SINK_EXPORT inspect(const Inspection &inspectionCommand); | ||
58 | |||
59 | /** | ||
60 | * Shutdown resource. | ||
61 | */ | ||
62 | KAsync::Job<void> SINK_EXPORT shutdown(const QByteArray &resourceIdentifier); | ||
63 | |||
64 | /** | ||
65 | * Start resource. | ||
66 | * | ||
67 | * The resource is ready for operation once this command completes. | ||
68 | * This command is only necessary if a resource was shutdown previously, | ||
69 | * otherwise the resource process will automatically start as necessary. | ||
70 | */ | ||
71 | KAsync::Job<void> SINK_EXPORT start(const QByteArray &resourceIdentifier); | ||
72 | |||
73 | /** | ||
74 | * Flushes any pending messages to disk | ||
75 | */ | ||
76 | KAsync::Job<void> SINK_EXPORT flushMessageQueue(const QByteArrayList &resourceIdentifier); | ||
77 | |||
78 | /** | ||
79 | * Flushes any pending messages that haven't been replayed to the source. | ||
80 | */ | ||
81 | KAsync::Job<void> SINK_EXPORT flushReplayQueue(const QByteArrayList &resourceIdentifier); | ||
82 | |||
83 | } | ||
84 | |||
85 | } | ||
86 | |||
diff --git a/common/notifier.cpp b/common/notifier.cpp new file mode 100644 index 0000000..e4248df --- /dev/null +++ b/common/notifier.cpp | |||
@@ -0,0 +1,69 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2015 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 | |||
21 | #include "notifier.h" | ||
22 | |||
23 | #include <functional> | ||
24 | |||
25 | #include "resourceaccess.h" | ||
26 | #include "log.h" | ||
27 | |||
28 | using namespace Sink; | ||
29 | |||
30 | class Sink::Notifier::Private { | ||
31 | public: | ||
32 | Private() | ||
33 | : context(new QObject) | ||
34 | { | ||
35 | |||
36 | } | ||
37 | QList<QSharedPointer<ResourceAccess> > resourceAccess; | ||
38 | QList<std::function<void(const Notification &)> > handler; | ||
39 | QSharedPointer<QObject> context; | ||
40 | }; | ||
41 | |||
42 | Notifier::Notifier(const QSharedPointer<ResourceAccess> &resourceAccess) | ||
43 | : d(new Sink::Notifier::Private) | ||
44 | { | ||
45 | QObject::connect(resourceAccess.data(), &ResourceAccess::notification, d->context.data(), [this](const Notification ¬ification) { | ||
46 | for (const auto &handler : d->handler) { | ||
47 | handler(notification); | ||
48 | } | ||
49 | }); | ||
50 | d->resourceAccess << resourceAccess; | ||
51 | } | ||
52 | |||
53 | Notifier::Notifier(const QByteArray &instanceIdentifier) | ||
54 | : d(new Sink::Notifier::Private) | ||
55 | { | ||
56 | auto resourceAccess = Sink::ResourceAccess::Ptr::create(instanceIdentifier); | ||
57 | resourceAccess->open(); | ||
58 | QObject::connect(resourceAccess.data(), &ResourceAccess::notification, d->context.data(), [this](const Notification ¬ification) { | ||
59 | for (const auto &handler : d->handler) { | ||
60 | handler(notification); | ||
61 | } | ||
62 | }); | ||
63 | d->resourceAccess << resourceAccess; | ||
64 | } | ||
65 | |||
66 | void Notifier::registerHandler(std::function<void(const Notification &)> handler) | ||
67 | { | ||
68 | d->handler << handler; | ||
69 | } | ||
diff --git a/common/notifier.h b/common/notifier.h new file mode 100644 index 0000000..d16a311 --- /dev/null +++ b/common/notifier.h | |||
@@ -0,0 +1,46 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2015 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 | |||
21 | #pragma once | ||
22 | |||
23 | #include "sink_export.h" | ||
24 | #include <QByteArray> | ||
25 | #include <QSharedPointer> | ||
26 | |||
27 | #include <Async/Async> | ||
28 | |||
29 | class QAbstractItemModel; | ||
30 | |||
31 | namespace Sink { | ||
32 | class ResourceAccess; | ||
33 | class Notification; | ||
34 | |||
35 | class SINK_EXPORT Notifier { | ||
36 | public: | ||
37 | Notifier(const QSharedPointer<ResourceAccess> &resourceAccess); | ||
38 | Notifier(const QByteArray &resourceInstanceIdentifier); | ||
39 | void registerHandler(std::function<void(const Notification &)>); | ||
40 | |||
41 | private: | ||
42 | class Private; | ||
43 | QSharedPointer<Private> d; | ||
44 | }; | ||
45 | |||
46 | } | ||
diff --git a/common/clientapi.cpp b/common/resourcecontrol.cpp index 01411c2..4a6f9b4 100644 --- a/common/clientapi.cpp +++ b/common/resourcecontrol.cpp | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (C) 2014 Christian Mollekopf <chrigi_1@fastmail.fm> | 2 | * Copyright (C) 2015 Christian Mollekopf <chrigi_1@fastmail.fm> |
3 | * | 3 | * |
4 | * This library is free software; you can redistribute it and/or | 4 | * This library is free software; you can redistribute it and/or |
5 | * modify it under the terms of the GNU Lesser General Public | 5 | * modify it under the terms of the GNU Lesser General Public |
@@ -18,30 +18,19 @@ | |||
18 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. | 18 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | #include "clientapi.h" | 21 | #include "resourcecontrol.h" |
22 | 22 | ||
23 | #include <QtConcurrent/QtConcurrentRun> | ||
24 | #include <QTimer> | ||
25 | #include <QTime> | 23 | #include <QTime> |
26 | #include <QEventLoop> | ||
27 | #include <QAbstractItemModel> | ||
28 | #include <QDir> | ||
29 | #include <QUuid> | 24 | #include <QUuid> |
30 | #include <functional> | 25 | #include <functional> |
31 | #include <memory> | ||
32 | 26 | ||
33 | #include "resourceaccess.h" | 27 | #include "resourceaccess.h" |
34 | #include "commands.h" | 28 | #include "commands.h" |
35 | #include "resourcefacade.h" | ||
36 | #include "definitions.h" | ||
37 | #include "resourceconfig.h" | ||
38 | #include "facadefactory.h" | ||
39 | #include "modelresult.h" | ||
40 | #include "storage.h" | ||
41 | #include "log.h" | 29 | #include "log.h" |
30 | #include "notifier.h" | ||
42 | 31 | ||
43 | #undef DEBUG_AREA | 32 | #undef DEBUG_AREA |
44 | #define DEBUG_AREA "client.clientapi" | 33 | #define DEBUG_AREA "client.resourcecontrol" |
45 | 34 | ||
46 | namespace Sink | 35 | namespace Sink |
47 | { | 36 | { |
@@ -129,47 +118,6 @@ KAsync::Job<void> ResourceControl::inspect(const Inspection &inspectionCommand) | |||
129 | }); | 118 | }); |
130 | } | 119 | } |
131 | 120 | ||
132 | class Sink::Notifier::Private { | ||
133 | public: | ||
134 | Private() | ||
135 | : context(new QObject) | ||
136 | { | ||
137 | |||
138 | } | ||
139 | QList<QSharedPointer<ResourceAccess> > resourceAccess; | ||
140 | QList<std::function<void(const Notification &)> > handler; | ||
141 | QSharedPointer<QObject> context; | ||
142 | }; | ||
143 | |||
144 | Notifier::Notifier(const QSharedPointer<ResourceAccess> &resourceAccess) | ||
145 | : d(new Sink::Notifier::Private) | ||
146 | { | ||
147 | QObject::connect(resourceAccess.data(), &ResourceAccess::notification, d->context.data(), [this](const Notification ¬ification) { | ||
148 | for (const auto &handler : d->handler) { | ||
149 | handler(notification); | ||
150 | } | ||
151 | }); | ||
152 | d->resourceAccess << resourceAccess; | ||
153 | } | ||
154 | |||
155 | Notifier::Notifier(const QByteArray &instanceIdentifier) | ||
156 | : d(new Sink::Notifier::Private) | ||
157 | { | ||
158 | auto resourceAccess = Sink::ResourceAccess::Ptr::create(instanceIdentifier); | ||
159 | resourceAccess->open(); | ||
160 | QObject::connect(resourceAccess.data(), &ResourceAccess::notification, d->context.data(), [this](const Notification ¬ification) { | ||
161 | for (const auto &handler : d->handler) { | ||
162 | handler(notification); | ||
163 | } | ||
164 | }); | ||
165 | d->resourceAccess << resourceAccess; | ||
166 | } | ||
167 | |||
168 | void Notifier::registerHandler(std::function<void(const Notification &)> handler) | ||
169 | { | ||
170 | d->handler << handler; | ||
171 | } | ||
172 | |||
173 | #define REGISTER_TYPE(T) template KAsync::Job<void> ResourceControl::inspect<T>(const Inspection &); \ | 121 | #define REGISTER_TYPE(T) template KAsync::Job<void> ResourceControl::inspect<T>(const Inspection &); \ |
174 | 122 | ||
175 | REGISTER_TYPE(ApplicationDomain::Event); | 123 | REGISTER_TYPE(ApplicationDomain::Event); |
diff --git a/common/resourcecontrol.h b/common/resourcecontrol.h new file mode 100644 index 0000000..5bfa67f --- /dev/null +++ b/common/resourcecontrol.h | |||
@@ -0,0 +1,62 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2015 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 | |||
21 | #pragma once | ||
22 | |||
23 | #include "sink_export.h" | ||
24 | #include <QByteArray> | ||
25 | |||
26 | #include <Async/Async> | ||
27 | |||
28 | #include "inspection.h" | ||
29 | |||
30 | namespace Sink { | ||
31 | namespace ResourceControl { | ||
32 | |||
33 | template <class DomainType> | ||
34 | KAsync::Job<void> SINK_EXPORT inspect(const Inspection &inspectionCommand); | ||
35 | |||
36 | /** | ||
37 | * Shutdown resource. | ||
38 | */ | ||
39 | KAsync::Job<void> SINK_EXPORT shutdown(const QByteArray &resourceIdentifier); | ||
40 | |||
41 | /** | ||
42 | * Start resource. | ||
43 | * | ||
44 | * The resource is ready for operation once this command completes. | ||
45 | * This command is only necessary if a resource was shutdown previously, | ||
46 | * otherwise the resource process will automatically start as necessary. | ||
47 | */ | ||
48 | KAsync::Job<void> SINK_EXPORT start(const QByteArray &resourceIdentifier); | ||
49 | |||
50 | /** | ||
51 | * Flushes any pending messages to disk | ||
52 | */ | ||
53 | KAsync::Job<void> SINK_EXPORT flushMessageQueue(const QByteArrayList &resourceIdentifier); | ||
54 | |||
55 | /** | ||
56 | * Flushes any pending messages that haven't been replayed to the source. | ||
57 | */ | ||
58 | KAsync::Job<void> SINK_EXPORT flushReplayQueue(const QByteArrayList &resourceIdentifier); | ||
59 | |||
60 | } | ||
61 | } | ||
62 | |||