xref: /third_party/alsa-utils/alsactl/alsactl.h (revision c72fcc34)
1#include <stdbool.h>
2#include <alsa/asoundlib.h>
3
4#define LOCK_TIMEOUT 10
5
6extern int debugflag;
7extern int force_restore;
8extern int ignore_nocards;
9extern int do_lock;
10extern int use_syslog;
11extern char *command;
12extern char *statefile;
13extern char *lockpath;
14extern char *lockfile;
15
16struct snd_card_iterator {
17	int card;
18	char name[16];
19	bool single;
20	bool first;
21};
22
23void info_(const char *fcn, long line, const char *fmt, ...);
24void error_(const char *fcn, long line, const char *fmt, ...);
25void cerror_(const char *fcn, long line, int cond, const char *fmt, ...);
26void dbg_(const char *fcn, long line, const char *fmt, ...);
27void error_handler(const char *file, int line, const char *function, int err, const char *fmt, ...);
28
29#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95)
30#define info(...) do { info_(__func__, __LINE__, __VA_ARGS__); } while (0)
31#define error(...) do { error_(__func__, __LINE__, __VA_ARGS__); } while (0)
32#define cerror(cond, ...) do { cerror_(__func__, __LINE__, (cond) != 0, __VA_ARGS__); } while (0)
33#define dbg(...) do { dbg_(__func__, __LINE__, __VA_ARGS__); } while (0)
34#else
35#define info(args...) do { info_(__func__, __LINE__, ##args); }  while (0)
36#define error(args...) do { error_(__func__, __LINE__, ##args); }  while (0)
37#define cerror(cond, ...) do { error_(__func__, __LINE__, (cond) != 0, ##args); } while (0)
38#define dbg(args...) do { dbg_(__func__, __LINE__, ##args); }  while (0)
39#endif
40
41#define FLAG_UCM_DISABLED	(1<<0)
42#define FLAG_UCM_FBOOT		(1<<1)
43#define FLAG_UCM_BOOT		(1<<2)
44#define FLAG_UCM_DEFAULTS	(1<<3)
45#define FLAG_UCM_NODEV		(1<<4)
46
47void snd_card_iterator_init(struct snd_card_iterator *iter, int cardno);
48int snd_card_iterator_sinit(struct snd_card_iterator *iter, const char *cardname);
49const char *snd_card_iterator_next(struct snd_card_iterator *iter);
50int snd_card_iterator_error(struct snd_card_iterator *iter);
51
52int load_configuration(const char *file, snd_config_t **top, int *open_failed);
53int init(const char *cfgdir, const char *file, int flags, const char *cardname);
54int init_ucm(int flags, int cardno);
55int state_lock(const char *file, int timeout);
56int state_unlock(int lock_fd, const char *file);
57int card_lock(int card_number, int timeout);
58int card_unlock(int lock_fd, int card_number);
59int save_state(const char *file, const char *cardname);
60int load_state(const char *cfgdir, const char *file,
61	       const char *initfile, int initflags,
62	       const char *cardname, int do_init);
63int power(const char *argv[], int argc);
64int monitor(const char *name);
65int general_info(const char *name);
66int state_daemon(const char *file, const char *cardname, int period,
67		 const char *pidfile);
68int state_daemon_kill(const char *pidfile, const char *cmd);
69int clean(const char *cardname, char *const *extra_args);
70int snd_card_clean_cfgdir(const char *cfgdir, int cardno);
71
72/* utils */
73
74int file_map(const char *filename, char **buf, size_t *bufsize);
75void file_unmap(void *buf, size_t bufsize);
76size_t line_width(const char *buf, size_t bufsize, size_t pos);
77void initfailed(int cardnumber, const char *reason, int exitcode);
78
79static inline int hextodigit(int c)
80{
81        if (c >= '0' && c <= '9')
82                c -= '0';
83        else if (c >= 'a' && c <= 'f')
84                c = c - 'a' + 10;
85        else if (c >= 'A' && c <= 'F')
86                c = c - 'A' + 10;
87        else
88                return -1;
89        return c;
90}
91
92#define ARRAY_SIZE(a) (sizeof (a) / sizeof (a)[0])
93