summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Mudgett <rmudgett@digium.com>2013-11-02 04:30:49 +0000
committerRichard Mudgett <rmudgett@digium.com>2013-11-02 04:30:49 +0000
commit7d2f2d6ef884dffc1d18c7312d2db274d6cb2a5a (patch)
tree86f4de520323dd375bdbf8dba1c38247b58bc74c
parent629a5fc39b1ad8bc638106c1f23537e797b5bedc (diff)
vector: Uppercase API to follow C convention.
C does not support templates like C++. ........ Merged revisions 402438 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@402439 65c4cc65-6c06-0410-ace0-fbb531ad65f3
-rw-r--r--include/asterisk/vector.h26
-rw-r--r--main/stasis.c46
-rw-r--r--main/stasis_message_router.c22
3 files changed, 47 insertions, 47 deletions
diff --git a/include/asterisk/vector.h b/include/asterisk/vector.h
index 4efc5ce4f..0a2c6c965 100644
--- a/include/asterisk/vector.h
+++ b/include/asterisk/vector.h
@@ -39,7 +39,7 @@
* \param name Optional vector struct name.
* \param type Vector element type.
*/
-#define ast_vector(name, type) \
+#define AST_VECTOR(name, type) \
struct name { \
type *elems; \
size_t max; \
@@ -58,7 +58,7 @@
* \return 0 on success.
* \return Non-zero on failure.
*/
-#define ast_vector_init(vec, size) ({ \
+#define AST_VECTOR_INIT(vec, size) ({ \
size_t __size = (size); \
size_t alloc_size = __size * sizeof(*((vec)->elems)); \
(vec)->elems = alloc_size ? ast_malloc(alloc_size) : NULL; \
@@ -79,7 +79,7 @@
*
* \param vec Vector to deallocate.
*/
-#define ast_vector_free(vec) do { \
+#define AST_VECTOR_FREE(vec) do { \
ast_free((vec)->elems); \
(vec)->elems = NULL; \
(vec)->max = 0; \
@@ -95,7 +95,7 @@
* \return 0 on success.
* \return Non-zero on failure.
*/
-#define ast_vector_append(vec, elem) ({ \
+#define AST_VECTOR_APPEND(vec, elem) ({ \
int res = 0; \
do { \
if ((vec)->current + 1 > (vec)->max) { \
@@ -125,7 +125,7 @@
* \param idx Index of the element to remove.
* \return The element that was removed.
*/
-#define ast_vector_remove_unordered(vec, idx) ({ \
+#define AST_VECTOR_REMOVE_UNORDERED(vec, idx) ({ \
typeof((vec)->elems[0]) res; \
size_t __idx = (idx); \
ast_assert(__idx < (vec)->current); \
@@ -146,14 +146,14 @@
* \return 0 if element was removed.
* \return Non-zero if element was not in the vector.
*/
-#define ast_vector_remove_cmp_unordered(vec, value, cmp, cleanup) ({ \
+#define AST_VECTOR_REMOVE_CMP_UNORDERED(vec, value, cmp, cleanup) ({ \
int res = -1; \
size_t idx; \
typeof(value) __value = (value); \
for (idx = 0; idx < (vec)->current; ++idx) { \
if (cmp((vec)->elems[idx], __value)) { \
cleanup((vec)->elems[idx]); \
- ast_vector_remove_unordered((vec), idx); \
+ AST_VECTOR_REMOVE_UNORDERED((vec), idx); \
res = 0; \
break; \
} \
@@ -162,7 +162,7 @@
})
/*!
- * \brief Default comparator for ast_vector_remove_elem_unordered()
+ * \brief Default comparator for AST_VECTOR_REMOVE_ELEM_UNORDERED()
*
* \param elem Element to compare against
* \param value Value to compare with the vector element.
@@ -191,8 +191,8 @@
* \return 0 if element was removed.
* \return Non-zero if element was not in the vector.
*/
-#define ast_vector_remove_elem_unordered(vec, elem, cleanup) ({ \
- ast_vector_remove_cmp_unordered((vec), (elem), \
+#define AST_VECTOR_REMOVE_ELEM_UNORDERED(vec, elem, cleanup) ({ \
+ AST_VECTOR_REMOVE_CMP_UNORDERED((vec), (elem), \
AST_VECTOR_ELEM_DEFAULT_CMP, cleanup); \
})
@@ -202,7 +202,7 @@
* \param vec Vector to query.
* \return Number of elements in the vector.
*/
-#define ast_vector_size(vec) (vec)->current
+#define AST_VECTOR_SIZE(vec) (vec)->current
/*!
* \brief Get an address of element in a vector.
@@ -210,7 +210,7 @@
* \param vec Vector to query.
* \param idx Index of the element to get address of.
*/
-#define ast_vector_get_addr(vec, idx) ({ \
+#define AST_VECTOR_GET_ADDR(vec, idx) ({ \
size_t __idx = (idx); \
ast_assert(__idx < (vec)->current); \
&(vec)->elems[__idx]; \
@@ -222,7 +222,7 @@
* \param vec Vector to query.
* \param idx Index of the element to get.
*/
-#define ast_vector_get(vec, idx) ({ \
+#define AST_VECTOR_GET(vec, idx) ({ \
size_t __idx = (idx); \
ast_assert(__idx < (vec)->current); \
(vec)->elems[__idx]; \
diff --git a/main/stasis.c b/main/stasis.c
index db95986ed..587a6a85e 100644
--- a/main/stasis.c
+++ b/main/stasis.c
@@ -140,10 +140,10 @@ STASIS_MESSAGE_TYPE_DEFN(stasis_subscription_change_type);
struct stasis_topic {
char *name;
/*! Variable length array of the subscribers */
- ast_vector(, struct stasis_subscription *) subscribers;
+ AST_VECTOR(, struct stasis_subscription *) subscribers;
/*! Topics forwarding into this topic */
- ast_vector(, struct stasis_topic *) upstream_topics;
+ AST_VECTOR(, struct stasis_topic *) upstream_topics;
};
/* Forward declarations for the tightly-coupled subscription object */
@@ -167,13 +167,13 @@ static void topic_dtor(void *obj)
/* Subscribers hold a reference to topics, so they should all be
* unsubscribed before we get here. */
- ast_assert(ast_vector_size(&topic->subscribers) == 0);
+ ast_assert(AST_VECTOR_SIZE(&topic->subscribers) == 0);
ast_free(topic->name);
topic->name = NULL;
- ast_vector_free(&topic->subscribers);
- ast_vector_free(&topic->upstream_topics);
+ AST_VECTOR_FREE(&topic->subscribers);
+ AST_VECTOR_FREE(&topic->upstream_topics);
}
struct stasis_topic *stasis_topic_create(const char *name)
@@ -192,8 +192,8 @@ struct stasis_topic *stasis_topic_create(const char *name)
return NULL;
}
- res |= ast_vector_init(&topic->subscribers, INITIAL_SUBSCRIBERS_MAX);
- res |= ast_vector_init(&topic->upstream_topics, 0);
+ res |= AST_VECTOR_INIT(&topic->subscribers, INITIAL_SUBSCRIBERS_MAX);
+ res |= AST_VECTOR_INIT(&topic->upstream_topics, 0);
if (res != 0) {
return NULL;
@@ -428,8 +428,8 @@ int stasis_subscription_is_subscribed(const struct stasis_subscription *sub)
struct stasis_topic *topic = sub->topic;
SCOPED_AO2LOCK(lock_topic, topic);
- for (i = 0; i < ast_vector_size(&topic->subscribers); ++i) {
- if (ast_vector_get(&topic->subscribers, i) == sub) {
+ for (i = 0; i < AST_VECTOR_SIZE(&topic->subscribers); ++i) {
+ if (AST_VECTOR_GET(&topic->subscribers, i) == sub) {
return 1;
}
}
@@ -480,11 +480,11 @@ static int topic_add_subscription(struct stasis_topic *topic, struct stasis_subs
*
* If we bumped the refcount here, the owner would have to unsubscribe
* and cleanup, which is a bit awkward. */
- ast_vector_append(&topic->subscribers, sub);
+ AST_VECTOR_APPEND(&topic->subscribers, sub);
- for (idx = 0; idx < ast_vector_size(&topic->upstream_topics); ++idx) {
+ for (idx = 0; idx < AST_VECTOR_SIZE(&topic->upstream_topics); ++idx) {
topic_add_subscription(
- ast_vector_get(&topic->upstream_topics, idx), sub);
+ AST_VECTOR_GET(&topic->upstream_topics, idx), sub);
}
return 0;
@@ -495,12 +495,12 @@ static int topic_remove_subscription(struct stasis_topic *topic, struct stasis_s
size_t idx;
SCOPED_AO2LOCK(lock_topic, topic);
- for (idx = 0; idx < ast_vector_size(&topic->upstream_topics); ++idx) {
+ for (idx = 0; idx < AST_VECTOR_SIZE(&topic->upstream_topics); ++idx) {
topic_remove_subscription(
- ast_vector_get(&topic->upstream_topics, idx), sub);
+ AST_VECTOR_GET(&topic->upstream_topics, idx), sub);
}
- return ast_vector_remove_elem_unordered(&topic->subscribers, sub,
+ return AST_VECTOR_REMOVE_ELEM_UNORDERED(&topic->subscribers, sub,
AST_VECTOR_ELEM_CLEANUP_NOOP);
}
@@ -549,8 +549,8 @@ void stasis_publish(struct stasis_topic *topic, struct stasis_message *message)
*/
ao2_ref(topic, +1);
ao2_lock(topic);
- for (i = 0; i < ast_vector_size(&topic->subscribers); ++i) {
- struct stasis_subscription *sub = ast_vector_get(&topic->subscribers, i);
+ for (i = 0; i < AST_VECTOR_SIZE(&topic->subscribers); ++i) {
+ struct stasis_subscription *sub = AST_VECTOR_GET(&topic->subscribers, i);
ast_assert(sub != NULL);
@@ -599,11 +599,11 @@ struct stasis_forward *stasis_forward_cancel(struct stasis_forward *forward)
to = forward->to_topic;
topic_lock_both(to, from);
- ast_vector_remove_elem_unordered(&to->upstream_topics, from,
+ AST_VECTOR_REMOVE_ELEM_UNORDERED(&to->upstream_topics, from,
AST_VECTOR_ELEM_CLEANUP_NOOP);
- for (idx = 0; idx < ast_vector_size(&to->subscribers); ++idx) {
- topic_remove_subscription(from, ast_vector_get(&to->subscribers, idx));
+ for (idx = 0; idx < AST_VECTOR_SIZE(&to->subscribers); ++idx) {
+ topic_remove_subscription(from, AST_VECTOR_GET(&to->subscribers, idx));
}
ao2_unlock(from);
ao2_unlock(to);
@@ -633,15 +633,15 @@ struct stasis_forward *stasis_forward_all(struct stasis_topic *from_topic,
forward->to_topic = ao2_bump(to_topic);
topic_lock_both(to_topic, from_topic);
- res = ast_vector_append(&to_topic->upstream_topics, from_topic);
+ res = AST_VECTOR_APPEND(&to_topic->upstream_topics, from_topic);
if (res != 0) {
ao2_unlock(from_topic);
ao2_unlock(to_topic);
return NULL;
}
- for (idx = 0; idx < ast_vector_size(&to_topic->subscribers); ++idx) {
- topic_add_subscription(from_topic, ast_vector_get(&to_topic->subscribers, idx));
+ for (idx = 0; idx < AST_VECTOR_SIZE(&to_topic->subscribers); ++idx) {
+ topic_add_subscription(from_topic, AST_VECTOR_GET(&to_topic->subscribers, idx));
}
ao2_unlock(from_topic);
ao2_unlock(to_topic);
diff --git a/main/stasis_message_router.c b/main/stasis_message_router.c
index 7ed9bcb83..ec0448bef 100644
--- a/main/stasis_message_router.c
+++ b/main/stasis_message_router.c
@@ -45,7 +45,7 @@ struct stasis_message_route {
void *data;
};
-ast_vector(route_table, struct stasis_message_route);
+AST_VECTOR(route_table, struct stasis_message_route);
static struct stasis_message_route *route_table_find(struct route_table *table,
struct stasis_message_type *message_type)
@@ -59,8 +59,8 @@ static struct stasis_message_route *route_table_find(struct route_table *table,
* tables, then we can look into containers with more efficient
* lookups.
*/
- for (idx = 0; idx < ast_vector_size(table); ++idx) {
- route = ast_vector_get_addr(table, idx);
+ for (idx = 0; idx < AST_VECTOR_SIZE(table); ++idx) {
+ route = AST_VECTOR_GET_ADDR(table, idx);
if (route->message_type == message_type) {
return route;
}
@@ -70,7 +70,7 @@ static struct stasis_message_route *route_table_find(struct route_table *table,
}
/*!
- * \brief route_table comparator for ast_vector_remove_cmp_unordered()
+ * \brief route_table comparator for AST_VECTOR_REMOVE_CMP_UNORDERED()
*
* \param elem Element to compare against
* \param value Value to compare with the vector element.
@@ -92,7 +92,7 @@ static struct stasis_message_route *route_table_find(struct route_table *table,
static int route_table_remove(struct route_table *table,
struct stasis_message_type *message_type)
{
- return ast_vector_remove_cmp_unordered(table, message_type, ROUTE_TABLE_ELEM_CMP,
+ return AST_VECTOR_REMOVE_CMP_UNORDERED(table, message_type, ROUTE_TABLE_ELEM_CMP,
ROUTE_TABLE_ELEM_CLEANUP);
}
@@ -110,7 +110,7 @@ static int route_table_add(struct route_table *table,
route.callback = callback;
route.data = data;
- res = ast_vector_append(table, route);
+ res = AST_VECTOR_APPEND(table, route);
if (res) {
ROUTE_TABLE_ELEM_CLEANUP(route);
}
@@ -122,11 +122,11 @@ static void route_table_dtor(struct route_table *table)
size_t idx;
struct stasis_message_route *route;
- for (idx = 0; idx < ast_vector_size(table); ++idx) {
- route = ast_vector_get_addr(table, idx);
+ for (idx = 0; idx < AST_VECTOR_SIZE(table); ++idx) {
+ route = AST_VECTOR_GET_ADDR(table, idx);
ROUTE_TABLE_ELEM_CLEANUP(*route);
}
- ast_vector_free(table);
+ AST_VECTOR_FREE(table);
}
/*! \internal */
@@ -218,8 +218,8 @@ struct stasis_message_router *stasis_message_router_create(
}
res = 0;
- res |= ast_vector_init(&router->routes, 0);
- res |= ast_vector_init(&router->cache_routes, 0);
+ res |= AST_VECTOR_INIT(&router->routes, 0);
+ res |= AST_VECTOR_INIT(&router->cache_routes, 0);
if (res) {
return NULL;
}