147ad5e4cf2f6810db3c0e7ec79696496a94b6f0dDante Russo/* Copyright (c) 2011-2014, The Linux Foundation. All rights reserved.
2f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani *
3f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani * Redistribution and use in source and binary forms, with or without
4f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani * modification, are permitted provided that the following conditions are
5f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani * met:
6f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani *     * Redistributions of source code must retain the above copyright
7f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani *       notice, this list of conditions and the following disclaimer.
8f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani *     * Redistributions in binary form must reproduce the above
9f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani *       copyright notice, this list of conditions and the following
10f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani *       disclaimer in the documentation and/or other materials provided
11f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani *       with the distribution.
12e14a6c846df2ce4bb1847e4250991f7c52fd793dDante Russo *     * Neither the name of The Linux Foundation, nor the names of its
13f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani *       contributors may be used to endorse or promote products derived
14f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani *       from this software without specific prior written permission.
15f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani *
16f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani *
28f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani */
29f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani
30f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani#ifndef LOC_CFG_H
31f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani#define LOC_CFG_H
32f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani
3347ad5e4cf2f6810db3c0e7ec79696496a94b6f0dDante Russo#include <stdio.h>
34e14a6c846df2ce4bb1847e4250991f7c52fd793dDante Russo#include <stdint.h>
35e14a6c846df2ce4bb1847e4250991f7c52fd793dDante Russo
36bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#define LOC_MAX_PARAM_NAME                 80
37f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani#define LOC_MAX_PARAM_STRING               80
38bfff6343845ad9ff062c5fd97bb3b9be1053340eDante Russo#define LOC_MAX_PARAM_LINE    (LOC_MAX_PARAM_NAME + LOC_MAX_PARAM_STRING)
39f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani
40fe660078f05f448ececb0b1170ecd79e600db440Kevin Tang#define UTIL_UPDATE_CONF(conf_data, len, config_table) \
41fe660078f05f448ececb0b1170ecd79e600db440Kevin Tang    loc_update_conf((conf_data), (len), (config_table), \
42fe660078f05f448ececb0b1170ecd79e600db440Kevin Tang                    sizeof(config_table) / sizeof(config_table[0]))
43fe660078f05f448ececb0b1170ecd79e600db440Kevin Tang
44e14a6c846df2ce4bb1847e4250991f7c52fd793dDante Russo#define UTIL_READ_CONF_DEFAULT(filename) \
45e14a6c846df2ce4bb1847e4250991f7c52fd793dDante Russo    loc_read_conf((filename), NULL, 0);
46e14a6c846df2ce4bb1847e4250991f7c52fd793dDante Russo
47e14a6c846df2ce4bb1847e4250991f7c52fd793dDante Russo#define UTIL_READ_CONF(filename, config_table) \
48fe660078f05f448ececb0b1170ecd79e600db440Kevin Tang    loc_read_conf((filename), (config_table), sizeof(config_table) / sizeof(config_table[0]))
49f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani
50f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani/*=============================================================================
51f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani *
52f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani *                        MODULE TYPE DECLARATION
53f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani *
54f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani *============================================================================*/
55f77c85bb51137f5ba854184e5e9194197027438aAjay Dudanitypedef struct
56f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani{
57f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani  char                           param_name[LOC_MAX_PARAM_NAME];
58f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani  void                          *param_ptr;
59e14a6c846df2ce4bb1847e4250991f7c52fd793dDante Russo  uint8_t                       *param_set;   /* was this value set by config file? */
60e14a6c846df2ce4bb1847e4250991f7c52fd793dDante Russo  char                           param_type;  /* 'n' for number,
61e14a6c846df2ce4bb1847e4250991f7c52fd793dDante Russo                                                 's' for string,
62e14a6c846df2ce4bb1847e4250991f7c52fd793dDante Russo                                                 'f' for float */
63f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani} loc_param_s_type;
64f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani
65f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani/*=============================================================================
66f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani *
67f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani *                          MODULE EXTERNAL DATA
68f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani *
69f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani *============================================================================*/
70f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani
71f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani#ifdef __cplusplus
72f77c85bb51137f5ba854184e5e9194197027438aAjay Dudaniextern "C" {
73f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani#endif
74f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani
75f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani/*=============================================================================
76f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani *
77f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani *                       MODULE EXPORTED FUNCTIONS
78f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani *
79f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani *============================================================================*/
80fe660078f05f448ececb0b1170ecd79e600db440Kevin Tangvoid loc_read_conf(const char* conf_file_name,
81fe660078f05f448ececb0b1170ecd79e600db440Kevin Tang                   loc_param_s_type* config_table,
82fe660078f05f448ececb0b1170ecd79e600db440Kevin Tang                   uint32_t table_length);
83fe660078f05f448ececb0b1170ecd79e600db440Kevin Tangint loc_read_conf_r(FILE *conf_fp, loc_param_s_type* config_table,
84fe660078f05f448ececb0b1170ecd79e600db440Kevin Tang                    uint32_t table_length);
85fe660078f05f448ececb0b1170ecd79e600db440Kevin Tangint loc_update_conf(const char* conf_data, int32_t length,
86fe660078f05f448ececb0b1170ecd79e600db440Kevin Tang                    loc_param_s_type* config_table, uint32_t table_length);
87f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani#ifdef __cplusplus
88f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani}
89f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani#endif
90f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani
91f77c85bb51137f5ba854184e5e9194197027438aAjay Dudani#endif /* LOC_CFG_H */
92