[asterisk-commits] mmichelson: branch group/CCSS r234370 - /team/group/CCSS/channels/chan_dahdi.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Dec 10 18:22:19 CST 2009


Author: mmichelson
Date: Thu Dec 10 18:22:15 2009
New Revision: 234370

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=234370
Log:
Break apart some of dahdi_request into subroutines.

"Why are you doing this in the CCSS branch?" you might
be asking. Well it will become apparent soon. And by soon,
I mean sometime tomorrow. I've been looking at chan_dahdi
all day today, and I'm done. I feel like my brain has
been deep fried in a vat of feces, and believe me, that's
not a good feeling.


Modified:
    team/group/CCSS/channels/chan_dahdi.c

Modified: team/group/CCSS/channels/chan_dahdi.c
URL: http://svnview.digium.com/svn/asterisk/team/group/CCSS/channels/chan_dahdi.c?view=diff&rev=234370&r1=234369&r2=234370
==============================================================================
--- team/group/CCSS/channels/chan_dahdi.c (original)
+++ team/group/CCSS/channels/chan_dahdi.c Thu Dec 10 18:22:15 2009
@@ -11798,18 +11798,6 @@
 
 static inline int available(struct dahdi_pvt *p, int channelmatch, ast_group_t groupmatch, int *reason, int *channelmatched, int *groupmatched)
 {
-	/* First, check group matching */
-	if (groupmatch) {
-		if ((p->group & groupmatch) != groupmatch)
-			return 0;
-		*groupmatched = 1;
-	}
-	/* Check to see if we have a channel match */
-	if (channelmatch != -1) {
-		if (p->channel != channelmatch)
-			return 0;
-		*channelmatched = 1;
-	}
 
 	if (p->inalarm)
 		return 0;
@@ -12004,25 +11992,15 @@
 	return p;
 }
 
-static struct ast_channel *dahdi_request(const char *type, format_t format, const struct ast_channel *requestor, void *data, int *cause)
-{
-	ast_group_t groupmatch = 0;
-	int channelmatch = -1;
-	int roundrobin = 0;
-	int callwait = 0;
-	int unavailreason = 0;
+static struct dahdi_pvt *determine_starting_point(char *data, ast_group_t *groupmatch, int *channelmatch, int *backwards, int *roundrobin)
+{
+	char *dest;
+	char *s;
+	int x;
+	char opt = 0;
+	int y = 0;
+	int res = 0;
 	struct dahdi_pvt *p;
-	struct ast_channel *tmp = NULL;
-	char *dest;
-	int x;
-	char *s;
-	char opt=0;
-	int res=0, y=0;
-	int backwards = 0;
-	struct dahdi_pvt *exitpvt;
-	int channelmatched = 0;
-	int groupmatched = 0;
-	int transcapdigital = 0;
 	AST_DECLARE_APP_ARGS(args,
 		AST_APP_ARG(group);	/* channel/group token */
 		//AST_APP_ARG(ext);	/* extension token */
@@ -12065,20 +12043,20 @@
 			ast_log(LOG_WARNING, "Unable to determine group for data %s\n", (char *)data);
 			return NULL;
 		}
-		groupmatch = ((ast_group_t) 1 << x);
+		*groupmatch = ((ast_group_t) 1 << x);
 
 		/* Lock the interface list */
 		ast_mutex_lock(&iflock);
 
 		if (toupper(args.group[0]) == 'G') {
 			if (args.group[0] == 'G') {
-				backwards = 1;
+				*backwards = 1;
 				p = ifend;
 			} else
 				p = iflist;
 		} else {
 			if (args.group[0] == 'R') {
-				backwards = 1;
+				*backwards = 1;
 				p = round_robin[x]?round_robin[x]->prev:ifend;
 				if (!p)
 					p = ifend;
@@ -12087,19 +12065,19 @@
 				if (!p)
 					p = iflist;
 			}
-			roundrobin = 1;
+			*roundrobin = 1;
 		}
 	} else {
 		s = args.group;
 		if (!strcasecmp(s, "pseudo")) {
 			/* Special case for pseudo */
 			x = CHAN_PSEUDO;
-			channelmatch = x;
+			*channelmatch = x;
 		} else if ((res = sscanf(s, "%30d%1c%30d", &x, &opt, &y)) < 1) {
 			ast_log(LOG_WARNING, "Unable to determine channel for data %s\n", (char *)data);
 			return NULL;
 		} else {
-			channelmatch = x;
+			*channelmatch = x;
 		}
 
 		/* Lock the interface list */
@@ -12107,6 +12085,28 @@
 
 		p = iflist;
 	}
+	return p;
+}
+
+static struct ast_channel *dahdi_request(const char *type, format_t format, const struct ast_channel *requestor, void *data, int *cause)
+{
+	ast_group_t groupmatch = 0;
+	int channelmatch = -1;
+	int roundrobin = 0;
+	int callwait = 0;
+	int unavailreason = 0;
+	struct dahdi_pvt *p;
+	struct ast_channel *tmp = NULL;
+	int x;
+	char opt=0;
+	int res=0, y=0;
+	int backwards = 0;
+	struct dahdi_pvt *exitpvt;
+	int channelmatched = 0;
+	int groupmatched = 0;
+	int transcapdigital = 0;
+
+	p = determine_starting_point(data, &groupmatch, &channelmatch, &backwards, &roundrobin);
 	/* Search for an unowned channel */
 	exitpvt = p;
 	while (p && !tmp) {
@@ -12115,6 +12115,20 @@
 #if 0
 		ast_verbose("name = %s, %d, %d, %llu\n",p->owner ? p->owner->name : "<none>", p->channel, channelmatch, groupmatch);
 #endif
+		/* First, check group matching */
+		if (groupmatch) {
+			if ((p->group & groupmatch) != groupmatch)
+				/* Doesn't match the specified group, try the next one */
+				goto next;
+			groupmatched = 1;
+		}
+		/* Check to see if we have a channel match */
+		if (channelmatch != -1) {
+			if (p->channel != channelmatch)
+				/* Doesn't match the specified channel, try the next one */
+				goto next;
+			channelmatched = 1;
+		}
 
 		if (p && available(p, channelmatch, groupmatch, &unavailreason, &channelmatched, &groupmatched)) {
 			ast_debug(1, "Using channel %d\n", p->channel);
@@ -12178,9 +12192,7 @@
 				tmp->cdrflags |= AST_CDR_CALLWAIT;
 			break;
 		}
-#ifdef HAVE_OPENR2
 next:
-#endif
 		if (backwards) {
 			p = p->prev;
 			if (!p)




More information about the asterisk-commits mailing list