[asterisk-commits] dlee: branch dlee/ASTERISK-21096 r383514 - in /team/dlee/ASTERISK-21096: ./ m...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Thu Mar 21 10:51:09 CDT 2013
Author: dlee
Date: Thu Mar 21 10:51:05 2013
New Revision: 383514
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=383514
Log:
Avoid duplicating the channel snapshot string on the same event.
........
Merged revisions 383509 from http://svn.asterisk.org/svn/asterisk/team/dlee/json_main
Modified:
team/dlee/ASTERISK-21096/ (props changed)
team/dlee/ASTERISK-21096/main/manager_channels.c
Propchange: team/dlee/ASTERISK-21096/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Thu Mar 21 10:51:05 2013
@@ -1,1 +1,1 @@
-/team/dlee/json_main:1-383336 /trunk:1-383315
+/team/dlee/json_main:1-383509 /trunk:1-383315
Modified: team/dlee/ASTERISK-21096/main/manager_channels.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ASTERISK-21096/main/manager_channels.c?view=diff&rev=383514&r1=383513&r2=383514
==============================================================================
--- team/dlee/ASTERISK-21096/main/manager_channels.c (original)
+++ team/dlee/ASTERISK-21096/main/manager_channels.c Thu Mar 21 10:51:05 2013
@@ -186,83 +186,25 @@
return out;
}
-static void channel_newexten(struct ast_channel_snapshot *snapshot)
-{
- RAII_VAR(struct ast_str *, channel_event_string, NULL, ast_free);
-
- if (ast_strlen_zero(snapshot->appl)) {
- /* Channel's not in a valid state for a Newexten event yet */
- return;
- }
-
- channel_event_string = manager_build_channel_state_string(snapshot);
-
- if (!channel_event_string) {
- return;
- }
-
- /* DEPRECATED: Extension field deprecated in 12; remove in 14 */
- /*** DOCUMENTATION
- <managerEventInstance>
- <synopsis>Raised when a channel enters a new context, extension, priority.</synopsis>
- <syntax>
- <xi:include xpointer="xpointer(/docs/managerEvent[@name='Newchannel']/managerEventInstance/syntax/parameter)" />
- <parameter name="Extension">
- <para>Deprecated in 12, but kept for
- backward compatability. Please use
- 'Exten' instead.</para>
- </parameter>
- <parameter name="Application">
- <para>The application about to be executed.</para>
- </parameter>
- <parameter name="AppData">
- <para>The data to be passed to the application.</para>
- </parameter>
- </syntax>
- </managerEventInstance>
- ***/
- manager_event(EVENT_FLAG_DIALPLAN, "Newexten",
- "%s"
- "Extension: %s\r\n"
- "Application: %s\r\n"
- "AppData: %s\r\n",
- ast_str_buffer(channel_event_string),
- snapshot->exten, snapshot->appl, snapshot->data);
-}
-
-static void channel_newcallerid(struct ast_channel_snapshot *snapshot)
-{
- RAII_VAR(struct ast_str *, channel_event_string, NULL, ast_free);
-
-
- channel_event_string = manager_build_channel_state_string(snapshot);
-
- if (!channel_event_string) {
- return;
- }
-
- /* XXX manager.c channelvars should be appeneded to this event
- * i.e. ChanVariable(SIP/blink-00000000): foo=bar
- */
-
- /*** DOCUMENTATION
- <managerEventInstance>
- <synopsis>Raised when a channel receives new Caller ID information.</synopsis>
- <syntax>
- <xi:include xpointer="xpointer(/docs/managerEvent[@name='Newchannel']/managerEventInstance/syntax/parameter)" />
- <parameter name="CID-CallingPres">
- <para>A description of the Caller ID presentation.</para>
- </parameter>
- </syntax>
- </managerEventInstance>
- ***/
- manager_event(EVENT_FLAG_CALL, "NewCallerid",
- "%s"
- "CID-CallingPres: %d (%s)\r\n",
- ast_str_buffer(channel_event_string),
- snapshot->caller_pres,
- ast_describe_caller_presentation(snapshot->caller_pres));
-
+static inline int cep_has_changed(
+ const struct ast_channel_snapshot *old_snapshot,
+ const struct ast_channel_snapshot *new_snapshot)
+{
+ ast_assert(old_snapshot != NULL);
+ ast_assert(new_snapshot != NULL);
+ return old_snapshot->priority != new_snapshot->priority ||
+ strcmp(old_snapshot->context, new_snapshot->context) != 0 ||
+ strcmp(old_snapshot->exten, new_snapshot->exten) != 0;
+}
+
+static inline int caller_id_changed(
+ const struct ast_channel_snapshot *old_snapshot,
+ const struct ast_channel_snapshot *new_snapshot)
+{
+ ast_assert(new_snapshot != NULL);
+ return old_snapshot && (
+ strcmp(old_snapshot->caller_number, new_snapshot->caller_number) != 0 ||
+ strcmp(old_snapshot->caller_name, new_snapshot->caller_name) != 0);
}
static void channel_snapshot_update(void *data, struct stasis_subscription *sub,
@@ -270,11 +212,13 @@
struct stasis_message *message)
{
RAII_VAR(struct ast_str *, extra_fields, NULL, ast_free);
+ RAII_VAR(struct ast_str *, channel_event_string, NULL, ast_free);
struct stasis_cache_update *update = stasis_message_data(message);
struct ast_channel_snapshot *old_snapshot;
struct ast_channel_snapshot *new_snapshot;
int is_hungup, was_hungup;
char *manager_event = NULL;
+ int new_exten, new_callerid;
if (ast_channel_snapshot() != update->type) {
return;
@@ -313,39 +257,88 @@
ast_cause2str(new_snapshot->hangupcause));
}
+ /* Detect Newexten transitions
+ * - if new snapshot has an application set AND
+ * - first snapshot OR
+ * - if the old snapshot has no application (first Newexten) OR
+ * - if the context/priority/exten changes
+ */
+ new_exten = !ast_strlen_zero(new_snapshot->appl) && (
+ !old_snapshot ||
+ ast_strlen_zero(old_snapshot->appl) ||
+ cep_has_changed(old_snapshot, new_snapshot));
+
+ new_callerid = caller_id_changed(old_snapshot, new_snapshot);
+
+ if (manager_event || new_exten || new_callerid) {
+ channel_event_string =
+ manager_build_channel_state_string(new_snapshot);
+ }
+
+ if (!channel_event_string) {
+ return;
+ }
+
/* Channel state change events */
if (manager_event) {
- RAII_VAR(struct ast_str *, channel_event_string, NULL, ast_free);
-
- channel_event_string =
- manager_build_channel_state_string(new_snapshot);
-
- if (channel_event_string) {
- manager_event(EVENT_FLAG_CALL, manager_event, "%s%s",
- ast_str_buffer(channel_event_string),
- ast_str_buffer(extra_fields));
- }
- }
-
- /* Detect Newexten transitions
- * - if the old snapshot has no application (first Newexten)
- * - or if the context/priority/exten changes
- */
- if (!old_snapshot || ast_strlen_zero(old_snapshot->appl) || (
- new_snapshot && (
- old_snapshot->priority != new_snapshot->priority ||
- strcmp(old_snapshot->context, new_snapshot->context) != 0 ||
- strcmp(old_snapshot->exten, new_snapshot->exten) != 0))) {
- channel_newexten(new_snapshot);
- }
-
- /* Detect NewCallerid */
- if (old_snapshot && (
- strcmp(old_snapshot->caller_number, new_snapshot->caller_number) != 0 ||
- strcmp(old_snapshot->caller_name, new_snapshot->caller_number) != 0)) {
- channel_newcallerid(new_snapshot);
- }
-
+ manager_event(EVENT_FLAG_CALL, manager_event, "%s%s",
+ ast_str_buffer(channel_event_string),
+ ast_str_buffer(extra_fields));
+ }
+
+ if (new_exten) {
+ /* DEPRECATED: Extension field deprecated in 12; remove in 14 */
+ /*** DOCUMENTATION
+ <managerEventInstance>
+ <synopsis>Raised when a channel enters a new context, extension, priority.</synopsis>
+ <syntax>
+ <xi:include xpointer="xpointer(/docs/managerEvent[@name='Newchannel']/managerEventInstance/syntax/parameter)" />
+ <parameter name="Extension">
+ <para>Deprecated in 12, but kept for
+ backward compatability. Please use
+ 'Exten' instead.</para>
+ </parameter>
+ <parameter name="Application">
+ <para>The application about to be executed.</para>
+ </parameter>
+ <parameter name="AppData">
+ <para>The data to be passed to the application.</para>
+ </parameter>
+ </syntax>
+ </managerEventInstance>
+ ***/
+ manager_event(EVENT_FLAG_DIALPLAN, "Newexten",
+ "%s"
+ "Extension: %s\r\n"
+ "Application: %s\r\n"
+ "AppData: %s\r\n",
+ ast_str_buffer(channel_event_string),
+ new_snapshot->exten,
+ new_snapshot->appl,
+ new_snapshot->data);
+ }
+
+ if (new_callerid) {
+ const char *pres_str = ast_describe_caller_presentation(
+ new_snapshot->caller_pres);
+ /*** DOCUMENTATION
+ <managerEventInstance>
+ <synopsis>Raised when a channel receives new Caller ID information.</synopsis>
+ <syntax>
+ <xi:include xpointer="xpointer(/docs/managerEvent[@name='Newchannel']/managerEventInstance/syntax/parameter)" />
+ <parameter name="CID-CallingPres">
+ <para>A description of the Caller ID presentation.</para>
+ </parameter>
+ </syntax>
+ </managerEventInstance>
+ ***/
+ manager_event(EVENT_FLAG_CALL, "NewCallerid",
+ "%s"
+ "CID-CallingPres: %d (%s)\r\n",
+ ast_str_buffer(channel_event_string),
+ new_snapshot->caller_pres,
+ pres_str);
+ }
}
static void channel_varset(struct ast_channel_blob *obj)
More information about the asterisk-commits
mailing list