[Asterisk-code-review] devicestate: Don't create topic when change isn't cached. (asterisk[15])
Joshua Colp
asteriskteam at digium.com
Wed Jul 25 05:54:06 CDT 2018
Joshua Colp has uploaded this change for review. ( https://gerrit.asterisk.org/9659
Change subject: devicestate: Don't create topic when change isn't cached.
......................................................................
devicestate: Don't create topic when change isn't cached.
When publishing a device state the change can be marked as being
cachable or not. If it is not cached the change is just published
to all interested and not stored away for later query. This was not
fully taken into account when publishing in stasis. The act of
publishing would create a topic for the device even if it may be
ephemeral.
This change makes it so messages which are not cached won't create
a topic for the device. If a topic does already exist it will be
published to but otherwise the change will only be published to
the device state all topic.
ASTERISK-27591
Change-Id: I18da0e8cbb18e79602e731020c46ba4101e59f0a
---
M include/asterisk/stasis.h
M main/devicestate.c
M main/stasis.c
3 files changed, 36 insertions(+), 4 deletions(-)
git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/59/9659/1
diff --git a/include/asterisk/stasis.h b/include/asterisk/stasis.h
index 62ed1ed..33f5ceb 100644
--- a/include/asterisk/stasis.h
+++ b/include/asterisk/stasis.h
@@ -744,6 +744,16 @@
*/
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_check_topic(const struct stasis_topic_pool *pool, const char *topic_name);
+
/*! \addtogroup StasisTopicsAndMessages
* @{
*/
diff --git a/main/devicestate.c b/main/devicestate.c
index 5df3449..74c63f3 100644
--- a/main/devicestate.c
+++ b/main/devicestate.c
@@ -737,7 +737,7 @@
{
RAII_VAR(struct ast_device_state_message *, device_state, 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));
@@ -756,12 +756,21 @@
return -1;
}
- device_specific_topic = ast_device_state_topic(device);
- if (!device_specific_topic) {
+ /* When this device state change is not cached we only publish
+ * on its own pool topic if one already exists. This means that
+ * something external is explicitly monitoring it.
+ */
+ if (cachable || stasis_topic_pool_check_topic(device_state_topic_pool, device)) {
+ topic = ast_device_state_topic(device);
+ } else {
+ topic = ast_device_state_topic_all();
+ }
+
+ if (!topic) {
return -1;
}
- stasis_publish(device_specific_topic, message);
+ stasis_publish(topic, message);
return 0;
}
diff --git a/main/stasis.c b/main/stasis.c
index 3254011..2121354 100644
--- a/main/stasis.c
+++ b/main/stasis.c
@@ -1196,6 +1196,19 @@
return topic_pool_entry->topic;
}
+int stasis_topic_pool_check_topic(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)
{
#ifdef AST_DEVMODE
--
To view, visit https://gerrit.asterisk.org/9659
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: 15
Gerrit-MessageType: newchange
Gerrit-Change-Id: I18da0e8cbb18e79602e731020c46ba4101e59f0a
Gerrit-Change-Number: 9659
Gerrit-PatchSet: 1
Gerrit-Owner: Joshua Colp <jcolp at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180725/fbcad5ef/attachment.html>
More information about the asterisk-code-review
mailing list