#include <gdbm.h>
#include <fcntl.h>
#include <sys/stat.h>
+#include <glib.h>
#include <system_info.h>
#include <system_info_private.h>
#define GDBM_CACHE_SIZE 10 /* GDBM default == 100 */
+GHashTable *hashtable = NULL;
+
enum tag_type {
TAG_TYPE_PLATFORM,
TAG_TYPE_CUSTOM,
return SYSTEM_INFO_ERROR_NOT_SUPPORTED;
}
+static void destroy_key_value(gpointer data)
+{
+ free(data);
+}
+
static int db_get_value(enum tag_type tag, const char *key,
const char *type, char *value, size_t len)
{
int ret;
char *tag_s;
int cache_size = GDBM_CACHE_SIZE;
+ char *temp;
if (!key || !type || !value)
return SYSTEM_INFO_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
return -EINVAL;
}
+ if (strstr(key, KEY_PREFIX) == key)
+ 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);
+
+ if (!hashtable) {
+ hashtable = g_hash_table_new_full(g_str_hash, g_str_equal, destroy_key_value, destroy_key_value);
+ } else {
+ temp = (char *)g_hash_table_lookup(hashtable, key_internal);
+ if (temp) {
+ snprintf(value, len, "%s", temp);
+ return SYSTEM_INFO_ERROR_NONE;
+ }
+ }
+
db = gdbm_open(SYSTEM_INFO_DB_PATH, 0, GDBM_READER, S_IRUSR | S_IRGRP | S_IROTH, NULL);
if (!db) {
_E("Failed to open db (%d, %s)", gdbm_errno, gdbm_strerror(gdbm_errno)); //LCOV_EXCL_LINE
if (ret < 0)
_E("Failed to set cache size to (%d) (ret:%d)", cache_size, gdbm_errno); //LCOV_EXCL_LINE
- if (strstr(key, KEY_PREFIX) == key)
- 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);
-
d_key.dptr = key_internal;
d_key.dsize = strlen(key_internal) + 1;
snprintf(value, len, "%s", d_data.dptr);
ret = SYSTEM_INFO_ERROR_NONE;
+ g_hash_table_insert(hashtable, strdup(key_internal), strdup(value));
out:
if (db)
gdbm_close(db);
int ret, i;
char *tag_s;
int cache_size = GDBM_CACHE_SIZE;
+ char *temp;
if (!key || !type)
return SYSTEM_INFO_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
return -EINVAL;
}
+ if (!hashtable) {
+ hashtable = g_hash_table_new_full(g_str_hash, g_str_equal, destroy_key_value, destroy_key_value);
+ } else {
+ for (i = 0 ; i < ARRAY_SIZE(info_type); i++) {
+ if (strstr(key, KEY_PREFIX) == key)
+ snprintf(key_internal, sizeof(key_internal),
+ "%s:%s:%s", key, info_type[i].type_str, tag_s);
+ else
+ snprintf(key_internal, sizeof(key_internal),
+ "%s%s:%s:%s", KEY_PREFIX, key, info_type[i].type_str, tag_s);
+ temp = g_hash_table_lookup(hashtable, key_internal);
+ if (!temp)
+ continue;
+
+ *type = info_type[i].type_e;
+ return SYSTEM_INFO_ERROR_NONE;
+ }
+ }
+
db = gdbm_open(SYSTEM_INFO_DB_PATH, 0, GDBM_READER, S_IRUSR | S_IRGRP | S_IROTH, NULL);
if (!db) {
_E("Failed to open db (%d, %s)", gdbm_errno, gdbm_strerror(gdbm_errno)); //LCOV_EXCL_LINE
if (d_data.dptr) {
*type = info_type[i].type_e;
ret = SYSTEM_INFO_ERROR_NONE;
+
+ g_hash_table_insert(hashtable, strdup(key_internal), strdup(d_data.dptr));
goto out;
}
}