[asterisk-commits] file: branch file/dialing_api r49345 -
/team/file/dialing_api/main/dial.c
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Wed Jan 3 14:50:28 MST 2007
Author: file
Date: Wed Jan 3 15:50:27 2007
New Revision: 49345
URL: http://svn.digium.com/view/asterisk?view=rev&rev=49345
Log:
Add (untested) async support.
Modified:
team/file/dialing_api/main/dial.c
Modified: team/file/dialing_api/main/dial.c
URL: http://svn.digium.com/view/asterisk/team/file/dialing_api/main/dial.c?view=diff&rev=49345&r1=49344&r2=49345
==============================================================================
--- team/file/dialing_api/main/dial.c (original)
+++ team/file/dialing_api/main/dial.c Wed Jan 3 15:50:27 2007
@@ -111,6 +111,9 @@
/* Initialize list of channels */
AST_LIST_HEAD_INIT_NOLOCK(&dial->channels);
+ /* Initialize thread to NULL */
+ dial->thread = AST_PTHREADT_NULL;
+
return dial;
}
@@ -290,6 +293,40 @@
return;
switch (fr->subclass) {
+ case AST_CONTROL_ANSWER:
+ if (option_verbose > 2)
+ ast_verbose( VERBOSE_PREFIX_3 "%s answered\n", channel->owner->name);
+ AST_LIST_REMOVE(&dial->channels, channel, list);
+ AST_LIST_INSERT_HEAD(&dial->channels, channel, list);
+ dial->status = AST_DIAL_RESULT_ANSWERED;
+ break;
+ case AST_CONTROL_BUSY:
+ if (option_verbose > 2)
+ ast_verbose(VERBOSE_PREFIX_3 "%s is busy\n", channel->owner->name);
+ ast_hangup(channel->owner);
+ channel->owner = NULL;
+ break;
+ case AST_CONTROL_CONGESTION:
+ if (option_verbose > 2)
+ ast_verbose(VERBOSE_PREFIX_3 "%s is circuit-busy\n", channel->owner->name);
+ ast_hangup(channel->owner);
+ channel->owner = NULL;
+ break;
+ case AST_CONTROL_RINGING:
+ if (option_verbose > 2)
+ ast_verbose(VERBOSE_PREFIX_3 "%s is ringing\n", channel->owner->name);
+ dial->status = AST_DIAL_RESULT_RINGING;
+ break;
+ case AST_CONTROL_PROGRESS:
+ if (option_verbose > 2)
+ ast_verbose (VERBOSE_PREFIX_3 "%s is making progress\n", channel->owner->name);
+ dial->status = AST_DIAL_RESULT_PROGRESS;
+ break;
+ case AST_CONTROL_PROCEEDING:
+ if (option_verbose > 2)
+ ast_verbose (VERBOSE_PREFIX_3 "%s is proceeding\n", channel->owner->name);
+ dial->status = AST_DIAL_RESULT_PROCEEDING;
+ break;
default:
break;
}
@@ -300,16 +337,12 @@
/*! \brief Helper function that basically keeps tabs on dialing attempts */
static enum ast_dial_result monitor_dial(struct ast_dial *dial, struct ast_channel *chan)
{
- int single = 0, timeout = -1, count = 0;
+ int timeout = -1, count = 0;
struct ast_channel *cs[AST_MAX_WATCHERS], *who = NULL;
struct ast_dial_channel *channel = NULL;
/* Switch dialing status to trying */
dial->status = AST_DIAL_RESULT_TRYING;
-
- /* See if this is a single dial attempt */
- if (AST_LIST_FIRST(&dial->channels) == AST_LIST_LAST(&dial->channels))
- single = 1;
/* Go into an infinite loop while we are trying */
while (dial->status == AST_DIAL_RESULT_TRYING) {
@@ -389,6 +422,17 @@
return dial->status;
}
+/*! \brief Dial async thread function */
+static void *async_dial(void *data)
+{
+ struct ast_dial *dial = data;
+
+ /* This is really really simple... we basically pass monitor_dial a NULL owner and it changes it's behavior */
+ monitor_dial(dial, NULL);
+
+ return NULL;
+}
+
/*! \brief Execute dialing synchronously or asynchronously
* \note Dials channels in a dial structure.
* \return Returns dial result code. (TRYING/INVALID/FAILED/ANSWERED/TIMEOUT/UNANSWERED).
@@ -411,6 +455,12 @@
/* If we are running async spawn a thread and send it away... otherwise block here */
if (async) {
+ /* Try to create a thread */
+ if (ast_pthread_create(&dial->thread, NULL, async_dial, dial)) {
+ /* Failed to create the thread - hangup all dialed channels and return failed */
+ ast_dial_hangup(dial);
+ res = AST_DIAL_RESULT_FAILED;
+ }
} else {
res = monitor_dial(dial, chan);
}
More information about the asterisk-commits
mailing list