From 911db88a6e622f2f98ef11444cf109a84391c95d Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 13 Dec 2007 22:17:20 +0000 Subject: [PATCH] add park_state git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@6771 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/include/switch_ivr.h | 1 + src/include/switch_module_interfaces.h | 3 ++ src/include/switch_types.h | 2 + .../applications/mod_commands/mod_commands.c | 46 ++++++++++++++++--- .../applications/mod_dptools/mod_dptools.c | 9 +++- src/switch_channel.c | 23 ++++++++++ src/switch_core_state_machine.c | 12 +++++ src/switch_ivr.c | 7 +++ 8 files changed, 95 insertions(+), 8 deletions(-) diff --git a/src/include/switch_ivr.h b/src/include/switch_ivr.h index 0dfeebff63..bbc05e087e 100644 --- a/src/include/switch_ivr.h +++ b/src/include/switch_ivr.h @@ -719,6 +719,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_phrase_macro(switch_core_session_t *s switch_input_args_t *args); SWITCH_DECLARE(void) switch_ivr_delay_echo(switch_core_session_t *session, uint32_t delay_ms); SWITCH_DECLARE(void) switch_ivr_intercept_session(switch_core_session_t *session, const char *uuid); +SWITCH_DECLARE(void) switch_ivr_park_session(switch_core_session_t *session); /** @} */ diff --git a/src/include/switch_module_interfaces.h b/src/include/switch_module_interfaces.h index 4611b673f7..39134a29f2 100644 --- a/src/include/switch_module_interfaces.h +++ b/src/include/switch_module_interfaces.h @@ -53,6 +53,7 @@ typedef enum { SWITCH_SHN_ON_HANGUP, SWITCH_SHN_ON_LOOPBACK, SWITCH_SHN_ON_TRANSMIT, + SWITCH_SHN_ON_PARK, SWITCH_SHN_ON_HOLD, SWITCH_SHN_ON_HIBERNATE, SWITCH_SHN_ON_RESET @@ -71,6 +72,8 @@ struct switch_state_handler_table { switch_state_handler_t on_loopback; /*! executed when the state changes to transmit */ switch_state_handler_t on_transmit; + /*! executed when the state changes to park */ + switch_state_handler_t on_park; /*! executed when the state changes to hold */ switch_state_handler_t on_hold; /*! executed when the state changes to hibernate */ diff --git a/src/include/switch_types.h b/src/include/switch_types.h index 03c4066886..0f9a512734 100644 --- a/src/include/switch_types.h +++ b/src/include/switch_types.h @@ -560,6 +560,7 @@ CS_RING - Channel is looking for a dialplan CS_TRANSMIT - Channel is in a passive transmit state CS_EXECUTE - Channel is executing it's dialplan CS_LOOPBACK - Channel is in loopback +CS_PARK - Channel is parked CS_HOLD - Channel is on hold CS_HIBERNATE - Channel is in a sleep state CS_RESET - Channel is in a reset state @@ -574,6 +575,7 @@ typedef enum { CS_TRANSMIT, CS_EXECUTE, CS_LOOPBACK, + CS_PARK, CS_HOLD, CS_HIBERNATE, CS_RESET, diff --git a/src/mod/applications/mod_commands/mod_commands.c b/src/mod/applications/mod_commands/mod_commands.c index c69ba88941..e88185bd18 100644 --- a/src/mod/applications/mod_commands/mod_commands.c +++ b/src/mod/applications/mod_commands/mod_commands.c @@ -685,6 +685,29 @@ SWITCH_STANDARD_API(kill_function) return SWITCH_STATUS_SUCCESS; } + +#define PARK_SYNTAX "" +SWITCH_STANDARD_API(park_function) +{ + switch_core_session_t *ksession = NULL; + + if (session) { + return SWITCH_STATUS_FALSE; + } + + if (!cmd) { + stream->write_function(stream, "-USAGE: %s\n", PARK_SYNTAX); + } else if ((ksession = switch_core_session_locate(cmd))) { + switch_ivr_park_session(ksession); + switch_core_session_rwunlock(ksession); + stream->write_function(stream, "+OK\n"); + } else { + stream->write_function(stream, "-ERR No Such Channel!\n"); + } + + return SWITCH_STATUS_SUCCESS; +} + #define TRANSFER_SYNTAX " [-bleg|-both] [] []" SWITCH_STANDARD_API(transfer_function) { @@ -1994,11 +2017,14 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load) SWITCH_ADD_API(commands_api_interface, "originate", "Originate a Call", originate_function, ORIGINATE_SYNTAX); SWITCH_ADD_API(commands_api_interface, "tone_detect", "Start Tone Detection on a channel", tone_detect_session_function, TONE_DETECT_SYNTAX); - SWITCH_ADD_API(commands_api_interface, "killchan", "Kill Channel", kill_function, KILL_SYNTAX); + SWITCH_ADD_API(commands_api_interface, "killchan", "Kill Channel (depricated)", kill_function, KILL_SYNTAX); + SWITCH_ADD_API(commands_api_interface, "uuid_kill", "Kill Channel", kill_function, KILL_SYNTAX); + SWITCH_ADD_API(commands_api_interface, "uuid_park", "Park Channel", park_function, PARK_SYNTAX); SWITCH_ADD_API(commands_api_interface, "reloadxml", "Reload XML", reload_function, ""); SWITCH_ADD_API(commands_api_interface, "unload", "Unload Module", unload_function, LOAD_SYNTAX); SWITCH_ADD_API(commands_api_interface, "load", "Load Module", load_function, LOAD_SYNTAX); - SWITCH_ADD_API(commands_api_interface, "transfer", "Transfer Module", transfer_function, TRANSFER_SYNTAX); + SWITCH_ADD_API(commands_api_interface, "transfer", "Transfer (depricated)", transfer_function, TRANSFER_SYNTAX); + SWITCH_ADD_API(commands_api_interface, "uuid_transfer", "Transfer a session", transfer_function, TRANSFER_SYNTAX); SWITCH_ADD_API(commands_api_interface, "pause", "Pause", pause_function, PAUSE_SYNTAX); SWITCH_ADD_API(commands_api_interface, "break", "Break", break_function, BREAK_SYNTAX); SWITCH_ADD_API(commands_api_interface, "show", "Show", show_function, SHOW_SYNTAX); @@ -2008,11 +2034,17 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load) SWITCH_ADD_API(commands_api_interface, "uuid_getvar", "uuid_getvar", uuid_getvar_function, GETVAR_SYNTAX); SWITCH_ADD_API(commands_api_interface, "global_setvar", "global_setvar", global_setvar_function, GLOBAL_SETVAR_SYNTAX); SWITCH_ADD_API(commands_api_interface, "global_getvar", "global_getvar", global_getvar_function, GLOBAL_GETVAR_SYNTAX); - SWITCH_ADD_API(commands_api_interface, "session_displace", "session displace", session_displace_function, " [start|stop] [] [mux]"); - SWITCH_ADD_API(commands_api_interface, "session_record", "session record", session_record_function, SESS_REC_SYNTAX); - SWITCH_ADD_API(commands_api_interface, "broadcast", "broadcast", uuid_broadcast_function, BROADCAST_SYNTAX); - SWITCH_ADD_API(commands_api_interface, "hold", "hold", uuid_hold_function, HOLD_SYNTAX); - SWITCH_ADD_API(commands_api_interface, "media", "media", uuid_media_function, MEDIA_SYNTAX); + SWITCH_ADD_API(commands_api_interface, "session_displace", "session displace (depricated)", + session_displace_function, " [start|stop] [] [mux]"); + SWITCH_ADD_API(commands_api_interface, "uuid_displace", "session displace", session_displace_function, " [start|stop] [] [mux]"); + SWITCH_ADD_API(commands_api_interface, "session_record", "session record (depricated)", session_record_function, SESS_REC_SYNTAX); + SWITCH_ADD_API(commands_api_interface, "uuid_record", "session record", session_record_function, SESS_REC_SYNTAX); + SWITCH_ADD_API(commands_api_interface, "broadcast", "broadcast (depricated)", uuid_broadcast_function, BROADCAST_SYNTAX); + SWITCH_ADD_API(commands_api_interface, "uuid_broadcast", "broadcast", uuid_broadcast_function, BROADCAST_SYNTAX); + SWITCH_ADD_API(commands_api_interface, "hold", "hold (depricated)", uuid_hold_function, HOLD_SYNTAX); + SWITCH_ADD_API(commands_api_interface, "uuid_hold", "hold", uuid_hold_function, HOLD_SYNTAX); + SWITCH_ADD_API(commands_api_interface, "media", "media (depricated)", uuid_media_function, MEDIA_SYNTAX); + SWITCH_ADD_API(commands_api_interface, "uuid media", "media", uuid_media_function, MEDIA_SYNTAX); SWITCH_ADD_API(commands_api_interface, "fsctl", "control messages", ctl_function, CTL_SYNTAX); SWITCH_ADD_API(commands_api_interface, "help", "Show help for all the api commands", help_function, ""); SWITCH_ADD_API(commands_api_interface, "version", "Show version of the switch", version_function, ""); diff --git a/src/mod/applications/mod_dptools/mod_dptools.c b/src/mod/applications/mod_dptools/mod_dptools.c index 2ebe74375f..f7ac9ee165 100644 --- a/src/mod/applications/mod_dptools/mod_dptools.c +++ b/src/mod/applications/mod_dptools/mod_dptools.c @@ -1027,6 +1027,12 @@ SWITCH_STANDARD_APP(park_function) } +SWITCH_STANDARD_APP(park_state_function) +{ + switch_ivr_park_session(session); + +} + /********************************************************************************/ /* Playback/Record Functions */ /********************************************************************************/ @@ -1637,7 +1643,8 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_dptools_load) SWITCH_ADD_APP(app_interface, "fax_detect", "Detect faxes", "Detect fax send tone", fax_detect_session_function, "", SAF_NONE); SWITCH_ADD_APP(app_interface, "tone_detect", "Detect tones", "Detect tones", tone_detect_session_function, "", SAF_NONE); SWITCH_ADD_APP(app_interface, "echo", "Echo", "Perform an echo test against the calling channel", echo_function, "", SAF_NONE); - SWITCH_ADD_APP(app_interface, "park", NULL, NULL, park_function, NULL, SAF_NONE); + SWITCH_ADD_APP(app_interface, "park", "Park", "Park", park_function, "", SAF_NONE); + SWITCH_ADD_APP(app_interface, "park_state", "Park State", "Park State", park_state_function, "", SAF_NONE); SWITCH_ADD_APP(app_interface, "gentones", "Generate Tones", "Generate tones to the channel", gentones_function, "[|]", SAF_NONE); SWITCH_ADD_APP(app_interface, "playback", "Playback File", "Playback a file to the channel", playback_function, "", SAF_NONE); SWITCH_ADD_APP(app_interface, "stop_record_session", "Stop Record Session", STOP_SESS_REC_DESC, stop_record_session_function, "", SAF_NONE); diff --git a/src/switch_channel.c b/src/switch_channel.c index 1a2f715e6b..3e6556c477 100644 --- a/src/switch_channel.c +++ b/src/switch_channel.c @@ -553,6 +553,7 @@ static const char *state_names[] = { "CS_TRANSMIT", "CS_EXECUTE", "CS_LOOPBACK", + "CS_PARK", "CS_HOLD", "CS_HIBERNATE", "CS_RESET", @@ -666,6 +667,7 @@ SWITCH_DECLARE(switch_channel_state_t) switch_channel_perform_set_state(switch_c case CS_TRANSMIT: case CS_RING: case CS_EXECUTE: + case CS_PARK: case CS_HOLD: case CS_HIBERNATE: case CS_RESET: @@ -680,6 +682,7 @@ SWITCH_DECLARE(switch_channel_state_t) switch_channel_perform_set_state(switch_c case CS_TRANSMIT: case CS_RING: case CS_EXECUTE: + case CS_PARK: case CS_HOLD: case CS_HIBERNATE: case CS_RESET: @@ -694,6 +697,7 @@ SWITCH_DECLARE(switch_channel_state_t) switch_channel_perform_set_state(switch_c case CS_LOOPBACK: case CS_RING: case CS_EXECUTE: + case CS_PARK: case CS_HOLD: case CS_HIBERNATE: case CS_RESET: @@ -703,6 +707,21 @@ SWITCH_DECLARE(switch_channel_state_t) switch_channel_perform_set_state(switch_c } break; + case CS_PARK: + switch (state) { + case CS_LOOPBACK: + case CS_RING: + case CS_EXECUTE: + case CS_TRANSMIT: + case CS_HIBERNATE: + case CS_RESET: + case CS_HOLD: + ok++; + default: + break; + } + break; + case CS_HOLD: switch (state) { case CS_LOOPBACK: @@ -711,6 +730,7 @@ SWITCH_DECLARE(switch_channel_state_t) switch_channel_perform_set_state(switch_c case CS_TRANSMIT: case CS_HIBERNATE: case CS_RESET: + case CS_PARK: ok++; default: break; @@ -723,6 +743,7 @@ SWITCH_DECLARE(switch_channel_state_t) switch_channel_perform_set_state(switch_c case CS_RING: case CS_EXECUTE: case CS_TRANSMIT: + case CS_PARK: case CS_HOLD: case CS_RESET: ok++; @@ -737,6 +758,7 @@ SWITCH_DECLARE(switch_channel_state_t) switch_channel_perform_set_state(switch_c case CS_LOOPBACK: case CS_EXECUTE: case CS_TRANSMIT: + case CS_PARK: case CS_HOLD: case CS_HIBERNATE: case CS_RESET: @@ -751,6 +773,7 @@ SWITCH_DECLARE(switch_channel_state_t) switch_channel_perform_set_state(switch_c case CS_LOOPBACK: case CS_TRANSMIT: case CS_RING: + case CS_PARK: case CS_HOLD: case CS_HIBERNATE: case CS_RESET: diff --git a/src/switch_core_state_machine.c b/src/switch_core_state_machine.c index d608f78699..2b7e65edf4 100644 --- a/src/switch_core_state_machine.c +++ b/src/switch_core_state_machine.c @@ -205,6 +205,15 @@ static void switch_core_standard_on_transmit(switch_core_session_t *session) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Standard TRANSMIT\n"); } +static void switch_core_standard_on_park(switch_core_session_t *session) +{ + switch_assert(session != NULL); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Standard PARK\n"); + switch_channel_clear_flag(session->channel, CF_TRANSFER); + switch_core_session_reset(session); + switch_ivr_park(session, NULL); +} + static void switch_core_standard_on_hold(switch_core_session_t *session) { switch_assert(session != NULL); @@ -419,6 +428,9 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session_t *session) case CS_TRANSMIT: /* send/recieve data to/from another channel */ STATE_MACRO(transmit, "TRANSMIT"); break; + case CS_PARK: /* wait in limbo */ + STATE_MACRO(park, "PARK"); + break; case CS_HOLD: /* wait in limbo */ STATE_MACRO(hold, "HOLD"); break; diff --git a/src/switch_ivr.c b/src/switch_ivr.c index d9fea5ed31..693f0fb8ef 100644 --- a/src/switch_ivr.c +++ b/src/switch_ivr.c @@ -1494,6 +1494,13 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_generate_xml_cdr(switch_core_session_ return SWITCH_STATUS_FALSE; } +SWITCH_DECLARE(void) switch_ivr_park_session(switch_core_session_t *session) +{ + switch_channel_t *channel = switch_core_session_get_channel(session); + switch_channel_set_state_flag(channel, CF_TRANSFER); + switch_channel_set_state(channel, CS_PARK); +} + SWITCH_DECLARE(void) switch_ivr_delay_echo(switch_core_session_t *session, uint32_t delay_ms) { stfu_instance_t *jb;