#define DBL_TYPE "double"
#define STR_TYPE "string"
+enum language {
+ DEFAULT = 0, /* Without language property */
+ C = 1, /* C and C++ */
+ WEB = 2, /* Web (JS, html) */
+ DOTNET = 3, /* C# */
+ LANG_MAX = 8
+};
+
+struct runtime {
+ enum language lang; /* Lauguage used by runtime */
+ char *xml_prop; /* Property name in model-config */
+ char *runtime_type; /* Value of RUNTIME_TYPE env */
+};
+
+/**
+ * Notice
+ *
+ * In current, each runtime_type has their own prefix with length = RT_PREFIX.
+ * So, system-info check only first RT_PREFIX characters for performance.
+ * If you add another language with having same prefix, you should change this logic.
+ */
+#define RT_PREFIX 2
+static const struct runtime runtime[LANG_MAX] = {
+ { C, "capi", "capp" },
+ { C, "capi", "c++app" },
+ { WEB, "webapi", "webapp" },
+ { DOTNET, "csapi", "dotnet" },
+ { LANG_MAX, NULL, NULL }
+};
+
int system_info_get_file(const char *key, char *value, size_t len);
int system_info_get_type_file(const char *key, system_info_type_e *type);
#define MODEL_CONFIG_TAG "model-config"
#define KEY_PREFIX "http://"
-static int db_set_value(GDBM_FILE *db, char *tag, char *name, char *type, char *value)
+extern const struct runtime runtime[LANG_MAX];
+
+static int db_set_value(GDBM_FILE *db, char *tag, char *name, char *type, char *value, int val_len)
{
char key[KEY_MAX];
datum d_key;
d_key.dsize = strlen(key) + 1;
d_data.dptr = value;
- d_data.dsize = strlen(value) + 1;
+ d_data.dsize = val_len + 1;
ret = gdbm_store(*db, d_key, d_data, GDBM_REPLACE);
if (ret != 0) {
return 0;
}
+static int db_set_value_foreach_runtime(GDBM_FILE *db, xmlNode *node,
+ char *tag, char *name, char *type, char *value)
+{
+ int rt;
+ xmlChar *prop_val;
+ char value_intg[LANG_MAX];
+ int ret;
+
+ memset(value_intg, strncmp(value, "true", 4) ? false : true, sizeof(value_intg));
+
+ for (rt = 0; rt < LANG_MAX; rt++) {
+ if (!runtime[rt].xml_prop)
+ break;
+
+ prop_val = xmlGetProp(node, (xmlChar *)(runtime[rt].xml_prop));
+ if (!prop_val)
+ continue;
+
+ value_intg[runtime[rt].lang] = xmlStrcmp(prop_val, (xmlChar *)"on") ? false : true;
+
+ xmlFree(prop_val);
+ }
+
+ ret = db_set_value(db, tag, name, type, value_intg, sizeof(value_intg));
+
+ return ret;
+}
+
static int system_info_get_values_config_xml(GDBM_FILE *db)
{
xmlDocPtr doc;
continue;
}
- ret = db_set_value(db, tag, name, type, value);
+ if (!strncmp(type, "bool", 4))
+ ret = db_set_value_foreach_runtime(db, cur_node, tag, name, type, value);
+ else
+ ret = db_set_value(db, tag, name, type, value, strlen(value));
+
if (ret < 0)
_E("Failed to set value (%d)", ret);
continue;
}
- ret = db_set_value(db, TAG_TYPE_PLATFORM_STR, ini_keys[i].key, STR_TYPE, value);
+ ret = db_set_value(db, TAG_TYPE_PLATFORM_STR, ini_keys[i].key, STR_TYPE, value, strlen(value));
if (ret < 0)
_E("Failed to set value (%d)", ret);
}
printf(" -h --help Show this help\n");
printf(" -k --key=KEY System info key to update\n");
printf(" -t --type=TYPE System info type to update (int/bool/double/string)\n");
- printf(" -g --tag=TAGE System info tag to update (platform/custom)\n");
+ printf(" -g --tag=TAG System info tag to update (platform/custom)\n");
+ printf(" -l --lang=LANG System info value to update (capi/webapi/csapi\n");
printf(" -v --value=VALUE System info value to update\n");
}
GDBM_FILE db;
int opt;
bool failed = false;
- char key[KEY_MAX] = { 0, };
- char type[KEY_MAX] = { 0, };
- char tag[KEY_MAX] = { 0, };
- char value[KEY_MAX] = { 0, };
+ char key[KEY_MAX] = {0};
+ char type[KEY_MAX] = {0};
+ char tag[KEY_MAX] = {0};
+ char value[KEY_MAX] = {0};
+ char lang[KEY_MAX] = {0};
+
struct option long_options[] = {
{ "key", required_argument, 0, 0 },
{ "type", required_argument, 0, 0 },
{ "tag", required_argument, 0, 0 },
{ "value", required_argument, 0, 0 },
+ { "lang", required_argument, 0, 0 },
{ "help", no_argument, 0, 0 },
{ 0, 0, 0, 0 },
};
while (1) {
- opt = getopt_long(argc, argv, "k:t:g:v:h",
+ opt = getopt_long(argc, argv, "k:t:g:v:l:h",
long_options, NULL);
if (opt < 0)
break;
case 'v':
snprintf(value, sizeof(value), "%s", optarg);
break;
+ case 'l':
+ snprintf(lang, sizeof(lang), "%s", optarg);
+ break;
case 'h':
default:
show_help();
return -ENOENT;
}
- ret = db_set_value(&db, tag, key, type, value);
+ ret = db_set_value(&db, tag, key, type, value, strlen(value));
if (ret != 0)
_E("Failed to set value (%d)", ret);
#define GDBM_CACHE_SIZE 10 /* GDBM default == 100 */
+extern const struct runtime runtime[LANG_MAX];
+
GHashTable *hashtable = NULL;
static pthread_mutex_t fmutex = PTHREAD_MUTEX_INITIALIZER;
}
if (strstr(key, KEY_PREFIX) == key)
- snprintf(key_internal, sizeof(key_internal),
- "%s:%s:%s", key, type, tag_s);
+ snprintf(key_internal, sizeof(key_internal), "%s:%s:%s", key, type, tag_s);
else
- snprintf(key_internal, sizeof(key_internal),
- "%s%s:%s:%s", KEY_PREFIX, key, type, tag_s);
+ snprintf(key_internal, sizeof(key_internal), "%s%s:%s:%s", KEY_PREFIX, key, type, tag_s);
pthread_mutex_lock(&fmutex);
if (!hashtable) {
char val[8];
char *valp;
size_t len;
+ const char *runtime_type;
+ int rt;
if (!key || !value)
return SYSTEM_INFO_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
ret = db_get_value(tag, key, BOOL_TYPE, val, sizeof(val));
- if (ret == SYSTEM_INFO_ERROR_NONE)
- goto out;
+ if (ret == SYSTEM_INFO_ERROR_NONE) {
+ runtime_type = getenv("RUNTIME_TYPE");
+ if (runtime_type) {
+ for (rt = 0; rt < LANG_MAX; rt++) {
+ if (!runtime[rt].runtime_type)
+ break;
+ if (!strncmp(runtime_type, runtime[rt].runtime_type, RT_PREFIX)) {
+ *value = val[runtime[rt].lang];
+ return SYSTEM_INFO_ERROR_NONE;
+ }
+ }
+ _I("Unknown RUNTIME_TYPE, return default value");
+ }
+
+ *value = val[runtime[DEFAULT].lang];
+ return SYSTEM_INFO_ERROR_NONE;
+ }
if (tag == TAG_TYPE_CUSTOM) {
ret = external_get_value(TAG_TYPE_CUSTOM_STR, key, BOOL_TYPE, &valp);
if (ret == SYSTEM_INFO_ERROR_NONE) {
snprintf(val, sizeof(val), "%s", valp); //LCOV_EXCL_LINE
free(valp); //LCOV_EXCL_LINE
- goto out; //LCOV_EXCL_LINE
+
+ len = strlen(val) + 0;
+ if (!strncmp(val, "true", len) || !strncmp(val, "TRUE", len))
+ *value = true;
+ else
+ *value = false;
+
+ return SYSTEM_INFO_ERROR_NONE;
}
}
_E("Invalid key (%s), type:bool", key);
return SYSTEM_INFO_ERROR_INVALID_PARAMETER;
-
-out:
- len = strlen(val) + 1;
- if (!strncmp(val, "true", len) || !strncmp(val, "TRUE", len))
- *value = true;
- else
- *value = false;
-
- return SYSTEM_INFO_ERROR_NONE;
}
static int system_info_get_int(enum tag_type tag, const char *key, int *value)