[asterisk-commits] dlee: branch dlee/stasis-cache-split r394021 - /team/dlee/stasis-cache-split/...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Jul 10 16:46:37 CDT 2013
Author: dlee
Date: Wed Jul 10 16:46:35 2013
New Revision: 394021
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=394021
Log:
Cache pattern
Added:
team/dlee/stasis-cache-split/main/stasis_cache_pattern.c (with props)
Added: team/dlee/stasis-cache-split/main/stasis_cache_pattern.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-cache-split/main/stasis_cache_pattern.c?view=auto&rev=394021
==============================================================================
--- team/dlee/stasis-cache-split/main/stasis_cache_pattern.c (added)
+++ team/dlee/stasis-cache-split/main/stasis_cache_pattern.c Wed Jul 10 16:46:35 2013
@@ -1,0 +1,182 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2013, Digium, Inc.
+ *
+ * David M. Lee, II <dlee at digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*! \file
+ *
+ * \brief Typical cache pattern for Stasis topics.
+ *
+ * \author David M. Lee, II <dlee at digium.com>
+ */
+
+/*** MODULEINFO
+ <support_level>core</support_level>
+ ***/
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
+#include "asterisk/astobj2.h"
+#include "asterisk/stasis_cache_pattern.h"
+
+struct stasis_cache_all {
+ struct stasis_topic *topic;
+ struct stasis_topic *topic_cached;
+ struct stasis_cache *cache;
+};
+
+struct stasis_cache_one {
+ struct stasis_topic *topic;
+ struct stasis_caching_topic *topic_cached;
+
+ struct stasis_subscription *forward;
+ struct stasis_subscription *forward_cached;
+};
+
+static void all_dtor(void *obj)
+{
+ struct stasis_cache_all *all = obj;
+
+ ao2_cleanup(all->topic);
+ ao2_cleanup(all->topic_cached);
+ ao2_cleanup(all->cache);
+}
+
+struct stasis_cache_all *stasis_cache_all_create(const char *name,
+ snapshot_get_id id_fn)
+{
+ RAII_VAR(char *, cached_name, NULL, ast_free);
+ RAII_VAR(struct stasis_cache_all *, all, NULL, ao2_cleanup);
+
+ all = ao2_alloc(sizeof(*all), all_dtor);
+ if (!all) {
+ return NULL;
+ }
+
+ ast_asprintf(&cached_name, "%s-cached", name);
+ if (!cached_name) {
+ return NULL;
+ }
+
+ all->topic = stasis_topic_create(name);
+ all->topic_cached = stasis_topic_create(cached_name);
+ all->cache = stasis_cache_create(id_fn);
+
+ if (!all->topic || !all->topic_cached || !all->cache) {
+ return NULL;
+ }
+
+ ao2_ref(all, +1);
+ return all;
+}
+
+struct stasis_topic *stasis_cache_all_topic(struct stasis_cache_all *all)
+{
+ if (!all) {
+ return NULL;
+ }
+ return all->topic;
+}
+
+struct stasis_topic *stasis_cache_all_topic_cached(
+ struct stasis_cache_all *all)
+{
+ if (!all) {
+ return NULL;
+ }
+ return all->topic_cached;
+}
+
+struct stasis_cache *stasis_cache_all_cache(struct stasis_cache_all *all)
+{
+ if (!all) {
+ return NULL;
+ }
+ return all->cache;
+}
+
+static void one_dtor(void *obj)
+{
+ struct stasis_cache_one *one = obj;
+
+ /* Should already be unsubscribed */
+ ast_assert(one->topic_cached == NULL);
+ ast_assert(one->forward == NULL);
+ ast_assert(one->forward_cached == NULL);
+
+ ao2_cleanup(one->topic);
+ one->topic = NULL;
+}
+
+struct stasis_cache_one *stasis_cache_one_create(struct stasis_cache_all *all,
+ const char *name)
+{
+ RAII_VAR(struct stasis_cache_one *, one, NULL, ao2_cleanup);
+
+ one = ao2_alloc(sizeof(*one), one_dtor);
+ if (!one) {
+ return NULL;
+ }
+
+ one->topic = stasis_topic_create(name);
+ one->topic_cached = stasis_caching_topic_create(one->topic, all->cache);
+
+ one->forward = stasis_forward_all(one->topic, all->topic);
+ one->forward_cached = stasis_forward_all(
+ stasis_caching_get_topic(one->topic_cached), all->topic_cached);
+
+ if (!one->topic || !one->topic_cached || !one->forward ||
+ !one->forward_cached) {
+ return NULL;
+ }
+
+ ao2_ref(one, +1);
+ return one;
+}
+
+void stasis_cache_one_unsubscribe(struct stasis_cache_one *one)
+{
+ if (!one) {
+ return;
+ }
+
+ stasis_caching_unsubscribe(one->topic_cached);
+ one->topic_cached = NULL;
+ stasis_unsubscribe(one->forward);
+ one->forward = NULL;
+ stasis_unsubscribe(one->forward_cached);
+ one->forward_cached = NULL;
+}
+
+struct stasis_topic *stasis_cache_one_topic(struct stasis_cache_one *one)
+{
+ if (!one) {
+ return NULL;
+ }
+ return one->topic;
+}
+
+struct stasis_topic *stasis_cache_one_topic_cached(
+ struct stasis_cache_one *one)
+{
+ if (!one) {
+ return NULL;
+ }
+ return stasis_caching_get_topic(one->topic_cached);
+}
+
Propchange: team/dlee/stasis-cache-split/main/stasis_cache_pattern.c
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: team/dlee/stasis-cache-split/main/stasis_cache_pattern.c
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: team/dlee/stasis-cache-split/main/stasis_cache_pattern.c
------------------------------------------------------------------------------
svn:mime-type = text/plain
More information about the asterisk-commits
mailing list