Go to the source code of this file.
Functions | |
static int | kb_is_valid_ientifier (const char *str) |
static void | kb_config_error (const char *file, unsigned int line, const char *func, unsigned int error, va_list argptr) |
static int | kb_parse_section (int argc, char *argv[], void *data) |
static int | kb_parse_modbus (int argc, char *argv[], void *data) |
static int | kb_parse_modbusaddr (int argc, char *argv[], void *data) |
static int | kb_parse_alias (int argc, char *argv[], void *data) |
static int | kb_parse_device (int argc, char *argv[], void *data) |
static int | kb_parse_register (int argc, char *argv[], void *data) |
int | kb_config_init (int argc, char *argv[]) |
void | kb_config_exit (void) |
kb_device_config_t * | kb_lookup_device (const char *name) |
kb_register_config_t * | kb_lookup_register (const char *name) |
static int | kb_is_valid_identifier (const char *str) |
static char * | kb_build_scoped_name (char *scoped_name, const char *name) |
int | kb_parse_config_file (const char *file) |
int | kb_enum_section (int(*func)(const char *name, kb_section_config_t *section, void *context), void *context) |
int | kb_enum_alias (const char *section_name, int(*func)(const char *name, kb_alias_config_t *alias, void *context), void *context) |
int | kb_enum_device (const char *section_name, int(*func)(const char *name, kb_device_config_t *device, void *context), void *context) |
int | kb_enum_register (const char *section_name, int(*func)(const char *name, kb_register_config_t *reg, void *context), void *context) |
Variables | |
static struct kb_command_s | kb_config_cmds [] |
const char * | device_class_names [] |
static kb_symbol_table_t | kb_config_table |
static kb_symbol_t * | kb_sections = NULL |
static kb_symbol_t * | kb_config_scope = NULL |
static const char * | kb_config_file = 0 |
static unsigned int | kb_config_line = 0 |
Configuration Handling
Definition in file kb_config.c.
static char* kb_build_scoped_name | ( | char * | scoped_name, | |
const char * | name | |||
) | [static] |
The function builds a symbol name using the current scope.
scoped_name | Pointer to the buffer that will receive the scoped name. If a NULL value is specified, the internal buffer is used. | |
name | Pointer to the name to scope |
Definition at line 263 of file kb_config.c.
References KB_SYMBOL_NAME_SIZE, and kb_symbol_s::name.
Referenced by kb_parse_alias(), kb_parse_device(), and kb_parse_register().
static void kb_config_error | ( | const char * | file, | |
unsigned int | line, | |||
const char * | func, | |||
unsigned int | error, | |||
va_list | argptr | |||
) | [static] |
This function is the error handler of the configuration file parser
file | A string containing the name of the file where the error has occurred. | |
line | Line number where the error has occurred. | |
func | A string containing the name of the function where the error has occurred. | |
error | the code of the error | |
argptr | optional arguments |
Definition at line 293 of file kb_config.c.
References kb_config_file, kb_config_line, and kb_verror().
Referenced by kb_parse_config_file().
void kb_config_exit | ( | void | ) |
This function should be called on exit by 'kb_init' and free all memory used in this module.
Definition at line 123 of file kb_config.c.
References kb_destroy_symbol_table().
Referenced by kb_exit(), and main().
int kb_config_init | ( | int | argc, | |
char * | argv[] | |||
) |
This function initializes the configuration tables and variables
argc | Number of element in the array of arguments | |
argv | Array of string containing all arguments |
Definition at line 78 of file kb_config.c.
References KB_CONFIG_DIR_INTERNAL, kb_create_symbol_table(), kb_parse_config_file(), KB_WARN_CONFIG_FILE, KB_WARN_OPENDIR, and kb_warning().
Referenced by kb_init(), and main().
int kb_enum_alias | ( | const char * | section_name, | |
int(*)(const char *name, kb_alias_config_t *alias, void *context) | func, | |||
void * | context | |||
) |
This function enumerates all aliases of a given section.
section_name | A string containing the name of the section | |
func | A function called for each alias found. | |
context | A Pointer or a value passed as parameter to function 'func'. |
Definition at line 934 of file kb_config.c.
References kb_section_config_s::alias_count, kb_section_config_s::aliases, kb_lookup_symbol(), KB_SYMBOL_TYPE_SECTION, kb_symbol_s::name, kb_alias_config_s::next, kb_symbol_s::type, and kb_symbol_s::value.
int kb_enum_device | ( | const char * | section_name, | |
int(*)(const char *name, kb_device_config_t *device, void *context) | func, | |||
void * | context | |||
) |
This function enumerates all devices of a given section.
section_name | A string containing the name of the section | |
func | A function called for each device found. | |
context | A Pointer or a value passed as parameter to function 'func'. |
Definition at line 985 of file kb_config.c.
References kb_section_config_s::device_count, kb_section_config_s::devices, kb_lookup_symbol(), KB_SYMBOL_TYPE_SECTION, kb_symbol_s::name, kb_device_config_s::next, kb_symbol_s::type, and kb_symbol_s::value.
Referenced by print_section().
int kb_enum_register | ( | const char * | section_name, | |
int(*)(const char *name, kb_register_config_t *reg, void *context) | func, | |||
void * | context | |||
) |
This function enumerate all registers of a given section
section_name | A string containing the name of the section | |
func | A function called for each register found. | |
context | A Pointer or a value passed as parameter to function 'func'. |
Definition at line 1035 of file kb_config.c.
References kb_lookup_symbol(), KB_SYMBOL_TYPE_SECTION, kb_symbol_s::name, kb_register_config_s::next, kb_section_config_s::register_count, kb_section_config_s::registers, kb_symbol_s::type, and kb_symbol_s::value.
Referenced by print_section().
int kb_enum_section | ( | int(*)(const char *name, kb_section_config_t *section, void *context) | func, | |
void * | context | |||
) |
This function enumerates all sections.
func | A Pointer to a function called for each section found. | |
context | A Pointer or a value passed as parameter to the function 'func' |
Definition at line 897 of file kb_config.c.
References kb_symbol_s::name, kb_section_config_s::next, and kb_symbol_s::value.
Referenced by main().
static int kb_is_valid_identifier | ( | const char * | str | ) | [static] |
This function checks if a string is a valid identifier. A valid identifier must begin with a letter of '_' and is followed by letters, digits or '_'. An identifier must be longer than 3 characters.
letter ::= [A-Za-z_] digit ::= [0-9]
identifier ::= letter ( letter | digit )*
str | Pointer to a string containing an identifier to check |
Definition at line 221 of file kb_config.c.
References kb_error(), and KB_ERROR_INVALID.
Referenced by kb_parse_alias(), kb_parse_device(), kb_parse_register(), and kb_parse_section().
static int kb_is_valid_ientifier | ( | const char * | str | ) | [static] |
kb_device_config_t* kb_lookup_device | ( | const char * | name | ) |
This function try to find a device configuration descriptor given its name.
name | A string containing the name of the device to find. |
Definition at line 137 of file kb_config.c.
References kb_lookup_symbol(), KB_SYMBOL_TYPE_ALIAS, KB_SYMBOL_TYPE_DEVICE, kb_alias_config_s::name, kb_alias_config_s::ptr, kb_symbol_s::type, and kb_symbol_s::value.
Referenced by knet_open(), and main().
kb_register_config_t* kb_lookup_register | ( | const char * | name | ) |
This function try to find a register configuration descriptor given its name.
name | A string containing the name of the register to find. |
Definition at line 175 of file kb_config.c.
References kb_lookup_symbol(), KB_SYMBOL_TYPE_ALIAS, KB_SYMBOL_TYPE_REGISTER, kb_alias_config_s::name, kb_alias_config_s::ptr, kb_symbol_s::type, and kb_symbol_s::value.
static int kb_parse_alias | ( | int | argc, | |
char * | argv[], | |||
void * | data | |||
) | [static] |
This function parses a 'alias' command line in a configuration
argc | Number of arguments | |
argv | An array of strings that represents the list of token |
Definition at line 458 of file kb_config.c.
References kb_section_config_s::alias_count, kb_section_config_s::aliases, kb_symbol_s::alloc, kb_add_symbol(), KB_ALLOC, kb_build_scoped_name(), kb_error(), KB_ERROR_NOSECTION, KB_ERROR_SYMDEF, kb_is_valid_identifier(), kb_lookup_symbol(), KB_SYMBOL_NAME_SIZE, KB_SYMBOL_TYPE_ALIAS, kb_symbol_s::name, kb_alias_config_s::name, kb_alias_config_s::next, kb_symbol_s::next, kb_alias_config_s::ptr, kb_symbol_s::type, and kb_symbol_s::value.
int kb_parse_config_file | ( | const char * | file | ) |
This function parses a configuration file, builds and stores configuration information in memory.
file | configuration file to parse |
Definition at line 836 of file kb_config.c.
References buf, KB_ALLOC, kb_config_error(), kb_config_file, kb_config_line, kb_error(), KB_ERROR_FILEOPEN, KB_ERROR_UNKCMD, kb_free, kb_parse_command(), and kb_set_error_handler().
Referenced by kb_config_init().
static int kb_parse_device | ( | int | argc, | |
char * | argv[], | |||
void * | data | |||
) | [static] |
This function parses a 'device' command line in a configuration
argc | Number of arguments | |
argv | An array of strings that represents the list of token |
Definition at line 535 of file kb_config.c.
References kb_device_config_s::address, kb_symbol_s::alloc, kb_device_config_s::defined, device_class_names, kb_section_config_s::device_count, kb_device_config_s::device_name, kb_section_config_s::devices, kb_add_symbol(), KB_ALLOC, kb_build_scoped_name(), KB_DEVICE_CLASS_I2C, KB_DEVICE_CLASS_MODULE, KB_DEVICE_CLASS_RS232, KB_DEVICE_CLASS_SPI, kb_error(), KB_ERROR_DEVCLASSUSED, KB_ERROR_INVNAME, KB_ERROR_INVNUM, KB_ERROR_NOSECTION, KB_ERROR_SYMDEF, KB_ERROR_UNKDEVCLASS, kb_find_string(), kb_is_valid_identifier(), kb_lookup_symbol(), KB_SYMBOL_NAME_SIZE, KB_SYMBOL_TYPE_DEVICE, kb_device_config_s::kclass, kb_symbol_s::name, kb_symbol_s::next, kb_device_config_s::next, kb_device_config_s::section, kb_symbol_s::type, and kb_symbol_s::value.
static int kb_parse_modbus | ( | int | argc, | |
char * | argv[], | |||
void * | data | |||
) | [static] |
This function parses a 'modulebus' command line in a configuration file. This will set the module bus for the current section. The module bus is used to access all the devices defined as 'module'.
argc | Number of arguments | |
argv | An array of strings that represents the list of token |
Definition at line 321 of file kb_config.c.
References kb_error(), KB_ERROR_NOSECTION, KB_ERROR_UNKBUS, kb_find_string(), knet_bus_names, kb_section_config_s::module_bus, and kb_symbol_s::value.
static int kb_parse_modbusaddr | ( | int | argc, | |
char * | argv[], | |||
void * | data | |||
) | [static] |
This function parses a 'modbusaddr' command line in a configuration file. This will set the address for module bus of the current section. The module bus is used to access all the devices defined as 'module'.
argc | Number of arguments | |
argv | An array of strings that represents the list of token |
Definition at line 367 of file kb_config.c.
References kb_error(), KB_ERROR_NOSECTION, kb_section_config_s::module_bus_addr, and kb_symbol_s::value.
static int kb_parse_register | ( | int | argc, | |
char * | argv[], | |||
void * | data | |||
) | [static] |
This function parses a 'register' command line in a configuration
argc | Number of arguments | |
argv | An array of strings that represents the list of token |
Definition at line 766 of file kb_config.c.
References kb_symbol_s::alloc, kb_add_symbol(), KB_ALLOC, kb_build_scoped_name(), kb_error(), KB_ERROR_INVNUM, KB_ERROR_NOSECTION, KB_ERROR_SYMDEF, kb_is_valid_identifier(), kb_lookup_symbol(), KB_SYMBOL_TYPE_REGISTER, kb_symbol_s::name, kb_symbol_s::next, kb_register_config_s::next, kb_section_config_s::register_count, kb_section_config_s::registers, kb_symbol_s::type, kb_register_config_s::value, and kb_symbol_s::value.
static int kb_parse_section | ( | int | argc, | |
char * | argv[], | |||
void * | data | |||
) | [static] |
This function parses a 'section' command line in a configuration
argc | Number of arguments | |
argv | An array of strings that represents the list of token |
Definition at line 400 of file kb_config.c.
References kb_symbol_s::alloc, kb_section_config_s::device_count, kb_section_config_s::devices, kb_add_symbol(), KB_ALLOC, kb_error(), KB_ERROR_SYMDEF, kb_is_valid_identifier(), kb_lookup_symbol(), KB_SYMBOL_TYPE_SECTION, kb_section_config_s::module_bus, kb_section_config_s::module_bus_addr, kb_symbol_s::name, kb_symbol_s::next, kb_section_config_s::next, kb_section_config_s::register_count, kb_section_config_s::registers, kb_symbol_s::type, and kb_symbol_s::value.
const char* device_class_names[] |
Initial value:
{ "i2c" , "spi" , "module" , "rs232" , NULL }
Definition at line 58 of file kb_config.c.
Referenced by kb_parse_device().
struct kb_command_s kb_config_cmds[] [static] |
Initial value:
{ { "section" , 1 , 1 , kb_parse_section } , { "modulebus" , 1 , 1 , kb_parse_modbus } , { "modbusaddr", 1 , 1 , kb_parse_modbusaddr} , { "alias" , 1 , 1 , kb_parse_alias } , { "device" , 3 , 3 , kb_parse_device } , { "register" , 2 , 2 , kb_parse_register } , { NULL , 0 , 0 , NULL } }
Definition at line 43 of file kb_config.c.
const char* kb_config_file = 0 [static] |
Definition at line 65 of file kb_config.c.
Referenced by kb_config_error(), and kb_parse_config_file().
unsigned int kb_config_line = 0 [static] |
Definition at line 66 of file kb_config.c.
Referenced by kb_config_error(), and kb_parse_config_file().
kb_symbol_t* kb_config_scope = NULL [static] |
Definition at line 64 of file kb_config.c.
kb_symbol_table_t kb_config_table [static] |
Definition at line 62 of file kb_config.c.
kb_symbol_t* kb_sections = NULL [static] |
Definition at line 63 of file kb_config.c.