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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sat Mar 21 11:55:11 CDT 2009


Author: russell
Date: Sat Mar 21 11:55:06 2009
New Revision: 183631

URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=183631
Log:
simplify pickup by name with ast_channel_callback()

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=183631&r1=183630&r2=183631
==============================================================================
--- team/russell/ast_channel_ao2/apps/app_directed_pickup.c (original)
+++ team/russell/ast_channel_ao2/apps/app_directed_pickup.c Sat Mar 21 11:55:06 2009
@@ -121,18 +121,35 @@
 		return 0;
 }
 
+struct pickup_by_name_args {
+	const char *name;
+	size_t len;
+};
+
+static int pickup_by_name_cb(void *obj, void *arg, void *data, int flags)
+{
+	struct ast_channel *chan = obj;
+	struct pickup_by_name_args *args = data;
+
+	ast_channel_lock(chan);
+	if (!strncasecmp(chan->name, args->name, args->len) && can_pickup(chan)) {
+		/* Return with the channel still locked on purpose */
+		return CMP_MATCH | CMP_STOP;
+	}
+	ast_channel_unlock(chan);
+
+	return 0;
+}
+
 /*! \brief Helper Function to walk through ALL channels checking NAME and STATE */
 static struct ast_channel *my_ast_get_channel_by_name_locked(const char *channame)
 {
-	struct ast_channel *chan = NULL;
 	char *chkchan;
-	size_t channame_len, chkchan_len;
-	struct ast_channel_iterator *iter;
-
-	channame_len = strlen(channame);
-	chkchan_len = channame_len + 2;
-
-	chkchan = alloca(chkchan_len);
+	struct pickup_by_name_args pickup_args;
+
+	pickup_args.len = strlen(channame) + 2;
+
+	chkchan = alloca(pickup_args.len);
 
 	/* need to append a '-' for the comparison so we check full channel name,
 	 * i.e SIP/hgc- , use a temporary variable so original stays the same for
@@ -141,22 +158,9 @@
 	strcpy(chkchan, channame);
 	strcat(chkchan, "-");
 
-	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)) {
-			break;
-		}
-		ast_channel_unlock(chan);
-		chan = ast_channel_unref(chan);
-	}
-
-	ast_channel_iterator_destroy(iter);
-
-	return chan;
+	pickup_args.name = chkchan;
+
+	return ast_channel_callback(pickup_by_name_cb, NULL, &pickup_args, 0);
 }
 
 /*! \brief Attempt to pick up specified channel named , does not use context */




More information about the asterisk-commits mailing list