[1564] | 1 | //events.c: |
---|
[1559] | 2 | |
---|
| 3 | /* |
---|
| 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009 |
---|
| 5 | * The code (may) include prototypes and comments (and maybe |
---|
| 6 | * other code fragements) from EsounD. |
---|
| 7 | * They are mostly copyrighted by Eric B. Mitchell (aka 'Ricdude) |
---|
| 8 | * <ericmit@ix.netcom.com>. For more information see AUTHORS.esd. |
---|
| 9 | * |
---|
| 10 | * This file is part of libroaresd 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 |
---|
[3517] | 25 | * the Free Software Foundation, 51 Franklin Street, Fifth Floor, |
---|
| 26 | * Boston, MA 02110-1301, USA. |
---|
[1559] | 27 | * |
---|
| 28 | * NOTE for everyone want's to change something and send patches: |
---|
| 29 | * read README and HACKING! There a addition information on |
---|
| 30 | * the license of this document you need to read before you send |
---|
| 31 | * any patches. |
---|
| 32 | */ |
---|
| 33 | |
---|
[1571] | 34 | #define ROAR_USE_OWN_SNDIO_HDL |
---|
[1559] | 35 | #include "libroarsndio.h" |
---|
| 36 | |
---|
[2859] | 37 | #define _CHECK() if ( hdl == NULL ) return 0 |
---|
| 38 | |
---|
[1564] | 39 | int sio_nfds (struct sio_hdl * hdl) { |
---|
[2862] | 40 | #ifdef ROAR_HAVE_H_POLL |
---|
[2859] | 41 | int fh = -1; |
---|
| 42 | |
---|
| 43 | _CHECK(); |
---|
| 44 | |
---|
| 45 | if ( hdl->stream_opened != 1 ) |
---|
| 46 | return 0; |
---|
| 47 | |
---|
| 48 | if ( roar_vio_ctl(&(hdl->svio), ROAR_VIO_CTL_GET_FH, &fh) == -1 ) |
---|
| 49 | return 0; |
---|
| 50 | |
---|
| 51 | if ( fh == -1 ) |
---|
| 52 | return 0; |
---|
| 53 | |
---|
| 54 | return 1; |
---|
[2862] | 55 | #else |
---|
| 56 | return 0; |
---|
| 57 | #endif |
---|
[1564] | 58 | } |
---|
| 59 | |
---|
| 60 | int sio_pollfd (struct sio_hdl * hdl, struct pollfd * pfd, int events) { |
---|
[2862] | 61 | #ifdef ROAR_HAVE_H_POLL |
---|
[2859] | 62 | int num; |
---|
| 63 | int fh; |
---|
| 64 | |
---|
| 65 | _CHECK(); |
---|
| 66 | |
---|
| 67 | if ( (num = sio_nfds(hdl)) == 0 ) |
---|
| 68 | return 0; |
---|
| 69 | |
---|
| 70 | // not supportet currently: |
---|
| 71 | if ( num > 1 ) |
---|
| 72 | return 0; |
---|
| 73 | |
---|
| 74 | memset(pfd, 0, num*sizeof(struct pollfd)); |
---|
| 75 | |
---|
| 76 | // if stream is ok is tested by sio_nfds() |
---|
| 77 | |
---|
| 78 | if ( roar_vio_ctl(&(hdl->svio), ROAR_VIO_CTL_GET_FH, &fh) == -1 ) |
---|
| 79 | return 0; |
---|
| 80 | |
---|
| 81 | if ( fh == -1 ) |
---|
| 82 | return 0; |
---|
| 83 | |
---|
| 84 | pfd->fd = fh; |
---|
| 85 | pfd->events = events; |
---|
| 86 | pfd->revents = 0; |
---|
| 87 | |
---|
| 88 | return num; |
---|
[2862] | 89 | #else |
---|
| 90 | return 0; |
---|
| 91 | #endif |
---|
[1564] | 92 | } |
---|
| 93 | |
---|
| 94 | int sio_revents(struct sio_hdl * hdl, struct pollfd * pfd) { |
---|
[2862] | 95 | #ifdef ROAR_HAVE_H_POLL |
---|
[2859] | 96 | short revents = 0; |
---|
| 97 | int num; |
---|
| 98 | int i; |
---|
| 99 | |
---|
| 100 | _CHECK(); |
---|
| 101 | |
---|
| 102 | if ( (num = sio_nfds(hdl)) == 0 ) |
---|
| 103 | return 0; |
---|
| 104 | |
---|
| 105 | for (i = 0; i < num; i++) |
---|
| 106 | revents |= pfd[i].revents; |
---|
| 107 | |
---|
| 108 | return revents; |
---|
[2862] | 109 | #else |
---|
| 110 | return 0; |
---|
| 111 | #endif |
---|
[1564] | 112 | } |
---|
| 113 | |
---|
| 114 | |
---|
[1559] | 115 | //ll |
---|