summaryrefslogtreecommitdiffstats
path: root/ctl-lib
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-10-25 19:09:09 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2018-12-13 15:02:54 +0100
commit8b005882eda47decef8743061536db091e6b5303 (patch)
treee620ccd39b0d463cfc9669e331aaa75dc36cf29e /ctl-lib
parenta295417a17e97a4109afd41be335b1039edf894d (diff)
Add action method to execute an action from its uid
Change-Id: Ic8f1d418db228ca8c646263b32a2431931a6a4be Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'ctl-lib')
-rw-r--r--ctl-lib/ctl-action.c24
-rw-r--r--ctl-lib/ctl-config.h1
2 files changed, 23 insertions, 2 deletions
diff --git a/ctl-lib/ctl-action.c b/ctl-lib/ctl-action.c
index 10eba09..bb4b874 100644
--- a/ctl-lib/ctl-action.c
+++ b/ctl-lib/ctl-action.c
@@ -25,17 +25,37 @@
#include "ctl-config.h"
PUBLIC int ActionLabelToIndex(CtlActionT*actions, const char* actionLabel) {
-
for (int idx = 0; actions[idx].uid; idx++) {
if (!strcasecmp(actionLabel, actions[idx].uid)) return idx;
}
return -1;
}
+PUBLIC void ActionExecUID(AFB_ReqT request, CtlConfigT *ctlConfig, const char *uid, json_object *queryJ)
+{
+ for(int i=0; ctlConfig->sections[i].key != NULL; i++)
+ {
+ if(ctlConfig->sections[i].actions)
+ {
+ for(int j=0; ctlConfig->sections[i].actions[j].uid != NULL; j++)
+ {
+ if(strcmp(ctlConfig->sections[i].actions[j].uid, uid) == 0)
+ {
+ CtlSourceT source;
+ source.uid = ctlConfig->sections[i].actions[j].uid;
+ source.api = ctlConfig->sections[i].actions[j].api;
+ source.request = request;
+
+ ActionExecOne(&source, &ctlConfig->sections[i].actions[j], queryJ);
+ }
+ }
+ }
+ }
+}
PUBLIC void ActionExecOne(CtlSourceT *source, CtlActionT* action, json_object *queryJ) {
int err;
-
+
switch (action->type) {
case CTL_TYPE_API:
{
diff --git a/ctl-lib/ctl-config.h b/ctl-lib/ctl-config.h
index 31b31d2..c3f5d4b 100644
--- a/ctl-lib/ctl-config.h
+++ b/ctl-lib/ctl-config.h
@@ -77,6 +77,7 @@ typedef enum {
// ctl-action.c
PUBLIC CtlActionT *ActionConfig(AFB_ApiT apiHandle, json_object *actionsJ, int exportApi);
+PUBLIC void ActionExecUID(AFB_ReqT request, CtlConfigT *ctlConfig, const char *uid, json_object *queryJ);
PUBLIC void ActionExecOne( CtlSourceT *source, CtlActionT* action, json_object *queryJ);
PUBLIC int ActionLoadOne(AFB_ApiT apiHandle, CtlActionT *action, json_object *, int exportApi);
PUBLIC int ActionLabelToIndex(CtlActionT* actions, const char* actionLabel);
} /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */ }
BBLAYERS =+ " \
  ${METADIR}/meta-agl/meta-agl-profile-cluster \
"