[asterisk-commits] file: branch file/dialing_api r49335 - in /team/file/dialing_api: include/ast...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Wed Jan 3 10:49:03 MST 2007


Author: file
Date: Wed Jan  3 11:49:03 2007
New Revision: 49335

URL: http://svn.digium.com/view/asterisk?view=rev&rev=49335
Log:
Change the way information is stored and add thread information for async running.

Modified:
    team/file/dialing_api/include/asterisk/dial.h
    team/file/dialing_api/main/dial.c

Modified: team/file/dialing_api/include/asterisk/dial.h
URL: http://svn.digium.com/view/asterisk/team/file/dialing_api/include/asterisk/dial.h?view=diff&rev=49335&r1=49334&r2=49335
==============================================================================
--- team/file/dialing_api/include/asterisk/dial.h (original)
+++ team/file/dialing_api/include/asterisk/dial.h Wed Jan  3 11:49:03 2007
@@ -42,6 +42,11 @@
 /*! \brief List of return codes for dial run API calls */
 enum ast_dial_result {
 	AST_DIAL_RESULT_INVALID = 0, /*! Invalid options were passed to run function */
+	AST_DIAL_RESULT_FAILED,      /*! Attempts to dial failed before reaching critical state */
+	AST_DIAL_RESULT_TRYING,      /*! Currently trying to dial */
+	AST_DIAL_RESULT_RINGING,     /*! Dial is presently ringing */
+	AST_DIAL_RESULT_PROGRESS,    /*! Dial is presently progressing */
+	AST_DIAL_RESULT_PROCEEDING,  /*! Dial is presently proceeding */
 	AST_DIAL_RESULT_ANSWERED,    /*! A channel was answered */
 	AST_DIAL_RESULT_TIMEOUT,     /*! Timeout was tripped, nobody answered */
 	AST_DIAL_RESULT_HANGUP,      /*! Caller hung up */

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=49335&r1=49334&r2=49335
==============================================================================
--- team/file/dialing_api/main/dial.c (original)
+++ team/file/dialing_api/main/dial.c Wed Jan  3 11:49:03 2007
@@ -46,9 +46,10 @@
 /*! \brief Main dialing structure. Contains global options, channels being dialed, and more! */
 struct ast_dial {
 	int num;                                           /*! Current number to give to next dialed channel */
+	enum ast_dial_result status;                       /*! Status of dial */
 	void *options[AST_DIAL_OPTION_MAX];                /*! Global options */
-	struct ast_channel *answered;                      /*! Channel that answered */
 	AST_LIST_HEAD_NOLOCK(, ast_dial_channel) channels; /*! Channels being dialed */
+	pthread_t thread;                                  /*! Thread (if running in async) */
 };
 
 /*! \brief Dialing channel structure. Contains per-channel dialing options, asterisk channel, and more! */
@@ -219,9 +220,8 @@
 enum ast_dial_result ast_dial_run(struct ast_dial *dial, struct ast_channel *chan, int timeout)
 {
 	int to_monitor = 0, single = 0;
-	struct ast_channel *cs[AST_MAX_WATCHERS] = {NULL, };
+	struct ast_channel *cs[AST_MAX_WATCHERS] = {NULL, }, *who = NULL;
 	struct ast_dial_channel *channel = NULL;
-	enum ast_dial_result res = AST_DIAL_RESULT_INVALID;
 
 	/* Ensure required arguments are passed */
 	if (!dial || !chan)
@@ -233,10 +233,13 @@
 
 	/* Dial each requested channel */
 	if (!(to_monitor = begin_dial(dial, chan)))
-		return AST_DIAL_RESULT_INVALID;
+		return AST_DIAL_RESULT_FAILED;
 
 	/* Increment by one since we have to monitor our own channel */
 	to_monitor++;
+
+	/* Set status to be in progress */
+	dial->status = AST_DIAL_RESULT_TRYING;
 
 	/* See if this is just a single dial */
 	if (AST_LIST_FIRST(&dial->channels) == AST_LIST_LAST(&dial->channels))
@@ -247,14 +250,13 @@
 		timeout = -1;
 
 	/* Go into a loop monitoring channels */
-	while (res == AST_DIAL_RESULT_INVALID) {
+	while (dial->status == AST_DIAL_RESULT_INVALID) {
 		int pos = 1;
-		struct ast_channel *who = NULL;
 		struct ast_frame *fr = NULL;
 
 		/* If we are down to a single channel to monitor then our attempts have failed */
 		if (to_monitor == 1) {
-			res = AST_DIAL_RESULT_UNANSWERED;
+			dial->status = AST_DIAL_RESULT_UNANSWERED;
 			break;
 		}
 		
@@ -279,8 +281,8 @@
 		if (!(fr = ast_read(who))) {
 			if (IS_CALLER(chan, who)) {
 				/* This is the caller who hung up */
-				res = AST_DIAL_RESULT_HANGUP;
-				continue;
+				dial->status = AST_DIAL_RESULT_HANGUP;
+				break;
 			}
 			ast_hangup(who);
 			channel->owner = NULL;
@@ -294,8 +296,10 @@
 			case AST_CONTROL_ANSWER:
 				if (option_verbose > 2)
 					ast_verbose( VERBOSE_PREFIX_3 "%s answered %s\n", who->name, chan->name);
-				dial->answered = who;
-				res = AST_DIAL_RESULT_ANSWERED;
+				/* This is sort of cheeky but what we do is make the first channel in the list the answered channel */
+				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)
@@ -358,11 +362,11 @@
 	}
 
 	/* Based on the result code we can determine what to do next */
-	switch (res) {
+	switch (dial->status) {
 	case AST_DIAL_RESULT_ANSWERED:
 		/* A channel was answered, so hang up all our other attempts */
 		AST_LIST_TRAVERSE(&dial->channels, channel, list) {
-			if (channel->owner && channel->owner != dial->answered) {
+			if (channel->owner && channel->owner != who) {
 				ast_hangup(channel->owner);
 				channel->owner = NULL;
 			}
@@ -383,7 +387,7 @@
 		break;
 	}
 
-	return res;
+	return dial->status;
 }
 
 /*! \brief Execute dialing asynchronously
@@ -405,7 +409,10 @@
  */
 struct ast_channel *ast_dial_answered(struct ast_dial *dial)
 {
-	return (dial ? dial->answered : NULL);
+	if (!dial)
+		return NULL;
+
+	return ((dial->status == AST_DIAL_RESULT_ANSWERED) ? AST_LIST_FIRST(&dial->channels)->owner : NULL);
 }
 
 /*! \brief Hangup channels



More information about the asterisk-commits mailing list