summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJackLivio <jack@livio.io>2018-08-28 15:16:31 -0400
committerJackLivio <jack@livio.io>2018-08-28 15:16:31 -0400
commita34939d71451c2ad859287d46a3950b6249e853b (patch)
treef85c65c761a6fe3f685ee52c0807c2c80b4ba001
parent28648f6012e225f3aa36e3a8263f9c8301ba3283 (diff)
downloadsdl_core-a34939d71451c2ad859287d46a3950b6249e853b.tar.gz
Allow empty moduleType array in PT
-rw-r--r--src/components/policy/policy_external/include/policy/policy_table/enums.h3
-rw-r--r--src/components/policy/policy_external/src/policy_table/enums.cc7
-rw-r--r--src/components/policy/policy_external/src/sql_pt_representation.cc32
-rw-r--r--src/components/policy/policy_regular/include/policy/policy_table/enums.h3
-rw-r--r--src/components/policy/policy_regular/src/policy_table/enums.cc7
-rw-r--r--src/components/policy/policy_regular/src/sql_pt_representation.cc32
6 files changed, 66 insertions, 18 deletions
diff --git a/src/components/policy/policy_external/include/policy/policy_table/enums.h b/src/components/policy/policy_external/include/policy/policy_table/enums.h
index 5fc43603d8..a31e955d99 100644
--- a/src/components/policy/policy_external/include/policy/policy_table/enums.h
+++ b/src/components/policy/policy_external/include/policy/policy_table/enums.h
@@ -173,7 +173,8 @@ enum ModuleType {
MT_SEAT,
MT_AUDIO,
MT_LIGHT,
- MT_HMI_SETTINGS
+ MT_HMI_SETTINGS,
+ MT_EMPTY
};
bool IsValidEnum(ModuleType val);
const char* EnumToJsonString(ModuleType val);
diff --git a/src/components/policy/policy_external/src/policy_table/enums.cc b/src/components/policy/policy_external/src/policy_table/enums.cc
index c2b304df67..31a6fc86e6 100644
--- a/src/components/policy/policy_external/src/policy_table/enums.cc
+++ b/src/components/policy/policy_external/src/policy_table/enums.cc
@@ -779,6 +779,8 @@ bool IsValidEnum(ModuleType val) {
return true;
case MT_SEAT:
return true;
+ case MT_EMPTY:
+ return true;
default:
return false;
}
@@ -797,6 +799,8 @@ const char* EnumToJsonString(ModuleType val) {
return "HMI_SETTINGS";
case MT_SEAT:
return "SEAT";
+ case MT_EMPTY:
+ return "EMPTY";
default:
return "";
}
@@ -821,6 +825,9 @@ bool EnumFromJsonString(const std::string& literal, ModuleType* result) {
} else if ("HMI_SETTINGS" == literal) {
*result = MT_HMI_SETTINGS;
return true;
+ } else if ("EMPTY" == literal) {
+ *result = MT_EMPTY;
+ return true;
} else {
return false;
}
diff --git a/src/components/policy/policy_external/src/sql_pt_representation.cc b/src/components/policy/policy_external/src/sql_pt_representation.cc
index b9b0194199..10be5a4626 100644
--- a/src/components/policy/policy_external/src/sql_pt_representation.cc
+++ b/src/components/policy/policy_external/src/sql_pt_representation.cc
@@ -1740,6 +1740,10 @@ bool SQLPTRepresentation::GatherModuleType(
if (!policy_table::EnumFromJsonString(query.GetString(0), &type)) {
return false;
}
+ if (policy_table::ModuleType::MT_EMPTY == type) {
+ app_types->mark_initialized();
+ continue;
+ }
app_types->push_back(type);
}
return true;
@@ -1772,18 +1776,30 @@ bool SQLPTRepresentation::SaveModuleType(
}
policy_table::ModuleTypes::const_iterator it;
- for (it = types.begin(); it != types.end(); ++it) {
+ if (!types.empty()) {
+ for (it = types.begin(); it != types.end(); ++it) {
+ query.Bind(0, app_id);
+ std::string module(policy_table::EnumToJsonString(*it));
+ query.Bind(1, module);
+ LOG4CXX_DEBUG(logger_,
+ "Module(app: " << app_id << ", type: " << module << ")");
+ if (!query.Exec() || !query.Reset()) {
+ LOG4CXX_WARN(logger_, "Incorrect insert into module type.");
+ return false;
+ }
+ }
+ } else if (types.is_initialized()) {
query.Bind(0, app_id);
- std::string module(policy_table::EnumToJsonString(*it));
- query.Bind(1, module);
- LOG4CXX_DEBUG(logger_,
- "Module(app: " << app_id << ", type: " << module << ")");
+ query.Bind(1,
+ std::string(policy_table::EnumToJsonString(
+ policy_table::ModuleType::MT_EMPTY)));
if (!query.Exec() || !query.Reset()) {
- LOG4CXX_WARN(logger_, "Incorrect insert into module type.");
+ LOG4CXX_WARN(logger_, "Incorrect insert into module types.");
return false;
- }
+ }
+ } else {
+ LOG4CXX_WARN(logger_, "Module Type omitted.");
}
-
return true;
}
diff --git a/src/components/policy/policy_regular/include/policy/policy_table/enums.h b/src/components/policy/policy_regular/include/policy/policy_table/enums.h
index 4107fad398..b2acf77ec1 100644
--- a/src/components/policy/policy_regular/include/policy/policy_table/enums.h
+++ b/src/components/policy/policy_regular/include/policy/policy_table/enums.h
@@ -159,7 +159,8 @@ enum ModuleType {
MT_SEAT,
MT_AUDIO,
MT_LIGHT,
- MT_HMI_SETTINGS
+ MT_HMI_SETTINGS,
+ MT_EMPTY
};
bool IsValidEnum(ModuleType val);
const char* EnumToJsonString(ModuleType val);
diff --git a/src/components/policy/policy_regular/src/policy_table/enums.cc b/src/components/policy/policy_regular/src/policy_table/enums.cc
index 83ace2feb2..138d866174 100644
--- a/src/components/policy/policy_regular/src/policy_table/enums.cc
+++ b/src/components/policy/policy_regular/src/policy_table/enums.cc
@@ -649,6 +649,8 @@ bool IsValidEnum(ModuleType val) {
return true;
case MT_HMI_SETTINGS:
return true;
+ case MT_EMPTY:
+ return true;
default:
return false;
}
@@ -667,6 +669,8 @@ const char* EnumToJsonString(ModuleType val) {
return "LIGHT";
case MT_HMI_SETTINGS:
return "HMI_SETTINGS";
+ case MT_EMPTY:
+ return "EMPTY";
default:
return "";
}
@@ -691,6 +695,9 @@ bool EnumFromJsonString(const std::string& literal, ModuleType* result) {
} else if ("HMI_SETTINGS" == literal) {
*result = MT_HMI_SETTINGS;
return true;
+ } else if ("EMPTY" == literal) {
+ *result = MT_EMPTY;
+ return true;
}
return false;
}
diff --git a/src/components/policy/policy_regular/src/sql_pt_representation.cc b/src/components/policy/policy_regular/src/sql_pt_representation.cc
index 00f3349050..ee655d624f 100644
--- a/src/components/policy/policy_regular/src/sql_pt_representation.cc
+++ b/src/components/policy/policy_regular/src/sql_pt_representation.cc
@@ -1696,6 +1696,10 @@ bool SQLPTRepresentation::GatherModuleType(
if (!policy_table::EnumFromJsonString(query.GetString(0), &type)) {
return false;
}
+ if (policy_table::ModuleType::MT_EMPTY == type) {
+ app_types->mark_initialized();
+ continue;
+ }
app_types->push_back(type);
}
return true;
@@ -1728,18 +1732,30 @@ bool SQLPTRepresentation::SaveModuleType(
}
policy_table::ModuleTypes::const_iterator it;
- for (it = types.begin(); it != types.end(); ++it) {
+ if (!types.empty()) {
+ for (it = types.begin(); it != types.end(); ++it) {
+ query.Bind(0, app_id);
+ std::string module(policy_table::EnumToJsonString(*it));
+ query.Bind(1, module);
+ LOG4CXX_DEBUG(logger_,
+ "Module(app: " << app_id << ", type: " << module << ")");
+ if (!query.Exec() || !query.Reset()) {
+ LOG4CXX_WARN(logger_, "Incorrect insert into module type.");
+ return false;
+ }
+ }
+ } else if (types.is_initialized()) {
query.Bind(0, app_id);
- std::string module(policy_table::EnumToJsonString(*it));
- query.Bind(1, module);
- LOG4CXX_DEBUG(logger_,
- "Module(app: " << app_id << ", type: " << module << ")");
+ query.Bind(1,
+ std::string(policy_table::EnumToJsonString(
+ policy_table::ModuleType::MT_EMPTY)));
if (!query.Exec() || !query.Reset()) {
- LOG4CXX_WARN(logger_, "Incorrect insert into module type.");
+ LOG4CXX_WARN(logger_, "Incorrect insert into module types.");
return false;
- }
+ }
+ } else {
+ LOG4CXX_WARN(logger_, "Module Type omitted.");
}
-
return true;
}