Re: [Freeswitch-users] Subscribing to events in managed C# / .NET
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> wrote:
try something like this
EventConsumer con = new EventConsumer("all", ""); Event ev = con.pop(0);
see lua sample - http://wiki.freeswitch.org/wiki/Lua#freeswitch.EventConsumer
Phillip Jones-2 wrote:
Hi there,
mod_managed exposes EventReceivedFunction such that:
Session.EventReceivedFunction = (e) => { Log.WriteLine(LogLevel.Alert, "Received Event {0}",
e.ToString());
return ""; };
should trap all events to which i subscribe.
But how do I subscribe to events? What is the .NET / managed equivalent of:
switch_event_bind(const char *id, switch_event_types_t event, const char *subclass_name, switch_event_callback_t callback, void *user_data);
Thank you!
Yes! public class LoadDemo : ILoadNotificationPlugin { public bool Load() { Log.WriteLine(LogLevel.Notice, "LoadDemo running."); return true; } } this example is from Michael Giagnocavo's Demo.csx which you can find into the mod_managed svn. And let me add that works like a charm :) Ciao, Raffaele On Sun, Sep 6, 2009 at 22:50, Josh Rivers <josh@radianttiger.com> wrote:
Is there a way to start this when FreeSWITCH starts? The lua and perl modules have a 'startup-script' configuration preference. Is there something similar in mod_managed? Or is there a way to have an api command executed at a startup?
<quote author="Phillip Jones"> Exactly what I was after - thank you!
On Thu, Sep 3, 2009 at 1:54 PM, Jeff Lenk <jlenk@frontiernet.net> wrote:
try something like this
EventConsumer con = new EventConsumer("all", ""); Event ev = con.pop(0);
see lua sample - http://wiki.freeswitch.org/wiki/Lua#freeswitch.EventConsumer
Phillip Jones-2 wrote:
Hi there,
mod_managed exposes EventReceivedFunction such that:
Session.EventReceivedFunction = (e) => { Log.WriteLine(LogLevel.Alert, "Received Event {0}",
e.ToString());
return ""; };
should trap all events to which i subscribe.
But how do I subscribe to events? What is the .NET / managed equivalent of:
switch_event_bind(const char *id, switch_event_types_t event, const
char
*subclass_name, switch_event_callback_t callback, void *user_data);
Thank you!
_______________________________________________ FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org
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> wrote:
Yes! public class LoadDemo : ILoadNotificationPlugin { public bool Load() { Log.WriteLine(LogLevel.Notice, "LoadDemo running."); return true; } }
this example is from Michael Giagnocavo's Demo.csx which you can find into the mod_managed svn.
And let me add that works like a charm :)
Ciao, Raffaele
On Sun, Sep 6, 2009 at 22:50, Josh Rivers <josh@radianttiger.com> wrote:
Is there a way to start this when FreeSWITCH starts? The lua and perl modules have a 'startup-script' configuration preference. Is there something similar in mod_managed? Or is there a way to have an api command executed at a startup?
<quote author="Phillip Jones"> Exactly what I was after - thank you!
On Thu, Sep 3, 2009 at 1:54 PM, Jeff Lenk <jlenk@frontiernet.net> wrote:
try something like this
EventConsumer con = new EventConsumer("all", ""); Event ev = con.pop(0);
see lua sample - http://wiki.freeswitch.org/wiki/Lua#freeswitch.EventConsumer
Phillip Jones-2 wrote:
Hi there,
mod_managed exposes EventReceivedFunction such that:
Session.EventReceivedFunction = (e) => { Log.WriteLine(LogLevel.Alert, "Received Event {0}",
e.ToString());
return ""; };
should trap all events to which i subscribe.
But how do I subscribe to events? What is the .NET / managed
equivalent
of:
switch_event_bind(const char *id, switch_event_types_t event, const char *subclass_name, switch_event_callback_t callback, void *user_data);
Thank you!
_______________________________________________ FreeSWITCH-users mailing list FreeSWITCH-users@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
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 [mailto: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 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<mailto: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 :) Ciao, Raffaele On Sun, Sep 6, 2009 at 22:50, Josh Rivers <josh@radianttiger.com<mailto:josh@radianttiger.com>> wrote: Is there a way to start this when FreeSWITCH starts? The lua and perl modules have a 'startup-script' configuration preference. Is there something similar in mod_managed? Or is there a way to have an api command executed at a startup? <quote author="Phillip Jones"> Exactly what I was after - thank you! On Thu, Sep 3, 2009 at 1:54 PM, Jeff Lenk <jlenk@frontiernet.net<mailto:jlenk@frontiernet.net>> wrote:
try something like this
EventConsumer con = new EventConsumer("all", ""); Event ev = con.pop(0);
see lua sample - http://wiki.freeswitch.org/wiki/Lua#freeswitch.EventConsumer
Phillip Jones-2 wrote:
Hi there,
mod_managed exposes EventReceivedFunction such that:
Session.EventReceivedFunction = (e) => { Log.WriteLine(LogLevel.Alert, "Received Event {0}", e.ToString()); return ""; };
should trap all events to which i subscribe.
But how do I subscribe to events? What is the .NET / managed equivalent of:
switch_event_bind(const char *id, switch_event_types_t event, const char *subclass_name, switch_event_callback_t callback, void *user_data);
Thank you!
_______________________________________________ FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org<mailto: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<mailto: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
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:
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 [mailto: 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 *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> wrote:
Yes!
public class LoadDemo : ILoadNotificationPlugin {
public bool Load() {
Log.WriteLine(LogLevel.Notice, "LoadDemo running.");
return true;
}
}
this example is from Michael Giagnocavo's Demo.csx which you can find into the mod_managed svn.
And let me add that works like a charm :)
Ciao,
Raffaele
On Sun, Sep 6, 2009 at 22:50, Josh Rivers <josh@radianttiger.com> wrote:
Is there a way to start this when FreeSWITCH starts? The lua and perl modules have a 'startup-script' configuration preference. Is there something similar in mod_managed? Or is there a way to have an api command executed at a startup?
<quote author="Phillip Jones">
Exactly what I was after - thank you!
On Thu, Sep 3, 2009 at 1:54 PM, Jeff Lenk <jlenk@frontiernet.net> wrote:
try something like this
EventConsumer con = new EventConsumer("all", "");
Event ev = con.pop(0);
see lua sample -
http://wiki.freeswitch.org/wiki/Lua#freeswitch.EventConsumer
Phillip Jones-2 wrote:
Hi there,
mod_managed exposes EventReceivedFunction such that:
Session.EventReceivedFunction = (e) =>
{
Log.WriteLine(LogLevel.Alert, "Received Event {0}",
e.ToString());
return "";
};
should trap all events to which i subscribe.
But how do I subscribe to events? What is the .NET / managed equivalent
of:
switch_event_bind(const char *id, switch_event_types_t event, const char
*subclass_name, switch_event_callback_t callback, void *user_data);
Thank you!
_______________________________________________ FreeSWITCH-users mailing list FreeSWITCH-users@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
_______________________________________________ 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
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 On 8-Sep-09, at 10:30 PM, Josh Rivers wrote:
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> wrote: 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 [mailto: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 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
wrote:
Yes!
public class LoadDemo : ILoadNotificationPlugin {
public bool Load() {
Log.WriteLine(LogLevel.Notice, "LoadDemo running.");
return true;
}
}
this example is from Michael Giagnocavo's Demo.csx which you can find into the mod_managed svn.
And let me add that works like a charm :)
Ciao,
Raffaele
On Sun, Sep 6, 2009 at 22:50, Josh Rivers <josh@radianttiger.com> wrote:
Is there a way to start this when FreeSWITCH starts? The lua and perl modules have a 'startup-script' configuration preference. Is there something similar in mod_managed? Or is there a way to have an api command executed at a startup?
<quote author="Phillip Jones">
Exactly what I was after - thank you!
On Thu, Sep 3, 2009 at 1:54 PM, Jeff Lenk <jlenk@frontiernet.net> wrote:
try something like this
EventConsumer con = new EventConsumer("all", "");
Event ev = con.pop(0);
see lua sample -
http://wiki.freeswitch.org/wiki/Lua#freeswitch.EventConsumer
Phillip Jones-2 wrote:
Hi there,
mod_managed exposes EventReceivedFunction such that:
Session.EventReceivedFunction = (e) =>
{
Log.WriteLine(LogLevel.Alert, "Received Event {0}",
e.ToString());
return "";
};
should trap all events to which i subscribe.
But how do I subscribe to events? What is the .NET / managed equivalent
of:
switch_event_bind(const char *id, switch_event_types_t event, const char
*subclass_name, switch_event_callback_t callback, void *user_data);
Thank you!
_______________________________________________ FreeSWITCH-users mailing list FreeSWITCH-users@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
_______________________________________________ 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
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> wrote:
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
On 8-Sep-09, at 10:30 PM, Josh Rivers wrote:
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>wrote:
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 [mailto: 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 *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> wrote:
Yes!
public class LoadDemo : ILoadNotificationPlugin {
public bool Load() {
Log.WriteLine(LogLevel.Notice, "LoadDemo running.");
return true;
}
}
this example is from Michael Giagnocavo's Demo.csx which you can find into the mod_managed svn.
And let me add that works like a charm :)
Ciao,
Raffaele
On Sun, Sep 6, 2009 at 22:50, Josh Rivers <josh@radianttiger.com> wrote:
Is there a way to start this when FreeSWITCH starts? The lua and perl modules have a 'startup-script' configuration preference. Is there something similar in mod_managed? Or is there a way to have an api command executed at a startup?
<quote author="Phillip Jones">
Exactly what I was after - thank you!
On Thu, Sep 3, 2009 at 1:54 PM, Jeff Lenk <jlenk@frontiernet.net> wrote:
try something like this
EventConsumer con = new EventConsumer("all", "");
Event ev = con.pop(0);
see lua sample -
http://wiki.freeswitch.org/wiki/Lua#freeswitch.EventConsumer
Phillip Jones-2 wrote:
Hi there,
mod_managed exposes EventReceivedFunction such that:
Session.EventReceivedFunction = (e) =>
{
Log.WriteLine(LogLevel.Alert, "Received Event {0}",
e.ToString());
return "";
};
should trap all events to which i subscribe.
But how do I subscribe to events? What is the .NET / managed equivalent
of:
switch_event_bind(const char *id, switch_event_types_t event, const char
*subclass_name, switch_event_callback_t callback, void *user_data);
Thank you!
_______________________________________________ FreeSWITCH-users mailing list FreeSWITCH-users@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
_______________________________________________ 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
_______________________________________________ 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
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()
> 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> wrote:
> 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> wrote:
>
>> 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
>>
>>
>>
>>
>> On 8-Sep-09, at 10:30 PM, Josh Rivers wrote:
>>
>> 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>wrote:
>>
>>> 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 [mailto:
>>> 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
>>> *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> wrote:
>>>
>>> Yes!
>>>
>>>
>>> public class LoadDemo : ILoadNotificationPlugin {
>>>
>>> public bool Load() {
>>>
>>> Log.WriteLine(LogLevel.Notice, "LoadDemo running.");
>>>
>>> return true;
>>>
>>> }
>>>
>>> }
>>>
>>>
>>> this example is from Michael Giagnocavo's Demo.csx which you can find
>>> into the mod_managed svn.
>>>
>>>
>>> And let me add that works like a charm :)
>>>
>>>
>>> Ciao,
>>>
>>> Raffaele
>>>
>>>
>>> On Sun, Sep 6, 2009 at 22:50, Josh Rivers <josh@radianttiger.com> wrote:
>>>
>>> Is there a way to start this when FreeSWITCH starts? The lua and perl
>>> modules have a 'startup-script' configuration preference. Is there something
>>> similar in mod_managed? Or is there a way to have an api command executed at
>>> a startup?
>>>
>>>
>>> <quote author="Phillip Jones">
>>>
>>> Exactly what I was after - thank you!
>>>
>>>
>>> On Thu, Sep 3, 2009 at 1:54 PM, Jeff Lenk <jlenk@frontiernet.net> wrote:
>>>
>>>
>>> >
>>>
>>> > try something like this
>>>
>>> >
>>>
>>> > EventConsumer con = new EventConsumer("all", "");
>>>
>>> > Event ev = con.pop(0);
>>>
>>> >
>>>
>>> > see lua sample -
>>>
>>> > http://wiki.freeswitch.org/wiki/Lua#freeswitch.EventConsumer
>>>
>>> >
>>>
>>> >
>>>
>>> > Phillip Jones-2 wrote:
>>>
>>> > >
>>>
>>> > > Hi there,
>>>
>>> > >
>>>
>>> > > mod_managed exposes EventReceivedFunction such that:
>>>
>>> > >
>>>
>>> > > Session.EventReceivedFunction = (e) =>
>>>
>>> > > {
>>>
>>> > > Log.WriteLine(LogLevel.Alert, "Received Event {0}",
>>> e.ToString());
>>>
>>> > > return "";
>>>
>>> > > };
>>>
>>> > >
>>>
>>> > > should trap all events to which i subscribe.
>>>
>>> > >
>>>
>>> > >
>>>
>>> > > But how do I subscribe to events? What is the .NET / managed
>>> equivalent
>>>
>>> > > of:
>>>
>>> > >
>>>
>>> > > switch_event_bind(const char *id, switch_event_types_t event, const
>>> char
>>>
>>> > > *subclass_name, switch_event_callback_t callback, void *user_data);
>>>
>>> > >
>>>
>>> > >
>>>
>>> > >
>>>
>>> > > Thank you!
>>>
>>> > >
>>>
>>> > >
>>>
>>> > >
>>>
>>>
>>> _______________________________________________
>>> FreeSWITCH-users mailing list
>>> FreeSWITCH-users@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
>>>
>>>
>>> _______________________________________________
>>> 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
>>
>>
>>
>> _______________________________________________
>> 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
>>
>>
>
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:
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-tp3573619p361319... Sent from the freeswitch-users mailing list archive at Nabble.com.
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:
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:
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-tp3573619p361319... 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
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:
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:
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:
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-tp3573619p361319... 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-tp3573619p361484... Sent from the freeswitch-users mailing list archive at Nabble.com.
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> wrote:
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:
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:
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:
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-tp3573619p361319...
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-tp3573619p361484... 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
Looks like the event object goes straight to pinvokes, so a null result just crashes?
If it's null, you should get a NullReferenceException. The C# compiler should callvirt the property getter and that'll do a null check. If that isn't happening, that'd be an interesting optimization somewhere along the line. -Michael From: freeswitch-users-bounces@lists.freeswitch.org [mailto:freeswitch-users-bounces@lists.freeswitch.org] On Behalf Of Josh Rivers Sent: Wednesday, September 09, 2009 3:01 PM To: freeswitch-users@lists.freeswitch.org Subject: Re: [Freeswitch-users] Subscribing to events in managed C# / .NET 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<mailto:jlenk@frontiernet.net>> wrote: 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<mailto:mgg@giagnocavo.net>>wrote:
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-tp3573619p361319... Sent from the freeswitch-users mailing list archive at Nabble.com. _______________________________________________ FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org<mailto: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
I have a new thought on the crashes...I'm able to crash FreeSWITCH any time I like, just by having an exception in a thread. public class CrashFreeSWITCH : ILoadNotificationPlugin { public bool Load() { ThreadPool.QueueUserWorkItem((o) => { throw new NotImplementedException(); }); return true; } } Perhaps Application.ThreadException or AppDomain.UnhandledException need to be trapped? On Wed, Sep 9, 2009 at 4:51 PM, Michael Giagnocavo <mgg@giagnocavo.net>wrote:
Looks like the event object goes straight to pinvokes, so a null result just crashes?
If it’s null, you should get a NullReferenceException. The C# compiler should callvirt the property getter and that’ll do a null check. If that isn’t happening, that’d be an interesting optimization somewhere along the line.
-Michael
*From:* freeswitch-users-bounces@lists.freeswitch.org [mailto: freeswitch-users-bounces@lists.freeswitch.org] *On Behalf Of *Josh Rivers *Sent:* Wednesday, September 09, 2009 3:01 PM
*To:* freeswitch-users@lists.freeswitch.org *Subject:* Re: [Freeswitch-users] Subscribing to events in managed C# / .NET
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:
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:
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-tp3573619p361319... 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
That's by design. If a thread fails, and there's no handler, then the application could be in a corrupted state, so the CLR takes down the process. I think there is a .NET 1.0 compat switch you can enable in the config if you like exceptions to be silently ignored :). -Michael From: freeswitch-users-bounces@lists.freeswitch.org [mailto:freeswitch-users-bounces@lists.freeswitch.org] On Behalf Of Josh Rivers Sent: Wednesday, September 09, 2009 6:39 PM To: freeswitch-users@lists.freeswitch.org Subject: Re: [Freeswitch-users] Subscribing to events in managed C# / .NET I have a new thought on the crashes...I'm able to crash FreeSWITCH any time I like, just by having an exception in a thread. public class CrashFreeSWITCH : ILoadNotificationPlugin { public bool Load() { ThreadPool.QueueUserWorkItem((o) => { throw new NotImplementedException(); }); return true; } } Perhaps Application.ThreadException or AppDomain.UnhandledException need to be trapped? On Wed, Sep 9, 2009 at 4:51 PM, Michael Giagnocavo <mgg@giagnocavo.net<mailto:mgg@giagnocavo.net>> wrote:
Looks like the event object goes straight to pinvokes, so a null result just crashes?
If it's null, you should get a NullReferenceException. The C# compiler should callvirt the property getter and that'll do a null check. If that isn't happening, that'd be an interesting optimization somewhere along the line. -Michael From: freeswitch-users-bounces@lists.freeswitch.org<mailto:freeswitch-users-bounces@lists.freeswitch.org> [mailto:freeswitch-users-bounces@lists.freeswitch.org<mailto:freeswitch-users-bounces@lists.freeswitch.org>] On Behalf Of Josh Rivers Sent: Wednesday, September 09, 2009 3:01 PM To: freeswitch-users@lists.freeswitch.org<mailto:freeswitch-users@lists.freeswitch.org> Subject: Re: [Freeswitch-users] Subscribing to events in managed C# / .NET 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<mailto:jlenk@frontiernet.net>> wrote: 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<mailto:mgg@giagnocavo.net>>wrote:
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-tp3573619p361319... Sent from the freeswitch-users mailing list archive at Nabble.com. _______________________________________________ FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org<mailto: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<mailto: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
The question is whether the CLR should take down the whole phone server due to an unhandled exception...definitely the CLR should terminate...but shouldn't it just log the exception to the console, not crash the core? On Wed, Sep 9, 2009 at 6:30 PM, Michael Giagnocavo <mgg@giagnocavo.net>wrote:
That’s by design. If a thread fails, and there’s no handler, then the application could be in a corrupted state, so the CLR takes down the process.
I think there is a .NET 1.0 compat switch you can enable in the config if you like exceptions to be silently ignored J.
-Michael
*From:* freeswitch-users-bounces@lists.freeswitch.org [mailto: freeswitch-users-bounces@lists.freeswitch.org] *On Behalf Of *Josh Rivers *Sent:* Wednesday, September 09, 2009 6:39 PM
*To:* freeswitch-users@lists.freeswitch.org *Subject:* Re: [Freeswitch-users] Subscribing to events in managed C# / .NET
I have a new thought on the crashes...I'm able to crash FreeSWITCH any time I like, just by having an exception in a thread.
public class CrashFreeSWITCH : ILoadNotificationPlugin
{
public bool Load()
{
ThreadPool.QueueUserWorkItem((o) => { throw new NotImplementedException(); });
return true;
}
}
Perhaps Application.ThreadException or AppDomain.UnhandledException need to be trapped?
On Wed, Sep 9, 2009 at 4:51 PM, Michael Giagnocavo <mgg@giagnocavo.net> wrote:
Looks like the event object goes straight to pinvokes, so a null result just crashes?
If it’s null, you should get a NullReferenceException. The C# compiler should callvirt the property getter and that’ll do a null check. If that isn’t happening, that’d be an interesting optimization somewhere along the line.
-Michael
*From:* freeswitch-users-bounces@lists.freeswitch.org [mailto: freeswitch-users-bounces@lists.freeswitch.org] *On Behalf Of *Josh Rivers *Sent:* Wednesday, September 09, 2009 3:01 PM
*To:* freeswitch-users@lists.freeswitch.org
*Subject:* Re: [Freeswitch-users] Subscribing to events in managed C# / .NET
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:
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:
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-tp3573619p361319... 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
_______________________________________________ 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
Well, a segfault in voicemail would do the same thing. Suppose your plugin runs a thread that does something important, like billing or so on. That thread fails - do you really want it to go on? Anyways, the solution is simple enough, handle your exceptions :). Every plugin can decide what it wants to do here. -Michael From: freeswitch-users-bounces@lists.freeswitch.org [mailto:freeswitch-users-bounces@lists.freeswitch.org] On Behalf Of Josh Rivers Sent: Wednesday, September 09, 2009 10:41 PM To: freeswitch-users@lists.freeswitch.org Subject: Re: [Freeswitch-users] Subscribing to events in managed C# / .NET The question is whether the CLR should take down the whole phone server due to an unhandled exception...definitely the CLR should terminate...but shouldn't it just log the exception to the console, not crash the core? On Wed, Sep 9, 2009 at 6:30 PM, Michael Giagnocavo <mgg@giagnocavo.net<mailto:mgg@giagnocavo.net>> wrote: That's by design. If a thread fails, and there's no handler, then the application could be in a corrupted state, so the CLR takes down the process. I think there is a .NET 1.0 compat switch you can enable in the config if you like exceptions to be silently ignored :). -Michael From: freeswitch-users-bounces@lists.freeswitch.org<mailto:freeswitch-users-bounces@lists.freeswitch.org> [mailto:freeswitch-users-bounces@lists.freeswitch.org<mailto:freeswitch-users-bounces@lists.freeswitch.org>] On Behalf Of Josh Rivers Sent: Wednesday, September 09, 2009 6:39 PM To: freeswitch-users@lists.freeswitch.org<mailto:freeswitch-users@lists.freeswitch.org> Subject: Re: [Freeswitch-users] Subscribing to events in managed C# / .NET I have a new thought on the crashes...I'm able to crash FreeSWITCH any time I like, just by having an exception in a thread. public class CrashFreeSWITCH : ILoadNotificationPlugin { public bool Load() { ThreadPool.QueueUserWorkItem((o) => { throw new NotImplementedException(); }); return true; } } Perhaps Application.ThreadException or AppDomain.UnhandledException need to be trapped? On Wed, Sep 9, 2009 at 4:51 PM, Michael Giagnocavo <mgg@giagnocavo.net<mailto:mgg@giagnocavo.net>> wrote:
Looks like the event object goes straight to pinvokes, so a null result just crashes?
If it's null, you should get a NullReferenceException. The C# compiler should callvirt the property getter and that'll do a null check. If that isn't happening, that'd be an interesting optimization somewhere along the line. -Michael From: freeswitch-users-bounces@lists.freeswitch.org<mailto:freeswitch-users-bounces@lists.freeswitch.org> [mailto:freeswitch-users-bounces@lists.freeswitch.org<mailto:freeswitch-users-bounces@lists.freeswitch.org>] On Behalf Of Josh Rivers Sent: Wednesday, September 09, 2009 3:01 PM To: freeswitch-users@lists.freeswitch.org<mailto:freeswitch-users@lists.freeswitch.org> Subject: Re: [Freeswitch-users] Subscribing to events in managed C# / .NET 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<mailto:jlenk@frontiernet.net>> wrote: 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<mailto:mgg@giagnocavo.net>>wrote:
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-tp3573619p361319... Sent from the freeswitch-users mailing list archive at Nabble.com. _______________________________________________ FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org<mailto: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<mailto: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<mailto: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
I'm only concerned with the difference in treatment. public class CrashFreeSWITCH : ILoadNotificationPlugin { public bool Load() { ThreadPool.QueueUserWorkItem((o) => { throw new NotImplementedException(); }); return true; } } Crashes the entire switch, terminating all calls and disconnecting from the PSTN. public class CrashFreeSWITCH : ILoadNotificationPlugin { public bool Load() { throw new NotImplementedException(); return true; } } Logs a message to the console and doesn't load the module, while leaving the switch operating. In my experience, exceptions in multi-threaded code: a) happen, b) are hard to diagnose. Is the best behavior for the environment to crash, providing no diagnostic information? That's hard in development, and even harder in production. I suppose 'terminate switch on fault' should be an option, to allow the operating system to restart the whole process on fault conditions, but if that is the intended result, shouldn't any fault do the same thing? What if the billing was happening in my second code block? Normally, I'd trap the ThreadException and UnhandledExceptions in my application, so that my code could choose the correct actions to perform should the application get into an unknown state. This can include terminating the whole application, but also logging diagnostic information, trying to save uncommitted data, and sending notifications of the failure. Is 'crash if it's a thread, but not if it's not' good because it's the way the module works now, or is it a better design for a reason I'm not understanding? On Wed, Sep 9, 2009 at 11:09 PM, Michael Giagnocavo <mgg@giagnocavo.net>wrote:
Well, a segfault in voicemail would do the same thing.
Suppose your plugin runs a thread that does something important, like billing or so on. That thread fails – do you really want it to go on?
Anyways, the solution is simple enough, handle your exceptions J. Every plugin can decide what it wants to do here.
-Michael
*From:* freeswitch-users-bounces@lists.freeswitch.org [mailto: freeswitch-users-bounces@lists.freeswitch.org] *On Behalf Of *Josh Rivers *Sent:* Wednesday, September 09, 2009 10:41 PM
*To:* freeswitch-users@lists.freeswitch.org *Subject:* Re: [Freeswitch-users] Subscribing to events in managed C# / .NET
The question is whether the CLR should take down the whole phone server due to an unhandled exception...definitely the CLR should terminate...but shouldn't it just log the exception to the console, not crash the core?
On Wed, Sep 9, 2009 at 6:30 PM, Michael Giagnocavo <mgg@giagnocavo.net> wrote:
That’s by design. If a thread fails, and there’s no handler, then the application could be in a corrupted state, so the CLR takes down the process.
I think there is a .NET 1.0 compat switch you can enable in the config if you like exceptions to be silently ignored J.
-Michael
*From:* freeswitch-users-bounces@lists.freeswitch.org [mailto: freeswitch-users-bounces@lists.freeswitch.org] *On Behalf Of *Josh Rivers *Sent:* Wednesday, September 09, 2009 6:39 PM
*To:* freeswitch-users@lists.freeswitch.org *Subject:* Re: [Freeswitch-users] Subscribing to events in managed C# / .NET
I have a new thought on the crashes...I'm able to crash FreeSWITCH any time I like, just by having an exception in a thread.
public class CrashFreeSWITCH : ILoadNotificationPlugin
{
public bool Load()
{
ThreadPool.QueueUserWorkItem((o) => { throw new NotImplementedException(); });
return true;
}
}
Perhaps Application.ThreadException or AppDomain.UnhandledException need to be trapped?
On Wed, Sep 9, 2009 at 4:51 PM, Michael Giagnocavo <mgg@giagnocavo.net> wrote:
Looks like the event object goes straight to pinvokes, so a null result just crashes?
If it’s null, you should get a NullReferenceException. The C# compiler should callvirt the property getter and that’ll do a null check. If that isn’t happening, that’d be an interesting optimization somewhere along the line.
-Michael
*From:* freeswitch-users-bounces@lists.freeswitch.org [mailto: freeswitch-users-bounces@lists.freeswitch.org] *On Behalf Of *Josh Rivers *Sent:* Wednesday, September 09, 2009 3:01 PM
*To:* freeswitch-users@lists.freeswitch.org
*Subject:* Re: [Freeswitch-users] Subscribing to events in managed C# / .NET
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:
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:
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-tp3573619p361319... 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
_______________________________________________ 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
Well, we have absolutely no idea what the background thread is doing. It might be critical, and the fix is trivial: put a try/catch on it. This is the model all .NET applications have. Background threads doing bad things should always take down the process. However, that's a good point about Load() failing. The approach taken is more or less how FreeSWITCH handles things in general now. If a module has an error, the switch just logs and goes on. I'm not really in favour of this, and suggested at least a "required" attribute in the modules.conf that would prevent the switch from loading if the module fails. The fix is probably to create an attribute you can apply to the plugin classes that indicate what kind of failure handling you want. For the assembly, we'd add an attribute with an enumeration like: - Default (scan, call ILoadNotificationPlugin, log errors if they occur) - NoLoad (don't load the assembly) - Critical (stop the switch if there's an exception during loading) That'd provide the control you want for loading. We could do something similar for App/Api plugins. I want to move ILoadNotificationPlugin from being this "catch all" thing that controls the entire assembly to something that can be used to fire up code; effectively "OnLoad" and "OnUnload". To dynamically control loading, we'll probably reflect on the individual plugins looking for attributes or perhaps some sort of static load function. How's that sound? From: freeswitch-users-bounces@lists.freeswitch.org [mailto:freeswitch-users-bounces@lists.freeswitch.org] On Behalf Of Josh Rivers Sent: Thursday, September 10, 2009 12:48 PM To: freeswitch-users@lists.freeswitch.org Subject: Re: [Freeswitch-users] Subscribing to events in managed C# / .NET I'm only concerned with the difference in treatment. public class CrashFreeSWITCH : ILoadNotificationPlugin { public bool Load() { ThreadPool.QueueUserWorkItem((o) => { throw new NotImplementedException(); }); return true; } } Crashes the entire switch, terminating all calls and disconnecting from the PSTN. public class CrashFreeSWITCH : ILoadNotificationPlugin { public bool Load() { throw new NotImplementedException(); return true; } } Logs a message to the console and doesn't load the module, while leaving the switch operating. In my experience, exceptions in multi-threaded code: a) happen, b) are hard to diagnose. Is the best behavior for the environment to crash, providing no diagnostic information? That's hard in development, and even harder in production. I suppose 'terminate switch on fault' should be an option, to allow the operating system to restart the whole process on fault conditions, but if that is the intended result, shouldn't any fault do the same thing? What if the billing was happening in my second code block? Normally, I'd trap the ThreadException and UnhandledExceptions in my application, so that my code could choose the correct actions to perform should the application get into an unknown state. This can include terminating the whole application, but also logging diagnostic information, trying to save uncommitted data, and sending notifications of the failure. Is 'crash if it's a thread, but not if it's not' good because it's the way the module works now, or is it a better design for a reason I'm not understanding? On Wed, Sep 9, 2009 at 11:09 PM, Michael Giagnocavo <mgg@giagnocavo.net<mailto:mgg@giagnocavo.net>> wrote: Well, a segfault in voicemail would do the same thing. Suppose your plugin runs a thread that does something important, like billing or so on. That thread fails - do you really want it to go on? Anyways, the solution is simple enough, handle your exceptions :). Every plugin can decide what it wants to do here. -Michael From: freeswitch-users-bounces@lists.freeswitch.org<mailto:freeswitch-users-bounces@lists.freeswitch.org> [mailto:freeswitch-users-bounces@lists.freeswitch.org<mailto:freeswitch-users-bounces@lists.freeswitch.org>] On Behalf Of Josh Rivers Sent: Wednesday, September 09, 2009 10:41 PM To: freeswitch-users@lists.freeswitch.org<mailto:freeswitch-users@lists.freeswitch.org> Subject: Re: [Freeswitch-users] Subscribing to events in managed C# / .NET The question is whether the CLR should take down the whole phone server due to an unhandled exception...definitely the CLR should terminate...but shouldn't it just log the exception to the console, not crash the core? On Wed, Sep 9, 2009 at 6:30 PM, Michael Giagnocavo <mgg@giagnocavo.net<mailto:mgg@giagnocavo.net>> wrote: That's by design. If a thread fails, and there's no handler, then the application could be in a corrupted state, so the CLR takes down the process. I think there is a .NET 1.0 compat switch you can enable in the config if you like exceptions to be silently ignored :). -Michael From: freeswitch-users-bounces@lists.freeswitch.org<mailto:freeswitch-users-bounces@lists.freeswitch.org> [mailto:freeswitch-users-bounces@lists.freeswitch.org<mailto:freeswitch-users-bounces@lists.freeswitch.org>] On Behalf Of Josh Rivers Sent: Wednesday, September 09, 2009 6:39 PM To: freeswitch-users@lists.freeswitch.org<mailto:freeswitch-users@lists.freeswitch.org> Subject: Re: [Freeswitch-users] Subscribing to events in managed C# / .NET I have a new thought on the crashes...I'm able to crash FreeSWITCH any time I like, just by having an exception in a thread. public class CrashFreeSWITCH : ILoadNotificationPlugin { public bool Load() { ThreadPool.QueueUserWorkItem((o) => { throw new NotImplementedException(); }); return true; } } Perhaps Application.ThreadException or AppDomain.UnhandledException need to be trapped? On Wed, Sep 9, 2009 at 4:51 PM, Michael Giagnocavo <mgg@giagnocavo.net<mailto:mgg@giagnocavo.net>> wrote:
Looks like the event object goes straight to pinvokes, so a null result just crashes?
If it's null, you should get a NullReferenceException. The C# compiler should callvirt the property getter and that'll do a null check. If that isn't happening, that'd be an interesting optimization somewhere along the line. -Michael From: freeswitch-users-bounces@lists.freeswitch.org<mailto:freeswitch-users-bounces@lists.freeswitch.org> [mailto:freeswitch-users-bounces@lists.freeswitch.org<mailto:freeswitch-users-bounces@lists.freeswitch.org>] On Behalf Of Josh Rivers Sent: Wednesday, September 09, 2009 3:01 PM To: freeswitch-users@lists.freeswitch.org<mailto:freeswitch-users@lists.freeswitch.org> Subject: Re: [Freeswitch-users] Subscribing to events in managed C# / .NET 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<mailto:jlenk@frontiernet.net>> wrote: 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<mailto:mgg@giagnocavo.net>>wrote:
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-tp3573619p361319... Sent from the freeswitch-users mailing list archive at Nabble.com. _______________________________________________ FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org<mailto: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<mailto: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<mailto: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<mailto: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
*I want to move ILoadNotificationPlugin from being this “catch all” thing that controls the entire assembly to something that can be used to fire up code; effectively “OnLoad” and “OnUnload”. To dynamically control loading, we’ll probably reflect on the individual plugins looking for attributes or perhaps some sort of static load function.* I meant to do something like that probably using spring to inject method names to be invoked. Also event listening (wich is I believe a generic need) could be managed this way and benefit from some abstraction. con.pop(1) is probably the most frequently written line by every plugin developer, probably some abstraction (an event started with his thread and the fs event passed as an argument?) could make code more elegant On Fri, Sep 11, 2009 at 00:19, Michael Giagnocavo <mgg@giagnocavo.net>wrote:
Well, we have absolutely no idea what the background thread is doing. It might be critical, and the fix is trivial: put a try/catch on it. This is the model all .NET applications have. Background threads doing bad things should always take down the process.
However, that’s a good point about Load() failing. The approach taken is more or less how FreeSWITCH handles things in general now. If a module has an error, the switch just logs and goes on. I’m not really in favour of this, and suggested at least a “required” attribute in the modules.conf that would prevent the switch from loading if the module fails.
The fix is probably to create an attribute you can apply to the plugin classes that indicate what kind of failure handling you want. For the assembly, we’d add an attribute with an enumeration like:
- Default (scan, call ILoadNotificationPlugin, log errors if they occur)
- NoLoad (don’t load the assembly)
- Critical (stop the switch if there’s an exception during loading)
That’d provide the control you want for loading. We could do something similar for App/Api plugins.
I want to move ILoadNotificationPlugin from being this “catch all” thing that controls the entire assembly to something that can be used to fire up code; effectively “OnLoad” and “OnUnload”. To dynamically control loading, we’ll probably reflect on the individual plugins looking for attributes or perhaps some sort of static load function.
How’s that sound?
*From:* freeswitch-users-bounces@lists.freeswitch.org [mailto: freeswitch-users-bounces@lists.freeswitch.org] *On Behalf Of *Josh Rivers *Sent:* Thursday, September 10, 2009 12:48 PM
*To:* freeswitch-users@lists.freeswitch.org *Subject:* Re: [Freeswitch-users] Subscribing to events in managed C# / .NET
I'm only concerned with the difference in treatment.
public class CrashFreeSWITCH : ILoadNotificationPlugin { public bool Load() { ThreadPool.QueueUserWorkItem((o) => { throw new NotImplementedException(); }); return true; } }
Crashes the entire switch, terminating all calls and disconnecting from the PSTN.
public class CrashFreeSWITCH : ILoadNotificationPlugin { public bool Load() { throw new NotImplementedException(); return true; } }
Logs a message to the console and doesn't load the module, while leaving the switch operating.
In my experience, exceptions in multi-threaded code: a) happen, b) are hard to diagnose. Is the best behavior for the environment to crash, providing no diagnostic information? That's hard in development, and even harder in production. I suppose 'terminate switch on fault' should be an option, to allow the operating system to restart the whole process on fault conditions, but if that is the intended result, shouldn't any fault do the same thing? What if the billing was happening in my second code block?
Normally, I'd trap the ThreadException and UnhandledExceptions in my application, so that my code could choose the correct actions to perform should the application get into an unknown state. This can include terminating the whole application, but also logging diagnostic information, trying to save uncommitted data, and sending notifications of the failure.
Is 'crash if it's a thread, but not if it's not' good because it's the way the module works now, or is it a better design for a reason I'm not understanding?
On Wed, Sep 9, 2009 at 11:09 PM, Michael Giagnocavo <mgg@giagnocavo.net> wrote:
Well, a segfault in voicemail would do the same thing.
Suppose your plugin runs a thread that does something important, like billing or so on. That thread fails – do you really want it to go on?
Anyways, the solution is simple enough, handle your exceptions J. Every plugin can decide what it wants to do here.
-Michael
*From:* freeswitch-users-bounces@lists.freeswitch.org [mailto: freeswitch-users-bounces@lists.freeswitch.org] *On Behalf Of *Josh Rivers *Sent:* Wednesday, September 09, 2009 10:41 PM
*To:* freeswitch-users@lists.freeswitch.org *Subject:* Re: [Freeswitch-users] Subscribing to events in managed C# / .NET
The question is whether the CLR should take down the whole phone server due to an unhandled exception...definitely the CLR should terminate...but shouldn't it just log the exception to the console, not crash the core?
On Wed, Sep 9, 2009 at 6:30 PM, Michael Giagnocavo <mgg@giagnocavo.net> wrote:
That’s by design. If a thread fails, and there’s no handler, then the application could be in a corrupted state, so the CLR takes down the process.
I think there is a .NET 1.0 compat switch you can enable in the config if you like exceptions to be silently ignored J.
-Michael
*From:* freeswitch-users-bounces@lists.freeswitch.org [mailto: freeswitch-users-bounces@lists.freeswitch.org] *On Behalf Of *Josh Rivers *Sent:* Wednesday, September 09, 2009 6:39 PM
*To:* freeswitch-users@lists.freeswitch.org *Subject:* Re: [Freeswitch-users] Subscribing to events in managed C# / .NET
I have a new thought on the crashes...I'm able to crash FreeSWITCH any time I like, just by having an exception in a thread.
public class CrashFreeSWITCH : ILoadNotificationPlugin
{
public bool Load()
{
ThreadPool.QueueUserWorkItem((o) => { throw new NotImplementedException(); });
return true;
}
}
Perhaps Application.ThreadException or AppDomain.UnhandledException need to be trapped?
On Wed, Sep 9, 2009 at 4:51 PM, Michael Giagnocavo <mgg@giagnocavo.net> wrote:
Looks like the event object goes straight to pinvokes, so a null result just crashes?
If it’s null, you should get a NullReferenceException. The C# compiler should callvirt the property getter and that’ll do a null check. If that isn’t happening, that’d be an interesting optimization somewhere along the line.
-Michael
*From:* freeswitch-users-bounces@lists.freeswitch.org [mailto: freeswitch-users-bounces@lists.freeswitch.org] *On Behalf Of *Josh Rivers *Sent:* Wednesday, September 09, 2009 3:01 PM
*To:* freeswitch-users@lists.freeswitch.org
*Subject:* Re: [Freeswitch-users] Subscribing to events in managed C# / .NET
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:
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:
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-tp3573619p361319... 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
_______________________________________________ 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
_______________________________________________ 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
I've been having the same idea, except completely different. I'd probably start with StructureMap or MEF. I'm attracted to the idea of creating an alternative to mod_event_socket except using WCF as the transport, enabling both WS-* and Rest access into the FreeSWITCH core. I think an effort to create a better archtecture in mod_managed is likely to get very religious very quickly. There's a _lot_ of difference of opinion in the .NET ecosystem. Just witness Michael and I disagreeing on something as simple as how to handle unhandled exceptions. Instead of architecting a more complete solution, I think a good solution might be to de-architect the current solution to easily enable extensibility and component replacement. That way, each of us can have the high-level framework we want without disagreement on the low-level framework. This is the same model used in ASP.NET MVC, where it works well out of the box, but you can easily hook in and replace any chunk of it you want if your needs vary. I started playing with a refactoring of the current managed.dll in order to make it more pluggable. It kinda got away from me....<grin>....I've published my code up on github at http://github.com/joshrivers/FreeSWITCH.Managed The first thing I did was make it _really_ easy to make your own managed.dll. There's two basic points where managed code attaches to unmanaged code. If you rewrite the loader class, you can make your own managed.dll that does anything you want. The next layer up exposes a simple IOC registry that could be modified to replace or add to the logging chain, the module loading chain, or the command execution chain. Beyond that, appdomain loading, script compilation, and inside-appdomain plugin loading are all plugabble. Current plugins should all remain compatible (mine at least haven't needed a recompile). What needs to be done: - There are a few changes in SVN that need to be integrated with my fork. - A lot more unit testing would be useful. - There should be a mechanism for indicating that a script or dll should be pre-loaded into all other appdomains (as a mechanism for defining new plugin types). - There should also be a mechanism for loading a script or dll into the primary appdomain (to allow your code to modify the core operation of mod_managed without recompiling the dll) Most of this should be simple, but I thought it was high time that I got some feedback. I think this model makes it possible to much more simply add new functionality to mod_managed allowing coders to establish their own plugin models and use frameworks such as StructureMap, Spring.NET, MEF, WCF, or Workflow to create their voip applications. Let me know what you think, Josh On Fri, Sep 11, 2009 at 12:55 AM, Raffaele P. Guidi < raffaele.p.guidi@gmail.com> wrote:
*I want to move ILoadNotificationPlugin from being this “catch all” thing that controls the entire assembly to something that can be used to fire up code; effectively “OnLoad” and “OnUnload”. To dynamically control loading, we’ll probably reflect on the individual plugins looking for attributes or perhaps some sort of static load function.* I meant to do something like that probably using spring to inject method names to be invoked. Also event listening (wich is I believe a generic need) could be managed this way and benefit from some abstraction. con.pop(1) is probably the most frequently written line by every plugin developer, probably some abstraction (an event started with his thread and the fs event passed as an argument?) could make code more elegant
On Fri, Sep 11, 2009 at 00:19, Michael Giagnocavo <mgg@giagnocavo.net>wrote:
Well, we have absolutely no idea what the background thread is doing. It might be critical, and the fix is trivial: put a try/catch on it. This is the model all .NET applications have. Background threads doing bad things should always take down the process.
However, that’s a good point about Load() failing. The approach taken is more or less how FreeSWITCH handles things in general now. If a module has an error, the switch just logs and goes on. I’m not really in favour of this, and suggested at least a “required” attribute in the modules.conf that would prevent the switch from loading if the module fails.
The fix is probably to create an attribute you can apply to the plugin classes that indicate what kind of failure handling you want. For the assembly, we’d add an attribute with an enumeration like:
- Default (scan, call ILoadNotificationPlugin, log errors if they occur)
- NoLoad (don’t load the assembly)
- Critical (stop the switch if there’s an exception during loading)
That’d provide the control you want for loading. We could do something similar for App/Api plugins.
I want to move ILoadNotificationPlugin from being this “catch all” thing that controls the entire assembly to something that can be used to fire up code; effectively “OnLoad” and “OnUnload”. To dynamically control loading, we’ll probably reflect on the individual plugins looking for attributes or perhaps some sort of static load function.
How’s that sound?
*From:* freeswitch-users-bounces@lists.freeswitch.org [mailto: freeswitch-users-bounces@lists.freeswitch.org] *On Behalf Of *Josh Rivers *Sent:* Thursday, September 10, 2009 12:48 PM
*To:* freeswitch-users@lists.freeswitch.org *Subject:* Re: [Freeswitch-users] Subscribing to events in managed C# / .NET
I'm only concerned with the difference in treatment.
public class CrashFreeSWITCH : ILoadNotificationPlugin { public bool Load() { ThreadPool.QueueUserWorkItem((o) => { throw new NotImplementedException(); }); return true; } }
Crashes the entire switch, terminating all calls and disconnecting from the PSTN.
public class CrashFreeSWITCH : ILoadNotificationPlugin { public bool Load() { throw new NotImplementedException(); return true; } }
Logs a message to the console and doesn't load the module, while leaving the switch operating.
In my experience, exceptions in multi-threaded code: a) happen, b) are hard to diagnose. Is the best behavior for the environment to crash, providing no diagnostic information? That's hard in development, and even harder in production. I suppose 'terminate switch on fault' should be an option, to allow the operating system to restart the whole process on fault conditions, but if that is the intended result, shouldn't any fault do the same thing? What if the billing was happening in my second code block?
Normally, I'd trap the ThreadException and UnhandledExceptions in my application, so that my code could choose the correct actions to perform should the application get into an unknown state. This can include terminating the whole application, but also logging diagnostic information, trying to save uncommitted data, and sending notifications of the failure.
Is 'crash if it's a thread, but not if it's not' good because it's the way the module works now, or is it a better design for a reason I'm not understanding?
On Wed, Sep 9, 2009 at 11:09 PM, Michael Giagnocavo <mgg@giagnocavo.net> wrote:
Well, a segfault in voicemail would do the same thing.
Suppose your plugin runs a thread that does something important, like billing or so on. That thread fails – do you really want it to go on?
Anyways, the solution is simple enough, handle your exceptions J. Every plugin can decide what it wants to do here.
-Michael
*From:* freeswitch-users-bounces@lists.freeswitch.org [mailto: freeswitch-users-bounces@lists.freeswitch.org] *On Behalf Of *Josh Rivers *Sent:* Wednesday, September 09, 2009 10:41 PM
*To:* freeswitch-users@lists.freeswitch.org *Subject:* Re: [Freeswitch-users] Subscribing to events in managed C# / .NET
The question is whether the CLR should take down the whole phone server due to an unhandled exception...definitely the CLR should terminate...but shouldn't it just log the exception to the console, not crash the core?
On Wed, Sep 9, 2009 at 6:30 PM, Michael Giagnocavo <mgg@giagnocavo.net> wrote:
That’s by design. If a thread fails, and there’s no handler, then the application could be in a corrupted state, so the CLR takes down the process.
I think there is a .NET 1.0 compat switch you can enable in the config if you like exceptions to be silently ignored J.
-Michael
*From:* freeswitch-users-bounces@lists.freeswitch.org [mailto: freeswitch-users-bounces@lists.freeswitch.org] *On Behalf Of *Josh Rivers *Sent:* Wednesday, September 09, 2009 6:39 PM
*To:* freeswitch-users@lists.freeswitch.org *Subject:* Re: [Freeswitch-users] Subscribing to events in managed C# / .NET
I have a new thought on the crashes...I'm able to crash FreeSWITCH any time I like, just by having an exception in a thread.
public class CrashFreeSWITCH : ILoadNotificationPlugin
{
public bool Load()
{
ThreadPool.QueueUserWorkItem((o) => { throw new NotImplementedException(); });
return true;
}
}
Perhaps Application.ThreadException or AppDomain.UnhandledException need to be trapped?
On Wed, Sep 9, 2009 at 4:51 PM, Michael Giagnocavo <mgg@giagnocavo.net> wrote:
Looks like the event object goes straight to pinvokes, so a null result just crashes?
If it’s null, you should get a NullReferenceException. The C# compiler should callvirt the property getter and that’ll do a null check. If that isn’t happening, that’d be an interesting optimization somewhere along the line.
-Michael
*From:* freeswitch-users-bounces@lists.freeswitch.org [mailto: freeswitch-users-bounces@lists.freeswitch.org] *On Behalf Of *Josh Rivers *Sent:* Wednesday, September 09, 2009 3:01 PM
*To:* freeswitch-users@lists.freeswitch.org
*Subject:* Re: [Freeswitch-users] Subscribing to events in managed C# / .NET
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:
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:
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-tp3573619p361319... 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
_______________________________________________ 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
_______________________________________________ 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
Hey nice to see someone interested in this - that's a lot of files you have there, and looks like you put a lot of effort into it! I haven't had time to look at it much, but here are a few initial impressions. Right off the bat: there can be tons of cleanup and refactoring, no doubt about that. Much of the current code is to satisfy my needs in production, which it does very well. With that out of the way... I'm a bit hesitant to go too far from the FreeSWITCH core as far as architecture goes. For instance, I'm not quite sure why'd we have our own managed logging subsystem that allows them to plug in other things that aren't part of FS. Either they should use the FS logging system, or use their own such as log4net. Or perhaps I don't see why we'd want this behavior. Going away from the core as far as adding .NET specific features (like look at the static ManagedSession.Originate that takes hangup delegates, or the "nice" wrapper for Log (Write and WeiteLine, with an enum instead of a string) are keeping close to the core, just adding a tiny bit of API cleanup. FreeSWITCH exposes a lot of strings, and while maybe that's important for some languages, .NET users are going to expect stronger typing. But I don't think these types of things get people away from FreeSWITCH much. Things like making a published SOAP interface for FS seem not really related to mod_managed. They can easily be done as 3rd party plugins, or convince the core FS team that exposing via SOAP via mod_managed is the way to go. Also keep in mind that the majority of users are on Linux, so that rules out WCF and some other fun stuff that only works on the CLR - I'd say it all has to work on Mono. As for all the rest of it, can we talk interactively, perhaps with other users interested in mod_managed? Reading over your email, I think I'm not understanding many of the use cases that are being fixed. Thanks a lot! -Michael From: freeswitch-users-bounces@lists.freeswitch.org [mailto:freeswitch-users-bounces@lists.freeswitch.org] On Behalf Of Josh Rivers Sent: Wednesday, September 23, 2009 5:00 PM To: freeswitch-users@lists.freeswitch.org Subject: Re: [Freeswitch-users] Subscribing to events in managed C# / .NET I've been having the same idea, except completely different. I'd probably start with StructureMap or MEF. I'm attracted to the idea of creating an alternative to mod_event_socket except using WCF as the transport, enabling both WS-* and Rest access into the FreeSWITCH core. I think an effort to create a better archtecture in mod_managed is likely to get very religious very quickly. There's a _lot_ of difference of opinion in the .NET ecosystem. Just witness Michael and I disagreeing on something as simple as how to handle unhandled exceptions. Instead of architecting a more complete solution, I think a good solution might be to de-architect the current solution to easily enable extensibility and component replacement. That way, each of us can have the high-level framework we want without disagreement on the low-level framework. This is the same model used in ASP.NET<http://ASP.NET> MVC, where it works well out of the box, but you can easily hook in and replace any chunk of it you want if your needs vary. I started playing with a refactoring of the current managed.dll in order to make it more pluggable. It kinda got away from me....<grin>....I've published my code up on github at http://github.com/joshrivers/FreeSWITCH.Managed The first thing I did was make it _really_ easy to make your own managed.dll. There's two basic points where managed code attaches to unmanaged code. If you rewrite the loader class, you can make your own managed.dll that does anything you want. The next layer up exposes a simple IOC registry that could be modified to replace or add to the logging chain, the module loading chain, or the command execution chain. Beyond that, appdomain loading, script compilation, and inside-appdomain plugin loading are all plugabble. Current plugins should all remain compatible (mine at least haven't needed a recompile). What needs to be done: - There are a few changes in SVN that need to be integrated with my fork. - A lot more unit testing would be useful. - There should be a mechanism for indicating that a script or dll should be pre-loaded into all other appdomains (as a mechanism for defining new plugin types). - There should also be a mechanism for loading a script or dll into the primary appdomain (to allow your code to modify the core operation of mod_managed without recompiling the dll) Most of this should be simple, but I thought it was high time that I got some feedback. I think this model makes it possible to much more simply add new functionality to mod_managed allowing coders to establish their own plugin models and use frameworks such as StructureMap, Spring.NET, MEF, WCF, or Workflow to create their voip applications. Let me know what you think, Josh On Fri, Sep 11, 2009 at 12:55 AM, Raffaele P. Guidi <raffaele.p.guidi@gmail.com<mailto:raffaele.p.guidi@gmail.com>> wrote: I want to move ILoadNotificationPlugin from being this "catch all" thing that controls the entire assembly to something that can be used to fire up code; effectively "OnLoad" and "OnUnload". To dynamically control loading, we'll probably reflect on the individual plugins looking for attributes or perhaps some sort of static load function. I meant to do something like that probably using spring to inject method names to be invoked. Also event listening (wich is I believe a generic need) could be managed this way and benefit from some abstraction. con.pop(1) is probably the most frequently written line by every plugin developer, probably some abstraction (an event started with his thread and the fs event passed as an argument?) could make code more elegant On Fri, Sep 11, 2009 at 00:19, Michael Giagnocavo <mgg@giagnocavo.net<mailto:mgg@giagnocavo.net>> wrote: Well, we have absolutely no idea what the background thread is doing. It might be critical, and the fix is trivial: put a try/catch on it. This is the model all .NET applications have. Background threads doing bad things should always take down the process. However, that's a good point about Load() failing. The approach taken is more or less how FreeSWITCH handles things in general now. If a module has an error, the switch just logs and goes on. I'm not really in favour of this, and suggested at least a "required" attribute in the modules.conf that would prevent the switch from loading if the module fails. The fix is probably to create an attribute you can apply to the plugin classes that indicate what kind of failure handling you want. For the assembly, we'd add an attribute with an enumeration like: - Default (scan, call ILoadNotificationPlugin, log errors if they occur) - NoLoad (don't load the assembly) - Critical (stop the switch if there's an exception during loading) That'd provide the control you want for loading. We could do something similar for App/Api plugins. I want to move ILoadNotificationPlugin from being this "catch all" thing that controls the entire assembly to something that can be used to fire up code; effectively "OnLoad" and "OnUnload". To dynamically control loading, we'll probably reflect on the individual plugins looking for attributes or perhaps some sort of static load function. How's that sound? From: freeswitch-users-bounces@lists.freeswitch.org<mailto:freeswitch-users-bounces@lists.freeswitch.org> [mailto:freeswitch-users-bounces@lists.freeswitch.org<mailto:freeswitch-users-bounces@lists.freeswitch.org>] On Behalf Of Josh Rivers Sent: Thursday, September 10, 2009 12:48 PM To: freeswitch-users@lists.freeswitch.org<mailto:freeswitch-users@lists.freeswitch.org> Subject: Re: [Freeswitch-users] Subscribing to events in managed C# / .NET I'm only concerned with the difference in treatment. public class CrashFreeSWITCH : ILoadNotificationPlugin { public bool Load() { ThreadPool.QueueUserWorkItem((o) => { throw new NotImplementedException(); }); return true; } } Crashes the entire switch, terminating all calls and disconnecting from the PSTN. public class CrashFreeSWITCH : ILoadNotificationPlugin { public bool Load() { throw new NotImplementedException(); return true; } } Logs a message to the console and doesn't load the module, while leaving the switch operating. In my experience, exceptions in multi-threaded code: a) happen, b) are hard to diagnose. Is the best behavior for the environment to crash, providing no diagnostic information? That's hard in development, and even harder in production. I suppose 'terminate switch on fault' should be an option, to allow the operating system to restart the whole process on fault conditions, but if that is the intended result, shouldn't any fault do the same thing? What if the billing was happening in my second code block? Normally, I'd trap the ThreadException and UnhandledExceptions in my application, so that my code could choose the correct actions to perform should the application get into an unknown state. This can include terminating the whole application, but also logging diagnostic information, trying to save uncommitted data, and sending notifications of the failure. Is 'crash if it's a thread, but not if it's not' good because it's the way the module works now, or is it a better design for a reason I'm not understanding? On Wed, Sep 9, 2009 at 11:09 PM, Michael Giagnocavo <mgg@giagnocavo.net<mailto:mgg@giagnocavo.net>> wrote: Well, a segfault in voicemail would do the same thing. Suppose your plugin runs a thread that does something important, like billing or so on. That thread fails - do you really want it to go on? Anyways, the solution is simple enough, handle your exceptions :). Every plugin can decide what it wants to do here. -Michael From: freeswitch-users-bounces@lists.freeswitch.org<mailto:freeswitch-users-bounces@lists.freeswitch.org> [mailto:freeswitch-users-bounces@lists.freeswitch.org<mailto:freeswitch-users-bounces@lists.freeswitch.org>] On Behalf Of Josh Rivers Sent: Wednesday, September 09, 2009 10:41 PM To: freeswitch-users@lists.freeswitch.org<mailto:freeswitch-users@lists.freeswitch.org> Subject: Re: [Freeswitch-users] Subscribing to events in managed C# / .NET The question is whether the CLR should take down the whole phone server due to an unhandled exception...definitely the CLR should terminate...but shouldn't it just log the exception to the console, not crash the core? On Wed, Sep 9, 2009 at 6:30 PM, Michael Giagnocavo <mgg@giagnocavo.net<mailto:mgg@giagnocavo.net>> wrote: That's by design. If a thread fails, and there's no handler, then the application could be in a corrupted state, so the CLR takes down the process. I think there is a .NET 1.0 compat switch you can enable in the config if you like exceptions to be silently ignored :). -Michael From: freeswitch-users-bounces@lists.freeswitch.org<mailto:freeswitch-users-bounces@lists.freeswitch.org> [mailto:freeswitch-users-bounces@lists.freeswitch.org<mailto:freeswitch-users-bounces@lists.freeswitch.org>] On Behalf Of Josh Rivers Sent: Wednesday, September 09, 2009 6:39 PM To: freeswitch-users@lists.freeswitch.org<mailto:freeswitch-users@lists.freeswitch.org> Subject: Re: [Freeswitch-users] Subscribing to events in managed C# / .NET I have a new thought on the crashes...I'm able to crash FreeSWITCH any time I like, just by having an exception in a thread. public class CrashFreeSWITCH : ILoadNotificationPlugin { public bool Load() { ThreadPool.QueueUserWorkItem((o) => { throw new NotImplementedException(); }); return true; } } Perhaps Application.ThreadException or AppDomain.UnhandledException need to be trapped? On Wed, Sep 9, 2009 at 4:51 PM, Michael Giagnocavo <mgg@giagnocavo.net<mailto:mgg@giagnocavo.net>> wrote:
Looks like the event object goes straight to pinvokes, so a null result just crashes?
If it's null, you should get a NullReferenceException. The C# compiler should callvirt the property getter and that'll do a null check. If that isn't happening, that'd be an interesting optimization somewhere along the line. -Michael From: freeswitch-users-bounces@lists.freeswitch.org<mailto:freeswitch-users-bounces@lists.freeswitch.org> [mailto:freeswitch-users-bounces@lists.freeswitch.org<mailto:freeswitch-users-bounces@lists.freeswitch.org>] On Behalf Of Josh Rivers Sent: Wednesday, September 09, 2009 3:01 PM To: freeswitch-users@lists.freeswitch.org<mailto:freeswitch-users@lists.freeswitch.org> Subject: Re: [Freeswitch-users] Subscribing to events in managed C# / .NET 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<mailto:jlenk@frontiernet.net>> wrote: 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<mailto:mgg@giagnocavo.net>>wrote:
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-tp3573619p361319... Sent from the freeswitch-users mailing list archive at Nabble.com. _______________________________________________ FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org<mailto: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<mailto: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<mailto: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<mailto: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<mailto: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<mailto: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
On Wed, Sep 23, 2009 at 7:31 PM, Michael Giagnocavo <mgg@giagnocavo.net>wrote:
Right off the bat: there can be tons of cleanup and refactoring, no doubt about that. Much of the current code is to satisfy my needs in production, which it does very well.
The current base doesn't have anything wrong with it for sure, in fact, I learned a good bit about PInvoke. AppDomains, and In-Process Remoting in the last week. My refactoring had the following goals (in no particular order) - Testability - I'd really like to see a decent unit test suite on the more module so that we can change it with confidence. Also, it's been drilled into me that a testable design is a good design. - Clarity - Where possible, I extracted blocks of code that served a particular purpose so that purpose could be self-documenting in the method calls rather than mixed in. - Modularity - I wanted to make it easy to remove or add alternative behavior to the managed.dll.
I’m a bit hesitant to go too far from the FreeSWITCH core as far as architecture goes. For instance, I’m not quite sure why’d we have our own managed logging subsystem that allows them to plug in other things that aren’t part of FS. Either they should use the FS logging system, or use their own such as log4net. Or perhaps I don’t see why we’d want this behavior.
I completely agree, with the following caveats: 1) I'd like to see things testable. It's very hard to do isolation testing with classes making direct calls out to a static Log class that in turn pinvokes out to unmanaged code. 2) I'd like to allow folk to make changes to the default behavior (optimally) without recompiling managed.dll. One thing at issue here is that there are two principal purposes for managed.dll. The first is to provide an interface into unmanaged code. The second is a module/plugin extensibility framework. The first purpose should absolutely provide the thinnest layer possible. The second purpose is very likely to need a lot of change and adaptation as people come up with development models that they would like to follow in using freeswitch. The extensibility framework should be mostly managed code, coded to interfaces for mock-ability and testabiliy. It should also be able to just push it out of the way and hook your own extensibilty framework in instead.
Going away from the core as far as adding .NET specific features (like look at the static ManagedSession.Originate that takes hangup delegates, or the “nice” wrapper for Log (Write and WeiteLine, with an enum instead of a string) are keeping close to the core, just adding a tiny bit of API cleanup. FreeSWITCH exposes a lot of strings, and while maybe that’s important for some languages, .NET users are going to expect stronger typing. But I don’t think these types of things get people away from FreeSWITCH much.
No disagreement here. I would like to see these things made available by interface rather than concrete implementation. It's currently not possible to test a plugin without loading it into FS. That precludes automated testing, and leaves a pretty big round-trip to test a tweak. I'm a sloppy coder too, so I'm always introducing interesting regressions, and that's why I like doing my testing without having to bring up a full process :)
Things like making a published SOAP interface for FS seem not really related to mod_managed. They can easily be done as 3rd party plugins, or convince the core FS team that exposing via SOAP via mod_managed is the way to go. Also keep in mind that the majority of users are on Linux, so that rules out WCF and some other fun stuff that only works on the CLR – I’d say it all has to work on Mono.
This kind of stuff is definitely beyond the scope of mod_managed. Although there is a slippery slope since we're building in an extensibility model. I don't think a WCF host, or a winforms host, or any of that should be baked in. Rather, I think we should provide the hooks for adding such a thing. If somebody wants to build ESL via WCF, why should they need to leave managed code? If the module system is general enough, then such a thing should just be a module. (BTW, I think WCF-Mono is getting there http://www.mono-project.com/WCF_Development) Absolutely, everything in mod_managed and managed.dll should run on mono and the CLR. However, there shouldn't be any reason that a Win-only developer can't build a complete FS application framework that plugs in and only runs on Windows.
As for all the rest of it, can we talk interactively, perhaps with other users interested in mod_managed? Reading over your email, I think I’m not understanding many of the use cases that are being fixed.
I'd be very glad to get a discussion going. I definitely haven't covered all of the issues here. -Josh
Great - hopefully we'll meet on IRC or the conference sometime on Friday. Email me when you're on. A few questions I have: Clarity - I agree with you there, and thanks! Testability - is this even remotely practical? Looking at our FS code plugins, there's simply no way any amount of test environment code would get us to anything testable. We make tons of direct P/Invoke calls, and the whole model for what variables are set when, the state machine progression, etc. does not seem like something that we can hope to possibly model right. And it's subject to many external influences (all the modules you have loaded in FS). Logging is a pretty simple case, sure, we can make it not call FS for testing. But in a real app, it just seems that there are way too many dependencies, no? Maybe others who have apps written can chime in? Modularity - I agree there are two parts. But, I think they are pretty tightly coupled. The FS interface into unmanaged code is done via unmanaged code and is really clear: App, Api, ApiBackground. The other ways I can think of are FS-specific, such as XML binding interface and so on. But those are things we should just add to the mod_managed core and be done with. I'm thinking maybe we are talking about different things? Can you provide some user stories that we want to cover with a pluggable loader/executor/etc.? Thanks for putting up with me! -Michael From: freeswitch-users-bounces@lists.freeswitch.org [mailto:freeswitch-users-bounces@lists.freeswitch.org] On Behalf Of Josh Rivers Sent: Thursday, September 24, 2009 12:32 AM To: freeswitch-users@lists.freeswitch.org Subject: Re: [Freeswitch-users] Subscribing to events in managed C# / .NET On Wed, Sep 23, 2009 at 7:31 PM, Michael Giagnocavo <mgg@giagnocavo.net<mailto:mgg@giagnocavo.net>> wrote: Right off the bat: there can be tons of cleanup and refactoring, no doubt about that. Much of the current code is to satisfy my needs in production, which it does very well. The current base doesn't have anything wrong with it for sure, in fact, I learned a good bit about PInvoke. AppDomains, and In-Process Remoting in the last week. My refactoring had the following goals (in no particular order) - Testability - I'd really like to see a decent unit test suite on the more module so that we can change it with confidence. Also, it's been drilled into me that a testable design is a good design. - Clarity - Where possible, I extracted blocks of code that served a particular purpose so that purpose could be self-documenting in the method calls rather than mixed in. - Modularity - I wanted to make it easy to remove or add alternative behavior to the managed.dll. I'm a bit hesitant to go too far from the FreeSWITCH core as far as architecture goes. For instance, I'm not quite sure why'd we have our own managed logging subsystem that allows them to plug in other things that aren't part of FS. Either they should use the FS logging system, or use their own such as log4net. Or perhaps I don't see why we'd want this behavior. I completely agree, with the following caveats: 1) I'd like to see things testable. It's very hard to do isolation testing with classes making direct calls out to a static Log class that in turn pinvokes out to unmanaged code. 2) I'd like to allow folk to make changes to the default behavior (optimally) without recompiling managed.dll. One thing at issue here is that there are two principal purposes for managed.dll. The first is to provide an interface into unmanaged code. The second is a module/plugin extensibility framework. The first purpose should absolutely provide the thinnest layer possible. The second purpose is very likely to need a lot of change and adaptation as people come up with development models that they would like to follow in using freeswitch. The extensibility framework should be mostly managed code, coded to interfaces for mock-ability and testabiliy. It should also be able to just push it out of the way and hook your own extensibilty framework in instead. Going away from the core as far as adding .NET specific features (like look at the static ManagedSession.Originate that takes hangup delegates, or the "nice" wrapper for Log (Write and WeiteLine, with an enum instead of a string) are keeping close to the core, just adding a tiny bit of API cleanup. FreeSWITCH exposes a lot of strings, and while maybe that's important for some languages, .NET users are going to expect stronger typing. But I don't think these types of things get people away from FreeSWITCH much. No disagreement here. I would like to see these things made available by interface rather than concrete implementation. It's currently not possible to test a plugin without loading it into FS. That precludes automated testing, and leaves a pretty big round-trip to test a tweak. I'm a sloppy coder too, so I'm always introducing interesting regressions, and that's why I like doing my testing without having to bring up a full process :) Things like making a published SOAP interface for FS seem not really related to mod_managed. They can easily be done as 3rd party plugins, or convince the core FS team that exposing via SOAP via mod_managed is the way to go. Also keep in mind that the majority of users are on Linux, so that rules out WCF and some other fun stuff that only works on the CLR - I'd say it all has to work on Mono. This kind of stuff is definitely beyond the scope of mod_managed. Although there is a slippery slope since we're building in an extensibility model. I don't think a WCF host, or a winforms host, or any of that should be baked in. Rather, I think we should provide the hooks for adding such a thing. If somebody wants to build ESL via WCF, why should they need to leave managed code? If the module system is general enough, then such a thing should just be a module. (BTW, I think WCF-Mono is getting there http://www.mono-project.com/WCF_Development) Absolutely, everything in mod_managed and managed.dll should run on mono and the CLR. However, there shouldn't be any reason that a Win-only developer can't build a complete FS application framework that plugs in and only runs on Windows. As for all the rest of it, can we talk interactively, perhaps with other users interested in mod_managed? Reading over your email, I think I'm not understanding many of the use cases that are being fixed. I'd be very glad to get a discussion going. I definitely haven't covered all of the issues here. -Josh
There are a few other things I can think would be nice additions to mod_managed. Maybe an event handler that does not require a thread to be sitting and waiting for events trying in a loop would be nice, instead something that is triggered each time there is a certain event class triggered. Also, there has been some interest in doing full endpoint modules in mod_managed. exposing all the state handlers in .net like ways and having that all work would be quite interesting, but probably requires someone specific actually ready to write a module like that to be worthwhile. Mike On Sep 24, 2009, at 4:01 AM, Michael Giagnocavo wrote:
Great – hopefully we’ll meet on IRC or the conference sometime on Friday. Email me when you’re on.
A few questions I have:
Clarity – I agree with you there, and thanks!
Testability – is this even remotely practical? Looking at our FS code plugins, there’s simply no way any amount of test environment code would get us to anything testable. We make tons of direct P/ Invoke calls, and the whole model for what variables are set when, the state machine progression, etc. does not seem like something that we can hope to possibly model right. And it’s subject to many external influences (all the modules you have loaded in FS). Logging is a pretty simple case, sure, we can make it not call FS for testing. But in a real app, it just seems that there are way too many dependencies, no? Maybe others who have apps written can chime in?
Modularity – I agree there are two parts. But, I think they are pretty tightly coupled. The FS interface into unmanaged code is done via unmanaged code and is really clear: App, Api, ApiBackground. The other ways I can think of are FS-specific, such as XML binding interface and so on. But those are things we should just add to the mod_managed core and be done with. I’m thinking maybe we are talking about different things? Can you provide some user stories that we want to cover with a pluggable loader/executor/etc.? Thanks for putting up with me!
-Michael
From: freeswitch-users-bounces@lists.freeswitch.org [mailto:freeswitch-users-bounces@lists.freeswitch.org] On Behalf Of Josh Rivers Sent: Thursday, September 24, 2009 12:32 AM To: freeswitch-users@lists.freeswitch.org Subject: Re: [Freeswitch-users] Subscribing to events in managed C# / .NET
On Wed, Sep 23, 2009 at 7:31 PM, Michael Giagnocavo <mgg@giagnocavo.net
wrote: Right off the bat: there can be tons of cleanup and refactoring, no doubt about that. Much of the current code is to satisfy my needs in production, which it does very well.
The current base doesn't have anything wrong with it for sure, in fact, I learned a good bit about PInvoke. AppDomains, and In-Process Remoting in the last week.
My refactoring had the following goals (in no particular order) - Testability - I'd really like to see a decent unit test suite on the more module so that we can change it with confidence. Also, it's been drilled into me that a testable design is a good design. - Clarity - Where possible, I extracted blocks of code that served a particular purpose so that purpose could be self-documenting in the method calls rather than mixed in. - Modularity - I wanted to make it easy to remove or add alternative behavior to the managed.dll.
I’m a bit hesitant to go too far from the FreeSWITCH core as far as architecture goes. For instance, I’m not quite sure why’d we have our own managed logging subsystem that allows them to plug in other things that aren’t part of FS. Either they should use the FS logging system, or use their own such as log4net. Or perhaps I don’t see why we’d want this behavior.
I completely agree, with the following caveats: 1) I'd like to see things testable. It's very hard to do isolation testing with classes making direct calls out to a static Log class that in turn pinvokes out to unmanaged code. 2) I'd like to allow folk to make changes to the default behavior (optimally) without recompiling managed.dll.
One thing at issue here is that there are two principal purposes for managed.dll. The first is to provide an interface into unmanaged code. The second is a module/plugin extensibility framework. The first purpose should absolutely provide the thinnest layer possible. The second purpose is very likely to need a lot of change and adaptation as people come up with development models that they would like to follow in using freeswitch. The extensibility framework should be mostly managed code, coded to interfaces for mock-ability and testabiliy. It should also be able to just push it out of the way and hook your own extensibilty framework in instead. Going away from the core as far as adding .NET specific features (like look at the static ManagedSession.Originate that takes hangup delegates, or the “nice” wrapper for Log (Write and WeiteLine, with an enum instead of a string) are keeping close to the core, just adding a tiny bit of API cleanup. FreeSWITCH exposes a lot of strings, and while maybe that’s important for some languages, .NET users are going to expect stronger typing. But I don’t think these types of things get people away from FreeSWITCH much.
No disagreement here. I would like to see these things made available by interface rather than concrete implementation. It's currently not possible to test a plugin without loading it into FS. That precludes automated testing, and leaves a pretty big round-trip to test a tweak. I'm a sloppy coder too, so I'm always introducing interesting regressions, and that's why I like doing my testing without having to bring up a full process :) Things like making a published SOAP interface for FS seem not really related to mod_managed. They can easily be done as 3rd party plugins, or convince the core FS team that exposing via SOAP via mod_managed is the way to go. Also keep in mind that the majority of users are on Linux, so that rules out WCF and some other fun stuff that only works on the CLR – I’d say it all has to work on Mono.
This kind of stuff is definitely beyond the scope of mod_managed. Although there is a slippery slope since we're building in an extensibility model. I don't think a WCF host, or a winforms host, or any of that should be baked in. Rather, I think we should provide the hooks for adding such a thing. If somebody wants to build ESL via WCF, why should they need to leave managed code? If the module system is general enough, then such a thing should just be a module. (BTW, I think WCF-Mono is getting there http://www.mono-project.com/WCF_Development ) Absolutely, everything in mod_managed and managed.dll should run on mono and the CLR. However, there shouldn't be any reason that a Win- only developer can't build a complete FS application framework that plugs in and only runs on Windows. As for all the rest of it, can we talk interactively, perhaps with other users interested in mod_managed? Reading over your email, I think I’m not understanding many of the use cases that are being fixed.
I'd be very glad to get a discussion going. I definitely haven't covered all of the issues here.
-Josh
_______________________________________________ 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
There is a new function I checked in a little bit ago that lets you create any of the SWIGTYPE_p_xxx types - all you need is a pointer to the memory to represent whatever it is in native land. So with that, it's actually possible to call most or all of the functions. (Yes DRK, you can now go do XML binding.) But sure, it'd be nice to make a real .NET-ish layer. Async events seems like it wouldn't be hard, assuming FreeSWITCH delivers them that way? -Michael From: freeswitch-users-bounces@lists.freeswitch.org [mailto:freeswitch-users-bounces@lists.freeswitch.org] On Behalf Of Michael Jerris Sent: Thursday, September 24, 2009 10:26 PM To: freeswitch-users@lists.freeswitch.org Subject: Re: [Freeswitch-users] Subscribing to events in managed C# / .NET There are a few other things I can think would be nice additions to mod_managed. Maybe an event handler that does not require a thread to be sitting and waiting for events trying in a loop would be nice, instead something that is triggered each time there is a certain event class triggered. Also, there has been some interest in doing full endpoint modules in mod_managed. exposing all the state handlers in .net like ways and having that all work would be quite interesting, but probably requires someone specific actually ready to write a module like that to be worthwhile. Mike On Sep 24, 2009, at 4:01 AM, Michael Giagnocavo wrote: Great - hopefully we'll meet on IRC or the conference sometime on Friday. Email me when you're on. A few questions I have: Clarity - I agree with you there, and thanks! Testability - is this even remotely practical? Looking at our FS code plugins, there's simply no way any amount of test environment code would get us to anything testable. We make tons of direct P/Invoke calls, and the whole model for what variables are set when, the state machine progression, etc. does not seem like something that we can hope to possibly model right. And it's subject to many external influences (all the modules you have loaded in FS). Logging is a pretty simple case, sure, we can make it not call FS for testing. But in a real app, it just seems that there are way too many dependencies, no? Maybe others who have apps written can chime in? Modularity - I agree there are two parts. But, I think they are pretty tightly coupled. The FS interface into unmanaged code is done via unmanaged code and is really clear: App, Api, ApiBackground. The other ways I can think of are FS-specific, such as XML binding interface and so on. But those are things we should just add to the mod_managed core and be done with. I'm thinking maybe we are talking about different things? Can you provide some user stories that we want to cover with a pluggable loader/executor/etc.? Thanks for putting up with me! -Michael From: freeswitch-users-bounces@lists.freeswitch.org<mailto:freeswitch-users-bounces@lists.freeswitch.org> [mailto:freeswitch-users-bounces@lists.freeswitch.org] On Behalf Of Josh Rivers Sent: Thursday, September 24, 2009 12:32 AM To: freeswitch-users@lists.freeswitch.org<mailto:freeswitch-users@lists.freeswitch.org> Subject: Re: [Freeswitch-users] Subscribing to events in managed C# / .NET On Wed, Sep 23, 2009 at 7:31 PM, Michael Giagnocavo <mgg@giagnocavo.net<mailto:mgg@giagnocavo.net>> wrote: Right off the bat: there can be tons of cleanup and refactoring, no doubt about that. Much of the current code is to satisfy my needs in production, which it does very well. The current base doesn't have anything wrong with it for sure, in fact, I learned a good bit about PInvoke. AppDomains, and In-Process Remoting in the last week. My refactoring had the following goals (in no particular order) - Testability - I'd really like to see a decent unit test suite on the more module so that we can change it with confidence. Also, it's been drilled into me that a testable design is a good design. - Clarity - Where possible, I extracted blocks of code that served a particular purpose so that purpose could be self-documenting in the method calls rather than mixed in. - Modularity - I wanted to make it easy to remove or add alternative behavior to the managed.dll. I'm a bit hesitant to go too far from the FreeSWITCH core as far as architecture goes. For instance, I'm not quite sure why'd we have our own managed logging subsystem that allows them to plug in other things that aren't part of FS. Either they should use the FS logging system, or use their own such as log4net. Or perhaps I don't see why we'd want this behavior. I completely agree, with the following caveats: 1) I'd like to see things testable. It's very hard to do isolation testing with classes making direct calls out to a static Log class that in turn pinvokes out to unmanaged code. 2) I'd like to allow folk to make changes to the default behavior (optimally) without recompiling managed.dll. One thing at issue here is that there are two principal purposes for managed.dll. The first is to provide an interface into unmanaged code. The second is a module/plugin extensibility framework. The first purpose should absolutely provide the thinnest layer possible. The second purpose is very likely to need a lot of change and adaptation as people come up with development models that they would like to follow in using freeswitch. The extensibility framework should be mostly managed code, coded to interfaces for mock-ability and testabiliy. It should also be able to just push it out of the way and hook your own extensibilty framework in instead. Going away from the core as far as adding .NET specific features (like look at the static ManagedSession.Originate that takes hangup delegates, or the "nice" wrapper for Log (Write and WeiteLine, with an enum instead of a string) are keeping close to the core, just adding a tiny bit of API cleanup. FreeSWITCH exposes a lot of strings, and while maybe that's important for some languages, .NET users are going to expect stronger typing. But I don't think these types of things get people away from FreeSWITCH much. No disagreement here. I would like to see these things made available by interface rather than concrete implementation. It's currently not possible to test a plugin without loading it into FS. That precludes automated testing, and leaves a pretty big round-trip to test a tweak. I'm a sloppy coder too, so I'm always introducing interesting regressions, and that's why I like doing my testing without having to bring up a full process :) Things like making a published SOAP interface for FS seem not really related to mod_managed. They can easily be done as 3rd party plugins, or convince the core FS team that exposing via SOAP via mod_managed is the way to go. Also keep in mind that the majority of users are on Linux, so that rules out WCF and some other fun stuff that only works on the CLR - I'd say it all has to work on Mono. This kind of stuff is definitely beyond the scope of mod_managed. Although there is a slippery slope since we're building in an extensibility model. I don't think a WCF host, or a winforms host, or any of that should be baked in. Rather, I think we should provide the hooks for adding such a thing. If somebody wants to build ESL via WCF, why should they need to leave managed code? If the module system is general enough, then such a thing should just be a module. (BTW, I think WCF-Mono is getting there http://www.mono-project.com/WCF_Development) Absolutely, everything in mod_managed and managed.dll should run on mono and the CLR. However, there shouldn't be any reason that a Win-only developer can't build a complete FS application framework that plugs in and only runs on Windows. As for all the rest of it, can we talk interactively, perhaps with other users interested in mod_managed? Reading over your email, I think I'm not understanding many of the use cases that are being fixed. I'd be very glad to get a discussion going. I definitely haven't covered all of the issues here. -Josh _______________________________________________ FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org<mailto: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
The ability to directly create swigtypes...that's huge! I'd love to see some examples of how to use that. I've update my refactoring to include the changes to the trunk up through r14981. I've also checked in updated binaries that should work with the latest trunk builds(I hope?) A question occurred to me: would it make any sense to push the plugin loader into a separate DLL? That way we could keep the P/Invoke layer very cleanly separated from the loader/process host/abstraction layer structures. Josh On Fri, Sep 25, 2009 at 1:13 PM, Michael Giagnocavo <mgg@giagnocavo.net>wrote:
There is a new function I checked in a little bit ago that lets you create any of the SWIGTYPE_p_xxx types – all you need is a pointer to the memory to represent whatever it is in native land. So with that, it’s actually possible to call most or all of the functions. (Yes DRK, you can now go do XML binding.) But sure, it’d be nice to make a real .NET-ish layer.
Async events seems like it wouldn’t be hard, assuming FreeSWITCH delivers them that way?
-Michael
*From:* freeswitch-users-bounces@lists.freeswitch.org [mailto: freeswitch-users-bounces@lists.freeswitch.org] *On Behalf Of *Michael Jerris *Sent:* Thursday, September 24, 2009 10:26 PM
*To:* freeswitch-users@lists.freeswitch.org *Subject:* Re: [Freeswitch-users] Subscribing to events in managed C# / .NET
There are a few other things I can think would be nice additions to mod_managed. Maybe an event handler that does not require a thread to be sitting and waiting for events trying in a loop would be nice, instead something that is triggered each time there is a certain event class triggered. Also, there has been some interest in doing full endpoint modules in mod_managed. exposing all the state handlers in .net like ways and having that all work would be quite interesting, but probably requires someone specific actually ready to write a module like that to be worthwhile.
Mike
On Sep 24, 2009, at 4:01 AM, Michael Giagnocavo wrote:
Great – hopefully we’ll meet on IRC or the conference sometime on Friday. Email me when you’re on.
A few questions I have:
Clarity – I agree with you there, and thanks!
Testability – is this even remotely practical? Looking at our FS code plugins, there’s simply no way any amount of test environment code would get us to anything testable. We make tons of direct P/Invoke calls, and the whole model for what variables are set when, the state machine progression, etc. does not seem like something that we can hope to possibly model right. And it’s subject to many external influences (all the modules you have loaded in FS). Logging is a pretty simple case, sure, we can make it not call FS for testing. But in a real app, it just seems that there are way too many dependencies, no? Maybe others who have apps written can chime in?
Modularity – I agree there are two parts. But, I think they are pretty tightly coupled. The FS interface into unmanaged code is done via unmanaged code and is really clear: App, Api, ApiBackground. The other ways I can think of are FS-specific, such as XML binding interface and so on. But those are things we should just add to the mod_managed core and be done with. I’m thinking maybe we are talking about different things? Can you provide some user stories that we want to cover with a pluggable loader/executor/etc.? Thanks for putting up with me!
-Michael
*From:* freeswitch-users-bounces@lists.freeswitch.org [mailto: freeswitch-users-bounces@lists.freeswitch.org] *On Behalf Of *Josh Rivers *Sent:* Thursday, September 24, 2009 12:32 AM *To:* freeswitch-users@lists.freeswitch.org *Subject:* Re: [Freeswitch-users] Subscribing to events in managed C# / .NET
On Wed, Sep 23, 2009 at 7:31 PM, Michael Giagnocavo <mgg@giagnocavo.net> wrote:
Right off the bat: there can be tons of cleanup and refactoring, no doubt about that. Much of the current code is to satisfy my needs in production, which it does very well.
The current base doesn't have anything wrong with it for sure, in fact, I learned a good bit about PInvoke. AppDomains, and In-Process Remoting in the last week.
My refactoring had the following goals (in no particular order)
- Testability - I'd really like to see a decent unit test suite on the more module so that we can change it with confidence. Also, it's been drilled into me that a testable design is a good design.
- Clarity - Where possible, I extracted blocks of code that served a particular purpose so that purpose could be self-documenting in the method calls rather than mixed in.
- Modularity - I wanted to make it easy to remove or add alternative behavior to the managed.dll.
I’m a bit hesitant to go too far from the FreeSWITCH core as far as architecture goes. For instance, I’m not quite sure why’d we have our own managed logging subsystem that allows them to plug in other things that aren’t part of FS. Either they should use the FS logging system, or use their own such as log4net. Or perhaps I don’t see why we’d want this behavior.
I completely agree, with the following caveats:
1) I'd like to see things testable. It's very hard to do isolation testing with classes making direct calls out to a static Log class that in turn pinvokes out to unmanaged code.
2) I'd like to allow folk to make changes to the default behavior (optimally) without recompiling managed.dll.
One thing at issue here is that there are two principal purposes for managed.dll. The first is to provide an interface into unmanaged code. The second is a module/plugin extensibility framework. The first purpose should absolutely provide the thinnest layer possible. The second purpose is very likely to need a lot of change and adaptation as people come up with development models that they would like to follow in using freeswitch. The extensibility framework should be mostly managed code, coded to interfaces for mock-ability and testabiliy. It should also be able to just push it out of the way and hook your own extensibilty framework in instead.
Going away from the core as far as adding .NET specific features (like look at the static ManagedSession.Originate that takes hangup delegates, or the “nice” wrapper for Log (Write and WeiteLine, with an enum instead of a string) are keeping close to the core, just adding a tiny bit of API cleanup. FreeSWITCH exposes a lot of strings, and while maybe that’s important for some languages, .NET users are going to expect stronger typing. But I don’t think these types of things get people away from FreeSWITCH much.
No disagreement here. I would like to see these things made available by interface rather than concrete implementation. It's currently not possible to test a plugin without loading it into FS. That precludes automated testing, and leaves a pretty big round-trip to test a tweak. I'm a sloppy coder too, so I'm always introducing interesting regressions, and that's why I like doing my testing without having to bring up a full process :)
Things like making a published SOAP interface for FS seem not really related to mod_managed. They can easily be done as 3rd party plugins, or convince the core FS team that exposing via SOAP via mod_managed is the way to go. Also keep in mind that the majority of users are on Linux, so that rules out WCF and some other fun stuff that only works on the CLR – I’d say it all has to work on Mono.
This kind of stuff is definitely beyond the scope of mod_managed. Although there is a slippery slope since we're building in an extensibility model. I don't think a WCF host, or a winforms host, or any of that should be baked in. Rather, I think we should provide the hooks for adding such a thing. If somebody wants to build ESL via WCF, why should they need to leave managed code? If the module system is general enough, then such a thing should just be a module.
(BTW, I think WCF-Mono is getting there http://www.mono-project.com/WCF_Development)
Absolutely, everything in mod_managed and managed.dll should run on mono and the CLR. However, there shouldn't be any reason that a Win-only developer can't build a complete FS application framework that plugs in and only runs on Windows.
As for all the rest of it, can we talk interactively, perhaps with other users interested in mod_managed? Reading over your email, I think I’m not understanding many of the use cases that are being fixed.
I'd be very glad to get a discussion going. I definitely haven't covered all of the issues here.
-Josh
_______________________________________________ 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
Hello All, I am a total newbie with FS. I use pbxiaf but would really like to try out FS. I have installed FS And everything seems to be working. My problem is that i have some family scattered round the globe who are all logging in to to my piaf. I am not able to reconfigure those phones ( Some SIP and some IAX2 ). Would it be enough to redirect port 5060 in my router to port 5080? Or would it be possible to still use port 5060. ( I don't want to be too long offline for tests ) -- Best regards, Henk
You shouldn't have to do nothing since we have NAT detection. Port 5080 (external SIP profile) is just for unauthenticated clients. jmesquita On Sun, Sep 27, 2009 at 3:00 AM, Henk Maaijen <postbus6@postbus.info> wrote:
Hello All,
I am a total newbie with FS. I use pbxiaf but would really like to try out FS. I have installed FS And everything seems to be working. My problem is that i have some family scattered round the globe who are all logging in to to my piaf. I am not able to reconfigure those phones ( Some SIP and some IAX2 ). Would it be enough to redirect port 5060 in my router to port 5080? Or would it be possible to still use port 5060. ( I don't want to be too long offline for tests )
-- Best regards, Henk
_______________________________________________ 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
Like jmesquita said, you shouldn't need to do anything special. Just make sure that the login credentials that you set up for FS match those that you have in sip.conf so that you don't have to change auth name and/or password for your SIP phones. FYI, FS does not currently support IAX2 auth. -MC 2009/9/27 João Mesquita <jmesquita@freeswitch.org>
You shouldn't have to do nothing since we have NAT detection.
Port 5080 (external SIP profile) is just for unauthenticated clients.
jmesquita
On Sun, Sep 27, 2009 at 3:00 AM, Henk Maaijen <postbus6@postbus.info>wrote:
Hello All,
I am a total newbie with FS. I use pbxiaf but would really like to try out FS. I have installed FS And everything seems to be working. My problem is that i have some family scattered round the globe who are all logging in to to my piaf. I am not able to reconfigure those phones ( Some SIP and some IAX2 ). Would it be enough to redirect port 5060 in my router to port 5080? Or would it be possible to still use port 5060. ( I don't want to be too long offline for tests )
-- Best regards, Henk
_______________________________________________ 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
One more addition added. The loader process now looks for the string ".primary" in the filename. If it exists, it loads the dll into the primary appdomain and executes to Load() routine on implementors of IPrimaryAppdomainExtension. I also added an example showing the use of this to display a WinForm logger. http://github.com/joshrivers/FreeSWITCH.Managed On Sat, Sep 26, 2009 at 10:28 PM, Josh Rivers <josh@radianttiger.com> wrote:
The ability to directly create swigtypes...that's huge! I'd love to see some examples of how to use that.
I've update my refactoring to include the changes to the trunk up through r14981. I've also checked in updated binaries that should work with the latest trunk builds(I hope?) A question occurred to me: would it make any sense to push the plugin loader into a separate DLL? That way we could keep the P/Invoke layer very cleanly separated from the loader/process host/abstraction layer structures.
Josh
On Fri, Sep 25, 2009 at 1:13 PM, Michael Giagnocavo <mgg@giagnocavo.net>wrote:
There is a new function I checked in a little bit ago that lets you create any of the SWIGTYPE_p_xxx types – all you need is a pointer to the memory to represent whatever it is in native land. So with that, it’s actually possible to call most or all of the functions. (Yes DRK, you can now go do XML binding.) But sure, it’d be nice to make a real .NET-ish layer.
Async events seems like it wouldn’t be hard, assuming FreeSWITCH delivers them that way?
-Michael
*From:* freeswitch-users-bounces@lists.freeswitch.org [mailto: freeswitch-users-bounces@lists.freeswitch.org] *On Behalf Of *Michael Jerris *Sent:* Thursday, September 24, 2009 10:26 PM
*To:* freeswitch-users@lists.freeswitch.org *Subject:* Re: [Freeswitch-users] Subscribing to events in managed C# / .NET
There are a few other things I can think would be nice additions to mod_managed. Maybe an event handler that does not require a thread to be sitting and waiting for events trying in a loop would be nice, instead something that is triggered each time there is a certain event class triggered. Also, there has been some interest in doing full endpoint modules in mod_managed. exposing all the state handlers in .net like ways and having that all work would be quite interesting, but probably requires someone specific actually ready to write a module like that to be worthwhile.
Mike
On Sep 24, 2009, at 4:01 AM, Michael Giagnocavo wrote:
Great – hopefully we’ll meet on IRC or the conference sometime on Friday. Email me when you’re on.
A few questions I have:
Clarity – I agree with you there, and thanks!
Testability – is this even remotely practical? Looking at our FS code plugins, there’s simply no way any amount of test environment code would get us to anything testable. We make tons of direct P/Invoke calls, and the whole model for what variables are set when, the state machine progression, etc. does not seem like something that we can hope to possibly model right. And it’s subject to many external influences (all the modules you have loaded in FS). Logging is a pretty simple case, sure, we can make it not call FS for testing. But in a real app, it just seems that there are way too many dependencies, no? Maybe others who have apps written can chime in?
Modularity – I agree there are two parts. But, I think they are pretty tightly coupled. The FS interface into unmanaged code is done via unmanaged code and is really clear: App, Api, ApiBackground. The other ways I can think of are FS-specific, such as XML binding interface and so on. But those are things we should just add to the mod_managed core and be done with. I’m thinking maybe we are talking about different things? Can you provide some user stories that we want to cover with a pluggable loader/executor/etc.? Thanks for putting up with me!
-Michael
*From:* freeswitch-users-bounces@lists.freeswitch.org [mailto: freeswitch-users-bounces@lists.freeswitch.org] *On Behalf Of *Josh Rivers *Sent:* Thursday, September 24, 2009 12:32 AM *To:* freeswitch-users@lists.freeswitch.org *Subject:* Re: [Freeswitch-users] Subscribing to events in managed C# / .NET
On Wed, Sep 23, 2009 at 7:31 PM, Michael Giagnocavo <mgg@giagnocavo.net> wrote:
Right off the bat: there can be tons of cleanup and refactoring, no doubt about that. Much of the current code is to satisfy my needs in production, which it does very well.
The current base doesn't have anything wrong with it for sure, in fact, I learned a good bit about PInvoke. AppDomains, and In-Process Remoting in the last week.
My refactoring had the following goals (in no particular order)
- Testability - I'd really like to see a decent unit test suite on the more module so that we can change it with confidence. Also, it's been drilled into me that a testable design is a good design.
- Clarity - Where possible, I extracted blocks of code that served a particular purpose so that purpose could be self-documenting in the method calls rather than mixed in.
- Modularity - I wanted to make it easy to remove or add alternative behavior to the managed.dll.
I’m a bit hesitant to go too far from the FreeSWITCH core as far as architecture goes. For instance, I’m not quite sure why’d we have our own managed logging subsystem that allows them to plug in other things that aren’t part of FS. Either they should use the FS logging system, or use their own such as log4net. Or perhaps I don’t see why we’d want this behavior.
I completely agree, with the following caveats:
1) I'd like to see things testable. It's very hard to do isolation testing with classes making direct calls out to a static Log class that in turn pinvokes out to unmanaged code.
2) I'd like to allow folk to make changes to the default behavior (optimally) without recompiling managed.dll.
One thing at issue here is that there are two principal purposes for managed.dll. The first is to provide an interface into unmanaged code. The second is a module/plugin extensibility framework. The first purpose should absolutely provide the thinnest layer possible. The second purpose is very likely to need a lot of change and adaptation as people come up with development models that they would like to follow in using freeswitch. The extensibility framework should be mostly managed code, coded to interfaces for mock-ability and testabiliy. It should also be able to just push it out of the way and hook your own extensibilty framework in instead.
Going away from the core as far as adding .NET specific features (like look at the static ManagedSession.Originate that takes hangup delegates, or the “nice” wrapper for Log (Write and WeiteLine, with an enum instead of a string) are keeping close to the core, just adding a tiny bit of API cleanup. FreeSWITCH exposes a lot of strings, and while maybe that’s important for some languages, .NET users are going to expect stronger typing. But I don’t think these types of things get people away from FreeSWITCH much.
No disagreement here. I would like to see these things made available by interface rather than concrete implementation. It's currently not possible to test a plugin without loading it into FS. That precludes automated testing, and leaves a pretty big round-trip to test a tweak. I'm a sloppy coder too, so I'm always introducing interesting regressions, and that's why I like doing my testing without having to bring up a full process :)
Things like making a published SOAP interface for FS seem not really related to mod_managed. They can easily be done as 3rd party plugins, or convince the core FS team that exposing via SOAP via mod_managed is the way to go. Also keep in mind that the majority of users are on Linux, so that rules out WCF and some other fun stuff that only works on the CLR – I’d say it all has to work on Mono.
This kind of stuff is definitely beyond the scope of mod_managed. Although there is a slippery slope since we're building in an extensibility model. I don't think a WCF host, or a winforms host, or any of that should be baked in. Rather, I think we should provide the hooks for adding such a thing. If somebody wants to build ESL via WCF, why should they need to leave managed code? If the module system is general enough, then such a thing should just be a module.
(BTW, I think WCF-Mono is getting there http://www.mono-project.com/WCF_Development)
Absolutely, everything in mod_managed and managed.dll should run on mono and the CLR. However, there shouldn't be any reason that a Win-only developer can't build a complete FS application framework that plugs in and only runs on Windows.
As for all the rest of it, can we talk interactively, perhaps with other users interested in mod_managed? Reading over your email, I think I’m not understanding many of the use cases that are being fixed.
I'd be very glad to get a discussion going. I definitely haven't covered all of the issues here.
-Josh
_______________________________________________ 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
It's in the "FSUtil" class (no I'm not happy with the name). I also made it an extension method on IntPtr (I'm not a big fan of extension methods, but the code is sorta messy anyways, so it's not relatively bad.) var x = CreateSwigTypePointer<SWIGTYPE_p_int>(somePtr); Moving stuff out of the SWIG DLL removes the ability to use partial classes to extend the generated swigtypes. This is used a bit, and will be used a lot more as the managed plugin is cleaned up. For example, most of the FS APIs return string, when they should return a better representation. Also, the constructors for some of the types are internal only, and I don't really enjoy using reflection to create them. -Michael From: freeswitch-users-bounces@lists.freeswitch.org [mailto:freeswitch-users-bounces@lists.freeswitch.org] On Behalf Of Josh Rivers Sent: Saturday, September 26, 2009 11:29 PM To: freeswitch-users@lists.freeswitch.org Subject: Re: [Freeswitch-users] Subscribing to events in managed C# / .NET The ability to directly create swigtypes...that's huge! I'd love to see some examples of how to use that. I've update my refactoring to include the changes to the trunk up through r14981. I've also checked in updated binaries that should work with the latest trunk builds(I hope?) A question occurred to me: would it make any sense to push the plugin loader into a separate DLL? That way we could keep the P/Invoke layer very cleanly separated from the loader/process host/abstraction layer structures. Josh On Fri, Sep 25, 2009 at 1:13 PM, Michael Giagnocavo <mgg@giagnocavo.net<mailto:mgg@giagnocavo.net>> wrote: There is a new function I checked in a little bit ago that lets you create any of the SWIGTYPE_p_xxx types - all you need is a pointer to the memory to represent whatever it is in native land. So with that, it's actually possible to call most or all of the functions. (Yes DRK, you can now go do XML binding.) But sure, it'd be nice to make a real .NET-ish layer. Async events seems like it wouldn't be hard, assuming FreeSWITCH delivers them that way? -Michael From: freeswitch-users-bounces@lists.freeswitch.org<mailto:freeswitch-users-bounces@lists.freeswitch.org> [mailto:freeswitch-users-bounces@lists.freeswitch.org<mailto:freeswitch-users-bounces@lists.freeswitch.org>] On Behalf Of Michael Jerris Sent: Thursday, September 24, 2009 10:26 PM To: freeswitch-users@lists.freeswitch.org<mailto:freeswitch-users@lists.freeswitch.org> Subject: Re: [Freeswitch-users] Subscribing to events in managed C# / .NET There are a few other things I can think would be nice additions to mod_managed. Maybe an event handler that does not require a thread to be sitting and waiting for events trying in a loop would be nice, instead something that is triggered each time there is a certain event class triggered. Also, there has been some interest in doing full endpoint modules in mod_managed. exposing all the state handlers in .net like ways and having that all work would be quite interesting, but probably requires someone specific actually ready to write a module like that to be worthwhile. Mike On Sep 24, 2009, at 4:01 AM, Michael Giagnocavo wrote: Great - hopefully we'll meet on IRC or the conference sometime on Friday. Email me when you're on. A few questions I have: Clarity - I agree with you there, and thanks! Testability - is this even remotely practical? Looking at our FS code plugins, there's simply no way any amount of test environment code would get us to anything testable. We make tons of direct P/Invoke calls, and the whole model for what variables are set when, the state machine progression, etc. does not seem like something that we can hope to possibly model right. And it's subject to many external influences (all the modules you have loaded in FS). Logging is a pretty simple case, sure, we can make it not call FS for testing. But in a real app, it just seems that there are way too many dependencies, no? Maybe others who have apps written can chime in? Modularity - I agree there are two parts. But, I think they are pretty tightly coupled. The FS interface into unmanaged code is done via unmanaged code and is really clear: App, Api, ApiBackground. The other ways I can think of are FS-specific, such as XML binding interface and so on. But those are things we should just add to the mod_managed core and be done with. I'm thinking maybe we are talking about different things? Can you provide some user stories that we want to cover with a pluggable loader/executor/etc.? Thanks for putting up with me! -Michael From: freeswitch-users-bounces@lists.freeswitch.org<mailto:freeswitch-users-bounces@lists.freeswitch.org> [mailto:freeswitch-users-bounces@lists.freeswitch.org<mailto:freeswitch-users-bounces@lists.freeswitch.org>] On Behalf Of Josh Rivers Sent: Thursday, September 24, 2009 12:32 AM To: freeswitch-users@lists.freeswitch.org<mailto:freeswitch-users@lists.freeswitch.org> Subject: Re: [Freeswitch-users] Subscribing to events in managed C# / .NET On Wed, Sep 23, 2009 at 7:31 PM, Michael Giagnocavo <mgg@giagnocavo.net<mailto:mgg@giagnocavo.net>> wrote: Right off the bat: there can be tons of cleanup and refactoring, no doubt about that. Much of the current code is to satisfy my needs in production, which it does very well. The current base doesn't have anything wrong with it for sure, in fact, I learned a good bit about PInvoke. AppDomains, and In-Process Remoting in the last week. My refactoring had the following goals (in no particular order) - Testability - I'd really like to see a decent unit test suite on the more module so that we can change it with confidence. Also, it's been drilled into me that a testable design is a good design. - Clarity - Where possible, I extracted blocks of code that served a particular purpose so that purpose could be self-documenting in the method calls rather than mixed in. - Modularity - I wanted to make it easy to remove or add alternative behavior to the managed.dll. I'm a bit hesitant to go too far from the FreeSWITCH core as far as architecture goes. For instance, I'm not quite sure why'd we have our own managed logging subsystem that allows them to plug in other things that aren't part of FS. Either they should use the FS logging system, or use their own such as log4net. Or perhaps I don't see why we'd want this behavior. I completely agree, with the following caveats: 1) I'd like to see things testable. It's very hard to do isolation testing with classes making direct calls out to a static Log class that in turn pinvokes out to unmanaged code. 2) I'd like to allow folk to make changes to the default behavior (optimally) without recompiling managed.dll. One thing at issue here is that there are two principal purposes for managed.dll. The first is to provide an interface into unmanaged code. The second is a module/plugin extensibility framework. The first purpose should absolutely provide the thinnest layer possible. The second purpose is very likely to need a lot of change and adaptation as people come up with development models that they would like to follow in using freeswitch. The extensibility framework should be mostly managed code, coded to interfaces for mock-ability and testabiliy. It should also be able to just push it out of the way and hook your own extensibilty framework in instead. Going away from the core as far as adding .NET specific features (like look at the static ManagedSession.Originate that takes hangup delegates, or the "nice" wrapper for Log (Write and WeiteLine, with an enum instead of a string) are keeping close to the core, just adding a tiny bit of API cleanup. FreeSWITCH exposes a lot of strings, and while maybe that's important for some languages, .NET users are going to expect stronger typing. But I don't think these types of things get people away from FreeSWITCH much. No disagreement here. I would like to see these things made available by interface rather than concrete implementation. It's currently not possible to test a plugin without loading it into FS. That precludes automated testing, and leaves a pretty big round-trip to test a tweak. I'm a sloppy coder too, so I'm always introducing interesting regressions, and that's why I like doing my testing without having to bring up a full process :) Things like making a published SOAP interface for FS seem not really related to mod_managed. They can easily be done as 3rd party plugins, or convince the core FS team that exposing via SOAP via mod_managed is the way to go. Also keep in mind that the majority of users are on Linux, so that rules out WCF and some other fun stuff that only works on the CLR - I'd say it all has to work on Mono. This kind of stuff is definitely beyond the scope of mod_managed. Although there is a slippery slope since we're building in an extensibility model. I don't think a WCF host, or a winforms host, or any of that should be baked in. Rather, I think we should provide the hooks for adding such a thing. If somebody wants to build ESL via WCF, why should they need to leave managed code? If the module system is general enough, then such a thing should just be a module. (BTW, I think WCF-Mono is getting there http://www.mono-project.com/WCF_Development) Absolutely, everything in mod_managed and managed.dll should run on mono and the CLR. However, there shouldn't be any reason that a Win-only developer can't build a complete FS application framework that plugs in and only runs on Windows. As for all the rest of it, can we talk interactively, perhaps with other users interested in mod_managed? Reading over your email, I think I'm not understanding many of the use cases that are being fixed. I'd be very glad to get a discussion going. I definitely haven't covered all of the issues here. -Josh _______________________________________________ FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org<mailto: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<mailto: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
Where does 'somePtr' come from? On Sun, Sep 27, 2009 at 4:06 PM, Michael Giagnocavo <mgg@giagnocavo.net>wrote:
It’s in the “FSUtil” class (no I’m not happy with the name). I also made it an extension method on IntPtr (I’m not a big fan of extension methods, but the code is sorta messy anyways, so it’s not relatively bad.)
var x = CreateSwigTypePointer<SWIGTYPE_p_int>(somePtr);
Moving stuff out of the SWIG DLL removes the ability to use partial classes to extend the generated swigtypes. This is used a bit, and will be used a lot more as the managed plugin is cleaned up. For example, most of the FS APIs return string, when they should return a better representation. Also, the constructors for some of the types are internal only, and I don’t really enjoy using reflection to create them.
-Michael
*From:* freeswitch-users-bounces@lists.freeswitch.org [mailto: freeswitch-users-bounces@lists.freeswitch.org] *On Behalf Of *Josh Rivers *Sent:* Saturday, September 26, 2009 11:29 PM
*To:* freeswitch-users@lists.freeswitch.org *Subject:* Re: [Freeswitch-users] Subscribing to events in managed C# / .NET
The ability to directly create swigtypes...that's huge! I'd love to see some examples of how to use that.
I've update my refactoring to include the changes to the trunk up through r14981. I've also checked in updated binaries that should work with the latest trunk builds(I hope?)
A question occurred to me: would it make any sense to push the plugin loader into a separate DLL? That way we could keep the P/Invoke layer very cleanly separated from the loader/process host/abstraction layer structures.
Josh
On Fri, Sep 25, 2009 at 1:13 PM, Michael Giagnocavo <mgg@giagnocavo.net> wrote:
There is a new function I checked in a little bit ago that lets you create any of the SWIGTYPE_p_xxx types – all you need is a pointer to the memory to represent whatever it is in native land. So with that, it’s actually possible to call most or all of the functions. (Yes DRK, you can now go do XML binding.) But sure, it’d be nice to make a real .NET-ish layer.
Async events seems like it wouldn’t be hard, assuming FreeSWITCH delivers them that way?
-Michael
*From:* freeswitch-users-bounces@lists.freeswitch.org [mailto: freeswitch-users-bounces@lists.freeswitch.org] *On Behalf Of *Michael Jerris *Sent:* Thursday, September 24, 2009 10:26 PM
*To:* freeswitch-users@lists.freeswitch.org *Subject:* Re: [Freeswitch-users] Subscribing to events in managed C# / .NET
There are a few other things I can think would be nice additions to mod_managed. Maybe an event handler that does not require a thread to be sitting and waiting for events trying in a loop would be nice, instead something that is triggered each time there is a certain event class triggered. Also, there has been some interest in doing full endpoint modules in mod_managed. exposing all the state handlers in .net like ways and having that all work would be quite interesting, but probably requires someone specific actually ready to write a module like that to be worthwhile.
Mike
On Sep 24, 2009, at 4:01 AM, Michael Giagnocavo wrote:
Great – hopefully we’ll meet on IRC or the conference sometime on Friday. Email me when you’re on.
A few questions I have:
Clarity – I agree with you there, and thanks!
Testability – is this even remotely practical? Looking at our FS code plugins, there’s simply no way any amount of test environment code would get us to anything testable. We make tons of direct P/Invoke calls, and the whole model for what variables are set when, the state machine progression, etc. does not seem like something that we can hope to possibly model right. And it’s subject to many external influences (all the modules you have loaded in FS). Logging is a pretty simple case, sure, we can make it not call FS for testing. But in a real app, it just seems that there are way too many dependencies, no? Maybe others who have apps written can chime in?
Modularity – I agree there are two parts. But, I think they are pretty tightly coupled. The FS interface into unmanaged code is done via unmanaged code and is really clear: App, Api, ApiBackground. The other ways I can think of are FS-specific, such as XML binding interface and so on. But those are things we should just add to the mod_managed core and be done with. I’m thinking maybe we are talking about different things? Can you provide some user stories that we want to cover with a pluggable loader/executor/etc.? Thanks for putting up with me!
-Michael
*From:* freeswitch-users-bounces@lists.freeswitch.org [mailto: freeswitch-users-bounces@lists.freeswitch.org] *On Behalf Of *Josh Rivers *Sent:* Thursday, September 24, 2009 12:32 AM *To:* freeswitch-users@lists.freeswitch.org *Subject:* Re: [Freeswitch-users] Subscribing to events in managed C# / .NET
On Wed, Sep 23, 2009 at 7:31 PM, Michael Giagnocavo <mgg@giagnocavo.net> wrote:
Right off the bat: there can be tons of cleanup and refactoring, no doubt about that. Much of the current code is to satisfy my needs in production, which it does very well.
The current base doesn't have anything wrong with it for sure, in fact, I learned a good bit about PInvoke. AppDomains, and In-Process Remoting in the last week.
My refactoring had the following goals (in no particular order)
- Testability - I'd really like to see a decent unit test suite on the more module so that we can change it with confidence. Also, it's been drilled into me that a testable design is a good design.
- Clarity - Where possible, I extracted blocks of code that served a particular purpose so that purpose could be self-documenting in the method calls rather than mixed in.
- Modularity - I wanted to make it easy to remove or add alternative behavior to the managed.dll.
I’m a bit hesitant to go too far from the FreeSWITCH core as far as architecture goes. For instance, I’m not quite sure why’d we have our own managed logging subsystem that allows them to plug in other things that aren’t part of FS. Either they should use the FS logging system, or use their own such as log4net. Or perhaps I don’t see why we’d want this behavior.
I completely agree, with the following caveats:
1) I'd like to see things testable. It's very hard to do isolation testing with classes making direct calls out to a static Log class that in turn pinvokes out to unmanaged code.
2) I'd like to allow folk to make changes to the default behavior (optimally) without recompiling managed.dll.
One thing at issue here is that there are two principal purposes for managed.dll. The first is to provide an interface into unmanaged code. The second is a module/plugin extensibility framework. The first purpose should absolutely provide the thinnest layer possible. The second purpose is very likely to need a lot of change and adaptation as people come up with development models that they would like to follow in using freeswitch. The extensibility framework should be mostly managed code, coded to interfaces for mock-ability and testabiliy. It should also be able to just push it out of the way and hook your own extensibilty framework in instead.
Going away from the core as far as adding .NET specific features (like look at the static ManagedSession.Originate that takes hangup delegates, or the “nice” wrapper for Log (Write and WeiteLine, with an enum instead of a string) are keeping close to the core, just adding a tiny bit of API cleanup. FreeSWITCH exposes a lot of strings, and while maybe that’s important for some languages, .NET users are going to expect stronger typing. But I don’t think these types of things get people away from FreeSWITCH much.
No disagreement here. I would like to see these things made available by interface rather than concrete implementation. It's currently not possible to test a plugin without loading it into FS. That precludes automated testing, and leaves a pretty big round-trip to test a tweak. I'm a sloppy coder too, so I'm always introducing interesting regressions, and that's why I like doing my testing without having to bring up a full process :)
Things like making a published SOAP interface for FS seem not really related to mod_managed. They can easily be done as 3rd party plugins, or convince the core FS team that exposing via SOAP via mod_managed is the way to go. Also keep in mind that the majority of users are on Linux, so that rules out WCF and some other fun stuff that only works on the CLR – I’d say it all has to work on Mono.
This kind of stuff is definitely beyond the scope of mod_managed. Although there is a slippery slope since we're building in an extensibility model. I don't think a WCF host, or a winforms host, or any of that should be baked in. Rather, I think we should provide the hooks for adding such a thing. If somebody wants to build ESL via WCF, why should they need to leave managed code? If the module system is general enough, then such a thing should just be a module.
(BTW, I think WCF-Mono is getting there http://www.mono-project.com/WCF_Development)
Absolutely, everything in mod_managed and managed.dll should run on mono and the CLR. However, there shouldn't be any reason that a Win-only developer can't build a complete FS application framework that plugs in and only runs on Windows.
As for all the rest of it, can we talk interactively, perhaps with other users interested in mod_managed? Reading over your email, I think I’m not understanding many of the use cases that are being fixed.
I'd be very glad to get a discussion going. I definitely haven't covered all of the issues here.
-Josh
_______________________________________________ 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
_______________________________________________ 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
You make it however you want. Marshal.StructureToPtr, AllocCoTaskMem; GCHandle.Alloc/GetAddrOfPinnedObject; stackalloc (C#); Ref.pin (F#). You can get it from unmanaged code (you could just P/Invoke malloc if you want). And I think the SWIGTYPEs expose a GCHandle so you can get their pointer if you need to convert their type. If it's a complex structure that swig hasn't created, and you really want nice typed access to it, you may want to create a nice struct in C# for marshalling. -Michael From: freeswitch-users-bounces@lists.freeswitch.org [mailto:freeswitch-users-bounces@lists.freeswitch.org] On Behalf Of Josh Rivers Sent: Sunday, September 27, 2009 9:36 PM To: freeswitch-users@lists.freeswitch.org Subject: Re: [Freeswitch-users] Subscribing to events in managed C# / .NET Where does 'somePtr' come from? On Sun, Sep 27, 2009 at 4:06 PM, Michael Giagnocavo <mgg@giagnocavo.net<mailto:mgg@giagnocavo.net>> wrote: It's in the "FSUtil" class (no I'm not happy with the name). I also made it an extension method on IntPtr (I'm not a big fan of extension methods, but the code is sorta messy anyways, so it's not relatively bad.) var x = CreateSwigTypePointer<SWIGTYPE_p_int>(somePtr); Moving stuff out of the SWIG DLL removes the ability to use partial classes to extend the generated swigtypes. This is used a bit, and will be used a lot more as the managed plugin is cleaned up. For example, most of the FS APIs return string, when they should return a better representation. Also, the constructors for some of the types are internal only, and I don't really enjoy using reflection to create them. -Michael From: freeswitch-users-bounces@lists.freeswitch.org<mailto:freeswitch-users-bounces@lists.freeswitch.org> [mailto:freeswitch-users-bounces@lists.freeswitch.org<mailto:freeswitch-users-bounces@lists.freeswitch.org>] On Behalf Of Josh Rivers Sent: Saturday, September 26, 2009 11:29 PM To: freeswitch-users@lists.freeswitch.org<mailto:freeswitch-users@lists.freeswitch.org> Subject: Re: [Freeswitch-users] Subscribing to events in managed C# / .NET The ability to directly create swigtypes...that's huge! I'd love to see some examples of how to use that. I've update my refactoring to include the changes to the trunk up through r14981. I've also checked in updated binaries that should work with the latest trunk builds(I hope?) A question occurred to me: would it make any sense to push the plugin loader into a separate DLL? That way we could keep the P/Invoke layer very cleanly separated from the loader/process host/abstraction layer structures. Josh On Fri, Sep 25, 2009 at 1:13 PM, Michael Giagnocavo <mgg@giagnocavo.net<mailto:mgg@giagnocavo.net>> wrote: There is a new function I checked in a little bit ago that lets you create any of the SWIGTYPE_p_xxx types - all you need is a pointer to the memory to represent whatever it is in native land. So with that, it's actually possible to call most or all of the functions. (Yes DRK, you can now go do XML binding.) But sure, it'd be nice to make a real .NET-ish layer. Async events seems like it wouldn't be hard, assuming FreeSWITCH delivers them that way? -Michael From: freeswitch-users-bounces@lists.freeswitch.org<mailto:freeswitch-users-bounces@lists.freeswitch.org> [mailto:freeswitch-users-bounces@lists.freeswitch.org<mailto:freeswitch-users-bounces@lists.freeswitch.org>] On Behalf Of Michael Jerris Sent: Thursday, September 24, 2009 10:26 PM To: freeswitch-users@lists.freeswitch.org<mailto:freeswitch-users@lists.freeswitch.org> Subject: Re: [Freeswitch-users] Subscribing to events in managed C# / .NET There are a few other things I can think would be nice additions to mod_managed. Maybe an event handler that does not require a thread to be sitting and waiting for events trying in a loop would be nice, instead something that is triggered each time there is a certain event class triggered. Also, there has been some interest in doing full endpoint modules in mod_managed. exposing all the state handlers in .net like ways and having that all work would be quite interesting, but probably requires someone specific actually ready to write a module like that to be worthwhile. Mike On Sep 24, 2009, at 4:01 AM, Michael Giagnocavo wrote: Great - hopefully we'll meet on IRC or the conference sometime on Friday. Email me when you're on. A few questions I have: Clarity - I agree with you there, and thanks! Testability - is this even remotely practical? Looking at our FS code plugins, there's simply no way any amount of test environment code would get us to anything testable. We make tons of direct P/Invoke calls, and the whole model for what variables are set when, the state machine progression, etc. does not seem like something that we can hope to possibly model right. And it's subject to many external influences (all the modules you have loaded in FS). Logging is a pretty simple case, sure, we can make it not call FS for testing. But in a real app, it just seems that there are way too many dependencies, no? Maybe others who have apps written can chime in? Modularity - I agree there are two parts. But, I think they are pretty tightly coupled. The FS interface into unmanaged code is done via unmanaged code and is really clear: App, Api, ApiBackground. The other ways I can think of are FS-specific, such as XML binding interface and so on. But those are things we should just add to the mod_managed core and be done with. I'm thinking maybe we are talking about different things? Can you provide some user stories that we want to cover with a pluggable loader/executor/etc.? Thanks for putting up with me! -Michael From: freeswitch-users-bounces@lists.freeswitch.org<mailto:freeswitch-users-bounces@lists.freeswitch.org> [mailto:freeswitch-users-bounces@lists.freeswitch.org<mailto:freeswitch-users-bounces@lists.freeswitch.org>] On Behalf Of Josh Rivers Sent: Thursday, September 24, 2009 12:32 AM To: freeswitch-users@lists.freeswitch.org<mailto:freeswitch-users@lists.freeswitch.org> Subject: Re: [Freeswitch-users] Subscribing to events in managed C# / .NET On Wed, Sep 23, 2009 at 7:31 PM, Michael Giagnocavo <mgg@giagnocavo.net<mailto:mgg@giagnocavo.net>> wrote: Right off the bat: there can be tons of cleanup and refactoring, no doubt about that. Much of the current code is to satisfy my needs in production, which it does very well. The current base doesn't have anything wrong with it for sure, in fact, I learned a good bit about PInvoke. AppDomains, and In-Process Remoting in the last week. My refactoring had the following goals (in no particular order) - Testability - I'd really like to see a decent unit test suite on the more module so that we can change it with confidence. Also, it's been drilled into me that a testable design is a good design. - Clarity - Where possible, I extracted blocks of code that served a particular purpose so that purpose could be self-documenting in the method calls rather than mixed in. - Modularity - I wanted to make it easy to remove or add alternative behavior to the managed.dll. I'm a bit hesitant to go too far from the FreeSWITCH core as far as architecture goes. For instance, I'm not quite sure why'd we have our own managed logging subsystem that allows them to plug in other things that aren't part of FS. Either they should use the FS logging system, or use their own such as log4net. Or perhaps I don't see why we'd want this behavior. I completely agree, with the following caveats: 1) I'd like to see things testable. It's very hard to do isolation testing with classes making direct calls out to a static Log class that in turn pinvokes out to unmanaged code. 2) I'd like to allow folk to make changes to the default behavior (optimally) without recompiling managed.dll. One thing at issue here is that there are two principal purposes for managed.dll. The first is to provide an interface into unmanaged code. The second is a module/plugin extensibility framework. The first purpose should absolutely provide the thinnest layer possible. The second purpose is very likely to need a lot of change and adaptation as people come up with development models that they would like to follow in using freeswitch. The extensibility framework should be mostly managed code, coded to interfaces for mock-ability and testabiliy. It should also be able to just push it out of the way and hook your own extensibilty framework in instead. Going away from the core as far as adding .NET specific features (like look at the static ManagedSession.Originate that takes hangup delegates, or the "nice" wrapper for Log (Write and WeiteLine, with an enum instead of a string) are keeping close to the core, just adding a tiny bit of API cleanup. FreeSWITCH exposes a lot of strings, and while maybe that's important for some languages, .NET users are going to expect stronger typing. But I don't think these types of things get people away from FreeSWITCH much. No disagreement here. I would like to see these things made available by interface rather than concrete implementation. It's currently not possible to test a plugin without loading it into FS. That precludes automated testing, and leaves a pretty big round-trip to test a tweak. I'm a sloppy coder too, so I'm always introducing interesting regressions, and that's why I like doing my testing without having to bring up a full process :) Things like making a published SOAP interface for FS seem not really related to mod_managed. They can easily be done as 3rd party plugins, or convince the core FS team that exposing via SOAP via mod_managed is the way to go. Also keep in mind that the majority of users are on Linux, so that rules out WCF and some other fun stuff that only works on the CLR - I'd say it all has to work on Mono. This kind of stuff is definitely beyond the scope of mod_managed. Although there is a slippery slope since we're building in an extensibility model. I don't think a WCF host, or a winforms host, or any of that should be baked in. Rather, I think we should provide the hooks for adding such a thing. If somebody wants to build ESL via WCF, why should they need to leave managed code? If the module system is general enough, then such a thing should just be a module. (BTW, I think WCF-Mono is getting there http://www.mono-project.com/WCF_Development) Absolutely, everything in mod_managed and managed.dll should run on mono and the CLR. However, there shouldn't be any reason that a Win-only developer can't build a complete FS application framework that plugs in and only runs on Windows. As for all the rest of it, can we talk interactively, perhaps with other users interested in mod_managed? Reading over your email, I think I'm not understanding many of the use cases that are being fixed. I'd be very glad to get a discussion going. I definitely haven't covered all of the issues here. -Josh _______________________________________________ FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org<mailto: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<mailto: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<mailto: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
I don't know what we'd want to write endpoints for, so I'll leave that one alone... ;) I do, however, agree with you on the event handler idea. My work on the module system is largely a precursor to putting in some work on a pub/sub event bus in managed code. I wanted some lifecycle and exception handling control that wasn't easy in the existing dll and I wanted to be able to create it without breaking stuff for other people. My question is this: is an event bus a good thing to put in mod_managed, or should it be an optional plugin that you load in? Josh On Thu, Sep 24, 2009 at 9:26 PM, Michael Jerris <mike@jerris.com> wrote:
There are a few other things I can think would be nice additions to mod_managed. Maybe an event handler that does not require a thread to be sitting and waiting for events trying in a loop would be nice, instead something that is triggered each time there is a certain event class triggered. Also, there has been some interest in doing full endpoint modules in mod_managed. exposing all the state handlers in .net like ways and having that all work would be quite interesting, but probably requires someone specific actually ready to write a module like that to be worthwhile. Mike
On Sep 24, 2009, at 4:01 AM, Michael Giagnocavo wrote:
Great – hopefully we’ll meet on IRC or the conference sometime on Friday. Email me when you’re on.
A few questions I have:
Clarity – I agree with you there, and thanks!
Testability – is this even remotely practical? Looking at our FS code plugins, there’s simply no way any amount of test environment code would get us to anything testable. We make tons of direct P/Invoke calls, and the whole model for what variables are set when, the state machine progression, etc. does not seem like something that we can hope to possibly model right. And it’s subject to many external influences (all the modules you have loaded in FS). Logging is a pretty simple case, sure, we can make it not call FS for testing. But in a real app, it just seems that there are way too many dependencies, no? Maybe others who have apps written can chime in?
Modularity – I agree there are two parts. But, I think they are pretty tightly coupled. The FS interface into unmanaged code is done via unmanaged code and is really clear: App, Api, ApiBackground. The other ways I can think of are FS-specific, such as XML binding interface and so on. But those are things we should just add to the mod_managed core and be done with. I’m thinking maybe we are talking about different things? Can you provide some user stories that we want to cover with a pluggable loader/executor/etc.? Thanks for putting up with me!
-Michael
*From:* freeswitch-users-bounces@lists.freeswitch.org [mailto: freeswitch-users-bounces@lists.freeswitch.org] *On Behalf Of *Josh Rivers *Sent:* Thursday, September 24, 2009 12:32 AM *To:* freeswitch-users@lists.freeswitch.org *Subject:* Re: [Freeswitch-users] Subscribing to events in managed C# / .NET
On Wed, Sep 23, 2009 at 7:31 PM, Michael Giagnocavo <mgg@giagnocavo.net> wrote:
Right off the bat: there can be tons of cleanup and refactoring, no doubt about that. Much of the current code is to satisfy my needs in production, which it does very well. The current base doesn't have anything wrong with it for sure, in fact, I learned a good bit about PInvoke. AppDomains, and In-Process Remoting in the last week.
My refactoring had the following goals (in no particular order) - Testability - I'd really like to see a decent unit test suite on the more module so that we can change it with confidence. Also, it's been drilled into me that a testable design is a good design. - Clarity - Where possible, I extracted blocks of code that served a particular purpose so that purpose could be self-documenting in the method calls rather than mixed in. - Modularity - I wanted to make it easy to remove or add alternative behavior to the managed.dll.
I’m a bit hesitant to go too far from the FreeSWITCH core as far as architecture goes. For instance, I’m not quite sure why’d we have our own managed logging subsystem that allows them to plug in other things that aren’t part of FS. Either they should use the FS logging system, or use their own such as log4net. Or perhaps I don’t see why we’d want this behavior.
I completely agree, with the following caveats: 1) I'd like to see things testable. It's very hard to do isolation testing with classes making direct calls out to a static Log class that in turn pinvokes out to unmanaged code. 2) I'd like to allow folk to make changes to the default behavior (optimally) without recompiling managed.dll.
One thing at issue here is that there are two principal purposes for managed.dll. The first is to provide an interface into unmanaged code. The second is a module/plugin extensibility framework. The first purpose should absolutely provide the thinnest layer possible. The second purpose is very likely to need a lot of change and adaptation as people come up with development models that they would like to follow in using freeswitch. The extensibility framework should be mostly managed code, coded to interfaces for mock-ability and testabiliy. It should also be able to just push it out of the way and hook your own extensibilty framework in instead.
Going away from the core as far as adding .NET specific features (like look at the static ManagedSession.Originate that takes hangup delegates, or the “nice” wrapper for Log (Write and WeiteLine, with an enum instead of a string) are keeping close to the core, just adding a tiny bit of API cleanup. FreeSWITCH exposes a lot of strings, and while maybe that’s important for some languages, .NET users are going to expect stronger typing. But I don’t think these types of things get people away from FreeSWITCH much.
No disagreement here. I would like to see these things made available by interface rather than concrete implementation. It's currently not possible to test a plugin without loading it into FS. That precludes automated testing, and leaves a pretty big round-trip to test a tweak. I'm a sloppy coder too, so I'm always introducing interesting regressions, and that's why I like doing my testing without having to bring up a full process :)
Things like making a published SOAP interface for FS seem not really related to mod_managed. They can easily be done as 3rd party plugins, or convince the core FS team that exposing via SOAP via mod_managed is the way to go. Also keep in mind that the majority of users are on Linux, so that rules out WCF and some other fun stuff that only works on the CLR – I’d say it all has to work on Mono.
This kind of stuff is definitely beyond the scope of mod_managed. Although there is a slippery slope since we're building in an extensibility model. I don't think a WCF host, or a winforms host, or any of that should be baked in. Rather, I think we should provide the hooks for adding such a thing. If somebody wants to build ESL via WCF, why should they need to leave managed code? If the module system is general enough, then such a thing should just be a module. (BTW, I think WCF-Mono is getting there http://www.mono-project.com/WCF_Development) Absolutely, everything in mod_managed and managed.dll should run on mono and the CLR. However, there shouldn't be any reason that a Win-only developer can't build a complete FS application framework that plugs in and only runs on Windows.
As for all the rest of it, can we talk interactively, perhaps with other users interested in mod_managed? Reading over your email, I think I’m not understanding many of the use cases that are being fixed.
I'd be very glad to get a discussion going. I definitely haven't covered all of the issues here.
-Josh
_______________________________________________ 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
Sorry for fading off for a few days. Having too much fun doing stuff! A few responses: On Thu, Sep 24, 2009 at 1:01 AM, Michael Giagnocavo <mgg@giagnocavo.net>wrote:
A few questions I have:
Testability – is this even remotely practical?
I've seen three areas of testability: 1) Interop 2) Module Extensibility Framework 3) Modules and Plugins The interop testability picture is not an area I'm very familiar. I imagine you could write a native mod_managed.dll testing shim and test against that. I think this would have some limited value. It would confirm that interop layers behaved as expected, but not much more. The biggest values would be a) verifying that the api doesn't change accidentally, and b) providing a good way of adding bug-solution cases when the behavior of the core is causing a failure that we need to provide some padding around. The extensibility portion is very easy to write tests for. The module loader framework that I've refactored out of your code is completely stupid about the unmanaged code. It blindly passes the pointers through to the consumers that want them, and all of the module loader responsibilities are in managed code and mostly coded to interface. Very easy to mock and test. Finally the plugin testability story. Currently this is harder, since the plugins are written to talk to a lot of static methods and direct unmanaged types. As things evolve, I'd want to create a updated plugin interface that passes all the interop points by interface. The unit testing responsibility for an app or api plugin should primarily be that for a given set of inputs or responses, it makes a specified set of calls. That should be possible to mock and test in managed code if we provide a thin managed interface layer over the P/Invoke|SWIG layer. I'm currently writing a plugin that does just this, but I have the interface layer inside my code. Not everyone should have to write their own though?
Modularity – I agree there are two parts. But, I think they are pretty tightly coupled. The FS interface into unmanaged code is done via unmanaged code and is really clear: App, Api, ApiBackground. The other ways I can think of are FS-specific, such as XML binding interface and so on. But those are things we should just add to the mod_managed core and be done with. I’m thinking maybe we are talking about different things? Can you provide some user stories that we want to cover with a pluggable loader/executor/etc.?
I'm going to be a bit long-winded here. I hope I can clarify my intent, because I think I've been unclear on it so far. A) Philosophy: I have two principal concepts that are guiding me in my push towards modularity. 1) Single Responsibility Principal: "Each class or code file should only have one reason to change." I don't think I'm quite here in the code I've shown you, but it's getting closer. (I could definitely use help.) The idea here is that the class that monitors the plugin directory shouldn't also load the files. The class that loads the files shouldn't be responsible for configuring and creating app domains. Neither of those classes should have concrete logging code in them. The good thing about this is that you don't have to worry about breaking the loader when you change the watcher, and vice-versa. If we later decide to change the watcher so that it only checks for updates manually, we don't need to even let the loader know. 2) Open-Closed Principal: "Classes should be open for extension and closed for modification." The idea here is that once we've written a working class that has it's bugs ironed out and it's unit tests written, we shouldn't (ideally) ever need to change it. If we need a new behavior, we can just subclass the original, or implement the same interface, or whatever, and use the new class instead of the old one. If everything is nice an loosely coupled, we can just slide the new implementation in for improved behavior without changing the old one. What this means for the module system is that we can create new functionality without breaking old functionality. B) Actual uses: (Please note, that in most cases, I don't think that mod_managed needs to build out these functions, rather, I think mod_managed should "get out of the way" and let developers plug in what they want) 1) Commercial PBX Developer/Distributor: Case: Say I want to write my own FreeSWITCH distro/UI/packaged software on Windows, and I want to do all of my development in managed code and I don't care about plugins or anything. Answer: recompile my managed.dll with just a few changed lines in Loader.cs and your code controls everything coming into mod_managed. Ultimate power. Roll your own. Use it to launch a UI. Go nutz. 2) Complicated interwoven plugins: Case: I want to write a bunch of plugin dlls and have them all cross-communicate and share caches and statics. Answer: provide your own implementation of IModuleLoader and plug it into the registry. Now you can eliminate all of those pesky appdomains that prevent your cross-plugin communication. Sure, you'll have to reload the switch when you want to reload a plugin, but that's not such a big deal. (Or if it is, you can try loading all your plugins into the same appdomain and reload that every time. It's up to you.) 3) New and Improved(TM) Plugin Model Case: You and I decide that the way we're calling the current plugins, passing them contexts and sessions, is completely dated and we want to change it to something new. Answer: instead of changing the current plugin api, we just add a set of loaders and handlers for the New and Improved(TM) plugin interfaces. We roll that into the managed.dll. Now folk can write old plugins and new plugins, don't need to recompile, and everybody's happy. In a year or two we can start deprecating the old interfaces and get people moving to the modern ones, if we feel strongly about it. 4) Aspect oriented plugins Case: I want to report every time a managed api call is made to a web service, and I don't want to change the existing plugin code. Answer: write a new Execute and ExecuteBackground handler, and register it. Have your handler fire for _all_ arguments, rather than filtering on the first argument. Send your logging info off with a web service call. These are all things that can be done with the structure I've outlined. What may be more intersting than all of these, later, is plugins that interact with the event model to provide in-process ESL-type control of the FS.
Thanks for putting up with me!
Thank _you_ for helping me get my thoughts out more clearly. Josh
Surely this is because you are calling ev.serialized_string and ev is null if there is not event waiting? i.e. con.pop(0); returns null if no event is waiting. Therefore if(ev != null) Log.WriteLine(LogLevel.Notice, "Event: " + ev.serialized_string); would work, alternatively calling Event ev = con.pop(1); would block until an event is available - and therefore ev cannot be null.... On Wed, Sep 9, 2009 at 2:01 PM, Josh Rivers <josh@radianttiger.com> wrote:
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:
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:
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-tp3573619p361319... 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
The ILoadNotifcationPlugin is run in the appdomain created for the plugin, so it should only get unloaded when the plugin gets reloaded. Spawning threads here should work, it's definitely the intention that if you need a long-running process, you can fire it up on load and have it work. As to the race condition on reload, mod_managed should do this: - Load the new plugin into a new appdomain - Remove the entry points to the old appdomain, add entries to the new one - Old appdomain now stays alive until foreground API and APP calls finish So, you can have many versions of the same plugin active in memory. I probably need to go break compatibility and make ILoadWhateverPlugin be something like IPluginController and allow it to return loading options to control the mod_managed behavior, as well as allow it to delay shutdown of the appdomain. Part of the question is: how many people out there need compatibility, or can we go breaking all of you and make you recompile? :) Although, IIRC, if you handle AppDomain.Unload (or whatever it is), it will stay alive until your event handler completes. Hope that helps a bit. -Michael -----Original Message----- From: freeswitch-users-bounces@lists.freeswitch.org [mailto:freeswitch-users-bounces@lists.freeswitch.org] On Behalf Of Jeff Lenk Sent: Wednesday, September 09, 2009 1:57 PM To: freeswitch-users@lists.freeswitch.org Subject: Re: [Freeswitch-users] Subscribing to events in managed C# / .NET 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:
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-tp3573619p361319... 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
Thanks Michael, I was seeing some strange behavior in a static compiled dll versus dynamically loaded and compiled scripts. This code when used in a dll was blowing up when a thread was spawned in the ILoadNotificationPlugin.Load but is not when used in a dynamically loaded script(csx). Code: ThreadPool.QueueUserWorkItem((o) => { Log.WriteLine(LogLevel.Notice, "Thread Starting. "); while (true) { Thread.Sleep(10000); Log.WriteLine(LogLevel.Notice, "Thread Running. "); } }); I will look into this more later. Jeff Michael Giagnocavo wrote:
The ILoadNotifcationPlugin is run in the appdomain created for the plugin, so it should only get unloaded when the plugin gets reloaded. Spawning threads here should work, it's definitely the intention that if you need a long-running process, you can fire it up on load and have it work.
As to the race condition on reload, mod_managed should do this:
- Load the new plugin into a new appdomain - Remove the entry points to the old appdomain, add entries to the new one - Old appdomain now stays alive until foreground API and APP calls finish
So, you can have many versions of the same plugin active in memory.
I probably need to go break compatibility and make ILoadWhateverPlugin be something like IPluginController and allow it to return loading options to control the mod_managed behavior, as well as allow it to delay shutdown of the appdomain. Part of the question is: how many people out there need compatibility, or can we go breaking all of you and make you recompile? :)
Although, IIRC, if you handle AppDomain.Unload (or whatever it is), it will stay alive until your event handler completes.
Hope that helps a bit.
-Michael
-----Original Message----- From: freeswitch-users-bounces@lists.freeswitch.org [mailto:freeswitch-users-bounces@lists.freeswitch.org] On Behalf Of Jeff Lenk Sent: Wednesday, September 09, 2009 1:57 PM To: freeswitch-users@lists.freeswitch.org Subject: Re: [Freeswitch-users] Subscribing to events in managed C# / .NET
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:
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-tp3573619p361319... 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-tp3573619p361752... Sent from the freeswitch-users mailing list archive at Nabble.com.
Were both of them actually loading completely? As in, they had an app or api plugin? -----Original Message----- From: freeswitch-users-bounces@lists.freeswitch.org [mailto:freeswitch-users-bounces@lists.freeswitch.org] On Behalf Of Jeff Lenk Sent: Thursday, September 10, 2009 8:34 AM To: freeswitch-users@lists.freeswitch.org Subject: Re: [Freeswitch-users] Subscribing to events in managed C# / .NET Thanks Michael, I was seeing some strange behavior in a static compiled dll versus dynamically loaded and compiled scripts. This code when used in a dll was blowing up when a thread was spawned in the ILoadNotificationPlugin.Load but is not when used in a dynamically loaded script(csx). Code: ThreadPool.QueueUserWorkItem((o) => { Log.WriteLine(LogLevel.Notice, "Thread Starting. "); while (true) { Thread.Sleep(10000); Log.WriteLine(LogLevel.Notice, "Thread Running. "); } }); I will look into this more later. Jeff Michael Giagnocavo wrote:
The ILoadNotifcationPlugin is run in the appdomain created for the plugin, so it should only get unloaded when the plugin gets reloaded. Spawning threads here should work, it's definitely the intention that if you need a long-running process, you can fire it up on load and have it work.
As to the race condition on reload, mod_managed should do this:
- Load the new plugin into a new appdomain - Remove the entry points to the old appdomain, add entries to the new one - Old appdomain now stays alive until foreground API and APP calls finish
So, you can have many versions of the same plugin active in memory.
I probably need to go break compatibility and make ILoadWhateverPlugin be something like IPluginController and allow it to return loading options to control the mod_managed behavior, as well as allow it to delay shutdown of the appdomain. Part of the question is: how many people out there need compatibility, or can we go breaking all of you and make you recompile? :)
Although, IIRC, if you handle AppDomain.Unload (or whatever it is), it will stay alive until your event handler completes.
Hope that helps a bit.
-Michael
-----Original Message----- From: freeswitch-users-bounces@lists.freeswitch.org [mailto:freeswitch-users-bounces@lists.freeswitch.org] On Behalf Of Jeff Lenk Sent: Wednesday, September 09, 2009 1:57 PM To: freeswitch-users@lists.freeswitch.org Subject: Re: [Freeswitch-users] Subscribing to events in managed C# / .NET
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:
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-tp3573619p361319... 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-tp3573619p361752... 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
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> 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> wrote:
Yes! public class LoadDemo : ILoadNotificationPlugin { public bool Load() { Log.WriteLine(LogLevel.Notice, "LoadDemo running."); return true; } }
this example is from Michael Giagnocavo's Demo.csx which you can find into the mod_managed svn.
And let me add that works like a charm :)
Ciao, Raffaele
On Sun, Sep 6, 2009 at 22:50, Josh Rivers <josh@radianttiger.com>wrote:
Is there a way to start this when FreeSWITCH starts? The lua and perl modules have a 'startup-script' configuration preference. Is there something similar in mod_managed? Or is there a way to have an api command executed at a startup?
<quote author="Phillip Jones"> Exactly what I was after - thank you!
On Thu, Sep 3, 2009 at 1:54 PM, Jeff Lenk <jlenk@frontiernet.net> wrote:
try something like this
EventConsumer con = new EventConsumer("all", ""); Event ev = con.pop(0);
see lua sample - http://wiki.freeswitch.org/wiki/Lua#freeswitch.EventConsumer
Phillip Jones-2 wrote:
Hi there,
mod_managed exposes EventReceivedFunction such that:
Session.EventReceivedFunction = (e) => { Log.WriteLine(LogLevel.Alert, "Received Event {0}",
e.ToString());
return ""; };
should trap all events to which i subscribe.
But how do I subscribe to events? What is the .NET / managed
equivalent
of:
switch_event_bind(const char *id, switch_event_types_t event, const char *subclass_name, switch_event_callback_t callback, void *user_data);
Thank you!
_______________________________________________ FreeSWITCH-users mailing list FreeSWITCH-users@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
_______________________________________________ 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
That's what his sample does, but he says it crashes. 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 10:08 AM To: 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<mailto: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<mailto: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 :) Ciao, Raffaele On Sun, Sep 6, 2009 at 22:50, Josh Rivers <josh@radianttiger.com<mailto:josh@radianttiger.com>> wrote: Is there a way to start this when FreeSWITCH starts? The lua and perl modules have a 'startup-script' configuration preference. Is there something similar in mod_managed? Or is there a way to have an api command executed at a startup? <quote author="Phillip Jones"> Exactly what I was after - thank you! On Thu, Sep 3, 2009 at 1:54 PM, Jeff Lenk <jlenk@frontiernet.net<mailto:jlenk@frontiernet.net>> wrote:
try something like this
EventConsumer con = new EventConsumer("all", ""); Event ev = con.pop(0);
see lua sample - http://wiki.freeswitch.org/wiki/Lua#freeswitch.EventConsumer
Phillip Jones-2 wrote:
Hi there,
mod_managed exposes EventReceivedFunction such that:
Session.EventReceivedFunction = (e) => { Log.WriteLine(LogLevel.Alert, "Received Event {0}", e.ToString()); return ""; };
should trap all events to which i subscribe.
But how do I subscribe to events? What is the .NET / managed equivalent of:
switch_event_bind(const char *id, switch_event_types_t event, const char *subclass_name, switch_event_callback_t callback, void *user_data);
Thank you!
_______________________________________________ FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org<mailto: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<http://www.freeswitch.org/> _______________________________________________ FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org<mailto: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<http://www.freeswitch.org/> _______________________________________________ FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org<mailto: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<http://www.freeswitch.org/>
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> wrote:
That’s what his sample does, but he says it crashes.
*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 10:08 AM
*To:* 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> 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> wrote:
Yes!
public class LoadDemo : ILoadNotificationPlugin {
public bool Load() {
Log.WriteLine(LogLevel.Notice, "LoadDemo running.");
return true;
}
}
this example is from Michael Giagnocavo's Demo.csx which you can find into the mod_managed svn.
And let me add that works like a charm :)
Ciao,
Raffaele
On Sun, Sep 6, 2009 at 22:50, Josh Rivers <josh@radianttiger.com> wrote:
Is there a way to start this when FreeSWITCH starts? The lua and perl modules have a 'startup-script' configuration preference. Is there something similar in mod_managed? Or is there a way to have an api command executed at a startup?
<quote author="Phillip Jones">
Exactly what I was after - thank you!
On Thu, Sep 3, 2009 at 1:54 PM, Jeff Lenk <jlenk@frontiernet.net> wrote:
try something like this
EventConsumer con = new EventConsumer("all", "");
Event ev = con.pop(0);
see lua sample -
http://wiki.freeswitch.org/wiki/Lua#freeswitch.EventConsumer
Phillip Jones-2 wrote:
Hi there,
mod_managed exposes EventReceivedFunction such that:
Session.EventReceivedFunction = (e) =>
{
Log.WriteLine(LogLevel.Alert, "Received Event {0}",
e.ToString());
return "";
};
should trap all events to which i subscribe.
But how do I subscribe to events? What is the .NET / managed equivalent
of:
switch_event_bind(const char *id, switch_event_types_t event, const char
*subclass_name, switch_event_callback_t callback, void *user_data);
Thank you!
_______________________________________________ FreeSWITCH-users mailing list FreeSWITCH-users@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
_______________________________________________ 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
" 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<mailto:mgg@giagnocavo.net>> wrote: That's what his sample does, but he says it crashes. From: freeswitch-users-bounces@lists.freeswitch.org<mailto:freeswitch-users-bounces@lists.freeswitch.org> [mailto:freeswitch-users-bounces@lists.freeswitch.org<mailto: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<mailto: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<mailto: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<mailto: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 :) Ciao, Raffaele On Sun, Sep 6, 2009 at 22:50, Josh Rivers <josh@radianttiger.com<mailto:josh@radianttiger.com>> wrote: Is there a way to start this when FreeSWITCH starts? The lua and perl modules have a 'startup-script' configuration preference. Is there something similar in mod_managed? Or is there a way to have an api command executed at a startup? <quote author="Phillip Jones"> Exactly what I was after - thank you! On Thu, Sep 3, 2009 at 1:54 PM, Jeff Lenk <jlenk@frontiernet.net<mailto:jlenk@frontiernet.net>> wrote:
try something like this
EventConsumer con = new EventConsumer("all", "");
Event ev = con.pop(0);
see lua sample -
http://wiki.freeswitch.org/wiki/Lua#freeswitch.EventConsumer
Phillip Jones-2 wrote:
Hi there,
mod_managed exposes EventReceivedFunction such that:
Session.EventReceivedFunction = (e) =>
{
Log.WriteLine(LogLevel.Alert, "Received Event {0}", e.ToString());
return "";
};
should trap all events to which i subscribe.
But how do I subscribe to events? What is the .NET / managed equivalent
of:
switch_event_bind(const char *id, switch_event_types_t event, const char
*subclass_name, switch_event_callback_t callback, void *user_data);
Thank you!
_______________________________________________ FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org<mailto: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<http://www.freeswitch.org/> _______________________________________________ FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org<mailto: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<http://www.freeswitch.org/> _______________________________________________ FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org<mailto: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<http://www.freeswitch.org/> _______________________________________________ FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org<mailto: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
Oh, I see... all those years wasted doing java stuff! :D On Tue, Sep 8, 2009 at 22:46, Michael Giagnocavo <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 [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> wrote:
That’s what his sample does, but he says it crashes.
*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 10:08 AM
*To:* 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> 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> wrote:
Yes!
public class LoadDemo : ILoadNotificationPlugin {
public bool Load() {
Log.WriteLine(LogLevel.Notice, "LoadDemo running.");
return true;
}
}
this example is from Michael Giagnocavo's Demo.csx which you can find into the mod_managed svn.
And let me add that works like a charm :)
Ciao,
Raffaele
On Sun, Sep 6, 2009 at 22:50, Josh Rivers <josh@radianttiger.com> wrote:
Is there a way to start this when FreeSWITCH starts? The lua and perl modules have a 'startup-script' configuration preference. Is there something similar in mod_managed? Or is there a way to have an api command executed at a startup?
<quote author="Phillip Jones">
Exactly what I was after - thank you!
On Thu, Sep 3, 2009 at 1:54 PM, Jeff Lenk <jlenk@frontiernet.net> wrote:
try something like this
EventConsumer con = new EventConsumer("all", "");
Event ev = con.pop(0);
see lua sample -
http://wiki.freeswitch.org/wiki/Lua#freeswitch.EventConsumer
Phillip Jones-2 wrote:
Hi there,
mod_managed exposes EventReceivedFunction such that:
Session.EventReceivedFunction = (e) =>
{
Log.WriteLine(LogLevel.Alert, "Received Event {0}",
e.ToString());
return "";
};
should trap all events to which i subscribe.
But how do I subscribe to events? What is the .NET / managed equivalent
of:
switch_event_bind(const char *id, switch_event_types_t event, const char
*subclass_name, switch_event_callback_t callback, void *user_data);
Thank you!
_______________________________________________ FreeSWITCH-users mailing list FreeSWITCH-users@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
_______________________________________________ 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
_______________________________________________ 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
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> wrote:
Oh, I see... all those years wasted doing java stuff! :D
On Tue, Sep 8, 2009 at 22:46, Michael Giagnocavo <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 [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> wrote:
That’s what his sample does, but he says it crashes.
*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 10:08 AM
*To:* 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> 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> wrote:
Yes!
public class LoadDemo : ILoadNotificationPlugin {
public bool Load() {
Log.WriteLine(LogLevel.Notice, "LoadDemo running.");
return true;
}
}
this example is from Michael Giagnocavo's Demo.csx which you can find into the mod_managed svn.
And let me add that works like a charm :)
Ciao,
Raffaele
On Sun, Sep 6, 2009 at 22:50, Josh Rivers <josh@radianttiger.com> wrote:
Is there a way to start this when FreeSWITCH starts? The lua and perl modules have a 'startup-script' configuration preference. Is there something similar in mod_managed? Or is there a way to have an api command executed at a startup?
<quote author="Phillip Jones">
Exactly what I was after - thank you!
On Thu, Sep 3, 2009 at 1:54 PM, Jeff Lenk <jlenk@frontiernet.net> wrote:
try something like this
EventConsumer con = new EventConsumer("all", "");
Event ev = con.pop(0);
see lua sample -
http://wiki.freeswitch.org/wiki/Lua#freeswitch.EventConsumer
Phillip Jones-2 wrote:
Hi there,
mod_managed exposes EventReceivedFunction such that:
Session.EventReceivedFunction = (e) =>
{
Log.WriteLine(LogLevel.Alert, "Received Event {0}",
e.ToString());
return "";
};
should trap all events to which i subscribe.
But how do I subscribe to events? What is the .NET / managed equivalent
of:
switch_event_bind(const char *id, switch_event_types_t event, const char
*subclass_name, switch_event_callback_t callback, void *user_data);
Thank you!
_______________________________________________ FreeSWITCH-users mailing list FreeSWITCH-users@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
_______________________________________________ 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
_______________________________________________ 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
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<mailto:raffaele.p.guidi@gmail.com>> wrote: Oh, I see... all those years wasted doing java stuff! :D On Tue, Sep 8, 2009 at 22:46, Michael Giagnocavo <mgg@giagnocavo.net<mailto: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<mailto:freeswitch-users-bounces@lists.freeswitch.org> [mailto: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<mailto: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<mailto:mgg@giagnocavo.net>> wrote: That's what his sample does, but he says it crashes. From: freeswitch-users-bounces@lists.freeswitch.org<mailto:freeswitch-users-bounces@lists.freeswitch.org> [mailto:freeswitch-users-bounces@lists.freeswitch.org<mailto: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<mailto: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<mailto: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<mailto: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 :) Ciao, Raffaele On Sun, Sep 6, 2009 at 22:50, Josh Rivers <josh@radianttiger.com<mailto:josh@radianttiger.com>> wrote: Is there a way to start this when FreeSWITCH starts? The lua and perl modules have a 'startup-script' configuration preference. Is there something similar in mod_managed? Or is there a way to have an api command executed at a startup? <quote author="Phillip Jones"> Exactly what I was after - thank you! On Thu, Sep 3, 2009 at 1:54 PM, Jeff Lenk <jlenk@frontiernet.net<mailto:jlenk@frontiernet.net>> wrote:
try something like this
EventConsumer con = new EventConsumer("all", "");
Event ev = con.pop(0);
see lua sample -
http://wiki.freeswitch.org/wiki/Lua#freeswitch.EventConsumer
Phillip Jones-2 wrote:
Hi there,
mod_managed exposes EventReceivedFunction such that:
Session.EventReceivedFunction = (e) =>
{
Log.WriteLine(LogLevel.Alert, "Received Event {0}", e.ToString());
return "";
};
should trap all events to which i subscribe.
But how do I subscribe to events? What is the .NET / managed equivalent
of:
switch_event_bind(const char *id, switch_event_types_t event, const char
*subclass_name, switch_event_callback_t callback, void *user_data);
Thank you!
_______________________________________________ FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org<mailto: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<http://www.freeswitch.org/> _______________________________________________ FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org<mailto: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<http://www.freeswitch.org/> _______________________________________________ FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org<mailto: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<http://www.freeswitch.org/> _______________________________________________ FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org<mailto: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<mailto: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<mailto: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
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>wrote:
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> wrote:
Oh, I see... all those years wasted doing java stuff! :D
On Tue, Sep 8, 2009 at 22:46, Michael Giagnocavo <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 [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> wrote:
That’s what his sample does, but he says it crashes.
*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 10:08 AM
*To:* 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> 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> wrote:
Yes!
public class LoadDemo : ILoadNotificationPlugin {
public bool Load() {
Log.WriteLine(LogLevel.Notice, "LoadDemo running.");
return true;
}
}
this example is from Michael Giagnocavo's Demo.csx which you can find into the mod_managed svn.
And let me add that works like a charm :)
Ciao,
Raffaele
On Sun, Sep 6, 2009 at 22:50, Josh Rivers <josh@radianttiger.com> wrote:
Is there a way to start this when FreeSWITCH starts? The lua and perl modules have a 'startup-script' configuration preference. Is there something similar in mod_managed? Or is there a way to have an api command executed at a startup?
<quote author="Phillip Jones">
Exactly what I was after - thank you!
On Thu, Sep 3, 2009 at 1:54 PM, Jeff Lenk <jlenk@frontiernet.net> wrote:
try something like this
EventConsumer con = new EventConsumer("all", "");
Event ev = con.pop(0);
see lua sample -
http://wiki.freeswitch.org/wiki/Lua#freeswitch.EventConsumer
Phillip Jones-2 wrote:
Hi there,
mod_managed exposes EventReceivedFunction such that:
Session.EventReceivedFunction = (e) =>
{
Log.WriteLine(LogLevel.Alert, "Received Event {0}",
e.ToString());
return "";
};
should trap all events to which i subscribe.
But how do I subscribe to events? What is the .NET / managed equivalent
of:
switch_event_bind(const char *id, switch_event_types_t event, const char
*subclass_name, switch_event_callback_t callback, void *user_data);
Thank you!
_______________________________________________ FreeSWITCH-users mailing list FreeSWITCH-users@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
_______________________________________________ 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
_______________________________________________ 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
_______________________________________________ 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
"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 On 8-Sep-09, at 10:46 PM, Josh Rivers wrote:
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> wrote: 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
wrote:
Oh, I see... all those years wasted doing java stuff! :D
On Tue, Sep 8, 2009 at 22:46, Michael Giagnocavo <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 [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> wrote:
That’s what his sample does, but he says it crashes.
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 10:08 AM
To: 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> 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
wrote:
Yes!
public class LoadDemo : ILoadNotificationPlugin {
public bool Load() {
Log.WriteLine(LogLevel.Notice, "LoadDemo running.");
return true;
}
}
this example is from Michael Giagnocavo's Demo.csx which you can find into the mod_managed svn.
And let me add that works like a charm :)
Ciao,
Raffaele
On Sun, Sep 6, 2009 at 22:50, Josh Rivers <josh@radianttiger.com> wrote:
Is there a way to start this when FreeSWITCH starts? The lua and perl modules have a 'startup-script' configuration preference. Is there something similar in mod_managed? Or is there a way to have an api command executed at a startup?
<quote author="Phillip Jones">
Exactly what I was after - thank you!
On Thu, Sep 3, 2009 at 1:54 PM, Jeff Lenk <jlenk@frontiernet.net> wrote:
try something like this
EventConsumer con = new EventConsumer("all", "");
Event ev = con.pop(0);
see lua sample -
http://wiki.freeswitch.org/wiki/Lua#freeswitch.EventConsumer
Phillip Jones-2 wrote:
Hi there,
mod_managed exposes EventReceivedFunction such that:
Session.EventReceivedFunction = (e) =>
{
Log.WriteLine(LogLevel.Alert, "Received Event {0}",
e.ToString());
return "";
};
should trap all events to which i subscribe.
But how do I subscribe to events? What is the .NET / managed equivalent
of:
switch_event_bind(const char *id, switch_event_types_t event, const char
*subclass_name, switch_event_callback_t callback, void *user_data);
Thank you!
_______________________________________________ FreeSWITCH-users mailing list FreeSWITCH-users@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
_______________________________________________ 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
_______________________________________________ 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
_______________________________________________ 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
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> 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> wrote:
Yes! public class LoadDemo : ILoadNotificationPlugin { public bool Load() { Log.WriteLine(LogLevel.Notice, "LoadDemo running."); return true; } }
this example is from Michael Giagnocavo's Demo.csx which you can find into the mod_managed svn.
And let me add that works like a charm :)
Ciao, Raffaele
On Sun, Sep 6, 2009 at 22:50, Josh Rivers <josh@radianttiger.com> wrote:
Is there a way to start this when FreeSWITCH starts? The lua and perl modules have a 'startup-script' configuration preference. Is there something similar in mod_managed? Or is there a way to have an api command executed at a startup?
<quote author="Phillip Jones"> Exactly what I was after - thank you!
On Thu, Sep 3, 2009 at 1:54 PM, Jeff Lenk <jlenk@frontiernet.net> wrote:
try something like this
EventConsumer con = new EventConsumer("all", ""); Event ev = con.pop(0);
see lua sample - http://wiki.freeswitch.org/wiki/Lua#freeswitch.EventConsumer
Phillip Jones-2 wrote:
Hi there,
mod_managed exposes EventReceivedFunction such that:
Session.EventReceivedFunction = (e) => { Log.WriteLine(LogLevel.Alert, "Received Event {0}",
e.ToString());
return ""; };
should trap all events to which i subscribe.
But how do I subscribe to events? What is the .NET / managed
equivalent
of:
switch_event_bind(const char *id, switch_event_types_t event, const char *subclass_name, switch_event_callback_t callback, void *user_data);
Thank you!
_______________________________________________ FreeSWITCH-users mailing list FreeSWITCH-users@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
_______________________________________________ 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
Yeah, probably just using con.pop(1) - that waits for an event to be caught, instead than con.pop(0), thus avoiding "sleeps" would do the trick On Tue, Sep 8, 2009 at 20:12, Phillip Jones <pjintheusa@gmail.com> wrote:
What is:
freeswitch.msleep(100);
Why aren't you using Thread.Sleep?
On Tue, Sep 8, 2009 at 2:21 AM, Josh Rivers <josh@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> wrote:
Yes! public class LoadDemo : ILoadNotificationPlugin { public bool Load() { Log.WriteLine(LogLevel.Notice, "LoadDemo running."); return true; } }
this example is from Michael Giagnocavo's Demo.csx which you can find into the mod_managed svn.
And let me add that works like a charm :)
Ciao, Raffaele
On Sun, Sep 6, 2009 at 22:50, Josh Rivers <josh@radianttiger.com> wrote:
Is there a way to start this when FreeSWITCH starts? The lua and perl modules have a 'startup-script' configuration preference. Is there something similar in mod_managed? Or is there a way to have an api command executed at a startup?
<quote author="Phillip Jones"> Exactly what I was after - thank you!
On Thu, Sep 3, 2009 at 1:54 PM, Jeff Lenk <jlenk@frontiernet.net> wrote:
try something like this
EventConsumer con = new EventConsumer("all", ""); Event ev = con.pop(0);
see lua sample - http://wiki.freeswitch.org/wiki/Lua#freeswitch.EventConsumer
Phillip Jones-2 wrote:
Hi there,
mod_managed exposes EventReceivedFunction such that:
Session.EventReceivedFunction = (e) => { Log.WriteLine(LogLevel.Alert, "Received Event {0}",
e.ToString());
return ""; };
should trap all events to which i subscribe.
But how do I subscribe to events? What is the .NET / managed
equivalent
of:
switch_event_bind(const char *id, switch_event_types_t event, const char *subclass_name, switch_event_callback_t callback, void *user_data);
Thank you!
_______________________________________________ FreeSWITCH-users mailing list FreeSWITCH-users@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
_______________________________________________ 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
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> wrote:
What is:
freeswitch.msleep(100);
Why aren't you using Thread.Sleep?
On Tue, Sep 8, 2009 at 2:21 AM, Josh Rivers <josh@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> wrote:
Yes! public class LoadDemo : ILoadNotificationPlugin { public bool Load() { Log.WriteLine(LogLevel.Notice, "LoadDemo running."); return true; } }
this example is from Michael Giagnocavo's Demo.csx which you can find into the mod_managed svn.
And let me add that works like a charm :)
Ciao, Raffaele
On Sun, Sep 6, 2009 at 22:50, Josh Rivers <josh@radianttiger.com> wrote:
Is there a way to start this when FreeSWITCH starts? The lua and perl modules have a 'startup-script' configuration preference. Is there something similar in mod_managed? Or is there a way to have an api command executed at a startup?
<quote author="Phillip Jones"> Exactly what I was after - thank you!
On Thu, Sep 3, 2009 at 1:54 PM, Jeff Lenk <jlenk@frontiernet.net> wrote:
try something like this
EventConsumer con = new EventConsumer("all", ""); Event ev = con.pop(0);
see lua sample - http://wiki.freeswitch.org/wiki/Lua#freeswitch.EventConsumer
Phillip Jones-2 wrote:
Hi there,
mod_managed exposes EventReceivedFunction such that:
Session.EventReceivedFunction = (e) => { Log.WriteLine(LogLevel.Alert, "Received Event {0}",
e.ToString());
return ""; };
should trap all events to which i subscribe.
But how do I subscribe to events? What is the .NET / managed
equivalent
of:
switch_event_bind(const char *id, switch_event_types_t event, const char *subclass_name, switch_event_callback_t callback, void *user_data);
Thank you!
_______________________________________________ FreeSWITCH-users mailing list FreeSWITCH-users@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
_______________________________________________ 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
participants (10)
-
Henk Maaijen
-
Jeff Lenk
-
Josh Rivers
-
João Mesquita
-
Mathieu Rene
-
Michael Collins
-
Michael Giagnocavo
-
Michael Jerris
-
Phillip Jones
-
Raffaele P. Guidi