source: roaraudio/libroarsndio/events.c @ 4038:5e7b9cca7dd2

Last change on this file since 4038:5e7b9cca7dd2 was 4038:5e7b9cca7dd2, checked in by phi, 14 years ago

some cleanup

File size: 2.5 KB
Line 
1//events.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2010
5 *  The code (may) include prototypes and comments (and maybe
6 *  other code fragements) from OpenBSD's sndio.
7 *
8 *  This file is part of libroaresd a part of RoarAudio,
9 *  a cross-platform sound system for both, home and professional use.
10 *  See README for details.
11 *
12 *  This file is free software; you can redistribute it and/or modify
13 *  it under the terms of the GNU General Public License version 3
14 *  as published by the Free Software Foundation.
15 *
16 *  RoarAudio is distributed in the hope that it will be useful,
17 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 *  GNU General Public License for more details.
20 *
21 *  You should have received a copy of the GNU General Public License
22 *  along with this software; see the file COPYING.  If not, write to
23 *  the Free Software Foundation, 51 Franklin Street, Fifth Floor,
24 *  Boston, MA 02110-1301, USA.
25 *
26 *  NOTE for everyone want's to change something and send patches:
27 *  read README and HACKING! There a addition information on
28 *  the license of this document you need to read before you send
29 *  any patches.
30 */
31
32#define ROAR_USE_OWN_SNDIO_HDL
33#include "libroarsndio.h"
34
35#define _CHECK() if ( hdl == NULL ) return 0
36
37int    sio_nfds   (struct sio_hdl * hdl) {
38#ifdef ROAR_HAVE_H_POLL
39 int fh = -1;
40
41 _CHECK();
42
43 if ( hdl->stream_opened != 1 )
44  return 0;
45
46 if ( roar_vio_ctl(&(hdl->svio), ROAR_VIO_CTL_GET_FH, &fh) == -1 )
47  return 0;
48
49 if ( fh == -1 )
50  return 0;
51
52 return 1;
53#else
54 (void)hdl;
55 return 0;
56#endif
57}
58
59int    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 (void)hdl, (void)pfd, (void)events;
90 return 0;
91#endif
92}
93
94int    sio_revents(struct sio_hdl * hdl, struct pollfd * pfd) {
95#ifdef ROAR_HAVE_H_POLL
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;
109#else
110 (void)hdl, (void)pfd;
111 return 0;
112#endif
113}
114
115
116//ll
Note: See TracBrowser for help on using the repository browser.