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