diff --git a/src/main/core/Module.mk b/src/main/core/Module.mk index f86102c..6f5364f 100644 --- a/src/main/core/Module.mk +++ b/src/main/core/Module.mk @@ -5,6 +5,7 @@ libs_core := \ src_core := \ boot.c \ + config-ext.c \ config-property-node.c \ log-bt-ext.c \ log-bt.c \ diff --git a/src/main/core/config-ext.c b/src/main/core/config-ext.c new file mode 100644 index 0000000..24ee081 --- /dev/null +++ b/src/main/core/config-ext.c @@ -0,0 +1,132 @@ +#include "iface-core/config.h" +#include "iface-core/log.h" + +#include "util/net.h" + +void bt_core_config_ext_s8_get( + const bt_core_config_t *config, const char *path, int8_t *value) +{ + bt_core_config_result_t result; + + result = bt_core_config_s8_get(config, path, value); + bt_core_config_fatal_on_error(result); +} + +void bt_core_config_ext_u8_get( + const bt_core_config_t *config, const char *path, uint8_t *value) +{ + bt_core_config_result_t result; + + result = bt_core_config_u8_get(config, path, value); + bt_core_config_fatal_on_error(result); +} + +void bt_core_config_ext_s16_get( + const bt_core_config_t *config, const char *path, int16_t *value) +{ + bt_core_config_result_t result; + + result = bt_core_config_s16_get(config, path, value); + bt_core_config_fatal_on_error(result); +} + +void bt_core_config_ext_u16_get( + const bt_core_config_t *config, const char *path, uint16_t *value) +{ + bt_core_config_result_t result; + + result = bt_core_config_u16_get(config, path, value); + bt_core_config_fatal_on_error(result); +} + +void bt_core_config_ext_s32_get( + const bt_core_config_t *config, const char *path, int32_t *value) +{ + bt_core_config_result_t result; + + result = bt_core_config_s32_get(config, path, value); + bt_core_config_fatal_on_error(result); +} + +void bt_core_config_ext_u32_get( + const bt_core_config_t *config, const char *path, uint32_t *value) +{ + bt_core_config_result_t result; + + result = bt_core_config_u32_get(config, path, value); + bt_core_config_fatal_on_error(result); +} + +void bt_core_config_ext_s64_get( + const bt_core_config_t *config, const char *path, int64_t *value) +{ + bt_core_config_result_t result; + + result = bt_core_config_s64_get(config, path, value); + bt_core_config_fatal_on_error(result); +} + +void bt_core_config_ext_u64_get( + const bt_core_config_t *config, const char *path, uint64_t *value) +{ + bt_core_config_result_t result; + + result = bt_core_config_u64_get(config, path, value); + bt_core_config_fatal_on_error(result); +} + +void bt_core_config_ext_float_get( + const bt_core_config_t *config, const char *path, float *value) +{ + bt_core_config_result_t result; + + result = bt_core_config_float_get(config, path, value); + bt_core_config_fatal_on_error(result); +} + +void bt_core_config_ext_double_get( + const bt_core_config_t *config, const char *path, double *value) +{ + bt_core_config_result_t result; + + result = bt_core_config_double_get(config, path, value); + bt_core_config_fatal_on_error(result); +} + +void bt_core_config_ext_bool_get( + const bt_core_config_t *config, const char *path, bool *value) +{ + bt_core_config_result_t result; + + result = bt_core_config_bool_get(config, path, value); + bt_core_config_fatal_on_error(result); +} + +void bt_core_config_ext_bin_get( + const bt_core_config_t *config, const char *path, void *value, size_t len) +{ + bt_core_config_result_t result; + + result = bt_core_config_bin_get(config, path, value, len); + bt_core_config_fatal_on_error(result); +} + +void bt_core_config_ext_str_get( + const bt_core_config_t *config, const char *path, char *value, size_t len) +{ + bt_core_config_result_t result; + + result = bt_core_config_str_get(config, path, value, len); + bt_core_config_fatal_on_error(result); +} + +void bt_core_config_ext_net_addr_get(const bt_core_config_t *config, const char *path, struct net_addr *addr) +{ + char buffer[1024]; + + bt_core_config_ext_str_get(config, "server", buffer, sizeof(buffer)); + + if (!net_str_parse(buffer, addr)) { + log_fatal("Cannot parse server address: %s", buffer); + } +} \ No newline at end of file diff --git a/src/main/core/config-ext.h b/src/main/core/config-ext.h new file mode 100644 index 0000000..09acf46 --- /dev/null +++ b/src/main/core/config-ext.h @@ -0,0 +1,36 @@ +#ifndef CORE_CONFIG_EXT_H +#define CORE_CONFIG_EXT_H + +#include "iface-core/config.h" + +#include "util/net.h" + +void bt_core_config_ext_s8_get( + const bt_core_config_t *config, const char *path, int8_t *value); +void bt_core_config_ext_u8_get( + const bt_core_config_t *config, const char *path, uint8_t *value); +void bt_core_config_ext_s16_get( + const bt_core_config_t *config, const char *path, int16_t *value); +void bt_core_config_ext_u16_get( + const bt_core_config_t *config, const char *path, uint16_t *value); +void bt_core_config_ext_s32_get( + const bt_core_config_t *config, const char *path, int32_t *value); +void bt_core_config_ext_u32_get( + const bt_core_config_t *config, const char *path, uint32_t *value); +void bt_core_config_ext_s64_get( + const bt_core_config_t *config, const char *path, int64_t *value); +void bt_core_config_ext_u64_get( + const bt_core_config_t *config, const char *path, uint64_t *value); +void bt_core_config_ext_float_get( + const bt_core_config_t *config, const char *path, float *value); +void bt_core_config_ext_double_get( + const bt_core_config_t *config, const char *path, double *value); +void bt_core_config_ext_bool_get( + const bt_core_config_t *config, const char *path, bool *value); +void bt_core_config_ext_bin_get( + const bt_core_config_t *config, const char *path, void *value, size_t len); +void bt_core_config_ext_str_get( + const bt_core_config_t *config, const char *path, char *value, size_t len); +void bt_core_config_ext_net_addr_get(const bt_core_config_t *config, const char *path, struct net_addr *addr); + +#endif \ No newline at end of file