summaryrefslogtreecommitdiff
path: root/main/stasis_cache.c
diff options
context:
space:
mode:
authorKinsey Moore <kmoore@digium.com>2013-03-08 16:00:14 +0000
committerKinsey Moore <kmoore@digium.com>2013-03-08 16:00:14 +0000
commitc6b06e40dc859125cf76bec4632bd76de42256bd (patch)
treef99d321c8621ce9285389c058d70dfb71ffe3809 /main/stasis_cache.c
parent4edd8be35cdef3b212355c48b68319f2304bc9f2 (diff)
Add message dump capability to stasis cache layer
The cache dump mechanism allows the developer to retreive multiple items of a given type (or of all types) from the cache residing in a stasis caching topic in addition to the existing single-item cache retreival mechanism. This also adds to the caching unit tests to ensure that the new cache dump mechanism is functioning properly. Review: https://reviewboard.asterisk.org/r/2367/ (issue ASTERISK-21097) git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@382705 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/stasis_cache.c')
-rw-r--r--main/stasis_cache.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/main/stasis_cache.c b/main/stasis_cache.c
index 2f4cf52fd..160daa6a7 100644
--- a/main/stasis_cache.c
+++ b/main/stasis_cache.c
@@ -205,6 +205,39 @@ struct stasis_message *stasis_cache_get(struct stasis_caching_topic *caching_top
return cached_entry->snapshot;
}
+struct cache_dump_data {
+ struct ao2_container *cached;
+ struct stasis_message_type *type;
+};
+
+static int cache_dump_cb(void *obj, void *arg, int flags)
+{
+ struct cache_dump_data *cache_dump = arg;
+ struct cache_entry *entry = obj;
+
+ if (!cache_dump->type || entry->type == cache_dump->type) {
+ ao2_link(cache_dump->cached, entry->snapshot);
+ }
+
+ return 0;
+}
+
+struct ao2_container *stasis_cache_dump(struct stasis_caching_topic *caching_topic, struct stasis_message_type *type)
+{
+ struct cache_dump_data cache_dump;
+
+ ast_assert(caching_topic->cache != NULL);
+
+ cache_dump.type = type;
+ cache_dump.cached = ao2_container_alloc(1, NULL, NULL);
+ if (!cache_dump.cached) {
+ return NULL;
+ }
+
+ ao2_callback(caching_topic->cache, OBJ_MULTIPLE | OBJ_NODATA, cache_dump_cb, &cache_dump);
+ return cache_dump.cached;
+}
+
static struct stasis_message_type *__cache_clear_data;
static struct stasis_message_type *cache_clear_data(void)