From de00f8fc07fef2f9f3783be7e58d3bfdb1e61518 Mon Sep 17 00:00:00 2001 From: Andrey Oleynik Date: Wed, 30 Aug 2017 15:22:50 +0300 Subject: Restored IsHMI/MessageForPlugin interfaces --- .../src/application_manager_impl.cc | 24 ++++++---- .../include/functional_module/plugin_manager.h | 16 +++++++ .../functional_module/src/plugin_manager.cc | 56 ++++++++++++++++++++++ 3 files changed, 86 insertions(+), 10 deletions(-) diff --git a/src/components/application_manager/src/application_manager_impl.cc b/src/components/application_manager/src/application_manager_impl.cc index d9d7fa5473..bcc22dcfb5 100644 --- a/src/components/application_manager/src/application_manager_impl.cc +++ b/src/components/application_manager/src/application_manager_impl.cc @@ -2982,10 +2982,12 @@ void ApplicationManagerImpl::Handle(const impl::MessageFromMobile message) { return; } #ifdef SDL_REMOTE_CONTROL - if (functional_modules::ProcessResult::PROCESSED == - plugin_manager_.ProcessMessage(message)) { - LOG4CXX_INFO(logger_, "Message is processed by plugin."); - return; + if (plugin_manager_.IsMessageForPlugin(message)) { + if (functional_modules::ProcessResult::PROCESSED == + plugin_manager_.ProcessMessage(message)) { + LOG4CXX_INFO(logger_, "Message is processed by plugin."); + return; + } } #endif ProcessMessageFromMobile(message); @@ -3034,12 +3036,14 @@ void ApplicationManagerImpl::Handle(const impl::MessageFromHmi message) { } #ifdef SDL_REMOTE_CONTROL - functional_modules::ProcessResult result = - plugin_manager_.ProcessHMIMessage(message); - if (functional_modules::ProcessResult::PROCESSED == result || - functional_modules::ProcessResult::FAILED == result) { - LOG4CXX_INFO(logger_, "Message is processed by plugin."); - return; + if (plugin_manager_.IsHMIMessageForPlugin(message)) { + functional_modules::ProcessResult result = + plugin_manager_.ProcessHMIMessage(message); + if (functional_modules::ProcessResult::PROCESSED == result || + functional_modules::ProcessResult::FAILED == result) { + LOG4CXX_INFO(logger_, "Message is processed by plugin."); + return; + } } #endif diff --git a/src/components/functional_module/include/functional_module/plugin_manager.h b/src/components/functional_module/include/functional_module/plugin_manager.h index ceb19bdf59..65939c9cf3 100644 --- a/src/components/functional_module/include/functional_module/plugin_manager.h +++ b/src/components/functional_module/include/functional_module/plugin_manager.h @@ -49,6 +49,22 @@ class PluginManager : public ModuleObserver { int LoadPlugins(const std::string& plugin_path); void UnloadPlugins(); + /** + * @brief IsMessageForPlugin Verifies whether mobile message will be processed + * by plugins + * @param msg Mobile message + * @return True if any of plugins will process the message, otherwise - false + */ + bool IsMessageForPlugin(application_manager::MessagePtr msg); + + /** + * @brief IsHMIMessageForPlugin Verifies whether HMI message will be processed + * by plugins + * @param msg HMI message + * @return True if any of plugins will process the message, otherwise - false + */ + bool IsHMIMessageForPlugin(application_manager::MessagePtr msg); + /** * @brief ProcessMessage forwards mobile message to modules if any is * subsribed for the message. diff --git a/src/components/functional_module/src/plugin_manager.cc b/src/components/functional_module/src/plugin_manager.cc index 2fff649f37..21ad3c1b88 100644 --- a/src/components/functional_module/src/plugin_manager.cc +++ b/src/components/functional_module/src/plugin_manager.cc @@ -166,6 +166,62 @@ void PluginManager::UnloadPlugins() { dlls_.clear(); } +bool PluginManager::IsMessageForPlugin(application_manager::MessagePtr msg) { + DCHECK(msg); + if (!msg) { + LOG4CXX_ERROR(logger_, "Null pointer message was received."); + return false; + } + if (protocol_handler::MajorProtocolVersion::PROTOCOL_VERSION_UNKNOWN != + msg->protocol_version() && + protocol_handler::MajorProtocolVersion::PROTOCOL_VERSION_HMI != + msg->protocol_version()) { + RCFunctionID id = static_cast(msg->function_id()); + return (mobile_subscribers_.find(id) != mobile_subscribers_.end()); + } else { + return false; + } +} + +bool PluginManager::IsHMIMessageForPlugin(application_manager::MessagePtr msg) { + DCHECK(msg); + if (!msg) { + LOG4CXX_ERROR(logger_, "Null pointer message was received."); + return false; + } + + Json::Value value; + Json::Reader reader; + reader.parse(msg->json_message(), value); + if (protocol_handler::MajorProtocolVersion::PROTOCOL_VERSION_HMI == + msg->protocol_version()) { + std::string msg_method; + // Request or notification from HMI + if (value.isMember("method") && value["method"].isString()) { + msg_method = value["method"].asCString(); + // Response from HMI + } else if (value.isMember("result") && value["result"].isMember("method") && + value["result"]["method"].isString()) { + msg_method = value["result"]["method"].asCString(); + // Error response from HMI + } else if (value.isMember("error") && value["error"].isMember("data") && + value["error"]["data"].isMember("method") && + value["error"]["data"]["method"].isString()) { + msg_method = value["error"]["data"]["method"].asCString(); + } else { + LOG4CXX_WARN(logger_, + "Message with HMI protocol version can not be handled by " + "plugin manager, because required 'method' field was not " + "found, or was containing an invalid string."); + return false; + } + + return (hmi_subscribers_.find(msg_method) != hmi_subscribers_.end()); + } + + return false; +} + ProcessResult PluginManager::ProcessMessage( application_manager::MessagePtr msg) { DCHECK(msg); -- cgit v1.2.1