[asterisk-commits] seanbright: branch seanbright/issue13827-1.4 r154795 - in /team/seanbright/is...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Nov 5 12:23:53 CST 2008
Author: seanbright
Date: Wed Nov 5 12:23:52 2008
New Revision: 154795
URL: http://svn.digium.com/view/asterisk?view=rev&rev=154795
Log:
Introduce ast_channel_search_locked and use it.
Modified:
team/seanbright/issue13827-1.4/channels/chan_sip.c
team/seanbright/issue13827-1.4/include/asterisk/channel.h
team/seanbright/issue13827-1.4/main/channel.c
Modified: team/seanbright/issue13827-1.4/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/seanbright/issue13827-1.4/channels/chan_sip.c?view=diff&rev=154795&r1=154794&r2=154795
==============================================================================
--- team/seanbright/issue13827-1.4/channels/chan_sip.c (original)
+++ team/seanbright/issue13827-1.4/channels/chan_sip.c Wed Nov 5 12:23:52 2008
@@ -7435,18 +7435,20 @@
callee must be dialing the same extension that is being monitored. Simply dialing
the hint'd device is not sufficient. */
if (global_notifycid) {
- struct ast_channel *caller = NULL;
-
- while ((caller = ast_channel_walk_locked(caller))) {
- if (caller->pbx &&
- (!strcasecmp(caller->macroexten, p->exten) || !strcasecmp(caller->exten, p->exten)) &&
- !strcasecmp(caller->context, p->context)) {
- local_display = ast_strdupa(caller->cid.cid_name);
- local_target = ast_strdupa(caller->cid.cid_num);
- ast_channel_unlock(caller);
- break;
- }
+ auto int find_calling_channel(struct ast_channel *c);
+ int find_calling_channel(struct ast_channel *c) {
+ return (c->pbx &&
+ (!strcasecmp(c->macroexten, p->exten) || !strcasecmp(c->exten, p->exten)) &&
+ !strcasecmp(c->context, p->context));
+ }
+
+ struct ast_channel *caller = ast_channel_search_locked(find_calling_channel);
+
+ if (caller) {
+ local_display = ast_strdupa(caller->cid.cid_name);
+ local_target = ast_strdupa(caller->cid.cid_num);
ast_channel_unlock(caller);
+ caller = NULL;
}
}
Modified: team/seanbright/issue13827-1.4/include/asterisk/channel.h
URL: http://svn.digium.com/view/asterisk/team/seanbright/issue13827-1.4/include/asterisk/channel.h?view=diff&rev=154795&r1=154794&r2=154795
==============================================================================
--- team/seanbright/issue13827-1.4/include/asterisk/channel.h (original)
+++ team/seanbright/issue13827-1.4/include/asterisk/channel.h Wed Nov 5 12:23:52 2008
@@ -966,6 +966,17 @@
struct ast_channel *ast_walk_channel_by_exten_locked(const struct ast_channel *chan, const char *exten,
const char *context);
+/*! \brief Search for a channel based on the passed channel matching callback
+ * Search for a channel based on the specified is_match callback, and return the
+ * first channel that we match. When returned, the channel will be locked. Note
+ * that the is_match callback is called with the passed channel locked, and should
+ * return 0 if there is no match, and non-zero if there is.
+ * \param is_match callback executed on each channel until non-zero is returned, or we
+ * run out of channels to search.
+ * \return Returns the matched channel, or NULL if no channel was matched.
+ */
+struct ast_channel *ast_channel_search_locked(int (*is_match)(struct ast_channel *));
+
/*! ! \brief Waits for a digit
* \param c channel to wait for a digit on
* \param ms how many milliseconds to wait
Modified: team/seanbright/issue13827-1.4/main/channel.c
URL: http://svn.digium.com/view/asterisk/team/seanbright/issue13827-1.4/main/channel.c?view=diff&rev=154795&r1=154794&r2=154795
==============================================================================
--- team/seanbright/issue13827-1.4/main/channel.c (original)
+++ team/seanbright/issue13827-1.4/main/channel.c Wed Nov 5 12:23:52 2008
@@ -1153,6 +1153,24 @@
const char *context)
{
return channel_find_locked(chan, NULL, 0, context, exten);
+}
+
+/*! \brief Search for a channel based on the passed channel matching callback (first match) and return it, locked */
+struct ast_channel *ast_channel_search_locked(int (*is_match)(struct ast_channel *))
+{
+ struct ast_channel *c = NULL;
+
+ AST_LIST_LOCK(&channels);
+ AST_LIST_TRAVERSE(&channels, c, chan_list) {
+ ast_channel_lock(c);
+ if (is_match(c)) {
+ break;
+ }
+ ast_channel_unlock(c);
+ }
+ AST_LIST_UNLOCK(&channels);
+
+ return c;
}
/*! \brief Wait, look for hangups and condition arg */
More information about the asterisk-commits
mailing list