[asterisk-commits] dlee: branch dlee/ASTERISK-21096 r383600 - /team/dlee/ASTERISK-21096/main/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Fri Mar 22 09:54:05 CDT 2013
Author: dlee
Date: Fri Mar 22 09:54:01 2013
New Revision: 383600
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=383600
Log:
Cleaned up channel_state_change, as suggested by opticron.
Modified:
team/dlee/ASTERISK-21096/main/manager_channels.c
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=383600&r1=383599&r2=383600
==============================================================================
--- team/dlee/ASTERISK-21096/main/manager_channels.c (original)
+++ team/dlee/ASTERISK-21096/main/manager_channels.c Fri Mar 22 09:54:01 2013
@@ -223,7 +223,7 @@
/*! manager_event manager_event() category. */
const char *manager_event;
AST_DECLARE_STRING_FIELDS(
- /* extra_fields_fmt Format string for extra fields to include. */
+ /* extra fields to include in the event. */
AST_STRING_FIELD(extra_fields);
);
};
@@ -239,6 +239,7 @@
* \param event_flags manager_event() flags parameter.
* \param manager_event manager_event() category.
* \param extra_fields_fmt Format string for extra fields to include.
+ * Or NO_EXTRA_FIELDS for no extra fields.
* \return New \ref snapshot_manager_event object.
* \return \c NULL on error.
*/
@@ -249,7 +250,6 @@
const char *manager_event,
const char *extra_fields_fmt,
...)
-
{
RAII_VAR(struct snapshot_manager_event *, ev, NULL, ao2_cleanup);
va_list argp;
@@ -278,6 +278,9 @@
return ev;
}
+/*! GCC warns about blank or NULL format strings. So, shenanigans! */
+#define NO_EXTRA_FIELDS "%s", ""
+
/*! \brief Typedef for callbacks that get called on channel snapshot updates */
typedef struct snapshot_manager_event *(*snapshot_monitor)(
struct ast_channel_snapshot *old_snapshot,
@@ -288,16 +291,12 @@
struct ast_channel_snapshot *old_snapshot,
struct ast_channel_snapshot *new_snapshot)
{
- RAII_VAR(char *, extra_fields, NULL, ast_free);
- char *manager_event = NULL;
int is_hungup, was_hungup;
if (!new_snapshot) {
/* Ignore cache clearing events; we'll see the hangup first */
return NULL;
}
-
- extra_fields = ast_strdup("");
was_hungup = (old_snapshot && ast_test_flag(&old_snapshot->flags, AST_FLAG_ZOMBIE)) ? 1 : 0;
is_hungup = ast_test_flag(&new_snapshot->flags, AST_FLAG_ZOMBIE) ? 1 : 0;
@@ -308,32 +307,26 @@
*/
if (!old_snapshot) {
- manager_event = "Newchannel";
- }
-
- if (old_snapshot && old_snapshot->state != new_snapshot->state) {
- manager_event = "Newstate";
+ return snapshot_manager_event_create(
+ EVENT_FLAG_CALL, "Newchannel", NO_EXTRA_FIELDS);
}
if (!was_hungup && is_hungup) {
- manager_event = "Hangup";
- ast_asprintf(&extra_fields,
- "Cause: %d\r\n"
- "Cause-txt: %s\r\n",
- new_snapshot->hangupcause,
- ast_cause2str(new_snapshot->hangupcause));
- if (!extra_fields) {
- return NULL;
- }
+ return snapshot_manager_event_create(
+ EVENT_FLAG_CALL, "Hangup",
+ "Cause: %d\r\n"
+ "Cause-txt: %s\r\n",
+ new_snapshot->hangupcause,
+ ast_cause2str(new_snapshot->hangupcause));
+ }
+
+ if (old_snapshot->state != new_snapshot->state) {
+ return snapshot_manager_event_create(
+ EVENT_FLAG_CALL, "Newstate", NO_EXTRA_FIELDS);
}
/* No event */
- if (!manager_event) {
- return NULL;
- }
-
- return snapshot_manager_event_create(
- EVENT_FLAG_CALL, manager_event, "%s", extra_fields);
+ return NULL;
}
/*!
More information about the asterisk-commits
mailing list