summaryrefslogtreecommitdiffstats
path: root/ctl-lib/ctl-lua.c
diff options
context:
space:
mode:
authorClément Bénier <clement.benier@iot.bzh>2018-07-03 18:34:11 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2018-07-10 07:51:56 +0000
commitbac7d6da81ef3876dc8cf6f50b1d602000a96749 (patch)
tree1feae5ee3fe194c25ca6057c9673a72f8fd35c48 /ctl-lib/ctl-lua.c
parent4a72073d15248dbb3c9d88377405ad44e75f6d1b (diff)
asynchronism for test: LockWait added
added LockWait to wait for incoming events, as soon as an event is received, the wait is unlocked You can indicate the timeout Change-Id: If29ca754618edb5b9fdc32c1c40b47016c6fc88a Signed-off-by: Clément Bénier <clement.benier@iot.bzh>
Diffstat (limited to 'ctl-lib/ctl-lua.c')
-rw-r--r--ctl-lib/ctl-lua.c33
1 files changed, 25 insertions, 8 deletions
diff --git a/ctl-lib/ctl-lua.c b/ctl-lib/ctl-lua.c
index 02487b5..ba29c9b 100644
--- a/ctl-lib/ctl-lua.c
+++ b/ctl-lib/ctl-lua.c
@@ -40,11 +40,15 @@
static lua_State* luaState;
CtlPluginT *ctlPlugins = NULL;
-#ifndef CTX_MAGIC
+#if CTX_MAGIC_VALUE
+static int CTX_MAGIC = CTX_MAGIC_VALUE;
+#else
static int CTX_MAGIC;
#endif
-#ifndef TIMER_MAGIC
+#if TIMER_MAGIC_VALUE
+static int TIMER_MAGIC = TIMER_MAGIC_VALUE;
+#else
static int TIMER_MAGIC;
#endif
@@ -599,6 +603,23 @@ static int LuaAfbEventSubscribe(lua_State* luaState) {
return 0;
}
+static int LuaLockWait(lua_State* luaState) {
+ luaL_checktype(luaState, LUA_FIST_ARG, LUA_TLIGHTUSERDATA);
+ luaL_checktype(luaState, LUA_FIST_ARG + 1, LUA_TNUMBER);
+
+ CtlSourceT *source = (CtlSourceT *)LuaSourcePop(luaState, LUA_FIST_ARG);
+ if (!source) {
+ lua_pushliteral(luaState, "LuaLockWait-Fail Invalid request handle");
+ lua_error(luaState);
+ return 1;
+ }
+ uint64_t utimeout = (int)lua_tointeger(luaState, LUA_FIST_ARG + 1);
+
+ uint64_t remain_timeout = LockWait(source->api, utimeout);
+ lua_pushinteger(luaState, remain_timeout);
+ return 1; //return nb of pushed elements
+}
+
static int LuaAfbEventMake(lua_State* luaState) {
int count = lua_gettop(luaState);
LuaAfbEvent *afbevt = calloc(1, sizeof (LuaAfbEvent));
@@ -1247,7 +1268,7 @@ static const luaL_Reg afbFunction[] = {
{"getuid", LuaAfbGetUid},
{"status", LuaAfbGetStatus},
{"context", LuaClientCtx},
-
+ {"lockwait", LuaLockWait},
{NULL, NULL} /* sentinel */
};
@@ -1328,13 +1349,9 @@ int LuaConfigLoad(AFB_ApiT apiHandle) {
free(lua_str);
// initialise static magic for context
-#ifndef CTX_MAGIC
+#ifndef CTX_MAGIC_VALUE
CTX_MAGIC = CtlConfigMagicNew();
#endif
-#ifndef TIMER_MAGIC
- TIMER_MAGIC = CtlConfigMagicNew();
-#endif
-
return 0;
}