/********** BoolFeature **********/
-BoolFeature::BoolFeature(std::string k, std::string v) : Feature(k)
+BoolFeature::BoolFeature(std::string t, std::string k, std::string v) : Feature(t, k)
{
if (!v.compare(STRBOOL_TRUE))
value.resize(NUM_RUNTIME, true);
value.resize(NUM_RUNTIME, false);
}
-BoolFeature::BoolFeature(std::string k, std::vector<bool> v) : Feature(k)
+BoolFeature::BoolFeature(std::string t, std::string k, std::vector<bool> v) : Feature(t, k)
{
value = std::move(v);
}
value[dice] = !value[dice];
break;
}
- ret = util.updateDB(key, STRTYPE_BOOL, runtimeList[dice].lang,
+ ret = util.updateDB(tag, key, STRTYPE_BOOL, runtimeList[dice].lang,
value[dice] ? STRBOOL_TRUE : STRBOOL_FALSE);
if (ret != SUCCEED)
return ret;
return ret;
}
- ret = system_info_get_platform_bool(key.c_str(), &output);
+ if (!tag.compare(STRTAG_PLATFORM))
+ ret = system_info_get_platform_bool(key.c_str(), &output);
+ else if (!tag.compare(STRTAG_CUSTOM))
+ ret = system_info_get_custom_bool(key.c_str(), &output);
+ else {
+ LOG << "Invalid tag : " << tag << ENDL;
+ return EINVAL;
+ }
+
if (ret != SYSTEM_INFO_ERROR_NONE) {
- LOG << "system_info_get_platform_bool failed : " << ret << ENDL;
+ LOG << "system_info_get_" << tag << "_bool failed : " << ret << ENDL;
return ret;
}
/********** IntFeature **********/
-IntFeature::IntFeature(std::string k, std::string v) : Feature(k)
+IntFeature::IntFeature(std::string t, std::string k, std::string v) : Feature(t, k)
{
value = stoi(v);
}
break;
}
- return util.updateDB(key, STRTYPE_INT, std::to_string(value));
+ return util.updateDB(tag, key, STRTYPE_INT, std::to_string(value));
}
int IntFeature::verifyValue(void)
int ret;
int output;
- ret = system_info_get_platform_int(key.c_str(), &output);
+ if (!tag.compare(STRTAG_PLATFORM))
+ ret = system_info_get_platform_int(key.c_str(), &output);
+ else if (!tag.compare(STRTAG_CUSTOM))
+ ret = system_info_get_custom_int(key.c_str(), &output);
+ else {
+ LOG << "Invalid tag : " << tag << ENDL;
+ return EINVAL;
+ }
+
if (ret != SYSTEM_INFO_ERROR_NONE) {
- LOG << "system_info_get_platform_int failed : " << ret << ENDL;
+ LOG << "system_info_get_" << tag << "_int failed : " << ret << ENDL;
return ret;
}
/********** DoubleFeature **********/
-DoubleFeature::DoubleFeature(std::string k, std::string v) : Feature(k)
+DoubleFeature::DoubleFeature(std::string t, std::string k, std::string v) : Feature(t, k)
{
value = stod(v);
}
// Set the decimal precision
oss << std::fixed << std::setprecision(15) << value;
- return util.updateDB(key, STRTYPE_DOUBLE, oss.str());
+ return util.updateDB(tag, key, STRTYPE_DOUBLE, oss.str());
}
int DoubleFeature::verifyValue(void)
int ret;
double output;
- ret = system_info_get_platform_double(key.c_str(), &output);
+ if (!tag.compare(STRTAG_PLATFORM))
+ ret = system_info_get_platform_double(key.c_str(), &output);
+ else if (!tag.compare(STRTAG_CUSTOM))
+ ret = system_info_get_custom_double(key.c_str(), &output);
+ else {
+ LOG << "Invalid tag : " << tag << ENDL;
+ return EINVAL;
+ }
+
if (ret != SYSTEM_INFO_ERROR_NONE) {
- LOG << "system_info_get_platform_double failed : " << ret << ENDL;
+ LOG << "system_info_get_" << tag << "_double failed : " << ret << ENDL;
return ret;
}
/********** StringFeature **********/
-StringFeature::StringFeature(std::string k, std::string v) : Feature(k)
+StringFeature::StringFeature(std::string t, std::string k, std::string v) : Feature(t, k)
{
value = v;
}
break;
}
- return util.updateDB(key, STRTYPE_STRING, value);
+ return util.updateDB(tag, key, STRTYPE_STRING, value);
}
int StringFeature::verifyValue(void)
int ret;
char *output = nullptr;
- ret = system_info_get_platform_string(key.c_str(), &output);
+ if (!tag.compare(STRTAG_PLATFORM))
+ ret = system_info_get_platform_string(key.c_str(), &output);
+ else if (!tag.compare(STRTAG_CUSTOM))
+ ret = system_info_get_custom_string(key.c_str(), &output);
+ else {
+ LOG << "Invalid tag : " << tag << ENDL;
+ return EINVAL;
+ }
+
if (ret != SYSTEM_INFO_ERROR_NONE) {
- LOG << "system_info_get_platform_string failed : " << ret << ENDL;
+ LOG << "system_info_get_" << tag << "_string failed : " << ret << ENDL;
return ret;
}
class Feature {
public:
- Feature(std::string k) : key(k) {}
+ Feature(std::string t, std::string k) : tag(t), key(k) {}
virtual ~Feature() {};
/**
virtual int verifyValue(void) = 0;
protected:
+ std::string tag;
std::string key;
enum class ModType {
class BoolFeature : public Feature {
public:
- BoolFeature(std::string k, std::string v);
- BoolFeature(std::string k, std::vector<bool> v);
+ BoolFeature(std::string t, std::string k, std::string v);
+ BoolFeature(std::string t, std::string k, std::vector<bool> v);
~BoolFeature();
int modifyValue(void);
class IntFeature : public Feature {
public:
- IntFeature(std::string k, std::string v);
+ IntFeature(std::string t, std::string k, std::string v);
int modifyValue(void);
int verifyValue(void);
class DoubleFeature : public Feature {
public:
- DoubleFeature(std::string k, std::string v);
+ DoubleFeature(std::string t, std::string k, std::string v);
int modifyValue(void);
int verifyValue(void);
class StringFeature : public Feature {
public:
- StringFeature(std::string k, std::string v);
+ StringFeature(std::string t, std::string k, std::string v);
int modifyValue(void);
int verifyValue(void);
#define BACKUP_DB_RO_PATH SYSTEM_INFO_DB_RO_PATH "_backup"
#define BACKUP_DB_RW_PATH SYSTEM_INFO_DB_RW_PATH "_backup"
+#define STRTAG_PLATFORM "platform"
+#define STRTAG_CUSTOM "custom"
+
#define STRTYPE_BOOL "bool"
#define STRTYPE_INT "int"
#define STRTYPE_DOUBLE "double"
std::string type;
std::string value;
int valueLen;
- Feature *feature = nullptr;
+ Feature *platformFeature = nullptr;
+ Feature *customFeature = nullptr;
for (int keyIndex = 0; keyIndex < 100; keyIndex++) {
key = keyPrefix + std::to_string(keyIndex);
// Runtime property will be modified in ModifyDB
type = STRTYPE_BOOL;
value = rand() % 2 == 1 ? STRBOOL_TRUE : STRBOOL_FALSE;
- feature = new BoolFeature(key, value);
+ platformFeature = new BoolFeature(STRTAG_PLATFORM, key, value);
+ customFeature = new BoolFeature(STRTAG_CUSTOM, key, value);
break;
case 1:
case 2:
// Int
type = STRTYPE_INT;
value = std::to_string(dice - 1000000); // -1M ~ 1M
- feature = new IntFeature(key, value);
+ platformFeature = new IntFeature(STRTAG_PLATFORM, key, value);
+ customFeature = new IntFeature(STRTAG_CUSTOM, key, value);
break;
case 4:
case 5:
// Double
type = STRTYPE_DOUBLE;
value = std::to_string(dice - 1000000.0); // -1.0M ~ 1.0M
- feature = new DoubleFeature(key, value);
+ platformFeature = new DoubleFeature(STRTAG_PLATFORM, key, value);
+ customFeature = new DoubleFeature(STRTAG_CUSTOM, key, value);
break;
case 7:
case 8:
do {
value += 't';
} while (--valueLen);
- feature = new StringFeature(key, value);
+ platformFeature = new StringFeature(STRTAG_PLATFORM, key, value);
+ customFeature = new StringFeature(STRTAG_CUSTOM, key, value);
break;
default:
LOG << "Invalid dice value : " << dice << ENDL;
return EIO;
}
- featureList.push_back(feature);
+ featureList.push_back(platformFeature);
+ featureList.push_back(customFeature);
- ret = util.updateDB(key, type, value);
+ ret = util.updateDB(STRTAG_PLATFORM, key, type, value);
+ ret |= util.updateDB(STRTAG_CUSTOM, key, type, value);
if (ret != SUCCEED) {
LOG << "Failed to insert key : " << ret << ENDL;
return ret;
#include <cstdarg>
#include <cstdlib>
+#include <vector>
#include <libxml/xmlmemory.h>
#include <libxml/parser.h>
return EFAULT;
}
-int Util::updateDB(std::string key, std::string type, std::string value)
+int Util::updateDB(std::string tag, std::string key, std::string type, std::string value)
{
return forkAndExec(INIT_DB,
- "-g", "platform",
+ "-g", tag.c_str(),
"-k", key.c_str(),
"-t", type.c_str(),
"-v", value.c_str(),
nullptr);
}
-int Util::updateDB(std::string key, std::string type, std::string lang, std::string value)
+int Util::updateDB(std::string tag, std::string key, std::string type, std::string lang, std::string value)
{
if (lang.empty())
- return updateDB(key, type, value);
+ return updateDB(tag, key, type, value);
return forkAndExec(INIT_DB,
- "-g", "platform",
+ "-g", tag.c_str(),
"-k", key.c_str(),
"-t", type.c_str(),
"-l", lang.c_str(),
nullptr);
}
-int Util::readModelConfig(void)
+int Util::readModelConfigKeys(xmlDocPtr doc, xmlNodePtr nodeKey, std::string tag)
{
int ret;
- xmlDocPtr doc = nullptr;
- xmlNodePtr nodeRoot = nullptr;
- xmlNodePtr nodeTag = nullptr;
- xmlNodePtr nodeKey = nullptr;
xmlNode *nodeCur = nullptr;
xmlChar *propName = nullptr;
xmlChar *propType = nullptr;
int numDoubleKey = 0;
int numStringKey = 0;
- // Read xml file
- doc = xmlParseFile(MODEL_CONFIG_RO_PATH);
- if (!doc) {
- LOG << "xmlParseFile failed" << ENDL;
- return ENOENT;
- }
-
- nodeRoot = xmlDocGetRootElement(doc);
- if (!nodeRoot) {
- LOG << "xmlDocGetRootElement failed" << ENDL;
- ret = ENOENT;
- goto clean;
- }
-
- if (xmlStrcmp(nodeRoot->name, (const xmlChar *)"model-config")) {
- LOG << "Failed to find model-config tag" << ENDL;
- ret = ENOENT;
- goto clean;
- }
-
- nodeTag = nodeRoot->xmlChildrenNode;
-
- for (nodeCur = nodeTag; nodeCur; nodeCur = nodeCur->next) {
- if (!xmlStrcmp(nodeCur->name, (const xmlChar *)"platform")) {
- nodeKey = nodeCur;
- break;
- }
- }
-
- if (!nodeKey) {
- LOG << "Failed to find platform tag" << ENDL;
- ret = ENOENT;
- goto clean;
+ if (!doc || !nodeKey) {
+ LOG << "Invalid parameter" << ENDL;
+ return EINVAL;
}
nodeKey = nodeKey->xmlChildrenNode;
}
boolValues[1] = boolValues[2];
- feature = new BoolFeature(name, boolValues);
+ feature = new BoolFeature(tag, name, boolValues);
numBoolKey++;
} else if (!type.compare(STRTYPE_INT)) {
- feature = new IntFeature(name, value);
+ feature = new IntFeature(tag, name, value);
numIntKey++;
} else if (!type.compare(STRTYPE_DOUBLE)) {
- feature = new DoubleFeature(name, value);
+ feature = new DoubleFeature(tag, name, value);
numDoubleKey++;
} else if (!type.compare(STRTYPE_STRING)) {
- feature = new StringFeature(name, value);
+ feature = new StringFeature(tag, name, value);
numStringKey++;
} else {
LOG << "Invalid type : key(" << name << "), type(" << type << ")" << ENDL;
xmlFree(propName);
}
- LOG << "Number of model-config platform key : "
+ LOG << "Number of model-config " << tag << " key : "
<< "Bool(" << numBoolKey
<< "), Int(" << numIntKey
<< "), Double(" << numDoubleKey
<< "), String(" << numStringKey
<< "), Total(" << numBoolKey + numIntKey + numDoubleKey + numStringKey << ")"
<< ENDL << ENDL;
+
ret = SUCCEED;
clean:
if (propName)
xmlFree(propName);
+ return ret;
+}
+
+int Util::readModelConfig(void)
+{
+ int ret;
+ xmlDocPtr doc = nullptr;
+ xmlNodePtr nodeRoot = nullptr;
+ xmlNodePtr nodeTag = nullptr;
+ xmlNode *nodeCur = nullptr;
+
+ // Read xml file
+ doc = xmlParseFile(MODEL_CONFIG_RO_PATH);
+ if (!doc) {
+ LOG << "xmlParseFile failed" << ENDL;
+ return ENOENT;
+ }
+
+ nodeRoot = xmlDocGetRootElement(doc);
+ if (!nodeRoot) {
+ LOG << "xmlDocGetRootElement failed" << ENDL;
+ ret = ENOENT;
+ goto clean;
+ }
+
+ if (xmlStrcmp(nodeRoot->name, (const xmlChar *)"model-config")) {
+ LOG << "Failed to find model-config tag" << ENDL;
+ ret = ENOENT;
+ goto clean;
+ }
+
+ nodeTag = nodeRoot->xmlChildrenNode;
+
+ for (nodeCur = nodeTag; nodeCur; nodeCur = nodeCur->next) {
+ if (!xmlStrcmp(nodeCur->name, (const xmlChar *)STRTAG_PLATFORM)) {
+ ret = readModelConfigKeys(doc, nodeCur, STRTAG_PLATFORM);
+ if (ret != SUCCEED)
+ break;
+ } else if (!xmlStrcmp(nodeCur->name, (const xmlChar *)STRTAG_CUSTOM)) {
+ ret = readModelConfigKeys(doc, nodeCur, STRTAG_CUSTOM);
+ if (ret != SUCCEED)
+ break;
+ }
+ }
+
+ if (ret != SUCCEED)
+ LOG << "Failed to read model-config key" << ENDL;
+
+clean:
if (doc)
xmlFreeDoc(doc);
#ifndef __UTIL_H__
#define __UTIL_H__
+#include <libxml/xmlmemory.h>
+
class Util {
public:
/**
* @brief Update system-info DB
* @retval SUCCEED on success, otherwise an error value
*/
- static int updateDB(std::string key, std::string type, std::string value);
- static int updateDB(std::string key, std::string type, std::string lang, std::string value);
+ static int updateDB(std::string tag, std::string key, std::string type, std::string value);
+ static int updateDB(std::string tag, std::string key, std::string type, std::string lang, std::string value);
/**
* @brief Read model-config
* @retval SUCCEED on success, otherwise an error value
*/
static int readModelConfig(void);
+
+private:
+ static int readModelConfigKeys(xmlDocPtr doc, xmlNodePtr nodeKey, std::string tag);
};
extern Util util;