<p>Joshua Colp <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/9659">View Change</a></p><div style="white-space:pre-wrap">Approvals:
George Joseph: Looks good to me, but someone else must approve
Kevin Harwell: Looks good to me, approved
Joshua Colp: Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">devicestate: Don't create topic when change isn't cached.<br><br>When publishing a device state the change can be marked as being<br>cachable or not. If it is not cached the change is just published<br>to all interested and not stored away for later query. This was not<br>fully taken into account when publishing in stasis. The act of<br>publishing would create a topic for the device even if it may be<br>ephemeral.<br><br>This change makes it so messages which are not cached won't create<br>a topic for the device. If a topic does already exist it will be<br>published to but otherwise the change will only be published to<br>the device state all topic.<br><br>ASTERISK-27591<br><br>Change-Id: I18da0e8cbb18e79602e731020c46ba4101e59f0a<br>---<br>M include/asterisk/stasis.h<br>M main/devicestate.c<br>M main/stasis.c<br>3 files changed, 43 insertions(+), 4 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/include/asterisk/stasis.h b/include/asterisk/stasis.h</span><br><span>index 62ed1ed..0373eeb 100644</span><br><span>--- a/include/asterisk/stasis.h</span><br><span>+++ b/include/asterisk/stasis.h</span><br><span>@@ -744,6 +744,16 @@</span><br><span> */</span><br><span> struct stasis_topic *stasis_topic_pool_get_topic(struct stasis_topic_pool *pool, const char *topic_name);</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Check if a topic exists in a pool</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param pool Pool to check</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param topic_name Name of the topic to check</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval 1 exists</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval 0 does not exist</span><br><span style="color: hsl(120, 100%, 40%);">+ * \since 13.23.0</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+int stasis_topic_pool_topic_exists(const struct stasis_topic_pool *pool, const char *topic_name);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /*! \addtogroup StasisTopicsAndMessages</span><br><span> * @{</span><br><span> */</span><br><span>diff --git a/main/devicestate.c b/main/devicestate.c</span><br><span>index 5df3449..fa05dad 100644</span><br><span>--- a/main/devicestate.c</span><br><span>+++ b/main/devicestate.c</span><br><span>@@ -737,7 +737,7 @@</span><br><span> {</span><br><span> RAII_VAR(struct ast_device_state_message *, device_state, NULL, ao2_cleanup);</span><br><span> RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);</span><br><span style="color: hsl(0, 100%, 40%);">- struct stasis_topic *device_specific_topic;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct stasis_topic *topic;</span><br><span> </span><br><span> ast_assert(!ast_strlen_zero(device));</span><br><span> </span><br><span>@@ -756,12 +756,28 @@</span><br><span> return -1;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- device_specific_topic = ast_device_state_topic(device);</span><br><span style="color: hsl(0, 100%, 40%);">- if (!device_specific_topic) {</span><br><span style="color: hsl(120, 100%, 40%);">+ /* When a device state is to be cached it is likely that something</span><br><span style="color: hsl(120, 100%, 40%);">+ * external will either be monitoring it or will want to pull the</span><br><span style="color: hsl(120, 100%, 40%);">+ * information from the cache, so we always publish to the device</span><br><span style="color: hsl(120, 100%, 40%);">+ * specific topic. Cachable updates traditionally come from such things</span><br><span style="color: hsl(120, 100%, 40%);">+ * as a SIP or PJSIP device.</span><br><span style="color: hsl(120, 100%, 40%);">+ * When a device state is not to be cached we only publish to its</span><br><span style="color: hsl(120, 100%, 40%);">+ * specific topic if something has already created the topic. Publishing</span><br><span style="color: hsl(120, 100%, 40%);">+ * to its topic otherwise would create the topic, which may not be</span><br><span style="color: hsl(120, 100%, 40%);">+ * necessary as it could be an ephemeral device. Uncachable updates</span><br><span style="color: hsl(120, 100%, 40%);">+ * traditionally come from such things as Local channels.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+ if (cachable || stasis_topic_pool_topic_exists(device_state_topic_pool, device)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ topic = ast_device_state_topic(device);</span><br><span style="color: hsl(120, 100%, 40%);">+ } else {</span><br><span style="color: hsl(120, 100%, 40%);">+ topic = ast_device_state_topic_all();</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!topic) {</span><br><span> return -1;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- stasis_publish(device_specific_topic, message);</span><br><span style="color: hsl(120, 100%, 40%);">+ stasis_publish(topic, message);</span><br><span> return 0;</span><br><span> }</span><br><span> </span><br><span>diff --git a/main/stasis.c b/main/stasis.c</span><br><span>index 3254011..1616deb 100644</span><br><span>--- a/main/stasis.c</span><br><span>+++ b/main/stasis.c</span><br><span>@@ -1196,6 +1196,19 @@</span><br><span> return topic_pool_entry->topic;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+int stasis_topic_pool_topic_exists(const struct stasis_topic_pool *pool, const char *topic_name)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ struct topic_pool_entry *topic_pool_entry;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ topic_pool_entry = ao2_find(pool->pool_container, topic_name, OBJ_SEARCH_KEY);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!topic_pool_entry) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_ref(topic_pool_entry, -1);</span><br><span style="color: hsl(120, 100%, 40%);">+ return 1;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> void stasis_log_bad_type_access(const char *name)</span><br><span> {</span><br><span> #ifdef AST_DEVMODE</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/9659">change 9659</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/9659"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 15 </div>
<div style="display:none"> Gerrit-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: I18da0e8cbb18e79602e731020c46ba4101e59f0a </div>
<div style="display:none"> Gerrit-Change-Number: 9659 </div>
<div style="display:none"> Gerrit-PatchSet: 3 </div>
<div style="display:none"> Gerrit-Owner: Joshua Colp <jcolp@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins2 </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Kevin Harwell <kharwell@digium.com> </div>