[asterisk-commits] russell: branch russell/ast_channel_ao2 r174146 - /team/russell/ast_channel_a...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sat Feb 7 09:07:13 CST 2009


Author: russell
Date: Sat Feb  7 09:07:13 2009
New Revision: 174146

URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=174146
Log:
convert app_directed_pickup

Modified:
    team/russell/ast_channel_ao2/apps/app_directed_pickup.c

Modified: team/russell/ast_channel_ao2/apps/app_directed_pickup.c
URL: http://svn.digium.com/svn-view/asterisk/team/russell/ast_channel_ao2/apps/app_directed_pickup.c?view=diff&rev=174146&r1=174145&r2=174146
==============================================================================
--- team/russell/ast_channel_ao2/apps/app_directed_pickup.c (original)
+++ team/russell/ast_channel_ao2/apps/app_directed_pickup.c Sat Feb  7 09:07:13 2009
@@ -127,6 +127,7 @@
 	struct ast_channel *chan;
 	char *chkchan;
 	size_t channame_len, chkchan_len;
+	struct ast_channel_iterator *iter;
 
 	channame_len = strlen(channame);
 	chkchan_len = channame_len + 2;
@@ -140,14 +141,21 @@
 	strcpy(chkchan, channame);
 	strcat(chkchan, "-");
 
-	for (chan = ast_walk_channel_by_name_prefix_locked(NULL, channame, channame_len);
-		 chan;
-		 chan = ast_walk_channel_by_name_prefix_locked(chan, channame, channame_len)) {
+	if (!(iter = ast_channel_iterator_by_name_new(0, channame, channame_len))) {
+		return NULL;
+	}
+
+	while ((chan = ast_channel_iterator_next(iter))) {
+		ast_channel_lock(chan);
 		if (!strncasecmp(chan->name, chkchan, chkchan_len) && can_pickup(chan)) {
 			return chan;
 		}
 		ast_channel_unlock(chan);
-	}
+		chan = ast_channel_unref(chan);
+	}
+
+	ast_channel_iterator_destroy(iter);
+
 	return NULL;
 }
 
@@ -164,69 +172,73 @@
 	if (chan->name != target->name && chan != target) {
 		res = pickup_do(chan, target);
 		ast_channel_unlock(target);
-	}
-
-	return res;
-}
-
-struct pickup_criteria {
-	const char *exten;
-	const char *context;
-};
-
-static int find_by_exten(struct ast_channel *c, void *data)
-{
-	struct pickup_criteria *info = data;
-
-	return (!strcasecmp(c->macroexten, info->exten) || !strcasecmp(c->exten, info->exten)) &&
-		!strcasecmp(c->dialcontext, info->context) &&
-		can_pickup(c);
+		target = ast_channel_unref(target);
+	}
+
+	return res;
 }
 
 /* Attempt to pick up specified extension with context */
 static int pickup_by_exten(struct ast_channel *chan, const char *exten, const char *context)
 {
 	struct ast_channel *target = NULL;
-	struct pickup_criteria search = {
-		.exten = exten,
-		.context = context,
-	};
-
-	target = ast_channel_search_locked(find_by_exten, &search);
+	struct ast_channel_iterator *iter;
+	int res = -1;
+
+	if (!(iter = ast_channel_iterator_by_exten_new(0, exten, context))) {
+		return -1;
+	}
+
+	while ((target = ast_channel_iterator_next(iter))) {
+		ast_channel_lock(target);
+		if (can_pickup(target)) {
+			break;
+		}
+		ast_channel_unlock(chan);
+		target = ast_channel_unref(target);
+	}
 
 	if (target) {
-		int res = pickup_do(chan, target);
+		res = pickup_do(chan, target);
 		ast_channel_unlock(target);
-		target = NULL;
-		return res;
-	}
-
-	return -1;
-}
-
-static int find_by_mark(struct ast_channel *c, void *data)
-{
+		target = ast_channel_unref(target);
+	}
+
+	return res;
+}
+
+static int find_by_mark(void *obj, void *arg, void *data, int flags)
+{
+	struct ast_channel *c = obj;
 	const char *mark = data;
 	const char *tmp;
-
-	return (tmp = pbx_builtin_getvar_helper(c, PICKUPMARK)) &&
+	int res;
+	
+	ast_channel_lock(c);
+
+	res = (tmp = pbx_builtin_getvar_helper(c, PICKUPMARK)) &&
 		!strcasecmp(tmp, mark) &&
 		can_pickup(c);
+	
+	ast_channel_unlock(c);
+
+	return res ? CMP_MATCH | CMP_STOP : 0;
 }
 
 /* Attempt to pick up specified mark */
 static int pickup_by_mark(struct ast_channel *chan, const char *mark)
 {
-	struct ast_channel *target = ast_channel_search_locked(find_by_mark, (char *) mark);
-
-	if (target) {
-		int res = pickup_do(chan, target);
+	struct ast_channel *target;
+	int res = -1;
+
+	if ((target = ast_channel_callback(find_by_mark, NULL, (char *) mark, 0))) {
+		ast_channel_lock(target);
+		res = pickup_do(chan, target);
 		ast_channel_unlock(target);
-		target = NULL;
-		return res;
-	}
-
-	return -1;
+		target = ast_channel_unref(target);
+	}
+
+	return res;
 }
 
 /* application entry point for Pickup() */




More information about the asterisk-commits mailing list