[Freeswitch-users] Subscribing to events in managed C# / .NET
Raffaele P. Guidi
raffaele.p.guidi at gmail.com
Tue Sep 8 11:50:20 PDT 2009
Yeah, probably just using con.pop(1) - that waits for an event to be caught,
instead than con.pop(0), thus avoiding "sleeps" would do the trick
On Tue, Sep 8, 2009 at 20:12, Phillip Jones <pjintheusa at gmail.com> wrote:
> What is:
>
> freeswitch.msleep(100);
>
> Why aren't you using Thread.Sleep?
>
>
> On Tue, Sep 8, 2009 at 2:21 AM, Josh Rivers <josh at radianttiger.com> wrote:
>
>> Thanks for the response!
>> I have tried putting a long-running loop here, but then it blocks anything
>> else managed from happening:
>>
>> public class TestLoop : ILoadNotificationPlugin
>> {
>> public bool Load()
>> {
>> EventConsumer con = new EventConsumer("all", "");
>> while (true)
>> {
>> Event ev = con.pop(0);
>> Log.WriteLine(LogLevel.Notice, "Event: " +
>> ev.serialized_string);
>> freeswitch.msleep(100);
>> }
>> }
>> }
>>
>> However, if I fork off a thread here, freeswitch crashes:
>> public class TestLoop : ILoadNotificationPlugin
>> {
>> public bool Load()
>> {
>> ThreadPool.QueueUserWorkItem((o) =>
>> {
>> Log.WriteLine(LogLevel.Notice, "Thread Starting. ");
>> EventConsumer con = new EventConsumer("all", "");
>> while (true)
>> {
>> Event ev = con.pop(0);
>> Log.WriteLine(LogLevel.Notice, "Event: " +
>> ev.serialized_string);
>> freeswitch.msleep(100);
>> }
>> });
>> return true;
>> }
>> }
>>
>> It doesn't look like this is a good place to start a long-running process?
>>
>> Thanks!
>> Josh
>>
>> On Mon, Sep 7, 2009 at 11:05 PM, Raffaele P. Guidi <
>> raffaele.p.guidi at gmail.com> wrote:
>>
>>> Yes!
>>> public class LoadDemo : ILoadNotificationPlugin {
>>> public bool Load() {
>>> Log.WriteLine(LogLevel.Notice, "LoadDemo running.");
>>> return true;
>>> }
>>> }
>>>
>>> this example is from Michael Giagnocavo's Demo.csx which you can find
>>> into the mod_managed svn.
>>>
>>> And let me add that works like a charm :)
>>>
>>> Ciao,
>>> Raffaele
>>>
>>> On Sun, Sep 6, 2009 at 22:50, Josh Rivers <josh at radianttiger.com> wrote:
>>>
>>>> Is there a way to start this when FreeSWITCH starts? The lua and perl
>>>> modules have a 'startup-script' configuration preference. Is there something
>>>> similar in mod_managed? Or is there a way to have an api command executed at
>>>> a startup?
>>>>
>>>> <quote author="Phillip Jones">
>>>> Exactly what I was after - thank you!
>>>>
>>>> On Thu, Sep 3, 2009 at 1:54 PM, Jeff Lenk <jlenk at frontiernet.net>
>>>> wrote:
>>>>
>>>> >
>>>> > try something like this
>>>> >
>>>> > EventConsumer con = new EventConsumer("all", "");
>>>> > Event ev = con.pop(0);
>>>> >
>>>> > see lua sample -
>>>> > http://wiki.freeswitch.org/wiki/Lua#freeswitch.EventConsumer
>>>> >
>>>> >
>>>> > Phillip Jones-2 wrote:
>>>> > >
>>>> > > Hi there,
>>>> > >
>>>> > > mod_managed exposes EventReceivedFunction such that:
>>>> > >
>>>> > > Session.EventReceivedFunction = (e) =>
>>>> > > {
>>>> > > Log.WriteLine(LogLevel.Alert, "Received Event {0}",
>>>> e.ToString());
>>>> > > return "";
>>>> > > };
>>>> > >
>>>> > > should trap all events to which i subscribe.
>>>> > >
>>>> > >
>>>> > > But how do I subscribe to events? What is the .NET / managed
>>>> equivalent
>>>> > > of:
>>>> > >
>>>> > > switch_event_bind(const char *id, switch_event_types_t event, const
>>>> char
>>>> > > *subclass_name, switch_event_callback_t callback, void *user_data);
>>>> > >
>>>> > >
>>>> > >
>>>> > > Thank you!
>>>> > >
>>>> > >
>>>> > >
>>>>
>>>> _______________________________________________
>>>> FreeSWITCH-users mailing list
>>>> FreeSWITCH-users at lists.freeswitch.org
>>>> http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
>>>> UNSUBSCRIBE:
>>>> http://lists.freeswitch.org/mailman/options/freeswitch-users
>>>> http://www.freeswitch.org
>>>>
>>>>
>>>
>>> _______________________________________________
>>> FreeSWITCH-users mailing list
>>> FreeSWITCH-users at lists.freeswitch.org
>>> http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
>>> UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
>>> http://www.freeswitch.org
>>>
>>>
>>
>> _______________________________________________
>> FreeSWITCH-users mailing list
>> FreeSWITCH-users at lists.freeswitch.org
>> http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
>> UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
>> http://www.freeswitch.org
>>
>>
>
> _______________________________________________
> FreeSWITCH-users mailing list
> FreeSWITCH-users at lists.freeswitch.org
> http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
> UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
> http://www.freeswitch.org
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freeswitch.org/pipermail/freeswitch-users/attachments/20090908/de19150f/attachment-0002.html
More information about the FreeSWITCH-users
mailing list