Changeset 3468:c2bff8bedf7c in roaraudio for libroarpulse
- Timestamp:
- 02/14/10 00:40:31 (14 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libroarpulse/mainloop.c
r3463 r3468 39 39 #include <libroarpulse/libroarpulse.h> 40 40 41 #define MAX_IO_EVENTS 8 42 43 struct pa_io_event { 44 int used; 45 pa_mainloop_api *api; 46 int fd; 47 pa_io_event_flags_t events; 48 pa_io_event_cb_t cb; 49 void *userdata; 50 pa_io_event_destroy_cb_t destroy; 51 }; 52 41 53 struct pa_mainloop { 42 54 pa_mainloop_api api; … … 45 57 int quit; 46 58 int quitval; 59 pa_io_event io_event[MAX_IO_EVENTS]; 47 60 }; 48 61 49 struct pa_io_event { 50 pa_mainloop_api *api; 51 int fd; 52 pa_io_event_flags_t events; 53 pa_io_event_cb_t cb; 54 void *userdata; 55 }; 62 // IO EVENTS: 63 static void _roar_pa_io_enable(pa_io_event* e, pa_io_event_flags_t events); 64 65 /** Create a new IO event source object */ 66 static pa_io_event* _roar_pa_io_new(pa_mainloop_api*a, int fd, 67 pa_io_event_flags_t events, pa_io_event_cb_t cb, void *userdata) { 68 pa_mainloop * mainloop = a->userdata; 69 pa_io_event * ret = NULL; 70 int i; 71 72 for (i = 0; i < MAX_IO_EVENTS; i++) { 73 if ( mainloop->io_event[i].used == 0 ) { 74 ret = &(mainloop->io_event[i]); 75 } 76 } 77 78 if ( ret == NULL ) 79 return NULL; 80 81 ret->used = 1; 82 83 ret->api = a; 84 ret->fd = fd; 85 ret->cb = cb; 86 ret->userdata = userdata; 87 88 // Callbacks: 89 ret->destroy = NULL; 90 91 _roar_pa_io_enable(ret, events); 92 93 return ret; 94 } 95 /** Enable or disable IO events on this object */ 96 static void _roar_pa_io_enable(pa_io_event* e, pa_io_event_flags_t events) { 97 if ( e == NULL ) 98 return; 99 100 e->events = events; 101 } 102 103 /** Free a IO event source object */ 104 static void _roar_pa_io_free(pa_io_event* e) { 105 if ( e == NULL ) 106 return; 107 108 if ( e->destroy != NULL ) 109 e->destroy(e->api, e, e->userdata); 110 111 e->used = 0; 112 } 113 /** Set a function that is called when the IO event source is destroyed. Use this to free the userdata argument if required */ 114 static void _roar_pa_io_set_destroy(pa_io_event *e, pa_io_event_destroy_cb_t cb) { 115 if ( e == NULL ) 116 return; 117 118 e->destroy = cb; 119 } 120 121 122 123 // API: 56 124 57 125 /** Allocate a new main loop object */ … … 64 132 memset(m, 0, sizeof(pa_mainloop)); 65 133 66 m->api.userdata = m; 134 m->api.userdata = m; 135 m->api.io_new = _roar_pa_io_new; 136 m->api.io_enable = _roar_pa_io_enable; 137 m->api.io_free = _roar_pa_io_free; 138 m->api.io_set_destroy = _roar_pa_io_set_destroy; 67 139 68 140 return m;
Note: See TracChangeset
for help on using the changeset viewer.