summaryrefslogtreecommitdiffstats
path: root/framework/actions/actionbroker.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2016-12-13 16:24:31 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2016-12-16 14:54:14 +0100
commit630f45719a527f8ee739b03bc62f886badea6df3 (patch)
treeb9d859cbfedb30ad8a9570e3b87a419bf24ba6c7 /framework/actions/actionbroker.cpp
parentb1a2e2de201985a00980bead5272977cda4ef637 (diff)
downloadkube-630f45719a527f8ee739b03bc62f886badea6df3.tar.gz
kube-630f45719a527f8ee739b03bc62f886badea6df3.zip
Revamp of composercontroller to use actions more.
Instead of setting all properties individually we directly assign all properties to a context that we assign to the actions. This way actions can automatically update themselves as new data becomes available, and we avoid the setter/getter boilerplate, at the cost of a less explicit interface (But that could be improved by allowing to define the required properties of a context in c++). By relying on prehandler/posthandler to execute certain actions we simplify the control flow and enable the future extension with handlers that i.e. do encryption etc.
Diffstat (limited to 'framework/actions/actionbroker.cpp')
-rw-r--r--framework/actions/actionbroker.cpp16
1 files changed, 13 insertions, 3 deletions
diff --git a/framework/actions/actionbroker.cpp b/framework/actions/actionbroker.cpp
index 24ef0b2c..17145440 100644
--- a/framework/actions/actionbroker.cpp
+++ b/framework/actions/actionbroker.cpp
@@ -21,11 +21,14 @@
21 21
22#include "context.h" 22#include "context.h"
23#include "actionhandler.h" 23#include "actionhandler.h"
24#include <sink/log.h>
24 25
25#include <QDebug> 26#include <QDebug>
26 27
27using namespace Kube; 28using namespace Kube;
28 29
30SINK_DEBUG_AREA("actionbroker")
31
29ActionBroker::ActionBroker(QObject *parent) 32ActionBroker::ActionBroker(QObject *parent)
30 : QObject(parent) 33 : QObject(parent)
31{ 34{
@@ -38,15 +41,20 @@ ActionBroker &ActionBroker::instance()
38 return instance; 41 return instance;
39} 42}
40 43
41bool ActionBroker::isActionReady(const QByteArray &actionId, Context *context) 44bool ActionBroker::isActionReady(const QByteArray &actionId, Context *context, const QList<QPointer<ActionHandler>> &preHandler)
42{ 45{
43 if (!context) { 46 if (!context) {
44 return false; 47 return false;
45 } 48 }
49 for (const auto handler : preHandler) {
50 if (!handler->isActionReady(context)) {
51 return false;
52 }
53 }
46 54
47 for (const auto handler : mHandler.values(actionId)) { 55 for (const auto handler : mHandler.values(actionId)) {
48 if (handler) { 56 if (handler) {
49 if (handler-> isActionReady(context)) { 57 if (handler->isActionReady(context)) {
50 return true; 58 return true;
51 } 59 }
52 } 60 }
@@ -59,6 +67,8 @@ ActionResult ActionBroker::executeAction(const QByteArray &actionId, Context *co
59{ 67{
60 ActionResult result; 68 ActionResult result;
61 if (context) { 69 if (context) {
70 SinkLog() << "Executing action " << actionId;
71 SinkLog() << *context;
62 for (const auto handler : preHandler) { 72 for (const auto handler : preHandler) {
63 handler->execute(context); 73 handler->execute(context);
64 } 74 }
@@ -73,7 +83,7 @@ ActionResult ActionBroker::executeAction(const QByteArray &actionId, Context *co
73 handler->execute(context); 83 handler->execute(context);
74 } 84 }
75 } else { 85 } else {
76 qWarning() << "Can't execute without context"; 86 SinkWarning() << "Can't execute without context";
77 result.setDone(); 87 result.setDone();
78 result.setError(1); 88 result.setError(1);
79 } 89 }