<p>Joshua Colp <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/15901">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Joshua Colp: Looks good to me, but someone else must approve; Approved for Submit
George Joseph: Looks good to me, approved
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">AMI: Add AMI event to expose hook flash events<br><br>Although Asterisk can receive and propogate flash events, it currently<br>provides no mechanism for doing anything with them itself.<br><br>This AMI event allows flash events to be processed by Asterisk.<br>Additionally, AST_CONTROL_FLASH is included in a switch statement<br>in channel.c to avoid throwing a warning when we shouldn't.<br><br>ASTERISK-29380<br><br>Change-Id: Ie17ffe65086e0282c88542e38eed6a461ec79e81<br>---<br>M configs/samples/stasis.conf.sample<br>A doc/CHANGES-staging/flash_ami_event.txt<br>M include/asterisk/stasis_channels.h<br>M main/channel.c<br>M main/manager_channels.c<br>M main/stasis.c<br>M main/stasis_channels.c<br>7 files changed, 44 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/configs/samples/stasis.conf.sample b/configs/samples/stasis.conf.sample</span><br><span>index 46a240e..6fadc74 100644</span><br><span>--- a/configs/samples/stasis.conf.sample</span><br><span>+++ b/configs/samples/stasis.conf.sample</span><br><span>@@ -53,6 +53,7 @@</span><br><span> ; decline=ast_channel_hangup_request_type</span><br><span> ; decline=ast_channel_dtmf_begin_type</span><br><span> ; decline=ast_channel_dtmf_end_type</span><br><span style="color: hsl(120, 100%, 40%);">+; decline=ast_channel_flash_type</span><br><span> ; decline=ast_channel_hold_type</span><br><span> ; decline=ast_channel_unhold_type</span><br><span> ; decline=ast_channel_chanspy_start_type</span><br><span>diff --git a/doc/CHANGES-staging/flash_ami_event.txt b/doc/CHANGES-staging/flash_ami_event.txt</span><br><span>new file mode 100644</span><br><span>index 0000000..4cbea80</span><br><span>--- /dev/null</span><br><span>+++ b/doc/CHANGES-staging/flash_ami_event.txt</span><br><span>@@ -0,0 +1,3 @@</span><br><span style="color: hsl(120, 100%, 40%);">+Subject: AMI Flash event</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+Hook flash events are now exposed as AMI events.</span><br><span>diff --git a/include/asterisk/stasis_channels.h b/include/asterisk/stasis_channels.h</span><br><span>index 0efefa7..f0e5e47 100644</span><br><span>--- a/include/asterisk/stasis_channels.h</span><br><span>+++ b/include/asterisk/stasis_channels.h</span><br><span>@@ -417,6 +417,13 @@</span><br><span> struct stasis_message_type *ast_channel_dtmf_end_type(void);</span><br><span> </span><br><span> /*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Message type for when a hook flash occurs on a channel.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval A stasis message type</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+struct stasis_message_type *ast_channel_flash_type(void);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span> * \since 12</span><br><span> * \brief Message type for when a channel is placed on hold.</span><br><span> *</span><br><span>diff --git a/main/channel.c b/main/channel.c</span><br><span>index 9154a2c..f27a0a3 100644</span><br><span>--- a/main/channel.c</span><br><span>+++ b/main/channel.c</span><br><span>@@ -3327,6 +3327,7 @@</span><br><span> case AST_CONTROL_UPDATE_RTP_PEER:</span><br><span> case AST_CONTROL_HOLD:</span><br><span> case AST_CONTROL_UNHOLD:</span><br><span style="color: hsl(120, 100%, 40%);">+ case AST_CONTROL_FLASH:</span><br><span> case -1:</span><br><span> /* Unimportant */</span><br><span> break;</span><br><span>@@ -3405,6 +3406,11 @@</span><br><span> ast_channel_publish_cached_blob(chan, ast_channel_dtmf_end_type(), blob);</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+static void send_flash_event(struct ast_channel *chan)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_publish_blob(chan, ast_channel_flash_type(), NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> static void ast_read_generator_actions(struct ast_channel *chan, struct ast_frame *f)</span><br><span> {</span><br><span> struct ast_generator *generator;</span><br><span>@@ -3871,6 +3877,8 @@</span><br><span> */</span><br><span> ast_frfree(f);</span><br><span> f = &ast_null_frame;</span><br><span style="color: hsl(120, 100%, 40%);">+ } else if (f->subclass.integer == AST_CONTROL_FLASH) {</span><br><span style="color: hsl(120, 100%, 40%);">+ send_flash_event(chan);</span><br><span> }</span><br><span> break;</span><br><span> case AST_FRAME_DTMF_END:</span><br><span>diff --git a/main/manager_channels.c b/main/manager_channels.c</span><br><span>index 9bc51ed..943e9f4 100644</span><br><span>--- a/main/manager_channels.c</span><br><span>+++ b/main/manager_channels.c</span><br><span>@@ -985,6 +985,24 @@</span><br><span> digit, duration_ms, direction);</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+static void channel_flash_cb(void *data, struct stasis_subscription *sub,</span><br><span style="color: hsl(120, 100%, 40%);">+ struct stasis_message *message)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_channel_blob *obj = stasis_message_data(message);</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_str *channel_event_string;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ channel_event_string = ast_manager_build_channel_state_string(obj->snapshot);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!channel_event_string) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return;</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%);">+ manager_event(EVENT_FLAG_CALL, "Flash",</span><br><span style="color: hsl(120, 100%, 40%);">+ "%s",</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_str_buffer(channel_event_string));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_free(channel_event_string);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> static void channel_hangup_handler_cb(void *data, struct stasis_subscription *sub,</span><br><span> struct stasis_message *message)</span><br><span> {</span><br><span>@@ -1345,6 +1363,9 @@</span><br><span> ast_channel_dtmf_end_type(), channel_dtmf_end_cb, NULL);</span><br><span> </span><br><span> ret |= stasis_message_router_add(message_router,</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_flash_type(), channel_flash_cb, NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ret |= stasis_message_router_add(message_router,</span><br><span> ast_channel_hangup_request_type(), channel_hangup_request_cb,</span><br><span> NULL);</span><br><span> </span><br><span>diff --git a/main/stasis.c b/main/stasis.c</span><br><span>index e0c0446..30567ab 100644</span><br><span>--- a/main/stasis.c</span><br><span>+++ b/main/stasis.c</span><br><span>@@ -120,6 +120,7 @@</span><br><span> <enum name="ast_channel_hangup_request_type" /></span><br><span> <enum name="ast_channel_dtmf_begin_type" /></span><br><span> <enum name="ast_channel_dtmf_end_type" /></span><br><span style="color: hsl(120, 100%, 40%);">+ <enum name="ast_channel_flash_type" /></span><br><span> <enum name="ast_channel_hold_type" /></span><br><span> <enum name="ast_channel_unhold_type" /></span><br><span> <enum name="ast_channel_chanspy_start_type" /></span><br><span>diff --git a/main/stasis_channels.c b/main/stasis_channels.c</span><br><span>index e97806c..1da2db5 100644</span><br><span>--- a/main/stasis_channels.c</span><br><span>+++ b/main/stasis_channels.c</span><br><span>@@ -1307,6 +1307,7 @@</span><br><span> STASIS_MESSAGE_TYPE_DEFN(ast_channel_unhold_type,</span><br><span> .to_json = unhold_to_json,</span><br><span> );</span><br><span style="color: hsl(120, 100%, 40%);">+STASIS_MESSAGE_TYPE_DEFN(ast_channel_flash_type);</span><br><span> STASIS_MESSAGE_TYPE_DEFN(ast_channel_chanspy_start_type);</span><br><span> STASIS_MESSAGE_TYPE_DEFN(ast_channel_chanspy_stop_type);</span><br><span> STASIS_MESSAGE_TYPE_DEFN(ast_channel_fax_type);</span><br><span>@@ -1351,6 +1352,7 @@</span><br><span> STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_masquerade_type);</span><br><span> STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_dtmf_begin_type);</span><br><span> STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_dtmf_end_type);</span><br><span style="color: hsl(120, 100%, 40%);">+ STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_flash_type);</span><br><span> STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_hold_type);</span><br><span> STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_unhold_type);</span><br><span> STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_chanspy_start_type);</span><br><span>@@ -1405,6 +1407,7 @@</span><br><span> res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_masquerade_type);</span><br><span> res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_dtmf_begin_type);</span><br><span> res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_dtmf_end_type);</span><br><span style="color: hsl(120, 100%, 40%);">+ res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_flash_type);</span><br><span> res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_hold_type);</span><br><span> res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_unhold_type);</span><br><span> res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_chanspy_start_type);</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/15901">change 15901</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/c/asterisk/+/15901"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 16 </div>
<div style="display:none"> Gerrit-Change-Id: Ie17ffe65086e0282c88542e38eed6a461ec79e81 </div>
<div style="display:none"> Gerrit-Change-Number: 15901 </div>
<div style="display:none"> Gerrit-PatchSet: 4 </div>
<div style="display:none"> Gerrit-Owner: N A <mail@interlinked.x10host.com> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@sangoma.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>