aboutsummaryrefslogtreecommitdiffstats
path: root/signal-composer-binding/ctl-lua.h
blob: df2379fa047d39a054290503a6a8be2165c1aee3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#ifdef SUSE_LUA_INCDIR
    #include <lua5.3/lua.h>
    #include <lua5.3/lauxlib.h>
    #include <lua5.3/lualib.h>
#else
    #include <lua.h>
    #include <lauxlib.h>
    #include <lualib.h>
#endif

#include <json-c/json.h>

#include "signal-composer-binding.hpp"

#ifndef CONTROL_DOSCRIPT_PRE
#define CONTROL_DOSCRIPT_PRE "doscript"
#endif

#ifndef CONTROL_CONFIG_PRE
#define CONTROL_CONFIG_PRE "onload"
#endif

#ifndef CONTROL_LUA_EVENT
#define CONTROL_LUA_EVENT "luaevt"
#endif

typedef int (*timerCallbackT)(void *context);

typedef struct TimerHandleS {
    int count;
    int delay;
    const char*label;
    void *context;
    timerCallbackT callback;
    sd_event_source *evtSource;
} TimerHandleT;

int TimerEvtInit (void);
afb_event TimerEvtGet(void);
void TimerEvtStart(TimerHandleT *timerHandle, timerCallbackT callback, void *context);
void TimerEvtStop(TimerHandleT *timerHandle);

typedef enum {
    CTL_MODE_NONE=0,
    CTL_MODE_API,
    CTL_MODE_CB,
    CTL_MODE_LUA,
} CtlRequestModeT;

typedef enum {
    CTL_SOURCE_CLOSE=-1,
    CTL_SOURCE_UNKNOWN=0,
    CTL_SOURCE_ONLOAD=1,
    CTL_SOURCE_OPEN=2,
    CTL_SOURCE_EVENT=3,
} DispatchSourceT;

typedef struct DispatchActionS{
    const char *info;
    const char* label;
    CtlRequestModeT mode;
    const char* api;
    const char* call;
    json_object *argsJ;
    int timeout;
    int (*actionCB)(DispatchSourceT source, const char*label,  json_object *argsJ, json_object *queryJ, void *context);
} DispatchActionT;

typedef enum {
    LUA_DOCALL,
    LUA_DOSTRING,
    LUA_DOSCRIPT,
} LuaDoActionT;

typedef int (*Lua2cFunctionT)(char *funcname, json_object *argsJ, void*context);