<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=us-ascii">
<meta name=Generator content="Microsoft Word 12 (filtered medium)">
<style>
<!--
/* Font Definitions */
@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: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;}
pre
        {mso-style-priority:99;
        mso-style-link:"HTML Preformatted Char";
        margin:0in;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";}
span.HTMLPreformattedChar
        {mso-style-name:"HTML Preformatted Char";
        mso-style-priority:99;
        mso-style-link:"HTML Preformatted";
        font-family:"Courier New";}
span.EmailStyle19
        {mso-style-type:personal;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
span.EmailStyle20
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@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='color:#1F497D'>Basically, if you want to do
something that’s not “made easy” for language plugins, you
just do it the C way, like any other FreeSWITCH C module. The mod_managed swig
wrappers expose nearly every function.<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>The difficult part is that some
of the indirect types (pointers to types and function pointers) aren’t
swig’d very nicely, and just have a wrapper class such as “SWIGTYPE_p_foo_t”.
In this case, you’re required to create the backing structure however
required, then get a pointer to that structure and wrap it in the
SWIGTYPE_p_xxx class. If your backing structure is a .NET type, you can use
GCHandle to get an IntPtr to it. Or you can directly allocate memory via the
Marshal class and use that IntPtr. This is likely to be annoying and a lot of
work.<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>It’s only really easy for
function pointers, as all you need to do is declare a delegate, attribute it [UnmanagedFunctionPointer(CallingConvention.Cdecl)],
then call Marshal.GetFunctionPointerForDelegate. The runtime will emit
unmanaged stubs that will handle unmanaged-managed transitioning and give you a
nice C compatible function pointer you can wrap and pass around. You can see
some examples in ManagedSession.cs. <o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>Additionally, the SWIGTYPE_p_xxx
classes don’t have public constructors, so the FSUtil class provides this
extension method on IntPtr:<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>public static T
CreateSwigTypePointer<T>(this IntPtr cPtr)<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>That way you can create the
wrapper classes as needed after you’ve created the structures and wrapped
them up.<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>In summary, it’s possible to
create an endpoint module from C#, but a major PITA. You should consider either
using a mixed-mode language such as C++/CLI or write a helper library in C/C++
and export that via swig. We’d welcome contributions to mod_managed that
simplify access to a set of the FS APIs.<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>-Michael<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p>
<div>
<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>Alex
To<br>
<b>Sent:</b> Monday, November 02, 2009 5:19 AM<br>
<b>To:</b> freeswitch-dev@lists.freeswitch.org<br>
<b>Subject:</b> Re: [Freeswitch-dev] mod managed, cant receive events thru
EventReceivedFunction callback<o:p></o:p></span></p>
</div>
</div>
<p class=MsoNormal><o:p> </o:p></p>
<p class=MsoNormal>Hi, I would like to raise this question again since it
doesn’t seem to have an answer yet.<o:p></o:p></p>
<p class=MsoNormal><o:p> </o:p></p>
<pre>I built a .NET module which implements IAppPlugin and IApiPlugin. I looked at the /contrib/verifier/eventsocket and it is actually the client to connect to FS through mod_event_socket (correct me if I’m wrong here). <o:p></o:p></pre><pre><o:p> </o:p></pre><pre>I believe Andrew’s concern was how to receive events through EventReceivedFunctionCallback but not connect to FS and receive event via TCP/IP. <o:p></o:p></pre><pre><o:p> </o:p></pre><pre>I would want to implement a .NET module that acts like an endpoint. Could someone show me the direction of how to hook up handlers like it is done in native C++? <o:p></o:p></pre><pre><o:p> </o:p></pre><pre>How would I read the incoming audio data and how would I send audio as an outgoing stream. <o:p></o:p></pre><pre><o:p> </o:p></pre><pre>I setup the .NET module and dial plan so that the Run() method in my module is invoked whenever a call is bridged to my endpoint. The ParkingLot and Demo script sample does enlighten me a little but I still have no clue how would I go about the audio stream after I call session.Answer().<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>Any help would be greatly appreciated. <o:p></o:p></pre><pre><o:p> </o:p></pre><pre>Best Regards<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>Alex To<o:p></o:p></pre><pre><o:p> </o:p></pre><pre><o:p> </o:p></pre>
<p class=MsoNormal><o:p> </o:p></p>
</div>
</body>
</html>