kb_config.c File Reference

This module reads, parses and store the information contained in the configuration files. More...

Include dependency graph for kb_config.c:

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_tkb_lookup_device (const char *name)
kb_register_config_tkb_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_tkb_sections = NULL
static kb_symbol_tkb_config_scope = NULL
static const char * kb_config_file = 0
static unsigned int kb_config_line = 0


Detailed Description

This module reads, parses and store the information contained in the configuration files.

Configuration Handling

Author:
Cédric Gaudin (K-Team SA)
Note:
Copyright (C) 2004 K-TEAM SA
Bug:
none discovered.
Todo:
nothing.

Definition in file kb_config.c.


Function Documentation

static char* kb_build_scoped_name ( char *  scoped_name,
const char *  name 
) [static]

The function builds a symbol name using the current scope.

Parameters:
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
Returns:
Pointer to the buffer
Remarks:
This function is not exported outside this module.

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

Parameters:
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
Remarks:
This function is NOT exported outside this module.

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().

Here is the call graph for this function:

void kb_config_exit ( void   ) 

This function should be called on exit by 'kb_init' and free all memory used in this module.

Remarks:
Never call this function !

Definition at line 123 of file kb_config.c.

References kb_destroy_symbol_table().

Referenced by kb_exit(), and main().

Here is the call graph for this function:

int kb_config_init ( int  argc,
char *  argv[] 
)

This function initializes the configuration tables and variables

Parameters:
argc Number of element in the array of arguments
argv Array of string containing all arguments
Returns:
an error code
  • <0 error code
  • 0 no error

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().

Here is the call graph for this function:

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.

Parameters:
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'.
Returns:
an error code:
  • <0 on error
  • >= number of aliases in a given section

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.

Here is the call graph for this function:

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.

Parameters:
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'.
Returns:
an error code:
  • <0 on error
  • >= number of devices in a given section

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().

Here is the call graph for this function:

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

Parameters:
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'.
Returns:
an error code:
  • <0 on error
  • >= number of registers in a given section

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().

Here is the call graph for this function:

int kb_enum_section ( int(*)(const char *name, kb_section_config_t *section, void *context)  func,
void *  context 
)

This function enumerates all sections.

Parameters:
func A Pointer to a function called for each section found.
context A Pointer or a value passed as parameter to the function 'func'
Returns:
an error code:
  • <0 on error
  • >=0 the number of sections

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 )*

Parameters:
str Pointer to a string containing an identifier to check
Returns:
An error code:
  • <0 on error
  • 0 the identifier is valid
Remarks:
This function is NOT exported outside this module.

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().

Here is the call graph for this function:

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.

Parameters:
name A string containing the name of the device to find.
Returns:
A pointer to the device configuration descriptor or NULL if no device is found.

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().

Here is the call graph for this function:

kb_register_config_t* kb_lookup_register ( const char *  name  ) 

This function try to find a register configuration descriptor given its name.

Parameters:
name A string containing the name of the register to find.
Returns:
A pointer to the register configuration descriptor or NULL if no register is found.

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.

Here is the call graph for this function:

static int kb_parse_alias ( int  argc,
char *  argv[],
void *  data 
) [static]

This function parses a 'alias' command line in a configuration

Parameters:
argc Number of arguments
argv An array of strings that represents the list of token
Returns:
an error code:
  • <0 on error
  • 0 'alias' already defined
  • 1 on success
Remarks:
This function is NOT exported outside this module

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.

Here is the call graph for this function:

int kb_parse_config_file ( const char *  file  ) 

This function parses a configuration file, builds and stores configuration information in memory.

Parameters:
file configuration file to parse
Returns:
an error code:
  • <0 on error
  • 0 on success

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().

Here is the call graph for this function:

static int kb_parse_device ( int  argc,
char *  argv[],
void *  data 
) [static]

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'.

Parameters:
argc Number of arguments
argv An array of strings that represents the list of token
Returns:
an error code:
  • <0 on error
  • 0 'section' already defined
  • 1 on success
Remarks:
This function is NOT exported outside this module

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.

Here is the call graph for this function:

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'.

Parameters:
argc Number of arguments
argv An array of strings that represents the list of token
Returns:
an error code:
  • <0 on error
  • 0 'section' already defined
  • 1 on success
Remarks:
This function is NOT exported outside this module

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.

Here is the call graph for this function:

static int kb_parse_register ( int  argc,
char *  argv[],
void *  data 
) [static]

This function parses a 'register' command line in a configuration

Parameters:
argc Number of arguments
argv An array of strings that represents the list of token
Returns:
an error code:
  • <0 on error
  • 0 'register' already defined
  • 1 on success
Remarks:
This function is NOT exported outside this module

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.

Here is the call graph for this function:

static int kb_parse_section ( int  argc,
char *  argv[],
void *  data 
) [static]

This function parses a 'section' command line in a configuration

Parameters:
argc Number of arguments
argv An array of strings that represents the list of token
Returns:
an error code:
  • <0 on error
  • 0 'section' already defined
  • 1 on success
Remarks:
This function is NOT exported outside this module

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.

Here is the call graph for this function:


Variable Documentation

const char* device_class_names[]

Initial value:

 { 
    "i2c" , "spi" , "module" , "rs232" , NULL 
  }
List of existing device class names, as they should appear in configuration files. Knet bus names are defined in knet.h.

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.

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.


Generated on Wed Dec 15 11:49:27 2010 for KoreBot Library by  doxygen 1.5.5