[asterisk-commits] kmoore: trunk r390249 - in /trunk: include/asterisk/ main/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri May 31 07:27:34 CDT 2013


Author: kmoore
Date: Fri May 31 07:27:29 2013
New Revision: 390249

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=390249
Log:
Add snapshot cache that indexes by channel name

This adds a new channel snapshot cache in parallel to the existing
cache; the difference being that it indexes the channel snapshots by
channel name instead of channel uniqueid.

Review: https://reviewboard.asterisk.org/r/2576

Modified:
    trunk/include/asterisk/stasis_channels.h
    trunk/main/stasis_channels.c

Modified: trunk/include/asterisk/stasis_channels.h
URL: http://svnview.digium.com/svn/asterisk/trunk/include/asterisk/stasis_channels.h?view=diff&rev=390249&r1=390248&r2=390249
==============================================================================
--- trunk/include/asterisk/stasis_channels.h (original)
+++ trunk/include/asterisk/stasis_channels.h Fri May 31 07:27:29 2013
@@ -104,6 +104,15 @@
 
 /*!
  * \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);
+
+/*!
+ * \since 12
  * \brief Message type for \ref ast_channel_snapshot.
  *
  * \retval Message type for \ref ast_channel_snapshot.
@@ -134,6 +143,18 @@
  * \retval NULL on error
  */
 struct ast_channel_snapshot *ast_channel_snapshot_get_latest(const char *uniqueid);
+
+/*!
+ * \since 12
+ * \brief Obtain the latest \ref ast_channel_snapshot from the \ref stasis cache. This is
+ * an ao2 object, so use \ref ao2_cleanup() to deallocate.
+ *
+ * \param name The channel's name
+ *
+ * \retval A \ref ast_channel_snapshot on success
+ * \retval NULL on error
+ */
+struct ast_channel_snapshot *ast_channel_snapshot_get_latest_by_name(const char *name);
 
 /*!
  * \since 12

Modified: trunk/main/stasis_channels.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/stasis_channels.c?view=diff&rev=390249&r1=390248&r2=390249
==============================================================================
--- trunk/main/stasis_channels.c (original)
+++ trunk/main/stasis_channels.c Fri May 31 07:27:29 2013
@@ -66,6 +66,9 @@
 /*! \brief Caching topic for all channels */
 struct stasis_caching_topic *channel_topic_all_cached;
 
+/*! \brief Caching topic for all channels indexed by name */
+struct stasis_caching_topic *channel_topic_all_cached_by_name;
+
 struct stasis_topic *ast_channel_topic_all(void)
 {
 	return channel_topic_all;
@@ -84,6 +87,21 @@
 	}
 	snapshot = stasis_message_data(message);
 	return snapshot->uniqueid;
+}
+
+struct stasis_caching_topic *ast_channel_topic_all_cached_by_name(void)
+{
+	return channel_topic_all_cached_by_name;
+}
+
+static const char *channel_snapshot_get_name(struct stasis_message *message)
+{
+	struct ast_channel_snapshot *snapshot;
+	if (ast_channel_snapshot_type() != stasis_message_type(message)) {
+		return NULL;
+	}
+	snapshot = stasis_message_data(message);
+	return snapshot->name;
 }
 
 /*! \internal \brief Hash function for \ref ast_channel_snapshot objects */
@@ -354,6 +372,28 @@
 	message = stasis_cache_get(ast_channel_topic_all_cached(),
 			ast_channel_snapshot_type(),
 			uniqueid);
+	if (!message) {
+		return NULL;
+	}
+
+	snapshot = stasis_message_data(message);
+	if (!snapshot) {
+		return NULL;
+	}
+	ao2_ref(snapshot, +1);
+	return snapshot;
+}
+
+struct ast_channel_snapshot *ast_channel_snapshot_get_latest_by_name(const char *name)
+{
+	RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);
+	struct ast_channel_snapshot *snapshot;
+
+	ast_assert(!ast_strlen_zero(name));
+
+	message = stasis_cache_get(ast_channel_topic_all_cached_by_name(),
+			ast_channel_snapshot_type(),
+			name);
 	if (!message) {
 		return NULL;
 	}
@@ -578,6 +618,7 @@
 static void stasis_channels_cleanup(void)
 {
 	channel_topic_all_cached = stasis_caching_unsubscribe_and_join(channel_topic_all_cached);
+	channel_topic_all_cached_by_name = stasis_caching_unsubscribe_and_join(channel_topic_all_cached_by_name);
 	ao2_cleanup(channel_topic_all);
 	channel_topic_all = NULL;
 	STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_snapshot_type);
@@ -623,4 +664,5 @@
 
 	channel_topic_all = stasis_topic_create("ast_channel_topic_all");
 	channel_topic_all_cached = stasis_caching_topic_create(channel_topic_all, channel_snapshot_get_id);
-}
+	channel_topic_all_cached_by_name = stasis_caching_topic_create(channel_topic_all, channel_snapshot_get_name);
+}




More information about the asterisk-commits mailing list