From 9bcc841bb00bfd7c6bdf86f8d5f20e3daac691bf Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 3 Feb 2009 17:17:31 +0000 Subject: [PATCH] Modify state machine behaviour. Endpoint handlers can still veto all other state handlers by returning SWITCH_STATUS_FALSE Application handlers can only veto each other by returning SWITCH_STATUS_FALSE. Global handlers will still be called when application vetos but they can still veto each other. Default handler will not be called if application or global vetos or if state has changed from any handler. git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@11610 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/switch_core_state_machine.c | 12 ++++++++---- src/switch_ivr_originate.c | 6 ++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/switch_core_state_machine.c b/src/switch_core_state_machine.c index d508771fad..c687495369 100644 --- a/src/switch_core_state_machine.c +++ b/src/switch_core_state_machine.c @@ -276,12 +276,12 @@ void switch_core_state_machine_init(switch_memory_pool_t *pool) midstate = state; \ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) State %s\n", switch_channel_get_name(session->channel), __STATE_STR); \ if (!driver_state_handler->on_##__STATE || (driver_state_handler->on_##__STATE(session) == SWITCH_STATUS_SUCCESS \ - && midstate == switch_channel_get_state(session->channel))) { \ + )) { \ while (do_extra_handlers && (application_state_handler = switch_channel_get_state_handler(session->channel, index++)) != 0) { \ if (!application_state_handler || !application_state_handler->on_##__STATE \ || (application_state_handler->on_##__STATE \ && application_state_handler->on_##__STATE(session) == SWITCH_STATUS_SUCCESS \ - && midstate == switch_channel_get_state(session->channel))) { \ + )) { \ proceed++; \ continue; \ } else { \ @@ -290,11 +290,13 @@ void switch_core_state_machine_init(switch_memory_pool_t *pool) } \ } \ index = 0; \ + if (!proceed) global_proceed = 0; \ + proceed = 1; \ while (do_extra_handlers && proceed && (application_state_handler = switch_core_get_state_handler(index++)) != 0) { \ if (!application_state_handler || !application_state_handler->on_##__STATE || \ (application_state_handler->on_##__STATE && \ application_state_handler->on_##__STATE(session) == SWITCH_STATUS_SUCCESS \ - && midstate == switch_channel_get_state(session->channel))) { \ + )) { \ proceed++; \ continue; \ } else { \ @@ -302,7 +304,8 @@ void switch_core_state_machine_init(switch_memory_pool_t *pool) break; \ } \ } \ - if (proceed) { \ + if (!proceed || midstate != switch_channel_get_state(session->channel)) global_proceed = 0; \ + if (global_proceed) { \ switch_core_standard_on_##__STATE(session); \ } \ } \ @@ -374,6 +377,7 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session_t *session) if (state != switch_channel_get_running_state(session->channel) || state == CS_HANGUP) { int index = 0; int proceed = 1; + int global_proceed = 1; int do_extra_handlers = 1; switch_channel_set_running_state(session->channel, state); diff --git a/src/switch_ivr_originate.c b/src/switch_ivr_originate.c index 6b6186bbc9..c54b3314a7 100644 --- a/src/switch_ivr_originate.c +++ b/src/switch_ivr_originate.c @@ -58,8 +58,10 @@ static switch_status_t originate_on_routing(switch_core_session_t *session) { switch_channel_t *channel = switch_core_session_get_channel(session); - /* put the channel in a passive state until it is answered */ - switch_channel_set_state(channel, CS_CONSUME_MEDIA); + if (switch_channel_get_state(channel) == CS_ROUTING) { + /* put the channel in a passive state until it is answered */ + switch_channel_set_state(channel, CS_CONSUME_MEDIA); + } return SWITCH_STATUS_FALSE; }