aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHolger Freyther <zecke@selfish.org>2009-02-14 22:51:00 +0000
committerHolger Freyther <zecke@selfish.org>2009-02-14 22:51:00 +0000
commit2b2d2e350e2cf03ca2eb0a7e5c6a9d99b774c457 (patch)
tree1af6b33b83a65dec193e161fd910c3583ffafeee
parent09d38d3b618a11c25ae884f04692d97681f93479 (diff)
[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
-rw-r--r--include/openbsc/Makefile.am2
-rw-r--r--include/openbsc/signal.h57
-rw-r--r--src/Makefile.am2
-rw-r--r--src/signal.c74
4 files changed, 133 insertions, 2 deletions
diff --git a/include/openbsc/Makefile.am b/include/openbsc/Makefile.am
index 109f3c806..062df346f 100644
--- a/include/openbsc/Makefile.am
+++ b/include/openbsc/Makefile.am
@@ -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
diff --git a/include/openbsc/signal.h b/include/openbsc/signal.h
new file mode 100644
index 000000000..6a0d6fb90
--- /dev/null
+++ b/include/openbsc/signal.h
@@ -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
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 <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);
+ }
+ }
+}