<br><br><div class="gmail_quote">On Wed, Jan 6, 2010 at 9:20 AM, Alex To <span dir="ltr"><<a href="mailto:tonhudung@gmail.com">tonhudung@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div link="blue" vlink="purple" lang="EN-US">
<div>
<p class="MsoNormal">Hi,</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">First of all, pardon my English. English isn’t my
native language <span style="font-family: Wingdings;">J</span>.</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">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:</p>
<p class="MsoNormal"> </p>
<p><span>1.<span style="font-family: "Times New Roman"; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">
</span></span>LINE 303: while ((state =
switch_channel_get_state(session->channel)) != CS_DESTROY) </p>
<p style="margin-left: 0.75in;"><span style="font-size: 10pt; font-family: Wingdings; color: blue;"><span>ð<span style="font-family: "Times New Roman"; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"> </span></span></span>if
state is CS_DESTROY return and do nothing ?</p>
<p class="MsoNormal"> </p></div></div></blockquote><div>state typically starts at CS_NEW the loop runs until state destroy is reached <br><br><br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div link="blue" vlink="purple" lang="EN-US"><div>
<p><span>2.<span style="font-family: "Times New Roman"; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">
</span></span>Inside if (state !=
switch_channel_get_running_state(session->channel) || state >= CS_HANGUP)
</p>
<p class="MsoNormal" style="margin-left: 0.5in; text-indent: 0.5in;">{ </p>
<p class="MsoNormal" style="margin-left: 99pt; text-indent: 9pt;">… </p>
<p class="MsoNormal" style="margin-left: 0.5in; text-indent: 0.5in;">} </p>
<p style="margin-left: 1in;"><span>a.<span style="font-family: "Times New Roman"; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"> </span></span>LINE
308: state !=
switch_channel_get_running_state(session->channel) || state >= CS_HANGUP</p>
<p style="margin-left: 1.25in;"><span style="font-size: 10pt; font-family: Wingdings; color: blue;"><span>ð<span style="font-family: "Times New Roman"; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"> </span></span></span>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) ?.</p></div></div></blockquote><div><br>Once we are >= HANGUP we dont want to do that test anymore.<br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div link="blue" vlink="purple" lang="EN-US"><div>
<p style="margin-left: 1in;"><span>b.<span style="font-family: "Times New Roman"; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"> </span></span>Inside
STATE_MACRO code block</p>
<p style="margin-left: 1.5in;"><span><span style="font-family: "Times New Roman"; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">
</span>i.<span style="font-family: "Times New Roman"; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">
</span></span>LINE 229: midstate = state</p>
<p style="margin-left: 1.75in;"><span style="font-size: 10pt; font-family: Wingdings; color: blue;"><span>ð<span style="font-family: "Times New Roman"; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"> </span></span></span> to
save the current state.</p>
<p style="margin-left: 1.5in;"><span><span style="font-family: "Times New Roman"; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">
</span>ii.<span style="font-family: "Times New Roman"; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">
</span></span>LINE 231: if
(!driver_state_handler->on_##__STATE ||
(driver_state_handler->on_##__STATE(session) == SWITCH_STATUS_SUCCESS)</p>
<p style="margin-left: 1.75in;"><span style="font-size: 10pt; font-family: Wingdings; color: blue;"><span>ð<span style="font-family: "Times New Roman"; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"> </span></span></span>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 ?</p>
<p style="margin-left: 1.5in;"><span><span style="font-family: "Times New Roman"; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">
</span>iii.<span style="font-family: "Times New Roman"; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">
</span></span>LINE 246: if (!proceed) global_proceed =
0;</p>
<p style="margin-left: 1.75in;"><span style="font-size: 10pt; font-family: Wingdings; color: blue;"><span>ð<span style="font-family: "Times New Roman"; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"> </span></span></span>If something
wrong in the previous while loop, do not run core standard state handlers ?</p></div></div></blockquote><div>yes the endpoints have the power to veto state handlers from being called<br><br><br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div link="blue" vlink="purple" lang="EN-US"><div>
<p style="margin-left: 1.5in;"><span><span style="font-family: "Times New Roman"; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">
</span>iv.<span style="font-family: "Times New Roman"; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">
</span></span>LINE 247: proceed = 1; </p>
<p class="MsoNormal" style="margin-left: 1.5in;">LINE 248: while
(do_extra_handlers && proceed && (application_state_handler =
switch_core_get_state_handler(index++)) != 0) { …}</p>
<p style="margin-left: 1.75in;"><span style="font-size: 10pt; font-family: Wingdings; color: blue;"><span>ð<span style="font-family: "Times New Roman"; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"> </span></span></span>Since
we set proceed = 1, do we still need (&& proceed) inside the condition
in while loop ?</p></div></div></blockquote><div>yes because proceed can become 0 within that loop<br><br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div link="blue" vlink="purple" lang="EN-US"><div>
<p style="margin-left: 1.5in;"><span><span style="font-family: "Times New Roman"; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">
</span>v.<span style="font-family: "Times New Roman"; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">
</span></span>LINE 260: if (!proceed || midstate !=
switch_channel_get_state(session->channel)) global_proceed = 0;</p>
<p style="margin-left: 1.75in;"><span style="font-size: 10pt; font-family: Wingdings; color: blue;"><span>ð<span style="font-family: "Times New Roman"; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"> </span></span></span>If not
proceed or the channel state has changed by some of the state handlers executed
earlier, do not execute core standard state handler ?</p></div></div></blockquote><div>Again, veto power.<br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div link="blue" vlink="purple" lang="EN-US"><div>
<p style="margin-left: 1.5in;"><span><span style="font-family: "Times New Roman"; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">
</span>vi.<span style="font-family: "Times New Roman"; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">
</span></span>LINE 266: while (silly)</p>
<p style="margin-left: 1.75in; text-align: justify;"><span style="font-size: 10pt; font-family: Wingdings; color: blue;"><span>ð<span style="font-family: "Times New Roman"; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"> </span></span></span>silly
is never changed, does it mean we could go into an endless while loop ?</p>
<p class="MsoNormal" style="text-align: justify;"> </p></div></div></blockquote><div>Its to stop the compiler from getting mad, that's why it's called silly its specific to using a while loop inside a macro<br><br>
</div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div link="blue" vlink="purple" lang="EN-US"><div>
<p class="MsoNormal" style="text-align: justify;">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 .</p>
<p class="MsoNormal" style="text-align: justify;"> </p></div></div></blockquote><div><br>Why are you digging into this code? do you have some problem you are attempting to solve?<br>The most important thing is that code like this that has taken so long to perfect, even if there could be improvements, is hard to even look at without causing regressions. So I'm curious what you were looking for.<br>
<br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div link="blue" vlink="purple" lang="EN-US"><div>
<p class="MsoNormal" style="text-align: justify;">Thank you for reading this</p>
<p class="MsoNormal" style="text-align: justify;"> </p>
<p class="MsoNormal" style="text-align: justify;">Regards</p>
<p class="MsoNormal" style="text-align: justify;"> </p>
<p class="MsoNormal" style="text-align: justify;">Alex To</p>
<p class="MsoNormal" style="text-align: justify;"> </p>
<p class="MsoNormal" style="text-align: justify;"> </p>
</div>
</div>
<br>_______________________________________________<br>
FreeSWITCH-dev mailing list<br>
<a href="mailto:FreeSWITCH-dev@lists.freeswitch.org">FreeSWITCH-dev@lists.freeswitch.org</a><br>
<a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-dev" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-dev</a><br>
UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-dev" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-dev</a><br>
<a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br>Anthony Minessale II<br><br>FreeSWITCH <a href="http://www.freeswitch.org/">http://www.freeswitch.org/</a><br>ClueCon <a href="http://www.cluecon.com/">http://www.cluecon.com/</a><br>
Twitter: <a href="http://twitter.com/FreeSWITCH_wire">http://twitter.com/FreeSWITCH_wire</a><br><br>AIM: anthm<br><a href="mailto:MSN%3Aanthony_minessale@hotmail.com">MSN:anthony_minessale@hotmail.com</a><br>GTALK/JABBER/<a href="mailto:PAYPAL%3Aanthony.minessale@gmail.com">PAYPAL:anthony.minessale@gmail.com</a><br>
IRC: <a href="http://irc.freenode.net">irc.freenode.net</a> #freeswitch<br><br>FreeSWITCH Developer Conference<br><a href="mailto:sip%3A888@conference.freeswitch.org">sip:888@conference.freeswitch.org</a><br><a href="http://iax:guest@conference.freeswitch.org/888">iax:guest@conference.freeswitch.org/888</a><br>
<a href="mailto:googletalk%3Aconf%2B888@conference.freeswitch.org">googletalk:conf+888@conference.freeswitch.org</a><br>pstn:+19193869900<br>