BoolFeature::BoolFeature(std::string k, std::string v) : Feature(k)
{
if (!v.compare(STRBOOL_TRUE))
- value = true;
- else if (!v.compare(STRBOOL_FALSE))
- value = false;
- else {
- LOG << "Invalid value : key(" << k << "), value(" << v << ")" << ENDL;
- value = false;
- }
+ value.resize(NUM_RUNTIME, true);
+ else
+ value.resize(NUM_RUNTIME, false);
+}
+
+BoolFeature::BoolFeature(std::string k, std::vector<bool> v) : Feature(k)
+{
+ value = std::move(v);
+}
+
+BoolFeature::~BoolFeature()
+{
+ value.clear();
}
int BoolFeature::modifyValue(void)
{
- switch (getModType()) {
- case ModType::NONE:
- break;
- case ModType::EXPAND:
- value = false;
+ int ret;
+ int dice = rand() % NUM_RUNTIME;
+
+ // Modify the value of specific runtime
+ switch (dice) {
+ case 0:
+ // DEFAULT : modify all runtimes
+ value.assign(NUM_RUNTIME, !value[dice]);
break;
- case ModType::SHRINK:
- value = true;
+ case 1:
+ case 2:
+ // C,C++ : modify C, C++ and default
+ value[0] = value[1] = value[2] = !value[dice];
break;
default:
- LOG << "Invalid modType" << ENDL;
- return EINVAL;
+ // WEB,DOTNET : modify their own runtime
+ value[dice] = !value[dice];
+ break;
}
+ ret = util.updateDB(key, STRTYPE_BOOL, runtimeList[dice].lang,
+ value[dice] ? STRBOOL_TRUE : STRBOOL_FALSE);
+ if (ret != SUCCEED)
+ return ret;
- return util.updateDB(key, STRTYPE_BOOL, value ? STRBOOL_TRUE : STRBOOL_FALSE);
+ return SUCCEED;
}
int BoolFeature::verifyValue(void)
int ret;
bool output;
- ret = system_info_get_platform_bool(key.c_str(), &output);
- if (ret != SYSTEM_INFO_ERROR_NONE) {
- LOG << "system_info_get_platform_bool failed : " << ret << ENDL;
- return ret;
+ // Verify all runtimes
+ for (unsigned int r = 0; r < NUM_RUNTIME; r++) {
+ if (runtimeList[r].env.empty())
+ ret = unsetenv(RUNTIME_ENV);
+ else
+ ret = setenv(RUNTIME_ENV, runtimeList[r].env.c_str(), 1);
+ if (ret != SUCCEED) {
+ LOG << "(un)setenv failed : " << errno << ENDL;
+ return ret;
+ }
+
+ ret = system_info_get_platform_bool(key.c_str(), &output);
+ if (ret != SYSTEM_INFO_ERROR_NONE) {
+ LOG << "system_info_get_platform_bool failed : " << ret << ENDL;
+ return ret;
+ }
+
+ ret = compareValue(output, static_cast<bool>(value[r]));
+ if (ret != SUCCEED)
+ return ret;
}
- return compareValue(output, value);
+ return SUCCEED;
}
/********** IntFeature **********/
class BoolFeature : public Feature {
public:
BoolFeature(std::string k, std::string v);
+ BoolFeature(std::string k, std::vector<bool> v);
+ ~BoolFeature();
int modifyValue(void);
int verifyValue(void);
private:
- bool value;
+ std::vector<bool> value;
};
class IntFeature : public Feature {
#define __SYSTEM_INFO_INIT_DB_TEST_H__
#include <iostream>
+#include <string>
+#include <vector>
#define INIT_DB "system_info_init_db"
#define STRBOOL_FALSE "false"
#define STRBOOL_TRUE "true"
+#define RUNTIME_ENV "RUNTIME_TYPE"
+
+typedef struct {
+ std::string lang;
+ std::string env;
+} Runtime;
+static const std::vector<Runtime> runtimeList = {
+ { "", "" }, // DEFAULT
+ { "capi", "capp" }, // C
+ { "capi", "c++app" }, // C++
+ { "webapi", "webapp" }, // WEB
+ { "csapi", "dotnet" }, // DOTNET
+};
+static const unsigned int NUM_RUNTIME = runtimeList.size();
+
#endif /* __SYSTEM_INFO_INIT_DB_TEST_H__ */
switch (dice % 10) {
case 0:
// Bool
+ // Runtime property will be modified in ModifyDB
type = STRTYPE_BOOL;
- value = (dice % 2 == 1) ? STRBOOL_TRUE : STRBOOL_FALSE;
+ value = rand() % 2 == 1 ? STRBOOL_TRUE : STRBOOL_FALSE;
feature = new BoolFeature(key, value);
break;
case 1:
nullptr);
}
+int Util::updateDB(std::string key, std::string type, std::string lang, std::string value)
+{
+ if (lang.empty())
+ return updateDB(key, type, value);
+
+ return forkAndExec(INIT_DB,
+ "-g", "platform",
+ "-k", key.c_str(),
+ "-t", type.c_str(),
+ "-l", lang.c_str(),
+ "-v", value.c_str(),
+ nullptr);
+}
+
int Util::readModelConfig(void)
{
int ret;
xmlChar *propName = nullptr;
xmlChar *propType = nullptr;
xmlChar *propValue = nullptr;
+ xmlChar *propRuntime = nullptr;
std::string name;
std::string type;
std::string value;
+ std::vector<bool> boolValues(NUM_RUNTIME);
Feature *feature = nullptr;
int numBoolKey = 0;
int numIntKey = 0;
if (!propName && !propType && !propValue)
continue;
- LOG << "Invalid feature : name(" << propName
- << "), type(" << propType
- << "), value(" << propValue << ")" << ENDL;
+ LOG << "Invalid feature : name(" << (propName ? (char *)propName : "NULL")
+ << "), type(" << (propType ? (char *)propType : "NULL")
+ << "), value(" << (propValue ? (char *)propValue : "NULL") << ")" << ENDL;
ret = EIO;
goto clean;
}
value.assign((char *)propValue);
if (!type.compare(STRTYPE_BOOL)) {
- feature = new BoolFeature(name, value);
+ // Initialize with DEFAULT value
+ boolValues.assign(NUM_RUNTIME, (!value.compare(STRBOOL_TRUE) ? true : false));
+
+ /**
+ * Modify if runtime property exists
+ *
+ * r = 0(DEFAULT) : already set
+ * r = 1(C) : same with 2(C++). So, we don't have to check two times
+ */
+ for (unsigned int r = 2; r < NUM_RUNTIME; r++) {
+ propRuntime = xmlGetProp(nodeCur, (const xmlChar *)runtimeList[r].lang.c_str());
+ if (!propRuntime)
+ continue;
+
+ boolValues[r] = (!xmlStrcmp(propRuntime, (xmlChar *)"on") ? true : false);
+ }
+ boolValues[1] = boolValues[2];
+
+ feature = new BoolFeature(name, boolValues);
numBoolKey++;
} else if (!type.compare(STRTYPE_INT)) {
feature = new IntFeature(name, value);
* @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);
/**
* @brief Read model-config