summaryrefslogtreecommitdiff
path: root/src/components/application_manager/src/commands/hmi/get_urls.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/application_manager/src/commands/hmi/get_urls.cc')
-rw-r--r--src/components/application_manager/src/commands/hmi/get_urls.cc204
1 files changed, 104 insertions, 100 deletions
diff --git a/src/components/application_manager/src/commands/hmi/get_urls.cc b/src/components/application_manager/src/commands/hmi/get_urls.cc
index af220051d4..bfcdf4985e 100644
--- a/src/components/application_manager/src/commands/hmi/get_urls.cc
+++ b/src/components/application_manager/src/commands/hmi/get_urls.cc
@@ -34,18 +34,7 @@
#include "application_manager/message.h"
#include "application_manager/application_manager.h"
#include "application_manager/policies/policy_handler.h"
-
-namespace {
-struct PolicyAppIdComparator {
- PolicyAppIdComparator(const std::string& policy_app_id)
- : policy_app_id_(policy_app_id) {}
-
- bool operator()(const policy::EndpointData& data) {
- return data.app_id == policy_app_id_;
- }
- std::string policy_app_id_;
-};
-}
+#include "utils/helpers.h"
namespace application_manager {
namespace commands {
@@ -58,41 +47,114 @@ GetUrls::~GetUrls() {}
void GetUrls::Run() {
LOG4CXX_AUTO_TRACE(logger_);
- using namespace smart_objects;
- using namespace application_manager;
- using namespace strings;
- using namespace hmi_apis;
+ namespace Common_Result = hmi_apis::Common_Result;
+ using policy::EndpointUrls;
if (!application_manager_.GetPolicyHandler().PolicyEnabled()) {
SendResponseToHMI(Common_Result::DATA_NOT_AVAILABLE);
return;
}
- SmartObject& object = *message_;
- const std::string service_to_check =
- object[msg_params][hmi_request::service].asString();
+ const uint32_t service_to_check =
+ (*message_)[strings::msg_params][hmi_request::service].asUInt();
+
+ EndpointUrls endpoints;
+ application_manager_.GetPolicyHandler().GetUpdateUrls(service_to_check,
+ endpoints);
- policy::EndpointUrls endpoints;
- application_manager_.GetPolicyHandler().GetServiceUrls(
- object[strings::msg_params][hmi_request::service].asString(), endpoints);
if (endpoints.empty()) {
LOG4CXX_ERROR(logger_, "No URLs for service " << service_to_check);
SendResponseToHMI(Common_Result::DATA_NOT_AVAILABLE);
return;
}
-#ifdef EXTENDED_POLICY
- const std::string policy_service = "7";
+#ifdef PROPRIETARY_MODE
+ const uint32_t policy_service = 7u;
if (policy_service == service_to_check) {
ProcessPolicyServiceURLs(endpoints);
return;
}
-#endif
+#endif // PROPRIETARY_MODE
+
ProcessServiceURLs(endpoints);
}
-#ifdef EXTENDED_POLICY
+void GetUrls::ProcessServiceURLs(const policy::EndpointUrls& endpoints) {
+ namespace Common_Result = hmi_apis::Common_Result;
+ using smart_objects::SmartObject;
+
+ (*message_)[strings::msg_params].erase(hmi_request::service);
+ SmartObject& urls = (*message_)[strings::msg_params][hmi_response::urls];
+
+ size_t index = 0;
+ for (size_t e = 0; e < endpoints.size(); ++e) {
+ ApplicationSharedPtr app =
+ application_manager_.application_by_policy_id(endpoints[e].app_id);
+
+#ifndef PROPRIETARY_MODE
+ bool registered_not_default = false;
+ if (policy::kDefaultId != endpoints[e].app_id) {
+ if (!app) {
+ LOG4CXX_ERROR(logger_,
+ "Can't find application with policy id "
+ << endpoints[e].app_id
+ << " URLs adding for this application is skipped.");
+ continue;
+ }
+ registered_not_default = true;
+ }
+#endif // EXTERNAL_PROPRIETARY_MODE || HTTP
+ for (size_t u = 0; u < endpoints[e].url.size(); ++u, ++index) {
+ const std::string& app_url = endpoints[e].url[u];
+ SmartObject& service_info = urls[index];
+
+ service_info[strings::url] = app_url;
+#ifndef PROPRIETARY_MODE
+ if (registered_not_default) {
+ service_info[strings::app_id] = app->hmi_app_id();
+ }
+#else // EXTERNAL_PROPRIETARY_MODE || HTTP
+ service_info[hmi_response::policy_app_id] = endpoints[e].app_id;
+#endif
+ }
+ }
+ SendResponseToHMI(Common_Result::SUCCESS);
+}
+
+void GetUrls::SendResponseToHMI(hmi_apis::Common_Result::eType result) {
+ (*message_)[strings::params][strings::message_type] = MessageType::kResponse;
+ (*message_)[strings::params][hmi_response::code] = result;
+ application_manager_.ManageHMICommand(message_);
+}
+
+#ifdef PROPRIETARY_MODE
+struct PolicyAppIdComparator {
+ PolicyAppIdComparator(const std::string& policy_app_id)
+ : policy_app_id_(policy_app_id) {}
+
+ bool operator()(const policy::EndpointData& data) {
+ return data.app_id == policy_app_id_;
+ }
+ std::string policy_app_id_;
+};
+
+void FillSODefaultUrls(smart_objects::SmartObject& urls,
+ const policy::EndpointUrls& endpoints) {
+ using smart_objects::SmartObject;
+ PolicyAppIdComparator comparator(policy::kDefaultId);
+ policy::EndpointUrls::const_iterator it =
+ std::find_if(endpoints.begin(), endpoints.end(), comparator);
+ if (it == endpoints.end()) {
+ return;
+ }
+ SmartObject service_info = SmartObject(smart_objects::SmartType_Map);
+ for (size_t i = 0; i < (*it).url.size(); ++i) {
+ service_info[strings::url] = (*it).url[i];
+ urls[i] = service_info;
+ }
+}
+
void GetUrls::ProcessPolicyServiceURLs(const policy::EndpointUrls& endpoints) {
LOG4CXX_AUTO_TRACE(logger_);
using namespace smart_objects;
@@ -133,87 +195,29 @@ void GetUrls::ProcessPolicyServiceURLs(const policy::EndpointUrls& endpoints) {
object[msg_params][hmi_response::urls] = SmartObject(SmartType_Array);
SmartObject& urls = object[msg_params][hmi_response::urls];
const std::string mobile_app_id = app->policy_app_id();
- std::string default_url = "URL is not found";
-
- // Will use only one URL for particular application if it will be found
- // Otherwise URL from default section will used
- SmartObject service_info = SmartObject(SmartType_Map);
-
- for (size_t e = 0; e < endpoints.size(); ++e) {
- if (mobile_app_id == endpoints[e].app_id) {
- if (endpoints[e].url.size()) {
- service_info[url] = endpoints[e].url[0];
- SendResponseToHMI(Common_Result::SUCCESS);
- return;
- }
- }
- if (policy::kDefaultId == endpoints[e].app_id) {
- if (endpoints[e].url.size()) {
- default_url = endpoints[e].url[0];
- }
- }
- }
-
- service_info[strings::app_id] = app->app_id();
- service_info[strings::url] = default_url;
- urls[0] = service_info;
- // TODO(AOleynik): Issue with absent policy_app_id. Need to fix later on.
- // Possibly related to smart schema
- SendResponseToHMI(Common_Result::SUCCESS);
- return;
-}
-#endif
-
-void GetUrls::ProcessServiceURLs(const policy::EndpointUrls& endpoints) {
- using namespace smart_objects;
- using namespace strings;
- using namespace hmi_apis;
-
- SmartObject& object = *message_;
- object[msg_params].erase(hmi_request::service);
- object[msg_params][hmi_response::urls] = SmartObject(SmartType_Array);
-
- SmartObject& urls = object[msg_params][hmi_response::urls];
size_t index = 0;
- for (size_t e = 0; e < endpoints.size(); ++e) {
- for (size_t u = 0; u < endpoints[e].url.size(); ++u, ++index) {
- const std::string app_url = endpoints[e].url[u];
-
- urls[index] = SmartObject(SmartType_Map);
- SmartObject& service_info = urls[index];
-
- service_info[url] = app_url;
- if (policy::kDefaultId != endpoints[e].app_id) {
- service_info[hmi_response::policy_app_id] = endpoints[e].app_id;
+ for (size_t i = 0; i < endpoints.size(); ++i) {
+ using namespace helpers;
+
+ const bool to_add = Compare<std::string, EQ, ONE>(
+ endpoints[i].app_id, mobile_app_id, policy::kDefaultId);
+ const bool is_default = policy::kDefaultId == endpoints[i].app_id;
+
+ if (to_add) {
+ for (size_t k = 0; k < endpoints[i].url.size(); ++k) {
+ if (!is_default) {
+ urls[index][strings::app_id] = app_id_to_send_to;
+ }
+ urls[index][strings::url] = endpoints[i].url[k];
+ ++index;
}
}
}
SendResponseToHMI(Common_Result::SUCCESS);
+ return;
}
-
-void GetUrls::FillSODefaultUrls(smart_objects::SmartObject& urls,
- const policy::EndpointUrls& endpoints) {
- using namespace smart_objects;
- LOG4CXX_AUTO_TRACE(logger_);
- PolicyAppIdComparator comparator(policy::kDefaultId);
- policy::EndpointUrls::const_iterator it =
- std::find_if(endpoints.begin(), endpoints.end(), comparator);
- if (it == endpoints.end()) {
- return;
- }
- SmartObject service_info = SmartObject(SmartType_Map);
- for (size_t i = 0; i < (*it).url.size(); ++i) {
- service_info[strings::url] = (*it).url[i];
- urls[i] = service_info;
- }
-}
-
-void GetUrls::SendResponseToHMI(hmi_apis::Common_Result::eType result) {
- (*message_)[strings::params][strings::message_type] = MessageType::kResponse;
- (*message_)[strings::params][hmi_response::code] = result;
- application_manager_.ManageHMICommand(message_);
-}
+#endif // PROPRIETARY_MODE
} // namespace commands
} // namespace application_manager