summaryrefslogtreecommitdiff
path: root/pbx/pbx_lua.c
diff options
context:
space:
mode:
authorMatthew Nicholson <mnicholson@digium.com>2011-05-06 19:01:57 +0000
committerMatthew Nicholson <mnicholson@digium.com>2011-05-06 19:01:57 +0000
commitd5e9ce9ab199d8e2762e305279f9fb3d6f842005 (patch)
tree481eb01b417501066625514e8b477d6f00bc2608 /pbx/pbx_lua.c
parent6c38322870a44ef5cd7f90b049e4daa07ed8ad9d (diff)
Make pbx_lua handle managing the autoservice better.
Make autoservice_start() and autoservice_stop() return nothing. Also check if the autoservice flag is set before starting or stopping the autoservice and stop and start the autoservice when returning control to and getting control from the pbx engine. git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@317803 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'pbx/pbx_lua.c')
-rw-r--r--pbx/pbx_lua.c53
1 files changed, 35 insertions, 18 deletions
diff --git a/pbx/pbx_lua.c b/pbx/pbx_lua.c
index 61f93ab63..25acc4981 100644
--- a/pbx/pbx_lua.c
+++ b/pbx/pbx_lua.c
@@ -717,26 +717,28 @@ static int lua_func_read(lua_State *L)
* This function will set a flag that will cause pbx_lua to maintain an
* autoservice on this channel. The autoservice will automatically be stopped
* and restarted before calling applications and functions.
- *
- * \return This function returns the result of the ast_autoservice_start()
- * function as a boolean to its lua caller.
*/
static int lua_autoservice_start(lua_State *L)
{
struct ast_channel *chan;
- int res;
+
+ lua_getfield(L, LUA_REGISTRYINDEX, "autoservice");
+ if (lua_toboolean(L, -1)) {
+ /* autservice already running */
+ lua_pop(L, 1);
+ return 0;
+ }
+ lua_pop(L, 1);
lua_getfield(L, LUA_REGISTRYINDEX, "channel");
chan = lua_touserdata(L, -1);
lua_pop(L, 1);
- res = ast_autoservice_start(chan);
+ ast_autoservice_start(chan);
- lua_pushboolean(L, !res);
+ lua_pushboolean(L, 1);
lua_setfield(L, LUA_REGISTRYINDEX, "autoservice");
-
- lua_pushboolean(L, !res);
- return 1;
+ return 0;
}
/*!
@@ -748,26 +750,28 @@ static int lua_autoservice_start(lua_State *L)
* This function will stop any autoservice running and turn off the autoservice
* flag. If this function returns false, it's probably because no autoservice
* was running to begin with.
- *
- * \return This function returns the result of the ast_autoservice_stop()
- * function as a boolean to its lua caller.
*/
static int lua_autoservice_stop(lua_State *L)
{
struct ast_channel *chan;
- int res;
+
+ lua_getfield(L, LUA_REGISTRYINDEX, "autoservice");
+ if (!lua_toboolean(L, -1)) {
+ /* no autservice running */
+ lua_pop(L, 1);
+ return 0;
+ }
+ lua_pop(L, 1);
lua_getfield(L, LUA_REGISTRYINDEX, "channel");
chan = lua_touserdata(L, -1);
lua_pop(L, 1);
- res = ast_autoservice_stop(chan);
+ ast_autoservice_stop(chan);
lua_pushboolean(L, 0);
lua_setfield(L, LUA_REGISTRYINDEX, "autoservice");
-
- lua_pushboolean(L, !res);
- return 1;
+ return 0;
}
/*!
@@ -1429,7 +1433,13 @@ static int exec(struct ast_channel *chan, const char *context, const char *exten
ast_module_user_remove(u);
return -1;
}
-
+
+ lua_getfield(L, LUA_REGISTRYINDEX, "autoservice");
+ if (lua_toboolean(L, -1)) {
+ ast_autoservice_start(chan);
+ }
+ lua_pop(L, 1);
+
lua_update_registry(L, context, exten, priority);
lua_pushstring(L, context);
@@ -1459,6 +1469,13 @@ static int exec(struct ast_channel *chan, const char *context, const char *exten
lua_pop(L, 1);
}
lua_remove(L, error_func);
+
+ lua_getfield(L, LUA_REGISTRYINDEX, "autoservice");
+ if (lua_toboolean(L, -1)) {
+ ast_autoservice_stop(chan);
+ }
+ lua_pop(L, 1);
+
if (!chan) lua_close(L);
ast_module_user_remove(u);
return res;