source: roaraudio/libroarpulse/mainloop-signal.c @ 3473:9b37ab18c87d

Last change on this file since 3473:9b37ab18c87d was 3473:9b37ab18c87d, checked in by phi, 10 years ago

a lot debug lions for the signal handler

File size: 4.0 KB
Line 
1//mainloop-signal.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010
5 *  The code (may) include prototypes and comments (and maybe
6 *  other code fragements) from libpulse*. They are mostly copyrighted by:
7 *  Lennart Poettering <poettering@users.sourceforge.net> and
8 *  Pierre Ossman <drzeus@drzeus.cx>
9 *
10 *  This file is part of libroarpulse a part of RoarAudio,
11 *  a cross-platform sound system for both, home and professional use.
12 *  See README for details.
13 *
14 *  This file is free software; you can redistribute it and/or modify
15 *  it under the terms of the GNU General Public License version 3
16 *  as published by the Free Software Foundation.
17 *
18 *  RoarAudio is distributed in the hope that it will be useful,
19 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
20 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 *  GNU General Public License for more details.
22 *
23 *  You should have received a copy of the GNU General Public License
24 *  along with this software; see the file COPYING.  If not, write to
25 *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
26 *
27 *  NOTE for everyone want's to change something and send patches:
28 *  read README and HACKING! There a addition information on
29 *  the license of this document you need to read before you send
30 *  any patches.
31 *
32 *  NOTE for uses of non-GPL (LGPL,...) software using libesd, libartsc
33 *  or libpulse*:
34 *  The libs libroaresd, libroararts and libroarpulse link this libroar
35 *  and are therefore GPL. Because of this it may be illigal to use
36 *  them with any software that uses libesd, libartsc or libpulse*.
37 */
38
39#include <libroarpulse/libroarpulse.h>
40
41#define MAX_SIG 64 /* there is no way to find out */
42
43typedef void (*pa_signal_cb_t) (pa_mainloop_api *api, pa_signal_event*e, int sig, void *userdata);
44
45struct pa_signal_event {
46 int used;
47 int sig;
48 pa_signal_cb_t cb;
49 void * userdata;
50};
51
52static int _roar_pa_signal_inited = 0;
53
54static struct {
55 pa_mainloop_api * api;
56 pa_signal_event sig[MAX_SIG];
57} _roar_pa_signal;
58
59static void _roar_pa_signal_handler (int sig) {
60 pa_signal_event * e;
61
62 ROAR_DBG("_roar_pa_signal_handler(sig=%s(%i)) = ?", strsignal(sig), sig);
63
64 if ( sig >= MAX_SIG )
65  return;
66
67 e = &(_roar_pa_signal.sig[sig]);
68
69 if ( !e->used )
70  return;
71
72 ROAR_DBG("_roar_pa_signal_handler(sig=%s(%i)): signal is used", strsignal(sig), sig);
73
74 ROAR_DBG("_roar_pa_signal_handler(sig=%s(%i)): callback at %p", strsignal(sig), sig, e->cb);
75
76 ROAR_DBG("_roar_pa_signal_handler(sig=%s(%i)): api=%p, userdata=%p", strsignal(sig), sig, _roar_pa_signal.api, e->userdata);
77
78 if ( e->cb != NULL )
79  e->cb(_roar_pa_signal.api, e, sig, e->userdata);
80
81 ROAR_DBG("_roar_pa_signal_handler(sig=%s(%i)) = (void)", strsignal(sig), sig);
82}
83
84/** Initialize the UNIX signal subsystem and bind it to the specified main loop */
85int pa_signal_init(pa_mainloop_api *api) {
86
87 if ( _roar_pa_signal_inited )
88  return -1;
89
90 memset(&_roar_pa_signal, 0, sizeof(_roar_pa_signal));
91
92 _roar_pa_signal.api = api;
93
94 _roar_pa_signal_inited = 1;
95
96 return 0;
97}
98
99/** Cleanup the signal subsystem */
100void pa_signal_done(void) {
101 _roar_pa_signal_inited = 0;
102}
103
104/** Create a new UNIX signal event source object */
105pa_signal_event* pa_signal_new(int sig, pa_signal_cb_t callback, void *userdata) {
106 if ( !_roar_pa_signal_inited )
107  return NULL;
108
109 if ( sig >= MAX_SIG )
110  return NULL;
111
112 _roar_pa_signal.sig[sig].used     = 1;
113 _roar_pa_signal.sig[sig].sig      = sig;
114 _roar_pa_signal.sig[sig].cb       = callback;
115 _roar_pa_signal.sig[sig].userdata = userdata;
116
117 signal(sig, _roar_pa_signal_handler);
118
119 return &(_roar_pa_signal.sig[sig]);
120}
121
122/** Free a UNIX signal event source object */
123void pa_signal_free(pa_signal_event *e) {
124 if ( !_roar_pa_signal_inited )
125  return;
126
127 if ( e == NULL )
128  return;
129
130 signal(e->sig, SIG_DFL);
131
132 e->used = 0;
133}
134
135/** Set a function that is called when the signal event source is destroyed. Use this to free the userdata argument if required */
136void pa_signal_set_destroy(pa_signal_event *e, void (*callback) (pa_mainloop_api *api, pa_signal_event*e, void *userdata));
137
138//ll
Note: See TracBrowser for help on using the repository browser.