<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">

<head>
<meta http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<meta name=Generator content="Microsoft Word 12 (filtered medium)">
<style>
<!--
 /* Font Definitions */
 @font-face
        {font-family:Wingdings;
        panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
        {mso-style-priority:34;
        margin-top:0in;
        margin-right:0in;
        margin-bottom:0in;
        margin-left:.5in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page Section1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.Section1
        {page:Section1;}
 /* List Definitions */
 @list l0
        {mso-list-id:273901532;
        mso-list-type:hybrid;
        mso-list-template-ids:-982071680 67698703 67698713 67698715 67698703 67698713 67698715 67698703 67698713 67698715;}
@list l0:level1
        {mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;}
@list l0:level2
        {mso-level-number-format:alpha-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;}
@list l0:level3
        {mso-level-number-format:roman-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:right;
        text-indent:-9.0pt;}
@list l0:level4
        {mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;}
@list l1
        {mso-list-id:1245651125;
        mso-list-type:hybrid;
        mso-list-template-ids:243152312 67698715 67698713 67698715 67698703 67698713 67698715 67698703 67698713 67698715;}
@list l1:level1
        {mso-level-number-format:roman-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:right;
        margin-left:117.0pt;
        text-indent:-.25in;}
@list l2
        {mso-list-id:1291471228;
        mso-list-type:hybrid;
        mso-list-template-ids:1962689904 -1394170316 -1394170316 -1394170316 67698689 67698691 67698693 67698689 67698691 67698693;}
@list l2:level1
        {mso-level-number-format:bullet;
        mso-level-text:\F0F0;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        margin-left:.75in;
        text-indent:-.25in;
        mso-ansi-font-size:10.0pt;
        font-family:Wingdings;
        mso-fareast-font-family:Calibri;
        mso-bidi-font-family:"Courier New";
        color:blue;}
@list l2:level2
        {mso-level-number-format:bullet;
        mso-level-text:\F0F0;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        margin-left:1.25in;
        text-indent:-.25in;
        mso-ansi-font-size:10.0pt;
        font-family:Wingdings;
        mso-fareast-font-family:Calibri;
        mso-bidi-font-family:"Courier New";
        color:blue;}
@list l2:level3
        {mso-level-number-format:bullet;
        mso-level-text:\F0F0;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        margin-left:1.75in;
        text-indent:-.25in;
        mso-ansi-font-size:10.0pt;
        font-family:Wingdings;
        mso-fareast-font-family:Calibri;
        mso-bidi-font-family:"Courier New";
        color:blue;}
ol
        {margin-bottom:0in;}
ul
        {margin-bottom:0in;}
-->
</style>
<!--[if gte mso 9]><xml>
 <o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
 <o:shapelayout v:ext="edit">
  <o:idmap v:ext="edit" data="1" />
 </o:shapelayout></xml><![endif]-->
</head>

<body lang=EN-US link=blue vlink=purple>

<div class=Section1>

<p class=MsoNormal>Hi,<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>First of all, pardon my English. English isn&#8217;t my
native language <span style='font-family:Wingdings'>J</span>.<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></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:<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoListParagraph style='text-indent:-.25in;mso-list:l0 level1 lfo1'><![if !supportLists]><span
style='mso-list:Ignore'>1.<span style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span><![endif]>LINE 303:              while ((state =
switch_channel_get_state(session-&gt;channel)) != CS_DESTROY) <o:p></o:p></p>

<p class=MsoListParagraph style='margin-left:.75in;text-indent:-.25in;
mso-list:l2 level1 lfo2'><![if !supportLists]><span style='font-size:10.0pt;
font-family:Wingdings;color:blue'><span style='mso-list:Ignore'>ð<span
style='font:7.0pt "Times New Roman"'>&nbsp; </span></span></span><![endif]>if
state is CS_DESTROY return and do nothing ?<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoListParagraph style='text-indent:-.25in;mso-list:l0 level1 lfo1'><![if !supportLists]><span
style='mso-list:Ignore'>2.<span style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span><![endif]>Inside if (state !=
switch_channel_get_running_state(session-&gt;channel) || state &gt;= CS_HANGUP)
<o:p></o:p></p>

<p class=MsoNormal style='margin-left:.5in;text-indent:.5in'>{ <o:p></o:p></p>

<p class=MsoNormal style='margin-left:99.0pt;text-indent:9.0pt'>&#8230; <o:p></o:p></p>

<p class=MsoNormal style='margin-left:.5in;text-indent:.5in'>}                                              <o:p></o:p></p>

<p class=MsoListParagraph style='margin-left:1.0in;text-indent:-.25in;
mso-list:l0 level2 lfo1'><![if !supportLists]><span style='mso-list:Ignore'>a.<span
style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><![endif]>LINE
308:              state !=
switch_channel_get_running_state(session-&gt;channel) || state &gt;= CS_HANGUP<o:p></o:p></p>

<p class=MsoListParagraph style='margin-left:1.25in;text-indent:-.25in;
mso-list:l2 level2 lfo2'><![if !supportLists]><span style='font-size:10.0pt;
font-family:Wingdings;color:blue'><span style='mso-list:Ignore'>ð<span
style='font:7.0pt "Times New Roman"'>&nbsp; </span></span></span><![endif]>to
check if channel-&gt;state and channel-&gt;running_state not equal. This is to
avoid running the STATE_MACRO multiple times. However I don&#8217;t understand
why do we need (state &gt;= CS_HANGUP) ?.<o:p></o:p></p>

<p class=MsoListParagraph style='margin-left:1.0in;text-indent:-.25in;
mso-list:l0 level2 lfo1'><![if !supportLists]><span style='mso-list:Ignore'>b.<span
style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><![endif]>Inside
STATE_MACRO code block<o:p></o:p></p>

<p class=MsoListParagraph style='margin-left:1.5in;text-indent:-1.5in;
mso-text-indent-alt:-9.0pt;mso-list:l0 level3 lfo1'><![if !supportLists]><span
style='mso-list:Ignore'><span style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span>i.<span style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span><![endif]>LINE 229:              midstate = state<o:p></o:p></p>

<p class=MsoListParagraph style='margin-left:1.75in;text-indent:-.25in;
mso-list:l2 level3 lfo2'><![if !supportLists]><span style='font-size:10.0pt;
font-family:Wingdings;color:blue'><span style='mso-list:Ignore'>ð<span
style='font:7.0pt "Times New Roman"'>&nbsp; </span></span></span><![endif]> to
save the current state.<o:p></o:p></p>

<p class=MsoListParagraph style='margin-left:1.5in;text-indent:-1.5in;
mso-text-indent-alt:-9.0pt;mso-list:l0 level3 lfo1'><![if !supportLists]><span
style='mso-list:Ignore'><span style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span>ii.<span style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span><![endif]>LINE 231:              if
(!driver_state_handler-&gt;on_##__STATE ||
(driver_state_handler-&gt;on_##__STATE(session) == SWITCH_STATUS_SUCCESS)<o:p></o:p></p>

<p class=MsoListParagraph style='margin-left:1.75in;text-indent:-.25in;
mso-list:l2 level3 lfo2'><![if !supportLists]><span style='font-size:10.0pt;
font-family:Wingdings;color:blue'><span style='mso-list:Ignore'>ð<span
style='font:7.0pt "Times New Roman"'>&nbsp; </span></span></span><![endif]>to
check either endpoint_interface-&gt;state_handler is NULL or return
SWITCH_STATUS_SUCCESS so it will continue to execute handlers in session-&gt;channel,
runtime.state_handlers and core standard state handlers. It means if the
condition is not true, channel-&gt;state_handlers, runtime.state_handlers and
core standard state handlers will NOT be executed at all ?<o:p></o:p></p>

<p class=MsoListParagraph style='margin-left:1.5in;text-indent:-1.5in;
mso-text-indent-alt:-9.0pt;mso-list:l0 level3 lfo1'><![if !supportLists]><span
style='mso-list:Ignore'><span style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span>iii.<span style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span><![endif]>LINE 246:              if (!proceed) global_proceed =
0;<o:p></o:p></p>

<p class=MsoListParagraph style='margin-left:1.75in;text-indent:-.25in;
mso-list:l2 level3 lfo2'><![if !supportLists]><span style='font-size:10.0pt;
font-family:Wingdings;color:blue'><span style='mso-list:Ignore'>ð<span
style='font:7.0pt "Times New Roman"'>&nbsp; </span></span></span><![endif]>If something
wrong in the previous while loop, do not run core standard state handlers ?<o:p></o:p></p>

<p class=MsoListParagraph style='margin-left:1.5in;text-indent:-1.5in;
mso-text-indent-alt:-9.0pt;mso-list:l0 level3 lfo1;text-autospace:none'><![if !supportLists]><span
style='mso-list:Ignore'><span style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span>iv.<span style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span><![endif]>LINE 247:              proceed = 1;                                                                                                                                                                                       <o:p></o:p></p>

<p class=MsoNormal style='margin-left:1.5in'>LINE 248:              while
(do_extra_handlers &amp;&amp; proceed &amp;&amp; (application_state_handler =
switch_core_get_state_handler(index++)) != 0) { &#8230;}<o:p></o:p></p>

<p class=MsoListParagraph style='margin-left:1.75in;text-indent:-.25in;
mso-list:l2 level3 lfo2'><![if !supportLists]><span style='font-size:10.0pt;
font-family:Wingdings;color:blue'><span style='mso-list:Ignore'>ð<span
style='font:7.0pt "Times New Roman"'>&nbsp; </span></span></span><![endif]>Since
we set proceed = 1, do we still need (&amp;&amp; proceed) inside the condition
in while loop ?<o:p></o:p></p>

<p class=MsoListParagraph style='margin-left:1.5in;text-indent:-1.5in;
mso-text-indent-alt:-9.0pt;mso-list:l0 level3 lfo1'><![if !supportLists]><span
style='mso-list:Ignore'><span style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span>v.<span style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span><![endif]>LINE 260:              if (!proceed || midstate !=
switch_channel_get_state(session-&gt;channel)) global_proceed = 0;<o:p></o:p></p>

<p class=MsoListParagraph style='margin-left:1.75in;text-indent:-.25in;
mso-list:l2 level3 lfo2'><![if !supportLists]><span style='font-size:10.0pt;
font-family:Wingdings;color:blue'><span style='mso-list:Ignore'>ð<span
style='font:7.0pt "Times New Roman"'>&nbsp; </span></span></span><![endif]>If not
proceed or the channel state has changed by some of the state handlers executed
earlier, do not execute core standard state handler ?<o:p></o:p></p>

<p class=MsoListParagraph style='margin-left:1.5in;text-indent:-1.5in;
mso-text-indent-alt:-9.0pt;mso-list:l0 level3 lfo1'><![if !supportLists]><span
style='mso-list:Ignore'><span style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span>vi.<span style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span><![endif]>LINE 266:              while (silly)<o:p></o:p></p>

<p class=MsoListParagraph style='margin-left:1.75in;text-align:justify;
text-indent:-.25in;mso-list:l2 level3 lfo2'><![if !supportLists]><span
style='font-size:10.0pt;font-family:Wingdings;color:blue'><span
style='mso-list:Ignore'>ð<span style='font:7.0pt "Times New Roman"'>&nbsp; </span></span></span><![endif]>silly
is never changed, does it mean we could go into an endless while loop ?<o:p></o:p></p>

<p class=MsoNormal style='text-align:justify'><o:p>&nbsp;</o:p></p>

<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 .<o:p></o:p></p>

<p class=MsoNormal style='text-align:justify'><o:p>&nbsp;</o:p></p>

<p class=MsoNormal style='text-align:justify'>Thank you for reading this<o:p></o:p></p>

<p class=MsoNormal style='text-align:justify'><o:p>&nbsp;</o:p></p>

<p class=MsoNormal style='text-align:justify'>Regards<o:p></o:p></p>

<p class=MsoNormal style='text-align:justify'><o:p>&nbsp;</o:p></p>

<p class=MsoNormal style='text-align:justify'>Alex To<o:p></o:p></p>

<p class=MsoNormal style='text-align:justify'><o:p>&nbsp;</o:p></p>

<p class=MsoNormal style='text-align:justify'><o:p>&nbsp;</o:p></p>

</div>

</body>

</html>