aboutsummaryrefslogtreecommitdiffstats
path: root/main/astobj2.c
diff options
context:
space:
mode:
authorseanbright <seanbright@f38db490-d61c-443f-a65b-d21fe96a405b>2008-11-07 22:39:30 +0000
committerseanbright <seanbright@f38db490-d61c-443f-a65b-d21fe96a405b>2008-11-07 22:39:30 +0000
commita7a95954c816e072bd44fb884029853a3585db33 (patch)
tree80eea1f19a98b0f9ca3ab09f32d0eea8aa0f85d5 /main/astobj2.c
parentf7be936f69d32c2b9aedb70d25395cb51c01eea6 (diff)
Add ability to pass arbitrary data to the ao2_callback_fn (called from
ao2_callback and ao2_find). Currently, passing OBJ_POINTER to either of these mandates that the passed 'arg' is a hashable object, making searching for an ao2 object based on outside criteria difficult. Reviewed by Russell and Mark M. via ReviewBoard: http://reviewboard.digium.com/r/36/ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@155401 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main/astobj2.c')
-rw-r--r--main/astobj2.c44
1 files changed, 22 insertions, 22 deletions
diff --git a/main/astobj2.c b/main/astobj2.c
index 2e9070d6d..d1fdcaaf7 100644
--- a/main/astobj2.c
+++ b/main/astobj2.c
@@ -135,7 +135,7 @@ static struct ao2_container *__ao2_container_alloc(struct ao2_container *c, cons
ao2_callback_fn *cmp_fn);
static struct bucket_list *__ao2_link(struct ao2_container *c, void *user_data);
static void *__ao2_callback(struct ao2_container *c,
- const enum search_flags flags, ao2_callback_fn *cb_fn, void *arg,
+ const enum search_flags flags, ao2_callback_fn *cb_fn, void *arg, void *data,
char *tag, char *file, int line, const char *funcname);
static void * __ao2_iterator_next(struct ao2_iterator *a, struct bucket_list **q);
@@ -511,7 +511,7 @@ void *_ao2_link(struct ao2_container *c, void *user_data)
/*!
* \brief another convenience function is a callback that matches on address
*/
-int ao2_match_by_addr(void *user_data, void *arg, int flags)
+int ao2_match_by_addr(void *user_data, void *arg, void *data, int flags)
{
return (user_data == arg) ? (CMP_MATCH | CMP_STOP) : 0;
}
@@ -526,7 +526,7 @@ void *_ao2_unlink_debug(struct ao2_container *c, void *user_data, char *tag,
if (INTERNAL_OBJ(user_data) == NULL) /* safety check on the argument */
return NULL;
- _ao2_callback_debug(c, OBJ_UNLINK | OBJ_POINTER | OBJ_NODATA, ao2_match_by_addr, user_data, tag, file, line, funcname);
+ _ao2_callback_debug(c, OBJ_UNLINK | OBJ_POINTER | OBJ_NODATA, ao2_match_by_addr, user_data, NULL, tag, file, line, funcname);
return NULL;
}
@@ -536,7 +536,7 @@ void *_ao2_unlink(struct ao2_container *c, void *user_data)
if (INTERNAL_OBJ(user_data) == NULL) /* safety check on the argument */
return NULL;
- _ao2_callback(c, OBJ_UNLINK | OBJ_POINTER | OBJ_NODATA, ao2_match_by_addr, user_data);
+ _ao2_callback(c, OBJ_UNLINK | OBJ_POINTER | OBJ_NODATA, ao2_match_by_addr, user_data, NULL);
return NULL;
}
@@ -544,7 +544,7 @@ void *_ao2_unlink(struct ao2_container *c, void *user_data)
/*!
* \brief special callback that matches all
*/
-static int cb_true(void *user_data, void *arg, int flags)
+static int cb_true(void *user_data, void *arg, void *data, int flags)
{
ast_log(LOG_ERROR,"If you see this, something is strange!\n");
return CMP_MATCH;
@@ -559,7 +559,7 @@ static int cb_true(void *user_data, void *arg, int flags)
* called as often as, say, the ao2_ref func is called.
*/
static void *__ao2_callback(struct ao2_container *c,
- const enum search_flags flags, ao2_callback_fn *cb_fn, void *arg,
+ const enum search_flags flags, ao2_callback_fn *cb_fn, void *arg, void *data,
char *tag, char *file, int line, const char *funcname)
{
int i, last; /* search boundaries */
@@ -602,7 +602,7 @@ static void *__ao2_callback(struct ao2_container *c,
struct bucket_list *cur;
AST_LIST_TRAVERSE_SAFE_BEGIN(&c->buckets[i], cur, entry) {
- int match = cb_fn(EXTERNAL_OBJ(cur->astobj), arg, flags) & (CMP_MATCH | CMP_STOP);
+ int match = cb_fn(EXTERNAL_OBJ(cur->astobj), arg, data, flags) & (CMP_MATCH | CMP_STOP);
/* we found the object, performing operations according flags */
if (match == 0) { /* no match, no stop, continue */
@@ -658,29 +658,29 @@ static void *__ao2_callback(struct ao2_container *c,
void *_ao2_callback_debug(struct ao2_container *c,
const enum search_flags flags,
- ao2_callback_fn *cb_fn, void *arg,
+ ao2_callback_fn *cb_fn, void *arg, void *data,
char *tag, char *file, int line, const char *funcname)
{
- return __ao2_callback(c,flags, cb_fn, arg, tag, file, line, funcname);
+ return __ao2_callback(c,flags, cb_fn, arg, data, tag, file, line, funcname);
}
void *_ao2_callback(struct ao2_container *c,const enum search_flags flags,
- ao2_callback_fn *cb_fn, void *arg)
+ ao2_callback_fn *cb_fn, void *arg, void *data)
{
- return __ao2_callback(c,flags, cb_fn, arg, NULL, NULL, 0, NULL);
+ return __ao2_callback(c,flags, cb_fn, arg, data, NULL, NULL, 0, NULL);
}
/*!
* the find function just invokes the default callback with some reasonable flags.
*/
-void *_ao2_find_debug(struct ao2_container *c, void *arg, enum search_flags flags, char *tag, char *file, int line, const char *funcname)
+void *_ao2_find_debug(struct ao2_container *c, void *arg, void *data, enum search_flags flags, char *tag, char *file, int line, const char *funcname)
{
- return _ao2_callback_debug(c, flags, c->cmp_fn, arg, tag, file, line, funcname);
+ return _ao2_callback_debug(c, flags, c->cmp_fn, arg, data, tag, file, line, funcname);
}
-void *_ao2_find(struct ao2_container *c, void *arg, enum search_flags flags)
+void *_ao2_find(struct ao2_container *c, void *arg, void *data, enum search_flags flags)
{
- return _ao2_callback(c, flags, c->cmp_fn, arg);
+ return _ao2_callback(c, flags, c->cmp_fn, arg, data);
}
/*!
@@ -793,13 +793,13 @@ void * _ao2_iterator_next(struct ao2_iterator *a)
/* callback for destroying container.
* we can make it simple as we know what it does
*/
-static int cd_cb(void *obj, void *arg, int flag)
+static int cd_cb(void *obj, void *arg, void *data, int flag)
{
_ao2_ref(obj, -1);
return 0;
}
-static int cd_cb_debug(void *obj, void *arg, int flag)
+static int cd_cb_debug(void *obj, void *arg, void *data, int flag)
{
_ao2_ref_debug(obj, -1, "deref object via container destroy", __FILE__, __LINE__, __PRETTY_FUNCTION__);
return 0;
@@ -810,7 +810,7 @@ static void container_destruct(void *_c)
struct ao2_container *c = _c;
int i;
- _ao2_callback(c, OBJ_UNLINK, cd_cb, NULL);
+ _ao2_callback(c, OBJ_UNLINK, cd_cb, NULL, NULL);
for (i = 0; i < c->n_buckets; i++) {
struct bucket_list *current;
@@ -830,7 +830,7 @@ static void container_destruct_debug(void *_c)
struct ao2_container *c = _c;
int i;
- _ao2_callback_debug(c, OBJ_UNLINK, cd_cb_debug, NULL, "container_destruct_debug called", __FILE__, __LINE__, __PRETTY_FUNCTION__);
+ _ao2_callback_debug(c, OBJ_UNLINK, cd_cb_debug, NULL, NULL, "container_destruct_debug called", __FILE__, __LINE__, __PRETTY_FUNCTION__);
for (i = 0; i < c->n_buckets; i++) {
struct bucket_list *current;
@@ -846,7 +846,7 @@ static void container_destruct_debug(void *_c)
}
#ifdef AO2_DEBUG
-static int print_cb(void *obj, void *arg, int flag)
+static int print_cb(void *obj, void *arg, void *data, int flag)
{
int *fd = arg;
char *s = (char *)obj;
@@ -938,7 +938,7 @@ static char *handle_astobj2_test(struct ast_cli_entry *e, int cmd, struct ast_cl
ao2_t_ref(obj, -1, "test");
}
ast_cli(a->fd, "testing callbacks\n");
- ao2_t_callback(c1, 0, print_cb, &a->fd,"test callback");
+ ao2_t_callback(c1, 0, print_cb, &a->fd, NULL, "test callback");
ast_cli(a->fd, "testing iterators, remove every second object\n");
{
struct ao2_iterator ai;
@@ -959,7 +959,7 @@ static char *handle_astobj2_test(struct ast_cli_entry *e, int cmd, struct ast_cl
}
}
ast_cli(a->fd, "testing callbacks again\n");
- ao2_t_callback(c1, 0, print_cb, &a->fd,"test callback");
+ ao2_t_callback(c1, 0, print_cb, &a->fd, NULL, "test callback");
ast_verbose("now you should see an error message:\n");
ao2_t_ref(&i, -1, ""); /* i is not a valid object so we print an error here */