source: roaraudio/include/roaraudio.h @ 2418:9e4fe07971a3

Last change on this file since 2418:9e4fe07971a3 was 2418:9e4fe07971a3, checked in by phi, 15 years ago

added roaraudio/misc.h

File size: 7.6 KB
Line 
1//roaraudio.h:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008
5 *
6 *  This file is 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 Lesser General Public License version 3
12 *  as published by the Free Software Foundation.
13 *
14 *  RoarAudio 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 Lesser General Public License for more details.
18 *
19 *  You should have received a copy of the GNU Lesser General Public License
20 *  along with this software; see the file COPYING.  If not, write to
21 *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
22 *
23 *  NOTE: Even though this file is LGPLed it (may) include GPLed files
24 *  so the license of this file is/may therefore downgraded to GPL.
25 *  See HACKING for details.
26 */
27
28#ifndef _ROARAUDIO_H_
29#define _ROARAUDIO_H_
30
31#include <roaraudio/config.h>
32#include <roaraudio/muconthacks.h>
33#include <roaraudio/win32hacks.h> // we include this at the beginning of the file
34                                  // so we can define well known standard types known to everyone
35                                  // and everywhere but win32 here
36
37// consts we need to set depending on the OS and features:
38#if defined(ROAR_NEED_GNU_SOURCE) && !defined(_GNU_SOURCE)
39#define _GNU_SOURCE
40#endif
41
42#if defined(ROAR_NEED_BSD_VISIBLE) && !defined(__BSD_VISIBLE)
43#define __BSD_VISIBLE 1
44#endif
45
46#include <stdint.h>
47#include <stdlib.h>
48
49#ifdef ROAR_HAVE_H_UNISTD
50#include <unistd.h>
51#endif
52
53#include <stdio.h>
54#include <string.h>
55#include <errno.h>
56
57#ifdef ROAR_HAVE_H_SYS_TYPES
58#include <sys/types.h>
59#endif
60
61#include <limits.h>
62#if !defined(ROAR_TARGET_WIN32) && !defined(ROAR_TARGET_MICROCONTROLLER)
63#include <sys/mman.h>
64#endif
65
66// TODO: can we move the next block into roard specific includes?
67#if !defined(ROAR_TARGET_WIN32) && !defined(ROAR_TARGET_MICROCONTROLLER)
68#include <grp.h>
69#include <pwd.h>
70#include <sys/stat.h>
71#endif
72
73#ifdef ROAR_TARGET_WIN32
74#include <winsock2.h>
75#else /* ROAR_TARGET_WIN32 */
76#ifdef ROAR_HAVE_BSDSOCKETS
77
78#if defined(ROAR_HAVE_IPV4) || defined(ROAR_HAVE_IPV6)
79#include <arpa/inet.h>
80#endif
81
82#ifdef ROAR_HAVE_SELECT
83#include <sys/socket.h>
84#endif
85
86#ifdef ROAR_HAVE_IPV4
87#include <netinet/in.h>
88#include <netinet/tcp.h>
89#endif
90#ifdef ROAR_HAVE_UNIX
91#include <sys/un.h>
92#endif
93
94#endif /* ROAR_HAVE_BSDSOCKETS */
95#endif /* ROAR_TARGET_WIN32 */
96
97#ifdef __NetBSD__
98#include <netinet/in_systm.h>
99#endif
100
101#if !defined(ROAR_TARGET_WIN32) && !defined(ROAR_TARGET_MICROCONTROLLER)
102#include <netdb.h>
103#endif
104
105// NOTE: we need this macro in some of our header files.
106#if INT_MAX >= 32767
107#define roar_intm16  int
108#define roar_uintm16 unsigned int
109#else
110#define roar_intm16  int16_t
111#define roar_uintm16 uint16_t
112#endif
113
114// this is to avoid warning messages on platforms
115// where sizeof(void*) == 8 and szeof(int) == 4
116#ifdef __LP64__
117#define ROAR_INSTINT long int
118#else
119#define ROAR_INSTINT int
120#endif
121
122#ifndef __BEGIN_DECLS
123#ifdef __cplusplus
124# define __BEGIN_DECLS extern "C" {
125# define __END_DECLS }
126#else
127# define __BEGIN_DECLS
128# define __END_DECLS
129#endif
130#endif
131
132__BEGIN_DECLS
133
134#include <roaraudio/proto.h>
135#include <roaraudio/error.h>
136#include <roaraudio/audio.h>
137#include <roaraudio/stream.h>
138#include <roaraudio/client.h>
139#include <roaraudio/sample.h>
140#include <roaraudio/meta.h>
141#include <roaraudio/acl.h>
142#include <roaraudio/misc.h>
143
144#include <libroar/libroar.h>
145
146// IP
147#define ROAR_DEFAULT_PORT        16002
148#define ROAR_DEFAULT_HOST        "localhost"
149
150// UNIX Domain Sockets
151#define ROAR_DEFAULT_SOCK_GLOBAL "/tmp/roar"
152#define ROAR_DEFAULT_SOCK_USER   ".roar"
153
154// DECnet
155#define ROAR_DEFAULT_OBJECT      "roar"
156#define ROAR_DEFAULT_NUM         0
157#define ROAR_DEFAULT_LISTEN_OBJECT "::" ROAR_DEFAULT_OBJECT
158
159// now handled by condiguere
160//#define ROAR_DEFAULT_SOCKGRP     "audio"
161
162#if defined(ROAR_HAVE_LIBWSOCK32) && defined(ROAR_HAVE_LIBWS2_32)
163#define ROAR_LIBS_WIN32          " -lwsock32 -lws2_32"
164#else
165#define ROAR_LIBS_WIN32          ""
166#endif
167
168#ifdef ROAR_HAVE_LIBSOCKET
169#define ROAR_LIBS_LIBSOCKET      " -lsocket"
170#else
171#define ROAR_LIBS_LIBSOCKET      ""
172#endif
173
174#ifdef ROAR_HAVE_LIBSENDFILE
175#define ROAR_LIBS_LIBSENDFILE    " -lsendfile"
176#else
177#define ROAR_LIBS_LIBSENDFILE    ""
178#endif
179
180#define ROAR_LIBS_NET_LIBS       ROAR_LIBS_LIBSOCKET ROAR_LIBS_WIN32
181
182#define ROAR_LIBS                "-lroar"       ROAR_LIBS_LIBSENDFILE ROAR_LIBS_NET_LIBS
183#define ROAR_LIBS_DSP            "-lroardsp "   ROAR_LIBS
184#define ROAR_LIBS_MIDI           "-lroarmidi "  ROAR_LIBS_DSP
185#define ROAR_LIBS_LIGHT          "-lroarlight " ROAR_LIBS
186#define ROAR_LIBS_EIO            "-lroareio "   ROAR_LIBS
187#define ROAR_CFLAGS              ""
188
189//some basic macros:
190#define ROAR_STDIN  0
191#define ROAR_STDOUT 1
192#define ROAR_STDERR 2
193
194#define ROAR_DEBUG_OUTFH stderr
195
196#ifdef ROAR_DBG_PREFIX
197#undef ROAR_DBG_PREFIX
198#endif
199#define ROAR_DBG_PREFIX "roaraudio"
200
201#define ROAR_DBG_FULLPREFIX "(" ROAR_DBG_PREFIX ": " __FILE__ ":%i): "
202
203#if __GNUC__ < 3
204 #define ROAR_DBG(format, args...)
205 #define ROAR_ERR(format, args...)
206 #define ROAR_WARN(format, args...)
207#else
208
209#ifdef DEBUG
210 #define ROAR_DBG(format, args...)  fprintf(ROAR_DEBUG_OUTFH, ROAR_DBG_FULLPREFIX "DEBUG: " format "\n", __LINE__, ## args)
211#else
212 #define ROAR_DBG(format, args...)
213#endif
214
215#define ROAR_ERR(format, args...)  fprintf(ROAR_DEBUG_OUTFH, ROAR_DBG_FULLPREFIX "Error: "   format "\n", __LINE__, ## args)
216#define ROAR_WARN(format, args...) fprintf(ROAR_DEBUG_OUTFH, ROAR_DBG_FULLPREFIX "Warning: " format "\n", __LINE__, ## args)
217
218#endif
219
220#ifdef ROAR_HAVE_SAFE_OVERFLOW
221#define ROAR_MATH_OVERFLOW_ADD(a, b) ((a)+(b))
222#else
223#define ROAR_MATH_OVERFLOW_ADD(a, b) ((4294967295U - (a)) + 1 + (b))
224#endif
225
226#ifdef ROAR_HAVE_MLOCK
227#ifdef __linux__
228#define ROAR_MLOCK(p,s) mlock((p), (s))
229#else
230int _ROAR_MLOCK(const void *addr, size_t len);
231#define ROAR_MLOCK _ROAR_MLOCK
232#endif
233#endif
234
235#if BYTE_ORDER == BIG_ENDIAN && !defined(ROAR_TARGET_WIN32)
236
237#ifdef ROAR_TARGET_WIN32
238#error This is nonsens. No win32 runs on a BE machine
239#endif
240
241#define ROAR_NET2HOST64(x) (x)
242#define ROAR_HOST2NET64(x) (x)
243#define ROAR_NET2HOST32(x) (x)
244#define ROAR_HOST2NET32(x) (x)
245#define ROAR_NET2HOST16(x) (x)
246#define ROAR_HOST2NET16(x) (x)
247
248#ifdef ROAR_HAVE_LIBDNET
249#define ROAR_dn_ntohs(x) ((((x)&0x0ff)<<8) | (((x)&0xff00)>>8))
250#define ROAR_dn_ntohl(x) ( ((dn_ntohs((x)&0xffff))<<16) |\
251                           ((dn_ntohs(((x)>>16)))) )
252#define ROAR_dn_htonl(x) ROAR_dn_ntohl(x)
253#define ROAR_dn_htons(x) ROAR_dn_ntohs(x)
254#endif
255
256//#elif BYTE_ORDER == LITTLE_ENDIAN
257#else
258
259#if BYTE_ORDER == LITTLE_ENDIAN
260#define _ROAR_MOVE_BYTE(x,p) (((x) & (0xFFUL << (8*(p)))) >> (8*(p)) << (64-8*((p)+1)))
261#define ROAR_NET2HOST64(x) ROAR_HOST2NET64(x)
262#define ROAR_HOST2NET64(x) (_ROAR_MOVE_BYTE((x), 0) | _ROAR_MOVE_BYTE((x), 1) | \
263                            _ROAR_MOVE_BYTE((x), 2) | _ROAR_MOVE_BYTE((x), 3) | \
264                            _ROAR_MOVE_BYTE((x), 4) | _ROAR_MOVE_BYTE((x), 5) | \
265                            _ROAR_MOVE_BYTE((x), 6) | _ROAR_MOVE_BYTE((x), 7) | )
266#else
267/* PDP byte order */
268#endif
269
270#define ROAR_NET2HOST32(x) ntohl((x))
271#define ROAR_HOST2NET32(x) htonl((x))
272#define ROAR_NET2HOST16(x) ntohs((x))
273#define ROAR_HOST2NET16(x) htons((x))
274
275#ifdef ROAR_HAVE_LIBDNET
276#if BYTE_ORDER == LITTLE_ENDIAN
277#define ROAR_dn_ntohs(x) (x)
278#define ROAR_dn_htons(x) (x)
279
280#define ROAR_dn_ntohl(x) (x)
281#define ROAR_dn_htonl(x) (x)
282#else
283#error can not build on this architecture with DECnet support enabled
284#endif
285#endif
286
287#endif
288
289__END_DECLS
290
291#endif
292
293//ll
Note: See TracBrowser for help on using the repository browser.