source: roaraudio/libroar/asyncctl.c @ 4341:37d7e22c37ff

Last change on this file since 4341:37d7e22c37ff was 4341:37d7e22c37ff, checked in by phi, 14 years ago

added libroar/asyncctl.[ch], added roar_wait()

File size: 3.0 KB
Line 
1//asyncctl.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010
5 *
6 *  This file is part of libroar a part of RoarAudio,
7 *  a cross-platform sound system for both, home and professional use.
8 *  See README for details.
9 *
10 *  This file is free software; you can redistribute it and/or modify
11 *  it under the terms of the GNU General Public License version 3
12 *  as published by the Free Software Foundation.
13 *
14 *  libroar is distributed in the hope that it will be useful,
15 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 *  GNU General Public License for more details.
18 *
19 *  You should have received a copy of the GNU General Public License
20 *  along with this software; see the file COPYING.  If not, write to
21 *  the Free Software Foundation, 51 Franklin Street, Fifth Floor,
22 *  Boston, MA 02110-1301, USA.
23 *
24 *  NOTE for everyone want's to change something and send patches:
25 *  read README and HACKING! There a addition information on
26 *  the license of this document you need to read before you send
27 *  any patches.
28 *
29 *  NOTE for uses of non-GPL (LGPL,...) software using libesd, libartsc
30 *  or libpulse*:
31 *  The libs libroaresd, libroararts and libroarpulse link this lib
32 *  and are therefore GPL. Because of this it may be illigal to use
33 *  them with any software that uses libesd, libartsc or libpulse*.
34 */
35
36#include "libroar.h"
37
38int roar_wait (struct roar_connection * con, struct roar_event * triggered, struct roar_event * events, size_t num) {
39 struct roar_message m;
40 uint16_t * u16 = (uint16_t *) m.data;
41 void * vp = m.data;
42 size_t i, len_left, len_have, tmp;
43
44 if ( con == NULL || triggered == NULL )
45  return -1;
46
47 memset(triggered, 0, sizeof(struct roar_event));
48
49 if ( num == 0 )
50  return 0;
51
52 if ( events == NULL )
53  return -1;
54
55 memset(&m, 0, sizeof(m));
56
57 m.cmd = ROAR_CMD_WAIT;
58 m.stream = -1;
59
60 u16[0] = ROAR_HOST2NET16(0); // version
61 u16[1] = ROAR_HOST2NET16(0); // flags
62
63 vp += 4; // we have 4 byte header (version + flags)
64
65 len_left = sizeof(m.data) - 4;
66 len_have = 4;
67
68 for (i = 0; i < num; i++) {
69  tmp = len_left;
70  if ( roar_event_to_blob(&(events[i]), vp, &tmp) == -1 )
71   return -1;
72
73  len_left -= tmp;
74  len_have += tmp;
75  vp       += tmp;
76 }
77
78 m.datalen = len_have;
79
80 if ( roar_req(con, &m, NULL) != 0 )
81  return -1;
82
83 if ( m.cmd != ROAR_CMD_OK )
84  return -1;
85
86 u16[0] = ROAR_NET2HOST16(u16[0]);
87 u16[1] = ROAR_NET2HOST16(u16[1]);
88
89 // check if we have a complet header:
90 if ( m.datalen < 2 )
91  return -1;
92
93 // check if we have a unsupported version or flags:
94 if ( u16[0] != 0 || u16[1] != 0 )
95  return -1;
96
97 vp  = (void*)m.data;
98 vp += 4;
99 len_have = tmp = m.datalen - 4;
100
101 if ( roar_event_from_blob(triggered, vp, &tmp) != 0 )
102  return -1;
103
104 // test if we have a length match:
105 if ( len_have != tmp )
106  return -1;
107
108 // we now have an event.
109
110 // we maybe have some data, need to reset this as it is of a local buffer:
111 triggered->arg2 = NULL;
112 triggered->arg2_len = 0;
113
114 return 0;
115}
116
117//ll
Note: See TracBrowser for help on using the repository browser.