[asterisk-commits] sgriepentrog: branch 13 r432385 - in /branches/13: include/asterisk/ main/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Feb 26 12:53:05 CST 2015


Author: sgriepentrog
Date: Thu Feb 26 12:52:56 2015
New Revision: 432385

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=432385
Log:
Dial API: add self destruct option when complete

This patch adds a self-destruction option to the
dial api.  The usefulness of this is mostly when
using async mode to spawn a separate thread used
to handle the new call, while the calling thread
is allowed to go on about other business.

The only alternative to this option would be the
calling thread spawning a new thread, or hanging
around itself waiting to destroy the dial struct
after completion.

Example of use (minus error checking):

  struct ast_dial *dial = ast_dial_create();

  ast_dial_append(dial, "PJSIP", "200", NULL);

  ast_dial_option_global_enable(dial, AST_DIAL_OPTION_ANSWER_EXEC, "Echo");
  ast_dial_option_global_enable(dial, AST_DIAL_OPTION_SELF_DESTROY, NULL);

  ast_dial_run(dial, NULL, 1);

The dial_run call will return almost immediately
after spawning the new thread to run and monitor
the dial.  If the call is answered, it is placed
into the echo app.  When completed, it will call
ast_dial_destroy() on the dial structure.

Note that any allocations made to pass values to
ast_dial_set_user_data() or dial options must be
free'd in a state callback function on any of:
  AST_DIAL_RESULT_UNASWERED,
  AST_DIAL_RESULT_ANSWERED,
  AST_DIAL_RESULT_HANGUP, or 
  AST_DIAL_RESULT_TIMEOUT.

Review: https://reviewboard.asterisk.org/r/4443/


Modified:
    branches/13/include/asterisk/dial.h
    branches/13/main/dial.c

Modified: branches/13/include/asterisk/dial.h
URL: http://svnview.digium.com/svn/asterisk/branches/13/include/asterisk/dial.h?view=diff&rev=432385&r1=432384&r2=432385
==============================================================================
--- branches/13/include/asterisk/dial.h (original)
+++ branches/13/include/asterisk/dial.h Thu Feb 26 12:52:56 2015
@@ -46,6 +46,7 @@
 	AST_DIAL_OPTION_DISABLE_CALL_FORWARDING, /*!< Disable call forwarding on channels */
 	AST_DIAL_OPTION_PREDIAL,                 /*!< Execute a predial subroutine before dialing */
 	AST_DIAL_OPTION_DIAL_REPLACES_SELF,      /*!< The dial operation is a replacement for the requester */
+	AST_DIAL_OPTION_SELF_DESTROY,            /*!< Destroy self at end of ast_dial_run */
 	AST_DIAL_OPTION_MAX,                     /*!< End terminator -- must always remain last */
 };
 

Modified: branches/13/main/dial.c
URL: http://svnview.digium.com/svn/asterisk/branches/13/main/dial.c?view=diff&rev=432385&r1=432384&r2=432385
==============================================================================
--- branches/13/main/dial.c (original)
+++ branches/13/main/dial.c Thu Feb 26 12:52:56 2015
@@ -206,6 +206,7 @@
 	{ AST_DIAL_OPTION_DISABLE_CALL_FORWARDING, NULL, NULL },                  /*!< Disable call forwarding on channels */
 	{ AST_DIAL_OPTION_PREDIAL, predial_enable, predial_disable },             /*!< Execute a subroutine on the outbound channels prior to dialing */
 	{ AST_DIAL_OPTION_DIAL_REPLACES_SELF, NULL, NULL },                       /*!< The dial operation is a replacement for the requester */
+	{ AST_DIAL_OPTION_SELF_DESTROY, NULL, NULL},                              /*!< Destroy self at end of ast_dial_run */
 	{ AST_DIAL_OPTION_MAX, NULL, NULL },                                      /*!< Terminator of list */
 };
 
@@ -889,6 +890,13 @@
 		AST_LIST_UNLOCK(&dial->channels);
 	}
 
+	if (dial->options[AST_DIAL_OPTION_SELF_DESTROY]) {
+		enum ast_dial_result state = dial->state;
+
+		ast_dial_destroy(dial);
+		return state;
+	}
+
 	return dial->state;
 }
 




More information about the asterisk-commits mailing list