[Freeswitch-svn] [commit] r5448 - in freeswitch/trunk/src: . include mod/applications/mod_dptools mod/event_handlers/mod_event_socket
Author: anthm Date: Sat Jun 23 01:41:07 2007 New Revision: 5448 Modified: freeswitch/trunk/src/include/switch_types.h freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c freeswitch/trunk/src/mod/event_handlers/mod_event_socket/mod_event_socket.c freeswitch/trunk/src/switch_core_session.c freeswitch/trunk/src/switch_core_state_machine.c freeswitch/trunk/src/switch_event.c Log: 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. Modified: freeswitch/trunk/src/include/switch_types.h ============================================================================== --- freeswitch/trunk/src/include/switch_types.h (original) +++ freeswitch/trunk/src/include/switch_types.h Sat Jun 23 01:41:07 2007 @@ -823,12 +823,14 @@ 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 @@ 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, Modified: freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c ============================================================================== --- freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c (original) +++ freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c Sat Jun 23 01:41:07 2007 @@ -443,6 +443,53 @@ } + + +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_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); Modified: freeswitch/trunk/src/mod/event_handlers/mod_event_socket/mod_event_socket.c ============================================================================== --- freeswitch/trunk/src/mod/event_handlers/mod_event_socket/mod_event_socket.c (original) +++ freeswitch/trunk/src/mod/event_handlers/mod_event_socket/mod_event_socket.c Sat Jun 23 01:41:07 2007 @@ -642,12 +642,14 @@ 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; Modified: freeswitch/trunk/src/switch_core_session.c ============================================================================== --- freeswitch/trunk/src/switch_core_session.c (original) +++ freeswitch/trunk/src/switch_core_session.c Sat Jun 23 01:41:07 2007 @@ -912,7 +912,8 @@ 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 @@ 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; } Modified: freeswitch/trunk/src/switch_core_state_machine.c ============================================================================== --- freeswitch/trunk/src/switch_core_state_machine.c (original) +++ freeswitch/trunk/src/switch_core_state_machine.c Sat Jun 23 01:41:07 2007 @@ -108,7 +108,6 @@ 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 @@ 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) { Modified: freeswitch/trunk/src/switch_event.c ============================================================================== --- freeswitch/trunk/src/switch_event.c (original) +++ freeswitch/trunk/src/switch_event.c Sat Jun 23 01:41:07 2007 @@ -103,12 +103,14 @@ "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",
participants (1)
-
Freeswitch SVN