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