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
RevLine 
[1564]1//events.c:
[1559]2
3/*
[3790]4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2010
[1559]5 *  The code (may) include prototypes and comments (and maybe
[4038]6 *  other code fragements) from OpenBSD's sndio.
[1559]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
[3517]23 *  the Free Software Foundation, 51 Franklin Street, Fifth Floor,
24 *  Boston, MA 02110-1301, USA.
[1559]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
[1571]32#define ROAR_USE_OWN_SNDIO_HDL
[1559]33#include "libroarsndio.h"
34
[2859]35#define _CHECK() if ( hdl == NULL ) return 0
36
[1564]37int    sio_nfds   (struct sio_hdl * hdl) {
[2862]38#ifdef ROAR_HAVE_H_POLL
[2859]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;
[2862]53#else
[3786]54 (void)hdl;
[2862]55 return 0;
56#endif
[1564]57}
58
59int    sio_pollfd (struct sio_hdl * hdl, struct pollfd * pfd, int events) {
[2862]60#ifdef ROAR_HAVE_H_POLL
[2859]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;
[2862]88#else
[3786]89 (void)hdl, (void)pfd, (void)events;
[2862]90 return 0;
91#endif
[1564]92}
93
94int    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
[3786]110 (void)hdl, (void)pfd;
[2862]111 return 0;
112#endif
[1564]113}
114
115
[1559]116//ll
Note: See TracBrowser for help on using the repository browser.