diff options
Diffstat (limited to 'src/components/application_manager/rpc_plugins')
18 files changed, 801 insertions, 108 deletions
diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/CMakeLists.txt b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/CMakeLists.txt index 1930a05b6e..00de927b6e 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/CMakeLists.txt +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/CMakeLists.txt @@ -45,10 +45,12 @@ set (HMI_COMMANDS_SOURCE_DIR collect_sources(MOBILE_COMMANDS "${MOBILE_COMMANDS_SOURCE_DIR}") collect_sources(HMI_COMMANDS "${HMI_COMMANDS_SOURCE_DIR}") collect_sources(PLUGIN_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src") +collect_sources(COMMANDS_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/commands") set(LIBRARIES HMI_API MOBILE_API + ApplicationManager v4_protocol_v1_2_no_extra SmartObjects Utils @@ -58,14 +60,12 @@ if(ENABLE_LOG) list(APPEND LIBRARIES log4cxx -L${LOG4CXX_LIBS_DIRECTORY}) endif() -add_library("rc_rpc_plugin" SHARED ${PLUGIN_SOURCES} ${MOBILE_COMMANDS} ${HMI_COMMANDS}) +add_library("rc_rpc_plugin" SHARED ${PLUGIN_SOURCES} ${MOBILE_COMMANDS} ${HMI_COMMANDS} ${COMMANDS_SOURCES}) target_link_libraries("rc_rpc_plugin" ${LIBRARIES}) add_library("RCRpcPluginStaticLib" ${PLUGIN_SOURCES} ${MOBILE_COMMANDS} ${HMI_COMMANDS}) target_link_libraries("RCRpcPluginStaticLib" ${LIBRARIES}) - - set(INSTALL_DESTINATION bin) install(TARGETS rc_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/hmi/rc_button_press_request.h b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/hmi/rc_button_press_request.h index fb77bc6169..7ee56c4437 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/hmi/rc_button_press_request.h +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/hmi/rc_button_press_request.h @@ -1,7 +1,7 @@ #ifndef SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_RC_RPC_PLUGIN_INCLUDE_COMMANDS_HMI_RC_BUTTON_PRESS_REQUEST_H #define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_RC_RPC_PLUGIN_INCLUDE_COMMANDS_HMI_RC_BUTTON_PRESS_REQUEST_H -#include "application_manager/commands/request_from_hmi.h" +#include "application_manager/commands/request_to_hmi.h" #include "utils/macro.h" namespace rc_rpc_plugin { @@ -9,14 +9,16 @@ namespace app_mngr = application_manager; namespace commands { class RCButtonPressRequest - : public application_manager::commands::RequestFromHMI { + : public application_manager::commands::RequestToHMI { public: RCButtonPressRequest( const app_mngr::commands::MessageSharedPtr& message, app_mngr::ApplicationManager& application_manager); - bool Init() OVERRIDE; + /** + * @brief Execute command + */ void Run() OVERRIDE; - void on_event(const application_manager::event_engine::Event& event) OVERRIDE; + virtual ~RCButtonPressRequest(); }; } // namespace commands } // namespace rc_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/hmi/rc_button_press_response.h b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/hmi/rc_button_press_response.h index 01093d3548..6972762515 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/hmi/rc_button_press_response.h +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/hmi/rc_button_press_response.h @@ -1,7 +1,7 @@ #ifndef SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_RC_RPC_PLUGIN_INCLUDE_COMMANDS_HMI_RC_BUTTON_PRESS_RESPONSE_H #define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_RC_RPC_PLUGIN_INCLUDE_COMMANDS_HMI_RC_BUTTON_PRESS_RESPONSE_H -#include "application_manager/commands/response_to_hmi.h" +#include "application_manager/commands/response_from_hmi.h" #include "utils/macro.h" namespace rc_rpc_plugin { @@ -9,14 +9,15 @@ namespace app_mngr = application_manager; namespace commands { class RCButtonPressResponse - : public application_manager::commands::ResponseToHMI { + : public application_manager::commands::ResponseFromHMI { public: RCButtonPressResponse( const app_mngr::commands::MessageSharedPtr& message, app_mngr::ApplicationManager& application_manager); - bool Init() OVERRIDE; + void Run() OVERRIDE; - void on_event(const application_manager::event_engine::Event& event); + + virtual ~RCButtonPressResponse(); }; } // namespace commands } // namespace rc_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/mobile/button_press_request.h b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/mobile/button_press_request.h index 7c88cea5a7..746eb152b7 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/mobile/button_press_request.h +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/mobile/button_press_request.h @@ -1,21 +1,62 @@ #ifndef SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_RC_RPC_PLUGIN_INCLUDE_COMMANDS_BUTTON_PRESS_REQUEST_H #define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_RC_RPC_PLUGIN_INCLUDE_COMMANDS_BUTTON_PRESS_REQUEST_H -#include "application_manager/commands/command_request_impl.h" -#include "utils/macro.h" +#include "rc_rpc_plugin/commands/rc_command_request.h" namespace rc_rpc_plugin { namespace app_mngr = application_manager; namespace commands { -class ButtonPressRequest : public app_mngr::commands::CommandRequestImpl { +class ButtonPressRequest : public RCCommandRequest { public: - ButtonPressRequest(const app_mngr::commands::MessageSharedPtr& message, - app_mngr::ApplicationManager& application_manager); - bool Init() OVERRIDE; - void Run() OVERRIDE; - void on_event(const application_manager::event_engine::Event& event) OVERRIDE; + ButtonPressRequest( + const app_mngr::commands::MessageSharedPtr& message, + app_mngr::ApplicationManager& application_manager, + rc_rpc_plugin::ResourceAllocationManager& resource_allocation_manager); + + /** + * @brief Execute command + * send HMI request if message contains appropriate + * button name and module type + * otherwise sends negative sesponse to mobile + */ + void Execute() FINAL; + + /** + * @brief AcquireResource Tries to acquire specific resource + * @param message Incoming message containg the resource name + * @return Acquire result + */ + AcquireResult::eType AcquireResource( + const app_mngr::commands::MessageSharedPtr& message) FINAL; + + /** + * @brief IsResourceFree check resource state + * @param module_type Resource name + * @return True if free, otherwise - false + */ + bool IsResourceFree(const std::string& module_type) const FINAL; + + /** + * @brief SetResourceState changes state of resource + * @param state State to set for resource + */ + void SetResourceState(const std::string& module_type, + const ResourceState::eType state) FINAL; + + /** + * @brief Interface method that is called whenever new event received + * + * @param event The received event + */ + void on_event(const app_mngr::event_engine::Event& event) FINAL; + + /** + * @brief ButtonPressRequest class destructor + */ + virtual ~ButtonPressRequest(); }; + } // namespace commands } // namespace rc_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/mobile/button_press_response.h b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/mobile/button_press_response.h index 165124cdfe..fa113df91e 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/mobile/button_press_response.h +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/mobile/button_press_response.h @@ -13,9 +13,11 @@ class ButtonPressResponse public: ButtonPressResponse(const app_mngr::commands::MessageSharedPtr& message, app_mngr::ApplicationManager& application_manager); - bool Init() OVERRIDE; void Run() OVERRIDE; - void on_event(const application_manager::event_engine::Event& event); + /** + * @brief ButtonPressResponse class destructor + */ + virtual ~ButtonPressResponse(); }; } // namespace commands } // namespace rc_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/rc_command_request.h b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/rc_command_request.h new file mode 100644 index 0000000000..f1d1f57704 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/commands/rc_command_request.h @@ -0,0 +1,161 @@ +/* + Copyright (c) 2018, Ford Motor Company + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following + disclaimer in the documentation and/or other materials provided with the + distribution. + + Neither the name of the Ford Motor Company nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_RC_RPC_PLUGIN_INCLUDE_RC_RPC_PLUGIN_COMMANDS_RC_COMMAND_REQUEST_H +#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_RC_RPC_PLUGIN_INCLUDE_RC_RPC_PLUGIN_COMMANDS_RC_COMMAND_REQUEST_H + +#include "rc_rpc_plugin/resource_allocation_manager.h" +#include "rc_rpc_plugin/rc_app_extension.h" +#include "application_manager/commands/command_request_impl.h" + +namespace rc_rpc_plugin { +namespace app_mngr = application_manager; + +enum TypeAccess { kDisallowed, kAllowed }; + +namespace commands { + +class RCCommandRequest : public app_mngr::commands::CommandRequestImpl { + public: + /** + * @brief RCCommandRequest class constructor + * + **/ + RCCommandRequest( + rc_rpc_plugin::ResourceAllocationManager& resource_allocation_manager, + const app_mngr::commands::MessageSharedPtr& message, + app_mngr::ApplicationManager& application_manager); + + virtual ~RCCommandRequest(); + + void onTimeOut() OVERRIDE; + + void Run() OVERRIDE; + + virtual void on_event(const app_mngr::event_engine::Event& event) OVERRIDE; + + protected: + ResourceAllocationManager& resource_allocation_manager_; + bool auto_allowed_; + + /** + * @brief AcquireResource try to allocate resource for application + * In case if allocation of resource is not required, return ALLOWED by + * default. + * This method should be overrided in RPCs that requires resource allocation + * @return result of resource allocation, in case if allocation os not + * required, return ALLOWED + */ + virtual AcquireResult::eType AcquireResource( + const app_mngr::commands::MessageSharedPtr& message) { + return AcquireResult::ALLOWED; + } + + /** + * @brief IsResourceFree check resource state + * This is default implementation which has to be redefined for RPCs which + * need to manage the resources + * @param module_type Resource name + * @return True if free, otherwise - false + */ + virtual bool IsResourceFree(const std::string& module_type) const { + UNUSED(module_type); + return true; + } + /** + * @brief SetResourceState changes state of resource + * This is default implementation which has to be redefined for RPCs which + * need to manage the resources + * @param module_type Resource name + * @param State to set for resource + */ + virtual void SetResourceState(const std::string& module_type, + const ResourceState::eType) {} + + /** + * Checks if module for application is present in policy table + * @param app_id id of application + * @param module type Resource name + * @return kAllowed if module is present, otherwise - kDisallowed + */ + TypeAccess CheckModule(const std::string& module_type, + application_manager::ApplicationSharedPtr app); + + bool auto_allowed() const { + return auto_allowed_; + } + + void set_auto_allowed(const bool value) { + auto_allowed_ = value; + } + + /** + * @brief executes specific logic of children classes + */ + void virtual Execute() = 0; + + void set_disallowed_info(const std::string& info) { + disallowed_info_ = info; + } + + private: + /** + * @brief CheckDriverConsent checks driver consent defined in policy table + * @return True if no consent is required, otherwise - false + */ + bool CheckDriverConsent(); + + /** + * @brief AcquireResources checks whether resource status is busy or not and + * then tries to acquire this resource. In case driver consent is required - + * sends consent request to HMI. + * @return True in case of resource is free and successfully acquired, + * otherwise false + */ + bool AcquireResources(); + void SendDisallowed(TypeAccess access); + + /** + * @brief SendGetUserConsent sends consent request to HMI + * @param module_type Resource name + */ + void SendGetUserConsent(const std::string& module_type); + void ProcessAccessResponse(const app_mngr::event_engine::Event& event); + bool IsInterfaceAvailable( + const app_mngr::HmiInterfaces::InterfaceID interface) const; + + std::string disallowed_info_; +}; +} +} + +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_RC_RPC_PLUGIN_INCLUDE_RC_RPC_PLUGIN_COMMANDS_RC_COMMAND_REQUEST_H diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_command_factory.h b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_command_factory.h index fc4ba13b85..af32cfc82b 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_command_factory.h +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_command_factory.h @@ -8,6 +8,7 @@ #include "application_manager/rpc_service.h" #include "application_manager/hmi_capabilities.h" #include "application_manager/policies/policy_handler_interface.h" +#include "rc_rpc_plugin/resource_allocation_manager.h" #include "utils/macro.h" namespace rc_rpc_plugin { @@ -17,7 +18,8 @@ class RCCommandFactory : public application_manager::CommandFactory { RCCommandFactory(app_mngr::ApplicationManager& app_manager, app_mngr::rpc_service::RPCService& rpc_service, app_mngr::HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handler); + policy::PolicyHandlerInterface& policy_handler, + ResourceAllocationManager& allocation_manager); application_manager::CommandSharedPtr CreateCommand( const app_mngr::commands::MessageSharedPtr& message, app_mngr::commands::Command::CommandSource source) OVERRIDE; @@ -35,6 +37,7 @@ class RCCommandFactory : public application_manager::CommandFactory { app_mngr::rpc_service::RPCService& rpc_service_; app_mngr::HMICapabilities& hmi_capabilities_; policy::PolicyHandlerInterface& policy_handler_; + ResourceAllocationManager& allocation_manager_; }; } // namespace rc_rpc_plugin #endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_RC_RPC_PLUGIN_INCLUDE_RC_RPC_PLUGIN_RC_COMMAND_FACTORY_H diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_module_constants.h b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_module_constants.h index 021e3cd6f0..d0f01d78ce 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_module_constants.h +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_module_constants.h @@ -33,7 +33,7 @@ #ifndef SRC_COMPONENTS_REMOTE_CONTROL_INCLUDE_REMOTE_CONTROL_RC_MODULE_CONSTANTS_H_ #define SRC_COMPONENTS_REMOTE_CONTROL_INCLUDE_REMOTE_CONTROL_RC_MODULE_CONSTANTS_H_ -namespace remote_control { +namespace rc_rpc_plugin { namespace strings { // RemoteControlCapabilities constants diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_rpc_plugin.h b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_rpc_plugin.h index ffc6cab609..e102dc597d 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_rpc_plugin.h +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_rpc_plugin.h @@ -61,4 +61,7 @@ class RCRPCPlugin : public plugins::RPCPlugin { std::unique_ptr<ResourceAllocationManager> resource_allocation_manager_; }; } // namespace rc_rpc_plugin + +extern "C" application_manager::plugin_manager::RPCPlugin* Create(); + #endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_RC_RPC_PLUGIN_INCLUDE_RC_RPC_PLUGIN_RC_PLUGIN_H diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/resource_allocation_manager.h b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/resource_allocation_manager.h index 8a829aa1dc..26472aa517 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/resource_allocation_manager.h +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/resource_allocation_manager.h @@ -5,6 +5,7 @@ #include "utils/shared_ptr.h" #include "interfaces/HMI_API.h" #include "application_manager/plugin_manager/rpc_plugin.h" +#include "rc_rpc_plugin/rc_app_extension.h" //#include "remote_control/event_engine/event.h" //#include "functional_module/generic_module.h" @@ -110,6 +111,9 @@ class ResourceAllocationManager { */ virtual void ResetAllAllocations() = 0; + virtual RCAppExtensionPtr GetApplicationExtention( + application_manager::ApplicationSharedPtr application) = 0; + virtual ~ResourceAllocationManager() {} }; diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/resource_allocation_manager_impl.h b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/resource_allocation_manager_impl.h index 433cfef33c..c99b47c5f8 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/resource_allocation_manager_impl.h +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/resource_allocation_manager_impl.h @@ -56,6 +56,14 @@ class ResourceAllocationManagerImpl : public ResourceAllocationManager { void ResetAllAllocations() FINAL; + /** + * @brief GetApplicationExtention Provides access to application RC extention + * @param application Application + * @return Pointer to RC extention of application or NULL if not available + */ + RCAppExtensionPtr GetApplicationExtention( + application_manager::ApplicationSharedPtr application) FINAL; + private: typedef std::vector<application_manager::ApplicationSharedPtr> Apps; @@ -96,14 +104,6 @@ class ResourceAllocationManagerImpl : public ResourceAllocationManager { void ProcessApplicationPolicyUpdate(); /** - * @brief GetApplicationExtention Provides access to application RC extention - * @param application Application - * @return Pointer to RC extention of application or NULL if not available - */ - RCAppExtensionPtr GetApplicationExtention( - application_manager::ApplicationSharedPtr application); - - /** * @brief RemoveAppsSubscriptions Removes subscriptions for interior data for * applications in the list * @param apps Application list diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/hmi/rc_button_press_request.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/hmi/rc_button_press_request.cc index c903791e7a..77f5bb6246 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/hmi/rc_button_press_request.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/hmi/rc_button_press_request.cc @@ -7,14 +7,14 @@ namespace commands { RCButtonPressRequest::RCButtonPressRequest( const app_mngr::commands::MessageSharedPtr& message, app_mngr::ApplicationManager& application_manager) - :app_mngr::commands::RequestFromHMI(message, application_manager) {} + :app_mngr::commands::RequestToHMI(message, application_manager) {} -bool RCButtonPressRequest::Init() { - return true; +RCButtonPressRequest::~RCButtonPressRequest(){} + +void RCButtonPressRequest::Run() { + LOG4CXX_AUTO_TRACE(logger_); + SendRequest(); } -void RCButtonPressRequest::Run() {} -void RCButtonPressRequest::on_event( - const application_manager::event_engine::Event& event) {} } // namespace commands } // namespace rc_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/hmi/rc_button_press_response.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/hmi/rc_button_press_response.cc index 14cc81b849..e0e8e74c82 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/hmi/rc_button_press_response.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/hmi/rc_button_press_response.cc @@ -1,5 +1,5 @@ #include "rc_rpc_plugin/commands/hmi/rc_button_press_response.h" -#include "utils/macro.h" +#include "application_manager/event_engine/event.h" namespace rc_rpc_plugin { namespace commands { @@ -7,14 +7,17 @@ namespace commands { RCButtonPressResponse::RCButtonPressResponse( const app_mngr::commands::MessageSharedPtr& message, app_mngr::ApplicationManager& application_manager) - :app_mngr::commands::ResponseToHMI(message, application_manager) {} + :app_mngr::commands::ResponseFromHMI(message, application_manager) {} -bool RCButtonPressResponse::Init() { - return true; +void RCButtonPressResponse::Run() { + LOG4CXX_AUTO_TRACE(logger_); + + app_mngr::event_engine::Event event(hmi_apis::FunctionID::Buttons_ButtonPress); + event.set_smart_object(*message_); + event.raise(application_manager_.event_dispatcher()); } -void RCButtonPressResponse::Run() {} -void RCButtonPressResponse::on_event( - const application_manager::event_engine::Event& event) {} + +RCButtonPressResponse::~RCButtonPressResponse(){} } // namespace commands } // namespace rc_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/button_press_request.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/button_press_request.cc index d3c328b43a..0329df5be4 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/button_press_request.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/button_press_request.cc @@ -1,20 +1,235 @@ #include "rc_rpc_plugin/commands/mobile/button_press_request.h" +#include "rc_rpc_plugin/rc_module_constants.h" #include "utils/macro.h" +#include "json/json.h" +#include "utils/helpers.h" +#include "interfaces/MOBILE_API.h" namespace rc_rpc_plugin { namespace commands { +using namespace json_keys; +using namespace message_params; + +CREATE_LOGGERPTR_GLOBAL(logger_, "RemoteControlModule") + +typedef std::map<std::string, mobile_apis::ButtonName::eType> ButtonsMap; + ButtonPressRequest::ButtonPressRequest( const app_mngr::commands::MessageSharedPtr& message, - app_mngr::ApplicationManager& application_manager) - : app_mngr::commands::CommandRequestImpl(message, application_manager) {} + app_mngr::ApplicationManager& application_manager, + rc_rpc_plugin::ResourceAllocationManager& resource_allocation_manager) + : RCCommandRequest( + resource_allocation_manager, message, application_manager) {} + +ButtonPressRequest::~ButtonPressRequest() {} + +const std::vector<std::string> buttons_climate() { + std::vector<std::string> data; + data.push_back(enums_value::kACMax); + data.push_back(enums_value::kAC); + data.push_back(enums_value::kRecirculate); + data.push_back(enums_value::kFanUp); + data.push_back(enums_value::kFanDown); + data.push_back(enums_value::kTempUp); + data.push_back(enums_value::kTempDown); + data.push_back(enums_value::kDefrostMax); + data.push_back(enums_value::kDefrost); + data.push_back(enums_value::kDefrostRear); + data.push_back(enums_value::kUpperVent); + data.push_back(enums_value::kLowerVent); + return data; +} + +const std::vector<std::string> buttons_radio() { + std::vector<std::string> data; + data.push_back(enums_value::kVolumeUp); + data.push_back(enums_value::kVolumeDown); + data.push_back(enums_value::kEject); + data.push_back(enums_value::kSource); + data.push_back(enums_value::kShuffle); + data.push_back(enums_value::kRepeat); + return data; +} + +const ButtonsMap buttons_map() { + using namespace mobile_apis; -bool ButtonPressRequest::Init() { + ButtonsMap buttons_map; + buttons_map[enums_value::kACMax] = ButtonName::AC_MAX; + buttons_map[enums_value::kAC] = ButtonName::AC; + buttons_map[enums_value::kRecirculate] = ButtonName::RECIRCULATE; + buttons_map[enums_value::kFanUp] = ButtonName::FAN_UP; + buttons_map[enums_value::kFanDown] = ButtonName::FAN_DOWN; + buttons_map[enums_value::kTempUp] = ButtonName::TEMP_UP; + buttons_map[enums_value::kTempDown] = ButtonName::TEMP_DOWN; + buttons_map[enums_value::kDefrostMax] = ButtonName::DEFROST_MAX; + buttons_map[enums_value::kDefrost] = ButtonName::DEFROST; + buttons_map[enums_value::kDefrostRear] = ButtonName::DEFROST_REAR; + buttons_map[enums_value::kUpperVent] = ButtonName::UPPER_VENT; + buttons_map[enums_value::kLowerVent] = ButtonName::LOWER_VENT; + buttons_map[enums_value::kVolumeUp] = ButtonName::VOLUME_UP; + buttons_map[enums_value::kVolumeDown] = ButtonName::VOLUME_DOWN; + buttons_map[enums_value::kEject] = ButtonName::EJECT; + buttons_map[enums_value::kSource] = ButtonName::SOURCE; + buttons_map[enums_value::kShuffle] = ButtonName::SHUFFLE; + buttons_map[enums_value::kRepeat] = ButtonName::REPEAT; + + return buttons_map; +} + +bool CheckIfButtonExistInRCCaps( + const smart_objects::SmartObject& rc_capabilities, + const mobile_apis::ButtonName::eType button) { + if (rc_capabilities.keyExists(strings::kbuttonCapabilities)) { + const smart_objects::SmartObject& button_caps = + rc_capabilities[strings::kbuttonCapabilities]; + auto it = button_caps.asArray()->begin(); + for (; it != button_caps.asArray()->end(); ++it) { + smart_objects::SmartObject& so = *it; + int64_t current_id = so[message_params::kName].asInt(); + if (-1 == current_id) { + // capabilities received from HMI contains enum values + // capabilities loaded from file contains string values + // TODO : unificate capabilities storing + const std::string& bt_name = so[message_params::kName].asString(); + static ButtonsMap btn_map = buttons_map(); + current_id = btn_map[bt_name]; + } + const mobile_apis::ButtonName::eType current_button = + static_cast<mobile_apis::ButtonName::eType>(current_id); + if (current_button == button) { + LOG4CXX_TRACE(logger_, + "Button id " << current_button + << " exist in capabilities"); + return true; + } + } + } + LOG4CXX_TRACE(logger_, + "Button id " << button << " do not exist in capabilities"); + return false; +} + +bool CheckButtonName(const std::string& module_type, + const std::string& button_name, + const smart_objects::SmartObject* rc_capabilities) { + LOG4CXX_AUTO_TRACE(logger_); + if (rc_capabilities == NULL) { + LOG4CXX_ERROR(logger_, "No remote controll capabilities available"); + return false; + } + + if (enums_value::kRadio == module_type) { + if (!helpers::in_range(buttons_radio(), button_name)) { + LOG4CXX_WARN(logger_, + "Trying to acceess climate button with module type radio"); + return false; + } + } + + if (enums_value::kClimate == module_type) { + if (!helpers::in_range(buttons_climate(), button_name)) { + LOG4CXX_WARN(logger_, + "Trying to acceess radio button with module type climate"); + return false; + } + } return true; } -void ButtonPressRequest::Run() {} -void ButtonPressRequest::on_event( - const application_manager::event_engine::Event& event) {} + +void ButtonPressRequest::Execute() { + LOG4CXX_AUTO_TRACE(logger_); + + const std::string button_name = + (*message_)[app_mngr::strings::msg_params][message_params::kButtonName].asString(); + const std::string module_type = + (*message_)[app_mngr::strings::msg_params][message_params::kModuleType].asString(); + + static ButtonsMap btn_map = buttons_map(); + mobile_apis::ButtonName::eType button_id = + mobile_apis::ButtonName::INVALID_ENUM; + if (btn_map.end() != btn_map.find(button_name)) { + button_id = btn_map[button_name]; + } + + const smart_objects::SmartObject* rc_capabilities = + application_manager_.hmi_capabilities().rc_capability(); + const bool button_name_matches_module_type = + CheckButtonName(module_type, button_name, rc_capabilities); + const bool button_id_exist_in_caps = + rc_capabilities && + CheckIfButtonExistInRCCaps(*rc_capabilities, button_id); + + if (button_name_matches_module_type && button_id_exist_in_caps) { + SendHMIRequest(hmi_apis::FunctionID::Buttons_ButtonPress, + &(*message_)[app_mngr::strings::msg_params], + true); + } else if (!button_name_matches_module_type) { + LOG4CXX_WARN(logger_, "Request module type and button name mismatch!"); + SendResponse(false, + mobile_apis::Result::INVALID_DATA, + "Request module type and button name mismatch!"); + } else { + LOG4CXX_WARN(logger_, "Requested button is not exists in capabilities!"); + SendResponse(false, + mobile_apis::Result::UNSUPPORTED_RESOURCE, + "Requested button is not exists in capabilities!"); + } +} + +AcquireResult::eType ButtonPressRequest::AcquireResource( + const app_mngr::commands::MessageSharedPtr& message) { + LOG4CXX_AUTO_TRACE(logger_); + const std::string module_type = + (*message_)[app_mngr::strings::msg_params][message_params::kModuleType] + .asString(); + app_mngr::ApplicationSharedPtr app = + application_manager_.application(CommandRequestImpl::connection_key()); + return resource_allocation_manager_.AcquireResource(module_type, app->app_id()); +} + +bool ButtonPressRequest::IsResourceFree(const std::string& module_type) const { + LOG4CXX_AUTO_TRACE(logger_); + return resource_allocation_manager_.IsResourceFree(module_type); +} + +void ButtonPressRequest::SetResourceState(const std::string& module_type, + const ResourceState::eType state) { + LOG4CXX_AUTO_TRACE(logger_); + app_mngr::ApplicationSharedPtr app = + application_manager_.application(CommandRequestImpl::connection_key()); + resource_allocation_manager_.SetResourceState(module_type, app->app_id(), state); +} + +void ButtonPressRequest::on_event(const app_mngr::event_engine::Event& event) { + LOG4CXX_AUTO_TRACE(logger_); + RCCommandRequest::on_event(event); + + if (hmi_apis::FunctionID::Buttons_ButtonPress != event.id()){ + return; + } + + const smart_objects::SmartObject& message = event.smart_object(); + mobile_apis::Result::eType result_code = + GetMobileResultCode(static_cast<hmi_apis::Common_Result::eType>( + message[app_mngr::strings::params][app_mngr::hmi_response::code] + .asUInt())); + + bool result = + helpers::Compare<mobile_apis::Result::eType, helpers::EQ, helpers::ONE>( + result_code, + mobile_apis::Result::SUCCESS, + mobile_apis::Result::WARNINGS); + + if (mobile_apis::Result::READ_ONLY == result_code) { + result = false; + result_code = mobile_apis::Result::GENERIC_ERROR; + } + std::string response_info; + GetInfo(message, response_info); + SendResponse(result, result_code, response_info.c_str()); +} } // namespace commands } // namespace rc_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/button_press_response.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/button_press_response.cc index 37e7029e9d..fda70dcd9f 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/button_press_response.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/button_press_response.cc @@ -1,5 +1,5 @@ #include "rc_rpc_plugin/commands/mobile/button_press_response.h" -#include "utils/macro.h" +#include "application_manager/rpc_service.h" namespace rc_rpc_plugin { namespace commands { @@ -9,12 +9,12 @@ ButtonPressResponse::ButtonPressResponse( app_mngr::ApplicationManager& application_manager) : app_mngr::commands::CommandResponseImpl(message, application_manager) {} -bool ButtonPressResponse::Init() { - return true; +ButtonPressResponse::~ButtonPressResponse(){} + +void ButtonPressResponse::Run() { + LOG4CXX_AUTO_TRACE(logger_); + application_manager_.GetRPCService().SendMessageToMobile(message_); } -void ButtonPressResponse::Run() {} -void ButtonPressResponse::on_event( - const application_manager::event_engine::Event& event) {} } // namespace commands } // namespace rc_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/rc_command_request.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/rc_command_request.cc new file mode 100644 index 0000000000..f39707c7d9 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/rc_command_request.cc @@ -0,0 +1,247 @@ +/* + Copyright (c) 2018, Ford Motor Company + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following + disclaimer in the documentation and/or other materials provided with the + distribution. + + Neither the name of the Ford Motor Company nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + */ + +#include "rc_rpc_plugin/commands/rc_command_request.h" +#include "rc_rpc_plugin/rc_module_constants.h" +#include "application_manager/message_helper.h" +#include "application_manager/hmi_interfaces.h" + +CREATE_LOGGERPTR_GLOBAL(logger_, "RemoteControlModule") + +namespace rc_rpc_plugin { +namespace commands { + +RCCommandRequest::RCCommandRequest( + rc_rpc_plugin::ResourceAllocationManager& resource_allocation_manager, + const app_mngr::commands::MessageSharedPtr& message, + app_mngr::ApplicationManager& application_manager) + : app_mngr::commands::CommandRequestImpl(message, application_manager) + , resource_allocation_manager_(resource_allocation_manager) {} + +RCCommandRequest::~RCCommandRequest(){} + +bool RCCommandRequest::IsInterfaceAvailable( + const app_mngr::HmiInterfaces::InterfaceID interface) const { + app_mngr::HmiInterfaces& hmi_interfaces = + application_manager_.hmi_interfaces(); + const app_mngr::HmiInterfaces::InterfaceState state = + hmi_interfaces.GetInterfaceState(interface); + return app_mngr::HmiInterfaces::STATE_NOT_AVAILABLE != state; +} + +void RCCommandRequest::onTimeOut() { + LOG4CXX_AUTO_TRACE(logger_); + SetResourceState( + (*message_)[app_mngr::strings::msg_params][message_params::kModuleType].asString(), + ResourceState::FREE); + SendResponse( + false, mobile_apis::Result::GENERIC_ERROR, "Request timeout expired"); +} + +bool RCCommandRequest::CheckDriverConsent() { + LOG4CXX_AUTO_TRACE(logger_); + app_mngr::ApplicationSharedPtr app = + application_manager_.application(CommandRequestImpl::connection_key()); + RCAppExtensionPtr extension = resource_allocation_manager_.GetApplicationExtention(app); + if (!extension) { + LOG4CXX_ERROR(logger_, "NULL pointer."); + return false; + } + const std::string module_type = + (*message_)[app_mngr::strings::msg_params][message_params::kModuleType].asString(); + rc_rpc_plugin::TypeAccess access = CheckModule(module_type, app); + + if (rc_rpc_plugin::kAllowed == access) { + set_auto_allowed(true); + return true; + } else { + SendDisallowed(access); + } + return false; +} + +rc_rpc_plugin::TypeAccess RCCommandRequest::CheckModule( + const std::string& module_type, + application_manager::ApplicationSharedPtr app) { + return application_manager_.GetPolicyHandler().CheckModule( + app->policy_app_id(), module_type) + ? rc_rpc_plugin::TypeAccess::kAllowed + : rc_rpc_plugin::TypeAccess::kDisallowed; +} + +void RCCommandRequest::SendDisallowed(rc_rpc_plugin::TypeAccess access) { + LOG4CXX_AUTO_TRACE(logger_); + std::string info; + if (rc_rpc_plugin::kDisallowed == access) { + info = disallowed_info_.empty() + ? "The RPC is disallowed by vehicle settings" + : disallowed_info_; + } else { + return; + } + LOG4CXX_ERROR(logger_, info); + SendResponse(false, mobile_apis::Result::DISALLOWED, info.c_str()); +} + +void RCCommandRequest::Run() { + LOG4CXX_AUTO_TRACE(logger_); + if (!IsInterfaceAvailable(app_mngr::HmiInterfaces::HMI_INTERFACE_RC)) { + LOG4CXX_WARN(logger_, "HMI interface RC is not available"); + SendResponse(false, + mobile_apis::Result::UNSUPPORTED_RESOURCE, + "Remote control is not supported by system"); + return; + } + LOG4CXX_TRACE(logger_, "RC interface is available!"); + if (CheckDriverConsent()) { + if (AcquireResources()) { + Execute(); // run child's logic + } + // If resource is not aqcuired, AcquireResources method will either + // send response to mobile or + // send additional request to HMI to ask driver consent + } +} + +bool RCCommandRequest::AcquireResources() { + LOG4CXX_AUTO_TRACE(logger_); + const std::string module_type = + (*message_)[app_mngr::strings::msg_params][message_params::kModuleType].asString(); + + if (!IsResourceFree(module_type)) { + LOG4CXX_WARN(logger_, "Resource is busy."); + SendResponse(false, mobile_apis::Result::IN_USE, ""); + return false; + } + + AcquireResult::eType acquire_result = AcquireResource(message_); + switch (acquire_result) { + case AcquireResult::ALLOWED: { + SetResourceState(module_type, ResourceState::BUSY); + return true; + } + case AcquireResult::IN_USE: { + SendResponse(false, mobile_apis::Result::IN_USE, ""); + return false; + } + case AcquireResult::ASK_DRIVER: { + SetResourceState(module_type, ResourceState::BUSY); + SendGetUserConsent(module_type); + return false; + } + case AcquireResult::REJECTED: { + SendResponse(false, mobile_apis::Result::REJECTED, ""); + return false; + } + } + return false; +} + +void RCCommandRequest::on_event(const app_mngr::event_engine::Event& event) { + LOG4CXX_AUTO_TRACE(logger_); + const std::string module_type = + (*message_)[app_mngr::strings::msg_params][message_params::kModuleType].asString(); + + SetResourceState(module_type, ResourceState::FREE); + + if (event.id() == hmi_apis::FunctionID::RC_GetInteriorVehicleDataConsent) { + ProcessAccessResponse(event); + } +} + +void RCCommandRequest::ProcessAccessResponse( + const app_mngr::event_engine::Event& event) { + LOG4CXX_AUTO_TRACE(logger_); + app_mngr::ApplicationSharedPtr app = + application_manager_.application(CommandRequestImpl::connection_key()); + const std::string module_type = + (*message_)[app_mngr::strings::msg_params][message_params::kModuleType].asString(); + if (!app) { + LOG4CXX_ERROR(logger_, "NULL pointer."); + SendResponse(false, mobile_apis::Result::APPLICATION_NOT_REGISTERED, ""); + return; + } + + const smart_objects::SmartObject& message = event.smart_object(); + + mobile_apis::Result::eType result_code = + GetMobileResultCode(static_cast<hmi_apis::Common_Result::eType>( + message[app_mngr::strings::params][app_mngr::hmi_response::code] + .asUInt())); + + const bool result = + helpers::Compare<mobile_apis::Result::eType, helpers::EQ, helpers::ONE>( + result_code, + mobile_apis::Result::SUCCESS, + mobile_apis::Result::WARNINGS); + + bool is_allowed = false; + if (result) { + if (message[app_mngr::strings::msg_params].keyExists(message_params::kAllowed)) { + is_allowed = + message[app_mngr::strings::msg_params][message_params::kAllowed].asBool(); + } + if (is_allowed) { + resource_allocation_manager_.ForceAcquireResource(module_type, + app->app_id()); + Execute(); // run child's logic + } else { + resource_allocation_manager_.OnDriverDisallowed(module_type, + app->app_id()); + SendResponse( + false, + mobile_apis::Result::REJECTED, + "The resource is in use and the driver disallows this remote " + "control RPC"); + } + } else { + std::string response_info; + GetInfo(message, response_info); + SendResponse(false, result_code, response_info.c_str()); + } +} + +void RCCommandRequest::SendGetUserConsent(const std::string& module_type) { + LOG4CXX_AUTO_TRACE(logger_); + app_mngr::ApplicationSharedPtr app = + application_manager_.application(CommandRequestImpl::connection_key()); + DCHECK(app); + smart_objects::SmartObject msg_params = + smart_objects::SmartObject(smart_objects::SmartType_Map); + msg_params[json_keys::kAppId] = app->hmi_app_id(); + msg_params[app_mngr::strings::msg_params][message_params::kModuleType] = module_type; + SendHMIRequest(hmi_apis::FunctionID::RC_GetInteriorVehicleDataConsent, + &msg_params, + true); +} +} +} diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_command_factory.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_command_factory.cc index e15edc8e42..57294b91a9 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_command_factory.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_command_factory.cc @@ -53,7 +53,7 @@ #include "interfaces/MOBILE_API.h" #include "interfaces/HMI_API.h" -CREATE_LOGGERPTR_GLOBAL(logger_, "RCCommandFactory") +CREATE_LOGGERPTR_GLOBAL(logger_, "RemoteControlModule") namespace rc_rpc_plugin { using namespace application_manager; @@ -62,11 +62,13 @@ RCCommandFactory::RCCommandFactory( app_mngr::ApplicationManager& app_manager, app_mngr::rpc_service::RPCService& rpc_service, app_mngr::HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handler) + policy::PolicyHandlerInterface& policy_handler, + ResourceAllocationManager& allocation_manager) : app_manager_(app_manager) , rpc_service_(rpc_service) , hmi_capabilities_(hmi_capabilities) - , policy_handler_(policy_handler) {} + , policy_handler_(policy_handler) + , allocation_manager_(allocation_manager) {} CommandSharedPtr RCCommandFactory::CreateCommand( const app_mngr::commands::MessageSharedPtr& message, @@ -84,14 +86,13 @@ CommandSharedPtr RCCommandFactory::CreateMobileCommand( CommandSharedPtr command; const int function_id = (*message)[strings::params][strings::function_id].asInt(); - LOG4CXX_DEBUG( - logger_, - "CreateMobileCommand function_id: " << function_id); + LOG4CXX_DEBUG(logger_, "CreateMobileCommand function_id: " << function_id); switch (function_id) { case mobile_apis::FunctionID::ButtonPressID: { if ((*message)[strings::params][strings::message_type] == static_cast<int>(application_manager::MessageType::kRequest)) { - command.reset(new commands::ButtonPressRequest(message, app_manager_)); + command.reset(new commands::ButtonPressRequest( + message, app_manager_, allocation_manager_)); } else { command.reset(new commands::ButtonPressResponse(message, app_manager_)); } @@ -132,57 +133,57 @@ CommandSharedPtr RCCommandFactory::CreateMobileCommand( CommandSharedPtr RCCommandFactory::CreateHMICommand( const app_mngr::commands::MessageSharedPtr& message, app_mngr::commands::Command::CommandSource source) { - CommandSharedPtr command; - const int function_id = - (*message)[strings::params][strings::function_id].asInt(); - LOG4CXX_DEBUG( - logger_, - "CreateHMICommand function_id: " << function_id); - switch (function_id) { - case hmi_apis::FunctionID::Buttons_ButtonPress: { - if ((*message)[strings::params][strings::message_type] == - static_cast<int>(application_manager::MessageType::kRequest)) { - command.reset(new commands::RCButtonPressRequest(message, app_manager_)); - } else { - command.reset(new commands::RCButtonPressResponse(message, app_manager_)); - } - break; - } - case hmi_apis::FunctionID::RC_GetInteriorVehicleData: { - if ((*message)[strings::params][strings::message_type] == - static_cast<int>(application_manager::MessageType::kRequest)) { - command.reset( - new commands::RCGetInteriorVehicleDataRequest(message, app_manager_)); - } else { - command.reset(new commands::RCGetInteriorVehicleDataResponse( - message, app_manager_)); - } - break; - } - case hmi_apis::FunctionID::RC_SetInteriorVehicleData: { - if ((*message)[strings::params][strings::message_type] == - static_cast<int>(application_manager::MessageType::kRequest)) { - command.reset( - new commands::RCSetInteriorVehicleDataRequest(message, app_manager_)); - } else { - command.reset(new commands::RCSetInteriorVehicleDataResponse( - message, app_manager_)); - } - break; + CommandSharedPtr command; + const int function_id = + (*message)[strings::params][strings::function_id].asInt(); + LOG4CXX_DEBUG(logger_, "CreateHMICommand function_id: " << function_id); + switch (function_id) { + case hmi_apis::FunctionID::Buttons_ButtonPress: { + if ((*message)[strings::params][strings::message_type] == + static_cast<int>(application_manager::MessageType::kRequest)) { + command.reset( + new commands::RCButtonPressRequest(message, app_manager_)); + } else { + command.reset( + new commands::RCButtonPressResponse(message, app_manager_)); } - case hmi_apis::FunctionID::RC_OnInteriorVehicleData: { - command.reset(new commands::RCOnInteriorVehicleDataNotification( + break; + } + case hmi_apis::FunctionID::RC_GetInteriorVehicleData: { + if ((*message)[strings::params][strings::message_type] == + static_cast<int>(application_manager::MessageType::kRequest)) { + command.reset(new commands::RCGetInteriorVehicleDataRequest( + message, app_manager_)); + } else { + command.reset(new commands::RCGetInteriorVehicleDataResponse( message, app_manager_)); - break; } - case hmi_apis::FunctionID::RC_OnRemoteControlSettings: { - command.reset(new commands::RCOnRemoteControlSettingsNotification( + break; + } + case hmi_apis::FunctionID::RC_SetInteriorVehicleData: { + if ((*message)[strings::params][strings::message_type] == + static_cast<int>(application_manager::MessageType::kRequest)) { + command.reset(new commands::RCSetInteriorVehicleDataRequest( + message, app_manager_)); + } else { + command.reset(new commands::RCSetInteriorVehicleDataResponse( message, app_manager_)); - break; } - default: { break; } + break; + } + case hmi_apis::FunctionID::RC_OnInteriorVehicleData: { + command.reset(new commands::RCOnInteriorVehicleDataNotification( + message, app_manager_)); + break; + } + case hmi_apis::FunctionID::RC_OnRemoteControlSettings: { + command.reset(new commands::RCOnRemoteControlSettingsNotification( + message, app_manager_)); + break; } - return command; + default: { break; } } + return command; +} } // namespace application_manager diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_rpc_plugin.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_rpc_plugin.cc index ef0ee9476f..a5d2e9b73d 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_rpc_plugin.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_rpc_plugin.cc @@ -13,6 +13,12 @@ bool RCRPCPlugin::Init( policy::PolicyHandlerInterface& policy_handler) { resource_allocation_manager_.reset( new ResourceAllocationManagerImpl(app_manager)); + command_factory_.reset( + new rc_rpc_plugin::RCCommandFactory(app_manager, + rpc_service, + hmi_capabilities, + policy_handler, + *resource_allocation_manager_)); return true; } @@ -48,3 +54,7 @@ void RCRPCPlugin::OnApplicationEvent( } } // namespace rc_rpc_plugin + +extern "C" application_manager::plugin_manager::RPCPlugin* Create() { + return new rc_rpc_plugin::RCRPCPlugin(); +} |