source: roaraudio/libroarsndio/events.c @ 2859:277d77b307d5

Last change on this file since 2859:277d77b307d5 was 2859:277d77b307d5, checked in by phi, 15 years ago

added sndio events system

File size: 2.4 KB
Line 
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
38int    sio_nfds   (struct sio_hdl * hdl) {
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}
54
55int    sio_pollfd (struct sio_hdl * hdl, struct pollfd * pfd, int events) {
56 int num;
57 int fh;
58
59 _CHECK();
60
61 if ( (num = sio_nfds(hdl)) == 0 )
62  return 0;
63
64 // not supportet currently:
65 if ( num > 1 )
66  return 0;
67
68 memset(pfd, 0, num*sizeof(struct pollfd));
69
70 // if stream is ok is tested by sio_nfds()
71
72 if ( roar_vio_ctl(&(hdl->svio), ROAR_VIO_CTL_GET_FH, &fh) == -1 )
73  return 0;
74
75 if ( fh == -1 )
76  return 0;
77
78 pfd->fd      = fh;
79 pfd->events  = events;
80 pfd->revents = 0;
81
82 return num;
83}
84
85int    sio_revents(struct sio_hdl * hdl, struct pollfd * pfd) {
86 short revents = 0;
87 int num;
88 int i;
89
90 _CHECK();
91
92 if ( (num = sio_nfds(hdl)) == 0 )
93  return 0;
94
95 for (i = 0; i < num; i++)
96  revents |= pfd[i].revents;
97
98 return revents;
99}
100
101
102//ll
Note: See TracBrowser for help on using the repository browser.