[Freeswitch-dev] mod managed, cant receive events thru EventReceivedFunction callback
Alex To
tonhudung at gmail.com
Mon Nov 2 21:43:32 PST 2009
Oh thank you Michael for answering all my dumb questions. :D I agree with
you Interoperability between unmanaged and managed code is such a PITA. I
think I am going back to C++ module for the moment since the unmanaged API
isn't "made easy" in managed code yet. If I have the time later, I will go
back and read the managed part, hopefully I could contribute to the managed
part in FS.
Regards
Alex To
From: freeswitch-dev-bounces at lists.freeswitch.org
[mailto:freeswitch-dev-bounces at lists.freeswitch.org] On Behalf Of Michael
Giagnocavo
Sent: Monday, November 02, 2009 8:34 PM
To: freeswitch-dev at lists.freeswitch.org
Subject: Re: [Freeswitch-dev] mod managed, cant receive events thru
EventReceivedFunction callback
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.
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.
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.
Additionally, the SWIGTYPE_p_xxx classes don't have public constructors, so
the FSUtil class provides this extension method on IntPtr:
public static T CreateSwigTypePointer<T>(this IntPtr cPtr)
That way you can create the wrapper classes as needed after you've created
the structures and wrapped them up.
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.
-Michael
From: freeswitch-dev-bounces at lists.freeswitch.org
[mailto:freeswitch-dev-bounces at lists.freeswitch.org] On Behalf Of Alex To
Sent: Monday, November 02, 2009 5:19 AM
To: freeswitch-dev at lists.freeswitch.org
Subject: Re: [Freeswitch-dev] mod managed, cant receive events thru
EventReceivedFunction callback
Hi, I would like to raise this question again since it doesn't seem to have
an answer yet.
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).
I believe Andrew's concern was how to receive events through
EventReceivedFunctionCallback but not connect to FS and receive event via
TCP/IP.
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++?
How would I read the incoming audio data and how would I send audio as an
outgoing stream.
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().
Any help would be greatly appreciated.
Best Regards
Alex To
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freeswitch.org/pipermail/freeswitch-dev/attachments/20091103/0fec3d8c/attachment-0001.html
More information about the FreeSWITCH-dev
mailing list