• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
2  * Use of this source code is governed by a BSD-style license that can be
3  * found in the LICENSE file.
4  */
5 
6 #include <getopt.h>
7 #include <signal.h>
8 #include <syslog.h>
9 
10 #include "cras_config.h"
11 #include "cras_iodev_list.h"
12 #include "cras_server.h"
13 #include "cras_system_state.h"
14 #include "cras_dsp.h"
15 
16 static struct option long_options[] = {
17 	{"dsp_config", required_argument, 0, 'd'},
18 	{"syslog_mask", required_argument, 0, 'l'},
19 	{"device_config_dir", required_argument, 0, 'c'},
20 	{"disable_profile", required_argument, 0, 'D'},
21 	{"internal_ucm_suffix", required_argument, 0, 'u'},
22 	{0, 0, 0, 0}
23 };
24 
25 /* Ignores sigpipe, we'll notice when a read/write fails. */
set_signals()26 static void set_signals()
27 {
28 	signal(SIGPIPE, SIG_IGN);
29 	signal(SIGCHLD, SIG_IGN);
30 }
31 
32 /* Entry point for the server. */
main(int argc,char ** argv)33 int main(int argc, char **argv)
34 {
35 	int c, option_index;
36 	int log_mask = LOG_ERR;
37 	const char default_dsp_config[] = CRAS_CONFIG_FILE_DIR "/dsp.ini";
38 	const char *dsp_config = default_dsp_config;
39 	const char *device_config_dir = CRAS_CONFIG_FILE_DIR;
40 	const char *internal_ucm_suffix = NULL;
41 	unsigned int profile_disable_mask = 0;
42 
43 	set_signals();
44 
45 	while (1) {
46 		c = getopt_long(argc, argv, "", long_options, &option_index);
47 		if (c == -1)
48 			break;
49 
50 		switch (c) {
51 		/* To keep this code simple we ask the (technical)
52 		   user to pass one of integer values defined in
53 		   syslog.h - this is a development feature after
54 		   all. While there is no formal standard for the
55 		   integer values there is an informal standard:
56 		   http://tools.ietf.org/html/rfc5424#page-11 */
57 		case 'l':
58 			log_mask = atoi(optarg);
59 			break;
60 
61 		case 'c':
62 			device_config_dir = optarg;
63 			break;
64 
65 		case 'd':
66 			dsp_config = optarg;
67 			break;
68 		/* --disable_profile option takes list of profile names separated by ',' */
69 		case 'D':
70 			while ((optarg != NULL) && (*optarg != 0)) {
71 				if (strncmp(optarg, "hfp", 3) == 0) {
72 					profile_disable_mask |= CRAS_SERVER_PROFILE_MASK_HFP;
73 				}
74 				if (strncmp(optarg, "hsp", 3) == 0) {
75 					profile_disable_mask |= CRAS_SERVER_PROFILE_MASK_HSP;
76 				}
77 				if (strncmp(optarg, "a2dp", 4) == 0) {
78 					profile_disable_mask |= CRAS_SERVER_PROFILE_MASK_A2DP;
79 				}
80 				optarg = strchr(optarg, ',');
81 				if (optarg != NULL) {
82 					optarg++;
83 				}
84 			}
85 			break;
86 		case 'u':
87 			if (*optarg != 0)
88 				internal_ucm_suffix = optarg;
89 			break;
90 		default:
91 			break;
92 		}
93 	}
94 
95 	switch (log_mask) {
96 		case LOG_EMERG: case LOG_ALERT: case LOG_CRIT: case LOG_ERR:
97 		case LOG_WARNING: case LOG_NOTICE: case LOG_INFO:
98 		case LOG_DEBUG:
99 			break;
100 		default:
101 			fprintf(stderr,
102 				"Unsupported syslog priority value: %d; using LOG_ERR=%d\n",
103 				log_mask, LOG_ERR);
104 			log_mask = LOG_ERR;
105 			break;
106 	}
107 	setlogmask(LOG_UPTO(log_mask));
108 
109 	/* Initialize system. */
110 	cras_server_init();
111 	cras_system_state_init(device_config_dir);
112 	if (internal_ucm_suffix)
113 		cras_system_state_set_internal_ucm_suffix(internal_ucm_suffix);
114 	cras_dsp_init(dsp_config);
115 	cras_iodev_list_init();
116 
117 	/* Start the server. */
118 	return cras_server_run(profile_disable_mask);
119 }
120