mod_managed - beginner's question about an event listener module
I've looked at mod_managed documentation and can see how to write an API command or a dialplan application, but could you give me a hint how to implement an automatically starting 'background' service that will listen to FS events? The module should start automatically at FS startup and should react to conference-related events. I've looked through Dave Kompel's examples but didn't find such example (or didin't understand the code well enough) Thanks RG
In order for mod_managed to actually load your module you have to implment at least one of those classes. The most simple is to implmement IApiPlugin and make a shutdown API so you can unload your module. Also implement ILoadPluginNotify, which will add a "Load" method to the class. That will get called as soon as your module is loaded. From there you can start a thread to new up an EventConsumer, and process events. Make sure you return true from the load method, so the module stays loaded. --Dave _____ From: Rafal Gwizdala [mailto:rafal.gwizdala@gmail.com] To: FreeSWITCH Users Help [mailto:freeswitch-users@lists.freeswitch.org] Sent: Thu, 19 Sep 2013 13:10:59 -0700 Subject: [Freeswitch-users] mod_managed - beginner's question about an event listener module I've looked at mod_managed documentation and can see how to write an API command or a dialplan application, but could you give me a hint how to implement an automatically starting 'background' service that will listen to FS events? The module should start automatically at FS startup and should react to conference-related events. I've looked through Dave Kompel's examples but didn't find such example (or didin't understand the code well enough) Thanks RG
Thanks Dave, Regarding the EventConsumer, should I actively poll for incoming events in a loop, using the 'pop' method, or is there a way to set up a callback routine? R On Fri, Sep 20, 2013 at 2:54 AM, Dave R. Kompel <drk@drkngs.net> wrote:
** In order for mod_managed to actually load your module you have to implment at least one of those classes. The most simple is to implmement IApiPlugin and make a shutdown API so you can unload your module.
Also implement ILoadPluginNotify, which will add a "Load" method to the class. That will get called as soon as your module is loaded. From there you can start a thread to new up an EventConsumer, and process events. Make sure you return true from the load method, so the module stays loaded.
--Dave
------------------------------ *From:* Rafal Gwizdala [mailto:rafal.gwizdala@gmail.com] *To:* FreeSWITCH Users Help [mailto:freeswitch-users@lists.freeswitch.org] *Sent:* Thu, 19 Sep 2013 13:10:59 -0700 *Subject:* [Freeswitch-users] mod_managed - beginner's question about an event listener module
I've looked at mod_managed documentation and can see how to write an API command or a dialplan application, but could you give me a hint how to implement an automatically starting 'background' service that will listen to FS events? The module should start automatically at FS startup and should react to conference-related events. I've looked through Dave Kompel's examples but didn't find such example (or didin't understand the code well enough) Thanks RG
_________________________________________________________________________ Professional FreeSWITCH Consulting Services: consulting@freeswitch.org http://www.freeswitchsolutions.com
FreeSWITCH-powered IP PBX: The CudaTel Communication Server http://www.cudatel.com
Official FreeSWITCH Sites http://www.freeswitch.org http://wiki.freeswitch.org http://www.cluecon.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
(...) one more thing, my module caused an access violation during FS shutdown. Probably because my event receiver thread wasn't stopped. Is there any 'system shutdown' hook so I could do the cleanup? 2013-09-20 12:25:21.485852 [CONSOLE] switch_event.c:495 Stopping dispatch thread s 2013-09-20 12:25:21.485852 [CONSOLE] switch_event.c:294 Dispatch Thread 0 Ended. 2013-09-20 12:25:21.489853 [CONSOLE] switch_core.c:2573 Finalizing Shutdown. 2013-09-20 12:25:21.492853 [CONSOLE] switch_log.c:317 Logger Ended. 2013-09-20 12:25:21.493853 [CONSOLE] switch_core_memory.c:602 Stopping memory po ol queue. Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. at EventConsumer.{dtor}(EventConsumer* ) at CSharp_delete_EventConsumer(Void* jarg1) at FreeSWITCH.Native.freeswitchPINVOKE.delete_EventConsumer(HandleRef jarg1) at FreeSWITCH.Native.EventConsumer.Dispose() at FreeSWITCH.Native.EventConsumer.Finalize() On Fri, Sep 20, 2013 at 12:23 PM, Rafal Gwizdala <rafal.gwizdala@gmail.com>wrote:
Thanks Dave, Regarding the EventConsumer, should I actively poll for incoming events in a loop, using the 'pop' method, or is there a way to set up a callback routine?
R
On Fri, Sep 20, 2013 at 2:54 AM, Dave R. Kompel <drk@drkngs.net> wrote:
** In order for mod_managed to actually load your module you have to implment at least one of those classes. The most simple is to implmement IApiPlugin and make a shutdown API so you can unload your module.
Also implement ILoadPluginNotify, which will add a "Load" method to the class. That will get called as soon as your module is loaded. From there you can start a thread to new up an EventConsumer, and process events. Make sure you return true from the load method, so the module stays loaded.
--Dave
------------------------------ *From:* Rafal Gwizdala [mailto:rafal.gwizdala@gmail.com] *To:* FreeSWITCH Users Help [mailto:freeswitch-users@lists.freeswitch.org ] *Sent:* Thu, 19 Sep 2013 13:10:59 -0700 *Subject:* [Freeswitch-users] mod_managed - beginner's question about an event listener module
I've looked at mod_managed documentation and can see how to write an API command or a dialplan application, but could you give me a hint how to implement an automatically starting 'background' service that will listen to FS events? The module should start automatically at FS startup and should react to conference-related events. I've looked through Dave Kompel's examples but didn't find such example (or didin't understand the code well enough) Thanks RG
_________________________________________________________________________ Professional FreeSWITCH Consulting Services: consulting@freeswitch.org http://www.freeswitchsolutions.com
FreeSWITCH-powered IP PBX: The CudaTel Communication Server http://www.cudatel.com
Official FreeSWITCH Sites http://www.freeswitch.org http://wiki.freeswitch.org http://www.cluecon.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
(...) and another finding, I subscribed to the 'SHUTDOWN' event to be notified about system shutdown. In the shutdown routine I'm trying to Dispose the EventConsumer that I created during startup But this dispose hangs indefinitely, preventing FS from terminating R On Fri, Sep 20, 2013 at 12:27 PM, Rafal Gwizdala <rafal.gwizdala@gmail.com>wrote:
(...) one more thing, my module caused an access violation during FS shutdown. Probably because my event receiver thread wasn't stopped. Is there any 'system shutdown' hook so I could do the cleanup?
2013-09-20 12:25:21.485852 [CONSOLE] switch_event.c:495 Stopping dispatch thread s 2013-09-20 12:25:21.485852 [CONSOLE] switch_event.c:294 Dispatch Thread 0 Ended.
2013-09-20 12:25:21.489853 [CONSOLE] switch_core.c:2573 Finalizing Shutdown. 2013-09-20 12:25:21.492853 [CONSOLE] switch_log.c:317 Logger Ended. 2013-09-20 12:25:21.493853 [CONSOLE] switch_core_memory.c:602 Stopping memory po ol queue.
Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. at EventConsumer.{dtor}(EventConsumer* ) at CSharp_delete_EventConsumer(Void* jarg1) at FreeSWITCH.Native.freeswitchPINVOKE.delete_EventConsumer(HandleRef jarg1) at FreeSWITCH.Native.EventConsumer.Dispose() at FreeSWITCH.Native.EventConsumer.Finalize()
On Fri, Sep 20, 2013 at 12:23 PM, Rafal Gwizdala <rafal.gwizdala@gmail.com
wrote:
Thanks Dave, Regarding the EventConsumer, should I actively poll for incoming events in a loop, using the 'pop' method, or is there a way to set up a callback routine?
R
On Fri, Sep 20, 2013 at 2:54 AM, Dave R. Kompel <drk@drkngs.net> wrote:
** In order for mod_managed to actually load your module you have to implment at least one of those classes. The most simple is to implmement IApiPlugin and make a shutdown API so you can unload your module.
Also implement ILoadPluginNotify, which will add a "Load" method to the class. That will get called as soon as your module is loaded. From there you can start a thread to new up an EventConsumer, and process events. Make sure you return true from the load method, so the module stays loaded.
--Dave
------------------------------ *From:* Rafal Gwizdala [mailto:rafal.gwizdala@gmail.com] *To:* FreeSWITCH Users Help [mailto: freeswitch-users@lists.freeswitch.org] *Sent:* Thu, 19 Sep 2013 13:10:59 -0700 *Subject:* [Freeswitch-users] mod_managed - beginner's question about an event listener module
I've looked at mod_managed documentation and can see how to write an API command or a dialplan application, but could you give me a hint how to implement an automatically starting 'background' service that will listen to FS events? The module should start automatically at FS startup and should react to conference-related events. I've looked through Dave Kompel's examples but didn't find such example (or didin't understand the code well enough) Thanks RG
_________________________________________________________________________ Professional FreeSWITCH Consulting Services: consulting@freeswitch.org http://www.freeswitchsolutions.com
FreeSWITCH-powered IP PBX: The CudaTel Communication Server http://www.cudatel.com
Official FreeSWITCH Sites http://www.freeswitch.org http://wiki.freeswitch.org http://www.cluecon.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
(...) my source code: http://pastebin.com/bKPyKSwS
To answer all your questions at once... put the EventConsumer inside a using() block, so it gets disposed. use a static boolean variable in a while loop to .pop the event consumer with a timeout, if pop returns null "continue" the while loop. Subscribe to shutdown, it sets the loop variable to false. API command "shutdown" in the same module to set the variable to false also, so you can unload your module at will w/o crashing This whole loop shoud be run on it's own thread started from the Load() method. --Dave _____ From: Rafal Gwizdala [mailto:rafal.gwizdala@gmail.com] To: FreeSWITCH Users Help [mailto:freeswitch-users@lists.freeswitch.org] Sent: Fri, 20 Sep 2013 04:08:58 -0700 Subject: Re: [Freeswitch-users] mod_managed - beginner's question about an event listener module (...) my source code: http://pastebin.com/bKPyKSwS
Dave, there must be something else. I did as you suggested, but my module will hang during shutdown. The program hangs on EventConsumer.Dispose. http://pastebin.com/58NRKSPf FreeSWITCH Version 1.5.6b+git~20130912T164754Z~d9216daedb (git d9216da 2013-09-12 16:47:54Z) windows 7 64 bit but if the EventConsumer is disposed before system shutdown (for example, after consuming a certain number of events), there is no problem, event receiver thread terminates correctly and system shuts down cleanly. I think i can live with that. Thanks for your help. R On Sat, Sep 21, 2013 at 3:56 AM, Dave R. Kompel <drk@drkngs.net> wrote:
** To answer all your questions at once...
put the EventConsumer inside a using() block, so it gets disposed.
use a static boolean variable in a while loop to .pop the event consumer with a timeout, if pop returns null "continue" the while loop.
Subscribe to shutdown, it sets the loop variable to false.
API command "shutdown" in the same module to set the variable to false also, so you can unload your module at will w/o crashing
This whole loop shoud be run on it's own thread started from the Load() method.
--Dave
------------------------------ *From:* Rafal Gwizdala [mailto:rafal.gwizdala@gmail.com] *To:* FreeSWITCH Users Help [mailto:freeswitch-users@lists.freeswitch.org] *Sent:* Fri, 20 Sep 2013 04:08:58 -0700 *Subject:* Re: [Freeswitch-users] mod_managed - beginner's question about an event listener module
(...) my source code: http://pastebin.com/bKPyKSwS
_________________________________________________________________________ Professional FreeSWITCH Consulting Services: consulting@freeswitch.org http://www.freeswitchsolutions.com
FreeSWITCH-powered IP PBX: The CudaTel Communication Server http://www.cudatel.com
Official FreeSWITCH Sites http://www.freeswitch.org http://wiki.freeswitch.org http://www.cluecon.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
I just looked at your code, and it's really simple to fix :) In your tProc routine, add another ec.bind("SHUTDOWN",String.Empty) so that you get the shutdown events. Then in your while loop, if the event is "SHUTDOWN", then set the _stop = true. Also you can get rid of the "_bind" list cause you're not using it... You also can get rid of implmenting IDisposable yourself, since mod_managed does not Dispose() for you. As long as you exit your thread loop when you get the "SHUTDOWN" event, you should be fine. Also since you are implmenting an API interface, you may want to do something like: if(context.args.ToLower() == "shutdown") _stop = true; So you can force it to shutdown, and then you can replace the DLL to load a new version while FS is still running. --Dave _____ From: Rafal Gwizdala [mailto:rafal.gwizdala@gmail.com] To: FreeSWITCH Users Help [mailto:freeswitch-users@lists.freeswitch.org] Sent: Sat, 21 Sep 2013 00:11:41 -0700 Subject: Re: [Freeswitch-users] mod_managed - beginner's question about an event listener module Dave, there must be something else. I did as you suggested, but my module will hang during shutdown. The program hangs on EventConsumer.Dispose. http://pastebin.com/58NRKSPf FreeSWITCH Version 1.5.6b+git~20130912T164754Z~d9216daedb (git d9216da 2013-09-12 16:47:54Z) windows 7 64 bit but if the EventConsumer is disposed before system shutdown (for example, after consuming a certain number of events), there is no problem, event receiver thread terminates correctly and system shuts down cleanly. I think i can live with that. Thanks for your help. R On Sat, Sep 21, 2013 at 3:56 AM, Dave R. Kompel <drk@drkngs.net> wrote: To answer all your questions at once... put the EventConsumer inside a using() block, so it gets disposed. use a static boolean variable in a while loop to .pop the event consumer with a timeout, if pop returns null "continue" the while loop. Subscribe to shutdown, it sets the loop variable to false. API command "shutdown" in the same module to set the variable to false also, so you can unload your module at will w/o crashing This whole loop shoud be run on it's own thread started from the Load() method. --Dave _____ From: Rafal Gwizdala [mailto:rafal.gwizdala@gmail.com] To: FreeSWITCH Users Help [mailto:freeswitch-users@lists.freeswitch.org] Sent: Fri, 20 Sep 2013 04:08:58 -0700 Subject: Re: [Freeswitch-users] mod_managed - beginner's question about an event listener module (...) my source code: http://pastebin.com/bKPyKSwS _________________________________________________________________________ Professional FreeSWITCH Consulting Services: consulting@freeswitch.org http://www.freeswitchsolutions.com FreeSWITCH-powered IP PBX: The CudaTel Communication Server http://www.cudatel.com Official FreeSWITCH Sites http://www.freeswitch.org http://wiki.freeswitch.org http://www.cluecon.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
participants (2)
-
Dave R. Kompel
-
Rafal Gwizdala