mirror of
https://github.com/asterisk/asterisk.git
synced 2025-11-18 07:48:14 +00:00
Merge "devicestate: Don't create topic when change isn't cached." into 13
This commit is contained in:
@@ -756,6 +756,16 @@ struct stasis_topic_pool *stasis_topic_pool_create(struct stasis_topic *pooled_t
|
|||||||
*/
|
*/
|
||||||
struct stasis_topic *stasis_topic_pool_get_topic(struct stasis_topic_pool *pool, const char *topic_name);
|
struct stasis_topic *stasis_topic_pool_get_topic(struct stasis_topic_pool *pool, const char *topic_name);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Check if a topic exists in a pool
|
||||||
|
* \param pool Pool to check
|
||||||
|
* \param topic_name Name of the topic to check
|
||||||
|
* \retval 1 exists
|
||||||
|
* \retval 0 does not exist
|
||||||
|
* \since 13.23.0
|
||||||
|
*/
|
||||||
|
int stasis_topic_pool_topic_exists(const struct stasis_topic_pool *pool, const char *topic_name);
|
||||||
|
|
||||||
/*! @} */
|
/*! @} */
|
||||||
|
|
||||||
/*! \addtogroup StasisTopicsAndMessages
|
/*! \addtogroup StasisTopicsAndMessages
|
||||||
|
|||||||
@@ -739,7 +739,7 @@ int ast_publish_device_state_full(
|
|||||||
{
|
{
|
||||||
RAII_VAR(struct ast_device_state_message *, device_state, NULL, ao2_cleanup);
|
RAII_VAR(struct ast_device_state_message *, device_state, NULL, ao2_cleanup);
|
||||||
RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);
|
RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);
|
||||||
struct stasis_topic *device_specific_topic;
|
struct stasis_topic *topic;
|
||||||
|
|
||||||
ast_assert(!ast_strlen_zero(device));
|
ast_assert(!ast_strlen_zero(device));
|
||||||
|
|
||||||
@@ -758,12 +758,28 @@ int ast_publish_device_state_full(
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
device_specific_topic = ast_device_state_topic(device);
|
/* When a device state is to be cached it is likely that something
|
||||||
if (!device_specific_topic) {
|
* external will either be monitoring it or will want to pull the
|
||||||
|
* information from the cache, so we always publish to the device
|
||||||
|
* specific topic. Cachable updates traditionally come from such things
|
||||||
|
* as a SIP or PJSIP device.
|
||||||
|
* When a device state is not to be cached we only publish to its
|
||||||
|
* specific topic if something has already created the topic. Publishing
|
||||||
|
* to its topic otherwise would create the topic, which may not be
|
||||||
|
* necessary as it could be an ephemeral device. Uncachable updates
|
||||||
|
* traditionally come from such things as Local channels.
|
||||||
|
*/
|
||||||
|
if (cachable || stasis_topic_pool_topic_exists(device_state_topic_pool, device)) {
|
||||||
|
topic = ast_device_state_topic(device);
|
||||||
|
} else {
|
||||||
|
topic = ast_device_state_topic_all();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!topic) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
stasis_publish(device_specific_topic, message);
|
stasis_publish(topic, message);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1198,6 +1198,19 @@ struct stasis_topic *stasis_topic_pool_get_topic(struct stasis_topic_pool *pool,
|
|||||||
return topic_pool_entry->topic;
|
return topic_pool_entry->topic;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int stasis_topic_pool_topic_exists(const struct stasis_topic_pool *pool, const char *topic_name)
|
||||||
|
{
|
||||||
|
struct topic_pool_entry *topic_pool_entry;
|
||||||
|
|
||||||
|
topic_pool_entry = ao2_find(pool->pool_container, topic_name, OBJ_SEARCH_KEY);
|
||||||
|
if (!topic_pool_entry) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
ao2_ref(topic_pool_entry, -1);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
void stasis_log_bad_type_access(const char *name)
|
void stasis_log_bad_type_access(const char *name)
|
||||||
{
|
{
|
||||||
#ifdef AST_DEVMODE
|
#ifdef AST_DEVMODE
|
||||||
|
|||||||
Reference in New Issue
Block a user