Changeset 3471:8c6856b26672 in roaraudio for libroarpulse


Ignore:
Timestamp:
02/14/10 02:11:34 (10 years ago)
Author:
phi
Branch:
default
Message:

worte unix signal stuff

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libroarpulse/mainloop-signal.c

    r3470 r3471  
    3939#include <libroarpulse/libroarpulse.h> 
    4040 
     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 = &(_roar_pa_signal.sig[sig]); 
     61 
     62 if ( e->cb != NULL ) 
     63  e->cb(_roar_pa_signal.api, e, sig, e->userdata); 
     64} 
     65 
     66/** Initialize the UNIX signal subsystem and bind it to the specified main loop */ 
     67int pa_signal_init(pa_mainloop_api *api) { 
     68 
     69 if ( _roar_pa_signal_inited ) 
     70  return -1; 
     71 
     72 memset(&_roar_pa_signal, 0, sizeof(_roar_pa_signal)); 
     73 
     74 _roar_pa_signal.api = api; 
     75 
     76 _roar_pa_signal_inited = 1; 
     77 
     78 return 0; 
     79} 
     80 
     81/** Cleanup the signal subsystem */ 
     82void pa_signal_done(void) { 
     83 _roar_pa_signal_inited = 0; 
     84} 
     85 
     86/** Create a new UNIX signal event source object */ 
     87pa_signal_event* pa_signal_new(int sig, pa_signal_cb_t callback, void *userdata) { 
     88 if ( !_roar_pa_signal_inited ) 
     89  return NULL; 
     90 
     91 if ( sig >= MAX_SIG ) 
     92  return NULL; 
     93 
     94 _roar_pa_signal.sig[sig].used     = 1; 
     95 _roar_pa_signal.sig[sig].sig      = sig; 
     96 _roar_pa_signal.sig[sig].cb       = callback; 
     97 _roar_pa_signal.sig[sig].userdata = userdata; 
     98 
     99 signal(sig, _roar_pa_signal_handler); 
     100 
     101 return &(_roar_pa_signal.sig[sig]); 
     102} 
     103 
     104/** Free a UNIX signal event source object */ 
     105void pa_signal_free(pa_signal_event *e) { 
     106 if ( !_roar_pa_signal_inited ) 
     107  return; 
     108 
     109 if ( e == NULL ) 
     110  return; 
     111 
     112 signal(e->sig, SIG_DFL); 
     113 
     114 e->used = 0; 
     115} 
     116 
     117/** Set a function that is called when the signal event source is destroyed. Use this to free the userdata argument if required */ 
     118void pa_signal_set_destroy(pa_signal_event *e, void (*callback) (pa_mainloop_api *api, pa_signal_event*e, void *userdata)); 
     119 
    41120//ll 
Note: See TracChangeset for help on using the changeset viewer.