[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
This commit is contained in:
Holger Freyther 2009-02-14 22:51:00 +00:00
parent 09d38d3b61
commit 2b2d2e350e
4 changed files with 133 additions and 2 deletions

View File

@ -1,4 +1,4 @@
noinst_HEADERS = abis_nm.h abis_rsl.h debug.h db.h gsm_04_08.h gsm_data.h \
gsm_subscriber.h linuxlist.h msgb.h select.h tlv.h gsm_04_11.h \
timer.h misdn.h chan_alloc.h telnet_interface.h paging.h \
subchan_demux.h trau_frame.h e1_input.h trau_mux.h
subchan_demux.h trau_frame.h e1_input.h trau_mux.h signal.h

57
include/openbsc/signal.h Normal file
View File

@ -0,0 +1,57 @@
/* Generic signalling/notification infrastructure */
/* (C) 2009 by Holger Hans Peter Freyther <zecke@selfish.org>
* 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.
*
*/
#ifndef OPENBSC_SIGNAL_H
#define OPENBSC_SIGNAL_H
#include <openbsc/gsm_data.h>
#include <openbsc/gsm_subscriber.h>
/*
* Signalling areas
*/
#define S_PAGING 0x0001
struct signal_data {
};
struct paging_signal_data {
struct signal_data data;
struct gsm_subscriber *subscr;
struct gsm_bts *bts;
/* NULL in case the paging didn't work */
struct gsm_lchan *lchan;
};
/* Management */
void register_signal_handler(int areas, int (*sig)(struct signal_data *, void *data), void *data);
void remove_signal_handler(int (*sig)(struct signal_data *, void *data), void *data);
/* Dispatch */
void dispatch_signal(int area, struct signal_data *data);
#endif

View File

@ -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

74
src/signal.c Normal file
View File

@ -0,0 +1,74 @@
/* Generic signalling/notification infrastructure */
/* (C) 2009 by Holger Hans Peter Freyther <zecke@selfish.org>
* 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 <openbsc/signal.h>
#include <malloc.h>
#include <string.h>
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);
}
}
}