[asterisk-commits] rizzo: trunk r47175 - /trunk/apps/app_dial.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Fri Nov 3 15:36:18 MST 2006


Author: rizzo
Date: Fri Nov  3 16:36:17 2006
New Revision: 47175

URL: http://svn.digium.com/view/asterisk?rev=47175&view=rev
Log:
change HANDLE_CAUSE into a function.


Modified:
    trunk/apps/app_dial.c

Modified: trunk/apps/app_dial.c
URL: http://svn.digium.com/view/asterisk/trunk/apps/app_dial.c?rev=47175&r1=47174&r2=47175&view=diff
==============================================================================
--- trunk/apps/app_dial.c (original)
+++ trunk/apps/app_dial.c Fri Nov  3 16:36:17 2006
@@ -318,30 +318,47 @@
 
 #define AST_MAX_WATCHERS 256
 
-#define HANDLE_CAUSE(cause, chan) do { \
-	switch(cause) { \
-	case AST_CAUSE_BUSY: \
-		if (chan->cdr) \
-			ast_cdr_busy(chan->cdr); \
-		numbusy++; \
-		break; \
-	case AST_CAUSE_CONGESTION: \
-		if (chan->cdr) \
-			ast_cdr_failed(chan->cdr); \
-		numcongestion++; \
-		break; \
-	case AST_CAUSE_UNREGISTERED: \
-		if (chan->cdr) \
-			ast_cdr_failed(chan->cdr); \
-		numnochan++; \
-		break; \
-	case AST_CAUSE_NORMAL_CLEARING: \
-		break; \
-	default: \
-		numnochan++; \
-		break; \
-	} \
-} while (0)
+/*
+ * argument to handle_cause() and other functions.
+ */
+struct cause_args {
+	struct ast_channel *chan;
+	int busy;
+	int congestion;
+	int nochan;
+};
+
+static void handle_cause(int cause, struct cause_args *num)
+{
+	struct ast_cdr *cdr = num->chan->cdr;
+
+	switch(cause) {
+	case AST_CAUSE_BUSY:
+		if (cdr)
+			ast_cdr_busy(cdr);
+		num->busy++;
+		break;
+
+	case AST_CAUSE_CONGESTION:
+		if (cdr)
+			ast_cdr_failed(cdr);
+		num->congestion++;
+		break;
+
+	case AST_CAUSE_UNREGISTERED:
+		if (cdr)
+			ast_cdr_failed(cdr);
+		num->nochan++;
+		break;
+
+	case AST_CAUSE_NORMAL_CLEARING:
+		break;
+
+	default:
+		num->nochan++;
+		break;
+	}
+}
 
 /* free the buffer if allocated, and set the pointer to the second arg */
 #define S_REPLACE(s, new_val)		\
@@ -402,12 +419,11 @@
 					src->name, dialstatus);
 }	
 
-static struct ast_channel *wait_for_answer(struct ast_channel *in, struct dial_localuser *outgoing, int *to, struct ast_flags *peerflags, int *sentringing, char *status, size_t statussize, int busystart, int nochanstart, int congestionstart, int priority_jump, int *result)
+static struct ast_channel *wait_for_answer(struct ast_channel *in, struct dial_localuser *outgoing, int *to, struct ast_flags *peerflags, int *sentringing, char *status, size_t statussize,
+	const struct cause_args *num_in, int priority_jump, int *result)
 {
-	int numbusy = busystart;
-	int numcongestion = congestionstart;
-	int numnochan = nochanstart;
-	int prestart = busystart + congestionstart + nochanstart;
+	struct cause_args num = *num_in;
+	int prestart = num.busy + num.congestion + num.nochan;
 	int orig = *to;
 	struct ast_channel *peer = NULL;
 	/* single is set if only one destination is enabled */
@@ -436,20 +452,20 @@
 			numlines++;
 		}
 		if (pos == 1) {	/* only the input channel is available */
-			if (numlines == (numbusy + numcongestion + numnochan)) {
+			if (numlines == (num.busy + num.congestion + num.nochan)) {
 				if (option_verbose > 2)
-					ast_verbose( VERBOSE_PREFIX_2 "Everyone is busy/congested at this time (%d:%d/%d/%d)\n", numlines, numbusy, numcongestion, numnochan);
-				if (numbusy)
+					ast_verbose( VERBOSE_PREFIX_2 "Everyone is busy/congested at this time (%d:%d/%d/%d)\n", numlines, num.busy, num.congestion, num.nochan);
+				if (num.busy)
 					strcpy(status, "BUSY");	
-				else if (numcongestion)
+				else if (num.congestion)
 					strcpy(status, "CONGESTION");
-				else if (numnochan)
+				else if (num.nochan)
 					strcpy(status, "CHANUNAVAIL");
 				if (ast_opt_priority_jumping || priority_jump)
 					ast_goto_if_exists(in, in->context, in->exten, in->priority + 101);
 			} else {
 				if (option_verbose > 2)
-					ast_verbose(VERBOSE_PREFIX_3 "No one is available to answer at this time (%d:%d/%d/%d)\n", numlines, numbusy, numcongestion, numnochan);
+					ast_verbose(VERBOSE_PREFIX_3 "No one is available to answer at this time (%d:%d/%d/%d)\n", numlines, num.busy, num.congestion, num.nochan);
 			}
 			*to = 0;
 			return NULL;
@@ -522,7 +538,7 @@
 				}
 				if (!c) {
 					ast_clear_flag(o, DIAL_STILLGOING);	
-					HANDLE_CAUSE(cause, in);
+					handle_cause(cause, &num);
 				} else {
 					ast_rtp_make_compatible(c, in, single);
 					if (c->cid.cid_num)
@@ -552,7 +568,7 @@
 						ast_clear_flag(o, DIAL_STILLGOING);	
 						ast_hangup(c);
 						c = o->chan = NULL;
-						numnochan++;
+						num.nochan++;
 					} else {
 						senddialevent(in, c);
 						/* After calling, set callerid to extension */
@@ -572,7 +588,7 @@
 				ast_hangup(c);
 				c = o->chan = NULL;
 				ast_clear_flag(o, DIAL_STILLGOING);
-				HANDLE_CAUSE(in->hangupcause, in);
+				handle_cause(in->hangupcause, &num);
 				continue;
 			}
 			if (f->frametype == AST_FRAME_CONTROL) {
@@ -605,7 +621,7 @@
 					ast_hangup(c);
 					c = o->chan = NULL;
 					ast_clear_flag(o, DIAL_STILLGOING);	
-					HANDLE_CAUSE(AST_CAUSE_BUSY, in);
+					handle_cause(AST_CAUSE_BUSY, &num);
 					break;
 				case AST_CONTROL_CONGESTION:
 					if (option_verbose > 2)
@@ -614,7 +630,7 @@
 					ast_hangup(c);
 					c = o->chan = NULL;
 					ast_clear_flag(o, DIAL_STILLGOING);
-					HANDLE_CAUSE(AST_CAUSE_CONGESTION, in);
+					handle_cause(AST_CAUSE_CONGESTION, &num);
 					break;
 				case AST_CONTROL_RINGING:
 					if (option_verbose > 2)
@@ -785,15 +801,13 @@
 
 static int dial_exec_full(struct ast_channel *chan, void *data, struct ast_flags *peerflags)
 {
-	int res = -1;
+	int res = -1;	/* default: error */
 	struct ast_module_user *u;
-	char *rest, *cur;
-	struct dial_localuser *outgoing = NULL;
+	char *rest, *cur;	/* scan the list of destinations */
+	struct dial_localuser *outgoing = NULL;	/* list of destinations */
 	struct ast_channel *peer;
-	int to;
-	int numbusy = 0;
-	int numcongestion = 0;
-	int numnochan = 0;
+	int to;	/* timeout */
+	struct cause_args num = { chan, 0, 0, 0 };
 	int cause;
 	char numsubst[AST_MAX_EXTENSION];
 	char cidname[AST_MAX_EXTENSION];
@@ -1092,7 +1106,7 @@
 		if (!tmp->chan) {
 			/* If we can't, just go on to the next call */
 			ast_log(LOG_WARNING, "Unable to create channel of type '%s' (cause %d - %s)\n", tech, cause, ast_cause2str(cause));
-			HANDLE_CAUSE(cause, chan);
+			handle_cause(cause, &num);
 			if (!rest)	/* we are on the last destination */
 				chan->hangupcause = cause;
 			continue;
@@ -1137,7 +1151,7 @@
 				cause = AST_CAUSE_CONGESTION;
 			}
 			if (!tmp->chan) {
-				HANDLE_CAUSE(cause, chan);
+				handle_cause(cause, &num);
 				continue;
 			}
 		}
@@ -1242,7 +1256,7 @@
 	}
 
 	time(&start_time);
-	peer = wait_for_answer(chan, outgoing, &to, peerflags, &sentringing, status, sizeof(status), numbusy, numnochan, numcongestion, ast_test_flag(&opts, OPT_PRIORITY_JUMP), &result);
+	peer = wait_for_answer(chan, outgoing, &to, peerflags, &sentringing, status, sizeof(status), &num, ast_test_flag(&opts, OPT_PRIORITY_JUMP), &result);
 	
 	if (!peer) {
 		if (result) {



More information about the asterisk-commits mailing list