1 /* Generic signalling/notification infrastructure */
2 /* (C) 2009 by Holger Hans Peter Freyther <zecke@selfish.org>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include <osmocom/core/signal.h>
22 #include <osmocom/core/talloc.h>
23 #include <osmocom/core/linuxlist.h>
29 static LLIST_HEAD(signal_handler_list);
31 struct signal_handler {
32 struct llist_head entry;
39 int register_signal_handler(unsigned int subsys, signal_cbfn *cbfn, void *data)
41 struct signal_handler *sig_data;
43 sig_data = talloc(tall_sigh_ctx, struct signal_handler);
47 memset(sig_data, 0, sizeof(*sig_data));
49 sig_data->subsys = subsys;
50 sig_data->data = data;
51 sig_data->cbfn = cbfn;
53 /* FIXME: check if we already have a handler for this subsys/cbfn/data */
55 llist_add_tail(&sig_data->entry, &signal_handler_list);
60 void unregister_signal_handler(unsigned int subsys, signal_cbfn *cbfn, void *data)
62 struct signal_handler *handler;
64 llist_for_each_entry(handler, &signal_handler_list, entry) {
65 if (handler->cbfn == cbfn && handler->data == data
66 && subsys == handler->subsys) {
67 llist_del(&handler->entry);
75 void dispatch_signal(unsigned int subsys, unsigned int signal, void *signal_data)
77 struct signal_handler *handler;
79 llist_for_each_entry(handler, &signal_handler_list, entry) {
80 if (handler->subsys != subsys)
82 (*handler->cbfn)(subsys, signal, handler->data, signal_data);