[svn-commits] mnicholson: trunk r317803 - in /trunk: UPGRADE.txt pbx/pbx_lua.c

SVN commits to the Digium repositories svn-commits at lists.digium.com
Fri May 6 14:02:01 CDT 2011


Author: mnicholson
Date: Fri May  6 14:01:57 2011
New Revision: 317803

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=317803
Log:
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.

Modified:
    trunk/UPGRADE.txt
    trunk/pbx/pbx_lua.c

Modified: trunk/UPGRADE.txt
URL: http://svnview.digium.com/svn/asterisk/trunk/UPGRADE.txt?view=diff&rev=317803&r1=317802&r2=317803
==============================================================================
--- trunk/UPGRADE.txt (original)
+++ trunk/UPGRADE.txt Fri May  6 14:01:57 2011
@@ -47,6 +47,7 @@
    (such as app.goto).  Now when an application such as app.goto() is called,
    control is returned back to the pbx engine and the current extension
    function stops executing.
+ - autoservice_start() and autoservice_start() no longer return a value.
 
 ===========================================================
 ===========================================================

Modified: trunk/pbx/pbx_lua.c
URL: http://svnview.digium.com/svn/asterisk/trunk/pbx/pbx_lua.c?view=diff&rev=317803&r1=317802&r2=317803
==============================================================================
--- trunk/pbx/pbx_lua.c (original)
+++ trunk/pbx/pbx_lua.c Fri May  6 14:01:57 2011
@@ -717,26 +717,28 @@
  * 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);
-
-	lua_pushboolean(L, !res);
+	ast_autoservice_start(chan);
+
+	lua_pushboolean(L, 1);
 	lua_setfield(L, LUA_REGISTRYINDEX, "autoservice");
-
-	lua_pushboolean(L, !res);
-	return 1;
+	return 0;
 }
 
 /*!
@@ -748,26 +750,28 @@
  * 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 @@
 		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 @@
 		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;




More information about the svn-commits mailing list