diff options
author | Andriy Byzhynar <AByzhynar@luxoft.com> | 2017-07-27 17:54:27 +0300 |
---|---|---|
committer | Andriy Byzhynar <AByzhynar@luxoft.com> | 2017-07-27 18:08:09 +0300 |
commit | 9e7fb8d1d9391a4c1164645f386e24d551d8d10a (patch) | |
tree | f34539fe02846fd9b4588af83c714e56cd8a1249 | |
parent | e10c3fa1246cc54a51895b63a9f04055f1ac4082 (diff) | |
download | sdl_core-9e7fb8d1d9391a4c1164645f386e24d551d8d10a.tar.gz |
Fix cutting of subscribe parameter
Implemented cutting off subscribe parameter from request to hmi
when app tries to subscribe/unsubscribe from module but app is already
subscribed/unsubscribed from it
2 files changed, 45 insertions, 1 deletions
diff --git a/src/components/remote_control/include/remote_control/commands/get_interior_vehicle_data_request.h b/src/components/remote_control/include/remote_control/commands/get_interior_vehicle_data_request.h index 148250a6fa..d687221fbe 100644 --- a/src/components/remote_control/include/remote_control/commands/get_interior_vehicle_data_request.h +++ b/src/components/remote_control/include/remote_control/commands/get_interior_vehicle_data_request.h @@ -68,6 +68,15 @@ class GetInteriorVehicleDataRequest : public BaseCommandRequest { void OnEvent(const rc_event_engine::Event<application_manager::MessagePtr, std::string>& event); + /** + * @brief Check if app wants to proceed with already setup subscription + * @param request_params request parameters to check + * @return true if app already subscribed(unsubsribed) for module type but + * wants to subscribe(unsubscribe) for the same module again + * otherwise - false + */ + bool HasRequestExcessiveSubscription(const Json::Value& request_params); + protected: virtual std::string ModuleType(const Json::Value& message); @@ -77,6 +86,12 @@ class GetInteriorVehicleDataRequest : public BaseCommandRequest { * @param hmi_response json message with response from HMI */ void ProccessSubscription(const Json::Value& hmi_response); + + /** + * @brief Cuts off subscribe parameter + * @param request_params request parameters to handle + */ + void RemoveExcessiveSubscription(Json::Value& request_params); }; } // namespace commands diff --git a/src/components/remote_control/src/commands/get_interior_vehicle_data_request.cc b/src/components/remote_control/src/commands/get_interior_vehicle_data_request.cc index cb19a2142c..cfd08b47f6 100644 --- a/src/components/remote_control/src/commands/get_interior_vehicle_data_request.cc +++ b/src/components/remote_control/src/commands/get_interior_vehicle_data_request.cc @@ -56,9 +56,13 @@ GetInteriorVehicleDataRequest::GetInteriorVehicleDataRequest( void GetInteriorVehicleDataRequest::Execute() { LOG4CXX_AUTO_TRACE(logger_); - const Json::Value request_params = + Json::Value request_params = MessageHelper::StringToValue(message_->json_message()); + if (HasRequestExcessiveSubscription(request_params)) { + RemoveExcessiveSubscription(request_params); + } + SendRequest(functional_modules::hmi_api::get_interior_vehicle_data, request_params); } @@ -152,6 +156,31 @@ void GetInteriorVehicleDataRequest::ProccessSubscription( } } +bool GetInteriorVehicleDataRequest::HasRequestExcessiveSubscription( + const Json::Value& request_params) { + LOG4CXX_AUTO_TRACE(logger_); + const bool is_subscribe_present_in_request = + IsMember(request_params, kSubscribe); + if (is_subscribe_present_in_request) { + RCAppExtensionPtr extension = GetAppExtension(app()); + const bool is_app_already_subscribed = + extension->IsSubscibedToInteriorVehicleData( + request_params[kModuleType]); + const bool app_wants_to_subscribe = request_params[kSubscribe].asBool(); + if (!app_wants_to_subscribe && !is_app_already_subscribed) { + return true; + } + return app_wants_to_subscribe && is_app_already_subscribed; + } + return false; +} + +void GetInteriorVehicleDataRequest::RemoveExcessiveSubscription( + Json::Value& request_params) { + LOG4CXX_AUTO_TRACE(logger_); + request_params.removeMember(kSubscribe); +} + std::string GetInteriorVehicleDataRequest::ModuleType( const Json::Value& message) { return message.get(message_params::kModuleType, "").asString(); |