[asterisk-commits] dlee: branch dlee/stasis-cache-split r393458 - /team/dlee/stasis-cache-split/...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Jul 2 13:19:08 CDT 2013


Author: dlee
Date: Tue Jul  2 13:19:05 2013
New Revision: 393458

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=393458
Log:
API changes for splitting the Stasis cache from the caching topic.

Modified:
    team/dlee/stasis-cache-split/include/asterisk/channel.h
    team/dlee/stasis-cache-split/include/asterisk/stasis.h
    team/dlee/stasis-cache-split/include/asterisk/stasis_channels.h

Modified: team/dlee/stasis-cache-split/include/asterisk/channel.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-cache-split/include/asterisk/channel.h?view=diff&rev=393458&r1=393457&r2=393458
==============================================================================
--- team/dlee/stasis-cache-split/include/asterisk/channel.h (original)
+++ team/dlee/stasis-cache-split/include/asterisk/channel.h Tue Jul  2 13:19:05 2013
@@ -4214,6 +4214,21 @@
 struct stasis_topic *ast_channel_topic(struct ast_channel *chan);
 
 /*!
+ * \since 12
+ * \brief A topic which publishes the events for a particular channel.
+ *
+ * If the given \a chan is \c NULL, ast_channel_topic_all_cached() is returned.
+ * This caching topic provides stasis_cache_update() messages for 
+ * ast_channel_snapshot_type() messages.
+ *
+ * \param chan Channel, or \c NULL.
+ *
+ * \retval Topic for channel's events.
+ * \retval ast_channel_topic_all() if \a chan is \c NULL.
+ */
+struct stasis_topic *ast_channel_topic_cached(struct ast_channel *chan);
+
+/*!
  * \brief Get the bridge associated with a channel
  * \since 12.0.0
  *

Modified: team/dlee/stasis-cache-split/include/asterisk/stasis.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-cache-split/include/asterisk/stasis.h?view=diff&rev=393458&r1=393457&r2=393458
==============================================================================
--- team/dlee/stasis-cache-split/include/asterisk/stasis.h (original)
+++ team/dlee/stasis-cache-split/include/asterisk/stasis.h Tue Jul  2 13:19:05 2013
@@ -575,22 +575,17 @@
 /*! @{ */
 
 /*!
+ * \brief A message cache, for use with \ref stasis_caching_topic.
+ * \since 12
+ */
+struct stasis_cache;
+
+/*!
  * \brief A topic wrapper, which caches certain messages.
  * \since 12
  */
 struct stasis_caching_topic;
 
-/*!
- * \brief A message which instructs the caching topic to remove an entry from its cache.
- *
- * \param message Message representative of the cache entry that should be cleared.
- *     This will become the data held in the stasis_cache_clear message.
- *
- * \return Message which, when sent to the \a topic, will clear the item from the cache.
- * \return \c NULL on error.
- * \since 12
- */
-struct stasis_message *stasis_cache_clear_create(struct stasis_message *message);
 
 /*!
  * \brief Callback extract a unique identity from a snapshot message.
@@ -604,6 +599,21 @@
  * \since 12
  */
 typedef const char *(*snapshot_get_id)(struct stasis_message *message);
+
+/*!
+ * \brief Create a cache.
+ *
+ * This is the backend store for a \ref stasis_caching_topic. The cache is
+ * thread safe, allowing concurrent reads and writes.
+ *
+ * The returned object is AO2 managed, so ao2_cleanup() when you're done.
+ *
+ * \param id_fn Callback to extract the id from a snapshot message.
+ * \return New cache indexed by \a id_fn.
+ * \return \c NULL on error
+ * \since 12
+ */
+struct stasis_cache *stasis_cache_create(snapshot_get_id id_fn);
 
 /*!
  * \brief Create a topic which monitors and caches messages from another topic.
@@ -614,12 +624,30 @@
  * the original snapshot message and the new message.
  *
  * \param original_topic Topic publishing snapshot messages.
- * \param id_fn Callback to extract the id from a snapshot message.
+ * \param cache Backend cache in which to keep snapshots.
  * \return New topic which changes snapshot messages to stasis_cache_update()
  *         messages, and forwards all other messages from the original topic.
- * \since 12
- */
-struct stasis_caching_topic *stasis_caching_topic_create(struct stasis_topic *original_topic, snapshot_get_id id_fn);
+ * \return \c NULL on error
+ * \since 12
+ */
+struct stasis_caching_topic *stasis_caching_topic_create(
+	struct stasis_topic *original_topic, struct stasis_cache *cache);
+
+/*!
+ * \brief Add a secondary cache to a caching topic.
+ *
+ * The secondary cache should identify objects by a different field than the
+ * primary cache. This is useful when snapshots may have multiple unique
+ * identifiers (such as \ref ast_channel's uniqueid and name), and may be looked
+ * up by either.
+ *
+ * \param caching_topic Topic to which to add the secondary cache.
+ * \param cache Secondary cache to add to the topic.
+ * \return 0 on success.
+ * \return -1 on error.
+ */
+int stasis_caching_topic_add_secondary_cache(
+	struct stasis_caching_topic *caching_topic, struct stasis_cache *cache);
 
 /*!
  * \brief Unsubscribes a caching topic from its upstream topic.
@@ -651,53 +679,70 @@
 /*!
  * \brief Returns the topic of cached events from a caching topics.
  * \param caching_topic The caching topic.
- * \return The topic that publishes cache update events, along with passthrough events
- *         from the underlying topic.
+ * \return The topic that publishes cache update events, along with passthrough
+ *         events from the underlying topic.
  * \return \c NULL if \a caching_topic is \c NULL.
  * \since 12
  */
-struct stasis_topic *stasis_caching_get_topic(struct stasis_caching_topic *caching_topic);
+struct stasis_topic *stasis_caching_get_topic(
+	struct stasis_caching_topic *caching_topic);
+
+/*!
+ * \brief A message which instructs the caching topic to remove an entry from
+ * its cache.
+ *
+ * \param message Message representative of the cache entry that should be
+ *                cleared. This will become the data held in the
+ *                stasis_cache_clear message.
+ *
+ * \return Message which, when sent to a \ref stasis_caching_topic, will clear
+ *         the item from the cache.
+ * \return \c NULL on error.
+ * \since 12
+ */
+struct stasis_message *stasis_cache_clear_create(struct stasis_message *message);
 
 /*!
  * \brief Retrieve an item from the cache.
  *
  * The returned item is AO2 managed, so ao2_cleanup() when you're done with it.
  *
- * \param caching_topic The topic returned from stasis_caching_topic_create().
+ * \param cache The cache to query.
  * \param type Type of message to retrieve.
  * \param id Identity of the snapshot to retrieve.
  * \return Message from the cache.
  * \return \c NULL if message is not found.
  * \since 12
  */
-#define stasis_cache_get(caching_topic, type, id) stasis_cache_get_extended(caching_topic, type, id, 0)
+#define stasis_cache_get(cache, type, id)		\
+	stasis_cache_get_extended(cache, type, id, 0)
 
 /*!
  * \brief Retrieve an item from the cache.
- * \param caching_topic The topic returned from stasis_caching_topic_create().
+ * \param cache The cache to query.
  * \param type Type of message to retrieve.
  * \param id Identity of the snapshot to retrieve.
- * \param guaranteed If set to 1 it is guaranteed that any pending messages have been processed.
+ * \param guaranteed If set to 1 it is guaranteed that any pending messages
+ *                   have been processed.
  * \return Message from the cache. The cache still owns the message, so
  *         ao2_ref() if you want to keep it.
  * \return \c NULL if message is not found.
  * \since 12
  */
-struct stasis_message *stasis_cache_get_extended(struct stasis_caching_topic *caching_topic,
-					struct stasis_message_type *type,
-					const char *id,
-					unsigned int guaranteed);
+struct stasis_message *stasis_cache_get_extended(
+	struct stasis_cache *cache, struct stasis_message_type *type,
+	const char *id, unsigned int guaranteed);
 
 /*!
  * \brief Dump cached items to a subscription
- * \param caching_topic The topic returned from stasis_caching_topic_create().
+ * \param cache The cache to query.
  * \param type Type of message to dump (any type if \c NULL).
  * \return ao2_container containing all matches (must be unreffed by caller)
  * \return \c NULL on allocation error
  * \since 12
  */
-struct ao2_container *stasis_cache_dump(struct stasis_caching_topic *caching_topic,
-					struct stasis_message_type *type);
+struct ao2_container *stasis_cache_dump(struct stasis_cache *cache,
+	struct stasis_message_type *type);
 
 /*! @} */
 

Modified: team/dlee/stasis-cache-split/include/asterisk/stasis_channels.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-cache-split/include/asterisk/stasis_channels.h?view=diff&rev=393458&r1=393457&r2=393458
==============================================================================
--- team/dlee/stasis-cache-split/include/asterisk/stasis_channels.h (original)
+++ team/dlee/stasis-cache-split/include/asterisk/stasis_channels.h Tue Jul  2 13:19:05 2013
@@ -105,16 +105,23 @@
  *
  * \retval Topic for all channel events.
  */
-struct stasis_caching_topic *ast_channel_topic_all_cached(void);
-
-/*!
- * \since 12
- * \brief A caching topic which caches \ref ast_channel_snapshot messages from
- * ast_channel_events_all(void) and indexes them by name.
- *
- * \retval Topic for all channel events.
- */
-struct stasis_caching_topic *ast_channel_topic_all_cached_by_name(void);
+struct stasis_topic *ast_channel_topic_all_cached(void);
+
+/*!
+ * \since 12
+ * \brief Cache backend for ast_channel_snapshot_type(), indexed by uniqueid.
+ *
+ * \retval Cache for \ref ast_channel_snapshot.
+ */
+struct stasis_cache *ast_channel_cache(void);
+
+/*!
+ * \since 12
+ * \brief Cache backend for ast_channel_snapshot_type(), indexed by name.
+ *
+ * \retval Cache for \ref ast_channel_snapshot.
+ */
+struct stasis_cache *ast_channel_cache_by_name(void);
 
 /*!
  * \since 12




More information about the asterisk-commits mailing list