1 /* Copyright 2017 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 <syslog.h>
7
8 #include "cras_board_config.h"
9 #include "iniparser_wrapper.h"
10
11 /* Allocate 63 chars + 1 for null where declared. */
12 static const unsigned int MAX_INI_NAME_LEN = 63;
13 static const unsigned int MAX_KEY_LEN = 63;
14 static const int32_t DEFAULT_OUTPUT_BUFFER_SIZE = 512;
15 static const int32_t AEC_SUPPORTED_DEFAULT = 0;
16
17 #define CONFIG_NAME "board.ini"
18 #define DEFAULT_OUTPUT_BUF_SIZE_INI_KEY "output:default_output_buffer_size"
19 #define AEC_SUPPORTED_INI_KEY "processing:aec_supported"
20
21
cras_board_config_get(const char * config_path,struct cras_board_config * board_config)22 void cras_board_config_get(const char *config_path,
23 struct cras_board_config *board_config)
24 {
25 char ini_name[MAX_INI_NAME_LEN + 1];
26 char ini_key[MAX_KEY_LEN + 1];
27 dictionary *ini;
28
29 board_config->default_output_buffer_size = DEFAULT_OUTPUT_BUFFER_SIZE;
30 board_config->aec_supported = AEC_SUPPORTED_DEFAULT;
31 if (config_path == NULL)
32 return;
33
34 snprintf(ini_name, MAX_INI_NAME_LEN, "%s/%s", config_path,
35 CONFIG_NAME);
36 ini_name[MAX_INI_NAME_LEN] = '\0';
37 ini = iniparser_load_wrapper(ini_name);
38 if (ini == NULL) {
39 syslog(LOG_DEBUG, "No ini file %s", ini_name);
40 return;
41 }
42
43 snprintf(ini_key, MAX_KEY_LEN, DEFAULT_OUTPUT_BUF_SIZE_INI_KEY);
44 ini_key[MAX_KEY_LEN] = 0;
45 board_config->default_output_buffer_size =
46 iniparser_getint(ini, ini_key, DEFAULT_OUTPUT_BUFFER_SIZE);
47
48 snprintf(ini_key, MAX_KEY_LEN, AEC_SUPPORTED_INI_KEY);
49 ini_key[MAX_KEY_LEN] = 0;
50 board_config->aec_supported =
51 iniparser_getint(ini, ini_key, AEC_SUPPORTED_DEFAULT);
52
53 iniparser_freedict(ini);
54 syslog(LOG_DEBUG, "Loaded ini file %s", ini_name);
55 }
56
57