[asterisk-commits] russell: branch russell/chan_refcount r82350 - in /team/russell/chan_refcount...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Thu Sep 13 16:29:22 CDT 2007
Author: russell
Date: Thu Sep 13 16:29:21 2007
New Revision: 82350
URL: http://svn.digium.com/view/asterisk?view=rev&rev=82350
Log:
Use a nested function that can access the local variables of the calling
function of ast_channel_callback(). This suggestion was made by kpfleming
to simplify the code where I was grouping args into a struct to be passed
to the callback.
Modified:
team/russell/chan_refcount/include/asterisk/channel.h
team/russell/chan_refcount/main/channel.c
team/russell/chan_refcount/res/snmp/agent.c
Modified: team/russell/chan_refcount/include/asterisk/channel.h
URL: http://svn.digium.com/view/asterisk/team/russell/chan_refcount/include/asterisk/channel.h?view=diff&rev=82350&r1=82349&r2=82350
==============================================================================
--- team/russell/chan_refcount/include/asterisk/channel.h (original)
+++ team/russell/chan_refcount/include/asterisk/channel.h Thu Sep 13 16:29:21 2007
@@ -1524,7 +1524,7 @@
/*!
* \brief Call a function with every active channel
*/
-void ast_channel_callback(ao2_callback_fn *cb_fn, void *arg);
+void ast_channel_callback(ao2_callback_fn *cb_fn);
struct ast_channel *ast_channel_get_by_name(const char *name);
Modified: team/russell/chan_refcount/main/channel.c
URL: http://svn.digium.com/view/asterisk/team/russell/chan_refcount/main/channel.c?view=diff&rev=82350&r1=82349&r2=82350
==============================================================================
--- team/russell/chan_refcount/main/channel.c (original)
+++ team/russell/chan_refcount/main/channel.c Thu Sep 13 16:29:21 2007
@@ -1139,9 +1139,9 @@
}
#endif
-void ast_channel_callback(ao2_callback_fn *cb_fn, void *arg)
-{
- ao2_callback(channels, OBJ_NODATA, cb_fn, arg);
+void ast_channel_callback(ao2_callback_fn *cb_fn)
+{
+ ao2_callback(channels, OBJ_NODATA, cb_fn, NULL);
}
struct ast_channel_iterator {
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=82350&r1=82349&r2=82350
==============================================================================
--- team/russell/chan_refcount/res/snmp/agent.c (original)
+++ team/russell/chan_refcount/res/snmp/agent.c Thu Sep 13 16:29:21 2007
@@ -189,16 +189,6 @@
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)
{
@@ -211,13 +201,21 @@
int i, bit;
struct ast_str *out = ast_str_alloca(2048);
+ auto int var_channels_cb(void *obj, void *arg, int flags);
+ int var_channels_cb(void *obj, void *arg, int flags)
+ {
+ if (!--i)
+ return CMP_STOP;
+ return 0;
+ }
+
if (header_simple_table(vp, name, length, exact, var_len, write_method, ast_active_channels()))
return NULL;
i = name[*length - 1] - 1;
if (i)
- ast_channel_callback(var_channels_cb, &i);
+ ast_channel_callback(var_channels_cb);
if (i)
return NULL;
@@ -501,22 +499,6 @@
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)
{
@@ -558,16 +540,22 @@
return (u_char *)&long_ret;
case ASTCHANTYPECHANNELS:
{
- struct chan_tech_channels_args args = {
- .long_ret = &long_ret,
- .tech = tech,
- };
+ auto int chan_tech_channels_cb(void *obj, void *arg, int flags);
+ int chan_tech_channels_cb(void *obj, void *arg, int flags)
+ {
+ struct ast_channel *chan = obj;
+
+ if (chan->tech == tech)
+ long_ret++;
+
+ return 0;
+ }
long_ret = 0;
- ast_channel_callback(chan_tech_channels_cb, &args);
-
- return (u_char *)&long_ret;
+ ast_channel_callback(chan_tech_channels_cb);
+
+ return (u_char *) &long_ret;
}
default:
break;
@@ -575,27 +563,27 @@
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;
+ auto int bridged_count_cb(void *obj, void *arg, int flags);
+ int bridged_count_cb(void *obj, void *arg, int flags)
+ {
+ struct ast_channel *chan = obj;
+
+ if (ast_bridged_channel(chan))
+ long_ret++;
+
+ return 0;
+ }
+
long_ret = 0;
if (header_generic(vp, name, length, exact, var_len, write_method))
return NULL;
- ast_channel_callback(bridged_count_cb, &long_ret);
+ ast_channel_callback(bridged_count_cb);
*var_len = sizeof(long_ret);
More information about the asterisk-commits
mailing list