1/*
2 *  ALSA lib - local header file
3 *  Copyright (c) 2000 by Abramo Bagnara <abramo@alsa-project.org>
4 *
5 *
6 *   This library is free software; you can redistribute it and/or modify
7 *   it under the terms of the GNU Lesser General Public License as
8 *   published by the Free Software Foundation; either version 2.1 of
9 *   the License, or (at your option) any later version.
10 *
11 *   This program is distributed in the hope that it will be useful,
12 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
13 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 *   GNU Lesser General Public License for more details.
15 *
16 *   You should have received a copy of the GNU Lesser General Public
17 *   License along with this library; if not, write to the Free Software
18 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 *
20 */
21
22#ifndef __LOCAL_H
23#define __LOCAL_H
24
25#include <unistd.h>
26#include <stdio.h>
27#include <stdlib.h>
28#include <string.h>
29#include <fcntl.h>
30#include <assert.h>
31#include <endian.h>
32#include <stdarg.h>
33#include <sys/poll.h>
34#include <errno.h>
35
36#include "config.h"
37#ifdef SUPPORT_RESMGR
38#include <resmgr.h>
39#endif
40#ifdef HAVE_LIBDL
41#include <dlfcn.h>
42#else
43#define RTLD_NOW	0
44#endif
45
46#define _snd_config_iterator list_head
47#define _snd_interval sndrv_interval
48#define _snd_pcm_info sndrv_pcm_info
49#define _snd_pcm_hw_params sndrv_pcm_hw_params
50#define _snd_pcm_sw_params sndrv_pcm_sw_params
51#define _snd_pcm_status sndrv_pcm_status
52
53#define _snd_ctl_card_info sndrv_ctl_card_info
54#define _snd_ctl_elem_id sndrv_ctl_elem_id
55#define _snd_ctl_elem_list sndrv_ctl_elem_list
56#define _snd_ctl_elem_info sndrv_ctl_elem_info
57#define _snd_ctl_elem_value sndrv_ctl_elem_value
58#define _snd_ctl_event sndrv_ctl_event
59
60#define _snd_rawmidi_info sndrv_rawmidi_info
61#define _snd_rawmidi_params sndrv_rawmidi_params
62#define _snd_rawmidi_status sndrv_rawmidi_status
63
64#define _snd_hwdep_info sndrv_hwdep_info
65#define _snd_hwdep_dsp_status sndrv_hwdep_dsp_status
66#define _snd_hwdep_dsp_image sndrv_hwdep_dsp_image
67
68#define _snd_seq_queue_tempo sndrv_seq_queue_tempo
69#define _snd_seq_client_info sndrv_seq_client_info
70#define _snd_seq_port_info sndrv_seq_port_info
71#define _snd_seq_system_info sndrv_seq_system_info
72#define _snd_seq_queue_info sndrv_seq_queue_info
73#define _snd_seq_queue_status sndrv_seq_queue_status
74#define _snd_seq_queue_timer sndrv_seq_queue_timer
75#define _snd_seq_port_subscribe sndrv_seq_port_subscribe
76#define _snd_seq_query_subscribe sndrv_seq_query_subs
77#define _snd_seq_client_pool sndrv_seq_client_pool
78#define _snd_seq_remove_events sndrv_seq_remove_events
79
80#define sndrv_seq_addr	snd_seq_addr
81#define sndrv_seq_tick_time_t	snd_seq_tick_time_t
82#define sndrv_seq_real_time	snd_seq_real_time
83#define sndrv_seq_timestamp	snd_seq_timestamp
84#define sndrv_seq_event		snd_seq_event
85
86#if 0
87typedef struct sndrv_seq_addr snd_seq_addr_t;
88#define snd_seq_tick_time_t sndrv_seq_tick_time_t
89typedef struct sndrv_seq_real_time snd_seq_real_time_t;
90typedef union sndrv_seq_timestamp snd_seq_timestamp_t;
91typedef struct sndrv_seq_event snd_seq_event_t;
92#endif
93
94#define _snd_timer_id sndrv_timer_id
95#define _snd_timer_ginfo sndrv_timer_ginfo
96#define _snd_timer_gparams sndrv_timer_gparams
97#define _snd_timer_gstatus sndrv_timer_gstatus
98#define _snd_timer_select sndrv_timer_select
99#define _snd_timer_info sndrv_timer_info
100#define _snd_timer_params sndrv_timer_params
101#define _snd_timer_status sndrv_timer_status
102
103#define ALSA_LIBRARY_BUILD
104
105#include <sound/asound.h>
106#include <sound/asoundef.h>
107#include "alsa-symbols.h"
108#include "version.h"
109#include "global.h"
110#include "input.h"
111#include "output.h"
112#include "error.h"
113#include "conf.h"
114#include "pcm.h"
115#include "pcm_plugin.h"
116#include "rawmidi.h"
117#include "timer.h"
118#include "hwdep.h"
119#include "control.h"
120#include "mixer.h"
121#include "seq_event.h"
122#include "seq.h"
123#include <sound/asequencer.h>
124#include "seqmid.h"
125#include "seq_midi_event.h"
126#include "list.h"
127
128#if __BYTE_ORDER == __LITTLE_ENDIAN
129#define SND_LITTLE_ENDIAN
130#endif
131#if __BYTE_ORDER == __BIG_ENDIAN
132#define SND_BIG_ENDIAN
133#endif
134
135struct _snd_async_handler {
136	enum {
137		SND_ASYNC_HANDLER_GENERIC,
138		SND_ASYNC_HANDLER_CTL,
139		SND_ASYNC_HANDLER_PCM,
140		SND_ASYNC_HANDLER_TIMER,
141	} type;
142	int fd;
143	union {
144		snd_ctl_t *ctl;
145		snd_pcm_t *pcm;
146		snd_timer_t *timer;
147	} u;
148	snd_async_callback_t callback;
149	void *private_data;
150	struct list_head glist;
151	struct list_head hlist;
152};
153
154typedef enum _snd_set_mode {
155	SND_CHANGE,
156	SND_TRY,
157	SND_TEST,
158} snd_set_mode_t;
159
160size_t page_align(size_t size);
161size_t page_size(void);
162size_t page_ptr(size_t object_offset, size_t object_size, size_t *offset, size_t *mmap_offset);
163
164int safe_strtol(const char *str, long *val);
165
166int snd_send_fd(int sock, void *data, size_t len, int fd);
167int snd_receive_fd(int sock, void *data, size_t len, int *fd);
168
169/*
170 * error messages
171 */
172#ifndef NDEBUG
173#define CHECK_SANITY(x) x
174extern snd_lib_error_handler_t snd_err_msg;
175#define SNDMSG(args...) snd_err_msg(__FILE__, __LINE__, __FUNCTION__, 0, ##args)
176#define SYSMSG(args...) snd_err_msg(__FILE__, __LINE__, __FUNCTION__, errno, ##args)
177#else
178#define CHECK_SANITY(x) 0 /* not evaluated */
179#define SNDMSG(args...) /* nop */
180#define SYSMSG(args...) /* nop */
181#endif
182
183/*
184 */
185#define HAVE_GNU_LD
186#define HAVE_ELF
187#define HAVE_ASM_PREVIOUS_DIRECTIVE
188
189/* Stolen from libc-symbols.h in GNU glibc */
190
191/* When a reference to SYMBOL is encountered, the linker will emit a
192   warning message MSG.  */
193
194#define ASM_NAME(name) __SYMBOL_PREFIX name
195
196#ifdef HAVE_GNU_LD
197# ifdef HAVE_ELF
198
199/* We want the .gnu.warning.SYMBOL section to be unallocated.  */
200#  ifdef HAVE_ASM_PREVIOUS_DIRECTIVE
201#   define __make_section_unallocated(section_string)	\
202  asm (".section " section_string "\n\t.previous");
203#  elif defined HAVE_ASM_POPSECTION_DIRECTIVE
204#   define __make_section_unallocated(section_string)	\
205  asm (".pushsection " section_string "\n\t.popsection");
206#  else
207#   define __make_section_unallocated(section_string)
208#  endif
209
210/* Tacking on "\n\t#" to the section name makes gcc put it's bogus
211   section attributes on what looks like a comment to the assembler.  */
212#  ifdef HAVE_SECTION_QUOTES
213#   define link_warning(symbol, msg) \
214  __make_section_unallocated (".gnu.warning." ASM_NAME(#symbol)) \
215  static const char __evoke_link_warning_##symbol[]	\
216    __attribute__ ((section (".gnu.warning." ASM_NAME(#symbol) "\"\n\t#\""))) = msg;
217#  else
218#   define link_warning(symbol, msg) \
219  __make_section_unallocated (".gnu.warning." ASM_NAME(#symbol)) \
220  static const char __evoke_link_warning_##symbol[]	\
221    __attribute__ ((section (".gnu.warning." ASM_NAME(#symbol) "\n\t#"))) = msg;
222#  endif
223# else
224#  define link_warning(symbol, msg)		\
225  asm (".stabs \"" msg "\",30,0,0,0\n\t"	\
226       ".stabs \"" ASM_NAME(#symbol) "\",1,0,0,0\n");
227# endif
228#else
229/* We will never be heard; they will all die horribly.  */
230# define link_warning(symbol, msg)
231#endif
232
233static inline int snd_open_device(const char *filename, int fmode)
234{
235	int fd;
236
237#ifdef O_CLOEXEC
238	fmode |= O_CLOEXEC;
239#endif
240	fd = open(filename, fmode);
241
242/* open with resmgr */
243#ifdef SUPPORT_RESMGR
244	if (fd < 0) {
245		if (errno == EAGAIN || errno == EBUSY)
246			return fd;
247		if (! access(filename, F_OK))
248			fd = rsm_open_device(filename, fmode);
249	}
250#endif
251	if (fd >= 0)
252		fcntl(fd, F_SETFD, FD_CLOEXEC);
253	return fd;
254}
255
256/* make local functions really local */
257#define snd_dlobj_cache_get \
258	snd1_dlobj_cache_get
259#define snd_dlobj_cache_put \
260	snd1_dlobj_cache_put
261#define snd_dlobj_cache_cleanup \
262	snd1_dlobj_cache_cleanup
263#define snd_config_set_hop \
264	snd1_config_set_hop
265#define snd_config_check_hop \
266	snd1_config_check_hop
267#define snd_config_search_alias_hooks \
268	snd1_config_search_alias_hooks
269
270/* dlobj cache */
271void *snd_dlobj_cache_get(const char *lib, const char *name, const char *version, int verbose);
272int snd_dlobj_cache_put(void *open_func);
273void snd_dlobj_cache_cleanup(void);
274
275/* for recursive checks */
276void snd_config_set_hop(snd_config_t *conf, int hop);
277int snd_config_check_hop(snd_config_t *conf);
278#define SND_CONF_MAX_HOPS	64
279
280int snd_config_search_alias_hooks(snd_config_t *config,
281                                  const char *base, const char *key,
282				  snd_config_t **result);
283
284#endif
285