diff options
author | Andrey Oleynik <ms_username@outlook.com> | 2017-08-30 15:22:50 +0300 |
---|---|---|
committer | Andrey Oleynik <ms_username@outlook.com> | 2017-08-30 16:49:53 +0300 |
commit | de00f8fc07fef2f9f3783be7e58d3bfdb1e61518 (patch) | |
tree | cdfa5bd0077ae52657272d4289c84955464c3298 | |
parent | 177d0a42c093b36947bd5b8bde1cfb346782dca4 (diff) | |
download | sdl_core-de00f8fc07fef2f9f3783be7e58d3bfdb1e61518.tar.gz |
Restored IsHMI/MessageForPlugin interfaces
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 @@ -50,6 +50,22 @@ class PluginManager : public ModuleObserver { 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. * @param msg Mobile message to process 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<RCFunctionID>(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); |