[Asterisk-code-review] core: Use macros to generate ao2 container callbacks where p... (asterisk[13])
Jenkins2
asteriskteam at digium.com
Wed Jan 3 07:49:58 CST 2018
Jenkins2 has submitted this change and it was merged. ( https://gerrit.asterisk.org/7781 )
Change subject: core: Use macros to generate ao2_container callbacks where possible.
......................................................................
core: Use macros to generate ao2_container callbacks where possible.
This uses AO2_STRING_FIELD_HASH_FN and AO2_STRING_FIELD_CMP_FN where
possible in the Asterisk core.
This removes CMP_STOP from the result of CMP_FN callbacks for the
following structure types:
* ast_bucket_metadata
* ast_bucket_scheme
* generic_monitor_instance_list (ccss.c)
* named_acl
Change-Id: Ide4c1449a894bce70dea1fef664dade9b57578f1
---
M main/bucket.c
M main/ccss.c
M main/cel.c
M main/codec.c
M main/endpoints.c
M main/format.c
M main/named_acl.c
M main/named_locks.c
M main/sorcery.c
9 files changed, 52 insertions(+), 605 deletions(-)
Approvals:
Joshua Colp: Looks good to me, but someone else must approve
George Joseph: Looks good to me, approved
Jenkins2: Approved for Submit
diff --git a/main/bucket.c b/main/bucket.c
index 7618761..084d253 100644
--- a/main/bucket.c
+++ b/main/bucket.c
@@ -560,33 +560,10 @@
}
/*! \brief Hashing function for file metadata */
-static int bucket_file_metadata_hash(const void *obj, const int flags)
-{
- const struct ast_bucket_metadata *object;
- const char *key;
-
- switch (flags & (OBJ_POINTER | OBJ_KEY | OBJ_PARTIAL_KEY)) {
- case OBJ_KEY:
- key = obj;
- return ast_str_hash(key);
- case OBJ_POINTER:
- object = obj;
- return ast_str_hash(object->name);
- default:
- /* Hash can only work on something with a full key */
- ast_assert(0);
- return 0;
- }
-}
+AO2_STRING_FIELD_HASH_FN(ast_bucket_metadata, name)
/*! \brief Comparison function for file metadata */
-static int bucket_file_metadata_cmp(void *obj, void *arg, int flags)
-{
- struct ast_bucket_metadata *metadata1 = obj, *metadata2 = arg;
- const char *name = arg;
-
- return !strcmp(metadata1->name, flags & OBJ_KEY ? name : metadata2->name) ? CMP_MATCH | CMP_STOP : 0;
-}
+AO2_STRING_FIELD_CMP_FN(ast_bucket_metadata, name)
/*! \brief Destructor for bucket files */
static void bucket_file_destroy(void *obj)
@@ -616,7 +593,7 @@
}
file->metadata = ao2_container_alloc_options(AO2_ALLOC_OPT_LOCK_NOLOCK, METADATA_BUCKETS,
- bucket_file_metadata_hash, bucket_file_metadata_cmp);
+ ast_bucket_metadata_hash_fn, ast_bucket_metadata_cmp_fn);
if (!file->metadata) {
return NULL;
}
@@ -851,33 +828,10 @@
}
/*! \brief Hashing function for scheme container */
-static int bucket_scheme_hash(const void *obj, const int flags)
-{
- const struct ast_bucket_scheme *object;
- const char *key;
-
- switch (flags & (OBJ_POINTER | OBJ_KEY | OBJ_PARTIAL_KEY)) {
- case OBJ_KEY:
- key = obj;
- return ast_str_hash(key);
- case OBJ_POINTER:
- object = obj;
- return ast_str_hash(object->name);
- default:
- /* Hash can only work on something with a full key */
- ast_assert(0);
- return 0;
- }
-}
+AO2_STRING_FIELD_HASH_FN(ast_bucket_scheme, name)
/*! \brief Comparison function for scheme container */
-static int bucket_scheme_cmp(void *obj, void *arg, int flags)
-{
- struct ast_bucket_scheme *scheme1 = obj, *scheme2 = arg;
- const char *name = arg;
-
- return !strcmp(scheme1->name, flags & OBJ_KEY ? name : scheme2->name) ? CMP_MATCH | CMP_STOP : 0;
-}
+AO2_STRING_FIELD_CMP_FN(ast_bucket_scheme, name)
/*! \brief Cleanup function for graceful shutdowns */
static void bucket_cleanup(void)
@@ -910,8 +864,8 @@
{
ast_register_cleanup(&bucket_cleanup);
- schemes = ao2_container_alloc_options(AO2_ALLOC_OPT_LOCK_RWLOCK, SCHEME_BUCKETS, bucket_scheme_hash,
- bucket_scheme_cmp);
+ schemes = ao2_container_alloc_options(AO2_ALLOC_OPT_LOCK_RWLOCK, SCHEME_BUCKETS,
+ ast_bucket_scheme_hash_fn, ast_bucket_scheme_cmp_fn);
if (!schemes) {
ast_log(LOG_ERROR, "Failed to create container for Bucket schemes\n");
return -1;
diff --git a/main/ccss.c b/main/ccss.c
index ca0c17c..f11fe1d 100644
--- a/main/ccss.c
+++ b/main/ccss.c
@@ -1386,19 +1386,8 @@
int core_id;
};
-static int generic_monitor_hash_fn(const void *obj, const int flags)
-{
- const struct generic_monitor_instance_list *generic_list = obj;
- return ast_str_hash(generic_list->device_name);
-}
-
-static int generic_monitor_cmp_fn(void *obj, void *arg, int flags)
-{
- const struct generic_monitor_instance_list *generic_list1 = obj;
- const struct generic_monitor_instance_list *generic_list2 = arg;
-
- return !strcmp(generic_list1->device_name, generic_list2->device_name) ? CMP_MATCH | CMP_STOP : 0;
-}
+AO2_STRING_FIELD_HASH_FN(generic_monitor_instance_list, device_name)
+AO2_STRING_FIELD_CMP_FN(generic_monitor_instance_list, device_name)
static struct generic_monitor_instance_list *find_generic_monitor_instance_list(const char * const device_name)
{
@@ -4671,8 +4660,8 @@
return -1;
}
if (!(generic_monitors = ao2_t_container_alloc(CC_CORE_INSTANCES_BUCKETS,
- generic_monitor_hash_fn, generic_monitor_cmp_fn,
- "Create generic monitor container"))) {
+ generic_monitor_instance_list_hash_fn, generic_monitor_instance_list_cmp_fn,
+ "Create generic monitor container"))) {
return -1;
}
if (!(cc_core_taskprocessor = ast_taskprocessor_get("CCSS_core", TPS_REF_DEFAULT))) {
diff --git a/main/cel.c b/main/cel.c
index 24d7faa..31cd045 100644
--- a/main/cel.c
+++ b/main/cel.c
@@ -331,129 +331,16 @@
};
/*! \brief Hashing function for cel_backend */
-static int cel_backend_hash(const void *obj, int flags)
-{
- const struct cel_backend *backend;
- const char *name;
-
- switch (flags & OBJ_SEARCH_MASK) {
- case OBJ_SEARCH_OBJECT:
- backend = obj;
- name = backend->name;
- break;
- case OBJ_SEARCH_KEY:
- name = obj;
- break;
- default:
- /* Hash can only work on something with a full key. */
- ast_assert(0);
- return 0;
- }
-
- return ast_str_hash(name);
-}
+AO2_STRING_FIELD_HASH_FN(cel_backend, name)
/*! \brief Comparator function for cel_backend */
-static int cel_backend_cmp(void *obj, void *arg, int flags)
-{
- const struct cel_backend *object_left = obj;
- const struct cel_backend *object_right = arg;
- const char *right_key = arg;
- int cmp;
-
- switch (flags & OBJ_SEARCH_MASK) {
- case OBJ_SEARCH_OBJECT:
- right_key = object_right->name;
- /* Fall through */
- case OBJ_SEARCH_KEY:
- cmp = strcmp(object_left->name, right_key);
- break;
- case OBJ_SEARCH_PARTIAL_KEY:
- /*
- * We could also use a partial key struct containing a length
- * so strlen() does not get called for every comparison instead.
- */
- cmp = strncmp(object_left->name, right_key, strlen(right_key));
- break;
- default:
- /*
- * What arg points to is specific to this traversal callback
- * and has no special meaning to astobj2.
- */
- cmp = 0;
- break;
- }
- if (cmp) {
- return 0;
- }
- /*
- * At this point the traversal callback is identical to a sorted
- * container.
- */
- return CMP_MATCH;
-}
+AO2_STRING_FIELD_CMP_FN(cel_backend, name)
/*! \brief Hashing function for dialstatus container */
-static int dialstatus_hash(const void *obj, int flags)
-{
- const struct cel_dialstatus *dialstatus;
- const char *key;
-
- switch (flags & OBJ_SEARCH_MASK) {
- case OBJ_SEARCH_KEY:
- key = obj;
- break;
- case OBJ_SEARCH_OBJECT:
- dialstatus = obj;
- key = dialstatus->uniqueid;
- break;
- default:
- /* Hash can only work on something with a full key. */
- ast_assert(0);
- return 0;
- }
- return ast_str_hash(key);
-}
+AO2_STRING_FIELD_HASH_FN(cel_dialstatus, uniqueid)
/*! \brief Comparator function for dialstatus container */
-static int dialstatus_cmp(void *obj, void *arg, int flags)
-{
- struct cel_dialstatus *object_left = obj;
- struct cel_dialstatus *object_right = arg;
- const char *right_key = arg;
- int cmp;
-
- switch (flags & OBJ_SEARCH_MASK) {
- case OBJ_SEARCH_OBJECT:
- right_key = object_right->uniqueid;
- /* Fall through */
- case OBJ_SEARCH_KEY:
- cmp = strcmp(object_left->uniqueid, right_key);
- break;
- case OBJ_SEARCH_PARTIAL_KEY:
- /*
- * We could also use a partial key struct containing a length
- * so strlen() does not get called for every comparison instead.
- */
- cmp = strncmp(object_left->uniqueid, right_key, strlen(right_key));
- break;
- default:
- /*
- * What arg points to is specific to this traversal callback
- * and has no special meaning to astobj2.
- */
- cmp = 0;
- break;
- }
- if (cmp) {
- return 0;
- }
- /*
- * At this point the traversal callback is identical to a sorted
- * container.
- */
- return CMP_MATCH;
-}
+AO2_STRING_FIELD_CMP_FN(cel_dialstatus, uniqueid)
unsigned int ast_cel_check_enabled(void)
{
@@ -1667,71 +1554,14 @@
return ret;
}
-static int lid_hash(const void *obj, const int flags)
-{
- const struct cel_linkedid *lid;
- const char *key;
-
- switch (flags & OBJ_SEARCH_MASK) {
- case OBJ_SEARCH_KEY:
- key = obj;
- break;
- case OBJ_SEARCH_OBJECT:
- lid = obj;
- key = lid->id;
- break;
- default:
- /* Hash can only work on something with a full key. */
- ast_assert(0);
- return 0;
- }
- return ast_str_hash(key);
-}
-
-static int lid_cmp(void *obj, void *arg, int flags)
-{
- const struct cel_linkedid *object_left = obj;
- const struct cel_linkedid *object_right = arg;
- const char *right_key = arg;
- int cmp;
-
- switch (flags & OBJ_SEARCH_MASK) {
- case OBJ_SEARCH_OBJECT:
- right_key = object_right->id;
- /* Fall through */
- case OBJ_SEARCH_KEY:
- cmp = strcmp(object_left->id, right_key);
- break;
- case OBJ_SEARCH_PARTIAL_KEY:
- /*
- * We could also use a partial key struct containing a length
- * so strlen() does not get called for every comparison instead.
- */
- cmp = strncmp(object_left->id, right_key, strlen(right_key));
- break;
- default:
- /*
- * What arg points to is specific to this traversal callback
- * and has no special meaning to astobj2.
- */
- cmp = 0;
- break;
- }
- if (cmp) {
- return 0;
- }
- /*
- * At this point the traversal callback is identical to a sorted
- * container.
- */
- return CMP_MATCH;
-}
+AO2_STRING_FIELD_HASH_FN(cel_linkedid, id)
+AO2_STRING_FIELD_CMP_FN(cel_linkedid, id)
int ast_cel_engine_init(void)
{
struct ao2_container *container;
- container = ao2_container_alloc(NUM_APP_BUCKETS, lid_hash, lid_cmp);
+ container = ao2_container_alloc(NUM_APP_BUCKETS, cel_linkedid_hash_fn, cel_linkedid_cmp_fn);
ao2_global_obj_replace_unref(cel_linkedids, container);
ao2_cleanup(container);
if (!container) {
@@ -1740,7 +1570,7 @@
}
container = ao2_container_alloc(NUM_DIALSTATUS_BUCKETS,
- dialstatus_hash, dialstatus_cmp);
+ cel_dialstatus_hash_fn, cel_dialstatus_cmp_fn);
ao2_global_obj_replace_unref(cel_dialstatus_store, container);
ao2_cleanup(container);
if (!container) {
@@ -1758,7 +1588,7 @@
return -1;
}
- container = ao2_container_alloc(BACKEND_BUCKETS, cel_backend_hash, cel_backend_cmp);
+ container = ao2_container_alloc(BACKEND_BUCKETS, cel_backend_hash_fn, cel_backend_cmp_fn);
ao2_global_obj_replace_unref(cel_backends, container);
ao2_cleanup(container);
if (!container) {
diff --git a/main/codec.c b/main/codec.c
index d0e6368..05cee4a 100644
--- a/main/codec.c
+++ b/main/codec.c
@@ -75,24 +75,7 @@
int __ast_codec_register_with_format(struct ast_codec *codec, const char *format_name,
struct ast_module *mod);
-static int codec_hash(const void *obj, int flags)
-{
- const struct ast_codec *codec;
- const char *key;
-
- switch (flags & OBJ_SEARCH_MASK) {
- case OBJ_SEARCH_KEY:
- key = obj;
- return ast_str_hash(key);
- case OBJ_SEARCH_OBJECT:
- codec = obj;
- return ast_str_hash(codec->name);
- default:
- /* Hash can only work on something with a full key. */
- ast_assert(0);
- return 0;
- }
-}
+AO2_STRING_FIELD_HASH_FN(ast_codec, name)
static int codec_cmp(void *obj, void *arg, int flags)
{
@@ -267,7 +250,8 @@
int ast_codec_init(void)
{
- codecs = ao2_container_alloc_options(AO2_ALLOC_OPT_LOCK_RWLOCK, CODEC_BUCKETS, codec_hash, codec_cmp);
+ codecs = ao2_container_alloc_options(AO2_ALLOC_OPT_LOCK_RWLOCK, CODEC_BUCKETS,
+ ast_codec_hash_fn, codec_cmp);
if (!codecs) {
return -1;
}
diff --git a/main/endpoints.c b/main/endpoints.c
index 80e7f87..88506a4 100644
--- a/main/endpoints.c
+++ b/main/endpoints.c
@@ -78,53 +78,8 @@
struct stasis_forward *tech_forward;
};
-static int endpoint_hash(const void *obj, int flags)
-{
- const struct ast_endpoint *endpoint;
- const char *key;
-
- switch (flags & OBJ_SEARCH_MASK) {
- case OBJ_SEARCH_KEY:
- key = obj;
- return ast_str_hash(key);
- case OBJ_SEARCH_OBJECT:
- endpoint = obj;
- return ast_str_hash(endpoint->id);
- default:
- /* Hash can only work on something with a full key. */
- ast_assert(0);
- return 0;
- }
-}
-
-static int endpoint_cmp(void *obj, void *arg, int flags)
-{
- const struct ast_endpoint *left = obj;
- const struct ast_endpoint *right = arg;
- const char *right_key = arg;
- int cmp;
-
- switch (flags & OBJ_SEARCH_MASK) {
- case OBJ_SEARCH_OBJECT:
- right_key = right->id;
- /* Fall through */
- case OBJ_SEARCH_KEY:
- cmp = strcmp(left->id, right_key);
- break;
- case OBJ_SEARCH_PARTIAL_KEY:
- cmp = strncmp(left->id, right_key, strlen(right_key));
- break;
- default:
- ast_assert(0);
- cmp = 0;
- break;
- }
- if (cmp) {
- return 0;
- }
-
- return CMP_MATCH;
-}
+AO2_STRING_FIELD_HASH_FN(ast_endpoint, id)
+AO2_STRING_FIELD_CMP_FN(ast_endpoint, id)
struct ast_endpoint *ast_endpoint_find_by_id(const char *id)
{
@@ -524,14 +479,14 @@
{
ast_register_cleanup(endpoint_cleanup);
- endpoints = ao2_container_alloc(ENDPOINT_BUCKETS, endpoint_hash,
- endpoint_cmp);
+ endpoints = ao2_container_alloc(ENDPOINT_BUCKETS, ast_endpoint_hash_fn,
+ ast_endpoint_cmp_fn);
if (!endpoints) {
return -1;
}
- tech_endpoints = ao2_container_alloc(TECH_ENDPOINT_BUCKETS, endpoint_hash,
- endpoint_cmp);
+ tech_endpoints = ao2_container_alloc(TECH_ENDPOINT_BUCKETS, ast_endpoint_hash_fn,
+ ast_endpoint_cmp_fn);
if (!tech_endpoints) {
return -1;
}
diff --git a/main/format.c b/main/format.c
index 758a7fc..b81a1f1 100644
--- a/main/format.c
+++ b/main/format.c
@@ -64,53 +64,8 @@
/*! \brief Container for registered format interfaces */
static struct ao2_container *interfaces;
-static int format_interface_hash(const void *obj, int flags)
-{
- const struct format_interface *format_interface;
- const char *key;
-
- switch (flags & OBJ_SEARCH_MASK) {
- case OBJ_SEARCH_KEY:
- key = obj;
- return ast_str_hash(key);
- case OBJ_SEARCH_OBJECT:
- format_interface = obj;
- return ast_str_hash(format_interface->codec);
- default:
- /* Hash can only work on something with a full key. */
- ast_assert(0);
- return 0;
- }
-}
-
-static int format_interface_cmp(void *obj, void *arg, int flags)
-{
- const struct format_interface *left = obj;
- const struct format_interface *right = arg;
- const char *right_key = arg;
- int cmp;
-
- switch (flags & OBJ_SEARCH_MASK) {
- case OBJ_SEARCH_OBJECT:
- cmp = strcmp(left->codec, right->codec);
- break;
- case OBJ_SEARCH_KEY:
- cmp = strcmp(left->codec, right_key);
- break;
- case OBJ_SEARCH_PARTIAL_KEY:
- cmp = strncmp(left->codec, right_key, strlen(right_key));
- break;
- default:
- ast_assert(0);
- cmp = 0;
- break;
- }
- if (cmp) {
- return 0;
- }
-
- return CMP_MATCH;
-}
+AO2_STRING_FIELD_HASH_FN(format_interface, codec)
+AO2_STRING_FIELD_CMP_FN(format_interface, codec)
/*! \brief Function called when the process is shutting down */
static void format_shutdown(void)
@@ -121,8 +76,8 @@
int ast_format_init(void)
{
- interfaces = ao2_container_alloc_options(AO2_ALLOC_OPT_LOCK_RWLOCK, FORMAT_INTERFACE_BUCKETS, format_interface_hash,
- format_interface_cmp);
+ interfaces = ao2_container_alloc_options(AO2_ALLOC_OPT_LOCK_RWLOCK, FORMAT_INTERFACE_BUCKETS,
+ format_interface_hash_fn, format_interface_cmp_fn);
if (!interfaces) {
return -1;
}
diff --git a/main/named_acl.c b/main/named_acl.c
index 458d4d3..9ea8990 100644
--- a/main/named_acl.c
+++ b/main/named_acl.c
@@ -107,19 +107,8 @@
char name[ACL_NAME_LENGTH]; /* Same max length as a configuration category */
};
-static int named_acl_hash_fn(const void *obj, const int flags)
-{
- const struct named_acl *entry = obj;
- return ast_str_hash(entry->name);
-}
-
-static int named_acl_cmp_fn(void *obj, void *arg, const int flags)
-{
- struct named_acl *entry1 = obj;
- struct named_acl *entry2 = arg;
-
- return (!strcmp(entry1->name, entry2->name)) ? (CMP_MATCH | CMP_STOP) : 0;
-}
+AO2_STRING_FIELD_HASH_FN(named_acl, name)
+AO2_STRING_FIELD_CMP_FN(named_acl, name)
/*! \brief destructor for named_acl_config */
static void named_acl_config_destructor(void *obj)
diff --git a/main/named_locks.c b/main/named_locks.c
index 5960483..6b41f2a 100644
--- a/main/named_locks.c
+++ b/main/named_locks.c
@@ -39,46 +39,8 @@
char key[0];
};
-static int named_locks_hash(const void *obj, const int flags)
-{
- const struct ast_named_lock *lock = obj;
-
- switch (flags & OBJ_SEARCH_MASK) {
- case OBJ_SEARCH_KEY:
- return ast_str_hash(obj);
- case OBJ_SEARCH_OBJECT:
- return ast_str_hash(lock->key);
- default:
- /* Hash can only work on something with a full key. */
- ast_assert(0);
- return 0;
- }
-}
-
-static int named_locks_cmp(void *obj_left, void *obj_right, int flags)
-{
- const struct ast_named_lock *object_left = obj_left;
- const struct ast_named_lock *object_right = obj_right;
- const char *right_key = obj_right;
- int cmp;
-
- switch (flags & OBJ_SEARCH_MASK) {
- case OBJ_SEARCH_OBJECT:
- right_key = object_right->key;
- /* Fall through */
- case OBJ_SEARCH_KEY:
- cmp = strcmp(object_left->key, right_key);
- break;
- case OBJ_SEARCH_PARTIAL_KEY:
- cmp = strncmp(object_left->key, right_key, strlen(right_key));
- break;
- default:
- cmp = 0;
- break;
- }
-
- return cmp ? 0 : CMP_MATCH;
-}
+AO2_STRING_FIELD_HASH_FN(ast_named_lock, key)
+AO2_STRING_FIELD_CMP_FN(ast_named_lock, key)
static void named_locks_shutdown(void)
{
@@ -88,7 +50,7 @@
int ast_named_locks_init(void)
{
named_locks = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
- NAMED_LOCKS_BUCKETS, named_locks_hash, NULL, named_locks_cmp);
+ NAMED_LOCKS_BUCKETS, ast_named_lock_hash_fn, NULL, ast_named_lock_cmp_fn);
if (!named_locks) {
return -1;
}
diff --git a/main/sorcery.c b/main/sorcery.c
index cb0aff5..c20854f 100644
--- a/main/sorcery.c
+++ b/main/sorcery.c
@@ -336,101 +336,14 @@
}
/*! \brief Hashing function for sorcery wizards */
-static int sorcery_wizard_hash(const void *obj, const int flags)
-{
- const struct ast_sorcery_internal_wizard *object;
- const char *key;
-
- switch (flags & OBJ_SEARCH_MASK) {
- case OBJ_SEARCH_KEY:
- key = obj;
- break;
- case OBJ_SEARCH_OBJECT:
- object = obj;
- key = object->callbacks.name;
- break;
- default:
- ast_assert(0);
- return 0;
- }
- return ast_str_hash(key);
-}
+AO2_STRING_FIELD_HASH_FN(ast_sorcery_internal_wizard, callbacks.name)
/*! \brief Comparator function for sorcery wizards */
-static int sorcery_wizard_cmp(void *obj, void *arg, int flags)
-{
- const struct ast_sorcery_internal_wizard *object_left = obj;
- const struct ast_sorcery_internal_wizard *object_right = arg;
- const char *right_key = arg;
- int cmp;
-
- switch (flags & OBJ_SEARCH_MASK) {
- case OBJ_SEARCH_OBJECT:
- right_key = object_right->callbacks.name;
- /* Fall through */
- case OBJ_SEARCH_KEY:
- cmp = strcmp(object_left->callbacks.name, right_key);
- break;
- case OBJ_SEARCH_PARTIAL_KEY:
- cmp = strncmp(object_left->callbacks.name, right_key, strlen(right_key));
- break;
- default:
- cmp = 0;
- break;
- }
- if (cmp) {
- return 0;
- }
- return CMP_MATCH;
-}
+AO2_STRING_FIELD_CMP_FN(ast_sorcery_internal_wizard, callbacks.name)
/*! \brief Hashing function for sorcery wizards */
-static int object_type_field_hash(const void *obj, const int flags)
-{
- const struct ast_sorcery_object_field *object_field;
- const char *key;
-
- switch (flags & OBJ_SEARCH_MASK) {
- case OBJ_SEARCH_KEY:
- key = obj;
- break;
- case OBJ_SEARCH_OBJECT:
- object_field = obj;
- key = object_field->name;
- break;
- default:
- ast_assert(0);
- return 0;
- }
- return ast_str_hash(key);
-}
-
-static int object_type_field_cmp(void *obj, void *arg, int flags)
-{
- const struct ast_sorcery_object_field *field_left = obj;
- const struct ast_sorcery_object_field *field_right = arg;
- const char *right_key = arg;
- int cmp;
-
- switch (flags & OBJ_SEARCH_MASK) {
- case OBJ_SEARCH_OBJECT:
- right_key = field_right->name;
- /* Fall through */
- case OBJ_SEARCH_KEY:
- cmp = strcmp(field_left->name, right_key);
- break;
- case OBJ_SEARCH_PARTIAL_KEY:
- cmp = strncmp(field_left->name, right_key, strlen(right_key));
- break;
- default:
- cmp = 0;
- break;
- }
- if (cmp) {
- return 0;
- }
- return CMP_MATCH;
-}
+AO2_STRING_FIELD_HASH_FN(ast_sorcery_object_field, name)
+AO2_STRING_FIELD_CMP_FN(ast_sorcery_object_field, name)
/*! \brief Cleanup function for graceful shutdowns */
static void sorcery_cleanup(void)
@@ -446,53 +359,10 @@
}
/*! \brief Compare function for sorcery instances */
-static int sorcery_instance_cmp(void *obj, void *arg, int flags)
-{
- const struct ast_sorcery *object_left = obj;
- const struct ast_sorcery *object_right = arg;
- const char *right_key = arg;
- int cmp;
-
- switch (flags & OBJ_SEARCH_MASK) {
- case OBJ_SEARCH_OBJECT:
- right_key = object_right->module_name;
- /* Fall through */
- case OBJ_SEARCH_KEY:
- cmp = strcmp(object_left->module_name, right_key);
- break;
- case OBJ_SEARCH_PARTIAL_KEY:
- cmp = strncmp(object_left->module_name, right_key, strlen(right_key));
- break;
- default:
- cmp = 0;
- break;
- }
- if (cmp) {
- return 0;
- }
- return CMP_MATCH;
-}
+AO2_STRING_FIELD_CMP_FN(ast_sorcery, module_name)
/*! \brief Hashing function for sorcery instances */
-static int sorcery_instance_hash(const void *obj, const int flags)
-{
- const struct ast_sorcery *object;
- const char *key;
-
- switch (flags & OBJ_SEARCH_MASK) {
- case OBJ_SEARCH_KEY:
- key = obj;
- break;
- case OBJ_SEARCH_OBJECT:
- object = obj;
- key = object->module_name;
- break;
- default:
- ast_assert(0);
- return 0;
- }
- return ast_str_hash(key);
-}
+AO2_STRING_FIELD_HASH_FN(ast_sorcery, module_name)
int ast_sorcery_init(void)
{
@@ -511,7 +381,7 @@
}
wizards = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, WIZARD_BUCKETS,
- sorcery_wizard_hash, NULL, sorcery_wizard_cmp);
+ ast_sorcery_internal_wizard_hash_fn, NULL, ast_sorcery_internal_wizard_cmp_fn);
if (!wizards) {
sorcery_cleanup();
return -1;
@@ -524,7 +394,7 @@
}
instances = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_RWLOCK, 0, INSTANCE_BUCKETS,
- sorcery_instance_hash, NULL, sorcery_instance_cmp);
+ ast_sorcery_hash_fn, NULL, ast_sorcery_cmp_fn);
if (!instances) {
sorcery_cleanup();
return -1;
@@ -724,53 +594,10 @@
}
/*! \brief Hashing function for sorcery types */
-static int sorcery_type_hash(const void *obj, const int flags)
-{
- const struct ast_sorcery_object_type *object;
- const char *key;
-
- switch (flags & OBJ_SEARCH_MASK) {
- case OBJ_SEARCH_KEY:
- key = obj;
- break;
- case OBJ_SEARCH_OBJECT:
- object = obj;
- key = object->name;
- break;
- default:
- ast_assert(0);
- return 0;
- }
- return ast_str_hash(key);
-}
+AO2_STRING_FIELD_HASH_FN(ast_sorcery_object_type, name)
/*! \brief Comparator function for sorcery types */
-static int sorcery_type_cmp(void *obj, void *arg, int flags)
-{
- const struct ast_sorcery_object_type *object_left = obj;
- const struct ast_sorcery_object_type *object_right = arg;
- const char *right_key = arg;
- int cmp;
-
- switch (flags & OBJ_SEARCH_MASK) {
- case OBJ_SEARCH_OBJECT:
- right_key = object_right->name;
- /* Fall through */
- case OBJ_SEARCH_KEY:
- cmp = strcmp(object_left->name, right_key);
- break;
- case OBJ_SEARCH_PARTIAL_KEY:
- cmp = strncmp(object_left->name, right_key, strlen(right_key));
- break;
- default:
- cmp = 0;
- break;
- }
- if (cmp) {
- return 0;
- }
- return CMP_MATCH;
-}
+AO2_STRING_FIELD_CMP_FN(ast_sorcery_object_type, name)
struct ast_sorcery *__ast_sorcery_open(const char *module_name)
{
@@ -787,7 +614,9 @@
goto done;
}
- if (!(sorcery->types = ao2_container_alloc_options(AO2_ALLOC_OPT_LOCK_RWLOCK, TYPE_BUCKETS, sorcery_type_hash, sorcery_type_cmp))) {
+ sorcery->types = ao2_container_alloc_options(AO2_ALLOC_OPT_LOCK_RWLOCK, TYPE_BUCKETS,
+ ast_sorcery_object_type_hash_fn, ast_sorcery_object_type_cmp_fn);
+ if (!sorcery->types) {
ao2_ref(sorcery, -1);
sorcery = NULL;
goto done;
@@ -863,7 +692,7 @@
}
object_type->fields = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_NOLOCK, 0,
- OBJECT_FIELD_BUCKETS, object_type_field_hash, NULL, object_type_field_cmp);
+ OBJECT_FIELD_BUCKETS, ast_sorcery_object_field_hash_fn, NULL, ast_sorcery_object_field_cmp_fn);
if (!object_type->fields) {
ao2_ref(object_type, -1);
return NULL;
--
To view, visit https://gerrit.asterisk.org/7781
To unsubscribe, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-MessageType: merged
Gerrit-Change-Id: Ide4c1449a894bce70dea1fef664dade9b57578f1
Gerrit-Change-Number: 7781
Gerrit-PatchSet: 1
Gerrit-Owner: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Jenkins2
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180103/9240569b/attachment-0001.html>
More information about the asterisk-code-review
mailing list