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
This commit is contained in:
Anthony Minessale 2009-02-03 17:17:31 +00:00
parent 417bbd1569
commit 9bcc841bb0
2 changed files with 12 additions and 6 deletions

View File

@ -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);

View File

@ -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;
}