Make stasis unsubscription functions return NULL
[asterisk/asterisk.git] / main / stasis_cache.c
index 2f4cf52..a824928 100644 (file)
@@ -42,6 +42,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 #define NUM_CACHE_BUCKETS 563
 #endif
 
+/*! \private */
 struct stasis_caching_topic {
        struct ao2_container *cache;
        struct stasis_topic *topic;
@@ -64,7 +65,7 @@ struct stasis_topic *stasis_caching_get_topic(struct stasis_caching_topic *cachi
        return caching_topic->topic;
 }
 
-void stasis_caching_unsubscribe(struct stasis_caching_topic *caching_topic)
+struct stasis_caching_topic *stasis_caching_unsubscribe(struct stasis_caching_topic *caching_topic)
 {
        if (caching_topic) {
                if (stasis_subscription_is_subscribed(caching_topic->sub)) {
@@ -73,6 +74,7 @@ void stasis_caching_unsubscribe(struct stasis_caching_topic *caching_topic)
                        ast_log(LOG_ERROR, "stasis_caching_topic unsubscribed multiple times\n");
                }
        }
+       return NULL;
 }
 
 struct cache_entry {
@@ -205,6 +207,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)