From 2b2d2e350e2cf03ca2eb0a7e5c6a9d99b774c457 Mon Sep 17 00:00:00 2001 From: Holger Freyther Date: Sat, 14 Feb 2009 22:51:00 +0000 Subject: [signal] Add generic signal registration and dispatch... This will be used for generic registration and dispatching of any kind of event. We will have different areas (like with the debug interface) and each layer can define their own struct for the event message... This is not tested yet --- src/Makefile.am | 2 +- src/signal.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 src/signal.c (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index 2a70b8bb5..714fff5d2 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -7,7 +7,7 @@ bsc_hack_SOURCES = bsc_hack.c abis_rsl.c abis_nm.c gsm_04_08.c gsm_data.c \ gsm_subscriber.c msgb.c select.c chan_alloc.c timer.c debug.c db.c \ gsm_04_11.c telnet_interface.c telnet_parser.l subchan_demux.c \ trau_frame.c trau_mux.c paging.c e1_config.c e1_input.c tlv_parser.c \ - input/misdn.c input/ipaccess.c + input/misdn.c input/ipaccess.c signal.c bsc_hack_LDADD = -ldl -ldbi bs11_config_SOURCES = bs11_config.c abis_nm.c gsm_data.c msgb.c debug.c select.c timer.c rs232.c diff --git a/src/signal.c b/src/signal.c new file mode 100644 index 000000000..d4a4a7ce2 --- /dev/null +++ b/src/signal.c @@ -0,0 +1,74 @@ +/* Generic signalling/notification infrastructure */ +/* (C) 2009 by Holger Hans Peter Freyther + * All Rights Reserved + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + +#include +#include +#include + + +static LLIST_HEAD(signal_handler_list); + +struct signal_handler { + struct llist_head entry; + int areas; + + int (*sig_handler)(struct signal_data *, void*); + void *data; +}; + + +void register_signal_handler(int areas, + int (*handler)(struct signal_data *, void *), void *data) +{ + struct signal_handler *sig_data = + (struct signal_handler *)malloc(sizeof(*sig_data)); + memset(sig_data, 0, sizeof(*sig_data)); + + + sig_data->areas = areas; + sig_data->data = data; + sig_data->sig_handler = handler; + llist_add_tail(&signal_handler_list, &sig_data->entry); +} + +void remove_signal_handler(int (*sig_handler)(struct signal_data *, void *), void *data) +{ + struct signal_handler *handler; + + llist_for_each_entry(handler, &signal_handler_list, entry) { + if (handler->sig_handler == sig_handler && handler->data == data) { + llist_del(&handler->entry); + free(handler); + break; + } + } +} + + +void dispatch_signal(int area, struct signal_data *data) +{ + struct signal_handler *handler; + + llist_for_each_entry(handler, &signal_handler_list, entry) { + if (handler->areas & area) { + (*handler->sig_handler)(data, handler->data); + } + } +} -- cgit v1.2.3