diff options
author | Sean Bright <sean@malleable.com> | 2008-11-07 22:39:30 +0000 |
---|---|---|
committer | Sean Bright <sean@malleable.com> | 2008-11-07 22:39:30 +0000 |
commit | 30d1744ffce823312d51379585e8c19f722ea4d6 (patch) | |
tree | 80eea1f19a98b0f9ca3ab09f32d0eea8aa0f85d5 /main | |
parent | bd3f685f205c602554b84f458e6bc67a37d4d3c0 (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: https://origsvn.digium.com/svn/asterisk/trunk@155401 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main')
-rw-r--r-- | main/astobj2.c | 44 | ||||
-rw-r--r-- | main/config.c | 4 | ||||
-rw-r--r-- | main/features.c | 4 | ||||
-rw-r--r-- | main/manager.c | 4 | ||||
-rw-r--r-- | main/taskprocessor.c | 6 |
5 files changed, 31 insertions, 31 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 */ diff --git a/main/config.c b/main/config.c index c4d6e6f31..6726b7ac2 100644 --- a/main/config.c +++ b/main/config.c @@ -149,7 +149,7 @@ static int hash_string(const void *obj, const int flags) return total; } -static int hashtab_compare_strings(void *a, void *b, int flags) +static int hashtab_compare_strings(void *a, void *b, void *data, int flags) { const struct inclfile *ae = a, *be = b; return !strcmp(ae->fname, be->fname) ? CMP_MATCH | CMP_STOP : 0; @@ -1509,7 +1509,7 @@ static void set_fn(char *fn, int fn_size, const char *file, const char *configfi else snprintf(fn, fn_size, "%s/%s", ast_config_AST_CONFIG_DIR, file); lookup.fname = fn; - *fi = ao2_find(fileset, &lookup, OBJ_POINTER); + *fi = ao2_find(fileset, &lookup, NULL, OBJ_POINTER); if (!(*fi)) { /* set up a file scratch pad */ struct inclfile *fx = ao2_alloc(sizeof(struct inclfile), inclfile_destroy); diff --git a/main/features.c b/main/features.c index 16fb8ea0e..276328365 100644 --- a/main/features.c +++ b/main/features.c @@ -295,7 +295,7 @@ static int parkinglot_hash_cb(const void *obj, const int flags) return ast_str_hash(parkinglot->name); } -static int parkinglot_cmp_cb(void *obj, void *arg, int flags) +static int parkinglot_cmp_cb(void *obj, void *arg, void *data, int flags) { struct ast_parkinglot *parkinglot = obj, *parkinglot2 = arg; return !strcasecmp(parkinglot->name, parkinglot2->name) ? CMP_MATCH | CMP_STOP : 0; @@ -2838,7 +2838,7 @@ struct ast_parkinglot *find_parkinglot(const char *name) ast_copy_string(tmp_parkinglot.name, name, sizeof(tmp_parkinglot.name)); - parkinglot = ao2_find(parkinglots, &tmp_parkinglot, OBJ_POINTER); + parkinglot = ao2_find(parkinglots, &tmp_parkinglot, NULL, OBJ_POINTER); if (parkinglot && option_debug) ast_log(LOG_DEBUG, "Found Parkinglot: %s\n", parkinglot->name); diff --git a/main/manager.c b/main/manager.c index 8f4917309..9292c739e 100644 --- a/main/manager.c +++ b/main/manager.c @@ -3558,7 +3558,7 @@ static int variable_count_hash_fn(const void *vvc, const int flags) return res; } -static int variable_count_cmp_fn(void *obj, void *vstr, int flags) +static int variable_count_cmp_fn(void *obj, void *vstr, void *data, int flags) { /* Due to the simplicity of struct variable_count, it makes no difference * if you pass in objects or strings, the same operation applies. This is @@ -3667,7 +3667,7 @@ static void xml_translate(struct ast_str **out, char *in, struct ast_variable *v if (!in_data) { /* build appropriate line start */ ast_str_append(out, 0, xml ? " " : "<tr><td>"); - if ((vc = ao2_find(vco, var, 0))) + if ((vc = ao2_find(vco, var, NULL, 0))) vc->count++; else { /* Create a new entry for this one */ diff --git a/main/taskprocessor.c b/main/taskprocessor.c index 6ed939b45..d8287257e 100644 --- a/main/taskprocessor.c +++ b/main/taskprocessor.c @@ -93,7 +93,7 @@ AST_MUTEX_DEFINE_STATIC(cli_ping_cond_lock); /*! \brief The astobj2 hash callback for taskprocessors */ static int tps_hash_cb(const void *obj, const int flags); /*! \brief The astobj2 compare callback for taskprocessors */ -static int tps_cmp_cb(void *obj, void *arg, int flags); +static int tps_cmp_cb(void *obj, void *arg, void *data, int flags); /*! \brief The task processing function executed by a taskprocessor */ static void *tps_processing_function(void *data); @@ -335,7 +335,7 @@ static int tps_hash_cb(const void *obj, const int flags) } /* compare callback for astobj2 */ -static int tps_cmp_cb(void *obj, void *arg, int flags) +static int tps_cmp_cb(void *obj, void *arg, void *data, int flags) { struct ast_taskprocessor *lhs = obj, *rhs = arg; @@ -415,7 +415,7 @@ struct ast_taskprocessor *ast_taskprocessor_get(char *name, enum ast_tps_options return NULL; } ao2_lock(tps_singletons); - p = ao2_find(tps_singletons, &tmp_tps, OBJ_POINTER); + p = ao2_find(tps_singletons, &tmp_tps, NULL, OBJ_POINTER); if (p) { ao2_unlock(tps_singletons); return p; |