<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;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","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
        {mso-style-priority:99;
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.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;}
-->
</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><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>Hi, Anthony<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>I appreciate you spend your time answering my questions. I have
no problem with FreeSwitch. Since you ask, I am digging into this code because
I am trying to understand how FreeSwitch works inside the core, probably will
take me a great deal of time but I am trying.<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>I wrote a custom EndPoint in FreeSwitch before to run a modem created
by the hardware engineer team. Basically it is similar to Zaptel compatible
card. The Modem Endpoint runs in FreeSwitch to provide PSTN Connectivity that uses
our specific modem.<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>While working with FreeSwitch, I have this idea to implement
something similar to FreeSwitch in 100% .NET managed code. Of course I am not
expecting it to be as mature as FreeSwitch but something basic first. A core
that allows me to write pluggable modules, basic dial plan and the the first
supported endpoint would be XMMP since I had some experience working with this
XMMP .Net library before.<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>The ultimate aim is code readability, simplicity and
maintainability. I have some other aims too but basically this is it, mostly. I
am working on this as a personal hobby project only </span><span
style='font-size:11.0pt;font-family:Wingdings;color:#1F497D'>J</span><span
style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>.<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>Cheers<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>Alex To<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'> <o:p></o:p></span></p>
<div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in'>
<p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span></b><span
style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>
freeswitch-dev-bounces@lists.freeswitch.org
[mailto:freeswitch-dev-bounces@lists.freeswitch.org] <b>On Behalf Of </b>Anthony
Minessale<br>
<b>Sent:</b> Thursday, January 07, 2010 12:16 AM<br>
<b>To:</b> freeswitch-dev@lists.freeswitch.org<br>
<b>Subject:</b> Re: [Freeswitch-dev] Need some explainations about method
switch_core_session_run(switch_core_session_t *session) in
switch_core_state_machine.c<o:p></o:p></span></p>
</div>
<p class=MsoNormal><o:p> </o:p></p>
<p class=MsoNormal style='margin-bottom:12.0pt'><o:p> </o:p></p>
<div>
<p class=MsoNormal>On Wed, Jan 6, 2010 at 9:20 AM, Alex To <<a
href="mailto:tonhudung@gmail.com">tonhudung@gmail.com</a>> wrote:<o:p></o:p></p>
<div>
<div>
<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'>Hi,<o:p></o:p></p>
<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'> <o:p></o:p></p>
<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'>First
of all, pardon my English. English isn’t my native language <span
style='font-family:Wingdings'>J</span>.<o:p></o:p></p>
<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'> <o:p></o:p></p>
<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'>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 style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'> <o:p></o:p></p>
<p>1.<span style='font-size:7.0pt'> </span>LINE
303:
while ((state = switch_channel_get_state(session->channel)) != CS_DESTROY) <o:p></o:p></p>
<p style='margin-left:.75in'><span style='font-size:10.0pt;font-family:Wingdings;
color:blue'>๐</span><span style='font-size:7.0pt;color:blue'> </span>if
state is CS_DESTROY return and do nothing ?<o:p></o:p></p>
<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'> <o:p></o:p></p>
</div>
</div>
<div>
<p class=MsoNormal>state typically starts at CS_NEW the loop runs until state
destroy is reached <br>
<br>
<br>
<o:p></o:p></p>
</div>
<blockquote style='border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;
margin-left:4.8pt;margin-right:0in'>
<div>
<div>
<p>2.<span style='font-size:7.0pt'> </span>Inside
if (state != switch_channel_get_running_state(session->channel) || state
>= CS_HANGUP) <o:p></o:p></p>
<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;
margin-left:.5in;text-indent:.5in'>{ <o:p></o:p></p>
<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;
margin-left:99.0pt;text-indent:9.0pt'>… <o:p></o:p></p>
<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;
margin-left:.5in;text-indent:.5in'>}
<o:p></o:p></p>
<p style='margin-left:1.0in'>a.<span style='font-size:7.0pt'>
</span>LINE
308:
state != switch_channel_get_running_state(session->channel) || state >=
CS_HANGUP<o:p></o:p></p>
<p style='margin-left:1.25in'><span style='font-size:10.0pt;font-family:Wingdings;
color:blue'>๐</span><span style='font-size:7.0pt;color:blue'> </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) ?.<o:p></o:p></p>
</div>
</div>
</blockquote>
<div>
<p class=MsoNormal><br>
Once we are >= HANGUP we dont want to do that test anymore.<br>
<o:p></o:p></p>
</div>
<blockquote style='border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;
margin-left:4.8pt;margin-right:0in'>
<div>
<div>
<p style='margin-left:1.0in'>b.<span style='font-size:7.0pt'>
</span>Inside STATE_MACRO code block<o:p></o:p></p>
<p style='margin-left:1.5in'><span style='font-size:7.0pt'>
</span>i.<span style='font-size:7.0pt'> </span>LINE
229:
midstate = state<o:p></o:p></p>
<p style='margin-left:1.75in'><span style='font-size:10.0pt;font-family:Wingdings;
color:blue'>๐</span><span style='font-size:7.0pt;color:blue'> </span> to
save the current state.<o:p></o:p></p>
<p style='margin-left:1.5in'><span style='font-size:7.0pt'>
</span>ii.<span style='font-size:7.0pt'> </span>LINE
231:
if (!driver_state_handler->on_##__STATE ||
(driver_state_handler->on_##__STATE(session) == SWITCH_STATUS_SUCCESS)<o:p></o:p></p>
<p style='margin-left:1.75in'><span style='font-size:10.0pt;font-family:Wingdings;
color:blue'>๐</span><span style='font-size:7.0pt;color:blue'> </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 ?<o:p></o:p></p>
<p style='margin-left:1.5in'><span style='font-size:7.0pt'>
</span>iii.<span style='font-size:7.0pt'> </span>LINE
246:
if (!proceed) global_proceed = 0;<o:p></o:p></p>
<p style='margin-left:1.75in'><span style='font-size:10.0pt;font-family:Wingdings;
color:blue'>๐</span><span style='font-size:7.0pt;color:blue'> </span>If
something wrong in the previous while loop, do not run core standard state
handlers ?<o:p></o:p></p>
</div>
</div>
</blockquote>
<div>
<p class=MsoNormal>yes the endpoints have the power to veto state handlers from
being called<br>
<br>
<br>
<o:p></o:p></p>
</div>
<blockquote style='border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;
margin-left:4.8pt;margin-right:0in'>
<div>
<div>
<p style='margin-left:1.5in'><span style='font-size:7.0pt'>
</span>iv.<span style='font-size:7.0pt'> </span>LINE
247:
proceed =
1;
<o:p></o:p></p>
<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;
margin-left:1.5in'>LINE
248:
while (do_extra_handlers && proceed &&
(application_state_handler = switch_core_get_state_handler(index++)) != 0) {
…}<o:p></o:p></p>
<p style='margin-left:1.75in'><span style='font-size:10.0pt;font-family:Wingdings;
color:blue'>๐</span><span style='font-size:7.0pt;color:blue'> </span>Since
we set proceed = 1, do we still need (&& proceed) inside the condition
in while loop ?<o:p></o:p></p>
</div>
</div>
</blockquote>
<div>
<p class=MsoNormal>yes because proceed can become 0 within that loop<br>
<br>
<o:p></o:p></p>
</div>
<blockquote style='border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;
margin-left:4.8pt;margin-right:0in'>
<div>
<div>
<p style='margin-left:1.5in'><span style='font-size:7.0pt'>
</span>v.<span style='font-size:7.0pt'> </span>LINE
260:
if (!proceed || midstate != switch_channel_get_state(session->channel))
global_proceed = 0;<o:p></o:p></p>
<p style='margin-left:1.75in'><span style='font-size:10.0pt;font-family:Wingdings;
color:blue'>๐</span><span style='font-size:7.0pt;color:blue'> </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 ?<o:p></o:p></p>
</div>
</div>
</blockquote>
<div>
<p class=MsoNormal>Again, veto power.<br>
<o:p></o:p></p>
</div>
<blockquote style='border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;
margin-left:4.8pt;margin-right:0in'>
<div>
<div>
<p style='margin-left:1.5in'><span style='font-size:7.0pt'>
</span>vi.<span style='font-size:7.0pt'> </span>LINE
266:
while (silly)<o:p></o:p></p>
<p style='margin-left:1.75in;text-align:justify'><span style='font-size:10.0pt;
font-family:Wingdings;color:blue'>๐</span><span style='font-size:7.0pt;
color:blue'> </span>silly is never changed, does it mean we could go into
an endless while loop ?<o:p></o:p></p>
<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;
text-align:justify'> <o:p></o:p></p>
</div>
</div>
</blockquote>
<div>
<p class=MsoNormal>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>
<o:p></o:p></p>
</div>
<blockquote style='border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;
margin-left:4.8pt;margin-right:0in'>
<div>
<div>
<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;
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='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;
text-align:justify'> <o:p></o:p></p>
</div>
</div>
</blockquote>
<div>
<p class=MsoNormal><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>
<o:p></o:p></p>
</div>
<blockquote style='border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;
margin-left:4.8pt;margin-right:0in'>
<div>
<div>
<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;
text-align:justify'>Thank you for reading this<o:p></o:p></p>
<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;
text-align:justify'> <o:p></o:p></p>
<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;
text-align:justify'>Regards<o:p></o:p></p>
<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;
text-align:justify'> <o:p></o:p></p>
<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;
text-align:justify'>Alex To<o:p></o:p></p>
<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;
text-align:justify'> <o:p></o:p></p>
<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;
text-align:justify'> <o:p></o:p></p>
</div>
</div>
<p class=MsoNormal style='margin-bottom:12.0pt'><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><o:p></o:p></p>
</blockquote>
</div>
<p class=MsoNormal><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<o:p></o:p></p>
</div>
</body>
</html>