[asterisk-commits] russell: trunk r165723 - in /trunk: apps/ include/asterisk/ main/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Dec 18 13:33:43 CST 2008


Author: russell
Date: Thu Dec 18 13:33:42 2008
New Revision: 165723

URL: http://svn.digium.com/view/asterisk?view=rev&rev=165723
Log:
Remove the need for AST_PBX_KEEPALIVE with the GoSub option from Dial.

This is part of an effort to completely remove AST_PBX_KEEPALIVE and other
similar return codes from the source.  While this usage was perfectly safe,
there are others that are problematic.  Since we know ahead of time that
we do not want to PBX to destroy the channel, the PBX API has been changed
so that information can be provided as an argument, instead, thus removing
the need for the KEEPALIVE return value.

Further changes to get rid of KEEPALIVE and related code is being done by
murf.  There is a patch up for that on review 29.

Review: http://reviewboard.digium.com/r/98/

Modified:
    trunk/apps/app_dial.c
    trunk/include/asterisk/pbx.h
    trunk/main/pbx.c

Modified: trunk/apps/app_dial.c
URL: http://svn.digium.com/view/asterisk/trunk/apps/app_dial.c?view=diff&rev=165723&r1=165722&r2=165723
==============================================================================
--- trunk/apps/app_dial.c (original)
+++ trunk/apps/app_dial.c Thu Dec 18 13:33:42 2008
@@ -2082,7 +2082,11 @@
 				if (gosub_args) {
 					res9 = pbx_exec(peer, theapp, gosub_args);
 					if (!res9) {
-						ast_pbx_run(peer);
+						struct ast_pbx_args args;
+						/* A struct initializer fails to compile for this case ... */
+						memset(&args, 0, sizeof(args));
+						args.no_hangup_chan = 1;
+						ast_pbx_run_args(peer, &args);
 					}
 					ast_free(gosub_args);
 					if (option_debug)
@@ -2428,7 +2432,7 @@
 	if (!con)
 		ast_log(LOG_ERROR, "Dial virtual context 'app_dial_gosub_virtual_context' does not exist and unable to create\n");
 	else
-		ast_add_extension2(con, 1, "s", 1, NULL, NULL, "KeepAlive", ast_strdup(""), ast_free_ptr, "app_dial");
+		ast_add_extension2(con, 1, "s", 1, NULL, NULL, "NoOp", ast_strdup(""), ast_free_ptr, "app_dial");
 
 	res = ast_register_application_xml(app, dial_exec);
 	res |= ast_register_application_xml(rapp, retrydial_exec);

Modified: trunk/include/asterisk/pbx.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/pbx.h?view=diff&rev=165723&r1=165722&r2=165723
==============================================================================
--- trunk/include/asterisk/pbx.h (original)
+++ trunk/include/asterisk/pbx.h Thu Dec 18 13:33:42 2008
@@ -291,6 +291,37 @@
  */
 enum ast_pbx_result ast_pbx_run(struct ast_channel *c);
 
+/*!
+ * \brief Options for ast_pbx_run()
+ */
+struct ast_pbx_args {
+	union {
+		/*! Pad this out so that we have plenty of room to add options
+		 *  but still maintain ABI compatibility over time. */
+		uint64_t __padding;
+		struct {
+			/*! Do not hangup the channel when the PBX is complete. */
+			unsigned int no_hangup_chan:1;
+		};
+	};
+};
+
+/*!
+ * \brief Execute the PBX in the current thread
+ *
+ * \param c channel to run the pbx on
+ * \param args options for the pbx
+ *
+ * This executes the PBX on a given channel. It allocates a new
+ * PBX structure for the channel, and provides all PBX functionality.
+ * See ast_pbx_start for an asynchronous function to run the PBX in a
+ * new thread as opposed to the current one.
+ * 
+ * \retval Zero on success
+ * \retval non-zero on failure
+ */
+enum ast_pbx_result ast_pbx_run_args(struct ast_channel *c, struct ast_pbx_args *args);
+
 /*! 
  * \brief Add and extension to an extension context.  
  * 

Modified: trunk/main/pbx.c
URL: http://svn.digium.com/view/asterisk/trunk/main/pbx.c?view=diff&rev=165723&r1=165722&r2=165723
==============================================================================
--- trunk/main/pbx.c (original)
+++ trunk/main/pbx.c Thu Dec 18 13:33:42 2008
@@ -386,16 +386,6 @@
 			and that further input should be allowed before matching can be considered
 			to be complete.  Can be used within a pattern match when certain criteria warrants
 			a longer match.</para>
-		</description>
-	</application>
-	<application name="KeepAlive" language="en_US">
-		<synopsis>
-			Returns AST_PBX_KEEPALIVE value.
-		</synopsis>
-		<syntax />
-		<description>
-			<para>This application is chiefly meant for internal use with Gosubs. Please do not run
-			it alone from the dialplan!</para>
 		</description>
 	</application>
 	<application name="NoOp" language="en_US">
@@ -931,7 +921,6 @@
 static int pbx_builtin_wait(struct ast_channel *, void *);
 static int pbx_builtin_waitexten(struct ast_channel *, void *);
 static int pbx_builtin_incomplete(struct ast_channel *, void *);
-static int pbx_builtin_keepalive(struct ast_channel *, void *);
 static int pbx_builtin_resetcdr(struct ast_channel *, void *);
 static int pbx_builtin_setamaflags(struct ast_channel *, void *);
 static int pbx_builtin_ringing(struct ast_channel *, void *);
@@ -1097,7 +1086,6 @@
 	{ "ImportVar",      pbx_builtin_importvar },
 	{ "Hangup",         pbx_builtin_hangup },
 	{ "Incomplete",     pbx_builtin_incomplete },
-	{ "KeepAlive",      pbx_builtin_keepalive },
 	{ "NoOp",           pbx_builtin_noop },
 	{ "Proceeding",     pbx_builtin_proceeding },
 	{ "Progress",       pbx_builtin_progress },
@@ -4139,7 +4127,8 @@
 	return 0;
 }
 
-static int __ast_pbx_run(struct ast_channel *c)
+static enum ast_pbx_result __ast_pbx_run(struct ast_channel *c, 
+		struct ast_pbx_args *args)
 {
 	int found = 0;	/* set if we find at least one match */
 	int res = 0;
@@ -4352,11 +4341,18 @@
 			}
 		}
 	}
-	if (!found && !error)
+
+	if (!found && !error) {
 		ast_log(LOG_WARNING, "Don't know what to do with '%s'\n", c->name);
-	if (res != AST_PBX_KEEPALIVE)
+	}
+
+	if (!args || !args->no_hangup_chan) {
 		ast_softhangup(c, c->hangupcause ? c->hangupcause : AST_CAUSE_NORMAL_CLEARING);
-	if ((res != AST_PBX_KEEPALIVE) && !ast_test_flag(c, AST_FLAG_BRIDGE_HANGUP_RUN) && ast_exists_extension(c, c->context, "h", 1, c->cid.cid_num)) {
+	}
+
+	if ((!args || !args->no_hangup_chan) &&
+			!ast_test_flag(c, AST_FLAG_BRIDGE_HANGUP_RUN) && 
+			ast_exists_extension(c, c->context, "h", 1, c->cid.cid_num)) {
 		set_ext_pri(c, "h", 1);
 		while ((res = ast_spawn_extension(c, c->context, c->exten, c->priority, c->cid.cid_num, &found, 1)) == 0) {
 			c->priority++;
@@ -4371,8 +4367,11 @@
 	ast_clear_flag(c, AST_FLAG_BRIDGE_HANGUP_RUN); /* from one round to the next, make sure this gets cleared */
 	pbx_destroy(c->pbx);
 	c->pbx = NULL;
-	if (res != AST_PBX_KEEPALIVE)
+
+	if (!args || !args->no_hangup_chan) {
 		ast_hangup(c);
+	}
+
 	return 0;
 }
 
@@ -4462,7 +4461,7 @@
 	 */
 	struct ast_channel *c = data;
 
-	__ast_pbx_run(c);
+	__ast_pbx_run(c, NULL);
 	decrease_call_count();
 
 	pthread_exit(NULL);
@@ -4492,17 +4491,24 @@
 	return AST_PBX_SUCCESS;
 }
 
+enum ast_pbx_result ast_pbx_run_args(struct ast_channel *c, struct ast_pbx_args *args)
+{
+	enum ast_pbx_result res = AST_PBX_SUCCESS;
+
+	if (increase_call_count(c)) {
+		return AST_PBX_CALL_LIMIT;
+	}
+
+	res = __ast_pbx_run(c, args);
+
+	decrease_call_count();
+
+	return res;
+}
+
 enum ast_pbx_result ast_pbx_run(struct ast_channel *c)
 {
-	enum ast_pbx_result res = AST_PBX_SUCCESS;
-
-	if (increase_call_count(c))
-		return AST_PBX_CALL_LIMIT;
-
-	res = __ast_pbx_run(c);
-	decrease_call_count();
-
-	return res;
+	return ast_pbx_run_args(c, NULL);
 }
 
 int ast_active_calls(void)
@@ -8310,11 +8316,6 @@
 	return __ast_answer(chan, delay);
 }
 
-static int pbx_builtin_keepalive(struct ast_channel *chan, void *data)
-{
-	return AST_PBX_KEEPALIVE;
-}
-
 static int pbx_builtin_incomplete(struct ast_channel *chan, void *data)
 {
 	char *options = data;




More information about the asterisk-commits mailing list