summaryrefslogtreecommitdiffstats
path: root/framework/actions/actionbroker.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2017-04-05 15:04:00 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2017-04-05 15:04:00 +0200
commit4b1798f0cdf87361869e7cf2b341acacd056c410 (patch)
tree3ff780641acdcb20b81f9b41533afd50a2525d38 /framework/actions/actionbroker.cpp
parent71721aa4f3e85bea1a2fe504e86d99f80a3106a9 (diff)
downloadkube-4b1798f0cdf87361869e7cf2b341acacd056c410.tar.gz
kube-4b1798f0cdf87361869e7cf2b341acacd056c410.zip
Moved cpp code into src directory
Diffstat (limited to 'framework/actions/actionbroker.cpp')
-rw-r--r--framework/actions/actionbroker.cpp101
1 files changed, 0 insertions, 101 deletions
diff --git a/framework/actions/actionbroker.cpp b/framework/actions/actionbroker.cpp
deleted file mode 100644
index f6bfdd8e..00000000
--- a/framework/actions/actionbroker.cpp
+++ /dev/null
@@ -1,101 +0,0 @@
1/*
2 Copyright (c) 2016 Christian Mollekopf <mollekopf@kolabsys.com>
3
4 This library is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or (at your
7 option) any later version.
8
9 This library is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301, USA.
18*/
19
20#include "actionbroker.h"
21
22#include "context.h"
23#include "actionhandler.h"
24#include <sink/log.h>
25
26#include <QDebug>
27
28using namespace Kube;
29
30SINK_DEBUG_AREA("actionbroker")
31
32ActionBroker::ActionBroker(QObject *parent)
33 : QObject(parent)
34{
35
36}
37
38ActionBroker &ActionBroker::instance()
39{
40 static ActionBroker instance;
41 return instance;
42}
43
44bool ActionBroker::isActionReady(const QByteArray &actionId, Context *context, const QList<QPointer<ActionHandler>> &preHandler)
45{
46 if (!context) {
47 return false;
48 }
49 for (const auto handler : preHandler) {
50 if (!handler->isActionReady(context)) {
51 return false;
52 }
53 }
54
55 for (const auto handler : mHandler.values(actionId)) {
56 if (handler) {
57 if (handler->isActionReady(context)) {
58 return true;
59 }
60 }
61 }
62
63 return false;
64}
65
66ActionResult ActionBroker::executeAction(const QByteArray &actionId, Context *context, const QList<QPointer<ActionHandler>> &preHandler, const QList<QPointer<ActionHandler>> &postHandler)
67{
68 ActionResult result;
69 if (context) {
70 SinkLog() << "Executing action " << actionId;
71 SinkLog() << *context;
72 for (const auto handler : preHandler) {
73 handler->execute(context);
74 }
75 //TODO the main handler should only execute once the pre handler is done
76 for (const auto handler : mHandler.values(actionId)) {
77 if (handler) {
78 result += handler->execute(context);
79 }
80 }
81 //TODO the post handler should only execute once the main handler is done
82 for (const auto handler : postHandler) {
83 handler->execute(context);
84 }
85 } else {
86 SinkWarning() << "Can't execute without context";
87 result.setDone();
88 result.setError(1);
89 }
90 return result;
91}
92
93void ActionBroker::registerHandler(const QByteArray &actionId, ActionHandler *handler)
94{
95 mHandler.insert(actionId, handler);
96}
97
98void ActionBroker::unregisterHandler(const QByteArray &actionId, ActionHandler *handler)
99{
100 mHandler.remove(actionId, handler);
101}