2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 2013, Digium, Inc.
6 * David M. Lee, II <dlee@digium.com>
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
21 * \brief Stasis Message API.
23 * \author David M. Lee, II <dlee@digium.com>
27 <support_level>core</support_level>
32 #include "asterisk/astobj2.h"
33 #include "asterisk/hashtab.h"
34 #include "asterisk/stasis_internal.h"
35 #include "asterisk/stasis.h"
36 #include "asterisk/utils.h"
37 #include "asterisk/vector.h"
40 #define NUM_CACHE_BUCKETS 17
42 #define NUM_CACHE_BUCKETS 563
47 struct ao2_container *entries;
48 snapshot_get_id id_fn;
49 cache_aggregate_calc_fn aggregate_calc_fn;
50 cache_aggregate_publish_fn aggregate_publish_fn;
54 struct stasis_caching_topic {
55 struct stasis_cache *cache;
56 struct stasis_topic *topic;
57 struct stasis_topic *original_topic;
58 struct stasis_subscription *sub;
61 static void stasis_caching_topic_dtor(void *obj)
63 struct stasis_caching_topic *caching_topic = obj;
65 /* Caching topics contain subscriptions, and must be manually
67 ast_assert(!stasis_subscription_is_subscribed(caching_topic->sub));
68 /* If there are any messages in flight to this subscription; that would
70 ast_assert(stasis_subscription_is_done(caching_topic->sub));
72 ao2_cleanup(caching_topic->sub);
73 caching_topic->sub = NULL;
74 ao2_cleanup(caching_topic->cache);
75 caching_topic->cache = NULL;
76 ao2_cleanup(caching_topic->topic);
77 caching_topic->topic = NULL;
78 ao2_cleanup(caching_topic->original_topic);
79 caching_topic->original_topic = NULL;
82 struct stasis_topic *stasis_caching_get_topic(struct stasis_caching_topic *caching_topic)
84 return caching_topic->topic;
87 struct stasis_caching_topic *stasis_caching_unsubscribe(struct stasis_caching_topic *caching_topic)
94 * The subscription may hold the last reference to this caching
95 * topic, but we want to make sure the unsubscribe finishes
96 * before kicking of the caching topic's dtor.
98 ao2_ref(caching_topic, +1);
100 if (stasis_subscription_is_subscribed(caching_topic->sub)) {
102 * Increment the reference to hold on to it past the
103 * unsubscribe. Will be cleaned up in dtor.
105 ao2_ref(caching_topic->sub, +1);
106 stasis_unsubscribe(caching_topic->sub);
108 ast_log(LOG_ERROR, "stasis_caching_topic unsubscribed multiple times\n");
110 ao2_cleanup(caching_topic);
114 struct stasis_caching_topic *stasis_caching_unsubscribe_and_join(struct stasis_caching_topic *caching_topic)
116 if (!caching_topic) {
120 /* Hold a ref past the unsubscribe */
121 ao2_ref(caching_topic, +1);
122 stasis_caching_unsubscribe(caching_topic);
123 stasis_subscription_join(caching_topic->sub);
124 ao2_cleanup(caching_topic);
129 * \brief The key for an entry in the cache
130 * \note The items in this struct must be immutable for the item in the cache
132 struct cache_entry_key {
133 /*! The message type of the item stored in the cache */
134 struct stasis_message_type *type;
135 /*! The unique ID of the item stored in the cache */
137 /*! The hash, computed from \c type and \c id */
141 struct stasis_cache_entry {
142 struct cache_entry_key key;
143 /*! Aggregate snapshot of the stasis cache. */
144 struct stasis_message *aggregate;
145 /*! Local entity snapshot of the stasis event. */
146 struct stasis_message *local;
147 /*! Remote entity snapshots of the stasis event. */
148 AST_VECTOR(, struct stasis_message *) remote;
151 static void cache_entry_dtor(void *obj)
153 struct stasis_cache_entry *entry = obj;
156 ao2_cleanup(entry->key.type);
157 entry->key.type = NULL;
158 ast_free((char *) entry->key.id);
159 entry->key.id = NULL;
161 ao2_cleanup(entry->aggregate);
162 entry->aggregate = NULL;
163 ao2_cleanup(entry->local);
166 for (idx = 0; idx < AST_VECTOR_SIZE(&entry->remote); ++idx) {
167 struct stasis_message *remote;
169 remote = AST_VECTOR_GET(&entry->remote, idx);
172 AST_VECTOR_FREE(&entry->remote);
175 static void cache_entry_compute_hash(struct cache_entry_key *key)
177 key->hash = ast_hashtab_hash_string(stasis_message_type_name(key->type));
178 key->hash += ast_hashtab_hash_string(key->id);
181 static struct stasis_cache_entry *cache_entry_create(struct stasis_message_type *type, const char *id, struct stasis_message *snapshot)
183 struct stasis_cache_entry *entry;
186 ast_assert(id != NULL);
187 ast_assert(snapshot != NULL);
193 entry = ao2_alloc_options(sizeof(*entry), cache_entry_dtor,
194 AO2_ALLOC_OPT_LOCK_NOLOCK);
199 entry->key.id = ast_strdup(id);
200 if (!entry->key.id) {
204 entry->key.type = ao2_bump(type);
205 cache_entry_compute_hash(&entry->key);
207 is_remote = ast_eid_cmp(&ast_eid_default, stasis_message_eid(snapshot)) ? 1 : 0;
208 if (AST_VECTOR_INIT(&entry->remote, is_remote)) {
214 if (AST_VECTOR_APPEND(&entry->remote, snapshot)) {
219 entry->local = snapshot;
226 static int cache_entry_hash(const void *obj, int flags)
228 const struct stasis_cache_entry *object;
229 const struct cache_entry_key *key;
231 switch (flags & OBJ_SEARCH_MASK) {
235 case OBJ_SEARCH_OBJECT:
240 /* Hash can only work on something with a full key. */
245 return (int)key->hash;
248 static int cache_entry_cmp(void *obj, void *arg, int flags)
250 const struct stasis_cache_entry *object_left = obj;
251 const struct stasis_cache_entry *object_right = arg;
252 const struct cache_entry_key *right_key = arg;
255 switch (flags & OBJ_SEARCH_MASK) {
256 case OBJ_SEARCH_OBJECT:
257 right_key = &object_right->key;
260 cmp = object_left->key.type != right_key->type
261 || strcmp(object_left->key.id, right_key->id);
263 case OBJ_SEARCH_PARTIAL_KEY:
264 /* Not supported by container */
270 * What arg points to is specific to this traversal callback
271 * and has no special meaning to astobj2.
280 * At this point the traversal callback is identical to a sorted
286 static void cache_dtor(void *obj)
288 struct stasis_cache *cache = obj;
290 ao2_cleanup(cache->entries);
291 cache->entries = NULL;
294 struct stasis_cache *stasis_cache_create_full(snapshot_get_id id_fn,
295 cache_aggregate_calc_fn aggregate_calc_fn,
296 cache_aggregate_publish_fn aggregate_publish_fn)
298 struct stasis_cache *cache;
300 cache = ao2_alloc_options(sizeof(*cache), cache_dtor,
301 AO2_ALLOC_OPT_LOCK_NOLOCK);
306 cache->entries = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_RWLOCK, 0,
307 NUM_CACHE_BUCKETS, cache_entry_hash, NULL, cache_entry_cmp);
308 if (!cache->entries) {
313 cache->id_fn = id_fn;
314 cache->aggregate_calc_fn = aggregate_calc_fn;
315 cache->aggregate_publish_fn = aggregate_publish_fn;
320 struct stasis_cache *stasis_cache_create(snapshot_get_id id_fn)
322 return stasis_cache_create_full(id_fn, NULL, NULL);
325 struct stasis_message *stasis_cache_entry_get_aggregate(struct stasis_cache_entry *entry)
327 return entry->aggregate;
330 struct stasis_message *stasis_cache_entry_get_local(struct stasis_cache_entry *entry)
335 struct stasis_message *stasis_cache_entry_get_remote(struct stasis_cache_entry *entry, int idx)
337 if (idx < AST_VECTOR_SIZE(&entry->remote)) {
338 return AST_VECTOR_GET(&entry->remote, idx);
345 * \brief Find the cache entry in the cache entries container.
347 * \param entries Container of cached entries.
348 * \param type Type of message to retrieve the cache entry.
349 * \param id Identity of the snapshot to retrieve the cache entry.
351 * \note The entries container is already locked.
353 * \retval Cache-entry on success.
354 * \retval NULL Not in cache.
356 static struct stasis_cache_entry *cache_find(struct ao2_container *entries, struct stasis_message_type *type, const char *id)
358 struct cache_entry_key search_key;
359 struct stasis_cache_entry *entry;
361 search_key.type = type;
363 cache_entry_compute_hash(&search_key);
364 entry = ao2_find(entries, &search_key, OBJ_SEARCH_KEY | OBJ_NOLOCK);
366 /* Ensure that what we looked for is what we found. */
368 || (!strcmp(stasis_message_type_name(entry->key.type),
369 stasis_message_type_name(type)) && !strcmp(entry->key.id, id)));
375 * \brief Remove the stasis snapshot in the cache entry determined by eid.
377 * \param entries Container of cached entries.
378 * \param cached_entry The entry to remove the snapshot from.
379 * \param eid Which snapshot in the cached entry.
381 * \note The entries container is already locked.
383 * \return Previous stasis entry snapshot.
385 static struct stasis_message *cache_remove(struct ao2_container *entries, struct stasis_cache_entry *cached_entry, const struct ast_eid *eid)
387 struct stasis_message *old_snapshot;
390 is_remote = ast_eid_cmp(eid, &ast_eid_default);
392 old_snapshot = cached_entry->local;
393 cached_entry->local = NULL;
398 for (idx = 0; idx < AST_VECTOR_SIZE(&cached_entry->remote); ++idx) {
399 struct stasis_message *cur;
401 cur = AST_VECTOR_GET(&cached_entry->remote, idx);
402 if (!ast_eid_cmp(eid, stasis_message_eid(cur))) {
403 old_snapshot = AST_VECTOR_REMOVE_UNORDERED(&cached_entry->remote, idx);
409 if (!cached_entry->local && !AST_VECTOR_SIZE(&cached_entry->remote)) {
410 ao2_unlink_flags(entries, cached_entry, OBJ_NOLOCK);
418 * \brief Update the stasis snapshot in the cache entry determined by eid.
420 * \param cached_entry The entry to remove the snapshot from.
421 * \param eid Which snapshot in the cached entry.
422 * \param new_snapshot Snapshot to replace the old snapshot.
424 * \return Previous stasis entry snapshot.
426 static struct stasis_message *cache_udpate(struct stasis_cache_entry *cached_entry, const struct ast_eid *eid, struct stasis_message *new_snapshot)
428 struct stasis_message *old_snapshot;
432 is_remote = ast_eid_cmp(eid, &ast_eid_default);
434 old_snapshot = cached_entry->local;
435 cached_entry->local = ao2_bump(new_snapshot);
440 for (idx = 0; idx < AST_VECTOR_SIZE(&cached_entry->remote); ++idx) {
441 struct stasis_message *cur;
443 cur = AST_VECTOR_GET(&cached_entry->remote, idx);
444 if (!ast_eid_cmp(eid, stasis_message_eid(cur))) {
445 old_snapshot = AST_VECTOR_REMOVE_UNORDERED(&cached_entry->remote, idx);
449 if (!AST_VECTOR_APPEND(&cached_entry->remote, new_snapshot)) {
450 ao2_bump(new_snapshot);
456 struct cache_put_snapshots {
457 /*! Old cache eid snapshot. */
458 struct stasis_message *old;
459 /*! Old cache aggregate snapshot. */
460 struct stasis_message *aggregate_old;
461 /*! New cache aggregate snapshot. */
462 struct stasis_message *aggregate_new;
465 static struct cache_put_snapshots cache_put(struct stasis_cache *cache,
466 struct stasis_message_type *type, const char *id, const struct ast_eid *eid,
467 struct stasis_message *new_snapshot)
469 struct stasis_cache_entry *cached_entry;
470 struct cache_put_snapshots snapshots;
472 ast_assert(cache->entries != NULL);
473 ast_assert(eid != NULL);/* Aggregate snapshots not allowed to be put directly. */
474 ast_assert(new_snapshot == NULL ||
475 type == stasis_message_type(new_snapshot));
477 memset(&snapshots, 0, sizeof(snapshots));
479 ao2_wrlock(cache->entries);
481 cached_entry = cache_find(cache->entries, type, id);
483 /* Update the eid snapshot. */
485 /* Remove snapshot from cache */
487 snapshots.old = cache_remove(cache->entries, cached_entry, eid);
489 } else if (cached_entry) {
490 /* Update snapshot in cache */
491 snapshots.old = cache_udpate(cached_entry, eid, new_snapshot);
493 /* Insert into the cache */
494 cached_entry = cache_entry_create(type, id, new_snapshot);
496 ao2_link_flags(cache->entries, cached_entry, OBJ_NOLOCK);
500 /* Update the aggregate snapshot. */
501 if (cache->aggregate_calc_fn && cached_entry) {
502 snapshots.aggregate_new = cache->aggregate_calc_fn(cached_entry, new_snapshot);
503 snapshots.aggregate_old = cached_entry->aggregate;
504 cached_entry->aggregate = ao2_bump(snapshots.aggregate_new);
507 ao2_unlock(cache->entries);
509 ao2_cleanup(cached_entry);
515 * \brief Dump all entity snapshots in the cache entry into the given container.
517 * \param snapshots Container to put all snapshots in the cache entry.
518 * \param entry Cache entry to use.
520 * \retval 0 on success.
521 * \retval non-zero on error.
523 static int cache_entry_dump(struct ao2_container *snapshots, const struct stasis_cache_entry *entry)
528 ast_assert(snapshots != NULL);
529 ast_assert(entry != NULL);
531 /* The aggregate snapshot is not a snapshot from an entity. */
534 err |= !ao2_link(snapshots, entry->local);
537 for (idx = 0; !err && idx < AST_VECTOR_SIZE(&entry->remote); ++idx) {
538 struct stasis_message *snapshot;
540 snapshot = AST_VECTOR_GET(&entry->remote, idx);
541 err |= !ao2_link(snapshots, snapshot);
547 struct ao2_container *stasis_cache_get_all(struct stasis_cache *cache, struct stasis_message_type *type, const char *id)
549 struct stasis_cache_entry *cached_entry;
550 struct ao2_container *found;
552 ast_assert(cache != NULL);
553 ast_assert(cache->entries != NULL);
554 ast_assert(id != NULL);
560 found = ao2_container_alloc_list(AO2_ALLOC_OPT_LOCK_NOLOCK, 0, NULL, NULL);
565 ao2_rdlock(cache->entries);
567 cached_entry = cache_find(cache->entries, type, id);
568 if (cached_entry && cache_entry_dump(found, cached_entry)) {
573 ao2_unlock(cache->entries);
575 ao2_cleanup(cached_entry);
581 * \brief Retrieve an item from the cache entry for a specific eid.
583 * \param entry Cache entry to use.
584 * \param eid Specific entity id to retrieve. NULL for aggregate.
586 * \note The returned snapshot has not had its reference bumped.
588 * \retval Snapshot from the cache.
589 * \retval \c NULL if snapshot is not found.
591 static struct stasis_message *cache_entry_by_eid(const struct stasis_cache_entry *entry, const struct ast_eid *eid)
598 return entry->aggregate;
601 /* Get snapshot with specific eid. */
602 is_remote = ast_eid_cmp(eid, &ast_eid_default);
607 for (idx = 0; idx < AST_VECTOR_SIZE(&entry->remote); ++idx) {
608 struct stasis_message *cur;
610 cur = AST_VECTOR_GET(&entry->remote, idx);
611 if (!ast_eid_cmp(eid, stasis_message_eid(cur))) {
619 struct stasis_message *stasis_cache_get_by_eid(struct stasis_cache *cache, struct stasis_message_type *type, const char *id, const struct ast_eid *eid)
621 struct stasis_cache_entry *cached_entry;
622 struct stasis_message *snapshot = NULL;
624 ast_assert(cache != NULL);
625 ast_assert(cache->entries != NULL);
626 ast_assert(id != NULL);
632 ao2_rdlock(cache->entries);
634 cached_entry = cache_find(cache->entries, type, id);
636 snapshot = cache_entry_by_eid(cached_entry, eid);
640 ao2_unlock(cache->entries);
642 ao2_cleanup(cached_entry);
646 struct stasis_message *stasis_cache_get(struct stasis_cache *cache, struct stasis_message_type *type, const char *id)
648 return stasis_cache_get_by_eid(cache, type, id, &ast_eid_default);
651 struct cache_dump_data {
652 struct ao2_container *container;
653 struct stasis_message_type *type;
654 const struct ast_eid *eid;
657 static int cache_dump_by_eid_cb(void *obj, void *arg, int flags)
659 struct cache_dump_data *cache_dump = arg;
660 struct stasis_cache_entry *entry = obj;
662 if (!cache_dump->type || entry->key.type == cache_dump->type) {
663 struct stasis_message *snapshot;
665 snapshot = cache_entry_by_eid(entry, cache_dump->eid);
667 if (!ao2_link(cache_dump->container, snapshot)) {
668 ao2_cleanup(cache_dump->container);
669 cache_dump->container = NULL;
678 struct ao2_container *stasis_cache_dump_by_eid(struct stasis_cache *cache, struct stasis_message_type *type, const struct ast_eid *eid)
680 struct cache_dump_data cache_dump;
682 ast_assert(cache != NULL);
683 ast_assert(cache->entries != NULL);
685 cache_dump.eid = eid;
686 cache_dump.type = type;
687 cache_dump.container = ao2_container_alloc_list(AO2_ALLOC_OPT_LOCK_NOLOCK, 0, NULL, NULL);
688 if (!cache_dump.container) {
692 ao2_callback(cache->entries, OBJ_MULTIPLE | OBJ_NODATA, cache_dump_by_eid_cb, &cache_dump);
693 return cache_dump.container;
696 struct ao2_container *stasis_cache_dump(struct stasis_cache *cache, struct stasis_message_type *type)
698 return stasis_cache_dump_by_eid(cache, type, &ast_eid_default);
701 static int cache_dump_all_cb(void *obj, void *arg, int flags)
703 struct cache_dump_data *cache_dump = arg;
704 struct stasis_cache_entry *entry = obj;
706 if (!cache_dump->type || entry->key.type == cache_dump->type) {
707 if (cache_entry_dump(cache_dump->container, entry)) {
708 ao2_cleanup(cache_dump->container);
709 cache_dump->container = NULL;
717 struct ao2_container *stasis_cache_dump_all(struct stasis_cache *cache, struct stasis_message_type *type)
719 struct cache_dump_data cache_dump;
721 ast_assert(cache != NULL);
722 ast_assert(cache->entries != NULL);
724 cache_dump.eid = NULL;
725 cache_dump.type = type;
726 cache_dump.container = ao2_container_alloc_list(AO2_ALLOC_OPT_LOCK_NOLOCK, 0, NULL, NULL);
727 if (!cache_dump.container) {
731 ao2_callback(cache->entries, OBJ_MULTIPLE | OBJ_NODATA, cache_dump_all_cb, &cache_dump);
732 return cache_dump.container;
735 STASIS_MESSAGE_TYPE_DEFN(stasis_cache_clear_type);
736 STASIS_MESSAGE_TYPE_DEFN(stasis_cache_update_type);
738 struct stasis_message *stasis_cache_clear_create(struct stasis_message *id_message)
740 return stasis_message_create(stasis_cache_clear_type(), id_message);
743 static void stasis_cache_update_dtor(void *obj)
745 struct stasis_cache_update *update = obj;
747 ao2_cleanup(update->old_snapshot);
748 update->old_snapshot = NULL;
749 ao2_cleanup(update->new_snapshot);
750 update->new_snapshot = NULL;
751 ao2_cleanup(update->type);
755 static struct stasis_message *update_create(struct stasis_message *old_snapshot, struct stasis_message *new_snapshot)
757 struct stasis_cache_update *update;
758 struct stasis_message *msg;
760 ast_assert(old_snapshot != NULL || new_snapshot != NULL);
762 if (!stasis_cache_update_type()) {
766 update = ao2_alloc_options(sizeof(*update), stasis_cache_update_dtor,
767 AO2_ALLOC_OPT_LOCK_NOLOCK);
773 ao2_ref(old_snapshot, +1);
774 update->old_snapshot = old_snapshot;
776 ao2_ref(stasis_message_type(old_snapshot), +1);
777 update->type = stasis_message_type(old_snapshot);
781 ao2_ref(new_snapshot, +1);
782 update->new_snapshot = new_snapshot;
783 ao2_ref(stasis_message_type(new_snapshot), +1);
784 update->type = stasis_message_type(new_snapshot);
787 msg = stasis_message_create(stasis_cache_update_type(), update);
793 static void caching_topic_exec(void *data, struct stasis_subscription *sub,
794 struct stasis_message *message)
796 struct stasis_caching_topic *caching_topic_needs_unref;
797 struct stasis_caching_topic *caching_topic = data;
798 struct stasis_message *msg;
799 struct stasis_message *msg_put;
800 struct stasis_message_type *msg_type;
801 const struct ast_eid *msg_eid;
804 ast_assert(caching_topic != NULL);
805 ast_assert(caching_topic->topic != NULL);
806 ast_assert(caching_topic->cache != NULL);
807 ast_assert(caching_topic->cache->id_fn != NULL);
809 if (stasis_subscription_final_message(sub, message)) {
810 caching_topic_needs_unref = caching_topic;
812 caching_topic_needs_unref = NULL;
815 msg_type = stasis_message_type(message);
816 if (stasis_cache_clear_type() == msg_type) {
817 /* Cache clear event. */
819 msg = stasis_message_data(message);
820 msg_type = stasis_message_type(msg);
822 /* Normal cache update event. */
826 ast_assert(msg_type != NULL);
828 msg_eid = stasis_message_eid(msg);/* msg_eid is NULL for aggregate message. */
829 msg_id = caching_topic->cache->id_fn(msg);
830 if (msg_id && msg_eid) {
831 struct stasis_message *update;
832 struct cache_put_snapshots snapshots;
834 /* Update the cache */
835 snapshots = cache_put(caching_topic->cache, msg_type, msg_id, msg_eid, msg_put);
836 if (snapshots.old || msg_put) {
837 update = update_create(snapshots.old, msg_put);
839 stasis_publish(caching_topic->topic, update);
844 "Attempting to remove an item from the %s cache that isn't there: %s %s\n",
845 stasis_topic_name(caching_topic->topic),
846 stasis_message_type_name(msg_type), msg_id);
849 if (snapshots.aggregate_old != snapshots.aggregate_new) {
850 if (snapshots.aggregate_new && caching_topic->cache->aggregate_publish_fn) {
851 caching_topic->cache->aggregate_publish_fn(caching_topic->original_topic,
852 snapshots.aggregate_new);
854 update = update_create(snapshots.aggregate_old, snapshots.aggregate_new);
856 stasis_publish(caching_topic->topic, update);
861 ao2_cleanup(snapshots.old);
862 ao2_cleanup(snapshots.aggregate_old);
863 ao2_cleanup(snapshots.aggregate_new);
866 ao2_cleanup(caching_topic_needs_unref);
869 struct stasis_caching_topic *stasis_caching_topic_create(struct stasis_topic *original_topic, struct stasis_cache *cache)
871 RAII_VAR(struct stasis_caching_topic *, caching_topic, NULL, ao2_cleanup);
872 struct stasis_subscription *sub;
873 RAII_VAR(char *, new_name, NULL, ast_free);
876 ret = ast_asprintf(&new_name, "%s-cached", stasis_topic_name(original_topic));
881 caching_topic = ao2_alloc_options(sizeof(*caching_topic),
882 stasis_caching_topic_dtor, AO2_ALLOC_OPT_LOCK_NOLOCK);
883 if (caching_topic == NULL) {
887 caching_topic->topic = stasis_topic_create(new_name);
888 if (caching_topic->topic == NULL) {
893 caching_topic->cache = cache;
895 sub = internal_stasis_subscribe(original_topic, caching_topic_exec, caching_topic, 0, 0);
900 ao2_ref(original_topic, +1);
901 caching_topic->original_topic = original_topic;
903 /* This is for the reference contained in the subscription above */
904 ao2_ref(caching_topic, +1);
905 caching_topic->sub = sub;
907 /* The subscription holds the reference, so no additional ref bump. */
908 return caching_topic;
911 static void stasis_cache_cleanup(void)
913 STASIS_MESSAGE_TYPE_CLEANUP(stasis_cache_clear_type);
914 STASIS_MESSAGE_TYPE_CLEANUP(stasis_cache_update_type);
917 int stasis_cache_init(void)
919 ast_register_cleanup(stasis_cache_cleanup);
921 if (STASIS_MESSAGE_TYPE_INIT(stasis_cache_clear_type) != 0) {
925 if (STASIS_MESSAGE_TYPE_INIT(stasis_cache_update_type) != 0) {