[asterisk-commits] kmoore: branch kmoore/stasis-mwi r382369 - in /team/kmoore/stasis-mwi: includ...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Mar 4 09:27:28 CST 2013


Author: kmoore
Date: Mon Mar  4 09:27:24 2013
New Revision: 382369

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=382369
Log:
Add ability to dump stasis cache

This adds a new function which will dump all cached items or a given
type of cached item into an AO2 container.

Modified:
    team/kmoore/stasis-mwi/include/asterisk/stasis.h
    team/kmoore/stasis-mwi/main/stasis_cache.c

Modified: team/kmoore/stasis-mwi/include/asterisk/stasis.h
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-mwi/include/asterisk/stasis.h?view=diff&rev=382369&r1=382368&r2=382369
==============================================================================
--- team/kmoore/stasis-mwi/include/asterisk/stasis.h (original)
+++ team/kmoore/stasis-mwi/include/asterisk/stasis.h Mon Mar  4 09:27:24 2013
@@ -439,6 +439,17 @@
 					struct stasis_message_type *type,
 					const char *id);
 
+/*!
+ * \brief Dump cached items to a subscription
+ * \param caching_topic The topic returned from stasis_caching_topic_create().
+ * \param type Type of message to dump (any type if NULL).
+ * \return ao2_container containing all matches (must be unreffed by caller)
+ * \return NULL on allocation error
+ * \since 12
+ */
+struct ao2_container *stasis_cache_dump(struct stasis_caching_topic *caching_topic,
+					struct stasis_message_type *type);
+
 /*! @} */
 
 /*! @{ */

Modified: team/kmoore/stasis-mwi/main/stasis_cache.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-mwi/main/stasis_cache.c?view=diff&rev=382369&r1=382368&r2=382369
==============================================================================
--- team/kmoore/stasis-mwi/main/stasis_cache.c (original)
+++ team/kmoore/stasis-mwi/main/stasis_cache.c Mon Mar  4 09:27:24 2013
@@ -192,6 +192,43 @@
 	ast_assert(cached_entry->snapshot != NULL);
 	ao2_ref(cached_entry->snapshot, +1);
 	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) {
+		ao2_link(cache_dump->cached, entry->snapshot);
+		return 0;
+	}
+
+	if (entry->type == cache_dump->type) {
+		ao2_link(cache_dump->cached, entry->snapshot);
+		return 0;
+	}
+	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;




More information about the asterisk-commits mailing list