[Asterisk-code-review] Expand the scope of Dial Events (asterisk[master])

Mark Michelson asteriskteam at digium.com
Thu Apr 14 17:43:04 CDT 2016


Mark Michelson has uploaded a new change for review.

  https://gerrit.asterisk.org/2621

Change subject: Expand the scope of Dial Events
......................................................................

Expand the scope of Dial Events

Dial events up to this point have come in two flavors
* A Dial event with no status to indicate that dialing has begun
* A Dial event with a status to indicate that dialing has ended

With this change, Dial events have been expanded to also give
intermediate events, such as "RINGING", "PROCEEDING", and "PROGRESS".
This is especially useful for ARI dialing, as it gives the application
writer the opportunity to place a channel into an early bridge when
early media is detected.

AMI handles these in-progress dial events by sending a new event called
"DialState" that simply indicates that dial state has changed but has
not ended. ARI never distinguished between DialBegin and DialEnd, so no
change was made to the event itself.

Another change here relates to dial forwards. A forward-related event
was previously only sent when a channel was successfully able to forward
a call to a new channel. With this set of changes, if forwarding is
blocked, we send a Dial event with a forwarding destination but no
forwarding channel, since we were prevented from creating one. This is
again useful for ARI since application writers can now handle call
forward attempts from within their own application.

ASTERISK-25925 #close
Reported by Mark Michelson

Change-Id: I30b0fcffda54c1a33e357260c041e6ae1ceaaea1
---
M CHANGES
M UPGRADE.txt
M apps/app_dial.c
M apps/app_followme.c
M apps/app_queue.c
M main/cdr.c
M main/dial.c
M main/manager_channels.c
M main/stasis_channels.c
9 files changed, 80 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/21/2621/1

diff --git a/CHANGES b/CHANGES
index e7f0656..5db2462 100644
--- a/CHANGES
+++ b/CHANGES
@@ -12,6 +12,13 @@
 --- Functionality changes from Asterisk 13 to Asterisk 14 --------------------
 ------------------------------------------------------------------------------
 
+AMI
+-----------------
+ * A new event, "DialState" has been added. This is similar to "DialBegin" and
+ "DialEnd" in that it tracks the state of a dialed call. The difference is that
+ this indicates some intermediate state change in the dial attempt, such as
+ "RINGING", "PROGRESS", or "PROCEEDING".
+
 ARI
 -----------------
  * A new ARI method has been added to the channels resource. "create" allows for
@@ -23,6 +30,10 @@
  * To complement the "create" method, a "dial" method has been added to the channels
  resource in order to place a call to a created channel.
 
+ * "Dial" events have been modified to not only be sent when dialing begins and ends.
+ They now are also sent for intermediate states, such as "RINGING", "PROGRESS", and
+ "PROCEEDING".
+
 Applications
 ------------------
 
diff --git a/UPGRADE.txt b/UPGRADE.txt
index 131ce6c..3d9b1eb 100644
--- a/UPGRADE.txt
+++ b/UPGRADE.txt
@@ -22,6 +22,14 @@
 === UPGRADE-13.txt  -- Upgrade info for 12 to 13
 ===========================================================
 
+ARI:
+ - The policy for when to send "Dial" events has changed. Previously, "Dial"
+ events were sent on the calling channel's topic. However, starting in Asterisk
+ 14, if there is no calling channel on which to send the event, the event is
+ instead sent on the called channel's topic. Note that for the ARI channels
+ resource's dial operation, this means that the "Dial" events will always be
+ sent on the called channel's topic.
+
 Channel Drivers:
 
 chan_dahdi:
diff --git a/apps/app_dial.c b/apps/app_dial.c
index 11591bd..5e034d3 100644
--- a/apps/app_dial.c
+++ b/apps/app_dial.c
@@ -872,6 +872,8 @@
 	/* If we have been told to ignore forwards, just set this channel to null and continue processing extensions normally */
 	if (ast_test_flag64(peerflags, OPT_IGNORE_FORWARDING)) {
 		ast_verb(3, "Forwarding %s to '%s/%s' prevented.\n", ast_channel_name(in), tech, stuff);
+		ast_channel_publish_dial_forward(in, original, NULL, NULL, "CANCEL",
+			ast_channel_call_forward(original));
 		c = o->chan = NULL;
 		cause = AST_CAUSE_BUSY;
 	} else {
@@ -1385,6 +1387,7 @@
 							pa->sentringing++;
 						}
 					}
+					ast_channel_publish_dial(in, c, NULL, "RINGING");
 					break;
 				case AST_CONTROL_PROGRESS:
 					ast_verb(3, "%s is making progress passing it to %s\n", ast_channel_name(c), ast_channel_name(in));
@@ -1404,6 +1407,7 @@
 							dtmf_progress);
 						ast_dtmf_stream(c, in, dtmf_progress, 250, 0);
 					}
+					ast_channel_publish_dial(in, c, NULL, "PROGRESS");
 					break;
 				case AST_CONTROL_VIDUPDATE:
 				case AST_CONTROL_SRCUPDATE:
@@ -1476,6 +1480,7 @@
 					}
 					if (!ast_test_flag64(outgoing, OPT_RINGBACK))
 						ast_indicate(in, AST_CONTROL_PROCEEDING);
+					ast_channel_publish_dial(in, c, NULL, "PROCEEDING");
 					break;
 				case AST_CONTROL_HOLD:
 					/* XXX this should be saved like AST_CONTROL_CONNECTED_LINE for !single || caller_entertained */
diff --git a/apps/app_followme.c b/apps/app_followme.c
index d2000fd..6687534 100644
--- a/apps/app_followme.c
+++ b/apps/app_followme.c
@@ -822,9 +822,11 @@
 						break;
 					case AST_CONTROL_RINGING:
 						ast_verb(3, "%s is ringing\n", ast_channel_name(winner));
+						ast_channel_publish_dial(caller, winner, NULL, "RINGING");
 						break;
 					case AST_CONTROL_PROGRESS:
 						ast_verb(3, "%s is making progress\n", ast_channel_name(winner));
+						ast_channel_publish_dial(caller, winner, NULL, "PROGRESS");
 						break;
 					case AST_CONTROL_VIDUPDATE:
 						ast_verb(3, "%s requested a video update\n", ast_channel_name(winner));
@@ -834,6 +836,7 @@
 						break;
 					case AST_CONTROL_PROCEEDING:
 						ast_verb(3, "%s is proceeding\n", ast_channel_name(winner));
+						ast_channel_publish_dial(caller, winner, NULL, "PROCEEDING");
 						break;
 					case AST_CONTROL_HOLD:
 						ast_verb(3, "%s placed call on hold\n", ast_channel_name(winner));
diff --git a/apps/app_queue.c b/apps/app_queue.c
index 0123e47..b7b06a7 100644
--- a/apps/app_queue.c
+++ b/apps/app_queue.c
@@ -4797,6 +4797,8 @@
 				/* Before processing channel, go ahead and check for forwarding */
 				if (!ast_strlen_zero(ast_channel_call_forward(o->chan)) && !forwardsallowed) {
 					ast_verb(3, "Forwarding %s to '%s' prevented.\n", inchan_name, ast_channel_call_forward(o->chan));
+					ast_channel_publish_dial_forward(qe->chan, o->chan, NULL, NULL,
+						"CANCEL", ast_channel_call_forward(o->chan));
 					numnochan++;
 					do_hang(o);
 					winner = NULL;
@@ -5003,6 +5005,8 @@
 						case AST_CONTROL_RINGING:
 							ast_verb(3, "%s is ringing\n", ochan_name);
 
+							ast_channel_publish_dial(qe->chan, o->chan, on, "RINGING");
+
 							/* Start ring indication when the channel is ringing, if specified */
 							if (qe->ring_when_ringing) {
 								ast_moh_stop(qe->chan);
diff --git a/main/cdr.c b/main/cdr.c
index b6a0b42..b43e361 100644
--- a/main/cdr.c
+++ b/main/cdr.c
@@ -1902,6 +1902,13 @@
 	return ret;
 }
 
+static int dial_status_end(const char *dialstatus)
+{
+	return (strcmp(dialstatus, "RINGING") &&
+			strcmp(dialstatus, "PROCEEDING") &&
+			strcmp(dialstatus, "PROGRESS"));
+}
+
 /* TOPIC ROUTER CALLBACKS */
 
 /*!
@@ -1970,7 +1977,7 @@
 			res &= it_cdr->fn_table->process_dial_begin(it_cdr,
 					caller,
 					peer);
-		} else {
+		} else if (dial_status_end(dial_status)) {
 			if (!it_cdr->fn_table->process_dial_end) {
 				continue;
 			}
diff --git a/main/dial.c b/main/dial.c
index 7066e46..34b1531 100644
--- a/main/dial.c
+++ b/main/dial.c
@@ -537,6 +537,8 @@
 		} else {
 			ast_hangup(original);
 		}
+		ast_channel_publish_dial_forward(chan, channel->owner, NULL, NULL, "CANCEL",
+			ast_channel_call_forward(original));
 		channel->owner = NULL;
 		return 0;
 	}
@@ -668,6 +670,7 @@
 			break;
 		case AST_CONTROL_RINGING:
 			ast_verb(3, "%s is ringing\n", ast_channel_name(channel->owner));
+			ast_channel_publish_dial(chan, channel->owner, channel->device, "RINGING");
 			if (!dial->options[AST_DIAL_OPTION_MUSIC]) {
 				if (bridge_chan) {
 					ast_bridge_channel_write_control_data(bridge_chan, AST_CONTROL_RINGING, NULL, 0);
@@ -678,6 +681,7 @@
 			set_state(dial, AST_DIAL_RESULT_RINGING);
 			break;
 		case AST_CONTROL_PROGRESS:
+			ast_channel_publish_dial(chan, channel->owner, channel->device, "PROGRESS");
 			if (chan) {
 				ast_verb(3, "%s is making progress, passing it to %s\n", ast_channel_name(channel->owner), ast_channel_name(chan));
 				ast_indicate(chan, AST_CONTROL_PROGRESS);
@@ -732,6 +736,7 @@
 			}
 			break;
 		case AST_CONTROL_PROCEEDING:
+			ast_channel_publish_dial(chan, channel->owner, channel->device, "PROCEEDING");
 			if (chan) {
 				ast_verb(3, "%s is proceeding, passing it to %s\n", ast_channel_name(channel->owner), ast_channel_name(chan));
 				ast_indicate(chan, AST_CONTROL_PROCEEDING);
diff --git a/main/manager_channels.c b/main/manager_channels.c
index da9bf47..e145e37 100644
--- a/main/manager_channels.c
+++ b/main/manager_channels.c
@@ -142,6 +142,33 @@
 			</see-also>
 		</managerEventInstance>
 	</managerEvent>
+	<managerEvent language="en_US" name="DialState">
+		<managerEventInstance class="EVENT_FLAG_CALL">
+			<synopsis>Raised when dial status has changed.</synopsis>
+			<syntax>
+				<channel_snapshot/>
+				<channel_snapshot prefix="Dest"/>
+				<parameter name="DialStatus">
+					<para> The new state of the outbound dial attempt.</para>
+					<enumlist>
+						<enum name="RINGING">
+							<para>The outbound channel is ringing.</para>
+						</enum>
+						<enum name="PROCEEDING">
+							<para>The call to the outbound channel is proceeding.</para>
+						</enum>
+						<enum name="PROGRESS">
+							<para>Progress has been received on the outbound channel.</para>
+						</enum>
+					</enumlist>
+				</parameter>
+				<parameter name="Forward" required="false">
+					<para>If the call was forwarded, where the call was
+					forwarded to.</para>
+				</parameter>
+			</syntax>
+		</managerEventInstance>
+	</managerEvent>
 	<managerEvent language="en_US" name="DialEnd">
 		<managerEventInstance class="EVENT_FLAG_CALL">
 			<synopsis>Raised when a dial action has completed.</synopsis>
@@ -1026,6 +1053,13 @@
 	publish_basic_channel_event("MonitorStop", EVENT_FLAG_CALL, payload->snapshot);
 }
 
+static int dial_status_end(const char *dialstatus)
+{
+	return (strcmp(dialstatus, "RINGING") &&
+			strcmp(dialstatus, "PROCEEDING") &&
+			strcmp(dialstatus, "PROGRESS"));
+}
+
 /*!
  * \brief Callback processing messages for channel dialing
  */
@@ -1069,7 +1103,7 @@
 	} else {
 		int forwarded = !ast_strlen_zero(forward);
 
-		manager_event(EVENT_FLAG_CALL, "DialEnd",
+		manager_event(EVENT_FLAG_CALL, dial_status_end(dialstatus) ? "DialEnd" : "DialState",
 				"%s"
 				"%s"
 				"%s%s%s"
diff --git a/main/stasis_channels.c b/main/stasis_channels.c
index eb1f1bc..5e06062 100644
--- a/main/stasis_channels.c
+++ b/main/stasis_channels.c
@@ -360,7 +360,7 @@
 		return;
 	}
 
-	publish_message_for_channel_topics(msg, caller);
+	publish_message_for_channel_topics(msg, caller ?: peer);
 }
 
 static void remove_dial_masquerade(struct ast_channel *peer);

-- 
To view, visit https://gerrit.asterisk.org/2621
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I30b0fcffda54c1a33e357260c041e6ae1ceaaea1
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: Mark Michelson <mmichelson at digium.com>



More information about the asterisk-code-review mailing list