Summary:ASTERISK-01343: [patch] Internal Manager Listener
Reporter:Anthony Minessale (anthm)Labels:
Date Opened:2004-04-05 12:52:58Date Closed:2011-06-07 14:04:46
Versions:Frequency of
Environment:Attachments:( 0) new.manager.diff.txt
( 1) new.manager.sample.diff.txt
Description:This patch implements the ability to register a custom function which will be called when the desired Event takes place on the system.

To register an internal session declare a container of type [struct intl_man_listener]

struct intl_man_listener {
   char *event;
   int (*func)(struct message *);
   struct intl_man_listener *next;

Create a custom callback function with the prototype
int myhandler(struct message *m);

static int myhandler(struct message *m) {
   char *event = astman_get_header(m,"Event");
   ast_log(LOG_WARNING,"Caught Event: %s\n",event);
   return 0;

in load_module() setup the container by putting in
a pointer to the event string and the callback func
event can be NULL or "all" for all events or
a string containing a '|' seperated list of events to match.

lstn1.event = "Hangup|Newchannel";
lstn1.func = myhandler;

in unload_module be sure to deregister


attached is the necessary patch an an example patch
to app_echo.c just showing you how to register events
Comments:By: tclark (tclark) 2004-04-05 18:30:07

tested here works nice

By: Mark Spencer (markster) 2004-04-10 16:56:23

Generally good code, but here are two things I want you to fix:
MINOR: Your implementation of deregister is substantially more complex than it should be.  Look at any of the 1000 linked list implementations in Asterisk and you'll see how you can more easily fix the code.

MAJOR: to prevent a deadlock, the function pointer should be called without the lock being held, which means you have to be a bit more careful with your code structure and you need to detect that things have changed.

MAJOR: If a function is slow, it could also cause things to slow down on the system.  For example, if we were using the management interface to transmit messages over TCP/IP sockets and the network became lagged, sending the event to each callback could cause the entire system to become slow.  I've got another interesting idea for receiving the internal events which could be used to even make the sending of events over TCP/IP work much better than the existing, poor strategy i've implemented in current Asterisk.  Find me on IRC and lets talk.

By: zoa (zoa) 2004-04-10 19:03:26

there are 3 kinds of people, those who can count and those who can't :)

By: twisted (twisted) 2004-05-02 23:51:43

hahahah... and on that note, with no response from the author, this bug is being suspended until the author can come back and clean it up - or until someone who gets this notification wishes to do so :)

By: Brian West (bkw918) 2004-05-02 23:52:23

This is a requirement for app_icd to work... or so i'm told.