Sponsor: VoiceMeUp - Corporate & Wholesale VoIP Services

VoIP Mailing List Archives
Mailing list archives for the VoIP community
 SearchSearch 

[Freeswitch-users] Subscribing to events in managed C# / .NET

Goto page Previous  1, 2, 3, 4  Next
 
Post new topic   Reply to topic    VoIP Mailing List Archives Forum Index -> freeSWITCH Users
View previous topic :: View next topic  
Author Message
mgg at giagnocavo.net
Guest





PostPosted: Tue Sep 08, 2009 3:57 pm    Post subject: [Freeswitch-users] Subscribing to events in managed C# / .NE Reply with quote

“ ThreadPool.QueueUserWorkItem((o) =>”
That starts a lambda, which is compiled to a delegate, same as anonymous methods.
Guess I’ll wait for him to respond on the crash he gets.


From: freeswitch-users-bounces@lists.freeswitch.org [mailto:freeswitch-users-bounces@lists.freeswitch.org] On Behalf Of Raffaele P. Guidi
Sent: Tuesday, September 08, 2009 12:22 PM
To: freeswitch-users@lists.freeswitch.org
Subject: Re: [Freeswitch-users] Subscribing to events in managed C# / .NET


Well, I can't see any delegate in josh sample, just a ThreadPool.QueueUserWorkItem. Here is an example that, at least on my system (I reached my home pc in the meanwhile), works fine.


public class LoadPluginDemo : ILoadNotificationPlugin {

delegate void Listener();

private void EventListener() {

EventConsumer con = new EventConsumer("all", null);

while (true){

Event ev = con.pop(1);

Log.WriteLine(LogLevel.Notice, "Got event " + ev.GetHeader("Event-Name"));

}

}

public bool Load() {

Log.WriteLine(LogLevel.Notice, "LoadDemo running.");

new Listener(EventListener).BeginInvoke(null,null);

return true;

}

}






On Tue, Sep 8, 2009 at 18:43, Michael Giagnocavo <mgg@giagnocavo.net (mgg@giagnocavo.net)> wrote:
That’s what his sample does, but he says it crashes.

From: freeswitch-users-bounces@lists.freeswitch.org (freeswitch-users-bounces@lists.freeswitch.org) [mailto:freeswitch-users-bounces@lists.freeswitch.org (freeswitch-users-bounces@lists.freeswitch.org)] On Behalf Of Raffaele P. Guidi
Sent: Tuesday, September 08, 2009 10:08 AM

To: freeswitch-users@lists.freeswitch.org (freeswitch-users@lists.freeswitch.org)
Subject: Re: [Freeswitch-users] Subscribing to events in managed C# / .NET



Hi, you just have to use delegates to asynchronously call the function containing the loop and return back the control to the calling thread. Here an example (don't have my code at hand, hope it doesn't contain typos).



Regards,

Raffaele



public class TestLoop : ILoadNotificationPlugin

{


Delegate void DoStuffDelegate();



public void doStuff()

{

EventConsumer con = new EventConsumer("all", "");


while (true)

{

Event ev = con.pop(0);


Log.WriteLine(LogLevel.Notice, "Event: " + ev.serialized_string);

freeswitch.msleep(100);

}

}

public bool Load()

{

DoStuffDelegate dsdlg = new DoStuffDelegate(doStuff);

dsdlg.BeginInvoke();

}


}


On Tue, Sep 8, 2009 at 08:21, Josh Rivers <josh@radianttiger.com (josh@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@gmail.com (raffaele.p.guidi@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 Smile



Ciao,

Raffaele


On Sun, Sep 6, 2009 at 22:50, Josh Rivers <josh@radianttiger.com (josh@radianttiger.com)> wrote:

Quote:

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@frontiernet.net (jlenk@frontiernet.net)> wrote:




Quote:
try something like this


Quote:
EventConsumer con = new EventConsumer("all", "");

Quote:
Event ev = con.pop(0);


Quote:
see lua sample -

Quote:
http://wiki.freeswitch.org/wiki/Lua#freeswitch.EventConsumer



Quote:
Phillip Jones-2 wrote:


Quote:
Quote:
Hi there,


Quote:
Quote:
mod_managed exposes EventReceivedFunction such that:


Quote:
Quote:
Session.EventReceivedFunction = (e) =>

Quote:
Quote:
{

Quote:
Quote:
Log.WriteLine(LogLevel.Alert, "Received Event {0}", e.ToString());

Quote:
Quote:
return "";

Quote:
Quote:
};


Quote:
Quote:
should trap all events to which i subscribe.



Quote:
Quote:
But how do I subscribe to events? What is the .NET / managed equivalent

Quote:
Quote:
of:


Quote:
Quote:
switch_event_bind(const char *id, switch_event_types_t event, const char

Quote:
Quote:
*subclass_name, switch_event_callback_t callback, void *user_data);




Quote:
Quote:
Thank you!









_______________________________________________
FreeSWITCH-users mailing list
FreeSWITCH-users@lists.freeswitch.org (FreeSWITCH-users@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@lists.freeswitch.org (FreeSWITCH-users@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@lists.freeswitch.org (FreeSWITCH-users@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@lists.freeswitch.org (FreeSWITCH-users@lists.freeswitch.org)
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
http://www.freeswitch.org
Back to top
raffaele.p.guidi at gm...
Guest





PostPosted: Tue Sep 08, 2009 4:31 pm    Post subject: [Freeswitch-users] Subscribing to events in managed C# / .NE Reply with quote

Oh, I see... all those years wasted doing java stuff! Very Happy

On Tue, Sep 8, 2009 at 22:46, Michael Giagnocavo <mgg@giagnocavo.net (mgg@giagnocavo.net)> wrote:
Quote:

“ ThreadPool.QueueUserWorkItem((o) =>”
That starts a lambda, which is compiled to a delegate, same as anonymous methods.
Guess I’ll wait for him to respond on the crash he gets.
 
 
From: freeswitch-users-bounces@lists.freeswitch.org (freeswitch-users-bounces@lists.freeswitch.org) [mailto:freeswitch-users-bounces@lists.freeswitch.org (freeswitch-users-bounces@lists.freeswitch.org)] On Behalf Of Raffaele P. Guidi
Sent: Tuesday, September 08, 2009 12:22 PM

To: freeswitch-users@lists.freeswitch.org (freeswitch-users@lists.freeswitch.org)
Subject: Re: [Freeswitch-users] Subscribing to events in managed C# / .NET





 
Well, I can't see any delegate in josh sample, just a ThreadPool.QueueUserWorkItem. Here is an example that, at least on my system (I reached my home pc in the meanwhile), works fine.
 

     public class LoadPluginDemo : ILoadNotificationPlugin {

          delegate void Listener();

          private void EventListener() {

            EventConsumer con = new EventConsumer("all", null);

            while (true){

                 Event ev = con.pop(1);

                 Log.WriteLine(LogLevel.Notice, "Got event " + ev.GetHeader("Event-Name"));        

            }

          }

        public bool Load() {

            Log.WriteLine(LogLevel.Notice, "LoadDemo running.");

            new Listener(EventListener).BeginInvoke(null,null);

            return true;

        }

     }

 

 

 
On Tue, Sep 8, 2009 at 18:43, Michael Giagnocavo <mgg@giagnocavo.net (mgg@giagnocavo.net)> wrote:
That’s what his sample does, but he says it crashes.
 
From: freeswitch-users-bounces@lists.freeswitch.org (freeswitch-users-bounces@lists.freeswitch.org) [mailto:freeswitch-users-bounces@lists.freeswitch.org (freeswitch-users-bounces@lists.freeswitch.org)] On Behalf Of Raffaele P. Guidi
Sent: Tuesday, September 08, 2009 10:08 AM

To: freeswitch-users@lists.freeswitch.org (freeswitch-users@lists.freeswitch.org)
Subject: Re: [Freeswitch-users] Subscribing to events in managed C# / .NET


 
Hi, you just have to use delegates to asynchronously call the function containing the loop and return back the control to the calling thread. Here an example (don't have my code at hand, hope it doesn't contain typos).

 

Regards,

   Raffaele

 

   public class TestLoop : ILoadNotificationPlugin

    {

 
       Delegate void DoStuffDelegate();

 

       public void doStuff()

        {

            EventConsumer con = new EventConsumer("all", "");


            while (true)

            {

                Event ev = con.pop(0);


                Log.WriteLine(LogLevel.Notice, "Event: " + ev.serialized_string);

                freeswitch.msleep(100);

            }

        }

        public bool Load()

        {

            DoStuffDelegate dsdlg = new DoStuffDelegate(doStuff);

            dsdlg.BeginInvoke();

        }


    }


On Tue, Sep 8, 2009 at 08:21, Josh Rivers <josh@radianttiger.com (josh@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@gmail.com (raffaele.p.guidi@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 Smile

 

Ciao,

   Raffaele

 
On Sun, Sep 6, 2009 at 22:50, Josh Rivers <josh@radianttiger.com (josh@radianttiger.com)> wrote:

Quote:

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@frontiernet.net (jlenk@frontiernet.net)> wrote:

 

Quote:
 

Quote:
try something like this

Quote:
 

Quote:
EventConsumer con = new EventConsumer("all", "");

Quote:
Event ev = con.pop(0);

Quote:
 

Quote:
see lua sample -

Quote:
http://wiki.freeswitch.org/wiki/Lua#freeswitch.EventConsumer

Quote:
 

Quote:
 

Quote:
Phillip Jones-2 wrote:


Quote:
Quote:
Hi there,


Quote:
Quote:
mod_managed exposes EventReceivedFunction such that:


Quote:
Quote:
 Session.EventReceivedFunction = (e) =>

Quote:
Quote:
 {

Quote:
Quote:
       Log.WriteLine(LogLevel.Alert, "Received Event {0}", e.ToString());

Quote:
Quote:
       return "";

Quote:
Quote:
 };


Quote:
Quote:
should trap all events to which i subscribe.



Quote:
Quote:
But how do I subscribe to events? What is the .NET / managed equivalent

Quote:
Quote:
of:


Quote:
Quote:
switch_event_bind(const char *id, switch_event_types_t event, const char

Quote:
Quote:
*subclass_name, switch_event_callback_t callback, void *user_data);




Quote:
Quote:
Thank you!






 


_______________________________________________
FreeSWITCH-users mailing list
FreeSWITCH-users@lists.freeswitch.org (FreeSWITCH-users@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@lists.freeswitch.org (FreeSWITCH-users@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@lists.freeswitch.org (FreeSWITCH-users@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@lists.freeswitch.org (FreeSWITCH-users@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@lists.freeswitch.org (FreeSWITCH-users@lists.freeswitch.org)
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
http://www.freeswitch.org

Back to top
pjintheusa at gmail.com
Guest





PostPosted: Tue Sep 08, 2009 5:01 pm    Post subject: [Freeswitch-users] Subscribing to events in managed C# / .NE Reply with quote

I build this out.

This seems to work fine:

ThreadPool.QueueUserWorkItem((o) =>
            {
                Log.WriteLine(LogLevel.Notice, "Thread Starting. ");
                EventConsumer con = new EventConsumer("all", "");
                while (true)
                {
                    Event ev = con.pop(1);
                    Log.WriteLine(LogLevel.Alert, "Event: " + ev.GetHeader("Event-Name"));
                    //freeswitch.msleep(100);
                }
            });

With
            Event ev = con.pop(0) however FS crashes with a System.NullReferenceException (attached)










On Tue, Sep 8, 2009 at 5:20 PM, Raffaele P. Guidi <raffaele.p.guidi@gmail.com (raffaele.p.guidi@gmail.com)> wrote:
Quote:
Oh, I see... all those years wasted doing java stuff! Very Happy


On Tue, Sep 8, 2009 at 22:46, Michael Giagnocavo <mgg@giagnocavo.net (mgg@giagnocavo.net)> wrote:
Quote:

“ ThreadPool.QueueUserWorkItem((o) =>”
That starts a lambda, which is compiled to a delegate, same as anonymous methods.
Guess I’ll wait for him to respond on the crash he gets.
 
 
From: freeswitch-users-bounces@lists.freeswitch.org (freeswitch-users-bounces@lists.freeswitch.org) [mailto:freeswitch-users-bounces@lists.freeswitch.org (freeswitch-users-bounces@lists.freeswitch.org)] On Behalf Of Raffaele P. Guidi
Sent: Tuesday, September 08, 2009 12:22 PM

To: freeswitch-users@lists.freeswitch.org (freeswitch-users@lists.freeswitch.org)
Subject: Re: [Freeswitch-users] Subscribing to events in managed C# / .NET





 
Well, I can't see any delegate in josh sample, just a ThreadPool.QueueUserWorkItem. Here is an example that, at least on my system (I reached my home pc in the meanwhile), works fine.
 

     public class LoadPluginDemo : ILoadNotificationPlugin {

          delegate void Listener();

          private void EventListener() {

            EventConsumer con = new EventConsumer("all", null);

            while (true){

                 Event ev = con.pop(1);

                 Log.WriteLine(LogLevel.Notice, "Got event " + ev.GetHeader("Event-Name"));        

            }

          }

        public bool Load() {

            Log.WriteLine(LogLevel.Notice, "LoadDemo running.");

            new Listener(EventListener).BeginInvoke(null,null);

            return true;

        }

     }

 

 

 
On Tue, Sep 8, 2009 at 18:43, Michael Giagnocavo <mgg@giagnocavo.net (mgg@giagnocavo.net)> wrote:
That’s what his sample does, but he says it crashes.
 
From: freeswitch-users-bounces@lists.freeswitch.org (freeswitch-users-bounces@lists.freeswitch.org) [mailto:freeswitch-users-bounces@lists.freeswitch.org (freeswitch-users-bounces@lists.freeswitch.org)] On Behalf Of Raffaele P. Guidi
Sent: Tuesday, September 08, 2009 10:08 AM

To: freeswitch-users@lists.freeswitch.org (freeswitch-users@lists.freeswitch.org)
Subject: Re: [Freeswitch-users] Subscribing to events in managed C# / .NET


 
Hi, you just have to use delegates to asynchronously call the function containing the loop and return back the control to the calling thread. Here an example (don't have my code at hand, hope it doesn't contain typos).

 

Regards,

   Raffaele

 

   public class TestLoop : ILoadNotificationPlugin

    {

 
       Delegate void DoStuffDelegate();

 

       public void doStuff()

        {

            EventConsumer con = new EventConsumer("all", "");


            while (true)

            {

                Event ev = con.pop(0);


                Log.WriteLine(LogLevel.Notice, "Event: " + ev.serialized_string);

                freeswitch.msleep(100);

            }

        }

        public bool Load()

        {

            DoStuffDelegate dsdlg = new DoStuffDelegate(doStuff);

            dsdlg.BeginInvoke();

        }


    }


On Tue, Sep 8, 2009 at 08:21, Josh Rivers <josh@radianttiger.com (josh@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@gmail.com (raffaele.p.guidi@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 Smile

 

Ciao,

   Raffaele

 
On Sun, Sep 6, 2009 at 22:50, Josh Rivers <josh@radianttiger.com (josh@radianttiger.com)> wrote:

Quote:

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@frontiernet.net (jlenk@frontiernet.net)> wrote:

 

Quote:
 

Quote:
try something like this

Quote:
 

Quote:
EventConsumer con = new EventConsumer("all", "");

Quote:
Event ev = con.pop(0);

Quote:
 

Quote:
see lua sample -

Quote:
http://wiki.freeswitch.org/wiki/Lua#freeswitch.EventConsumer

Quote:
 

Quote:
 

Quote:
Phillip Jones-2 wrote:


Quote:
Quote:
Hi there,


Quote:
Quote:
mod_managed exposes EventReceivedFunction such that:


Quote:
Quote:
 Session.EventReceivedFunction = (e) =>

Quote:
Quote:
 {

Quote:
Quote:
       Log.WriteLine(LogLevel.Alert, "Received Event {0}", e.ToString());

Quote:
Quote:
       return "";

Quote:
Quote:
 };


Quote:
Quote:
should trap all events to which i subscribe.



Quote:
Quote:
But how do I subscribe to events? What is the .NET / managed equivalent

Quote:
Quote:
of:


Quote:
Quote:
switch_event_bind(const char *id, switch_event_types_t event, const char

Quote:
Quote:
*subclass_name, switch_event_callback_t callback, void *user_data);




Quote:
Quote:
Thank you!






 


_______________________________________________
FreeSWITCH-users mailing list
FreeSWITCH-users@lists.freeswitch.org (FreeSWITCH-users@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@lists.freeswitch.org (FreeSWITCH-users@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@lists.freeswitch.org (FreeSWITCH-users@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@lists.freeswitch.org (FreeSWITCH-users@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@lists.freeswitch.org (FreeSWITCH-users@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@lists.freeswitch.org (FreeSWITCH-users@lists.freeswitch.org)
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
http://www.freeswitch.org

Back to top
mgg at giagnocavo.net
Guest





PostPosted: Tue Sep 08, 2009 9:18 pm    Post subject: [Freeswitch-users] Subscribing to events in managed C# / .NE Reply with quote

I’m not sure how EventConsumer is supposed to work – maybe one of the real devs can explain how pop works and if it should fail on pop 0 or not.

From: freeswitch-users-bounces@lists.freeswitch.org [mailto:freeswitch-users-bounces@lists.freeswitch.org] On Behalf Of Phillip Jones
Sent: Tuesday, September 08, 2009 3:50 PM
To: freeswitch-users@lists.freeswitch.org
Subject: Re: [Freeswitch-users] Subscribing to events in managed C# / .NET


I build this out.

This seems to work fine:

ThreadPool.QueueUserWorkItem((o) =>
{
Log.WriteLine(LogLevel.Notice, "Thread Starting. ");
EventConsumer con = new EventConsumer("all", "");
while (true)
{
Event ev = con.pop(1);
Log.WriteLine(LogLevel.Alert, "Event: " + ev.GetHeader("Event-Name"));
//freeswitch.msleep(100);
}
});

With
Event ev = con.pop(0) however FS crashes with a System.NullReferenceException (attached)










On Tue, Sep 8, 2009 at 5:20 PM, Raffaele P. Guidi <raffaele.p.guidi@gmail.com (raffaele.p.guidi@gmail.com)> wrote:
Oh, I see... all those years wasted doing java stuff! Very Happy

On Tue, Sep 8, 2009 at 22:46, Michael Giagnocavo <mgg@giagnocavo.net (mgg@giagnocavo.net)> wrote:
“ ThreadPool.QueueUserWorkItem((o) =>”
That starts a lambda, which is compiled to a delegate, same as anonymous methods.
Guess I’ll wait for him to respond on the crash he gets.


From: freeswitch-users-bounces@lists.freeswitch.org (freeswitch-users-bounces@lists.freeswitch.org) [mailto:freeswitch-users-bounces@lists.freeswitch.org (freeswitch-users-bounces@lists.freeswitch.org)] On Behalf Of Raffaele P. Guidi
Sent: Tuesday, September 08, 2009 12:22 PM

To: freeswitch-users@lists.freeswitch.org (freeswitch-users@lists.freeswitch.org)
Subject: Re: [Freeswitch-users] Subscribing to events in managed C# / .NET




Well, I can't see any delegate in josh sample, just a ThreadPool.QueueUserWorkItem. Here is an example that, at least on my system (I reached my home pc in the meanwhile), works fine.


public class LoadPluginDemo : ILoadNotificationPlugin {

delegate void Listener();

private void EventListener() {

EventConsumer con = new EventConsumer("all", null);

while (true){

Event ev = con.pop(1);

Log.WriteLine(LogLevel.Notice, "Got event " + ev.GetHeader("Event-Name"));

}

}

public bool Load() {

Log.WriteLine(LogLevel.Notice, "LoadDemo running.");

new Listener(EventListener).BeginInvoke(null,null);

return true;

}

}






On Tue, Sep 8, 2009 at 18:43, Michael Giagnocavo <mgg@giagnocavo.net (mgg@giagnocavo.net)> wrote:
That’s what his sample does, but he says it crashes.

From: freeswitch-users-bounces@lists.freeswitch.org (freeswitch-users-bounces@lists.freeswitch.org) [mailto:freeswitch-users-bounces@lists.freeswitch.org (freeswitch-users-bounces@lists.freeswitch.org)] On Behalf Of Raffaele P. Guidi
Sent: Tuesday, September 08, 2009 10:08 AM

To: freeswitch-users@lists.freeswitch.org (freeswitch-users@lists.freeswitch.org)
Subject: Re: [Freeswitch-users] Subscribing to events in managed C# / .NET



Hi, you just have to use delegates to asynchronously call the function containing the loop and return back the control to the calling thread. Here an example (don't have my code at hand, hope it doesn't contain typos).



Regards,

Raffaele



public class TestLoop : ILoadNotificationPlugin

{


Delegate void DoStuffDelegate();



public void doStuff()

{

EventConsumer con = new EventConsumer("all", "");


while (true)

{

Event ev = con.pop(0);


Log.WriteLine(LogLevel.Notice, "Event: " + ev.serialized_string);

freeswitch.msleep(100);

}

}

public bool Load()

{

DoStuffDelegate dsdlg = new DoStuffDelegate(doStuff);

dsdlg.BeginInvoke();

}


}


On Tue, Sep 8, 2009 at 08:21, Josh Rivers <josh@radianttiger.com (josh@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@gmail.com (raffaele.p.guidi@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 Smile



Ciao,

Raffaele


On Sun, Sep 6, 2009 at 22:50, Josh Rivers <josh@radianttiger.com (josh@radianttiger.com)> wrote:

Quote:

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@frontiernet.net (jlenk@frontiernet.net)> wrote:




Quote:
try something like this


Quote:
EventConsumer con = new EventConsumer("all", "");

Quote:
Event ev = con.pop(0);


Quote:
see lua sample -

Quote:
http://wiki.freeswitch.org/wiki/Lua#freeswitch.EventConsumer



Quote:
Phillip Jones-2 wrote:


Quote:
Quote:
Hi there,


Quote:
Quote:
mod_managed exposes EventReceivedFunction such that:


Quote:
Quote:
Session.EventReceivedFunction = (e) =>

Quote:
Quote:
{

Quote:
Quote:
Log.WriteLine(LogLevel.Alert, "Received Event {0}", e.ToString());

Quote:
Quote:
return "";

Quote:
Quote:
};


Quote:
Quote:
should trap all events to which i subscribe.



Quote:
Quote:
But how do I subscribe to events? What is the .NET / managed equivalent

Quote:
Quote:
of:


Quote:
Quote:
switch_event_bind(const char *id, switch_event_types_t event, const char

Quote:
Quote:
*subclass_name, switch_event_callback_t callback, void *user_data);




Quote:
Quote:
Thank you!









_______________________________________________
FreeSWITCH-users mailing list
FreeSWITCH-users@lists.freeswitch.org (FreeSWITCH-users@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@lists.freeswitch.org (FreeSWITCH-users@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@lists.freeswitch.org (FreeSWITCH-users@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@lists.freeswitch.org (FreeSWITCH-users@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@lists.freeswitch.org (FreeSWITCH-users@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@lists.freeswitch.org (FreeSWITCH-users@lists.freeswitch.org)
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
http://www.freeswitch.org
Back to top
mrene_lists at avgs.ca
Guest





PostPosted: Wed Sep 09, 2009 12:40 am    Post subject: [Freeswitch-users] Subscribing to events in managed C# / .NE Reply with quote

Click Break, then go in Window, Debug, Stack Trace (or something similar, I don't have any VS nearby), then copy paste that.
Mathieu Rene
Avant-Garde Solutions Inc
Office: + 1 (514) 664-1044 x100
Cell: +1 (514) 664-1044 x200
mrene@avgs.ca (mrene@avgs.ca)








On 8-Sep-09, at 10:30 PM, Josh Rivers wrote:
Quote:
Here is the error I get with the loop I mentioned. -Josh
<Capture.PNG>

On Tue, Sep 8, 2009 at 5:05 AM, Michael Giagnocavo <mgg@giagnocavo.net (mgg@giagnocavo.net)> wrote:
Quote:

Hi,

Can you please elaborate on the crash you receive when you queue a thread during load?

Thanks,
Michael

From: freeswitch-users-bounces@lists.freeswitch.org (freeswitch-users-bounces@lists.freeswitch.org) [mailto:freeswitch-users-bounces@lists.freeswitch.org (freeswitch-users-bounces@lists.freeswitch.org)] On Behalf Of Josh Rivers
Sent: Tuesday, September 08, 2009 12:22 AM
To: freeswitch-users@lists.freeswitch.org (freeswitch-users@lists.freeswitch.org)
Subject: Re: [Freeswitch-users] Subscribing to events in managed C# / .NET



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@gmail.com (raffaele.p.guidi@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 Smile



Ciao,

Raffaele


On Sun, Sep 6, 2009 at 22:50, Josh Rivers <josh@radianttiger.com (josh@radianttiger.com)> wrote:

Quote:

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@frontiernet.net (jlenk@frontiernet.net)> wrote:




Quote:
try something like this


Quote:
EventConsumer con = new EventConsumer("all", "");

Quote:
Event ev = con.pop(0);


Quote:
see lua sample -

Quote:
http://wiki.freeswitch.org/wiki/Lua#freeswitch.EventConsumer



Quote:
Phillip Jones-2 wrote:


Quote:
Quote:
Hi there,


Quote:
Quote:
mod_managed exposes EventReceivedFunction such that:


Quote:
Quote:
Session.EventReceivedFunction = (e) =>

Quote:
Quote:
{

Quote:
Quote:
Log.WriteLine(LogLevel.Alert, "Received Event {0}", e.ToString());

Quote:
Quote:
return "";

Quote:
Quote:
};


Quote:
Quote:
should trap all events to which i subscribe.



Quote:
Quote:
But how do I subscribe to events? What is the .NET / managed equivalent

Quote:
Quote:
of:


Quote:
Quote:
switch_event_bind(const char *id, switch_event_types_t event, const char

Quote:
Quote:
*subclass_name, switch_event_callback_t callback, void *user_data);




Quote:
Quote:
Thank you!









_______________________________________________
FreeSWITCH-users mailing list
FreeSWITCH-users@lists.freeswitch.org (FreeSWITCH-users@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@lists.freeswitch.org (FreeSWITCH-users@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@lists.freeswitch.org (FreeSWITCH-users@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@lists.freeswitch.org (FreeSWITCH-users@lists.freeswitch.org)
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
http://www.freeswitch.org
Back to top
josh at radianttiger.com
Guest





PostPosted: Wed Sep 09, 2009 12:40 am    Post subject: [Freeswitch-users] Subscribing to events in managed C# / .NE Reply with quote

Here is the error I get with the loop I mentioned. -Josh


On Tue, Sep 8, 2009 at 5:05 AM, Michael Giagnocavo <mgg@giagnocavo.net (mgg@giagnocavo.net)> wrote:
Quote:

Hi,
 
                Can you please elaborate on the crash you receive when you queue a thread during load?
 
Thanks,
Michael               
 
From: freeswitch-users-bounces@lists.freeswitch.org (freeswitch-users-bounces@lists.freeswitch.org) [mailto:freeswitch-users-bounces@lists.freeswitch.org (freeswitch-users-bounces@lists.freeswitch.org)] On Behalf Of Josh Rivers
Sent: Tuesday, September 08, 2009 12:22 AM
To: freeswitch-users@lists.freeswitch.org (freeswitch-users@lists.freeswitch.org)
Subject: Re: [Freeswitch-users] Subscribing to events in managed C# / .NET


 
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@gmail.com (raffaele.p.guidi@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 Smile

 

Ciao,

   Raffaele

 
On Sun, Sep 6, 2009 at 22:50, Josh Rivers <josh@radianttiger.com (josh@radianttiger.com)> wrote:

Quote:

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@frontiernet.net (jlenk@frontiernet.net)> wrote:

 

Quote:
 

Quote:
try something like this

Quote:
 

Quote:
EventConsumer con = new EventConsumer("all", "");

Quote:
Event ev = con.pop(0);

Quote:
 

Quote:
see lua sample -

Quote:
http://wiki.freeswitch.org/wiki/Lua#freeswitch.EventConsumer

Quote:
 

Quote:
 

Quote:
Phillip Jones-2 wrote:


Quote:
Quote:
Hi there,


Quote:
Quote:
mod_managed exposes EventReceivedFunction such that:


Quote:
Quote:
 Session.EventReceivedFunction = (e) =>

Quote:
Quote:
 {

Quote:
Quote:
       Log.WriteLine(LogLevel.Alert, "Received Event {0}", e.ToString());

Quote:
Quote:
       return "";

Quote:
Quote:
 };


Quote:
Quote:
should trap all events to which i subscribe.



Quote:
Quote:
But how do I subscribe to events? What is the .NET / managed equivalent

Quote:
Quote:
of:


Quote:
Quote:
switch_event_bind(const char *id, switch_event_types_t event, const char

Quote:
Quote:
*subclass_name, switch_event_callback_t callback, void *user_data);




Quote:
Quote:
Thank you!






 


_______________________________________________
FreeSWITCH-users mailing list
FreeSWITCH-users@lists.freeswitch.org (FreeSWITCH-users@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@lists.freeswitch.org (FreeSWITCH-users@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@lists.freeswitch.org (FreeSWITCH-users@lists.freeswitch.org)
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
http://www.freeswitch.org

Back to top
josh at radianttiger.com
Guest





PostPosted: Wed Sep 09, 2009 12:42 am    Post subject: [Freeswitch-users] Subscribing to events in managed C# / .NE Reply with quote

You are probably right, but commenting out the msleep doesn't prevent the crash. -Josh

On Tue, Sep 8, 2009 at 11:12 AM, Phillip Jones <pjintheusa@gmail.com (pjintheusa@gmail.com)> wrote:
Quote:
What is:

freeswitch.msleep(100);

Why aren't you using Thread.Sleep?


On Tue, Sep 8, 2009 at 2:21 AM, Josh Rivers <josh@radianttiger.com (josh@radianttiger.com)> wrote:
Quote:
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@gmail.com (raffaele.p.guidi@gmail.com)> wrote:
Quote:
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 Smile


Ciao,
   Raffaele


On Sun, Sep 6, 2009 at 22:50, Josh Rivers <josh@radianttiger.com (josh@radianttiger.com)> wrote:


Quote:

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@frontiernet.net (jlenk@frontiernet.net)> wrote:


Quote:

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:
Quote:

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@lists.freeswitch.org (FreeSWITCH-users@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@lists.freeswitch.org (FreeSWITCH-users@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@lists.freeswitch.org (FreeSWITCH-users@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@lists.freeswitch.org (FreeSWITCH-users@lists.freeswitch.org)
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
http://www.freeswitch.org

Back to top
josh at radianttiger.com
Guest





PostPosted: Wed Sep 09, 2009 12:53 am    Post subject: [Freeswitch-users] Subscribing to events in managed C# / .NE Reply with quote

I confirmed that pop(1) works for me. since it's spinning in it's own thread, that's probably the right solution. These are the relevant pieces of core code, though:


APU_DECLARE(apr_status_t) apr_queue_trypop(apr_queue_t *queue, void **data)
{
    apr_status_t rv;


    if (queue->terminated) {
        return APR_EOF; /* no more elements ever again */
    }


    rv = apr_thread_mutex_lock(queue->one_big_mutex);
    if (rv != APR_SUCCESS) {
        return rv;
    }


    if (apr_queue_empty(queue)) {
        rv = apr_thread_mutex_unlock(queue->one_big_mutex);
        return APR_EAGAIN;
    } 


    *data = queue->data[queue->out];
    queue->nelts--;


    queue->out = (queue->out + 1) % queue->bounds;
    if (queue->full_waiters) {
        Q_DBG("signal !full", queue);
        rv = apr_thread_cond_signal(queue->not_full);
        if (rv != APR_SUCCESS) {
            apr_thread_mutex_unlock(queue->one_big_mutex);
            return rv;
        }
    }


    rv = apr_thread_mutex_unlock(queue->one_big_mutex);
    return rv;
}


AND


APU_DECLARE(apr_status_t) apr_queue_pop(apr_queue_t *queue, void **data)
{
    apr_status_t rv;


    if (queue->terminated) {
        return APR_EOF; /* no more elements ever again */
    }


    rv = apr_thread_mutex_lock(queue->one_big_mutex);
    if (rv != APR_SUCCESS) {
        return rv;
    }


    /* Keep waiting until we wake up and find that the queue is not empty. */
    if (apr_queue_empty(queue)) {
        if (!queue->terminated) {
            queue->empty_waiters++;
            rv = apr_thread_cond_wait(queue->not_empty, queue->one_big_mutex);
            queue->empty_waiters--;
            if (rv != APR_SUCCESS) {
                apr_thread_mutex_unlock(queue->one_big_mutex);
                return rv;
            }
        }
        /* If we wake up and it's still empty, then we were interrupted */
        if (apr_queue_empty(queue)) {
            Q_DBG("queue empty (intr)", queue);
            rv = apr_thread_mutex_unlock(queue->one_big_mutex);
            if (rv != APR_SUCCESS) {
                return rv;
            }
            if (queue->terminated) {
                return APR_EOF; /* no more elements ever again */
            }
            else {
                return APR_EINTR;
            }
        }
    } 


    *data = queue->data[queue->out];
    queue->nelts--;


    queue->out = (queue->out + 1) % queue->bounds;
    if (queue->full_waiters) {
        Q_DBG("signal !full", queue);
        rv = apr_thread_cond_signal(queue->not_full);
        if (rv != APR_SUCCESS) {
            apr_thread_mutex_unlock(queue->one_big_mutex);
            return rv;
        }
    }


    rv = apr_thread_mutex_unlock(queue->one_big_mutex);
    return rv;
}


Is the trypop method returning without unlocking the mutex?


    rv = apr_thread_mutex_lock(queue->one_big_mutex);
    if (rv != APR_SUCCESS) {
        return rv;
    }




On Tue, Sep 8, 2009 at 7:06 PM, Michael Giagnocavo <mgg@giagnocavo.net (mgg@giagnocavo.net)> wrote:
Quote:

I’m not sure how EventConsumer is supposed to work – maybe one of the real devs can explain how pop works and if it should fail on pop 0 or not.
 
From: freeswitch-users-bounces@lists.freeswitch.org (freeswitch-users-bounces@lists.freeswitch.org) [mailto:freeswitch-users-bounces@lists.freeswitch.org (freeswitch-users-bounces@lists.freeswitch.org)] On Behalf Of Phillip Jones
Sent: Tuesday, September 08, 2009 3:50 PM

To: freeswitch-users@lists.freeswitch.org (freeswitch-users@lists.freeswitch.org)
Subject: Re: [Freeswitch-users] Subscribing to events in managed C# / .NET





 
I build this out.

This seems to work fine:

ThreadPool.QueueUserWorkItem((o) =>
            {
                Log.WriteLine(LogLevel.Notice, "Thread Starting. ");
                EventConsumer con = new EventConsumer("all", "");
                while (true)
                {
                    Event ev = con.pop(1);
                    Log.WriteLine(LogLevel.Alert, "Event: " + ev.GetHeader("Event-Name"));
                    //freeswitch.msleep(100);
                }
            });

With
            Event ev = con.pop(0) however FS crashes with a System.NullReferenceException (attached)










On Tue, Sep 8, 2009 at 5:20 PM, Raffaele P. Guidi <raffaele.p.guidi@gmail.com (raffaele.p.guidi@gmail.com)> wrote:
Oh, I see... all those years wasted doing java stuff! Very Happy
 
On Tue, Sep 8, 2009 at 22:46, Michael Giagnocavo <mgg@giagnocavo.net (mgg@giagnocavo.net)> wrote:
“ ThreadPool.QueueUserWorkItem((o) =>”
That starts a lambda, which is compiled to a delegate, same as anonymous methods.
Guess I’ll wait for him to respond on the crash he gets.
 
 
From: freeswitch-users-bounces@lists.freeswitch.org (freeswitch-users-bounces@lists.freeswitch.org) [mailto:freeswitch-users-bounces@lists.freeswitch.org (freeswitch-users-bounces@lists.freeswitch.org)] On Behalf Of Raffaele P. Guidi
Sent: Tuesday, September 08, 2009 12:22 PM

To: freeswitch-users@lists.freeswitch.org (freeswitch-users@lists.freeswitch.org)
Subject: Re: [Freeswitch-users] Subscribing to events in managed C# / .NET



 
Well, I can't see any delegate in josh sample, just a ThreadPool.QueueUserWorkItem. Here is an example that, at least on my system (I reached my home pc in the meanwhile), works fine.
 

     public class LoadPluginDemo : ILoadNotificationPlugin {

          delegate void Listener();

          private void EventListener() {

            EventConsumer con = new EventConsumer("all", null);

            while (true){

                 Event ev = con.pop(1);

                 Log.WriteLine(LogLevel.Notice, "Got event " + ev.GetHeader("Event-Name"));        

            }

          }

        public bool Load() {

            Log.WriteLine(LogLevel.Notice, "LoadDemo running.");

            new Listener(EventListener).BeginInvoke(null,null);

            return true;

        }

     }

 

 

 
On Tue, Sep 8, 2009 at 18:43, Michael Giagnocavo <mgg@giagnocavo.net (mgg@giagnocavo.net)> wrote:
That’s what his sample does, but he says it crashes.
 
From: freeswitch-users-bounces@lists.freeswitch.org (freeswitch-users-bounces@lists.freeswitch.org) [mailto:freeswitch-users-bounces@lists.freeswitch.org (freeswitch-users-bounces@lists.freeswitch.org)] On Behalf Of Raffaele P. Guidi
Sent: Tuesday, September 08, 2009 10:08 AM

To: freeswitch-users@lists.freeswitch.org (freeswitch-users@lists.freeswitch.org)
Subject: Re: [Freeswitch-users] Subscribing to events in managed C# / .NET


 
Hi, you just have to use delegates to asynchronously call the function containing the loop and return back the control to the calling thread. Here an example (don't have my code at hand, hope it doesn't contain typos).

 

Regards,

   Raffaele

 

   public class TestLoop : ILoadNotificationPlugin

    {

 
       Delegate void DoStuffDelegate();

 

       public void doStuff()

        {

            EventConsumer con = new EventConsumer("all", "");


            while (true)

            {

                Event ev = con.pop(0);


                Log.WriteLine(LogLevel.Notice, "Event: " + ev.serialized_string);

                freeswitch.msleep(100);

            }

        }

        public bool Load()

        {

            DoStuffDelegate dsdlg = new DoStuffDelegate(doStuff);

            dsdlg.BeginInvoke();

        }


    }


On Tue, Sep 8, 2009 at 08:21, Josh Rivers <josh@radianttiger.com (josh@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@gmail.com (raffaele.p.guidi@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 Smile

 

Ciao,

   Raffaele

 
On Sun, Sep 6, 2009 at 22:50, Josh Rivers <josh@radianttiger.com (josh@radianttiger.com)> wrote:

Quote:

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@frontiernet.net (jlenk@frontiernet.net)> wrote:

 

Quote:
 

Quote:
try something like this

Quote:
 

Quote:
EventConsumer con = new EventConsumer("all", "");

Quote:
Event ev = con.pop(0);

Quote:
 

Quote:
see lua sample -

Quote:
http://wiki.freeswitch.org/wiki/Lua#freeswitch.EventConsumer

Quote:
 

Quote:
 

Quote:
Phillip Jones-2 wrote:


Quote:
Quote:
Hi there,


Quote:
Quote:
mod_managed exposes EventReceivedFunction such that:


Quote:
Quote:
 Session.EventReceivedFunction = (e) =>

Quote:
Quote:
 {

Quote:
Quote:
       Log.WriteLine(LogLevel.Alert, "Received Event {0}", e.ToString());

Quote:
Quote:
       return "";

Quote:
Quote:
 };


Quote:
Quote:
should trap all events to which i subscribe.



Quote:
Quote:
But how do I subscribe to events? What is the .NET / managed equivalent

Quote:
Quote:
of:


Quote:
Quote:
switch_event_bind(const char *id, switch_event_types_t event, const char

Quote:
Quote:
*subclass_name, switch_event_callback_t callback, void *user_data);




Quote:
Quote:
Thank you!






 


_______________________________________________
FreeSWITCH-users mailing list
FreeSWITCH-users@lists.freeswitch.org (FreeSWITCH-users@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@lists.freeswitch.org (FreeSWITCH-users@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@lists.freeswitch.org (FreeSWITCH-users@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@lists.freeswitch.org (FreeSWITCH-users@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@lists.freeswitch.org (FreeSWITCH-users@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@lists.freeswitch.org (FreeSWITCH-users@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@lists.freeswitch.org (FreeSWITCH-users@lists.freeswitch.org)
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
http://www.freeswitch.org

Back to top
josh at radianttiger.com
Guest





PostPosted: Wed Sep 09, 2009 12:53 am    Post subject: [Freeswitch-users] Subscribing to events in managed C# / .NE Reply with quote

I'm running of the binary release, so I don't have debug symbols for the freeswitch core. I can do a build...but does somebody else already have one handy? -Josh

On Tue, Sep 8, 2009 at 10:33 PM, Mathieu Rene <mrene_lists@avgs.ca (mrene_lists@avgs.ca)> wrote:
Quote:
Click Break, then go in Window, Debug, Stack Trace (or something similar, I don't have any VS nearby), then copy paste that.
Mathieu Rene
Avant-Garde Solutions Inc
Office: + 1 (514) 664-1044 x100
Cell: +1 (514) 664-1044 x200
mrene@avgs.ca (mrene@avgs.ca)









On 8-Sep-09, at 10:30 PM, Josh Rivers wrote:


Quote:
Here is the error I get with the loop I mentioned. -Josh


<Capture.PNG>

On Tue, Sep 8, 2009 at 5:05 AM, Michael Giagnocavo <mgg@giagnocavo.net (mgg@giagnocavo.net)> wrote:
Quote:

Hi,  


                Can you please elaborate on the crash you receive when you queue a thread during load?  


Thanks,
Michael                 


From: freeswitch-users-bounces@lists.freeswitch.org (freeswitch-users-bounces@lists.freeswitch.org) [mailto:freeswitch-users-bounces@lists.freeswitch.org (freeswitch-users-bounces@lists.freeswitch.org)] On Behalf Of Josh Rivers
Sent: Tuesday, September 08, 2009 12:22 AM
To: freeswitch-users@lists.freeswitch.org (freeswitch-users@lists.freeswitch.org)
Subject: Re: [Freeswitch-users] Subscribing to events in managed C# / .NET

 


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@gmail.com (raffaele.p.guidi@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 Smile
 



Ciao,

   Raffaele
 


On Sun, Sep 6, 2009 at 22:50, Josh Rivers <josh@radianttiger.com (josh@radianttiger.com)> wrote:

Quote:

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@frontiernet.net (jlenk@frontiernet.net)> wrote:
 



Quote:
 

Quote:
try something like this

Quote:
 

Quote:
EventConsumer con = new EventConsumer("all", "");

Quote:
Event ev = con.pop(0);

Quote:
 

Quote:
see lua sample -

Quote:
http://wiki.freeswitch.org/wiki/Lua#freeswitch.EventConsumer

Quote:
 

Quote:
 

Quote:
Phillip Jones-2 wrote:


Quote:
Quote:
Hi there,


Quote:
Quote:
mod_managed exposes EventReceivedFunction such that:


Quote:
Quote:
 Session.EventReceivedFunction = (e) =>

Quote:
Quote:
 {

Quote:
Quote:
       Log.WriteLine(LogLevel.Alert, "Received Event {0}", e.ToString());

Quote:
Quote:
       return "";

Quote:
Quote:
 };


Quote:
Quote:
should trap all events to which i subscribe.



Quote:
Quote:
But how do I subscribe to events? What is the .NET / managed equivalent

Quote:
Quote:
of:


Quote:
Quote:
switch_event_bind(const char *id, switch_event_types_t event, const char

Quote:
Quote:
*subclass_name, switch_event_callback_t callback, void *user_data);




Quote:
Quote:
Thank you!





 




_______________________________________________
FreeSWITCH-users mailing list
FreeSWITCH-users@lists.freeswitch.org (FreeSWITCH-users@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@lists.freeswitch.org (FreeSWITCH-users@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@lists.freeswitch.org (FreeSWITCH-users@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@lists.freeswitch.org (FreeSWITCH-users@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@lists.freeswitch.org (FreeSWITCH-users@lists.freeswitch.org)
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
http://www.freeswitch.org

Back to top
mrene_lists at avgs.ca
Guest





PostPosted: Wed Sep 09, 2009 12:56 am    Post subject: [Freeswitch-users] Subscribing to events in managed C# / .NE Reply with quote

"Is the trypop method returning without unlocking the mutex?"

No, since the condition returns if a lock could NOT be acquired. (hence the try).

Mathieu Rene
Avant-Garde Solutions Inc
Office: + 1 (514) 664-1044 x100
Cell: +1 (514) 664-1044 x200
mrene@avgs.ca (mrene@avgs.ca)








On 8-Sep-09, at 10:46 PM, Josh Rivers wrote:
Quote:
I confirmed that pop(1) works for me. since it's spinning in it's own thread, that's probably the right solution. These are the relevant pieces of core code, though:


APU_DECLARE(apr_status_t) apr_queue_trypop(apr_queue_t *queue, void **data)
{
apr_status_t rv;


if (queue->terminated) {
return APR_EOF; /* no more elements ever again */
}


rv = apr_thread_mutex_lock(queue->one_big_mutex);
if (rv != APR_SUCCESS) {
return rv;
}


if (apr_queue_empty(queue)) {
rv = apr_thread_mutex_unlock(queue->one_big_mutex);
return APR_EAGAIN;
}


*data = queue->data[queue->out];
queue->nelts--;


queue->out = (queue->out + 1) % queue->bounds;
if (queue->full_waiters) {
Q_DBG("signal !full", queue);
rv = apr_thread_cond_signal(queue->not_full);
if (rv != APR_SUCCESS) {
apr_thread_mutex_unlock(queue->one_big_mutex);
return rv;
}
}


rv = apr_thread_mutex_unlock(queue->one_big_mutex);
return rv;
}


AND


APU_DECLARE(apr_status_t) apr_queue_pop(apr_queue_t *queue, void **data)
{
apr_status_t rv;


if (queue->terminated) {
return APR_EOF; /* no more elements ever again */
}


rv = apr_thread_mutex_lock(queue->one_big_mutex);
if (rv != APR_SUCCESS) {
return rv;
}


/* Keep waiting until we wake up and find that the queue is not empty. */
if (apr_queue_empty(queue)) {
if (!queue->terminated) {
queue->empty_waiters++;
rv = apr_thread_cond_wait(queue->not_empty, queue->one_big_mutex);
queue->empty_waiters--;
if (rv != APR_SUCCESS) {
apr_thread_mutex_unlock(queue->one_big_mutex);
return rv;
}
}
/* If we wake up and it's still empty, then we were interrupted */
if (apr_queue_empty(queue)) {
Q_DBG("queue empty (intr)", queue);
rv = apr_thread_mutex_unlock(queue->one_big_mutex);
if (rv != APR_SUCCESS) {
return rv;
}
if (queue->terminated) {
return APR_EOF; /* no more elements ever again */
}
else {
return APR_EINTR;
}
}
}


*data = queue->data[queue->out];
queue->nelts--;


queue->out = (queue->out + 1) % queue->bounds;
if (queue->full_waiters) {
Q_DBG("signal !full", queue);
rv = apr_thread_cond_signal(queue->not_full);
if (rv != APR_SUCCESS) {
apr_thread_mutex_unlock(queue->one_big_mutex);
return rv;
}
}


rv = apr_thread_mutex_unlock(queue->one_big_mutex);
return rv;
}


Is the trypop method returning without unlocking the mutex?


rv = apr_thread_mutex_lock(queue->one_big_mutex);
if (rv != APR_SUCCESS) {
return rv;
}




On Tue, Sep 8, 2009 at 7:06 PM, Michael Giagnocavo <mgg@giagnocavo.net (mgg@giagnocavo.net)> wrote:
Quote:

I’m not sure how EventConsumer is supposed to work – maybe one of the real devs can explain how pop works and if it should fail on pop 0 or not.

From: freeswitch-users-bounces@lists.freeswitch.org (freeswitch-users-bounces@lists.freeswitch.org) [mailto:freeswitch-users-bounces@lists.freeswitch.org (freeswitch-users-bounces@lists.freeswitch.org)] On Behalf Of Phillip Jones
Sent: Tuesday, September 08, 2009 3:50 PM

To: freeswitch-users@lists.freeswitch.org (freeswitch-users@lists.freeswitch.org)
Subject: Re: [Freeswitch-users] Subscribing to events in managed C# / .NET






I build this out.

This seems to work fine:

ThreadPool.QueueUserWorkItem((o) =>
{
Log.WriteLine(LogLevel.Notice, "Thread Starting. ");
EventConsumer con = new EventConsumer("all", "");
while (true)
{
Event ev = con.pop(1);
Log.WriteLine(LogLevel.Alert, "Event: " + ev.GetHeader("Event-Name"));
//freeswitch.msleep(100);
}
});

With
Event ev = con.pop(0) however FS crashes with a System.NullReferenceException (attached)










On Tue, Sep 8, 2009 at 5:20 PM, Raffaele P. Guidi <raffaele.p.guidi@gmail.com (raffaele.p.guidi@gmail.com)> wrote:
Oh, I see... all those years wasted doing java stuff! Very Happy

On Tue, Sep 8, 2009 at 22:46, Michael Giagnocavo <mgg@giagnocavo.net (mgg@giagnocavo.net)> wrote:
“ ThreadPool.QueueUserWorkItem((o) =>”
That starts a lambda, which is compiled to a delegate, same as anonymous methods.
Guess I’ll wait for him to respond on the crash he gets.


From: freeswitch-users-bounces@lists.freeswitch.org (freeswitch-users-bounces@lists.freeswitch.org) [mailto:freeswitch-users-bounces@lists.freeswitch.org (freeswitch-users-bounces@lists.freeswitch.org)] On Behalf Of Raffaele P. Guidi
Sent: Tuesday, September 08, 2009 12:22 PM

To: freeswitch-users@lists.freeswitch.org (freeswitch-users@lists.freeswitch.org)
Subject: Re: [Freeswitch-users] Subscribing to events in managed C# / .NET




Well, I can't see any delegate in josh sample, just a ThreadPool.QueueUserWorkItem. Here is an example that, at least on my system (I reached my home pc in the meanwhile), works fine.


public class LoadPluginDemo : ILoadNotificationPlugin {

delegate void Listener();

private void EventListener() {

EventConsumer con = new EventConsumer("all", null);

while (true){

Event ev = con.pop(1);

Log.WriteLine(LogLevel.Notice, "Got event " + ev.GetHeader("Event-Name"));

}

}

public bool Load() {

Log.WriteLine(LogLevel.Notice, "LoadDemo running.");

new Listener(EventListener).BeginInvoke(null,null);

return true;

}

}






On Tue, Sep 8, 2009 at 18:43, Michael Giagnocavo <mgg@giagnocavo.net (mgg@giagnocavo.net)> wrote:
That’s what his sample does, but he says it crashes.

From: freeswitch-users-bounces@lists.freeswitch.org (freeswitch-users-bounces@lists.freeswitch.org) [mailto:freeswitch-users-bounces@lists.freeswitch.org (freeswitch-users-bounces@lists.freeswitch.org)] On Behalf Of Raffaele P. Guidi
Sent: Tuesday, September 08, 2009 10:08 AM

To: freeswitch-users@lists.freeswitch.org (freeswitch-users@lists.freeswitch.org)
Subject: Re: [Freeswitch-users] Subscribing to events in managed C# / .NET



Hi, you just have to use delegates to asynchronously call the function containing the loop and return back the control to the calling thread. Here an example (don't have my code at hand, hope it doesn't contain typos).



Regards,

Raffaele



public class TestLoop : ILoadNotificationPlugin

{


Delegate void DoStuffDelegate();



public void doStuff()

{

EventConsumer con = new EventConsumer("all", "");


while (true)

{

Event ev = con.pop(0);


Log.WriteLine(LogLevel.Notice, "Event: " + ev.serialized_string);

freeswitch.msleep(100);

}

}

public bool Load()

{

DoStuffDelegate dsdlg = new DoStuffDelegate(doStuff);

dsdlg.BeginInvoke();

}


}


On Tue, Sep 8, 2009 at 08:21, Josh Rivers <josh@radianttiger.com (josh@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@gmail.com (raffaele.p.guidi@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 Smile



Ciao,

Raffaele


On Sun, Sep 6, 2009 at 22:50, Josh Rivers <josh@radianttiger.com (josh@radianttiger.com)> wrote:

Quote:

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@frontiernet.net (jlenk@frontiernet.net)> wrote:




Quote:
try something like this


Quote:
EventConsumer con = new EventConsumer("all", "");

Quote:
Event ev = con.pop(0);


Quote:
see lua sample -

Quote:
http://wiki.freeswitch.org/wiki/Lua#freeswitch.EventConsumer



Quote:
Phillip Jones-2 wrote:


Quote:
Quote:
Hi there,


Quote:
Quote:
mod_managed exposes EventReceivedFunction such that:


Quote:
Quote:
Session.EventReceivedFunction = (e) =>

Quote:
Quote:
{

Quote:
Quote:
Log.WriteLine(LogLevel.Alert, "Received Event {0}", e.ToString());

Quote:
Quote:
return "";

Quote:
Quote:
};


Quote:
Quote:
should trap all events to which i subscribe.



Quote:
Quote:
But how do I subscribe to events? What is the .NET / managed equivalent

Quote:
Quote:
of:


Quote:
Quote:
switch_event_bind(const char *id, switch_event_types_t event, const char

Quote:
Quote:
*subclass_name, switch_event_callback_t callback, void *user_data);




Quote:
Quote:
Thank you!









_______________________________________________
FreeSWITCH-users mailing list
FreeSWITCH-users@lists.freeswitch.org (FreeSWITCH-users@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@lists.freeswitch.org (FreeSWITCH-users@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@lists.freeswitch.org (FreeSWITCH-users@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@lists.freeswitch.org (FreeSWITCH-users@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@lists.freeswitch.org (FreeSWITCH-users@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@lists.freeswitch.org (FreeSWITCH-users@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@lists.freeswitch.org (FreeSWITCH-users@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@lists.freeswitch.org (FreeSWITCH-users@lists.freeswitch.org)
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
http://www.freeswitch.org
Back to top
jlenk at frontiernet.net
Guest





PostPosted: Wed Sep 09, 2009 3:08 pm    Post subject: [Freeswitch-users] Subscribing to events in managed C# / .NE Reply with quote

I think the problem here is that the loader only keeps this method in scope
until completion then it drops the remoted connection. Therefore you should
not use threads in this method. Michael please correct me if I am wrong
here.

As an example of the failure simply just put a Sleep(10000) call in the
thread and you will see the failure.

As Michael said this method was only designed to allow the option to opt out
of being loaded.

In order to support this perhaps a configuration flag simular to the lua
"startup-script" should be added.



Here is the error I get with the loop I mentioned. -Josh
[image: Capture.PNG]

On Tue, Sep 8, 2009 at 5:05 AM, Michael Giagnocavo
<mgg@giagnocavo.net>wrote:

Quote:
Hi,



Can you please elaborate on the crash you receive when you
queue a thread during load?



Thanks,

Michael



--
View this message in context: http://n2.nabble.com/Subscribing-to-events-in-managed-C-NET-tp3573619p3613195.html
Sent from the freeswitch-users mailing list archive at Nabble.com.

_______________________________________________
FreeSWITCH-users mailing list
FreeSWITCH-users@lists.freeswitch.org
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
http://www.freeswitch.org
Back to top
josh at radianttiger.com
Guest





PostPosted: Wed Sep 09, 2009 3:48 pm    Post subject: [Freeswitch-users] Subscribing to events in managed C# / .NE Reply with quote

  kernel32.dll!77e4bef7()
Here's that call stack.


  [Frames below may be incorrect and/or missing, no symbols loaded for kernel32.dll]
  kernel32.dll!77e4bef7()
  msvcr80.dll!78158e89()
  mscorwks.dll!79e7a17a()
  mscorwks.dll!79ea0fa8()
  mscorwks.dll!79ea0eff()
  mscorwks.dll!79e976cc()
  mscorwks.dll!79e976b3()
  mscorwks.dll!79e9e3bd()
  mscorwks.dll!79e970c8()
  mscorwks.dll!79f782f1()
  mscorwks.dll!79eaa5c5()
  mscorwks.dll!79eaad29()
  mscorwks.dll!79e9a15d()
  mscorwks.dll!79e9a15d()
  mscorwks.dll!79e7a1f1()
  mscorwks.dll!79e7a1f1()
  mscorwks.dll!79e7a17a()
  mscorwks.dll!79e88cca()
  mscorwks.dll!79e96571()
  mscorwks.dll!79e965a4()
  mscorwks.dll!79e965c2()
  mscorwks.dll!79f59330()
  mscorwks.dll!79f59492()
  mscorlib.ni.dll!792d5348()
  mscorlib.ni.dll!792d514f()
  mscorlib.ni.dll!792d4fde()
  mscorlib.ni.dll!79799714()
  mscorwks.dll!79e813e4()
  mscorwks.dll!79e813ec()
Quote:
FreeSwitch.dll!switch_loadable_module_load_file(char * path=0x01181250, char * filename=0x01181240, switch_bool_t global=SWITCH_FALSE, switch_loadable_module * * new_module=0x0012d9e0)  Line 846 + 0xd bytes C
  FreeSwitch.dll!switch_loadable_module_load_module_ex(char * dir=0x003994a8, char * fname=0x01081d59, switch_bool_t runtime=SWITCH_FALSE, switch_bool_t global=SWITCH_FALSE, const char * * err=0x0012da5c)  Line 942 + 0x15 bytes C
  FreeSwitch.dll!switch_loadable_module_init()  Line 1174 + 0x23 bytes C
  FreeSwitch.dll!switch_core_init_and_modload(unsigned int flags=129, switch_bool_t console=SWITCH_TRUE, const char * * err=0x0012fdec)  Line 1469 + 0x5 bytes C
  FreeSwitch.exe!main(int argc=1, char * * argv=0x00394f80)  Line 748 + 0x23 bytes C
  FreeSwitch.exe!__tmainCRTStartup()  Line 586 + 0x19 bytes C
  FreeSwitch.exe!mainCRTStartup()  Line 403 C
  kernel32.dll!77e6f23b()


The breakpoint is: status = load_func_ptr(&module_interface, pool);
Line 846 in switch_loadable_module.c


--Josh

On Tue, Sep 8, 2009 at 10:50 PM, Josh Rivers <josh@radianttiger.com (josh@radianttiger.com)> wrote:
Quote:
I'm running of the binary release, so I don't have debug symbols for the freeswitch core. I can do a build...but does somebody else already have one handy? -Josh


On Tue, Sep 8, 2009 at 10:33 PM, Mathieu Rene <mrene_lists@avgs.ca (mrene_lists@avgs.ca)> wrote:
Quote:
Click Break, then go in Window, Debug, Stack Trace (or something similar, I don't have any VS nearby), then copy paste that.
Mathieu Rene
Avant-Garde Solutions Inc
Office: + 1 (514) 664-1044 x100
Cell: +1 (514) 664-1044 x200
mrene@avgs.ca (mrene@avgs.ca)









On 8-Sep-09, at 10:30 PM, Josh Rivers wrote:


Quote:
Here is the error I get with the loop I mentioned. -Josh


<Capture.PNG>

On Tue, Sep 8, 2009 at 5:05 AM, Michael Giagnocavo <mgg@giagnocavo.net (mgg@giagnocavo.net)> wrote:
Quote:

Hi,  


                Can you please elaborate on the crash you receive when you queue a thread during load?  


Thanks,
Michael                 


From: freeswitch-users-bounces@lists.freeswitch.org (freeswitch-users-bounces@lists.freeswitch.org) [mailto:freeswitch-users-bounces@lists.freeswitch.org (freeswitch-users-bounces@lists.freeswitch.org)] On Behalf Of Josh Rivers
Sent: Tuesday, September 08, 2009 12:22 AM
To: freeswitch-users@lists.freeswitch.org (freeswitch-users@lists.freeswitch.org)
Subject: Re: [Freeswitch-users] Subscribing to events in managed C# / .NET

 


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@gmail.com (raffaele.p.guidi@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 Smile
 



Ciao,

   Raffaele
 


On Sun, Sep 6, 2009 at 22:50, Josh Rivers <josh@radianttiger.com (josh@radianttiger.com)> wrote:

Quote:

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@frontiernet.net (jlenk@frontiernet.net)> wrote:
 



Quote:
 

Quote:
try something like this

Quote:
 

Quote:
EventConsumer con = new EventConsumer("all", "");

Quote:
Event ev = con.pop(0);

Quote:
 

Quote:
see lua sample -

Quote:
http://wiki.freeswitch.org/wiki/Lua#freeswitch.EventConsumer

Quote:
 

Quote:
 

Quote:
Phillip Jones-2 wrote:


Quote:
Quote:
Hi there,


Quote:
Quote:
mod_managed exposes EventReceivedFunction such that:


Quote:
Quote:
 Session.EventReceivedFunction = (e) =>

Quote:
Quote:
 {

Quote:
Quote:
       Log.WriteLine(LogLevel.Alert, "Received Event {0}", e.ToString());

Quote:
Quote:
       return "";

Quote:
Quote:
 };


Quote:
Quote:
should trap all events to which i subscribe.



Quote:
Quote:
But how do I subscribe to events? What is the .NET / managed equivalent

Quote:
Quote:
of:


Quote:
Quote:
switch_event_bind(const char *id, switch_event_types_t event, const char

Quote:
Quote:
*subclass_name, switch_event_callback_t callback, void *user_data);




Quote:
Quote:
Thank you!





 




_______________________________________________
FreeSWITCH-users mailing list
FreeSWITCH-users@lists.freeswitch.org (FreeSWITCH-users@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@lists.freeswitch.org (FreeSWITCH-users@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@lists.freeswitch.org (FreeSWITCH-users@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@lists.freeswitch.org (FreeSWITCH-users@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@lists.freeswitch.org (FreeSWITCH-users@lists.freeswitch.org)
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
http://www.freeswitch.org





Back to top
josh at radianttiger.com
Guest





PostPosted: Wed Sep 09, 2009 4:11 pm    Post subject: [Freeswitch-users] Subscribing to events in managed C# / .NE Reply with quote

A new discovery:        public bool Load()
        {
            ThreadPool.QueueUserWorkItem((o) =>
            {
                Log.WriteLine(LogLevel.Notice, "Thread Starting. ");
                EventConsumer con = new EventConsumer("all", "");
                while (true)
                {
                    Event ev = con.pop(0);
                    if (ev == null) continue;
                    Log.WriteLine(LogLevel.Notice, "Event: " + ev.serialized_string);
                }
            });
            return true;
        }
Does not crash. (Adding the null check prevents crash.) The backgrounded loop runs fine. Looks like the event object goes straight to pinvokes, so a null result just crashes?


I like the idea of a 'startup-script' for mod_managed. It would also be excellent if there was an event or message  informing the background code to terminate nicely when the module reloads.


--Josh

On Wed, Sep 9, 2009 at 12:57 PM, Jeff Lenk <jlenk@frontiernet.net (jlenk@frontiernet.net)> wrote:
Quote:

I think the problem here is that the loader only keeps this method in scope
until completion then it drops the remoted connection. Therefore you should
not use threads in this method. Michael please correct me if I am wrong
here.

As an example of the failure simply just put a Sleep(10000) call in the
thread and you will see the failure.

As Michael said this method was only designed to allow the option to opt out
of being loaded.

In order to support this perhaps a configuration flag simular to the lua
"startup-script" should be added.



Here is the error I get with the loop I mentioned. -Josh
[image: Capture.PNG]

On Tue, Sep 8, 2009 at 5:05 AM, Michael Giagnocavo
<mgg@giagnocavo.net (mgg@giagnocavo.net)>wrote:

Quote:
 Hi,



                Can you please elaborate on the crash you receive when you
queue a thread during load?



Thanks,

Michael




--
View this message in context: http://n2.nabble.com/Subscribing-to-events-in-managed-C-NET-tp3573619p3613195.html
Sent from the freeswitch-users mailing list archive at Nabble.com.


_______________________________________________
FreeSWITCH-users mailing list
FreeSWITCH-users@lists.freeswitch.org (FreeSWITCH-users@lists.freeswitch.org)
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
http://www.freeswitch.org


Back to top
jlenk at frontiernet.net
Guest





PostPosted: Wed Sep 09, 2009 4:42 pm    Post subject: [Freeswitch-users] Subscribing to events in managed C# / .NE Reply with quote

Yeah I noticed that but the thread was still terminating after a few seconds
anyway for me. Does it stay running for you?


Josh Rivers-2 wrote:
Quote:

A new discovery: public bool Load()
{
ThreadPool.QueueUserWorkItem((o) =>
{
Log.WriteLine(LogLevel.Notice, "Thread Starting. ");
EventConsumer con = new EventConsumer("all", "");
while (true)
{
Event ev = con.pop(0);
if (ev == null) continue;
Log.WriteLine(LogLevel.Notice, "Event: " +
ev.serialized_string);
}
});
return true;
}
Does not crash. (Adding the null check prevents crash.) The backgrounded
loop runs fine. Looks like the event object goes straight to pinvokes, so
a
null result just crashes?

I like the idea of a 'startup-script' for mod_managed. It would also be
excellent if there was an event or message informing the background code
to
terminate nicely when the module reloads.

--Josh

On Wed, Sep 9, 2009 at 12:57 PM, Jeff Lenk <jlenk@frontiernet.net> wrote:

Quote:

I think the problem here is that the loader only keeps this method in
scope
until completion then it drops the remoted connection. Therefore you
should
not use threads in this method. Michael please correct me if I am wrong
here.

As an example of the failure simply just put a Sleep(10000) call in the
thread and you will see the failure.

As Michael said this method was only designed to allow the option to opt
out
of being loaded.

In order to support this perhaps a configuration flag simular to the lua
"startup-script" should be added.



Here is the error I get with the loop I mentioned. -Josh
[image: Capture.PNG]

On Tue, Sep 8, 2009 at 5:05 AM, Michael Giagnocavo
<mgg@giagnocavo.net>wrote:

Quote:
Hi,



Can you please elaborate on the crash you receive when
you
Quote:
queue a thread during load?



Thanks,

Michael



--
View this message in context:
http://n2.nabble.com/Subscribing-to-events-in-managed-C-NET-tp3573619p3613195.html
Sent from the freeswitch-users mailing list archive at Nabble.com.

_______________________________________________
FreeSWITCH-users mailing list
FreeSWITCH-users@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@lists.freeswitch.org
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
http://www.freeswitch.org



--
View this message in context: http://n2.nabble.com/Subscribing-to-events-in-managed-C-NET-tp3573619p3614845.html
Sent from the freeswitch-users mailing list archive at Nabble.com.

_______________________________________________
FreeSWITCH-users mailing list
FreeSWITCH-users@lists.freeswitch.org
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
http://www.freeswitch.org
Back to top
josh at radianttiger.com
Guest





PostPosted: Wed Sep 09, 2009 5:20 pm    Post subject: [Freeswitch-users] Subscribing to events in managed C# / .NE Reply with quote

It does from a fresh start of FreeSWITCH. I've noticed, although not really confirmed, a race condition between the unload and reload of managed code. It seems that threads started in the newly submodule are terminated along with the threads for the old, unloading submodule. Is that what you are seeing as well?

On Wed, Sep 9, 2009 at 2:38 PM, Jeff Lenk <jlenk@frontiernet.net (jlenk@frontiernet.net)> wrote:
Quote:

Yeah I noticed that but the thread was still terminating after a few seconds
anyway for me. Does it stay running for you?



Josh Rivers-2 wrote:
Quote:

A new discovery:        public bool Load()
        {
            ThreadPool.QueueUserWorkItem((o) =>
            {
                Log.WriteLine(LogLevel.Notice, "Thread Starting. ");
                EventConsumer con = new EventConsumer("all", "");
                while (true)
                {
                    Event ev = con.pop(0);
                    if (ev == null) continue;
                    Log.WriteLine(LogLevel.Notice, "Event: " +
ev.serialized_string);
                }
            });
            return true;
        }
Does not crash. (Adding the null check prevents crash.) The backgrounded
loop runs fine. Looks like the event object goes straight to pinvokes, so
a
null result just crashes?

I like the idea of a 'startup-script' for mod_managed. It would also be
excellent if there was an event or message  informing the background code
to
terminate nicely when the module reloads.

--Josh

On Wed, Sep 9, 2009 at 12:57 PM, Jeff Lenk <jlenk@frontiernet.net (jlenk@frontiernet.net)> wrote:

Quote:

I think the problem here is that the loader only keeps this method in
scope
until completion then it drops the remoted connection. Therefore you
should
not use threads in this method. Michael please correct me if I am wrong
here.

As an example of the failure simply just put a Sleep(10000) call in the
thread and you will see the failure.

As Michael said this method was only designed to allow the option to opt
out
of being loaded.

In order to support this perhaps a configuration flag simular to the lua
"startup-script" should be added.



Here is the error I get with the loop I mentioned. -Josh
[image: Capture.PNG]

On Tue, Sep 8, 2009 at 5:05 AM, Michael Giagnocavo
<mgg@giagnocavo.net (mgg@giagnocavo.net)>wrote:

Quote:
 Hi,



                Can you please elaborate on the crash you receive when
you
Quote:
queue a thread during load?



Thanks,

Michael



--
View this message in context:
http://n2.nabble.com/Subscribing-to-events-in-managed-C-NET-tp3573619p3613195.html
Sent from the freeswitch-users mailing list archive at Nabble.com.

_______________________________________________
FreeSWITCH-users mailing list
FreeSWITCH-users@lists.freeswitch.org (FreeSWITCH-users@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@lists.freeswitch.org (FreeSWITCH-users@lists.freeswitch.org)
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
http://www.freeswitch.org





--
View this message in context: http://n2.nabble.com/Subscribing-to-events-in-managed-C-NET-tp3573619p3614845.html

Sent from the freeswitch-users mailing list archive at Nabble.com.

_______________________________________________
FreeSWITCH-users mailing list
FreeSWITCH-users@lists.freeswitch.org (FreeSWITCH-users@lists.freeswitch.org)
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
http://www.freeswitch.org


Back to top
Display posts from previous:   
Post new topic   Reply to topic    VoIP Mailing List Archives Forum Index -> freeSWITCH Users All times are GMT - 5 Hours
Goto page Previous  1, 2, 3, 4  Next
Page 2 of 4

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group

VoiceMeUp - Corporate & Wholesale VoIP Services