CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
SET(INIT_DB "system_info_init_db")
-SET(SRCS ${CMAKE_SOURCE_DIR}/src/init_db/system_info_db_init.c)
+SET(SRCS system_info_db_init.c system_info_generated_util.c)
INCLUDE_DIRECTORIES(include)
SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie")
+ADD_CUSTOM_TARGET(SYSTEM_INFO_GENERATED_UTIL ALL
+ WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
+ BYPRODUCTS system_info_generated_util.c system_info_generated_util.h
+ COMMAND ${Python3_EXECUTABLE} -m SystemInfoGenerator
+ --input ${MODEL_CONFIG_RO_PATH}
+ --output-util-source=src/init_db/system_info_generated_util.c
+ --output-util-header=src/init_db/system_info_generated_util.h
+ VERBATIM)
+
ADD_EXECUTABLE(${INIT_DB} ${SRCS})
TARGET_LINK_LIBRARIES(${INIT_DB} ${init_db_pkgs_LDFLAGS})
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
+#include <stdbool.h>
#include <string.h>
#include <unistd.h>
#include <ctype.h>
#include <libxml/tree.h>
#include "system_info_private.h"
+#include "system_info_generated_util.h" /* auto-generated by SystemInfoGenerator */
#ifdef LOG_TAG
#undef LOG_TAG
//LCOV_EXCL_START
extern const struct runtime runtime[LANG_MAX];
-static int db_set_value(const char *db_path, char *tag, char *name, char *type, char *value, int val_len)
+static bool is_enum_type(const char *type)
+{
+ if (!type)
+ return false;
+
+ return (strncmp(type, "bool", sizeof("bool")) != 0
+ && strncmp(type, "int", sizeof("int")) != 0
+ && strncmp(type, "double", sizeof("double")) != 0
+ && strncmp(type, "string", sizeof("string")) != 0);
+}
+
+static int db_set_value(const char *db_path,
+ const char *tag, const char *name, const char *type, const char *value, int val_len)
{
int ret;
char key_internal[KEY_MAX];
FILE *fp = NULL;
FILE *fp_new = NULL;
int key_idx;
+ char enumerator_value[32] = { 0 , };
if (!db_path || !tag || !name || !type || !value)
return -EINVAL;
if (db_path[0] == '\0')
db_path = SYSTEM_INFO_DB_RO_PATH;
+ if (is_enum_type(type)) {
+ int __enumerator_value;
+
+ ret = system_info_util_get_enumerator_value(value, &__enumerator_value);
+ if (ret < 0) {
+ _E("cannot find enumerator %s", value);
+ return ret;
+ }
+
+ ret = snprintf(enumerator_value, sizeof(enumerator_value) - 1, "%d", __enumerator_value);
+ if (ret >= sizeof(enumerator_value) - 1) {
+ _E("too long digit for enumerator value");
+ return -EOVERFLOW;
+ }
+
+ /* Internally, treat enum as an integer */
+ type = "int";
+ value = enumerator_value;
+ }
+
if (name == strstr(name, KEY_PREFIX))
snprintf(key_internal, sizeof(key_internal), "%s:%s:%s", tag, name + strlen(KEY_PREFIX), type);
else