1 #include <stdbool.h>
2 #include <alsa/asoundlib.h>
3
4 #define LOCK_TIMEOUT 10
5
6 extern int debugflag;
7 extern int force_restore;
8 extern int ignore_nocards;
9 extern int do_lock;
10 extern int use_syslog;
11 extern char *command;
12 extern char *statefile;
13 extern char *lockpath;
14 extern char *lockfile;
15
16 struct snd_card_iterator {
17 int card;
18 char name[16];
19 bool single;
20 bool first;
21 };
22
23 void info_(const char *fcn, long line, const char *fmt, ...);
24 void error_(const char *fcn, long line, const char *fmt, ...);
25 void cerror_(const char *fcn, long line, int cond, const char *fmt, ...);
26 void dbg_(const char *fcn, long line, const char *fmt, ...);
27 void 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
47 void snd_card_iterator_init(struct snd_card_iterator *iter, int cardno);
48 int snd_card_iterator_sinit(struct snd_card_iterator *iter, const char *cardname);
49 const char *snd_card_iterator_next(struct snd_card_iterator *iter);
50 int snd_card_iterator_error(struct snd_card_iterator *iter);
51
52 int load_configuration(const char *file, snd_config_t **top, int *open_failed);
53 int init(const char *cfgdir, const char *file, int flags, const char *cardname);
54 int init_ucm(int flags, int cardno);
55 int state_lock(const char *file, int timeout);
56 int state_unlock(int lock_fd, const char *file);
57 int card_lock(int card_number, int timeout);
58 int card_unlock(int lock_fd, int card_number);
59 int save_state(const char *file, const char *cardname);
60 int load_state(const char *cfgdir, const char *file,
61 const char *initfile, int initflags,
62 const char *cardname, int do_init);
63 int power(const char *argv[], int argc);
64 int monitor(const char *name);
65 int general_info(const char *name);
66 int state_daemon(const char *file, const char *cardname, int period,
67 const char *pidfile);
68 int state_daemon_kill(const char *pidfile, const char *cmd);
69 int clean(const char *cardname, char *const *extra_args);
70 int snd_card_clean_cfgdir(const char *cfgdir, int cardno);
71
72 /* utils */
73
74 int file_map(const char *filename, char **buf, size_t *bufsize);
75 void file_unmap(void *buf, size_t bufsize);
76 size_t line_width(const char *buf, size_t bufsize, size_t pos);
77 void initfailed(int cardnumber, const char *reason, int exitcode);
78
hextodigit(int c)79 static 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