[Asterisk-code-review] AMI: Add AMI event to expose hook flash events (asterisk[master])

N A asteriskteam at digium.com
Thu May 13 10:37:54 CDT 2021


N A has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/15889 )


Change subject: AMI: Add AMI event to expose hook flash events
......................................................................

AMI: Add AMI event to expose hook flash events

Although Asterisk can receive and propogate flash events, it currently
provides no mechanism for doing anything with them itself.

This AMI event allows flash events to be processed by Asterisk.
Additionally, AST_CONTROL_FLASH is included in a switch statement
in channel.c to avoid throwing a warning when we shouldn't.

ASTERISK-29380

Change-Id: Ie17ffe65086e0282c88542e38eed6a461ec79e81
---
M configs/samples/stasis.conf.sample
M include/asterisk/stasis_channels.h
M main/channel.c
M main/manager_channels.c
M main/stasis.c
M main/stasis_channels.c
6 files changed, 42 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/89/15889/1

diff --git a/configs/samples/stasis.conf.sample b/configs/samples/stasis.conf.sample
index 46a240e..6fadc74 100644
--- a/configs/samples/stasis.conf.sample
+++ b/configs/samples/stasis.conf.sample
@@ -53,6 +53,7 @@
 ; decline=ast_channel_hangup_request_type
 ; decline=ast_channel_dtmf_begin_type
 ; decline=ast_channel_dtmf_end_type
+; decline=ast_channel_flash_type
 ; decline=ast_channel_hold_type
 ; decline=ast_channel_unhold_type
 ; decline=ast_channel_chanspy_start_type
diff --git a/include/asterisk/stasis_channels.h b/include/asterisk/stasis_channels.h
index 02654e9..56d785e 100644
--- a/include/asterisk/stasis_channels.h
+++ b/include/asterisk/stasis_channels.h
@@ -526,6 +526,14 @@
 struct stasis_message_type *ast_channel_dtmf_end_type(void);
 
 /*!
+ * \since 18
+ * \brief Message type for when a hook flash occurs on a channel.
+ *
+ * \retval A stasis message type
+ */
+struct stasis_message_type *ast_channel_flash_type(void);
+
+/*!
  * \since 12
  * \brief Message type for when a channel is placed on hold.
  *
diff --git a/main/channel.c b/main/channel.c
index e92eaf8..42083c3 100644
--- a/main/channel.c
+++ b/main/channel.c
@@ -3315,6 +3315,7 @@
 				case AST_CONTROL_UPDATE_RTP_PEER:
 				case AST_CONTROL_HOLD:
 				case AST_CONTROL_UNHOLD:
+				case AST_CONTROL_FLASH:
 				case -1:
 					/* Unimportant */
 					break;
@@ -3393,6 +3394,11 @@
 	ast_channel_publish_blob(chan, ast_channel_dtmf_end_type(), blob);
 }
 
+static void send_flash_event(struct ast_channel *chan)
+{
+	ast_channel_publish_blob(chan, ast_channel_flash_type(), NULL);
+}
+
 static void ast_read_generator_actions(struct ast_channel *chan, struct ast_frame *f)
 {
 	struct ast_generator *generator;
@@ -3859,6 +3865,8 @@
 				 */
 				ast_frfree(f);
 				f = &ast_null_frame;
+			} else if (f->subclass.integer == AST_CONTROL_FLASH) {
+				send_flash_event(chan);
 			}
 			break;
 		case AST_FRAME_DTMF_END:
diff --git a/main/manager_channels.c b/main/manager_channels.c
index 7f40efe..dae737c 100644
--- a/main/manager_channels.c
+++ b/main/manager_channels.c
@@ -968,6 +968,24 @@
 		digit, duration_ms, direction);
 }
 
+static void channel_flash_cb(void *data, struct stasis_subscription *sub,
+	struct stasis_message *message)
+{
+	struct ast_channel_blob *obj = stasis_message_data(message);
+	struct ast_str *channel_event_string;
+
+	channel_event_string = ast_manager_build_channel_state_string(obj->snapshot);
+	if (!channel_event_string) {
+		return;
+	}
+
+	manager_event(EVENT_FLAG_CALL, "Flash",
+		"%s",
+		ast_str_buffer(channel_event_string));
+
+	ast_free(channel_event_string);
+}
+
 static void channel_hangup_handler_cb(void *data, struct stasis_subscription *sub,
 		struct stasis_message *message)
 {
@@ -1328,6 +1346,9 @@
 		ast_channel_dtmf_end_type(), channel_dtmf_end_cb, NULL);
 
 	ret |= stasis_message_router_add(message_router,
+		ast_channel_flash_type(), channel_flash_cb, NULL);
+
+	ret |= stasis_message_router_add(message_router,
 		ast_channel_hangup_request_type(), channel_hangup_request_cb,
 		NULL);
 
diff --git a/main/stasis.c b/main/stasis.c
index 4ae6d6a..bc11b7f 100644
--- a/main/stasis.c
+++ b/main/stasis.c
@@ -120,6 +120,7 @@
 							<enum name="ast_channel_hangup_request_type" />
 							<enum name="ast_channel_dtmf_begin_type" />
 							<enum name="ast_channel_dtmf_end_type" />
+							<enum name="ast_channel_flash_type" />
 							<enum name="ast_channel_hold_type" />
 							<enum name="ast_channel_unhold_type" />
 							<enum name="ast_channel_chanspy_start_type" />
diff --git a/main/stasis_channels.c b/main/stasis_channels.c
index 3f3312b..5e39c07 100644
--- a/main/stasis_channels.c
+++ b/main/stasis_channels.c
@@ -1598,6 +1598,7 @@
 STASIS_MESSAGE_TYPE_DEFN(ast_channel_unhold_type,
 	.to_json = unhold_to_json,
 	);
+STASIS_MESSAGE_TYPE_DEFN(ast_channel_flash_type);
 STASIS_MESSAGE_TYPE_DEFN(ast_channel_chanspy_start_type);
 STASIS_MESSAGE_TYPE_DEFN(ast_channel_chanspy_stop_type);
 STASIS_MESSAGE_TYPE_DEFN(ast_channel_fax_type);
@@ -1642,6 +1643,7 @@
 	STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_masquerade_type);
 	STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_dtmf_begin_type);
 	STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_dtmf_end_type);
+	STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_flash_type);
 	STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_hold_type);
 	STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_unhold_type);
 	STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_chanspy_start_type);
@@ -1695,6 +1697,7 @@
 	res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_masquerade_type);
 	res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_dtmf_begin_type);
 	res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_dtmf_end_type);
+	res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_flash_type);
 	res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_hold_type);
 	res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_unhold_type);
 	res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_chanspy_start_type);

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/15889
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Change-Id: Ie17ffe65086e0282c88542e38eed6a461ec79e81
Gerrit-Change-Number: 15889
Gerrit-PatchSet: 1
Gerrit-Owner: N A <mail at interlinked.x10host.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20210513/a4393b98/attachment.html>


More information about the asterisk-code-review mailing list