mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-05 04:11:08 +00:00
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 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@390249 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -66,6 +66,9 @@ struct stasis_topic *channel_topic_all;
|
||||
/*! \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;
|
||||
@@ -86,6 +89,21 @@ static const char *channel_snapshot_get_id(struct stasis_message *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 */
|
||||
static int channel_snapshot_hash_cb(const void *obj, const int flags)
|
||||
{
|
||||
@@ -366,6 +384,28 @@ struct ast_channel_snapshot *ast_channel_snapshot_get_latest(const char *uniquei
|
||||
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;
|
||||
}
|
||||
|
||||
snapshot = stasis_message_data(message);
|
||||
if (!snapshot) {
|
||||
return NULL;
|
||||
}
|
||||
ao2_ref(snapshot, +1);
|
||||
return snapshot;
|
||||
}
|
||||
|
||||
static void channel_role_snapshot_dtor(void *obj)
|
||||
{
|
||||
struct channel_role_snapshot *role_snapshot = obj;
|
||||
@@ -578,6 +618,7 @@ int ast_channel_snapshot_caller_id_equal(
|
||||
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 @@ void ast_stasis_channels_init(void)
|
||||
|
||||
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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user