[1564] | 1 | //events.c: |
---|
[1559] | 2 | |
---|
| 3 | /* |
---|
[4708] | 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2011 |
---|
[1559] | 5 | * The code (may) include prototypes and comments (and maybe |
---|
[4038] | 6 | * other code fragements) from OpenBSD's sndio. |
---|
[4050] | 7 | * See 'Copyright for sndio' below for more information on |
---|
| 8 | * code fragments taken from OpenBSD's sndio. |
---|
| 9 | * |
---|
| 10 | * --- Copyright for sndio --- |
---|
| 11 | * Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org> |
---|
| 12 | * |
---|
| 13 | * Permission to use, copy, modify, and distribute this software for any |
---|
| 14 | * purpose with or without fee is hereby granted, provided that the above |
---|
| 15 | * copyright notice and this permission notice appear in all copies. |
---|
| 16 | * |
---|
| 17 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
---|
| 18 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
---|
| 19 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
---|
| 20 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
---|
| 21 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
---|
| 22 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
---|
| 23 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
---|
| 24 | * --- End of Copyright for sndio --- |
---|
[1559] | 25 | * |
---|
| 26 | * This file is part of libroaresd a part of RoarAudio, |
---|
| 27 | * a cross-platform sound system for both, home and professional use. |
---|
| 28 | * See README for details. |
---|
| 29 | * |
---|
| 30 | * This file is free software; you can redistribute it and/or modify |
---|
| 31 | * it under the terms of the GNU General Public License version 3 |
---|
| 32 | * as published by the Free Software Foundation. |
---|
| 33 | * |
---|
| 34 | * RoarAudio is distributed in the hope that it will be useful, |
---|
| 35 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 36 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 37 | * GNU General Public License for more details. |
---|
| 38 | * |
---|
| 39 | * You should have received a copy of the GNU General Public License |
---|
| 40 | * along with this software; see the file COPYING. If not, write to |
---|
[3517] | 41 | * the Free Software Foundation, 51 Franklin Street, Fifth Floor, |
---|
| 42 | * Boston, MA 02110-1301, USA. |
---|
[1559] | 43 | * |
---|
| 44 | * NOTE for everyone want's to change something and send patches: |
---|
| 45 | * read README and HACKING! There a addition information on |
---|
| 46 | * the license of this document you need to read before you send |
---|
| 47 | * any patches. |
---|
| 48 | */ |
---|
| 49 | |
---|
[1571] | 50 | #define ROAR_USE_OWN_SNDIO_HDL |
---|
[1559] | 51 | #include "libroarsndio.h" |
---|
| 52 | |
---|
[2859] | 53 | #define _CHECK() if ( hdl == NULL ) return 0 |
---|
| 54 | |
---|
[1564] | 55 | int sio_nfds (struct sio_hdl * hdl) { |
---|
[2862] | 56 | #ifdef ROAR_HAVE_H_POLL |
---|
[2859] | 57 | int fh = -1; |
---|
| 58 | |
---|
| 59 | _CHECK(); |
---|
| 60 | |
---|
| 61 | if ( hdl->stream_opened != 1 ) |
---|
| 62 | return 0; |
---|
| 63 | |
---|
| 64 | if ( roar_vio_ctl(&(hdl->svio), ROAR_VIO_CTL_GET_FH, &fh) == -1 ) |
---|
| 65 | return 0; |
---|
| 66 | |
---|
| 67 | if ( fh == -1 ) |
---|
| 68 | return 0; |
---|
| 69 | |
---|
| 70 | return 1; |
---|
[2862] | 71 | #else |
---|
[3786] | 72 | (void)hdl; |
---|
[2862] | 73 | return 0; |
---|
| 74 | #endif |
---|
[1564] | 75 | } |
---|
| 76 | |
---|
| 77 | int sio_pollfd (struct sio_hdl * hdl, struct pollfd * pfd, int events) { |
---|
[2862] | 78 | #ifdef ROAR_HAVE_H_POLL |
---|
[2859] | 79 | int num; |
---|
| 80 | int fh; |
---|
| 81 | |
---|
| 82 | _CHECK(); |
---|
| 83 | |
---|
| 84 | if ( (num = sio_nfds(hdl)) == 0 ) |
---|
| 85 | return 0; |
---|
| 86 | |
---|
| 87 | // not supportet currently: |
---|
| 88 | if ( num > 1 ) |
---|
| 89 | return 0; |
---|
| 90 | |
---|
| 91 | memset(pfd, 0, num*sizeof(struct pollfd)); |
---|
| 92 | |
---|
| 93 | // if stream is ok is tested by sio_nfds() |
---|
| 94 | |
---|
| 95 | if ( roar_vio_ctl(&(hdl->svio), ROAR_VIO_CTL_GET_FH, &fh) == -1 ) |
---|
| 96 | return 0; |
---|
| 97 | |
---|
| 98 | if ( fh == -1 ) |
---|
| 99 | return 0; |
---|
| 100 | |
---|
| 101 | pfd->fd = fh; |
---|
| 102 | pfd->events = events; |
---|
| 103 | pfd->revents = 0; |
---|
| 104 | |
---|
| 105 | return num; |
---|
[2862] | 106 | #else |
---|
[3786] | 107 | (void)hdl, (void)pfd, (void)events; |
---|
[2862] | 108 | return 0; |
---|
| 109 | #endif |
---|
[1564] | 110 | } |
---|
| 111 | |
---|
| 112 | int sio_revents(struct sio_hdl * hdl, struct pollfd * pfd) { |
---|
[2862] | 113 | #ifdef ROAR_HAVE_H_POLL |
---|
[2859] | 114 | short revents = 0; |
---|
| 115 | int num; |
---|
| 116 | int i; |
---|
| 117 | |
---|
| 118 | _CHECK(); |
---|
| 119 | |
---|
| 120 | if ( (num = sio_nfds(hdl)) == 0 ) |
---|
| 121 | return 0; |
---|
| 122 | |
---|
| 123 | for (i = 0; i < num; i++) |
---|
| 124 | revents |= pfd[i].revents; |
---|
| 125 | |
---|
| 126 | return revents; |
---|
[2862] | 127 | #else |
---|
[3786] | 128 | (void)hdl, (void)pfd; |
---|
[2862] | 129 | return 0; |
---|
| 130 | #endif |
---|
[1564] | 131 | } |
---|
| 132 | |
---|
| 133 | |
---|
[1559] | 134 | //ll |
---|