Asterisk - The Open Source Telephony Project  18.5.0
stasis_cache_pattern.h
Go to the documentation of this file.
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 2013, Digium, Inc.
5  *
6  * David M. Lee, II <[email protected]>
7  *
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.
13  *
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.
17  */
18 
19 #ifndef _ASTERISK_STASIS_CACHE_PATTERN_H
20 #define _ASTERISK_STASIS_CACHE_PATTERN_H
21 
22 /*! \file
23  *
24  * \brief Caching pattern for \ref stasis topics.
25  *
26  * A typical pattern for Stasis objects is to have individual objects, which
27  * have their own topic and caching topic. These individual topics feed an
28  * upstream aggregate topics, and a shared cache.
29  *
30  * The \ref stasis_cp_all object contains the aggregate topics and shared cache.
31  * This is built with the base name for the topics, and the identity function to
32  * identify messages in the cache.
33  *
34  * The \ref stasis_cp_single object contains the \ref stasis_topic for a single
35  * instance, and the corresponding \ref stasis_caching_topic.
36  *
37  * Since the \ref stasis_cp_single object has subscriptions for forwarding
38  * and caching, it must be disposed of using stasis_cp_single_unsubscribe()
39  * instead of simply ao2_cleanup().
40  */
41 
42 #include "asterisk/stasis.h"
43 
44 /*!
45  * \brief The 'all' side of the cache pattern. These are typically built as
46  * global objects for specific modules.
47  */
48 struct stasis_cp_all;
49 
50 /*!
51  * \brief Create an all instance of the cache pattern.
52  *
53  * This object is AO2 managed, so dispose of it with ao2_cleanup().
54  *
55  * \param name Base name of the topics.
56  * \param id_fn Identity function for the cache.
57  * \return All side instance.
58  * \return \c NULL on error.
59  */
60 struct stasis_cp_all *stasis_cp_all_create(const char *name,
61  snapshot_get_id id_fn);
62 
63 /*!
64  * \brief Get the aggregate topic.
65  *
66  * This topic aggregates all messages published to corresponding
67  * stasis_cp_single_topic() topics.
68  *
69  * \param all All side caching pattern object.
70  * \return The aggregate topic.
71  * \return \c NULL if \a all is \c NULL
72  */
74 
75 /*!
76  * \brief Get the caching topic.
77  *
78  * This topic aggregates all messages from the corresponding
79  * stasis_cp_single_topic_cached() topics.
80  *
81  * Note that one normally only subscribes to the caching topic, since data
82  * is fed to it from its upstream topic.
83  *
84  * \param all All side caching pattern object.
85  * \return The aggregate caching topic.
86  * \return \c NULL if \a all is \c NULL
87  */
89  struct stasis_cp_all *all);
90 
91 /*!
92  * \brief Get the cache.
93  *
94  * This is the shared cache for all corresponding \ref stasis_cp_single objects.
95  *
96  * \param all All side caching pattern object.
97  * \return The cache.
98  * \return \c NULL if \a all is \c NULL
99  */
100 struct stasis_cache *stasis_cp_all_cache(struct stasis_cp_all *all);
101 
102 /*!
103  * \brief The 'one' side of the cache pattern. These are built per-instance for
104  * some corresponding object, and must be explicitly disposed of using
105  * stasis_cp_single_unsubscribe().
106  */
107 struct stasis_cp_single;
108 
109 /*!
110  * \brief Create the 'one' side of the cache pattern.
111  *
112  * Create the 'one' and forward to all's topic and topic_cached.
113  *
114  * Dispose of using stasis_cp_single_unsubscribe().
115  *
116  * \param all Corresponding all side.
117  * \param name Base name for the topics.
118  * \return One side instance
119  */
121  const char *name);
122 
123 /*!
124  * \brief Create a sink in the cache pattern
125  *
126  * Create the 'one' but do not automatically forward to the all's topic.
127  * This is useful when aggregating other topic's messages created with
128  * \c stasis_cp_single_create in another caching topic without replicating
129  * those messages in the all's topics.
130  *
131  * Dispose of using stasis_cp_single_unsubscribe().
132  *
133  * \param all Corresponding all side.
134  * \param name Base name for the topics.
135  * \return One side instance
136  */
138  const char *name);
139 
140 /*!
141  * \brief Stops caching and forwarding messages.
142  *
143  * \param one One side of the cache pattern.
144  */
146 
147 /*!
148  * \brief Get the topic for this instance.
149  *
150  * This is the topic to which one would post instance-specific messages, or
151  * subscribe for single-instance, uncached messages.
152  *
153  * \param one One side of the cache pattern.
154  * \return The main topic.
155  * \return \c NULL if \a one is \c NULL
156  */
158 
159 /*!
160  * \brief Get the caching topic for this instance.
161  *
162  * Note that one normally only subscribes to the caching topic, since data
163  * is fed to it from its upstream topic.
164  *
165  * \param one One side of the cache pattern.
166  * \return The caching topic.
167  * \return \c NULL if \a one is \c NULL
168  */
170  struct stasis_cp_single *one);
171 
172 /*!
173  * \brief Indicate to an instance that we are interested in a message type.
174  *
175  * This will cause the caching topic to receive messages of the given message
176  * type. This enables internal filtering in the stasis message bus to reduce
177  * messages.
178  *
179  * \param one One side of the cache pattern.
180  * \param type The message type we wish to receive.
181  * \retval 0 on success
182  * \retval -1 failure
183  *
184  * \since 17.0.0
185  */
187  struct stasis_message_type *type);
188 
189 /*!
190  * \brief Set the message type filtering level on a cache
191  *
192  * This will cause the underlying subscription to filter messages according to the
193  * provided filter level. For example if selective is used then only
194  * messages matching those provided to \ref stasis_subscription_accept_message_type
195  * will be raised to the subscription callback.
196  *
197  * \param one One side of the cache pattern.
198  * \param filter What filter to use
199  * \retval 0 on success
200  * \retval -1 failure
201  *
202  * \since 17.0.0
203  */
206 
207 #endif /* _ASTERISK_STASIS_CACHE_PATTERN_H */
static const char type[]
Definition: chan_ooh323.c:109
struct stasis_topic * stasis_cp_single_topic_cached(struct stasis_cp_single *one)
Get the caching topic for this instance.
struct stasis_topic * stasis_cp_all_topic_cached(struct stasis_cp_all *all)
Get the caching topic.
Stasis Message Bus API. See Stasis Message Bus API for detailed documentation.
void stasis_cp_single_unsubscribe(struct stasis_cp_single *one)
Stops caching and forwarding messages.
struct stasis_cp_single * stasis_cp_single_create(struct stasis_cp_all *all, const char *name)
Create the &#39;one&#39; side of the cache pattern.
struct stasis_cache * stasis_cp_all_cache(struct stasis_cp_all *all)
Get the cache.
static const char name[]
Definition: cdr_mysql.c:74
struct stasis_topic * stasis_cp_single_topic(struct stasis_cp_single *one)
Get the topic for this instance.
int stasis_cp_single_set_filter(struct stasis_cp_single *one, enum stasis_subscription_message_filter filter)
Set the message type filtering level on a cache.
stasis_subscription_message_filter
Stasis subscription message filters.
Definition: stasis.h:297
int stasis_cp_single_accept_message_type(struct stasis_cp_single *one, struct stasis_message_type *type)
Indicate to an instance that we are interested in a message type.
struct stasis_topic * stasis_cp_all_topic(struct stasis_cp_all *all)
Get the aggregate topic.
static int filter(struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t len)
Definition: func_strings.c:709
struct stasis_cp_all * stasis_cp_all_create(const char *name, snapshot_get_id id_fn)
Create an all instance of the cache pattern.
struct stasis_cp_single * stasis_cp_sink_create(struct stasis_cp_all *all, const char *name)
Create a sink in the cache pattern.
const char *(* snapshot_get_id)(struct stasis_message *message)
Callback extract a unique identity from a snapshot message.
Definition: stasis.h:1011