summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorScott Griepentrog <sgriepentrog@digium.com>2015-02-26 18:53:36 +0000
committerScott Griepentrog <sgriepentrog@digium.com>2015-02-26 18:53:36 +0000
commitd79670b2694c22ab078e029a6a3b7e066d6ae531 (patch)
treee9061ebe6b0d7e261a36208319003f4909f5e9b4 /main
parentd04fbb0f9df89f55d5696024ba9569279109ce90 (diff)
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/ ........ Merged revisions 432385 from http://svn.asterisk.org/svn/asterisk/branches/13 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@432386 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main')
-rw-r--r--main/dial.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/main/dial.c b/main/dial.c
index a27ac5b59..827b5ef23 100644
--- a/main/dial.c
+++ b/main/dial.c
@@ -206,6 +206,7 @@ static const struct ast_option_types option_types[] = {
{ 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 @@ static enum ast_dial_result monitor_dial(struct ast_dial *dial, struct ast_chann
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;
}