Hi,
First of all, pardon my English. English isn’t my
native language J.
I am reading the method switch_core_session_run(switch_core_session_t
*session) and I would be really appreciated if someone could shed some light on
how the method works. Below is the logic according to my understanding:
1.
LINE 303: while ((state =
switch_channel_get_state(session->channel)) != CS_DESTROY)
ð if
state is CS_DESTROY return and do nothing ?
2.
Inside if (state !=
switch_channel_get_running_state(session->channel) || state >= CS_HANGUP)
{
…
}
a. LINE
308: state !=
switch_channel_get_running_state(session->channel) || state >= CS_HANGUP
ð to
check if channel->state and channel->running_state not equal. This is to
avoid running the STATE_MACRO multiple times. However I don’t understand
why do we need (state >= CS_HANGUP) ?.
b. Inside
STATE_MACRO code block
i.
LINE 229: midstate = state
ð to
save the current state.
ii.
LINE 231: if
(!driver_state_handler->on_##__STATE ||
(driver_state_handler->on_##__STATE(session) == SWITCH_STATUS_SUCCESS)
ð to
check either endpoint_interface->state_handler is NULL or return
SWITCH_STATUS_SUCCESS so it will continue to execute handlers in session->channel,
runtime.state_handlers and core standard state handlers. It means if the
condition is not true, channel->state_handlers, runtime.state_handlers and
core standard state handlers will NOT be executed at all ?
iii.
LINE 246: if (!proceed) global_proceed =
0;
ð If something
wrong in the previous while loop, do not run core standard state handlers ?
iv.
LINE 247: proceed = 1;
LINE 248: while
(do_extra_handlers && proceed && (application_state_handler =
switch_core_get_state_handler(index++)) != 0) { …}
ð Since
we set proceed = 1, do we still need (&& proceed) inside the condition
in while loop ?
v.
LINE 260: if (!proceed || midstate !=
switch_channel_get_state(session->channel)) global_proceed = 0;
ð If not
proceed or the channel state has changed by some of the state handlers executed
earlier, do not execute core standard state handler ?
vi.
LINE 266: while (silly)
ð silly
is never changed, does it mean we could go into an endless while loop ?
Sorry for the long email and some
questions are probably dumb but I am trying to understand about FreeSwitch, especially
the core and the core state machine. If it is documented somewhere about the
workflow happening inside FreeSwitch, please enlighten me as what I am doing
now is to read the code line by line and figure out which may not be the most
efficient .
Thank you for reading this
Regards
Alex To