1 | //events.c: |
---|
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 |
---|
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 | |
---|
33 | #define ROAR_USE_OWN_SNDIO_HDL |
---|
34 | #include "libroarsndio.h" |
---|
35 | |
---|
36 | #define _CHECK() if ( hdl == NULL ) return 0 |
---|
37 | |
---|
38 | int sio_nfds (struct sio_hdl * hdl) { |
---|
39 | #ifdef ROAR_HAVE_H_POLL |
---|
40 | int fh = -1; |
---|
41 | |
---|
42 | _CHECK(); |
---|
43 | |
---|
44 | if ( hdl->stream_opened != 1 ) |
---|
45 | return 0; |
---|
46 | |
---|
47 | if ( roar_vio_ctl(&(hdl->svio), ROAR_VIO_CTL_GET_FH, &fh) == -1 ) |
---|
48 | return 0; |
---|
49 | |
---|
50 | if ( fh == -1 ) |
---|
51 | return 0; |
---|
52 | |
---|
53 | return 1; |
---|
54 | #else |
---|
55 | return 0; |
---|
56 | #endif |
---|
57 | } |
---|
58 | |
---|
59 | int sio_pollfd (struct sio_hdl * hdl, struct pollfd * pfd, int events) { |
---|
60 | #ifdef ROAR_HAVE_H_POLL |
---|
61 | int num; |
---|
62 | int fh; |
---|
63 | |
---|
64 | _CHECK(); |
---|
65 | |
---|
66 | if ( (num = sio_nfds(hdl)) == 0 ) |
---|
67 | return 0; |
---|
68 | |
---|
69 | // not supportet currently: |
---|
70 | if ( num > 1 ) |
---|
71 | return 0; |
---|
72 | |
---|
73 | memset(pfd, 0, num*sizeof(struct pollfd)); |
---|
74 | |
---|
75 | // if stream is ok is tested by sio_nfds() |
---|
76 | |
---|
77 | if ( roar_vio_ctl(&(hdl->svio), ROAR_VIO_CTL_GET_FH, &fh) == -1 ) |
---|
78 | return 0; |
---|
79 | |
---|
80 | if ( fh == -1 ) |
---|
81 | return 0; |
---|
82 | |
---|
83 | pfd->fd = fh; |
---|
84 | pfd->events = events; |
---|
85 | pfd->revents = 0; |
---|
86 | |
---|
87 | return num; |
---|
88 | #else |
---|
89 | return 0; |
---|
90 | #endif |
---|
91 | } |
---|
92 | |
---|
93 | int sio_revents(struct sio_hdl * hdl, struct pollfd * pfd) { |
---|
94 | #ifdef ROAR_HAVE_H_POLL |
---|
95 | short revents = 0; |
---|
96 | int num; |
---|
97 | int i; |
---|
98 | |
---|
99 | _CHECK(); |
---|
100 | |
---|
101 | if ( (num = sio_nfds(hdl)) == 0 ) |
---|
102 | return 0; |
---|
103 | |
---|
104 | for (i = 0; i < num; i++) |
---|
105 | revents |= pfd[i].revents; |
---|
106 | |
---|
107 | return revents; |
---|
108 | #else |
---|
109 | return 0; |
---|
110 | #endif |
---|
111 | } |
---|
112 | |
---|
113 | |
---|
114 | //ll |
---|