summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJackLivio <jack@livio.io>2019-01-27 17:53:10 -0500
committerJackLivio <jack@livio.io>2019-01-27 17:53:10 -0500
commit852ec29c4b7395e4316be60e85488607387d6123 (patch)
treee79072026c0c0444a74e85e7665ad7ae6a3c52f0
parenta811be5a47658fc162357c9982bae789bcb53b6e (diff)
downloadsdl_core-852ec29c4b7395e4316be60e85488607387d6123.tar.gz
Add HandledRPC struct to policies
-rw-r--r--src/components/application_manager/src/policies/policy_handler.cc15
-rw-r--r--src/components/policy/policy_regular/include/policy/policy_table/types.h26
-rw-r--r--src/components/policy/policy_regular/src/policy_table/types.cc45
-rw-r--r--src/components/policy/policy_regular/src/policy_table/validation.cc4
-rw-r--r--src/components/policy/policy_regular/src/sql_pt_representation.cc12
5 files changed, 91 insertions, 11 deletions
diff --git a/src/components/application_manager/src/policies/policy_handler.cc b/src/components/application_manager/src/policies/policy_handler.cc
index 22e4cc1131..456c127025 100644
--- a/src/components/application_manager/src/policies/policy_handler.cc
+++ b/src/components/application_manager/src/policies/policy_handler.cc
@@ -1952,7 +1952,7 @@ bool PolicyHandler::CheckAppServiceParameters(
smart_objects::SmartArray* requested_handled_rpcs) const {
std::string service_name = std::string();
std::string service_type = std::string();
- std::vector<uint32_t> handled_rpcs = {};
+ std::vector<int32_t> handled_rpcs = {};
policy_table::AppServiceParameters app_service_parameters =
policy_table::AppServiceParameters();
@@ -1978,17 +1978,24 @@ bool PolicyHandler::CheckAppServiceParameters(
}
// todo handled rpcs check
- /*if (requested_handled_rpcs) {
+ if (requested_handled_rpcs) {
+ auto temp_rpcs =
+ *(app_service_parameters[requested_service_type].handled_rpcs);
+ for (auto handled_it = temp_rpcs.begin(); handled_it != temp_rpcs.end();
+ ++handled_it) {
+ handled_rpcs.push_back(handled_it->function_id);
+ }
+
for (auto requested_it = requested_handled_rpcs->begin();
requested_it != requested_handled_rpcs->end();
++requested_it) {
auto find_result = std::find(
- handled_rpcs.begin(), handled_rpcs.end(), requested_it->asUInt());
+ handled_rpcs.begin(), handled_rpcs.end(), requested_it->asInt());
if (find_result == handled_rpcs.end()) {
return false;
}
}
- }*/
+ }
return true;
}
diff --git a/src/components/policy/policy_regular/include/policy/policy_table/types.h b/src/components/policy/policy_regular/include/policy/policy_table/types.h
index 4b379ee7b6..b7522065bd 100644
--- a/src/components/policy/policy_regular/include/policy/policy_table/types.h
+++ b/src/components/policy/policy_regular/include/policy/policy_table/types.h
@@ -50,6 +50,7 @@ struct MessageLanguages;
struct MessageString;
struct RpcParameters;
struct Rpcs;
+struct AppServiceHandledRpc;
struct AppServiceInfo;
} // namespace policy_table_interface_base
} // namespace rpc
@@ -102,9 +103,9 @@ typedef Strings RequestSubTypes;
typedef String<0, 255> AppServiceType;
typedef String<0, 255> AppServiceName;
typedef Array<AppServiceName, 0, 255> AppServiceNames;
-typedef Array<Integer<uint32_t, 0, UINT32_MAX>, 0, 255> AppServiceHandledRpcs;
-
+typedef Array<AppServiceHandledRpc, 0, 255> AppServiceHandledRpcs;
typedef Map<AppServiceInfo, 0, 255> AppServiceParameters;
+typedef Integer<int32_t, 0, INT32_MAX> FunctionIDInt;
typedef Map<Strings, 0, 255> RemoteRpcs;
typedef Map<RemoteRpcs, 0, 255> AccessModules;
@@ -113,10 +114,31 @@ typedef Array<Enum<ModuleType>, 0, 255> ModuleTypes;
typedef AppHMIType AppHmiType;
typedef std::vector<AppHMIType> AppHmiTypes;
+struct AppServiceHandledRpc : CompositeType {
+ public:
+ FunctionIDInt function_id;
+
+ public:
+ AppServiceHandledRpc();
+ ~AppServiceHandledRpc();
+ AppServiceHandledRpc(const Json::Value* value__);
+ Json::Value ToJsonValue() const;
+ bool is_valid() const;
+ bool is_initialized() const;
+ bool struct_empty() const;
+ virtual void SetPolicyTableType(PolicyTableType pt_type);
+ void ReportErrors(rpc::ValidationReport* report__) const;
+
+ private:
+ bool Validate() const;
+};
+
struct AppServiceInfo : CompositeType {
public:
Optional<AppServiceNames> service_names;
Optional<AppServiceHandledRpcs> handled_rpcs;
+
+ public:
AppServiceInfo();
~AppServiceInfo();
AppServiceInfo(const Json::Value* value__);
diff --git a/src/components/policy/policy_regular/src/policy_table/types.cc b/src/components/policy/policy_regular/src/policy_table/types.cc
index ed8b5c58ac..d5991b5210 100644
--- a/src/components/policy/policy_regular/src/policy_table/types.cc
+++ b/src/components/policy/policy_regular/src/policy_table/types.cc
@@ -149,6 +149,51 @@ void ApplicationPoliciesSection::SetPolicyTableType(PolicyTableType pt_type) {
device.SetPolicyTableType(pt_type);
apps.SetPolicyTableType(pt_type);
}
+// Handled RPC Methods
+AppServiceHandledRpc::AppServiceHandledRpc() : CompositeType(kUninitialized) {}
+
+AppServiceHandledRpc::~AppServiceHandledRpc() {}
+
+AppServiceHandledRpc::AppServiceHandledRpc(const Json::Value* value__)
+ : CompositeType(InitHelper(value__, &Json::Value::isObject))
+ , function_id(impl::ValueMember(value__, "function_id")) {}
+
+Json::Value AppServiceHandledRpc::ToJsonValue() const {
+ Json::Value result__(Json::objectValue);
+ impl::WriteJsonField("function_id", function_id, &result__);
+ return result__;
+}
+
+bool AppServiceHandledRpc::is_valid() const {
+ if (!function_id.is_valid()) {
+ return false;
+ }
+ return Validate();
+}
+
+bool AppServiceHandledRpc::is_initialized() const {
+ return (initialization_state__ != kUninitialized) || (!struct_empty());
+}
+
+bool AppServiceHandledRpc::struct_empty() const {
+ if (function_id.is_initialized()) {
+ return false;
+ }
+ return true;
+}
+
+void AppServiceHandledRpc::SetPolicyTableType(PolicyTableType pt_type) {
+ function_id.SetPolicyTableType(pt_type);
+}
+
+void AppServiceHandledRpc::ReportErrors(rpc::ValidationReport* report__) const {
+ if (struct_empty()) {
+ rpc::CompositeType::ReportErrors(report__);
+ }
+ if (!function_id.is_valid()) {
+ function_id.ReportErrors(&report__->ReportSubobject("function_id"));
+ }
+}
// AppServiceInfo methods
AppServiceInfo::AppServiceInfo() : CompositeType(kUninitialized) {}
diff --git a/src/components/policy/policy_regular/src/policy_table/validation.cc b/src/components/policy/policy_regular/src/policy_table/validation.cc
index 6804b1266f..6c15d958f5 100644
--- a/src/components/policy/policy_regular/src/policy_table/validation.cc
+++ b/src/components/policy/policy_regular/src/policy_table/validation.cc
@@ -177,6 +177,10 @@ bool ApplicationParams::ValidateModuleTypes() const {
return true;
}
+bool AppServiceHandledRpc::Validate() const {
+ return true; // todo add validation
+}
+
bool AppServiceInfo::Validate() const {
return true; // todo add validation
}
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 6656bb3162..dd2c38a72b 100644
--- a/src/components/policy/policy_regular/src/sql_pt_representation.cc
+++ b/src/components/policy/policy_regular/src/sql_pt_representation.cc
@@ -1291,7 +1291,7 @@ bool SQLPTRepresentation::SaveAppServiceParameters(
for (rpc_it = handled_rpcs->begin(); rpc_it != handled_rpcs->end();
++rpc_it) {
handled_rpcs_query.Bind(0, static_cast<int64_t>(id));
- handled_rpcs_query.Bind(1, static_cast<int64_t>(*rpc_it));
+ handled_rpcs_query.Bind(1, static_cast<int32_t>(rpc_it->function_id));
if (!handled_rpcs_query.Exec() || !handled_rpcs_query.Reset()) {
LOG4CXX_WARN(logger_, "Incorrect insert into app service handled rpcs");
return false;
@@ -1775,8 +1775,10 @@ bool SQLPTRepresentation::GatherAppServiceParameters(
handled_rpcs_query.Bind(0, service_type_id);
while (handled_rpcs_query.Next()) {
+ policy_table::AppServiceHandledRpc handled_rpc;
+ handled_rpc.function_id = handled_rpcs_query.GetInteger(0);
(*app_service_parameters)[service_type].handled_rpcs->push_back(
- handled_rpcs_query.GetInteger(0));
+ handled_rpc);
}
service_name_query.Reset();
@@ -2136,9 +2138,9 @@ bool SQLPTRepresentation::SetDefaultPolicy(const std::string& app_id) {
return false;
}
- policy_table::HandledRpcs handled_rpcs;
- if (!GatherAppServiceParameters(kDefaultId, &handled_rpcs) ||
- !SaveAppServiceParameters(app_id, handled_rpcs)) {
+ policy_table::AppServiceParameters app_service_parameters;
+ if (!GatherAppServiceParameters(kDefaultId, &app_service_parameters) ||
+ !SaveAppServiceParameters(app_id, app_service_parameters)) {
return false;
}