[asterisk-commits] russell: branch russell/chan_refcount r82343 - /team/russell/chan_refcount/re...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Thu Sep 13 14:54:32 CDT 2007
Author: russell
Date: Thu Sep 13 14:54:31 2007
New Revision: 82343
URL: http://svn.digium.com/view/asterisk?view=rev&rev=82343
Log:
convert res_snmp to new functions for iterating channels
Modified:
team/russell/chan_refcount/res/snmp/agent.c
Modified: team/russell/chan_refcount/res/snmp/agent.c
URL: http://svn.digium.com/view/asterisk/team/russell/chan_refcount/res/snmp/agent.c?view=diff&rev=82343&r1=82342&r2=82343
==============================================================================
--- team/russell/chan_refcount/res/snmp/agent.c (original)
+++ team/russell/chan_refcount/res/snmp/agent.c Thu Sep 13 14:54:31 2007
@@ -189,6 +189,16 @@
return (u_char *)&long_ret;
}
+static int var_channels_cb(void *obj, void *arg, int flags)
+{
+ int *i = arg;
+
+ if (!--(*i))
+ return CMP_STOP;
+
+ return 0;
+}
+
static u_char *ast_var_channels_table(struct variable *vp, oid *name, size_t *length,
int exact, size_t *var_len, WriteMethod **write_method)
{
@@ -205,12 +215,13 @@
return NULL;
i = name[*length - 1] - 1;
- for (chan = ast_channel_walk_locked(NULL);
- chan && i;
- chan = ast_channel_walk_locked(chan), i--)
- ast_channel_unlock(chan);
- if (chan == NULL)
- return NULL;
+
+ if (i)
+ ast_channel_callback(var_channels_cb, &i);
+
+ if (i)
+ return NULL;
+
*var_len = sizeof(long_ret);
switch (vp->magic) {
@@ -490,13 +501,28 @@
return (u_char *)&long_ret;
}
+struct chan_tech_channels_args {
+ unsigned long *long_ret;
+ const struct ast_channel_tech *tech;
+};
+
+static int chan_tech_channels_cb(void *obj, void *arg, int flags)
+{
+ struct chan_tech_channels_args *args = arg;
+ struct ast_channel *chan = obj;
+
+ if (chan->tech == args->tech)
+ args->long_ret++;
+
+ return 0;
+}
+
static u_char *ast_var_channel_types_table(struct variable *vp, oid *name, size_t *length,
int exact, size_t *var_len, WriteMethod **write_method)
{
const struct ast_channel_tech *tech = NULL;
struct ast_variable *channel_types, *next;
static unsigned long long_ret;
- struct ast_channel *chan;
u_long i;
if (header_simple_table(vp, name, length, exact, var_len, write_method, -1))
@@ -531,34 +557,45 @@
long_ret = tech->transfer ? 1 : 2;
return (u_char *)&long_ret;
case ASTCHANTYPECHANNELS:
+ {
+ struct chan_tech_channels_args args = {
+ .long_ret = &long_ret,
+ .tech = tech,
+ };
+
long_ret = 0;
- for (chan = ast_channel_walk_locked(NULL); chan; chan = ast_channel_walk_locked(chan)) {
- ast_channel_unlock(chan);
- if (chan->tech == tech)
- long_ret++;
- }
- return (u_char *)&long_ret;
+
+ ast_channel_callback(chan_tech_channels_cb, &args);
+
+ return (u_char *)&long_ret;
+ }
default:
break;
}
return NULL;
}
+static int bridged_count_cb(void *obj, void *arg, int flags)
+{
+ unsigned long *long_ret = arg;
+ struct ast_channel *chan = obj;
+
+ if (ast_bridged_channel(chan))
+ (*long_ret)++;
+
+ return 0;
+}
+
static u_char *ast_var_channel_bridge(struct variable *vp, oid *name, size_t *length,
int exact, size_t *var_len, WriteMethod **write_method)
{
static unsigned long long_ret;
- struct ast_channel *chan = NULL;
long_ret = 0;
if (header_generic(vp, name, length, exact, var_len, write_method))
return NULL;
- while ((chan = ast_channel_walk_locked(chan))) {
- if (ast_bridged_channel(chan))
- long_ret++;
- ast_channel_unlock(chan);
- }
+ ast_channel_callback(bridged_count_cb, &long_ret);
*var_len = sizeof(long_ret);
More information about the asterisk-commits
mailing list