feat: Add config-ext

Add wrapper functions that fatal on any error.
Saves a lot of error checking code on occasions
where we want to fail anyway because some
configuration value could not be retrieved
successfully.
This commit is contained in:
icex2
2024-08-15 11:34:33 +02:00
parent e3c97801ed
commit c965011788
3 changed files with 169 additions and 0 deletions
+1
View File
@@ -5,6 +5,7 @@ libs_core := \
src_core := \
boot.c \
config-ext.c \
config-property-node.c \
log-bt-ext.c \
log-bt.c \
+132
View File
@@ -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);
}
}
+36
View File
@@ -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