Add events around all application execution:

fire SWITCH_EVEHT_CHANNEL_EXECUTE
<execute app>
fire SWITCH_EVEHT_CHANNEL_EXECUTE_COMPLETE

This can be used in async socket connections to tell
when a queued application has finished executing.



Add the "event" application to the dialplan:

<action application="event" data="header1=val1,header2=val2"/>

Events fired from this applcation will always have the type SWITCH_EVENT_CHANNEL_APPLICATION.

You can add up to 25 headers of your own to the event via the application arguements.





git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@5448 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2007-06-23 05:41:07 +00:00
parent c43c080fa3
commit a039d870c3
6 changed files with 72 additions and 11 deletions

View File

@ -823,12 +823,14 @@ typedef enum {
SWITCH_EVENT_CHANNEL_ANSWER - A channel has been answered
SWITCH_EVENT_CHANNEL_HANGUP - A channel has been hungup
SWITCH_EVENT_CHANNEL_EXECUTE - A channel has executed a module's application
SWITCH_EVENT_CHANNEL_EXECUTE_COMPLETE - A channel has finshed executing a module's application
SWITCH_EVENT_CHANNEL_BRIDGE - A channel has bridged to another channel
SWITCH_EVENT_CHANNEL_UNBRIDGE - A channel has unbridged from another channel
SWITCH_EVENT_CHANNEL_PROGRESS - A channel has been parked
SWITCH_EVENT_CHANNEL_OUTGOING - A channel has been unparked
SWITCH_EVENT_CHANNEL_PARK - A channel has been parked
SWITCH_EVENT_CHANNEL_UNPARK - A channel has been unparked
SWITCH_EVENT_CHANNEL_APPLICATION- A channel has called and event from an application
SWITCH_EVENT_API - An API call has been executed
SWITCH_EVENT_LOG - A LOG event has been triggered
SWITCH_EVENT_INBOUND_CHAN - A new inbound channel has been created
@ -872,12 +874,14 @@ typedef enum {
SWITCH_EVENT_CHANNEL_ANSWER,
SWITCH_EVENT_CHANNEL_HANGUP,
SWITCH_EVENT_CHANNEL_EXECUTE,
SWITCH_EVENT_CHANNEL_EXECUTE_COMPLETE,
SWITCH_EVENT_CHANNEL_BRIDGE,
SWITCH_EVENT_CHANNEL_UNBRIDGE,
SWITCH_EVENT_CHANNEL_PROGRESS,
SWITCH_EVENT_CHANNEL_OUTGOING,
SWITCH_EVENT_CHANNEL_PARK,
SWITCH_EVENT_CHANNEL_UNPARK,
SWITCH_EVENT_CHANNEL_APPLICATION,
SWITCH_EVENT_API,
SWITCH_EVENT_LOG,
SWITCH_EVENT_INBOUND_CHAN,

View File

@ -443,6 +443,53 @@ SWITCH_STANDARD_APP(info_function)
}
SWITCH_STANDARD_APP(event_function)
{
switch_channel_t *channel;
switch_event_t *event;
char *argv[25];
int argc = 0;
char *lbuf;
channel = switch_core_session_get_channel(session);
assert(channel != NULL);
if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_APPLICATION) == SWITCH_STATUS_SUCCESS) {
switch_channel_event_set_data(channel, event);
if (data && (lbuf = switch_core_session_strdup(session, data))
&& (argc = switch_separate_string(lbuf, ',', argv, (sizeof(argv) / sizeof(argv[0]))))) {
int x = 0;
for (x = 0; x < argc; x++) {
char *p, *this = argv[x];
p = this;
while(*p == ' ') *p++ = '\0';
this = p;
if (this) {
char *var = this, *val = NULL;
if ((val = strchr(var, '='))) {
p = val - 1;
*val++ = '\0';
while(*p == ' ') *p-- = '\0';
p = val;
while(*p == ' ') *p++ = '\0';
val = p;
switch_event_add_header(event, SWITCH_STACK_BOTTOM, var, "%s", val);
}
}
}
}
switch_event_fire(&event);
}
}
SWITCH_STANDARD_APP(privacy_function)
{
switch_channel_t *channel;
@ -1082,6 +1129,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_dptools_load)
SWITCH_ADD_APP(app_interface, "hangup", "Hangup the call", "Hangup the call for a channel.", hangup_function, "[<cause>]", SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "log", "Logs a channel varaible", LOG_LONG_DESC, log_function, "<varname>", SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "info", "Display Call Info", "Display Call Info", info_function, "", SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "event", "Fire an event", "Fire an event", event_function, "", SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "export", "Export a channel varaible across a bridge", EXPORT_LONG_DESC, export_function, "<varname>=<value>", SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "set", "Set a channel varaible", SET_LONG_DESC, set_function, "<varname>=<value>", SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "unset", "Unset a channel varaible", UNSET_LONG_DESC, unset_function, "<varname>", SAF_SUPPORT_NOMEDIA);

View File

@ -642,12 +642,14 @@ static switch_status_t parse_command(listener_t * listener, switch_event_t *even
listener->event_list[SWITCH_EVENT_CHANNEL_ANSWER] = 1;
listener->event_list[SWITCH_EVENT_CHANNEL_HANGUP] = 1;
listener->event_list[SWITCH_EVENT_CHANNEL_EXECUTE] = 1;
listener->event_list[SWITCH_EVENT_CHANNEL_EXECUTE_COMPLETE] = 1;
listener->event_list[SWITCH_EVENT_CHANNEL_BRIDGE] = 1;
listener->event_list[SWITCH_EVENT_CHANNEL_UNBRIDGE] = 1;
listener->event_list[SWITCH_EVENT_CHANNEL_PROGRESS] = 1;
listener->event_list[SWITCH_EVENT_CHANNEL_OUTGOING] = 1;
listener->event_list[SWITCH_EVENT_CHANNEL_PARK] = 1;
listener->event_list[SWITCH_EVENT_CHANNEL_UNPARK] = 1;
listener->event_list[SWITCH_EVENT_CHANNEL_APPLICATION] = 1;
listener->event_list[SWITCH_EVENT_TALK] = 1;
listener->event_list[SWITCH_EVENT_DTMF] = 1;
listener->event_list[SWITCH_EVENT_NOTALK] = 1;

View File

@ -912,7 +912,8 @@ SWITCH_DECLARE(switch_app_log_t *) switch_core_session_get_app_log(switch_core_s
SWITCH_DECLARE(switch_status_t) switch_core_session_exec(switch_core_session_t *session,
const switch_application_interface_t *application_interface, char *arg) {
switch_app_log_t *log, *lp;
switch_event_t *event;
log = switch_core_session_alloc(session, sizeof(*log));
assert(log != NULL);
@ -928,7 +929,21 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_exec(switch_core_session_t *
session->app_log = log;
}
if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_EXECUTE) == SWITCH_STATUS_SUCCESS) {
switch_channel_event_set_data(session->channel, event);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Application", "%s", application_interface->interface_name);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Application-Data", "%s", arg);
switch_event_fire(&event);
}
application_interface->application_function(session, arg);
if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_EXECUTE_COMPLETE) == SWITCH_STATUS_SUCCESS) {
switch_channel_event_set_data(session->channel, event);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Application", "%s", application_interface->interface_name);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Application-Data", "%s", arg);
switch_event_fire(&event);
}
return SWITCH_STATUS_SUCCESS;
}

View File

@ -108,7 +108,6 @@ static void switch_core_standard_on_ring(switch_core_session_t *session)
static void switch_core_standard_on_execute(switch_core_session_t *session)
{
switch_caller_extension_t *extension;
switch_event_t *event;
const switch_application_interface_t *application_interface;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Standard EXECUTE\n");
@ -149,15 +148,6 @@ static void switch_core_standard_on_execute(switch_core_session_t *session)
expanded);
}
if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_EXECUTE) == SWITCH_STATUS_SUCCESS) {
switch_channel_event_set_data(session->channel, event);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Application", "%s", extension->current_application->application_name);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Application-Data-Orig", "%s", extension->current_application->application_data);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Application-Data", "%s", expanded);
switch_event_fire(&event);
}
if (switch_channel_get_variable(session->channel, "presence_id")) {
char *arg = switch_mprintf("%s(%s)", extension->current_application->application_name, expanded);
if (arg) {

View File

@ -103,12 +103,14 @@ static char *EVENT_NAMES[] = {
"CHANNEL_ANSWER",
"CHANNEL_HANGUP",
"CHANNEL_EXECUTE",
"CHANNEL_EXECUTE_COMPLETE",
"CHANNEL_BRIDGE",
"CHANNEL_UNBRIDGE",
"CHANNEL_PROGRESS",
"CHANNEL_OUTGOING",
"CHANNEL_PARK",
"CHANNEL_UNPARK",
"CHANNEL_APPLICATION",
"API",
"LOG",
"INBOUND_CHAN",