[Asterisk-code-review] res sorcery config.c: Cleanup ao2 container usage idioms. (asterisk[master])
Joshua Colp
asteriskteam at digium.com
Tue Aug 16 08:24:38 CDT 2016
Joshua Colp has submitted this change and it was merged.
Change subject: res_sorcery_config.c: Cleanup ao2 container usage idioms.
......................................................................
res_sorcery_config.c: Cleanup ao2 container usage idioms.
Change-Id: Iad24b335fb121a2bc7f1d048ab7420569edcba5a
---
M res/res_sorcery_config.c
1 file changed, 13 insertions(+), 27 deletions(-)
Approvals:
Mark Michelson: Looks good to me, but someone else must approve
Joshua Colp: Looks good to me, approved; Verified
diff --git a/res/res_sorcery_config.c b/res/res_sorcery_config.c
index 6059a52..852537b 100644
--- a/res/res_sorcery_config.c
+++ b/res/res_sorcery_config.c
@@ -109,22 +109,6 @@
ast_variables_destroy(config->criteria);
}
-/*! \brief Hashing function for sorcery objects */
-static int sorcery_config_hash(const void *obj, const int flags)
-{
- const char *id = obj;
-
- return ast_str_hash(flags & OBJ_KEY ? id : ast_sorcery_object_get_id(obj));
-}
-
-/*! \brief Comparator function for sorcery objects */
-static int sorcery_config_cmp(void *obj, void *arg, int flags)
-{
- const char *id = arg;
-
- return !strcmp(ast_sorcery_object_get_id(obj), flags & OBJ_KEY ? id : ast_sorcery_object_get_id(arg)) ? CMP_MATCH | CMP_STOP : 0;
-}
-
static int sorcery_config_fields_cmp(void *obj, void *arg, int flags)
{
const struct sorcery_config_fields_cmp_params *params = arg;
@@ -145,14 +129,16 @@
return 0;
}
+ /* We want this object */
if (params->container) {
+ /*
+ * We are putting the found objects into the given container instead
+ * of the normal container traversal return mechanism.
+ */
ao2_link(params->container, obj);
-
- /* As multiple objects are being returned keep going */
return 0;
} else {
- /* Immediately stop and return, we only want a single object */
- return CMP_MATCH | CMP_STOP;
+ return CMP_MATCH;
}
}
@@ -179,7 +165,7 @@
struct sorcery_config *config = data;
RAII_VAR(struct ao2_container *, objects, ao2_global_obj_ref(config->objects), ao2_cleanup);
- return objects ? ao2_find(objects, id, OBJ_KEY) : NULL;
+ return objects ? ao2_find(objects, id, OBJ_SEARCH_KEY) : NULL;
}
static void sorcery_config_retrieve_multiple(const struct ast_sorcery *sorcery, void *data, const char *type, struct ao2_container *objects, const struct ast_variable *fields)
@@ -196,7 +182,7 @@
return;
}
- ao2_callback(config_objects, 0, sorcery_config_fields_cmp, ¶ms);
+ ao2_callback(config_objects, OBJ_NODATA | OBJ_MULTIPLE, sorcery_config_fields_cmp, ¶ms);
}
static void sorcery_config_retrieve_regex(const struct ast_sorcery *sorcery, void *data, const char *type, struct ao2_container *objects, const char *regex)
@@ -218,7 +204,7 @@
return;
}
- ao2_callback(config_objects, 0, sorcery_config_fields_cmp, ¶ms);
+ ao2_callback(config_objects, OBJ_NODATA | OBJ_MULTIPLE, sorcery_config_fields_cmp, ¶ms);
regfree(&expression);
}
@@ -280,8 +266,9 @@
ast_debug(2, "Using bucket size of '%d' for objects of type '%s' from '%s'\n",
buckets, type, config->filename);
- if (!(objects = ao2_container_alloc_options(AO2_ALLOC_OPT_LOCK_NOLOCK, buckets,
- sorcery_config_hash, sorcery_config_cmp))) {
+ objects = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_NOLOCK, 0, buckets,
+ ast_sorcery_object_id_hash, NULL, ast_sorcery_object_id_compare);
+ if (!objects) {
ast_log(LOG_ERROR, "Could not create bucket for new objects from '%s', keeping existing objects\n",
config->filename);
ast_config_destroy(cfg);
@@ -300,8 +287,7 @@
/* Confirm an object with this id does not already exist in the bucket.
* If it exists, however, the configuration is invalid so stop
* processing and destroy it. */
- obj = ao2_find(objects, id, OBJ_KEY);
-
+ obj = ao2_find(objects, id, OBJ_SEARCH_KEY);
if (obj) {
ast_log(LOG_ERROR, "Config file '%s' could not be loaded; configuration contains a duplicate object: '%s' of type '%s'\n",
config->filename, id, type);
--
To view, visit https://gerrit.asterisk.org/3497
To unsubscribe, visit https://gerrit.asterisk.org/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Iad24b335fb121a2bc7f1d048ab7420569edcba5a
Gerrit-PatchSet: 2
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: Richard Mudgett <rmudgett at digium.com>
Gerrit-Reviewer: Anonymous Coward #1000019
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Mark Michelson <mmichelson at digium.com>
Gerrit-Reviewer: Matt Jordan <mjordan at digium.com>
More information about the asterisk-code-review
mailing list