diff options
author | Artem Nosach (GitHub) <ANosach@luxoft.com> | 2016-10-04 17:59:37 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-04 17:59:37 +0300 |
commit | 0b802679f3cc947debfa6ff00f1aac0701176291 (patch) | |
tree | 5987892cca290ffe4b1e7a0556d4b140db9c99f7 | |
parent | 85c71b25bde1eaca791e94ee3f16bb37d389efce (diff) | |
parent | 333644a3993bede76609a306757d689164bd24b2 (diff) | |
download | sdl_core-0b802679f3cc947debfa6ff00f1aac0701176291.tar.gz |
Merge pull request #858 from dtrunov/feature/UI_interface_SDL_behavior_in_case_HMI_does_not_respond_to_IsReady_request_or_respond_with_available_false
UI interface: SDL behavior in case HMI does not respond to IsReady request or respond with "available" = false
55 files changed, 1784 insertions, 1300 deletions
diff --git a/src/components/application_manager/include/application_manager/commands/command_request_impl.h b/src/components/application_manager/include/application_manager/commands/command_request_impl.h index 8a00764ca3..30859765ba 100644 --- a/src/components/application_manager/include/application_manager/commands/command_request_impl.h +++ b/src/components/application_manager/include/application_manager/commands/command_request_impl.h @@ -47,8 +47,54 @@ class SmartObject; namespace application_manager { namespace commands { +struct ResponseInfo { + ResponseInfo() + : result_code(hmi_apis::Common_Result::INVALID_ENUM) + , interface(HmiInterfaces::HMI_INTERFACE_INVALID_ENUM) + , interface_state(HmiInterfaces::STATE_NOT_RESPONSE) + , is_ok(false) + , is_unsupported_resource(false) + , is_invalid_enum(false) {} + ResponseInfo(hmi_apis::Common_Result::eType result, + HmiInterfaces::InterfaceID interface) + : result_code(result) + , interface(interface) + , interface_state(HmiInterfaces::STATE_NOT_RESPONSE) + , is_ok(false) + , is_unsupported_resource(false) + , is_invalid_enum(false) {} + hmi_apis::Common_Result::eType result_code; + HmiInterfaces::InterfaceID interface; + HmiInterfaces::InterfaceState interface_state; + bool is_ok; + bool is_unsupported_resource; + bool is_invalid_enum; +}; + namespace NsSmart = NsSmartDeviceLink::NsSmartObjects; +/** + * @brief MergeInfos merge 2 infos in one string + * @param first - info string that should be first in result info + * @param second - info string that should be second in result info + * @return if first is empty return second + * if second is empty return first + * if both are empty return empty string + * if both are not empty return empty first +", " + second + */ +std::string MergeInfos(const std::string& first, const std::string& second); + +/** + * @brief MergeInfos merge 3 infos in one string + * @param first - info string that should be first in result info + * @param second - info string that should be second in result info + * @param third - info string that should be second in result info + * @return resulting string contain merge all incoming parameters + */ +std::string MergeInfos(const std::string& first, + const std::string& second, + const std::string& third); + class CommandRequestImpl : public CommandImpl, public event_engine::EventObserver { public: @@ -153,6 +199,55 @@ class CommandRequestImpl : public CommandImpl, */ bool HasDisallowedParams() const; + /** + * @brief Checks result code from HMI for single RPC + * and returns parameter for sending to mobile app. + * @param result_code contains result code from HMI response + * @param interface contains interface for which HMI sent response + * @return true if result code complies successful result cods + * otherwise returns false. + */ + bool PrepareResultForMobileResponse( + hmi_apis::Common_Result::eType result_code, + HmiInterfaces::InterfaceID interface) const; + + /** + * @brief Checks result code from HMI for splitted RPC + * and returns parameter for sending to mobile app. + * @param first contains result_code from HMI response and + * interface that returns response + * @param second contains result_code from HMI response and + * interface that returns response + * @return true if result code complies successful result code + * otherwise returns false + */ + bool PrepareResultForMobileResponse(ResponseInfo& out_first, + ResponseInfo& out_second) const; + /** + * @brief If message from HMI contains returns this info + * or process result code from HMI and checks state of interface + * and create info. + * @param interface contains interface for which HMI sent response + * @param result_code contains result code from HMI + * @param response_from_hmi contains response from HMI + * @param out_info contain info for sending to application + */ + void GetInfo(HmiInterfaces::InterfaceID interface, + hmi_apis::Common_Result::eType result_code, + const smart_objects::SmartObject& response_from_hmi, + std::string& out_info); + + /** + * @brief Prepare result code for sending to mobile application + * @param first contains result_code from HMI response and + * interface that returns response + * @param second contains result_code from HMI response and + * interface that returns response. + * @return resulting code for sending to mobile application. + */ + mobile_apis::Result::eType PrepareResultCodeForResponse( + const ResponseInfo& first, const ResponseInfo& second); + protected: /** * @brief Returns policy parameters permissions diff --git a/src/components/application_manager/include/application_manager/commands/hmi/request_to_hmi.h b/src/components/application_manager/include/application_manager/commands/hmi/request_to_hmi.h index e512279e79..9ebb5761c1 100644 --- a/src/components/application_manager/include/application_manager/commands/hmi/request_to_hmi.h +++ b/src/components/application_manager/include/application_manager/commands/hmi/request_to_hmi.h @@ -40,6 +40,26 @@ namespace application_manager { namespace commands { +/** + * @brief Check if HMI's interface is available. + * @param application_manager contains application manager component + * @param interface contains name of HMI's interface + * @return true if interface is available otherwise return fasle. + */ +bool CheckAvailabilityHMIInterfaces(ApplicationManager& application_manager, + HmiInterfaces::InterfaceID interface); +/** + * @brief Change interface state + * @param application_manager contains ApplicationManager instance + * @param response_from_hmi contains response from HMI + * @param interface contanins InterfaceID whose state is changed. + * @return true if field available exist and contains true in response params + * otherwise return false. + */ +bool ChangeInterfaceState(ApplicationManager& application_manager, + const smart_objects::SmartObject& response_from_hmi, + HmiInterfaces::InterfaceID interface); + class RequestToHMI : public CommandImpl { public: RequestToHMI(const MessageSharedPtr& message, diff --git a/src/components/application_manager/include/application_manager/commands/hmi/tts_is_ready_request.h b/src/components/application_manager/include/application_manager/commands/hmi/tts_is_ready_request.h index 81bd8eb27b..b0acec73b2 100644 --- a/src/components/application_manager/include/application_manager/commands/hmi/tts_is_ready_request.h +++ b/src/components/application_manager/include/application_manager/commands/hmi/tts_is_ready_request.h @@ -42,7 +42,8 @@ namespace commands { /** * @brief TTSIsReadyRequest command class **/ -class TTSIsReadyRequest : public RequestToHMI { +class TTSIsReadyRequest : public RequestToHMI, + public event_engine::EventObserver { public: /** * @brief TTSIsReadyRequest class constructor @@ -55,12 +56,27 @@ class TTSIsReadyRequest : public RequestToHMI { /** * @brief TTSIsReadyRequest class destructor **/ - virtual ~TTSIsReadyRequest(); + ~TTSIsReadyRequest() OVERRIDE; /** * @brief Execute command **/ - virtual void Run(); + void Run() OVERRIDE; + + /** + * @brief On event callback + **/ + void on_event(const event_engine::Event& event) OVERRIDE; + + /** + * @brief onTimeOut from requrst Controller + */ + void onTimeOut() OVERRIDE; + + /** + * @brief Send request to HMI for fetching of cappabilities + */ + void SendMessageToHMI(); private: DISALLOW_COPY_AND_ASSIGN(TTSIsReadyRequest); diff --git a/src/components/application_manager/include/application_manager/commands/hmi/ui_is_ready_request.h b/src/components/application_manager/include/application_manager/commands/hmi/ui_is_ready_request.h index a505df6de4..33da7a67b7 100644 --- a/src/components/application_manager/include/application_manager/commands/hmi/ui_is_ready_request.h +++ b/src/components/application_manager/include/application_manager/commands/hmi/ui_is_ready_request.h @@ -42,7 +42,8 @@ namespace commands { /** * @brief UIIsReadyRequest command class **/ -class UIIsReadyRequest : public RequestToHMI { +class UIIsReadyRequest : public RequestToHMI, + public event_engine::EventObserver { public: /** * @brief UIIsReadyRequest class constructor @@ -55,12 +56,27 @@ class UIIsReadyRequest : public RequestToHMI { /** * @brief UIIsReadyRequest class destructor **/ - virtual ~UIIsReadyRequest(); + ~UIIsReadyRequest() OVERRIDE; /** * @brief Execute command **/ - virtual void Run(); + void Run() OVERRIDE; + + /** + * @brief On event callback + **/ + void on_event(const event_engine::Event& event) OVERRIDE; + + /** + * @brief onTimeOut from requrst Controller + */ + virtual void onTimeOut() OVERRIDE; + + /** + * @brief Send request to HMI for fetching of cappabilities + */ + void SendMessageToHMI(); private: DISALLOW_COPY_AND_ASSIGN(UIIsReadyRequest); diff --git a/src/components/application_manager/include/application_manager/commands/hmi/vi_is_ready_request.h b/src/components/application_manager/include/application_manager/commands/hmi/vi_is_ready_request.h index 9049db4d24..a81a8c8b7c 100644 --- a/src/components/application_manager/include/application_manager/commands/hmi/vi_is_ready_request.h +++ b/src/components/application_manager/include/application_manager/commands/hmi/vi_is_ready_request.h @@ -42,7 +42,8 @@ namespace commands { /** * @brief VIIsReadyRequest command class **/ -class VIIsReadyRequest : public RequestToHMI { +class VIIsReadyRequest : public RequestToHMI, + public event_engine::EventObserver { public: /** * @brief VIIsReadyRequest class constructor @@ -55,12 +56,27 @@ class VIIsReadyRequest : public RequestToHMI { /** * @brief VIIsReadyRequest class destructor **/ - virtual ~VIIsReadyRequest(); + ~VIIsReadyRequest() OVERRIDE; /** * @brief Execute command **/ - virtual void Run(); + void Run() OVERRIDE; + + /** + * @brief On event callback + **/ + void on_event(const event_engine::Event& event) OVERRIDE; + + /** + * @brief onTimeOut from requrst Controller + */ + void onTimeOut() OVERRIDE; + + /** + * @brief Send request to HMI for fetching of cappabilities + */ + void SendMessageToHMI(); private: DISALLOW_COPY_AND_ASSIGN(VIIsReadyRequest); diff --git a/src/components/application_manager/include/application_manager/commands/hmi/vr_is_ready_request.h b/src/components/application_manager/include/application_manager/commands/hmi/vr_is_ready_request.h index 9fc4ccd2f3..784a6e4a48 100644 --- a/src/components/application_manager/include/application_manager/commands/hmi/vr_is_ready_request.h +++ b/src/components/application_manager/include/application_manager/commands/hmi/vr_is_ready_request.h @@ -34,6 +34,7 @@ #define SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_COMMANDS_HMI_VR_IS_READY_REQUEST_H_ #include "application_manager/commands/hmi/request_to_hmi.h" +#include "application_manager/message_helper.h" namespace application_manager { @@ -42,7 +43,8 @@ namespace commands { /** * @brief VRIsReadyRequest command class **/ -class VRIsReadyRequest : public RequestToHMI { +class VRIsReadyRequest : public RequestToHMI, + public event_engine::EventObserver { public: /** * @brief VRIsReadyRequest class constructor @@ -62,6 +64,21 @@ class VRIsReadyRequest : public RequestToHMI { **/ virtual void Run(); + /** + * @brief On event callback + **/ + virtual void on_event(const event_engine::Event& event); + + /** + * @brief onTimeOut from requrst Controller + */ + virtual void onTimeOut(); + + /** + * @brief Send request to HMI for fetching of cappabilities + */ + void SendMessageToHMI(); + private: DISALLOW_COPY_AND_ASSIGN(VRIsReadyRequest); }; diff --git a/src/components/application_manager/include/application_manager/commands/mobile/alert_request.h b/src/components/application_manager/include/application_manager/commands/mobile/alert_request.h index bc99665d82..84241f8f80 100644 --- a/src/components/application_manager/include/application_manager/commands/mobile/alert_request.h +++ b/src/components/application_manager/include/application_manager/commands/mobile/alert_request.h @@ -34,6 +34,8 @@ #ifndef SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_COMMANDS_ALERT_REQUEST_H_ #define SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_COMMANDS_ALERT_REQUEST_H_ +#include <string> + #include "application_manager/commands/command_request_impl.h" #include "interfaces/MOBILE_API.h" #include "utils/macro.h" @@ -126,14 +128,25 @@ class AlertRequest : public CommandRequestImpl { */ bool CheckStringsOfAlertRequest(); + /* + * @brief Prepare result code and result for sending to mobile application + * @param result_code contains result code for sending to mobile application + * @param info contains info for mobile app. + * @return result for sending to mobile application. + */ + bool PrepareResponseParameters(mobile_apis::Result::eType& result_code, + std::string& info); + bool awaiting_ui_alert_response_; bool awaiting_tts_speak_response_; bool awaiting_tts_stop_speaking_response_; bool is_alert_succeeded_; bool is_ui_alert_sent_; - mobile_apis::Result::eType alert_result_; + hmi_apis::Common_Result::eType alert_result_; smart_objects::SmartObject alert_response_params_; - mobile_apis::Result::eType tts_speak_result_; + hmi_apis::Common_Result::eType tts_speak_result_; + std::string ui_response_info_; + std::string tts_response_info_; DISALLOW_COPY_AND_ASSIGN(AlertRequest); }; diff --git a/src/components/application_manager/include/application_manager/commands/mobile/change_registration_request.h b/src/components/application_manager/include/application_manager/commands/mobile/change_registration_request.h index c81ed0b5d3..f783af12b3 100644 --- a/src/components/application_manager/include/application_manager/commands/mobile/change_registration_request.h +++ b/src/components/application_manager/include/application_manager/commands/mobile/change_registration_request.h @@ -106,15 +106,6 @@ class ChangeRegistrationRequest : public CommandRequestImpl { */ bool IsPendingResponseExist(); - /* - * @brief Checks result codes - * - * @return true if all of result codes is success - */ - bool AllHmiResponsesSuccess(const hmi_apis::Common_Result::eType ui, - const hmi_apis::Common_Result::eType vr, - const hmi_apis::Common_Result::eType tts); - /** * @brief Checks change_registration params(ttsName, appname, * ngnMediaScreenAppName, vrSynonyms) on invalid characters. @@ -141,11 +132,20 @@ class ChangeRegistrationRequest : public CommandRequestImpl { bool IsNicknameAllowed(const custom_str::CustomString& app_name) const; /** - * @brief Predicate for using with CheckCoincidence method to compare with VR - * synonym SO - * - * @return TRUE if there is coincidence of VR, otherwise FALSE + * @brief Prepare result code and result for sending to mobile application + * @param result_code contains result code for sending to mobile application + * @param response_info contains info for sending to mobile application + * @return result for sending to mobile application. */ + bool PrepareResponseParameters(mobile_apis::Result::eType& result_code, + std::string& ResponseInfo); + + /** + * @brief Predicate for using with CheckCoincidence method to compare with VR + * synonym SO + * + * @return TRUE if there is coincidence of VR, otherwise FALSE + */ struct CoincidencePredicateVR { CoincidencePredicateVR(const custom_str::CustomString& newItem) : newItem_(newItem){}; @@ -163,6 +163,9 @@ class ChangeRegistrationRequest : public CommandRequestImpl { hmi_apis::Common_Result::eType ui_result_; hmi_apis::Common_Result::eType vr_result_; hmi_apis::Common_Result::eType tts_result_; + std::string ui_response_info_; + std::string vr_response_info_; + std::string tts_response_info_; DISALLOW_COPY_AND_ASSIGN(ChangeRegistrationRequest); }; diff --git a/src/components/application_manager/include/application_manager/commands/mobile/delete_command_request.h b/src/components/application_manager/include/application_manager/commands/mobile/delete_command_request.h index 70fd8f3742..4e392f3857 100644 --- a/src/components/application_manager/include/application_manager/commands/mobile/delete_command_request.h +++ b/src/components/application_manager/include/application_manager/commands/mobile/delete_command_request.h @@ -82,12 +82,14 @@ class DeleteCommandRequest : public CommandRequestImpl { */ bool IsPendingResponseExist(); - /** - * @brief CalculateResult calculate mobile result from received ui and vr - * results - * @return calculated mobile result - */ - bool CalculateResult(); + /* + * @brief Prepare result code and result for sending to mobile application + * @param result_code contains result code for sending to mobile application + * @param info contains info for mobile app. + * @return result for sending to mobile application. + */ + bool PrepareResponseParameters(mobile_apis::Result::eType& result_code, + std::string& info); bool is_ui_send_; bool is_vr_send_; @@ -97,7 +99,8 @@ class DeleteCommandRequest : public CommandRequestImpl { hmi_apis::Common_Result::eType ui_result_; hmi_apis::Common_Result::eType vr_result_; - std::string info_; + std::string ui_info_; + std::string vr_info_; }; } // namespace commands diff --git a/src/components/application_manager/include/application_manager/commands/mobile/perform_audio_pass_thru_request.h b/src/components/application_manager/include/application_manager/commands/mobile/perform_audio_pass_thru_request.h index b69cb969e1..aff7430c6a 100644 --- a/src/components/application_manager/include/application_manager/commands/mobile/perform_audio_pass_thru_request.h +++ b/src/components/application_manager/include/application_manager/commands/mobile/perform_audio_pass_thru_request.h @@ -85,23 +85,31 @@ class PerformAudioPassThruRequest : public CommandRequestImpl { void on_event(const event_engine::Event& event); private: - /* + /** + * @brief Prepare result code, result and info for sending to mobile + * application + * @param result_code contains result code for sending to mobile application + * @return result for sending to mobile application. + */ + bool PrepareResponseParameters(mobile_apis::Result::eType& result_code, + std::string& info); + /** * @brief Sends TTS Speak request */ void SendSpeakRequest(); - /* + /** * @brief Sends UI PerformAudioPassThru request */ void SendPerformAudioPassThruRequest(); - /* + /** * @brief Sends UI RecordStart notification after TTS Speak response received. * Indicates that capturing mic data should be started */ void SendRecordStartNotification(); - /* + /** * @brief Starts microphone recording */ void StartMicrophoneRecording(); @@ -115,21 +123,25 @@ class PerformAudioPassThruRequest : public CommandRequestImpl { bool IsWhiteSpaceExist(); /** - * @brief Waiting for TTS.Speak response, after default timeout send - * GENERIC_ERROR response - * @return if receive TTS.Speak return TRUE, FALSE otherwise - */ - bool WaitTTSSpeak(); - - /** * @brief If is_active_tts_speak_ TRUE - set up to FALSE and send request * TTS_StopSpeaking to HMI */ void FinishTTSSpeak(); - // flag display state of speak during perform audio pass thru - bool is_active_tts_speak_; - mobile_apis::Result::eType result_tts_speak_; + /* + * @brief Tells if there are sent requests without responses + */ + bool IsWaitingHMIResponse(); + + /* flag display state of speak and ui perform audio + during perform audio pass thru*/ + bool awaiting_tts_speak_response_; + bool awaiting_ui_response_; + + hmi_apis::Common_Result::eType result_tts_speak_; + hmi_apis::Common_Result::eType result_ui_; + std::string ui_info_; + std::string tts_info_; DISALLOW_COPY_AND_ASSIGN(PerformAudioPassThruRequest); }; diff --git a/src/components/application_manager/include/application_manager/commands/mobile/perform_interaction_request.h b/src/components/application_manager/include/application_manager/commands/mobile/perform_interaction_request.h index 70d51444de..4cf40959b4 100644 --- a/src/components/application_manager/include/application_manager/commands/mobile/perform_interaction_request.h +++ b/src/components/application_manager/include/application_manager/commands/mobile/perform_interaction_request.h @@ -33,6 +33,7 @@ #ifndef SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_COMMANDS_PERFORM_INTERACTION_REQUEST_H_ #define SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_COMMANDS_PERFORM_INTERACTION_REQUEST_H_ +#include <string> #include "application_manager/commands/command_request_impl.h" #include "application_manager/application.h" @@ -87,25 +88,24 @@ class PerformInteractionRequest : public CommandRequestImpl { virtual void onTimeOut(); private: - /* + /** * @brief Function will be called when VR_OnCommand event * comes - * * @param message which should send to mobile side - * + * @return true if send response to mobile application otherwise + * return false. */ - void ProcessVRResponse(const smart_objects::SmartObject& message, + bool ProcessVRResponse(const smart_objects::SmartObject& message, smart_objects::SmartObject& msg_params); - /* + /** * @brief Sends PerformInteraction response to mobile side - * * @param message which should send to mobile side - * + * @return true if send response to mobile application otherwise + * return false. */ - void ProcessPerformInteractionResponse( - const smart_objects::SmartObject& message, - smart_objects::SmartObject& msg_params); + bool ProcessUIResponse(const smart_objects::SmartObject& message, + smart_objects::SmartObject& msg_params); /* * @brief Sends UI PerformInteraction request to HMI @@ -218,12 +218,6 @@ class PerformInteractionRequest : public CommandRequestImpl { const bool HasHMIResponsesToWait() const; /** - * @brief Check VR response result code, in case GENERIC_ERROR, REJECTED, - * send resultCode FALSE, in case WARNINGS send resultCode TRUE - */ - void CheckResponseResultCode(); - - /** * @brief Check UI & VR result codes, send response to mobile * @param msg_param Message params to send */ @@ -232,12 +226,12 @@ class PerformInteractionRequest : public CommandRequestImpl { mobile_apis::InteractionMode::eType interaction_mode_; bool ui_response_recived_; bool vr_response_recived_; - bool ui_result_; - bool vr_result_; bool app_pi_was_active_before_; static uint32_t pi_requests_count_; - mobile_apis::Result::eType vr_resultCode_; - mobile_apis::Result::eType ui_resultCode_; + hmi_apis::Common_Result::eType vr_result_code_; + hmi_apis::Common_Result::eType ui_result_code_; + std::string ui_info_; + std::string vr_info_; DISALLOW_COPY_AND_ASSIGN(PerformInteractionRequest); }; diff --git a/src/components/application_manager/include/application_manager/commands/mobile/register_app_interface_request.h b/src/components/application_manager/include/application_manager/commands/mobile/register_app_interface_request.h index 507f8f9bed..12a89793a2 100644 --- a/src/components/application_manager/include/application_manager/commands/mobile/register_app_interface_request.h +++ b/src/components/application_manager/include/application_manager/commands/mobile/register_app_interface_request.h @@ -97,11 +97,11 @@ class RegisterAppInterfaceRequest : public CommandRequestImpl { const uint32_t app_id); /** - * @brief SendChangeRagistrationOnHMI send required SendChangeRagistration + * @brief SendChangeRegistrationOnHMI send required SendChangeRegistration * HMI * @param app application to change registration */ - void SendChangeRagistrationOnHMI(ApplicationConstSharedPtr app); + void SendChangeRegistrationOnHMI(ApplicationConstSharedPtr app); /** * @brief Sends OnAppRegistered notification to HMI diff --git a/src/components/application_manager/include/application_manager/commands/mobile/set_global_properties_request.h b/src/components/application_manager/include/application_manager/commands/mobile/set_global_properties_request.h index aa26a70393..0300245af8 100644 --- a/src/components/application_manager/include/application_manager/commands/mobile/set_global_properties_request.h +++ b/src/components/application_manager/include/application_manager/commands/mobile/set_global_properties_request.h @@ -32,7 +32,7 @@ #ifndef SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_COMMANDS_MOBILE_SET_GLOBAL_PROPERTIES_REQUEST_H_ #define SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_COMMANDS_MOBILE_SET_GLOBAL_PROPERTIES_REQUEST_H_ - +#include <string> #include "application_manager/commands/command_request_impl.h" #include "utils/macro.h" #include "application_manager/application.h" @@ -125,6 +125,15 @@ class SetGlobalPropertiesRequest : public CommandRequestImpl { */ bool IsWhiteSpaceExist(); + /* + * @brief Prepare result code and result for sending to mobile application + * @param result_code contains result code for sending to mobile application + * @param info contains info for sending to mobile applicaion + * @return result for sending to mobile application. + */ + bool PrepareResponseParameters(mobile_apis::Result::eType& result_code, + std::string& info); + bool is_ui_send_; bool is_tts_send_; @@ -133,6 +142,8 @@ class SetGlobalPropertiesRequest : public CommandRequestImpl { hmi_apis::Common_Result::eType ui_result_; hmi_apis::Common_Result::eType tts_result_; + std::string ui_response_info_; + std::string tts_response_info_; DISALLOW_COPY_AND_ASSIGN(SetGlobalPropertiesRequest); }; diff --git a/src/components/application_manager/include/application_manager/hmi_capabilities_impl.h b/src/components/application_manager/include/application_manager/hmi_capabilities_impl.h index 6724f4fdd5..ec7bbcebbd 100644 --- a/src/components/application_manager/include/application_manager/hmi_capabilities_impl.h +++ b/src/components/application_manager/include/application_manager/hmi_capabilities_impl.h @@ -70,13 +70,6 @@ class HMICapabilitiesImpl : public HMICapabilities { */ virtual ~HMICapabilitiesImpl(); - /** - * @brief Checks if all HMI capabilities received - * - * @return TRUE if all information received, otherwise FALSE - */ - bool is_hmi_capabilities_initialized() const OVERRIDE; - /* * @brief Checks is image type(Static/Dynamic) requested by * Mobile Device is supported on current HMI. @@ -430,6 +423,13 @@ class HMICapabilitiesImpl : public HMICapabilities { */ HMILanguageHandler& get_hmi_language_handler() OVERRIDE; + /** + * @brief Trigger waiting for response + * @param request Request object + */ + void set_handle_response_for( + const smart_objects::SmartObject& request) OVERRIDE; + protected: /* * @brief Loads capabilities from local file in case SDL was launched @@ -470,13 +470,6 @@ class HMICapabilitiesImpl : public HMICapabilities { bool is_navi_cooperating_; bool is_ivi_cooperating_; - // to check if IsReady response for corresponding interface received - bool is_vr_ready_response_recieved_; - bool is_tts_ready_response_recieved_; - bool is_ui_ready_response_recieved_; - bool is_navi_ready_response_recieved_; - bool is_ivi_ready_response_recieved_; - bool attenuated_supported_; hmi_apis::Common_Language::eType ui_language_; hmi_apis::Common_Language::eType vr_language_; diff --git a/src/components/application_manager/include/application_manager/hmi_interfaces.h b/src/components/application_manager/include/application_manager/hmi_interfaces.h index c2bfba5747..1c6559db37 100644 --- a/src/components/application_manager/include/application_manager/hmi_interfaces.h +++ b/src/components/application_manager/include/application_manager/hmi_interfaces.h @@ -28,7 +28,12 @@ * 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. + */ +/** + * @brief The class contains information about state HMI's interfaces + * (Buttons, BasicCommunication, VR, TTS, UI, Navigation,VehicleInfo, + * SDL) and provides this information through public interfaces. */ #ifndef SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_HMI_INTERFACES_H_ #define SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_HMI_INTERFACES_H_ diff --git a/src/components/application_manager/src/commands/command_request_impl.cc b/src/components/application_manager/src/commands/command_request_impl.cc index 303cdadef5..609180197c 100644 --- a/src/components/application_manager/src/commands/command_request_impl.cc +++ b/src/components/application_manager/src/commands/command_request_impl.cc @@ -37,10 +37,69 @@ #include "application_manager/application_manager.h" #include "application_manager/message_helper.h" #include "smart_objects/smart_object.h" + namespace application_manager { namespace commands { +std::string MergeInfos(const std::string& first, const std::string& second) { + return first + ((!first.empty() && !second.empty()) ? ", " : "") + second; +} + +std::string MergeInfos(const std::string& first, + const std::string& second, + const std::string& third) { + std::string result = MergeInfos(first, second); + return MergeInfos(result, third); +} + +const std::string CreateInfoForUnsupportedResult( + HmiInterfaces::InterfaceID interface) { + switch (interface) { + case (HmiInterfaces::InterfaceID::HMI_INTERFACE_VR): { + return "VR is not supported by system"; + } + case (HmiInterfaces::InterfaceID::HMI_INTERFACE_TTS): { + return "TTS is not supported by system"; + } + case (HmiInterfaces::InterfaceID::HMI_INTERFACE_UI): { + return "UI is not supported by system"; + } + case (HmiInterfaces::InterfaceID::HMI_INTERFACE_Navigation): { + return "Navi is not supported by system"; + } + default: +#ifdef ENABLE_LOG + CREATE_LOGGERPTR_LOCAL(logger, "Commands"); + LOG4CXX_WARN(logger, + "Could not create info because" + " interface isn't valid. Interface is:" + << static_cast<int32_t>(interface)); +#endif // ENABLE_LOG + return ""; + } +} + +bool CheckResultCode(const ResponseInfo& first, const ResponseInfo& second) { + if (first.is_ok && second.is_unsupported_resource) { + return true; + } + if (first.is_invalid_enum && second.is_unsupported_resource && + HmiInterfaces::STATE_NOT_AVAILABLE != second.interface_state) { + return true; + } + return false; +} + +bool IsResultCodeUnsupported(const ResponseInfo& first, + const ResponseInfo& second) { + return ((first.is_ok || first.is_invalid_enum) && + second.is_unsupported_resource) || + ((second.is_ok || second.is_invalid_enum) && + first.is_unsupported_resource) || + (first.is_unsupported_resource && second.is_unsupported_resource); +} + struct DisallowedParamsInserter { DisallowedParamsInserter(smart_objects::SmartObject& response, mobile_apis::VehicleDataResultCode::eType code) @@ -207,23 +266,7 @@ smart_objects::SmartObject CreateUnsupportedResourceResponse( params[strings::function_id] = function_id; params[hmi_response::code] = hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; smart_objects::SmartObject& msg_params = response[strings::msg_params]; - - switch (interface) { - case HmiInterfaces::HMI_INTERFACE_VR: { - msg_params[strings::info] = "VR is not supported by system"; - break; - } - case HmiInterfaces::HMI_INTERFACE_VehicleInfo: { - msg_params[strings::info] = "VehicleInfo is not supported by system"; - break; - } - case HmiInterfaces::HMI_INTERFACE_UI: { - msg_params[strings::info] = "UI is not supported by system"; - break; - } - default: - break; - } + msg_params[strings::info] = CreateInfoForUnsupportedResult(interface); return response; } @@ -605,6 +648,118 @@ bool CommandRequestImpl::HasDisallowedParams() const { (!removed_parameters_permissions_.undefined_params.empty())); } +bool CommandRequestImpl::PrepareResultForMobileResponse( + hmi_apis::Common_Result::eType result_code, + HmiInterfaces::InterfaceID interface) const { + using namespace helpers; + + if (Compare<hmi_apis::Common_Result::eType, EQ, ONE>( + result_code, + hmi_apis::Common_Result::SUCCESS, + hmi_apis::Common_Result::WARNINGS, + hmi_apis::Common_Result::WRONG_LANGUAGE, + hmi_apis::Common_Result::RETRY, + hmi_apis::Common_Result::SAVED)) { + return true; + } + + const HmiInterfaces::InterfaceState state = + application_manager_.hmi_interfaces().GetInterfaceState(interface); + if ((hmi_apis::Common_Result::UNSUPPORTED_RESOURCE == result_code) && + (HmiInterfaces::STATE_NOT_AVAILABLE != state)) { + return true; + } + return false; +} + +bool CommandRequestImpl::PrepareResultForMobileResponse( + ResponseInfo& out_first, ResponseInfo& out_second) const { + using namespace helpers; + + out_first.is_ok = Compare<hmi_apis::Common_Result::eType, EQ, ONE>( + out_first.result_code, + hmi_apis::Common_Result::SUCCESS, + hmi_apis::Common_Result::WARNINGS, + hmi_apis::Common_Result::WRONG_LANGUAGE, + hmi_apis::Common_Result::RETRY, + hmi_apis::Common_Result::SAVED); + + out_second.is_ok = Compare<hmi_apis::Common_Result::eType, EQ, ONE>( + out_second.result_code, + hmi_apis::Common_Result::SUCCESS, + hmi_apis::Common_Result::WARNINGS, + hmi_apis::Common_Result::WRONG_LANGUAGE, + hmi_apis::Common_Result::RETRY, + hmi_apis::Common_Result::SAVED); + + out_first.is_invalid_enum = + hmi_apis::Common_Result::INVALID_ENUM == out_first.result_code; + + out_second.is_invalid_enum = + hmi_apis::Common_Result::INVALID_ENUM == out_second.result_code; + + out_first.is_unsupported_resource = + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE == out_first.result_code; + + out_second.is_unsupported_resource = + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE == out_second.result_code; + + out_first.interface_state = + application_manager_.hmi_interfaces().GetInterfaceState( + out_first.interface); + out_second.interface_state = + application_manager_.hmi_interfaces().GetInterfaceState( + out_second.interface); + + bool result = (out_first.is_ok && out_second.is_ok) || + (out_second.is_invalid_enum && out_first.is_ok) || + (out_first.is_invalid_enum && out_second.is_ok); + result = result || CheckResultCode(out_first, out_second); + result = result || CheckResultCode(out_second, out_first); + return result; +} + +void CommandRequestImpl::GetInfo( + HmiInterfaces::InterfaceID interface, + hmi_apis::Common_Result::eType result_code, + const smart_objects::SmartObject& response_from_hmi, + std::string& out_info) { + if (response_from_hmi[strings::msg_params].keyExists(strings::info)) { + out_info = response_from_hmi[strings::msg_params][strings::info].asString(); + } else { + HmiInterfaces::InterfaceState interface_state = + application_manager_.hmi_interfaces().GetInterfaceState(interface); + if (hmi_apis::Common_Result::UNSUPPORTED_RESOURCE == result_code && + HmiInterfaces::InterfaceState::STATE_NOT_RESPONSE == interface_state) { + out_info = CreateInfoForUnsupportedResult(interface); + } + } +} + +mobile_apis::Result::eType CommandRequestImpl::PrepareResultCodeForResponse( + const ResponseInfo& first, const ResponseInfo& second) { + mobile_apis::Result::eType result_code = mobile_apis::Result::INVALID_ENUM; + if (IsResultCodeUnsupported(first, second)) { + result_code = mobile_apis::Result::UNSUPPORTED_RESOURCE; + } else { + // If response contains erroneous result code SDL need return erroneus + // result code. + hmi_apis::Common_Result::eType first_result = + hmi_apis::Common_Result::INVALID_ENUM; + hmi_apis::Common_Result::eType second_result = + hmi_apis::Common_Result::INVALID_ENUM; + if (!first.is_unsupported_resource) { + first_result = first.result_code; + } + if (!second.is_unsupported_resource) { + second_result = second.result_code; + } + result_code = + MessageHelper::HMIToMobileResult(std::max(first_result, second_result)); + } + return result_code; +} + const CommandParametersPermissions& CommandRequestImpl::parameters_permissions() const { return parameters_permissions_; diff --git a/src/components/application_manager/src/commands/hmi/close_popup_request.cc b/src/components/application_manager/src/commands/hmi/close_popup_request.cc index b0ab48dd96..d628475438 100644 --- a/src/components/application_manager/src/commands/hmi/close_popup_request.cc +++ b/src/components/application_manager/src/commands/hmi/close_popup_request.cc @@ -44,7 +44,6 @@ ClosePopupRequest::~ClosePopupRequest() {} void ClosePopupRequest::Run() { LOG4CXX_AUTO_TRACE(logger_); - SendRequest(); } diff --git a/src/components/application_manager/src/commands/hmi/request_to_hmi.cc b/src/components/application_manager/src/commands/hmi/request_to_hmi.cc index 2e7d7e9df1..39d549ac72 100644 --- a/src/components/application_manager/src/commands/hmi/request_to_hmi.cc +++ b/src/components/application_manager/src/commands/hmi/request_to_hmi.cc @@ -36,6 +36,29 @@ namespace application_manager { namespace commands { +bool CheckAvailabilityHMIInterfaces(ApplicationManager& application_manager, + HmiInterfaces::InterfaceID interface) { + const HmiInterfaces::InterfaceState state = + application_manager.hmi_interfaces().GetInterfaceState(interface); + return HmiInterfaces::STATE_NOT_AVAILABLE != state; +} + +bool ChangeInterfaceState(ApplicationManager& application_manager, + const smart_objects::SmartObject& response_from_hmi, + HmiInterfaces::InterfaceID interface) { + if (response_from_hmi[strings::msg_params].keyExists(strings::available)) { + const bool is_available = + response_from_hmi[strings::msg_params][strings::available].asBool(); + const HmiInterfaces::InterfaceState interface_state = + is_available ? HmiInterfaces::STATE_AVAILABLE + : HmiInterfaces::STATE_NOT_AVAILABLE; + application_manager.hmi_interfaces().SetInterfaceState(interface, + interface_state); + return is_available; + } + return false; +} + RequestToHMI::RequestToHMI(const MessageSharedPtr& message, ApplicationManager& application_manager) : CommandImpl(message, application_manager) { @@ -58,7 +81,6 @@ void RequestToHMI::Run() {} void RequestToHMI::SendRequest() { (*message_)[strings::params][strings::protocol_type] = hmi_protocol_type_; (*message_)[strings::params][strings::protocol_version] = protocol_version_; - application_manager_.SendMessageToHMI(message_); } diff --git a/src/components/application_manager/src/commands/hmi/tts_is_ready_request.cc b/src/components/application_manager/src/commands/hmi/tts_is_ready_request.cc index e7fd335808..71e89dd9b9 100644 --- a/src/components/application_manager/src/commands/hmi/tts_is_ready_request.cc +++ b/src/components/application_manager/src/commands/hmi/tts_is_ready_request.cc @@ -31,6 +31,7 @@ */ #include "application_manager/commands/hmi/tts_is_ready_request.h" +#include "application_manager/message_helper.h" namespace application_manager { @@ -38,16 +39,68 @@ namespace commands { TTSIsReadyRequest::TTSIsReadyRequest(const MessageSharedPtr& message, ApplicationManager& application_manager) - : RequestToHMI(message, application_manager) {} + : RequestToHMI(message, application_manager) + , EventObserver(application_manager.event_dispatcher()) {} TTSIsReadyRequest::~TTSIsReadyRequest() {} void TTSIsReadyRequest::Run() { LOG4CXX_AUTO_TRACE(logger_); - + subscribe_on_event(hmi_apis::FunctionID::TTS_IsReady, correlation_id()); SendRequest(); } +void TTSIsReadyRequest::on_event(const event_engine::Event& event) { + LOG4CXX_AUTO_TRACE(logger_); + + const smart_objects::SmartObject& message = event.smart_object(); + switch (event.id()) { + case hmi_apis::FunctionID::TTS_IsReady: { + LOG4CXX_DEBUG(logger_, "Received TTS_IsReady event"); + unsubscribe_from_event(hmi_apis::FunctionID::TTS_IsReady); + const bool is_available = ChangeInterfaceState( + application_manager_, message, HmiInterfaces::HMI_INTERFACE_TTS); + HMICapabilities& hmi_capabilities = + application_manager_.hmi_capabilities(); + hmi_capabilities.set_is_tts_cooperating(is_available); + if (!CheckAvailabilityHMIInterfaces(application_manager_, + HmiInterfaces::HMI_INTERFACE_TTS)) { + LOG4CXX_INFO(logger_, + "HmiInterfaces::HMI_INTERFACE_TTS isn't available"); + return; + } + SendMessageToHMI(); + break; + } + default: { + LOG4CXX_ERROR(logger_, "Received unknown event" << event.id()); + return; + } + } +} + +void TTSIsReadyRequest::onTimeOut() { + // Note(dtrunov): According to new requirment APPLINK-27956 + SendMessageToHMI(); +} + +void TTSIsReadyRequest::SendMessageToHMI() { + utils::SharedPtr<smart_objects::SmartObject> get_language( + MessageHelper::CreateModuleInfoSO(hmi_apis::FunctionID::TTS_GetLanguage, + application_manager_)); + HMICapabilities& hmi_capabilities = application_manager_.hmi_capabilities(); + hmi_capabilities.set_handle_response_for(*get_language); + application_manager_.ManageHMICommand(get_language); + utils::SharedPtr<smart_objects::SmartObject> get_all_languages( + MessageHelper::CreateModuleInfoSO( + hmi_apis::FunctionID::TTS_GetSupportedLanguages, + application_manager_)); + application_manager_.ManageHMICommand(get_all_languages); + utils::SharedPtr<smart_objects::SmartObject> get_capabilities( + MessageHelper::CreateModuleInfoSO( + hmi_apis::FunctionID::TTS_GetCapabilities, application_manager_)); + application_manager_.ManageHMICommand(get_capabilities); +} } // namespace commands } // namespace application_manager diff --git a/src/components/application_manager/src/commands/hmi/tts_is_ready_response.cc b/src/components/application_manager/src/commands/hmi/tts_is_ready_response.cc index 91efb293c9..30e2f4816b 100644 --- a/src/components/application_manager/src/commands/hmi/tts_is_ready_response.cc +++ b/src/components/application_manager/src/commands/hmi/tts_is_ready_response.cc @@ -43,15 +43,9 @@ TTSIsReadyResponse::~TTSIsReadyResponse() {} void TTSIsReadyResponse::Run() { LOG4CXX_AUTO_TRACE(logger_); - smart_objects::SmartObject& object = *message_; - - bool is_available = false; - if (object[strings::msg_params].keyExists(strings::available)) { - is_available = object[strings::msg_params][strings::available].asBool(); - } - - HMICapabilities& hmi_capabilities = application_manager_.hmi_capabilities(); - hmi_capabilities.set_is_tts_cooperating(is_available); + event_engine::Event event(hmi_apis::FunctionID::TTS_IsReady); + event.set_smart_object(*message_); + event.raise(application_manager_.event_dispatcher()); } } // namespace commands diff --git a/src/components/application_manager/src/commands/hmi/ui_is_ready_request.cc b/src/components/application_manager/src/commands/hmi/ui_is_ready_request.cc index 463ae9d41d..9e27e23d34 100644 --- a/src/components/application_manager/src/commands/hmi/ui_is_ready_request.cc +++ b/src/components/application_manager/src/commands/hmi/ui_is_ready_request.cc @@ -31,6 +31,7 @@ */ #include "application_manager/commands/hmi/ui_is_ready_request.h" +#include "application_manager/message_helper.h" namespace application_manager { @@ -38,16 +39,68 @@ namespace commands { UIIsReadyRequest::UIIsReadyRequest(const MessageSharedPtr& message, ApplicationManager& application_manager) - : RequestToHMI(message, application_manager) {} + : RequestToHMI(message, application_manager) + , EventObserver(application_manager.event_dispatcher()) {} UIIsReadyRequest::~UIIsReadyRequest() {} void UIIsReadyRequest::Run() { LOG4CXX_AUTO_TRACE(logger_); - + subscribe_on_event(hmi_apis::FunctionID::UI_IsReady, correlation_id()); SendRequest(); } +void UIIsReadyRequest::on_event(const event_engine::Event& event) { + LOG4CXX_AUTO_TRACE(logger_); + const smart_objects::SmartObject& message = event.smart_object(); + switch (event.id()) { + case hmi_apis::FunctionID::UI_IsReady: { + LOG4CXX_DEBUG(logger_, "Received UI_IsReady event"); + unsubscribe_from_event(hmi_apis::FunctionID::UI_IsReady); + const bool is_available = ChangeInterfaceState( + application_manager_, message, HmiInterfaces::HMI_INTERFACE_UI); + HMICapabilities& hmi_capabilities = + application_manager_.hmi_capabilities(); + hmi_capabilities.set_is_ui_cooperating(is_available); + if (!CheckAvailabilityHMIInterfaces(application_manager_, + HmiInterfaces::HMI_INTERFACE_UI)) { + LOG4CXX_INFO(logger_, + "HmiInterfaces::HMI_INTERFACE_UI isn't available"); + return; + } + SendMessageToHMI(); + break; + } + default: { + LOG4CXX_ERROR(logger_, "Received unknown event" << event.id()); + return; + } + } +} + +void UIIsReadyRequest::onTimeOut() { + // Note(dtrunov): According to new requirment APPLINK-27956 + SendMessageToHMI(); +} + +void UIIsReadyRequest::SendMessageToHMI() { + utils::SharedPtr<smart_objects::SmartObject> get_language( + MessageHelper::CreateModuleInfoSO(hmi_apis::FunctionID::UI_GetLanguage, + application_manager_)); + HMICapabilities& hmi_capabilities = application_manager_.hmi_capabilities(); + hmi_capabilities.set_handle_response_for(*get_language); + application_manager_.ManageHMICommand(get_language); + utils::SharedPtr<smart_objects::SmartObject> get_all_languages( + MessageHelper::CreateModuleInfoSO( + hmi_apis::FunctionID::UI_GetSupportedLanguages, + application_manager_)); + application_manager_.ManageHMICommand(get_all_languages); + utils::SharedPtr<smart_objects::SmartObject> get_capabilities( + MessageHelper::CreateModuleInfoSO( + hmi_apis::FunctionID::UI_GetCapabilities, application_manager_)); + application_manager_.ManageHMICommand(get_capabilities); +} + } // namespace commands } // namespace application_manager diff --git a/src/components/application_manager/src/commands/hmi/ui_is_ready_response.cc b/src/components/application_manager/src/commands/hmi/ui_is_ready_response.cc index 8ad5d89ba7..088baeb8b2 100644 --- a/src/components/application_manager/src/commands/hmi/ui_is_ready_response.cc +++ b/src/components/application_manager/src/commands/hmi/ui_is_ready_response.cc @@ -43,22 +43,10 @@ UIIsReadyResponse::~UIIsReadyResponse() {} void UIIsReadyResponse::Run() { LOG4CXX_AUTO_TRACE(logger_); - smart_objects::SmartObject& object = *message_; - bool is_available = false; - if (object[strings::msg_params].keyExists(strings::available)) { - is_available = object[strings::msg_params][strings::available].asBool(); - } - - HMICapabilities& hmi_capabilities = application_manager_.hmi_capabilities(); - - hmi_capabilities.set_is_ui_cooperating(is_available); - const HmiInterfaces::InterfaceState interface_state = - is_available ? HmiInterfaces::STATE_AVAILABLE - : HmiInterfaces::STATE_NOT_AVAILABLE; - HmiInterfaces& hmi_interfaces = application_manager_.hmi_interfaces(); - hmi_interfaces.SetInterfaceState(HmiInterfaces::HMI_INTERFACE_UI, - interface_state); + event_engine::Event event(hmi_apis::FunctionID::UI_IsReady); + event.set_smart_object(*message_); + event.raise(application_manager_.event_dispatcher()); } } // namespace commands diff --git a/src/components/application_manager/src/commands/hmi/vi_is_ready_request.cc b/src/components/application_manager/src/commands/hmi/vi_is_ready_request.cc index 3ecc2ffe90..ddd08695a0 100644 --- a/src/components/application_manager/src/commands/hmi/vi_is_ready_request.cc +++ b/src/components/application_manager/src/commands/hmi/vi_is_ready_request.cc @@ -31,6 +31,7 @@ */ #include "application_manager/commands/hmi/vi_is_ready_request.h" +#include "application_manager/message_helper.h" namespace application_manager { @@ -38,16 +39,65 @@ namespace commands { VIIsReadyRequest::VIIsReadyRequest(const MessageSharedPtr& message, ApplicationManager& application_manager) - : RequestToHMI(message, application_manager) {} + : RequestToHMI(message, application_manager) + , EventObserver(application_manager.event_dispatcher()) {} VIIsReadyRequest::~VIIsReadyRequest() {} void VIIsReadyRequest::Run() { LOG4CXX_AUTO_TRACE(logger_); - + subscribe_on_event(hmi_apis::FunctionID::VehicleInfo_IsReady, + correlation_id()); SendRequest(); } +void VIIsReadyRequest::on_event(const event_engine::Event& event) { + LOG4CXX_AUTO_TRACE(logger_); + const smart_objects::SmartObject& message = event.smart_object(); + switch (event.id()) { + case hmi_apis::FunctionID::VehicleInfo_IsReady: { + LOG4CXX_DEBUG(logger_, "VehicleInfo_IsReady event"); + unsubscribe_from_event(hmi_apis::FunctionID::VehicleInfo_IsReady); + const bool is_available = + ChangeInterfaceState(application_manager_, + message, + HmiInterfaces::HMI_INTERFACE_VehicleInfo); + + HMICapabilities& hmi_capabilities = + application_manager_.hmi_capabilities(); + hmi_capabilities.set_is_ivi_cooperating(is_available); + application_manager_.GetPolicyHandler().OnVIIsReady(); + if (!CheckAvailabilityHMIInterfaces( + application_manager_, HmiInterfaces::HMI_INTERFACE_VehicleInfo)) { + LOG4CXX_INFO( + logger_, + "HmiInterfaces::HMI_INTERFACE_VehicleInfo isn't available"); + return; + } + SendMessageToHMI(); + + break; + } + default: { + LOG4CXX_ERROR(logger_, "Received unknown event" << event.id()); + return; + } + } +} + +void VIIsReadyRequest::onTimeOut() { + // Note(dtrunov): According to new requirment APPLINK-27956 + SendMessageToHMI(); +} + +void VIIsReadyRequest::SendMessageToHMI() { + utils::SharedPtr<smart_objects::SmartObject> get_type( + MessageHelper::CreateModuleInfoSO( + hmi_apis::FunctionID::VehicleInfo_GetVehicleType, + application_manager_)); + application_manager_.ManageHMICommand(get_type); +} + } // namespace commands } // namespace application_manager diff --git a/src/components/application_manager/src/commands/hmi/vi_is_ready_response.cc b/src/components/application_manager/src/commands/hmi/vi_is_ready_response.cc index 0f62b6662a..2f84190494 100644 --- a/src/components/application_manager/src/commands/hmi/vi_is_ready_response.cc +++ b/src/components/application_manager/src/commands/hmi/vi_is_ready_response.cc @@ -43,23 +43,9 @@ VIIsReadyResponse::~VIIsReadyResponse() {} void VIIsReadyResponse::Run() { LOG4CXX_AUTO_TRACE(logger_); - smart_objects::SmartObject& object = *message_; - - bool is_available = false; - if (object[strings::msg_params].keyExists(strings::available)) { - is_available = object[strings::msg_params][strings::available].asBool(); - const HmiInterfaces::InterfaceState interface_state = - is_available ? HmiInterfaces::STATE_AVAILABLE - : HmiInterfaces::STATE_NOT_AVAILABLE; - HmiInterfaces& hmi_interfaces = application_manager_.hmi_interfaces(); - hmi_interfaces.SetInterfaceState(HmiInterfaces::HMI_INTERFACE_VehicleInfo, - interface_state); - } - - HMICapabilities& hmi_capabilities = application_manager_.hmi_capabilities(); - hmi_capabilities.set_is_ivi_cooperating(is_available); - - application_manager_.GetPolicyHandler().OnVIIsReady(); + event_engine::Event event(hmi_apis::FunctionID::VehicleInfo_IsReady); + event.set_smart_object(*message_); + event.raise(application_manager_.event_dispatcher()); } } // namespace commands diff --git a/src/components/application_manager/src/commands/hmi/vr_is_ready_request.cc b/src/components/application_manager/src/commands/hmi/vr_is_ready_request.cc index 8c5e8bd49b..086b5d4490 100644 --- a/src/components/application_manager/src/commands/hmi/vr_is_ready_request.cc +++ b/src/components/application_manager/src/commands/hmi/vr_is_ready_request.cc @@ -38,16 +38,69 @@ namespace commands { VRIsReadyRequest::VRIsReadyRequest(const MessageSharedPtr& message, ApplicationManager& application_manager) - : RequestToHMI(message, application_manager) {} + : RequestToHMI(message, application_manager) + , EventObserver(application_manager.event_dispatcher()) {} VRIsReadyRequest::~VRIsReadyRequest() {} void VRIsReadyRequest::Run() { LOG4CXX_AUTO_TRACE(logger_); - + subscribe_on_event(hmi_apis::FunctionID::VR_IsReady, correlation_id()); SendRequest(); } +void VRIsReadyRequest::on_event(const event_engine::Event& event) { + LOG4CXX_AUTO_TRACE(logger_); + const smart_objects::SmartObject& message = event.smart_object(); + switch (event.id()) { + case hmi_apis::FunctionID::VR_IsReady: { + LOG4CXX_DEBUG(logger_, "Received VR_IsReady event"); + unsubscribe_from_event(hmi_apis::FunctionID::VR_IsReady); + const bool is_available = ChangeInterfaceState( + application_manager_, message, HmiInterfaces::HMI_INTERFACE_VR); + + HMICapabilities& hmi_capabilities = + application_manager_.hmi_capabilities(); + hmi_capabilities.set_is_vr_cooperating(is_available); + if (!CheckAvailabilityHMIInterfaces(application_manager_, + HmiInterfaces::HMI_INTERFACE_VR)) { + LOG4CXX_INFO(logger_, + "HmiInterfaces::HMI_INTERFACE_VR isn't available"); + return; + } + SendMessageToHMI(); + break; + } + default: { + LOG4CXX_ERROR(logger_, "Received unknown event" << event.id()); + return; + } + } +} + +void VRIsReadyRequest::onTimeOut() { + // Note(dtrunov): According to new requirment APPLINK-27956 + SendMessageToHMI(); +} + +void VRIsReadyRequest::SendMessageToHMI() { + utils::SharedPtr<smart_objects::SmartObject> get_language( + MessageHelper::CreateModuleInfoSO(hmi_apis::FunctionID::VR_GetLanguage, + application_manager_)); + HMICapabilities& hmi_capabilities = application_manager_.hmi_capabilities(); + hmi_capabilities.set_handle_response_for(*get_language); + application_manager_.ManageHMICommand(get_language); + utils::SharedPtr<smart_objects::SmartObject> get_all_languages( + MessageHelper::CreateModuleInfoSO( + hmi_apis::FunctionID::VR_GetSupportedLanguages, + application_manager_)); + application_manager_.ManageHMICommand(get_all_languages); + utils::SharedPtr<smart_objects::SmartObject> get_capabilities( + MessageHelper::CreateModuleInfoSO( + hmi_apis::FunctionID::VR_GetCapabilities, application_manager_)); + application_manager_.ManageHMICommand(get_capabilities); +} + } // namespace commands } // namespace application_manager diff --git a/src/components/application_manager/src/commands/hmi/vr_is_ready_response.cc b/src/components/application_manager/src/commands/hmi/vr_is_ready_response.cc index c523387f1b..78e2dae23b 100644 --- a/src/components/application_manager/src/commands/hmi/vr_is_ready_response.cc +++ b/src/components/application_manager/src/commands/hmi/vr_is_ready_response.cc @@ -43,21 +43,9 @@ VRIsReadyResponse::~VRIsReadyResponse() {} void VRIsReadyResponse::Run() { LOG4CXX_AUTO_TRACE(logger_); - smart_objects::SmartObject& object = *message_; - - bool is_available = false; - if (object[strings::msg_params].keyExists(strings::available)) { - is_available = object[strings::msg_params][strings::available].asBool(); - const HmiInterfaces::InterfaceState interface_state = - is_available ? HmiInterfaces::STATE_AVAILABLE - : HmiInterfaces::STATE_NOT_AVAILABLE; - HmiInterfaces& hmi_interfaces = application_manager_.hmi_interfaces(); - hmi_interfaces.SetInterfaceState(HmiInterfaces::HMI_INTERFACE_VR, - interface_state); - } - - HMICapabilities& hmi_capabilities = application_manager_.hmi_capabilities(); - hmi_capabilities.set_is_vr_cooperating(is_available); + event_engine::Event event(hmi_apis::FunctionID::VR_IsReady); + event.set_smart_object(*message_); + event.raise(application_manager_.event_dispatcher()); } } // namespace commands diff --git a/src/components/application_manager/src/commands/mobile/add_command_request.cc b/src/components/application_manager/src/commands/mobile/add_command_request.cc index d30209982e..9d46f67aee 100644 --- a/src/components/application_manager/src/commands/mobile/add_command_request.cc +++ b/src/components/application_manager/src/commands/mobile/add_command_request.cc @@ -315,7 +315,7 @@ void AddCommandRequest::on_event(const event_engine::Event& event) { is_ui_received_ = true; ui_result_ = static_cast<hmi_apis::Common_Result::eType>( message[strings::params][hmi_response::code].asInt()); - ui_info_ = message[strings::msg_params][strings::info].asString(); + GetInfo(HmiInterfaces::HMI_INTERFACE_UI, ui_result_, message, ui_info_); if (hmi_apis::Common_Result::SUCCESS != ui_result_) { (*message_)[strings::msg_params].erase(strings::menu_params); } @@ -326,7 +326,7 @@ void AddCommandRequest::on_event(const event_engine::Event& event) { is_vr_received_ = true; vr_result_ = static_cast<hmi_apis::Common_Result::eType>( message[strings::params][hmi_response::code].asInt()); - vr_info_ = message[strings::msg_params][strings::info].asString(); + GetInfo(HmiInterfaces::HMI_INTERFACE_VR, vr_result_, message, vr_info_); if (hmi_apis::Common_Result::SUCCESS != vr_result_) { (*message_)[strings::msg_params].erase(strings::vr_commands); } @@ -360,6 +360,10 @@ void AddCommandRequest::on_event(const event_engine::Event& event) { ui_result_, hmi_apis::Common_Result::INVALID_ENUM, hmi_apis::Common_Result::UNSUPPORTED_RESOURCE); + const bool is_vr_unsupported = + vr_result_ == hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; + const bool is_ui_unsupported = + ui_result_ == hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; const bool is_no_ui_error = Compare<hmi_apis::Common_Result::eType, EQ, ONE>( ui_result_, @@ -382,6 +386,7 @@ void AddCommandRequest::on_event(const event_engine::Event& event) { bool result = (is_no_ui_error && is_no_vr_error) || (is_no_ui_error && is_vr_invalid_unsupported) || (is_no_vr_error && is_ui_invalid_unsupported); + LOG4CXX_DEBUG(logger_, "calculated result " << ui_result_ << " " << is_no_ui_error << " " << is_no_vr_error); @@ -457,7 +462,18 @@ void AddCommandRequest::on_event(const event_engine::Event& event) { LOG4CXX_DEBUG(logger_, "Result " << result); } - if (!BothSend() && is_vr_or_ui_unsupported) { + HmiInterfaces::InterfaceState ui_interface_state = + application_manager_.hmi_interfaces().GetInterfaceState( + HmiInterfaces::HMI_INTERFACE_UI); + HmiInterfaces::InterfaceState vr_interface_state = + application_manager_.hmi_interfaces().GetInterfaceState( + HmiInterfaces::HMI_INTERFACE_VR); + + if (!BothSend() && + ((is_vr_unsupported && + HmiInterfaces::STATE_NOT_AVAILABLE == vr_interface_state) || + (is_ui_unsupported && + HmiInterfaces::STATE_NOT_AVAILABLE == ui_interface_state))) { LOG4CXX_DEBUG(logger_, "!BothSend() && is_vr_or_ui_unsupported"); result = false; } @@ -528,19 +544,6 @@ bool AddCommandRequest::BothSend() const { return send_vr_ && send_ui_; } -/** - * @brief MergeInfos merge 2 infos in one string - * @param lval - info string that should be first in result info - * @param rval - info string that should be second in result info - * @return if lval is empty return rval - * if rval is empty return lval - * if both are empty return empty string - * if both are not empty return empty lval +", " + rval - */ -std::string MergeInfos(const std::string& lval, const std::string& rval) { - return lval + ((!lval.empty() && !rval.empty()) ? ", " : "") + rval; -} - const std::string AddCommandRequest::GenerateMobileResponseInfo() { // In case if vr_result_ is UNSUPPORTED_RESOURCE vr_info should be on the // first place diff --git a/src/components/application_manager/src/commands/mobile/add_sub_menu_request.cc b/src/components/application_manager/src/commands/mobile/add_sub_menu_request.cc index 83f137ac19..3d91dbecfc 100644 --- a/src/components/application_manager/src/commands/mobile/add_sub_menu_request.cc +++ b/src/components/application_manager/src/commands/mobile/add_sub_menu_request.cc @@ -33,6 +33,7 @@ #include "application_manager/commands/mobile/add_sub_menu_request.h" +#include "application_manager/message_helper.h" #include "application_manager/application.h" #include "utils/helpers.h" @@ -98,19 +99,18 @@ void AddSubMenuRequest::Run() { void AddSubMenuRequest::on_event(const event_engine::Event& event) { LOG4CXX_AUTO_TRACE(logger_); - using namespace helpers; const smart_objects::SmartObject& message = event.smart_object(); switch (event.id()) { case hmi_apis::FunctionID::UI_AddSubMenu: { - mobile_apis::Result::eType result_code = - static_cast<mobile_apis::Result::eType>( + hmi_apis::Common_Result::eType result_code = + static_cast<hmi_apis::Common_Result::eType>( message[strings::params][hmi_response::code].asInt()); - - const bool result = Compare<mobile_api::Result::eType, EQ, ONE>( - result_code, - mobile_api::Result::SUCCESS, - mobile_api::Result::WARNINGS); + std::string response_info; + GetInfo( + HmiInterfaces::HMI_INTERFACE_UI, result_code, message, response_info); + const bool result = PrepareResultForMobileResponse( + result_code, HmiInterfaces::HMI_INTERFACE_UI); ApplicationSharedPtr application = application_manager_.application(connection_key()); @@ -125,7 +125,10 @@ void AddSubMenuRequest::on_event(const event_engine::Event& event) { (*message_)[strings::msg_params][strings::menu_id].asInt(), (*message_)[strings::msg_params]); } - SendResponse(result, result_code, NULL, &(message[strings::msg_params])); + SendResponse(result, + MessageHelper::HMIToMobileResult(result_code), + response_info.empty() ? NULL : response_info.c_str(), + &(message[strings::msg_params])); if (result) { application->UpdateHash(); } diff --git a/src/components/application_manager/src/commands/mobile/alert_request.cc b/src/components/application_manager/src/commands/mobile/alert_request.cc index 770900845b..069b21cb66 100644 --- a/src/components/application_manager/src/commands/mobile/alert_request.cc +++ b/src/components/application_manager/src/commands/mobile/alert_request.cc @@ -55,8 +55,8 @@ AlertRequest::AlertRequest(const MessageSharedPtr& message, , awaiting_tts_stop_speaking_response_(false) , is_alert_succeeded_(false) , is_ui_alert_sent_(false) - , alert_result_(mobile_apis::Result::INVALID_ENUM) - , tts_speak_result_(mobile_apis::Result::INVALID_ENUM) { + , alert_result_(hmi_apis::Common_Result::INVALID_ENUM) + , tts_speak_result_(hmi_apis::Common_Result::INVALID_ENUM) { subscribe_on_event(hmi_apis::FunctionID::UI_OnResetTimeout); subscribe_on_event(hmi_apis::FunctionID::TTS_OnResetTimeout); } @@ -131,8 +131,6 @@ void AlertRequest::onTimeOut() { void AlertRequest::on_event(const event_engine::Event& event) { LOG4CXX_AUTO_TRACE(logger_); - using namespace helpers; - const smart_objects::SmartObject& message = event.smart_object(); switch (event.id()) { @@ -153,26 +151,24 @@ void AlertRequest::on_event(const event_engine::Event& event) { // Unsubscribe from event to avoid unwanted messages unsubscribe_from_event(hmi_apis::FunctionID::UI_Alert); awaiting_ui_alert_response_ = false; + HmiInterfaces::InterfaceState ui_interface_state = + application_manager_.hmi_interfaces().GetInterfaceState( + HmiInterfaces::HMI_INTERFACE_UI); - if (awaiting_tts_speak_response_) { + if (awaiting_tts_speak_response_ && + HmiInterfaces::STATE_NOT_AVAILABLE != ui_interface_state) { awaiting_tts_stop_speaking_response_ = true; SendHMIRequest(hmi_apis::FunctionID::TTS_StopSpeaking, NULL, true); } + alert_result_ = static_cast<hmi_apis::Common_Result::eType>( + message[strings::params][hmi_response::code].asInt()); - mobile_apis::Result::eType result_code = - static_cast<mobile_apis::Result::eType>( - message[strings::params][hmi_response::code].asInt()); // Mobile Alert request is successful when UI_Alert is successful - - const bool is_alert_ok = Compare<mobile_api::Result::eType, EQ, ONE>( - result_code, - mobile_apis::Result::SUCCESS, - mobile_apis::Result::UNSUPPORTED_RESOURCE, - mobile_apis::Result::WARNINGS); - - is_alert_succeeded_ = is_alert_ok; - alert_result_ = result_code; alert_response_params_ = message[strings::msg_params]; + GetInfo(HmiInterfaces::HMI_INTERFACE_UI, + alert_result_, + message, + ui_response_info_); break; } case hmi_apis::FunctionID::TTS_Speak: { @@ -180,8 +176,12 @@ void AlertRequest::on_event(const event_engine::Event& event) { // Unsubscribe from event to avoid unwanted messages unsubscribe_from_event(hmi_apis::FunctionID::TTS_Speak); awaiting_tts_speak_response_ = false; - tts_speak_result_ = static_cast<mobile_apis::Result::eType>( + tts_speak_result_ = static_cast<hmi_apis::Common_Result::eType>( message[strings::params][hmi_response::code].asInt()); + GetInfo(HmiInterfaces::HMI_INTERFACE_TTS, + tts_speak_result_, + message, + tts_response_info_); break; } case hmi_apis::FunctionID::TTS_StopSpeaking: { @@ -200,56 +200,42 @@ void AlertRequest::on_event(const event_engine::Event& event) { if (HasHmiResponsesToWait()) { return; } + mobile_apis::Result::eType result_code = mobile_apis::Result::INVALID_ENUM; + std::string info; + const bool result = PrepareResponseParameters(result_code, info); + SendResponse(result, + result_code, + info.empty() ? NULL : info.c_str(), + &alert_response_params_); +} - const bool is_tts_alert_unsupported = - Compare<mobile_api::Result::eType, EQ, ALL>( - mobile_api::Result::UNSUPPORTED_RESOURCE, - tts_speak_result_, - alert_result_); - - const bool is_alert_ok = Compare<mobile_api::Result::eType, EQ, ONE>( - alert_result_, mobile_api::Result::SUCCESS, mobile_api::Result::WARNINGS); - - std::string response_info; - if (mobile_apis::Result::UNSUPPORTED_RESOURCE == tts_speak_result_ && - !is_ui_alert_sent_) { - is_alert_succeeded_ = false; - alert_result_ = mobile_apis::Result::WARNINGS; - response_info = "Unsupported phoneme type sent in a prompt"; - } else if (is_tts_alert_unsupported) { - alert_result_ = mobile_apis::Result::WARNINGS; - response_info = - "Unsupported phoneme type sent in a prompt and " - "unsupported image sent in soft buttons"; - } else if (mobile_apis::Result::UNSUPPORTED_RESOURCE == tts_speak_result_ && - is_alert_ok) { - alert_result_ = mobile_apis::Result::WARNINGS; - response_info = "Unsupported phoneme type sent in a prompt"; - } else if (mobile_apis::Result::SUCCESS == tts_speak_result_ && - (mobile_apis::Result::INVALID_ENUM == alert_result_ && - !is_ui_alert_sent_)) { - alert_result_ = mobile_apis::Result::SUCCESS; - is_alert_succeeded_ = true; - } - - const bool is_tts_not_ok = - Compare<mobile_api::Result::eType, EQ, ONE>(tts_speak_result_, - mobile_api::Result::ABORTED, - mobile_api::Result::REJECTED); - - if (is_tts_not_ok && !is_ui_alert_sent_) { - is_alert_succeeded_ = false; - alert_result_ = tts_speak_result_; +bool AlertRequest::PrepareResponseParameters( + mobile_apis::Result::eType& result_code, std::string& info) { + ResponseInfo ui_alert_info(alert_result_, HmiInterfaces::HMI_INTERFACE_UI); + ResponseInfo tts_alert_info(tts_speak_result_, + HmiInterfaces::HMI_INTERFACE_TTS); + + bool result = PrepareResultForMobileResponse(ui_alert_info, tts_alert_info); + + /* result=false if UI interface is ok and TTS interface = UNSUPPORTED_RESOURCE + * and sdl receive TTS.IsReady=true or SDL doesn't receive responce for + * TTS.IsReady. + */ + if (result && ui_alert_info.is_ok && tts_alert_info.is_unsupported_resource && + HmiInterfaces::STATE_NOT_AVAILABLE != tts_alert_info.interface_state) { + result = false; } - - if (mobile_apis::Result::WARNINGS == tts_speak_result_) { - alert_result_ = mobile_apis::Result::WARNINGS; + result_code = mobile_apis::Result::WARNINGS; + if ((ui_alert_info.is_ok || ui_alert_info.is_invalid_enum) && + tts_alert_info.is_unsupported_resource && + HmiInterfaces::STATE_AVAILABLE == tts_alert_info.interface_state) { + tts_response_info_ = "Unsupported phoneme type sent in a prompt"; + info = MergeInfos(ui_response_info_, tts_response_info_); + return result; } - - SendResponse(is_alert_succeeded_, - alert_result_, - response_info.empty() ? NULL : response_info.c_str(), - &alert_response_params_); + result_code = PrepareResultCodeForResponse(ui_alert_info, tts_alert_info); + info = MergeInfos(ui_response_info_, tts_response_info_); + return result; } bool AlertRequest::Validate(uint32_t app_id) { diff --git a/src/components/application_manager/src/commands/mobile/change_registration_request.cc b/src/components/application_manager/src/commands/mobile/change_registration_request.cc index 63339fdc33..9477c3beae 100644 --- a/src/components/application_manager/src/commands/mobile/change_registration_request.cc +++ b/src/components/application_manager/src/commands/mobile/change_registration_request.cc @@ -38,6 +38,7 @@ #include "application_manager/application_impl.h" #include "interfaces/MOBILE_API.h" #include "interfaces/HMI_API.h" +#include "application_manager/message_helper.h" namespace { namespace custom_str = utils::custom_string; @@ -69,9 +70,6 @@ void ChangeRegistrationRequest::Run() { LOG4CXX_AUTO_TRACE(logger_); using namespace smart_objects; - const HMICapabilities& hmi_capabilities = - application_manager_.hmi_capabilities(); - ApplicationSharedPtr app = application_manager_.application(connection_key()); if (!app) { LOG4CXX_ERROR(logger_, "NULL pointer"); @@ -91,18 +89,6 @@ void ChangeRegistrationRequest::Run() { return; } - if (!hmi_capabilities.is_ui_cooperating()) { - ui_result_ = hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; - } - - if (!hmi_capabilities.is_vr_cooperating()) { - vr_result_ = hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; - } - - if (!hmi_capabilities.is_tts_cooperating()) { - tts_result_ = hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; - } - SmartObject& msg_params = (*message_)[strings::msg_params]; const int32_t hmi_language = @@ -174,15 +160,6 @@ void ChangeRegistrationRequest::Run() { hmi_apis::FunctionID::TTS_ChangeRegistration, &tts_params, true); } -bool ChangeRegistrationRequest::AllHmiResponsesSuccess( - const hmi_apis::Common_Result::eType ui, - const hmi_apis::Common_Result::eType vr, - const hmi_apis::Common_Result::eType tts) { - return hmi_apis::Common_Result::SUCCESS == ui && - hmi_apis::Common_Result::SUCCESS == vr && - hmi_apis::Common_Result::SUCCESS == tts; -} - void ChangeRegistrationRequest::on_event(const event_engine::Event& event) { LOG4CXX_AUTO_TRACE(logger_); const smart_objects::SmartObject& message = event.smart_object(); @@ -195,6 +172,10 @@ void ChangeRegistrationRequest::on_event(const event_engine::Event& event) { pending_requests_.Remove(event_id); ui_result_ = static_cast<hmi_apis::Common_Result::eType>( message[strings::params][hmi_response::code].asInt()); + GetInfo(HmiInterfaces::HMI_INTERFACE_UI, + ui_result_, + message, + ui_response_info_); break; } case hmi_apis::FunctionID::VR_ChangeRegistration: { @@ -202,6 +183,10 @@ void ChangeRegistrationRequest::on_event(const event_engine::Event& event) { pending_requests_.Remove(event_id); vr_result_ = static_cast<hmi_apis::Common_Result::eType>( message[strings::params][hmi_response::code].asInt()); + GetInfo(HmiInterfaces::HMI_INTERFACE_VR, + vr_result_, + message, + vr_response_info_); break; } case hmi_apis::FunctionID::TTS_ChangeRegistration: { @@ -209,6 +194,10 @@ void ChangeRegistrationRequest::on_event(const event_engine::Event& event) { pending_requests_.Remove(event_id); tts_result_ = static_cast<hmi_apis::Common_Result::eType>( message[strings::params][hmi_response::code].asInt()); + GetInfo(HmiInterfaces::HMI_INTERFACE_TTS, + tts_result_, + message, + tts_response_info_); break; } default: { @@ -237,16 +226,16 @@ void ChangeRegistrationRequest::on_event(const event_engine::Event& event) { application->set_language(static_cast<mobile_api::Language::eType>( (*message_)[strings::msg_params][strings::language].asInt())); } - - int32_t greates_result_code = - std::max(std::max(ui_result_, vr_result_), tts_result_); + mobile_apis::Result::eType result_code = mobile_apis::Result::INVALID_ENUM; + std::string response_info; + const bool result = PrepareResponseParameters(result_code, response_info); (*message_)[strings::params][strings::function_id] = mobile_apis::FunctionID::eType::ChangeRegistrationID; - SendResponse(AllHmiResponsesSuccess(ui_result_, vr_result_, tts_result_), - static_cast<mobile_apis::Result::eType>(greates_result_code), - NULL, + SendResponse(result, + result_code, + response_info.empty() ? NULL : response_info.c_str(), &(message[strings::msg_params])); } else { LOG4CXX_INFO(logger_, @@ -255,6 +244,85 @@ void ChangeRegistrationRequest::on_event(const event_engine::Event& event) { } } +bool ChangeRegistrationRequest::PrepareResponseParameters( + mobile_apis::Result::eType& result_code, std::string& response_info) { + LOG4CXX_AUTO_TRACE(logger_); + using namespace helpers; + const bool is_tts_succeeded_unsupported = + Compare<hmi_apis::Common_Result::eType, EQ, ONE>( + tts_result_, + hmi_apis::Common_Result::SUCCESS, + hmi_apis::Common_Result::WARNINGS, + hmi_apis::Common_Result::WRONG_LANGUAGE, + hmi_apis::Common_Result::RETRY, + hmi_apis::Common_Result::SAVED, + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE); + + const bool is_ui_succeeded_unsupported = + Compare<hmi_apis::Common_Result::eType, EQ, ONE>( + ui_result_, + hmi_apis::Common_Result::SUCCESS, + hmi_apis::Common_Result::WARNINGS, + hmi_apis::Common_Result::WRONG_LANGUAGE, + hmi_apis::Common_Result::RETRY, + hmi_apis::Common_Result::SAVED, + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE); + + const bool is_vr_succeeded_unsupported = + Compare<hmi_apis::Common_Result::eType, EQ, ONE>( + vr_result_, + hmi_apis::Common_Result::SUCCESS, + hmi_apis::Common_Result::WARNINGS, + hmi_apis::Common_Result::WRONG_LANGUAGE, + hmi_apis::Common_Result::RETRY, + hmi_apis::Common_Result::SAVED, + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE); + + const bool is_tts_ui_vr_unsupported = + Compare<hmi_apis::Common_Result::eType, EQ, ALL>( + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE, + tts_result_, + ui_result_, + vr_result_); + + bool result = ((!is_tts_ui_vr_unsupported) && is_tts_succeeded_unsupported && + is_ui_succeeded_unsupported && is_vr_succeeded_unsupported); + + const bool is_tts_or_ui_or_vr_unsupported = + Compare<hmi_apis::Common_Result::eType, EQ, ONE>( + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE, + tts_result_, + ui_result_, + vr_result_); + + if ((result && is_tts_or_ui_or_vr_unsupported) || is_tts_ui_vr_unsupported) { + result_code = mobile_apis::Result::UNSUPPORTED_RESOURCE; + } else { + // If response contains erroneous result code SDL need return erroneus + // result code. + hmi_apis::Common_Result::eType ui_result = + hmi_apis::Common_Result::INVALID_ENUM; + hmi_apis::Common_Result::eType vr_result = + hmi_apis::Common_Result::INVALID_ENUM; + hmi_apis::Common_Result::eType tts_result = + hmi_apis::Common_Result::INVALID_ENUM; + if (hmi_apis::Common_Result::UNSUPPORTED_RESOURCE != ui_result_) { + ui_result = ui_result_; + } + if (hmi_apis::Common_Result::UNSUPPORTED_RESOURCE != vr_result_) { + vr_result = vr_result_; + } + if (hmi_apis::Common_Result::UNSUPPORTED_RESOURCE != tts_result_) { + tts_result = tts_result_; + } + result_code = MessageHelper::HMIToMobileResult( + std::max(std::max(ui_result, vr_result), tts_result)); + } + response_info = + MergeInfos(ui_response_info_, vr_response_info_, tts_response_info_); + return result; +} + bool ChangeRegistrationRequest::IsLanguageSupportedByUI( const int32_t& hmi_display_lang) { const HMICapabilities& hmi_capabilities = diff --git a/src/components/application_manager/src/commands/mobile/delete_command_request.cc b/src/components/application_manager/src/commands/mobile/delete_command_request.cc index 7de1188c97..f6146e080e 100644 --- a/src/components/application_manager/src/commands/mobile/delete_command_request.cc +++ b/src/components/application_manager/src/commands/mobile/delete_command_request.cc @@ -94,16 +94,19 @@ void DeleteCommandRequest::Run() { if ((*command).keyExists(strings::vr_commands)) { ++chaining_counter; } - + /* Need to set all flags before sending request to HMI + * for correct processing this flags in method on_event */ if ((*command).keyExists(strings::menu_params)) { is_ui_send_ = true; - - SendHMIRequest(hmi_apis::FunctionID::UI_DeleteCommand, &msg_params, true); } // check vr params if ((*command).keyExists(strings::vr_commands)) { is_vr_send_ = true; - + } + if (is_ui_send_) { + SendHMIRequest(hmi_apis::FunctionID::UI_DeleteCommand, &msg_params, true); + } + if (is_vr_send_) { // VR params msg_params[strings::grammar_id] = application->get_grammar_id(); msg_params[strings::type] = hmi_apis::Common_VRCommandType::Command; @@ -111,110 +114,57 @@ void DeleteCommandRequest::Run() { } } -bool DeleteCommandRequest::CalculateResult() { +bool DeleteCommandRequest::PrepareResponseParameters( + mobile_apis::Result::eType& result_code, std::string& info) { using namespace helpers; - // Invalid enum means that request didn't sent - const bool is_vr_success_invalid = - Compare<hmi_apis::Common_Result::eType, EQ, ONE>( - vr_result_, - hmi_apis::Common_Result::SUCCESS, - hmi_apis::Common_Result::WARNINGS, - hmi_apis::Common_Result::WRONG_LANGUAGE, - hmi_apis::Common_Result::RETRY, - hmi_apis::Common_Result::SAVED, - hmi_apis::Common_Result::INVALID_ENUM); - - const bool is_ui_success_invalid = - Compare<hmi_apis::Common_Result::eType, EQ, ONE>( - ui_result_, - hmi_apis::Common_Result::SUCCESS, - hmi_apis::Common_Result::WARNINGS, - hmi_apis::Common_Result::WRONG_LANGUAGE, - hmi_apis::Common_Result::RETRY, - hmi_apis::Common_Result::SAVED, - hmi_apis::Common_Result::INVALID_ENUM); - - const bool is_vr_ui_invalid = - Compare<hmi_apis::Common_Result::eType, EQ, ALL>( - hmi_apis::Common_Result::INVALID_ENUM, vr_result_, ui_result_); - - const bool is_ui_warning = Compare<hmi_apis::Common_Result::eType, EQ, ONE>( - ui_result_, hmi_apis::Common_Result::WARNINGS); - - const bool is_vr_warning = Compare<hmi_apis::Common_Result::eType, EQ, ONE>( - vr_result_, hmi_apis::Common_Result::WARNINGS); - - const bool is_vr_unsupported = - vr_result_ == hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; - const bool is_ui_unsupported = - ui_result_ == hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; - - const bool is_ui_success_warnings = - Compare<hmi_apis::Common_Result::eType, EQ, ONE>( - ui_result_, - hmi_apis::Common_Result::SUCCESS, - hmi_apis::Common_Result::WARNINGS, - hmi_apis::Common_Result::WRONG_LANGUAGE, - hmi_apis::Common_Result::RETRY, - hmi_apis::Common_Result::SAVED, - hmi_apis::Common_Result::UNSUPPORTED_RESOURCE); - - const bool is_vr_success_warnings = - Compare<hmi_apis::Common_Result::eType, EQ, ONE>( - vr_result_, - hmi_apis::Common_Result::SUCCESS, - hmi_apis::Common_Result::WARNINGS, - hmi_apis::Common_Result::WRONG_LANGUAGE, - hmi_apis::Common_Result::RETRY, - hmi_apis::Common_Result::SAVED, - hmi_apis::Common_Result::UNSUPPORTED_RESOURCE); - - // At least one (VR or UI is success or didn't sent) - bool result = - (is_vr_success_invalid && is_ui_success_invalid && !is_vr_ui_invalid); - - // VR is succeed on didn't send, but UI respond with WARNING - result = result || (is_vr_success_invalid && is_ui_warning); - - // UI is succeed on didn't send, but VR respond with WARNINGS - result = result || (is_ui_success_invalid && is_vr_warning); - - // If VR is unsupported UI should be SUCCESS or WARNINGS - result = result || (is_vr_unsupported && is_ui_success_warnings); - - // If VR is unsupported UI should be SUCCESS or WARNINGS - result = result || (is_ui_unsupported && is_vr_success_warnings); + ResponseInfo ui_delete_info(ui_result_, HmiInterfaces::HMI_INTERFACE_UI); + ResponseInfo vr_delete_info(vr_result_, HmiInterfaces::HMI_INTERFACE_VR); + const bool result = + PrepareResultForMobileResponse(ui_delete_info, vr_delete_info); + const bool is_vr_or_ui_warning = + Compare<hmi_apis::Common_Result::eType, EQ, ONE>( + hmi_apis::Common_Result::WARNINGS, ui_result_, vr_result_); + info = MergeInfos(ui_info_, vr_info_); + if (!result && hmi_apis::Common_Result::REJECTED == ui_result_ && + (!vr_delete_info.is_invalid_enum)) { + result_code = MessageHelper::HMIToMobileResult(vr_result_); + return result; + } + if (is_vr_or_ui_warning && !ui_delete_info.is_unsupported_resource && + !vr_delete_info.is_unsupported_resource) { + LOG4CXX_DEBUG(logger_, "VR or UI result is warning"); + result_code = mobile_apis::Result::WARNINGS; + return result; + } + result_code = PrepareResultCodeForResponse(ui_delete_info, vr_delete_info); LOG4CXX_DEBUG(logger_, "Result is " << (result ? "true" : "false")); - return result; } void DeleteCommandRequest::on_event(const event_engine::Event& event) { LOG4CXX_AUTO_TRACE(logger_); - using namespace helpers; const smart_objects::SmartObject& message = event.smart_object(); - if (message[strings::msg_params].keyExists(strings::info)) { - info_ += message[strings::msg_params][strings::info].asString(); - } switch (event.id()) { case hmi_apis::FunctionID::UI_DeleteCommand: { is_ui_received_ = true; - const int result = message[strings::params][hmi_response::code].asInt(); - ui_result_ = static_cast<hmi_apis::Common_Result::eType>(result); + ui_result_ = static_cast<hmi_apis::Common_Result::eType>( + message[strings::params][hmi_response::code].asInt()); LOG4CXX_DEBUG(logger_, "Received UI_DeleteCommand event with result " << MessageHelper::HMIResultToString(ui_result_)); + GetInfo(HmiInterfaces::HMI_INTERFACE_UI, ui_result_, message, ui_info_); break; } case hmi_apis::FunctionID::VR_DeleteCommand: { is_vr_received_ = true; - const int result = message[strings::params][hmi_response::code].asInt(); - vr_result_ = static_cast<hmi_apis::Common_Result::eType>(result); + vr_result_ = static_cast<hmi_apis::Common_Result::eType>( + message[strings::params][hmi_response::code].asInt()); LOG4CXX_DEBUG(logger_, "Received VR_DeleteCommand event with result " << MessageHelper::HMIResultToString(vr_result_)); + GetInfo(HmiInterfaces::HMI_INTERFACE_VR, vr_result_, message, vr_info_); break; } default: { @@ -248,37 +198,14 @@ void DeleteCommandRequest::on_event(const event_engine::Event& event) { << connection_key()); return; } - - bool result = CalculateResult(); - - const bool is_vr_or_ui_warning = - Compare<hmi_apis::Common_Result::eType, EQ, ONE>( - hmi_apis::Common_Result::WARNINGS, ui_result_, vr_result_); - const bool is_vr_or_ui_unsupported = - Compare<hmi_apis::Common_Result::eType, EQ, ONE>( - hmi_apis::Common_Result::UNSUPPORTED_RESOURCE, - ui_result_, - vr_result_); + mobile_apis::Result::eType result_code = mobile_apis::Result::INVALID_ENUM; + std::string info; + const bool result = PrepareResponseParameters(result_code, info); if (result) { application->RemoveCommand(msg_params[strings::cmd_id].asInt()); } - - mobile_apis::Result::eType result_code = mobile_apis::Result::INVALID_ENUM; - if (!result && hmi_apis::Common_Result::REJECTED == ui_result_) { - result_code = MessageHelper::HMIToMobileResult(vr_result_); - } else if (result && is_vr_or_ui_unsupported) { - LOG4CXX_DEBUG(logger_, "VR or UI result is unsupported resource"); - result_code = mobile_apis::Result::UNSUPPORTED_RESOURCE; - } else if (is_vr_or_ui_warning) { - LOG4CXX_DEBUG(logger_, "VR or UI result is warning"); - result_code = mobile_apis::Result::WARNINGS; - } else { - result_code = - MessageHelper::HMIToMobileResult(std::max(ui_result_, vr_result_)); - } - SendResponse( - result, result_code, info_.empty() ? NULL : info_.c_str(), &msg_params); + result, result_code, info.empty() ? NULL : info.c_str(), &msg_params); if (result) { application->UpdateHash(); } diff --git a/src/components/application_manager/src/commands/mobile/delete_sub_menu_request.cc b/src/components/application_manager/src/commands/mobile/delete_sub_menu_request.cc index bdb5521921..eec7960df8 100644 --- a/src/components/application_manager/src/commands/mobile/delete_sub_menu_request.cc +++ b/src/components/application_manager/src/commands/mobile/delete_sub_menu_request.cc @@ -33,6 +33,7 @@ #include "application_manager/commands/mobile/delete_sub_menu_request.h" +#include "application_manager/message_helper.h" #include "application_manager/application_impl.h" #include "interfaces/HMI_API.h" #include "utils/helpers.h" @@ -138,19 +139,18 @@ void DeleteSubMenuRequest::DeleteSubMenuUICommands( void DeleteSubMenuRequest::on_event(const event_engine::Event& event) { LOG4CXX_AUTO_TRACE(logger_); - using namespace helpers; const smart_objects::SmartObject& message = event.smart_object(); switch (event.id()) { case hmi_apis::FunctionID::UI_DeleteSubMenu: { - mobile_apis::Result::eType result_code = - static_cast<mobile_apis::Result::eType>( + hmi_apis::Common_Result::eType result_code = + static_cast<hmi_apis::Common_Result::eType>( message[strings::params][hmi_response::code].asInt()); - - const bool result = Compare<mobile_api::Result::eType, EQ, ONE>( - result_code, - mobile_api::Result::SUCCESS, - mobile_api::Result::WARNINGS); + std::string response_info; + GetInfo( + HmiInterfaces::HMI_INTERFACE_UI, result_code, message, response_info); + const bool result = PrepareResultForMobileResponse( + result_code, HmiInterfaces::HMI_INTERFACE_UI); ApplicationSharedPtr application = application_manager_.application(connection_key()); @@ -168,7 +168,10 @@ void DeleteSubMenuRequest::on_event(const event_engine::Event& event) { (*message_)[strings::msg_params][strings::menu_id].asInt()); } - SendResponse(result, result_code, NULL, &(message[strings::msg_params])); + SendResponse(result, + MessageHelper::HMIToMobileResult(result_code), + response_info.empty() ? NULL : response_info.c_str(), + &(message[strings::msg_params])); if (result) { application->UpdateHash(); } diff --git a/src/components/application_manager/src/commands/mobile/end_audio_pass_thru_request.cc b/src/components/application_manager/src/commands/mobile/end_audio_pass_thru_request.cc index 5a922f595f..25a83e5aef 100644 --- a/src/components/application_manager/src/commands/mobile/end_audio_pass_thru_request.cc +++ b/src/components/application_manager/src/commands/mobile/end_audio_pass_thru_request.cc @@ -32,6 +32,7 @@ */ #include "application_manager/commands/mobile/end_audio_pass_thru_request.h" +#include "application_manager/message_helper.h" namespace application_manager { @@ -55,12 +56,14 @@ void EndAudioPassThruRequest::on_event(const event_engine::Event& event) { switch (event.id()) { case hmi_apis::FunctionID::UI_EndAudioPassThru: { - mobile_apis::Result::eType mobile_code = - GetMobileResultCode(static_cast<hmi_apis::Common_Result::eType>( - message[strings::params][hmi_response::code].asUInt())); - - bool result = mobile_apis::Result::SUCCESS == mobile_code; - + hmi_apis::Common_Result::eType result_code = + static_cast<hmi_apis::Common_Result::eType>( + message[strings::params][hmi_response::code].asUInt()); + std::string response_info; + GetInfo( + HmiInterfaces::HMI_INTERFACE_UI, result_code, message, response_info); + const bool result = PrepareResultForMobileResponse( + result_code, HmiInterfaces::HMI_INTERFACE_UI); if (result) { bool ended_successfully = application_manager_.EndAudioPassThrough(); if (ended_successfully) { @@ -68,7 +71,10 @@ void EndAudioPassThruRequest::on_event(const event_engine::Event& event) { } } - SendResponse(result, mobile_code, NULL, &(message[strings::msg_params])); + SendResponse(result, + MessageHelper::HMIToMobileResult(result_code), + response_info.empty() ? NULL : response_info.c_str(), + &(message[strings::msg_params])); break; } default: { diff --git a/src/components/application_manager/src/commands/mobile/perform_audio_pass_thru_request.cc b/src/components/application_manager/src/commands/mobile/perform_audio_pass_thru_request.cc index d595119d45..b44d2144ee 100644 --- a/src/components/application_manager/src/commands/mobile/perform_audio_pass_thru_request.cc +++ b/src/components/application_manager/src/commands/mobile/perform_audio_pass_thru_request.cc @@ -47,8 +47,10 @@ namespace str = strings; PerformAudioPassThruRequest::PerformAudioPassThruRequest( const MessageSharedPtr& message, ApplicationManager& application_manager) : CommandRequestImpl(message, application_manager) - , is_active_tts_speak_(false) - , result_tts_speak_(mobile_apis::Result::SUCCESS) { + , awaiting_tts_speak_response_(false) + , awaiting_ui_response_(false) + , result_tts_speak_(hmi_apis::Common_Result::INVALID_ENUM) + , result_ui_(hmi_apis::Common_Result::INVALID_ENUM) { subscribe_on_event(hmi_apis::FunctionID::TTS_OnResetTimeout); } @@ -92,7 +94,10 @@ void PerformAudioPassThruRequest::Run() { SendResponse(false, mobile_apis::Result::INVALID_DATA); return; } + // According with new implementation processing of UNSUPPORTE_RESOURCE + // need set flag before sending to hmi + awaiting_ui_response_ = true; if ((*message_)[str::msg_params].keyExists(str::initial_prompt) && (0 < (*message_)[str::msg_params][str::initial_prompt].length())) { // In case TTS Speak, subscribe on notification @@ -114,56 +119,44 @@ void PerformAudioPassThruRequest::on_event(const event_engine::Event& event) { switch (event.id()) { case hmi_apis::FunctionID::UI_PerformAudioPassThru: { LOG4CXX_TRACE(logger_, "Received UI_PerformAudioPassThru"); + awaiting_ui_response_ = false; - if (!WaitTTSSpeak()) { - LOG4CXX_DEBUG(logger_, "TTS.Speak is absent"); - return; - } - - mobile_apis::Result::eType mobile_code = - GetMobileResultCode(static_cast<hmi_apis::Common_Result::eType>( - message[strings::params][hmi_response::code].asUInt())); + result_ui_ = static_cast<hmi_apis::Common_Result::eType>( + message[strings::params][hmi_response::code].asUInt()); + GetInfo(HmiInterfaces::HMI_INTERFACE_UI, result_ui_, message, ui_info_); // in case perform audio is started by other request skip stopping - if (mobile_apis::Result::REJECTED == mobile_code) { + if (hmi_apis::Common_Result::REJECTED == result_ui_) { LOG4CXX_ERROR(logger_, "Request was rejected"); - SendResponse(false, mobile_code, NULL, &(message[strings::msg_params])); + SendResponse(false, + MessageHelper::HMIToMobileResult(result_ui_), + NULL, + &(message[strings::msg_params])); return; } - FinishTTSSpeak(); - - std::string return_info; - const bool result = Compare<mobile_api::Result::eType, EQ, ONE>( - mobile_code, - mobile_apis::Result::SUCCESS, - mobile_apis::Result::RETRY, - mobile_apis::Result::WARNINGS); - - const bool is_result_ok = Compare<mobile_api::Result::eType, EQ, ONE>( - mobile_code, - mobile_apis::Result::SUCCESS, - mobile_apis::Result::WARNINGS); - - if (is_result_ok && - mobile_apis::Result::UNSUPPORTED_RESOURCE == result_tts_speak_) { - mobile_code = mobile_apis::Result::WARNINGS; - return_info = "Unsupported phoneme type sent in a prompt"; - } - - SendResponse(result, - mobile_code, - return_info.empty() ? NULL : return_info.c_str(), - &(message[strings::msg_params])); break; } case hmi_apis::FunctionID::TTS_Speak: { LOG4CXX_INFO(logger_, "Received TTS_Speak event"); - result_tts_speak_ = - GetMobileResultCode(static_cast<hmi_apis::Common_Result::eType>( - message[strings::params][hmi_response::code].asUInt())); - is_active_tts_speak_ = false; - if (mobile_apis::Result::SUCCESS == result_tts_speak_) { + result_tts_speak_ = static_cast<hmi_apis::Common_Result::eType>( + message[strings::params][hmi_response::code].asUInt()); + GetInfo(HmiInterfaces::HMI_INTERFACE_TTS, + result_tts_speak_, + message, + tts_info_); + awaiting_tts_speak_response_ = false; + const bool is_tts_speak_success_unsuported = + Compare<hmi_apis::Common_Result::eType, EQ, ONE>( + result_tts_speak_, + hmi_apis::Common_Result::SUCCESS, + hmi_apis::Common_Result::WARNINGS, + hmi_apis::Common_Result::WRONG_LANGUAGE, + hmi_apis::Common_Result::RETRY, + hmi_apis::Common_Result::SAVED, + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE); + + if (is_tts_speak_success_unsuported) { SendRecordStartNotification(); StartMicrophoneRecording(); @@ -185,6 +178,40 @@ void PerformAudioPassThruRequest::on_event(const event_engine::Event& event) { return; } } + if (IsWaitingHMIResponse()) { + return; + } + + std::string return_info; + mobile_apis::Result::eType result_code = mobile_apis::Result::INVALID_ENUM; + const bool result = PrepareResponseParameters(result_code, return_info); + + SendResponse(result, + result_code, + return_info.empty() ? NULL : return_info.c_str(), + &(message[strings::msg_params])); +} + +bool PerformAudioPassThruRequest::PrepareResponseParameters( + mobile_apis::Result::eType& result_code, std::string& info) { + LOG4CXX_AUTO_TRACE(logger_); + + ResponseInfo ui_perform_info(result_ui_, HmiInterfaces::HMI_INTERFACE_UI); + ResponseInfo tts_perform_info(result_tts_speak_, + HmiInterfaces::HMI_INTERFACE_TTS); + const bool result = + PrepareResultForMobileResponse(ui_perform_info, tts_perform_info); + + if (ui_perform_info.is_ok && tts_perform_info.is_unsupported_resource && + HmiInterfaces::STATE_AVAILABLE == tts_perform_info.interface_state) { + result_code = mobile_apis::Result::WARNINGS; + tts_info_ = "Unsupported phoneme type sent in a prompt"; + info = MergeInfos(ui_info_, tts_info_); + return result; + } + result_code = PrepareResultCodeForResponse(ui_perform_info, tts_perform_info); + info = MergeInfos(ui_info_, tts_info_); + return result; } void PerformAudioPassThruRequest::SendSpeakRequest() { @@ -194,23 +221,19 @@ void PerformAudioPassThruRequest::SendSpeakRequest() { using namespace smart_objects; SmartObject msg_params = smart_objects::SmartObject(SmartType_Map); - - if ((*message_)[str::msg_params].keyExists(str::initial_prompt) && - (0 < (*message_)[str::msg_params][str::initial_prompt].length())) { - for (uint32_t i = 0; - i < (*message_)[str::msg_params][str::initial_prompt].length(); - ++i) { - msg_params[hmi_request::tts_chunks][i][str::text] = - (*message_)[str::msg_params][str::initial_prompt][i][str::text]; - msg_params[hmi_request::tts_chunks][i][str::type] = - (*message_)[str::msg_params][str::initial_prompt][i][str::type]; - } - // app_id - msg_params[strings::app_id] = connection_key(); - msg_params[hmi_request::speak_type] = Common_MethodName::AUDIO_PASS_THRU; - is_active_tts_speak_ = true; - SendHMIRequest(FunctionID::TTS_Speak, &msg_params, true); + for (uint32_t i = 0; + i < (*message_)[str::msg_params][str::initial_prompt].length(); + ++i) { + msg_params[hmi_request::tts_chunks][i][str::text] = + (*message_)[str::msg_params][str::initial_prompt][i][str::text]; + msg_params[hmi_request::tts_chunks][i][str::type] = + (*message_)[str::msg_params][str::initial_prompt][i][str::type]; } + // app_id + msg_params[strings::app_id] = connection_key(); + msg_params[hmi_request::speak_type] = Common_MethodName::AUDIO_PASS_THRU; + awaiting_tts_speak_response_ = true; + SendHMIRequest(FunctionID::TTS_Speak, &msg_params, true); } void PerformAudioPassThruRequest::SendPerformAudioPassThruRequest() { @@ -333,37 +356,16 @@ void PerformAudioPassThruRequest::FinishTTSSpeak() { LOG4CXX_DEBUG(logger_, "Stop AudioPassThru."); application_manager_.StopAudioPassThru(connection_key()); } - if (!is_active_tts_speak_) { + if (!awaiting_tts_speak_response_) { LOG4CXX_WARN(logger_, "TTS Speak is inactive."); return; } - is_active_tts_speak_ = false; SendHMIRequest(hmi_apis::FunctionID::TTS_StopSpeaking, NULL); } -bool PerformAudioPassThruRequest::WaitTTSSpeak() { +bool PerformAudioPassThruRequest::IsWaitingHMIResponse() { LOG4CXX_AUTO_TRACE(logger_); - uint64_t default_timeout_msec = - application_manager_.get_settings().default_timeout(); - const TimevalStruct start_time = date_time::DateTime::getCurrentTime(); - - // Waiting for TTS_Speak - while (is_active_tts_speak_) { - uint64_t difference_between_start_current_time = - date_time::DateTime::calculateTimeSpan(start_time); - // Send GENERIC_ERROR after default timeout - if (difference_between_start_current_time > default_timeout_msec) { - LOG4CXX_WARN(logger_, "Expired timeout for TTS.Speak response"); - // Don't use onTimeOut(), because default_timeout_ is bigger than - // Default time in *.ini file - FinishTTSSpeak(); - SendResponse(false, - mobile_apis::Result::eType::GENERIC_ERROR, - "Expired timeout for TTS.Speak response"); - return false; - } - } - return true; + return awaiting_tts_speak_response_ || awaiting_ui_response_; } } // namespace commands diff --git a/src/components/application_manager/src/commands/mobile/perform_interaction_request.cc b/src/components/application_manager/src/commands/mobile/perform_interaction_request.cc index 39ad51e822..37987e5f5b 100644 --- a/src/components/application_manager/src/commands/mobile/perform_interaction_request.cc +++ b/src/components/application_manager/src/commands/mobile/perform_interaction_request.cc @@ -59,11 +59,9 @@ PerformInteractionRequest::PerformInteractionRequest( , interaction_mode_(mobile_apis::InteractionMode::INVALID_ENUM) , ui_response_recived_(false) , vr_response_recived_(false) - , ui_result_(false) - , vr_result_(false) , app_pi_was_active_before_(false) - , vr_resultCode_(mobile_apis::Result::INVALID_ENUM) - , ui_resultCode_(mobile_apis::Result::INVALID_ENUM) { + , vr_result_code_(hmi_apis::Common_Result::INVALID_ENUM) + , ui_result_code_(hmi_apis::Common_Result::INVALID_ENUM) { subscribe_on_event(hmi_apis::FunctionID::UI_OnResetTimeout); subscribe_on_event(hmi_apis::FunctionID::VR_OnCommand); subscribe_on_event(hmi_apis::FunctionID::Buttons_OnButtonPress); @@ -230,20 +228,26 @@ void PerformInteractionRequest::on_event(const event_engine::Event& event) { LOG4CXX_DEBUG(logger_, "Received UI_PerformInteraction event"); ui_response_recived_ = true; unsubscribe_from_event(hmi_apis::FunctionID::UI_PerformInteraction); - ui_resultCode_ = - GetMobileResultCode(static_cast<hmi_apis::Common_Result::eType>( - message[strings::params][hmi_response::code].asUInt())); - ProcessPerformInteractionResponse(event.smart_object(), msg_param); + ui_result_code_ = static_cast<hmi_apis::Common_Result::eType>( + message[strings::params][hmi_response::code].asUInt()); + GetInfo( + HmiInterfaces::HMI_INTERFACE_UI, ui_result_code_, message, ui_info_); + if (ProcessUIResponse(event.smart_object(), msg_param)) { + return; + } break; } case hmi_apis::FunctionID::VR_PerformInteraction: { LOG4CXX_DEBUG(logger_, "Received VR_PerformInteraction"); vr_response_recived_ = true; unsubscribe_from_event(hmi_apis::FunctionID::VR_PerformInteraction); - vr_resultCode_ = - GetMobileResultCode(static_cast<hmi_apis::Common_Result::eType>( - message[strings::params][hmi_response::code].asUInt())); - ProcessVRResponse(event.smart_object(), msg_param); + vr_result_code_ = static_cast<hmi_apis::Common_Result::eType>( + message[strings::params][hmi_response::code].asUInt()); + GetInfo( + HmiInterfaces::HMI_INTERFACE_VR, vr_result_code_, message, vr_info_); + if (ProcessVRResponse(event.smart_object(), msg_param)) { + return; + } break; } default: { @@ -252,8 +256,7 @@ void PerformInteractionRequest::on_event(const event_engine::Event& event) { } } - if (mobile_apis::InteractionMode::BOTH == interaction_mode_ && - !HasHMIResponsesToWait()) { + if (!HasHMIResponsesToWait()) { LOG4CXX_DEBUG(logger_, "Send response in BOTH iteraction mode"); SendBothModeResponse(msg_param); } @@ -292,12 +295,12 @@ void PerformInteractionRequest::onTimeOut() { }; } -void PerformInteractionRequest::ProcessVRResponse( +bool PerformInteractionRequest::ProcessVRResponse( const smart_objects::SmartObject& message, smart_objects::SmartObject& msg_params) { LOG4CXX_AUTO_TRACE(logger_); + using namespace hmi_apis; using namespace mobile_apis; - using namespace mobile_apis::Result; using namespace smart_objects; using namespace helpers; @@ -305,37 +308,36 @@ void PerformInteractionRequest::ProcessVRResponse( if (!app) { LOG4CXX_ERROR(logger_, "NULL pointer"); - return; + return false; } - CheckResponseResultCode(); msg_params[strings::trigger_source] = static_cast<int32_t>(TriggerSource::TS_VR); - const bool is_vr_aborted_timeout = - Compare<Result::eType, EQ, ONE>(vr_resultCode_, ABORTED, TIMED_OUT); + const bool is_vr_aborted_timeout = Compare<Common_Result::eType, EQ, ONE>( + vr_result_code_, Common_Result::ABORTED, Common_Result::TIMED_OUT); if (is_vr_aborted_timeout) { LOG4CXX_DEBUG(logger_, "VR response aborted"); if (InteractionMode::VR_ONLY == interaction_mode_) { LOG4CXX_DEBUG(logger_, "Aborted or Timeout Send Close Popup"); TerminatePerformInteraction(); - SendResponse(false, vr_resultCode_); - return; + SendResponse(false, MessageHelper::HMIToMobileResult(vr_result_code_)); + return true; } LOG4CXX_DEBUG(logger_, "Update timeout for UI"); application_manager_.updateRequestTimeout( connection_key(), correlation_id(), default_timeout()); - return; + return false; } - if (SUCCESS == vr_resultCode_ && + if (Common_Result::SUCCESS == vr_result_code_ && InteractionMode::MANUAL_ONLY == interaction_mode_) { LOG4CXX_DEBUG(logger_, "VR response SUCCESS in MANUAL_ONLY mode " << "Wait for UI response"); // in case MANUAL_ONLY mode VR.PI SUCCESS just return - return; + return false; } const SmartObject& hmi_msg_params = message[strings::msg_params]; @@ -345,26 +347,15 @@ void PerformInteractionRequest::ProcessVRResponse( LOG4CXX_ERROR(logger_, "Wrong choiceID was received from HMI"); TerminatePerformInteraction(); SendResponse( - false, GENERIC_ERROR, "Wrong choiceID was received from HMI"); - return; + false, Result::GENERIC_ERROR, "Wrong choiceID was received from HMI"); + return true; } msg_params[strings::choice_id] = choise_id; } - - vr_result_ = true; - - if (mobile_apis::InteractionMode::BOTH == interaction_mode_ && - mobile_apis::Result::SUCCESS != vr_resultCode_) { - LOG4CXX_DEBUG(logger_, "VR response isn't SUCCESS in BOTH mode"); - return; - } - - LOG4CXX_DEBUG(logger_, "VR response consider to be SUCCESS"); - TerminatePerformInteraction(); - SendResponse(vr_result_, SUCCESS, NULL, &msg_params); + return false; } -void PerformInteractionRequest::ProcessPerformInteractionResponse( +bool PerformInteractionRequest::ProcessUIResponse( const smart_objects::SmartObject& message, smart_objects::SmartObject& msg_params) { LOG4CXX_AUTO_TRACE(logger_); @@ -374,34 +365,40 @@ void PerformInteractionRequest::ProcessPerformInteractionResponse( ApplicationSharedPtr app = application_manager_.application(connection_key()); if (!app) { LOG4CXX_ERROR(logger_, "NULL pointer"); - return; + return false; } - ui_result_ = Compare<mobile_api::Result::eType, EQ, ONE>( - ui_resultCode_, - mobile_apis::Result::SUCCESS, - mobile_apis::Result::WARNINGS, - mobile_apis::Result::UNSUPPORTED_RESOURCE); + HmiInterfaces::InterfaceState ui_interface_state = + application_manager_.hmi_interfaces().GetInterfaceState( + HmiInterfaces::HMI_INTERFACE_UI); + bool result = false; + result = Compare<hmi_apis::Common_Result::eType, EQ, ONE>( + ui_result_code_, + hmi_apis::Common_Result::SUCCESS, + hmi_apis::Common_Result::WARNINGS); - const bool is_pi_warning = Compare<mobile_api::Result::eType, EQ, ONE>( - ui_resultCode_, mobile_apis::Result::WARNINGS); + result = result || + (hmi_apis::Common_Result::UNSUPPORTED_RESOURCE == ui_result_code_ && + HmiInterfaces::STATE_NOT_AVAILABLE != ui_interface_state); - const bool is_pi_unsupported = Compare<mobile_api::Result::eType, EQ, ONE>( - ui_resultCode_, mobile_apis::Result::UNSUPPORTED_RESOURCE); + const bool is_pi_warning = Compare<hmi_apis::Common_Result::eType, EQ, ONE>( + ui_result_code_, hmi_apis::Common_Result::WARNINGS); - std::string info; + const bool is_pi_unsupported = + Compare<hmi_apis::Common_Result::eType, EQ, ONE>( + ui_result_code_, hmi_apis::Common_Result::UNSUPPORTED_RESOURCE); - if (ui_result_) { + if (result) { if (is_pi_warning) { - ui_resultCode_ = mobile_apis::Result::WARNINGS; - info = "Unsupported phoneme type was sent in an item"; + ui_result_code_ = hmi_apis::Common_Result::WARNINGS; + ui_info_ = "Unsupported phoneme type was sent in an item"; if (message.keyExists(strings::params) && message[strings::params].keyExists(strings::data)) { msg_params = message[strings::params][strings::data]; } } else if (is_pi_unsupported) { - ui_resultCode_ = mobile_apis::Result::UNSUPPORTED_RESOURCE; - info = "Unsupported phoneme type was sent in an item"; + ui_result_code_ = hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; + ui_info_ = "Unsupported phoneme type was sent in an item"; } else if (message.keyExists(strings::msg_params)) { msg_params = message[strings::msg_params]; } @@ -409,8 +406,8 @@ void PerformInteractionRequest::ProcessPerformInteractionResponse( if (msg_params.keyExists(strings::choice_id)) { if (!CheckChoiceIDFromResponse(app, msg_params[strings::choice_id].asInt())) { - ui_resultCode_ = mobile_apis::Result::GENERIC_ERROR; - info = "Wrong choiceID was received from HMI"; + ui_result_code_ = hmi_apis::Common_Result::GENERIC_ERROR; + ui_info_ = "Wrong choiceID was received from HMI"; } else { msg_params[strings::trigger_source] = mobile_apis::TriggerSource::TS_MENU; @@ -424,14 +421,17 @@ void PerformInteractionRequest::ProcessPerformInteractionResponse( } } - DisablePerformInteraction(); - const SmartObject* response_params = msg_params.empty() ? NULL : &msg_params; - - if (mobile_apis::InteractionMode::BOTH != interaction_mode_) { + if (mobile_apis::InteractionMode::BOTH != interaction_mode_ && + HmiInterfaces::STATE_NOT_AVAILABLE != ui_interface_state) { DisablePerformInteraction(); - SendResponse(ui_result_, ui_resultCode_, info.c_str(), response_params); + SendResponse(result, + MessageHelper::HMIToMobileResult(ui_result_code_), + ui_info_.empty() ? NULL : ui_info_.c_str(), + response_params); + return true; } + return false; } void PerformInteractionRequest::SendUIPerformInteractionRequest( @@ -932,57 +932,27 @@ const bool PerformInteractionRequest::HasHMIResponsesToWait() const { return !ui_response_recived_ || !vr_response_recived_; } -void PerformInteractionRequest::CheckResponseResultCode() { - LOG4CXX_AUTO_TRACE(logger_); - mobile_apis::Result::eType resultCode = mobile_apis::Result::INVALID_ENUM; - bool result = false; - if (mobile_apis::Result::GENERIC_ERROR == vr_resultCode_) { - LOG4CXX_DEBUG(logger_, "VR response GENERIC_ERROR"); - resultCode = mobile_apis::Result::GENERIC_ERROR; - } else if (mobile_apis::Result::REJECTED == vr_resultCode_) { - LOG4CXX_DEBUG(logger_, "VR had been rejected."); - resultCode = mobile_apis::Result::REJECTED; - } else if (mobile_apis::Result::WARNINGS == vr_resultCode_ || - mobile_apis::Result::UNSUPPORTED_REQUEST == vr_resultCode_) { - LOG4CXX_DEBUG(logger_, "VR response WARNINGS"); - resultCode = mobile_api::Result::WARNINGS; - result = true; - } - - if (mobile_apis::Result::INVALID_ENUM != resultCode) { - TerminatePerformInteraction(); - SendResponse(result, resultCode); - } -} - void PerformInteractionRequest::SendBothModeResponse( const smart_objects::SmartObject& msg_param) { LOG4CXX_AUTO_TRACE(logger_); - using namespace mobile_apis::Result; - - bool result = ui_result_ || vr_result_; - mobile_apis::Result::eType perform_interaction_result_code = ui_resultCode_; - - if (UNSUPPORTED_RESOURCE == vr_resultCode_ && - UNSUPPORTED_RESOURCE != ui_resultCode_) { - perform_interaction_result_code = vr_resultCode_; - } else if (UNSUPPORTED_RESOURCE == vr_resultCode_ && - UNSUPPORTED_RESOURCE == ui_resultCode_) { - result = false; - } - - const bool is_error_code = (SUCCESS != perform_interaction_result_code || - WARNINGS != perform_interaction_result_code); - - if (vr_resultCode_ == ui_resultCode_ && is_error_code) { - result = false; - } - + mobile_apis::Result::eType perform_interaction_result_code = + mobile_apis::Result::INVALID_ENUM; + ResponseInfo ui_perform_info(ui_result_code_, + HmiInterfaces::HMI_INTERFACE_UI); + ResponseInfo vr_perform_info(vr_result_code_, + HmiInterfaces::HMI_INTERFACE_VR); + const bool result = + PrepareResultForMobileResponse(ui_perform_info, vr_perform_info); + perform_interaction_result_code = + PrepareResultCodeForResponse(ui_perform_info, vr_perform_info); const smart_objects::SmartObject* response_params = msg_param.empty() ? NULL : &msg_param; - - TerminatePerformInteraction(); - SendResponse(result, perform_interaction_result_code, NULL, response_params); + std::string info = MergeInfos(ui_info_, vr_info_); + DisablePerformInteraction(); + SendResponse(result, + perform_interaction_result_code, + info.empty() ? NULL : info.c_str(), + response_params); } } // namespace commands diff --git a/src/components/application_manager/src/commands/mobile/register_app_interface_request.cc b/src/components/application_manager/src/commands/mobile/register_app_interface_request.cc index dd44825b64..34c0863ddf 100644 --- a/src/components/application_manager/src/commands/mobile/register_app_interface_request.cc +++ b/src/components/application_manager/src/commands/mobile/register_app_interface_request.cc @@ -578,7 +578,7 @@ void RegisterAppInterfaceRequest::SendRegisterAppInterfaceResponseToMobile() { // By default app subscribed to CUSTOM_BUTTON SendSubscribeCustomButtonNotification(); - SendChangeRagistrationOnHMI(application); + SendChangeRegistrationOnHMI(application); } void RegisterAppInterfaceRequest::SendChangeRegistration( @@ -602,7 +602,7 @@ void RegisterAppInterfaceRequest::SendChangeRegistration( } } -void RegisterAppInterfaceRequest::SendChangeRagistrationOnHMI( +void RegisterAppInterfaceRequest::SendChangeRegistrationOnHMI( ApplicationConstSharedPtr app) { using namespace hmi_apis::FunctionID; DCHECK_OR_RETURN_VOID(app); diff --git a/src/components/application_manager/src/commands/mobile/scrollable_message_request.cc b/src/components/application_manager/src/commands/mobile/scrollable_message_request.cc index 89bd43fcd6..a897aba811 100644 --- a/src/components/application_manager/src/commands/mobile/scrollable_message_request.cc +++ b/src/components/application_manager/src/commands/mobile/scrollable_message_request.cc @@ -115,7 +115,6 @@ void ScrollableMessageRequest::Run() { void ScrollableMessageRequest::on_event(const event_engine::Event& event) { LOG4CXX_AUTO_TRACE(logger_); - using namespace helpers; const smart_objects::SmartObject& message = event.smart_object(); switch (event.id()) { @@ -128,24 +127,20 @@ void ScrollableMessageRequest::on_event(const event_engine::Event& event) { case hmi_apis::FunctionID::UI_ScrollableMessage: { LOG4CXX_INFO(logger_, "Received UI_ScrollableMessage event"); - mobile_apis::Result::eType result_code = - static_cast<mobile_apis::Result::eType>( + hmi_apis::Common_Result::eType result_code = + static_cast<hmi_apis::Common_Result::eType>( message[strings::params][hmi_response::code].asInt()); + std::string response_info; + GetInfo( + HmiInterfaces::HMI_INTERFACE_UI, result_code, message, response_info); - HMICapabilities& hmi_capabilities = - application_manager_.hmi_capabilities(); + const bool result = PrepareResultForMobileResponse( + result_code, HmiInterfaces::HMI_INTERFACE_UI); - bool result = Compare<mobile_api::Result::eType, EQ, ONE>( - result_code, - mobile_api::Result::SUCCESS, - mobile_api::Result::WARNINGS); - - if (mobile_apis::Result::UNSUPPORTED_RESOURCE == result_code && - hmi_capabilities.is_ui_cooperating()) { - result = true; - } - - SendResponse(result, result_code, NULL, &(message[strings::msg_params])); + SendResponse(result, + MessageHelper::HMIToMobileResult(result_code), + response_info.empty() ? NULL : response_info.c_str(), + &(message[strings::msg_params])); break; } default: { diff --git a/src/components/application_manager/src/commands/mobile/set_app_icon_request.cc b/src/components/application_manager/src/commands/mobile/set_app_icon_request.cc index 40b708e30d..e7130d8e17 100644 --- a/src/components/application_manager/src/commands/mobile/set_app_icon_request.cc +++ b/src/components/application_manager/src/commands/mobile/set_app_icon_request.cc @@ -34,6 +34,7 @@ #include <algorithm> #include "application_manager/commands/mobile/set_app_icon_request.h" +#include "application_manager/message_helper.h" #include "application_manager/application_impl.h" #include "interfaces/MOBILE_API.h" #include "interfaces/HMI_API.h" @@ -229,20 +230,18 @@ bool SetAppIconRequest::IsEnoughSpaceForIcon(const uint64_t icon_size) const { void SetAppIconRequest::on_event(const event_engine::Event& event) { LOG4CXX_AUTO_TRACE(logger_); - using namespace helpers; const smart_objects::SmartObject& message = event.smart_object(); switch (event.id()) { case hmi_apis::FunctionID::UI_SetAppIcon: { - mobile_apis::Result::eType result_code = - static_cast<mobile_apis::Result::eType>( + hmi_apis::Common_Result::eType result_code = + static_cast<hmi_apis::Common_Result::eType>( message[strings::params][hmi_response::code].asInt()); - - const bool result = Compare<mobile_api::Result::eType, EQ, ONE>( - result_code, - mobile_api::Result::SUCCESS, - mobile_api::Result::WARNINGS); - + const bool result = PrepareResultForMobileResponse( + result_code, HmiInterfaces::HMI_INTERFACE_UI); + std::string response_info; + GetInfo( + HmiInterfaces::HMI_INTERFACE_UI, result_code, message, response_info); if (result) { ApplicationSharedPtr app = application_manager_.application(connection_key()); @@ -261,7 +260,10 @@ void SetAppIconRequest::on_event(const event_engine::Event& event) { "Icon path was set to '" << app->app_icon_path() << "'"); } - SendResponse(result, result_code, NULL, &(message[strings::msg_params])); + SendResponse(result, + MessageHelper::HMIToMobileResult(result_code), + response_info.empty() ? NULL : response_info.c_str(), + &(message[strings::msg_params])); break; } default: { diff --git a/src/components/application_manager/src/commands/mobile/set_display_layout_request.cc b/src/components/application_manager/src/commands/mobile/set_display_layout_request.cc index 6cb6318791..b4122b9210 100644 --- a/src/components/application_manager/src/commands/mobile/set_display_layout_request.cc +++ b/src/components/application_manager/src/commands/mobile/set_display_layout_request.cc @@ -33,6 +33,7 @@ #include "application_manager/commands/mobile/set_display_layout_request.h" +#include "application_manager/message_helper.h" #include "application_manager/application_impl.h" namespace application_manager { @@ -69,14 +70,14 @@ void SetDisplayLayoutRequest::on_event(const event_engine::Event& event) { switch (event.id()) { case hmi_apis::FunctionID::UI_SetDisplayLayout: { LOG4CXX_INFO(logger_, "Received UI_SetDisplayLayout event"); - - mobile_apis::Result::eType result_code = - static_cast<mobile_apis::Result::eType>( + hmi_apis::Common_Result::eType result_code = + static_cast<hmi_apis::Common_Result::eType>( message[strings::params][hmi_response::code].asInt()); - bool response_success = mobile_apis::Result::SUCCESS == result_code; - + const bool response_success = PrepareResultForMobileResponse( + result_code, HmiInterfaces::HMI_INTERFACE_UI); + std::string info; + GetInfo(HmiInterfaces::HMI_INTERFACE_UI, result_code, message, info); smart_objects::SmartObject msg_params = message[strings::msg_params]; - if (response_success) { HMICapabilities& hmi_capabilities = application_manager_.hmi_capabilities(); @@ -93,7 +94,10 @@ void SetDisplayLayoutRequest::on_event(const event_engine::Event& event) { } } } - SendResponse(response_success, result_code, NULL, &msg_params); + SendResponse(response_success, + MessageHelper::HMIToMobileResult(result_code), + info.empty() ? NULL : info.c_str(), + &msg_params); break; } default: { diff --git a/src/components/application_manager/src/commands/mobile/set_global_properties_request.cc b/src/components/application_manager/src/commands/mobile/set_global_properties_request.cc index 171b902df1..1dd56faea5 100644 --- a/src/components/application_manager/src/commands/mobile/set_global_properties_request.cc +++ b/src/components/application_manager/src/commands/mobile/set_global_properties_request.cc @@ -127,6 +127,12 @@ void SetGlobalPropertiesRequest::Run() { SendResponse(false, mobile_apis::Result::REJECTED); return; } + + /* Need to set flags before sending request to HMI + * for correct processing this flags in method on_event */ + if (is_help_prompt_present || is_timeout_prompt_present) { + is_tts_send_ = true; + } if (is_vr_help_title_present && is_vr_help_present) { LOG4CXX_DEBUG(logger_, "VRHelp params presents"); @@ -226,6 +232,10 @@ void SetGlobalPropertiesRequest::on_event(const event_engine::Event& event) { is_ui_received_ = true; ui_result_ = static_cast<hmi_apis::Common_Result::eType>( message[strings::params][hmi_response::code].asInt()); + GetInfo(HmiInterfaces::HMI_INTERFACE_UI, + ui_result_, + message, + ui_response_info_); break; } case hmi_apis::FunctionID::TTS_SetGlobalProperties: { @@ -233,6 +243,10 @@ void SetGlobalPropertiesRequest::on_event(const event_engine::Event& event) { is_tts_received_ = true; tts_result_ = static_cast<hmi_apis::Common_Result::eType>( message[strings::params][hmi_response::code].asInt()); + GetInfo(HmiInterfaces::HMI_INTERFACE_TTS, + tts_result_, + message, + tts_response_info_); break; } default: { @@ -245,54 +259,18 @@ void SetGlobalPropertiesRequest::on_event(const event_engine::Event& event) { LOG4CXX_DEBUG(logger_, "Continue waiting for response"); return; } - - const bool is_tts_succeeded = - Compare<hmi_apis::Common_Result::eType, EQ, ONE>( - tts_result_, - hmi_apis::Common_Result::SUCCESS, - hmi_apis::Common_Result::UNSUPPORTED_RESOURCE, - hmi_apis::Common_Result::WARNINGS); - - const bool is_ui_succeeded = Compare<hmi_apis::Common_Result::eType, EQ, ONE>( - ui_result_, - hmi_apis::Common_Result::SUCCESS, - hmi_apis::Common_Result::UNSUPPORTED_RESOURCE, - hmi_apis::Common_Result::WARNINGS); - - const bool is_ui_invalid_unsupported = - Compare<hmi_apis::Common_Result::eType, EQ, ONE>( - ui_result_, - hmi_apis::Common_Result::INVALID_ENUM, - hmi_apis::Common_Result::UNSUPPORTED_RESOURCE); - - bool result = (is_tts_succeeded && is_ui_succeeded) || - (is_ui_succeeded && - hmi_apis::Common_Result::INVALID_ENUM == tts_result_) || - (is_ui_invalid_unsupported && is_tts_succeeded); - mobile_apis::Result::eType result_code = mobile_apis::Result::INVALID_ENUM; - const char* return_info = NULL; - - const bool is_ui_or_tts_warning = - Compare<hmi_apis::Common_Result::eType, EQ, ONE>( - hmi_apis::Common_Result::WARNINGS, tts_result_, ui_result_); - - if (result && (hmi_apis::Common_Result::UNSUPPORTED_RESOURCE == tts_result_ || - is_ui_or_tts_warning)) { - result_code = mobile_apis::Result::WARNINGS; - return_info = - std::string("Unsupported phoneme type sent in a prompt").c_str(); - } else { - result_code = - MessageHelper::HMIToMobileResult(std::max(ui_result_, tts_result_)); - } + std::string response_info; + const bool result = PrepareResponseParameters(result_code, response_info); // TODO{ALeshin} APPLINK-15858. connection_key removed during SendResponse ApplicationSharedPtr application = application_manager_.application(connection_key()); - SendResponse( - result, result_code, return_info, &(message[strings::msg_params])); + SendResponse(result, + result_code, + response_info.empty() ? NULL : response_info.c_str(), + &(message[strings::msg_params])); if (!application) { LOG4CXX_DEBUG(logger_, "NULL pointer."); @@ -304,6 +282,31 @@ void SetGlobalPropertiesRequest::on_event(const event_engine::Event& event) { } } +bool SetGlobalPropertiesRequest::PrepareResponseParameters( + mobile_apis::Result::eType& result_code, std::string& info) { + LOG4CXX_AUTO_TRACE(logger_); + using namespace helpers; + + ResponseInfo ui_properties_info(ui_result_, HmiInterfaces::HMI_INTERFACE_UI); + + ResponseInfo tts_properties_info(tts_result_, + HmiInterfaces::HMI_INTERFACE_TTS); + const bool result = + PrepareResultForMobileResponse(ui_properties_info, tts_properties_info); + if (result && + (HmiInterfaces::STATE_AVAILABLE == tts_properties_info.interface_state) && + (tts_properties_info.is_unsupported_resource)) { + result_code = mobile_apis::Result::WARNINGS; + tts_response_info_ = "Unsupported phoneme type sent in a prompt"; + info = MergeInfos(tts_response_info_, ui_response_info_); + return result; + } + result_code = + PrepareResultCodeForResponse(ui_properties_info, tts_properties_info); + info = MergeInfos(tts_response_info_, ui_response_info_); + return result; +} + bool SetGlobalPropertiesRequest::ValidateVRHelpTitle( const smart_objects::SmartObject* const vr_help_so_ptr) { LOG4CXX_AUTO_TRACE(logger_); @@ -397,17 +400,17 @@ void SetGlobalPropertiesRequest::PrepareUIRequestMenuAndKeyboardData( void SetGlobalPropertiesRequest::SendTTSRequest( const smart_objects::SmartObject& params, bool use_events) { LOG4CXX_AUTO_TRACE(logger_); + is_tts_send_ = true; SendHMIRequest( hmi_apis::FunctionID::TTS_SetGlobalProperties, ¶ms, use_events); - is_tts_send_ = true; } void SetGlobalPropertiesRequest::SendUIRequest( const smart_objects::SmartObject& params, bool use_events) { LOG4CXX_AUTO_TRACE(logger_); + is_ui_send_ = true; SendHMIRequest( hmi_apis::FunctionID::UI_SetGlobalProperties, ¶ms, use_events); - is_ui_send_ = true; } bool SetGlobalPropertiesRequest::IsPendingResponseExist() { diff --git a/src/components/application_manager/src/commands/mobile/set_media_clock_timer_request.cc b/src/components/application_manager/src/commands/mobile/set_media_clock_timer_request.cc index a198ce63c3..1ec6a26ae5 100644 --- a/src/components/application_manager/src/commands/mobile/set_media_clock_timer_request.cc +++ b/src/components/application_manager/src/commands/mobile/set_media_clock_timer_request.cc @@ -33,6 +33,7 @@ #include "application_manager/commands/mobile/set_media_clock_timer_request.h" +#include "application_manager/message_helper.h" #include "application_manager/application_impl.h" #include "interfaces/MOBILE_API.h" #include "interfaces/HMI_API.h" @@ -84,13 +85,19 @@ void SetMediaClockRequest::on_event(const event_engine::Event& event) { switch (event.id()) { case hmi_apis::FunctionID::UI_SetMediaClockTimer: { - mobile_apis::Result::eType result_code = - static_cast<mobile_apis::Result::eType>( + hmi_apis::Common_Result::eType result_code = + static_cast<hmi_apis::Common_Result::eType>( message[strings::params][hmi_response::code].asInt()); - - bool result = mobile_apis::Result::SUCCESS == result_code; - - SendResponse(result, result_code, NULL, &(message[strings::msg_params])); + const bool result = PrepareResultForMobileResponse( + result_code, HmiInterfaces::HMI_INTERFACE_UI); + std::string response_info; + GetInfo( + HmiInterfaces::HMI_INTERFACE_UI, result_code, message, response_info); + + SendResponse(result, + MessageHelper::HMIToMobileResult(result_code), + response_info.empty() ? NULL : response_info.c_str(), + &(message[strings::msg_params])); break; } default: { diff --git a/src/components/application_manager/src/commands/mobile/show_request.cc b/src/components/application_manager/src/commands/mobile/show_request.cc index 467d8d0236..d518c8fdc3 100644 --- a/src/components/application_manager/src/commands/mobile/show_request.cc +++ b/src/components/application_manager/src/commands/mobile/show_request.cc @@ -228,23 +228,22 @@ void ShowRequest::on_event(const event_engine::Event& event) { case hmi_apis::FunctionID::UI_Show: { LOG4CXX_DEBUG(logger_, "Received UI_Show event."); std::string response_info; - mobile_apis::Result::eType result_code = - static_cast<mobile_apis::Result::eType>( + hmi_apis::Common_Result::eType result_code = + static_cast<hmi_apis::Common_Result::eType>( message[strings::params][hmi_response::code].asInt()); - - const bool result = Compare<mobile_api::Result::eType, EQ, ONE>( - result_code, - mobile_api::Result::SUCCESS, - mobile_api::Result::WARNINGS); - - if (mobile_apis::Result::WARNINGS == result_code && + const bool result = PrepareResultForMobileResponse( + result_code, HmiInterfaces::HMI_INTERFACE_UI); + GetInfo(HmiInterfaces::InterfaceID::HMI_INTERFACE_UI, + result_code, + message, + response_info); + if (hmi_apis::Common_Result::WARNINGS == result_code && message[strings::params].keyExists(hmi_response::message)) { response_info = message[strings::params][hmi_response::message].asString(); } - SendResponse(result, - result_code, + MessageHelper::HMIToMobileResult(result_code), response_info.empty() ? NULL : response_info.c_str(), &(message[strings::msg_params])); break; diff --git a/src/components/application_manager/src/commands/mobile/slider_request.cc b/src/components/application_manager/src/commands/mobile/slider_request.cc index 3920b49db3..8170c3ce52 100644 --- a/src/components/application_manager/src/commands/mobile/slider_request.cc +++ b/src/components/application_manager/src/commands/mobile/slider_request.cc @@ -154,13 +154,15 @@ void SliderRequest::on_event(const event_engine::Event& event) { response_msg_params[strings::slider_position] = 0; } } - - const bool is_response_success = Compare<Common_Result::eType, EQ, ONE>( - response_code, Common_Result::SUCCESS, Common_Result::WARNINGS); + std::string response_info; + GetInfo( + HmiInterfaces::HMI_INTERFACE_UI, response_code, message, response_info); + const bool is_response_success = PrepareResultForMobileResponse( + response_code, HmiInterfaces::HMI_INTERFACE_UI); SendResponse(is_response_success, MessageHelper::HMIToMobileResult(response_code), - 0, + response_info.empty() ? NULL : response_info.c_str(), &response_msg_params); } diff --git a/src/components/application_manager/src/hmi_capabilities_impl.cc b/src/components/application_manager/src/hmi_capabilities_impl.cc index 07b691f889..c6fa321401 100644 --- a/src/components/application_manager/src/hmi_capabilities_impl.cc +++ b/src/components/application_manager/src/hmi_capabilities_impl.cc @@ -324,11 +324,6 @@ HMICapabilitiesImpl::HMICapabilitiesImpl(ApplicationManager& app_mngr) , is_ui_cooperating_(false) , is_navi_cooperating_(false) , is_ivi_cooperating_(false) - , is_vr_ready_response_recieved_(false) - , is_tts_ready_response_recieved_(false) - , is_ui_ready_response_recieved_(false) - , is_navi_ready_response_recieved_(false) - , is_ivi_ready_response_recieved_(false) , attenuated_supported_(false) , ui_language_(hmi_apis::Common_Language::INVALID_ENUM) , vr_language_(hmi_apis::Common_Language::INVALID_ENUM) @@ -353,12 +348,6 @@ HMICapabilitiesImpl::HMICapabilitiesImpl(ApplicationManager& app_mngr) , hmi_language_handler_(app_mngr) { InitCapabilities(); if (false == app_mngr_.get_settings().launch_hmi()) { - is_vr_ready_response_recieved_ = true; - is_tts_ready_response_recieved_ = true; - is_ui_ready_response_recieved_ = true; - is_navi_ready_response_recieved_ = true; - is_ivi_ready_response_recieved_ = true; - is_vr_cooperating_ = true; is_tts_cooperating_ = true; is_ui_cooperating_ = true; @@ -384,45 +373,6 @@ HMICapabilitiesImpl::~HMICapabilitiesImpl() { delete prerecorded_speech_; } -bool HMICapabilitiesImpl::is_hmi_capabilities_initialized() const { - bool result = true; - - if (is_vr_ready_response_recieved_ && is_tts_ready_response_recieved_ && - is_ui_ready_response_recieved_ && is_navi_ready_response_recieved_ && - is_ivi_ready_response_recieved_) { - if (is_vr_cooperating_) { - if ((!vr_supported_languages_) || - (hmi_apis::Common_Language::INVALID_ENUM == vr_language_)) { - result = false; - } - } - - if (is_tts_cooperating_) { - if ((!tts_supported_languages_) || - (hmi_apis::Common_Language::INVALID_ENUM == tts_language_)) { - result = false; - } - } - - if (is_ui_cooperating_) { - if ((!ui_supported_languages_) || - (hmi_apis::Common_Language::INVALID_ENUM == ui_language_)) { - result = false; - } - } - - if (is_ivi_cooperating_) { - if (!vehicle_type_) { - result = false; - } - } - } else { - result = false; - } - - return result; -} - bool HMICapabilitiesImpl::VerifyImageType(const int32_t image_type) const { if (!display_capabilities_) { return false; @@ -442,79 +392,23 @@ bool HMICapabilitiesImpl::VerifyImageType(const int32_t image_type) const { } void HMICapabilitiesImpl::set_is_vr_cooperating(const bool value) { - is_vr_ready_response_recieved_ = true; is_vr_cooperating_ = value; - if (is_vr_cooperating_) { - utils::SharedPtr<smart_objects::SmartObject> get_language( - MessageHelper::CreateModuleInfoSO(hmi_apis::FunctionID::VR_GetLanguage, - app_mngr_)); - hmi_language_handler_.set_handle_response_for(*get_language); - app_mngr_.ManageHMICommand(get_language); - utils::SharedPtr<smart_objects::SmartObject> get_all_languages( - MessageHelper::CreateModuleInfoSO( - hmi_apis::FunctionID::VR_GetSupportedLanguages, app_mngr_)); - app_mngr_.ManageHMICommand(get_all_languages); - utils::SharedPtr<smart_objects::SmartObject> get_capabilities( - MessageHelper::CreateModuleInfoSO( - hmi_apis::FunctionID::VR_GetCapabilities, app_mngr_)); - app_mngr_.ManageHMICommand(get_capabilities); - } } void HMICapabilitiesImpl::set_is_tts_cooperating(const bool value) { - is_tts_ready_response_recieved_ = true; is_tts_cooperating_ = value; - if (is_tts_cooperating_) { - utils::SharedPtr<smart_objects::SmartObject> get_language( - MessageHelper::CreateModuleInfoSO(hmi_apis::FunctionID::TTS_GetLanguage, - app_mngr_)); - hmi_language_handler_.set_handle_response_for(*get_language); - app_mngr_.ManageHMICommand(get_language); - utils::SharedPtr<smart_objects::SmartObject> get_all_languages( - MessageHelper::CreateModuleInfoSO( - hmi_apis::FunctionID::TTS_GetSupportedLanguages, app_mngr_)); - app_mngr_.ManageHMICommand(get_all_languages); - utils::SharedPtr<smart_objects::SmartObject> get_capabilities( - MessageHelper::CreateModuleInfoSO( - hmi_apis::FunctionID::TTS_GetCapabilities, app_mngr_)); - app_mngr_.ManageHMICommand(get_capabilities); - } } void HMICapabilitiesImpl::set_is_ui_cooperating(const bool value) { - is_ui_ready_response_recieved_ = true; is_ui_cooperating_ = value; - if (is_ui_cooperating_) { - utils::SharedPtr<smart_objects::SmartObject> get_language( - MessageHelper::CreateModuleInfoSO(hmi_apis::FunctionID::UI_GetLanguage, - app_mngr_)); - hmi_language_handler_.set_handle_response_for(*get_language); - app_mngr_.ManageHMICommand(get_language); - utils::SharedPtr<smart_objects::SmartObject> get_all_languages( - MessageHelper::CreateModuleInfoSO( - hmi_apis::FunctionID::UI_GetSupportedLanguages, app_mngr_)); - app_mngr_.ManageHMICommand(get_all_languages); - utils::SharedPtr<smart_objects::SmartObject> get_capabilities( - MessageHelper::CreateModuleInfoSO( - hmi_apis::FunctionID::UI_GetCapabilities, app_mngr_)); - app_mngr_.ManageHMICommand(get_capabilities); - } } void HMICapabilitiesImpl::set_is_navi_cooperating(const bool value) { - is_navi_ready_response_recieved_ = true; is_navi_cooperating_ = value; } void HMICapabilitiesImpl::set_is_ivi_cooperating(const bool value) { - is_ivi_ready_response_recieved_ = true; is_ivi_cooperating_ = value; - if (is_ivi_cooperating_) { - utils::SharedPtr<smart_objects::SmartObject> get_type( - MessageHelper::CreateModuleInfoSO( - hmi_apis::FunctionID::VehicleInfo_GetVehicleType, app_mngr_)); - app_mngr_.ManageHMICommand(get_type); - } } void HMICapabilitiesImpl::set_attenuated_supported(const bool state) { @@ -1179,4 +1073,9 @@ HMILanguageHandler& HMICapabilitiesImpl::get_hmi_language_handler() { return hmi_language_handler_; } +void HMICapabilitiesImpl::set_handle_response_for( + const smart_objects::SmartObject& request) { + hmi_language_handler_.set_handle_response_for(request); +} + } // namespace application_manager diff --git a/src/components/application_manager/src/hmi_interfaces_impl.cc b/src/components/application_manager/src/hmi_interfaces_impl.cc index 08f5d3cc93..5665d0654a 100644 --- a/src/components/application_manager/src/hmi_interfaces_impl.cc +++ b/src/components/application_manager/src/hmi_interfaces_impl.cc @@ -120,7 +120,7 @@ generate_function_to_interface_convert_map() { convert_map[VR_GetSupportedLanguages] = HmiInterfaces::HMI_INTERFACE_VR; convert_map[VR_GetLanguage] = HmiInterfaces::HMI_INTERFACE_VR; convert_map[VR_GetCapabilities] = HmiInterfaces::HMI_INTERFACE_VR; - convert_map[TTS_GetCapabilities] = HmiInterfaces::HMI_INTERFACE_VR; + convert_map[TTS_GetCapabilities] = HmiInterfaces::HMI_INTERFACE_TTS; convert_map[TTS_Started] = HmiInterfaces::HMI_INTERFACE_TTS; convert_map[TTS_Stopped] = HmiInterfaces::HMI_INTERFACE_TTS; convert_map[TTS_IsReady] = HmiInterfaces::HMI_INTERFACE_TTS; diff --git a/src/components/application_manager/test/commands/hmi/CMakeLists.txt b/src/components/application_manager/test/commands/hmi/CMakeLists.txt index 4345ec58ab..6175fe9e19 100644 --- a/src/components/application_manager/test/commands/hmi/CMakeLists.txt +++ b/src/components/application_manager/test/commands/hmi/CMakeLists.txt @@ -39,9 +39,9 @@ include_directories( set (SOURCES ${AM_SOURCE_DIR}/src/smart_object_keys.cc ${AM_SOURCE_DIR}/test/mock_message_helper.cc - ${COMMANDS_TEST_SOURCE_DIR}/hmi/vi_is_ready_response_test.cc - ${COMMANDS_TEST_SOURCE_DIR}/hmi/vr_is_ready_response_test.cc -) + ${COMMANDS_TEST_SOURCE_DIR}/hmi/vi_is_ready_request_test.cc + ${COMMANDS_TEST_SOURCE_DIR}/hmi/vr_is_ready_request_test.cc + ) set(LIBRARIES gmock diff --git a/src/components/application_manager/test/commands/hmi/vi_is_ready_request_test.cc b/src/components/application_manager/test/commands/hmi/vi_is_ready_request_test.cc new file mode 100644 index 0000000000..aa4b450a98 --- /dev/null +++ b/src/components/application_manager/test/commands/hmi/vi_is_ready_request_test.cc @@ -0,0 +1,175 @@ +/* + * Copyright (c) 2016, 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 "application_manager/commands/hmi/vi_is_ready_request.h" + +#include "gtest/gtest.h" +#include "utils/shared_ptr.h" +#include "smart_objects/smart_object.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/hmi_interfaces.h" +#include "application_manager/mock_hmi_interface.h" +#include "application_manager/mock_hmi_capabilities.h" +#include "application_manager/policies/mock_policy_handler_interface.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/event_engine/event.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { + +using ::testing::_; +using ::testing::ReturnRef; +using ::testing::Return; +namespace am = ::application_manager; +using am::commands::MessageSharedPtr; +using am::commands::VIIsReadyRequest; +using am::MockMessageHelper; +using am::event_engine::Event; + +typedef SharedPtr<VIIsReadyRequest> VIIsReadyRequestPtr; + +class VIIsReadyRequestTest + : public CommandRequestTest<CommandsTestMocks::kIsNice> { + public: + VIIsReadyRequestTest() : command_(CreateCommand<VIIsReadyRequest>()) {} + + void SetUpExpectations(bool is_vi_cooperating_available, + bool is_send_message_to_hmi, + bool is_message_contain_param, + am::HmiInterfaces::InterfaceState state) { + EXPECT_CALL(app_mngr_, hmi_capabilities()) + .WillOnce(ReturnRef(mock_hmi_capabilities_)); + EXPECT_CALL(mock_hmi_capabilities_, + set_is_ivi_cooperating(is_vi_cooperating_available)); + + if (is_message_contain_param) { + EXPECT_CALL(app_mngr_, hmi_interfaces()) + .WillRepeatedly(ReturnRef(mock_hmi_interfaces_)); + EXPECT_CALL(mock_hmi_interfaces_, + SetInterfaceState( + am::HmiInterfaces::HMI_INTERFACE_VehicleInfo, state)); + } else { + EXPECT_CALL(app_mngr_, hmi_interfaces()) + .WillOnce(ReturnRef(mock_hmi_interfaces_)); + EXPECT_CALL(mock_hmi_interfaces_, SetInterfaceState(_, _)).Times(0); + } + EXPECT_CALL(app_mngr_, GetPolicyHandler()) + .WillOnce(ReturnRef(mock_policy_handler_interface_)); + EXPECT_CALL(mock_policy_handler_interface_, OnVIIsReady()); + + EXPECT_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_VehicleInfo)) + .WillOnce(Return(state)); + + if (is_send_message_to_hmi) { + ExpectSendMessagesToHMI(); + } + } + + void ExpectSendMessagesToHMI() { + smart_objects::SmartObjectSPtr ivi_type; + EXPECT_CALL( + *(MockMessageHelper::message_helper_mock()), + CreateModuleInfoSO(hmi_apis::FunctionID::VehicleInfo_GetVehicleType, _)) + .WillOnce(Return(ivi_type)); + EXPECT_CALL(app_mngr_, ManageHMICommand(ivi_type)); + } + + void PrepareEvent(bool is_message_contain_param, + Event& event, + bool is_vi_cooperating_available = false) { + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + if (is_message_contain_param) { + (*msg)[am::strings::msg_params][am::strings::available] = + is_vi_cooperating_available; + } + event.set_smart_object(*msg); + } + + VIIsReadyRequestPtr command_; + am::MockHmiInterfaces mock_hmi_interfaces_; + application_manager_test::MockHMICapabilities mock_hmi_capabilities_; + policy_test::MockPolicyHandlerInterface mock_policy_handler_interface_; +}; + +TEST_F(VIIsReadyRequestTest, Run_NoKeyAvailableInMessage_HmiInterfacesIgnored) { + const bool is_vi_cooperating_available = false; + const bool is_send_message_to_hmi = true; + const bool is_message_contain_param = false; + Event event(hmi_apis::FunctionID::VehicleInfo_IsReady); + PrepareEvent(is_message_contain_param, event); + SetUpExpectations(is_vi_cooperating_available, + is_send_message_to_hmi, + is_message_contain_param, + am::HmiInterfaces::STATE_NOT_RESPONSE); + command_->on_event(event); +} + +TEST_F(VIIsReadyRequestTest, Run_KeyAvailableEqualToFalse_StateNotAvailable) { + const bool is_vi_cooperating_available = false; + const bool is_send_message_to_hmi = false; + const bool is_message_contain_param = true; + Event event(hmi_apis::FunctionID::VehicleInfo_IsReady); + PrepareEvent(is_message_contain_param, event); + SetUpExpectations(is_vi_cooperating_available, + is_send_message_to_hmi, + is_message_contain_param, + am::HmiInterfaces::STATE_NOT_AVAILABLE); + command_->on_event(event); +} + +TEST_F(VIIsReadyRequestTest, Run_KeyAvailableEqualToTrue_StateAvailable) { + const bool is_vi_cooperating_available = true; + const bool is_send_message_to_hmi = true; + const bool is_message_contain_param = true; + Event event(hmi_apis::FunctionID::VehicleInfo_IsReady); + PrepareEvent(is_message_contain_param, event, is_vi_cooperating_available); + SetUpExpectations(is_vi_cooperating_available, + is_send_message_to_hmi, + is_message_contain_param, + am::HmiInterfaces::STATE_AVAILABLE); + command_->on_event(event); +} + +TEST_F(VIIsReadyRequestTest, Run_HMIDoestRespond_SendMessageToHMIByTimeout) { + ExpectSendMessagesToHMI(); + command_->onTimeOut(); +} + +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/test/commands/hmi/vi_is_ready_response_test.cc b/src/components/application_manager/test/commands/hmi/vi_is_ready_response_test.cc deleted file mode 100644 index e2a5aa56ea..0000000000 --- a/src/components/application_manager/test/commands/hmi/vi_is_ready_response_test.cc +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright (c) 2016, 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 "application_manager/commands/hmi/vi_is_ready_response.h" - -#include "gtest/gtest.h" -#include "utils/shared_ptr.h" -#include "smart_objects/smart_object.h" -#include "application_manager/smart_object_keys.h" -#include "application_manager/commands/commands_test.h" -#include "application_manager/mock_application_manager.h" -#include "application_manager/hmi_interfaces.h" -#include "application_manager/mock_hmi_interface.h" -#include "application_manager/mock_hmi_capabilities.h" -#include "application_manager/policies/mock_policy_handler_interface.h" - -namespace test { -namespace components { -namespace commands_test { -namespace hmi_commands_test { - -using ::testing::_; -using ::testing::ReturnRef; -namespace am = ::application_manager; -using am::commands::MessageSharedPtr; -using am::commands::VIIsReadyResponse; - -typedef SharedPtr<VIIsReadyResponse> VIIsReadyResponsePtr; - -class VIIsReadyResponseTest : public CommandsTest<CommandsTestMocks::kIsNice> { - public: - VIIsReadyResponseTest() - : message_(CreateMessage()) - , command_(CreateCommand<VIIsReadyResponse>(message_)) {} - - void SetUpExpectations(bool is_vi_cooperating_available) { - EXPECT_CALL(app_mngr_, hmi_capabilities()) - .WillOnce(ReturnRef(mock_hmi_capabilities_)); - EXPECT_CALL(mock_hmi_capabilities_, - set_is_ivi_cooperating(is_vi_cooperating_available)); - - EXPECT_CALL(app_mngr_, GetPolicyHandler()) - .WillOnce(ReturnRef(mock_policy_handler_interface_)); - EXPECT_CALL(mock_policy_handler_interface_, OnVIIsReady()); - } - - MessageSharedPtr message_; - VIIsReadyResponsePtr command_; - am::MockHmiInterfaces mock_hmi_interfaces_; - application_manager_test::MockHMICapabilities mock_hmi_capabilities_; - policy_test::MockPolicyHandlerInterface mock_policy_handler_interface_; -}; - -TEST_F(VIIsReadyResponseTest, - Run_NoKeyAvailableInMessage_HmiInterfacesIgnored) { - EXPECT_CALL(app_mngr_, hmi_interfaces()).Times(0); - EXPECT_CALL(mock_hmi_interfaces_, SetInterfaceState(_, _)).Times(0); - // VI cooperating by default is not available. - const bool is_vi_cooperating_available = false; - SetUpExpectations(is_vi_cooperating_available); - command_->Run(); -} - -TEST_F(VIIsReadyResponseTest, Run_KeyAvailableEqualToFalse_StateNotAvailable) { - const bool is_vi_cooperating_available = false; - (*message_)[am::strings::msg_params][am::strings::available] = - is_vi_cooperating_available; - - EXPECT_CALL(app_mngr_, hmi_interfaces()) - .WillOnce(ReturnRef(mock_hmi_interfaces_)); - EXPECT_CALL(mock_hmi_interfaces_, - SetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_VehicleInfo, - am::HmiInterfaces::STATE_NOT_AVAILABLE)); - - SetUpExpectations(is_vi_cooperating_available); - - command_->Run(); -} - -TEST_F(VIIsReadyResponseTest, Run_KeyAvailableEqualToFalse_StateAvailable) { - const bool is_vi_cooperating_available = true; - (*message_)[am::strings::msg_params][am::strings::available] = - is_vi_cooperating_available; - - EXPECT_CALL(app_mngr_, hmi_interfaces()) - .WillOnce(ReturnRef(mock_hmi_interfaces_)); - EXPECT_CALL(mock_hmi_interfaces_, - SetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_VehicleInfo, - am::HmiInterfaces::STATE_AVAILABLE)); - - SetUpExpectations(is_vi_cooperating_available); - - command_->Run(); -} - -} // namespace mobile_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/hmi/vr_is_ready_request_test.cc b/src/components/application_manager/test/commands/hmi/vr_is_ready_request_test.cc new file mode 100644 index 0000000000..e5989d0b64 --- /dev/null +++ b/src/components/application_manager/test/commands/hmi/vr_is_ready_request_test.cc @@ -0,0 +1,193 @@ +/* + * Copyright (c) 2016, 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 "application_manager/commands/hmi/vr_is_ready_request.h" + +#include "gtest/gtest.h" +#include "utils/shared_ptr.h" +#include "smart_objects/smart_object.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/hmi_interfaces.h" +#include "application_manager/mock_hmi_interface.h" +#include "application_manager/mock_hmi_capabilities.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/event_engine/event.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { + +using ::testing::_; +using ::testing::ReturnRef; +namespace am = ::application_manager; +using am::commands::MessageSharedPtr; +using am::commands::VRIsReadyRequest; +using am::MockMessageHelper; +using am::event_engine::Event; + +typedef SharedPtr<VRIsReadyRequest> VRIsReadyRequestPtr; + +class VRIsReadyRequestTest + : public CommandRequestTest<CommandsTestMocks::kIsNice> { + public: + VRIsReadyRequestTest() : command_(CreateCommand<VRIsReadyRequest>()) {} + + void SetUpExpectations(bool is_vr_cooperating_available, + bool is_send_message_to_hmi, + bool is_message_contain_param, + am::HmiInterfaces::InterfaceState state) { + const bool is_send_message_by_timeout = false; + if (is_send_message_to_hmi) { + EXPECT_CALL(app_mngr_, hmi_capabilities()) + .WillRepeatedly(ReturnRef(mock_hmi_capabilities_)); + ExpectSendMessagesToHMI(is_send_message_by_timeout); + } else { + EXPECT_CALL(app_mngr_, hmi_capabilities()) + .WillOnce(ReturnRef(mock_hmi_capabilities_)); + } + EXPECT_CALL(mock_hmi_capabilities_, + set_is_vr_cooperating(is_vr_cooperating_available)); + + if (is_message_contain_param) { + EXPECT_CALL(app_mngr_, hmi_interfaces()) + .WillRepeatedly(ReturnRef(mock_hmi_interfaces_)); + EXPECT_CALL( + mock_hmi_interfaces_, + SetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_VR, state)); + } else { + EXPECT_CALL(app_mngr_, hmi_interfaces()) + .WillOnce(ReturnRef(mock_hmi_interfaces_)); + EXPECT_CALL(mock_hmi_interfaces_, SetInterfaceState(_, _)).Times(0); + } + EXPECT_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_VR)) + .WillOnce(Return(state)); + } + + void ExpectSendMessagesToHMI(bool is_send_message_by_timeout) { + if (is_send_message_by_timeout) { + EXPECT_CALL(app_mngr_, hmi_capabilities()) + .WillOnce(ReturnRef(mock_hmi_capabilities_)); + } + + smart_objects::SmartObjectSPtr language( + new smart_objects::SmartObject(smart_objects::SmartType_Map)); + EXPECT_CALL(*(MockMessageHelper::message_helper_mock()), + CreateModuleInfoSO(hmi_apis::FunctionID::VR_GetLanguage, _)) + .WillOnce(Return(language)); + EXPECT_CALL(mock_hmi_capabilities_, set_handle_response_for(*language)); + EXPECT_CALL(app_mngr_, ManageHMICommand(language)); + + smart_objects::SmartObjectSPtr support_language( + new smart_objects::SmartObject(smart_objects::SmartType_Map)); + EXPECT_CALL( + *(MockMessageHelper::message_helper_mock()), + CreateModuleInfoSO(hmi_apis::FunctionID::VR_GetSupportedLanguages, _)) + .WillOnce(Return(support_language)); + EXPECT_CALL(app_mngr_, ManageHMICommand(support_language)); + + smart_objects::SmartObjectSPtr capabilities( + new smart_objects::SmartObject(smart_objects::SmartType_Map)); + EXPECT_CALL(*(MockMessageHelper::message_helper_mock()), + CreateModuleInfoSO(hmi_apis::FunctionID::VR_GetCapabilities, _)) + .WillOnce(Return(capabilities)); + EXPECT_CALL(app_mngr_, ManageHMICommand(capabilities)); + } + + void PrepareEvent(bool is_message_contain_param, + Event& event, + bool is_vr_cooperating_available = false) { + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + if (is_message_contain_param) { + (*msg)[am::strings::msg_params][am::strings::available] = + is_vr_cooperating_available; + } + event.set_smart_object(*msg); + } + + VRIsReadyRequestPtr command_; + am::MockHmiInterfaces mock_hmi_interfaces_; + application_manager_test::MockHMICapabilities mock_hmi_capabilities_; +}; + +TEST_F(VRIsReadyRequestTest, Run_NoKeyAvailableInMessage_HmiInterfacesIgnored) { + const bool is_vr_cooperating_available = false; + const bool is_send_message_to_hmi = true; + const bool is_message_contain_param = false; + Event event(hmi_apis::FunctionID::VR_IsReady); + PrepareEvent(is_message_contain_param, event); + SetUpExpectations(is_vr_cooperating_available, + is_send_message_to_hmi, + is_message_contain_param, + am::HmiInterfaces::STATE_NOT_RESPONSE); + command_->on_event(event); +} + +TEST_F(VRIsReadyRequestTest, Run_KeyAvailableEqualToFalse_StateNotAvailable) { + const bool is_vr_cooperating_available = false; + const bool is_send_message_to_hmi = false; + const bool is_message_contain_param = true; + Event event(hmi_apis::FunctionID::VR_IsReady); + PrepareEvent(is_message_contain_param, event); + SetUpExpectations(is_vr_cooperating_available, + is_send_message_to_hmi, + is_message_contain_param, + am::HmiInterfaces::STATE_NOT_AVAILABLE); + command_->on_event(event); +} + +TEST_F(VRIsReadyRequestTest, Run_KeyAvailableEqualToTrue_StateAvailable) { + const bool is_vr_cooperating_available = true; + const bool is_send_message_to_hmi = true; + const bool is_message_contain_param = true; + Event event(hmi_apis::FunctionID::VR_IsReady); + PrepareEvent(is_message_contain_param, event, is_vr_cooperating_available); + SetUpExpectations(is_vr_cooperating_available, + is_send_message_to_hmi, + is_message_contain_param, + am::HmiInterfaces::STATE_AVAILABLE); + command_->on_event(event); +} + +TEST_F(VRIsReadyRequestTest, Run_HMIDoestRespond_SendMessageToHMIByTimeout) { + const bool is_send_message_by_timeout = true; + ExpectSendMessagesToHMI(is_send_message_by_timeout); + command_->onTimeOut(); +} + +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/test/commands/hmi/vr_is_ready_response_test.cc b/src/components/application_manager/test/commands/hmi/vr_is_ready_response_test.cc deleted file mode 100644 index 3fc5fea985..0000000000 --- a/src/components/application_manager/test/commands/hmi/vr_is_ready_response_test.cc +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright (c) 2016, 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 "application_manager/commands/hmi/vr_is_ready_response.h" - -#include "gtest/gtest.h" -#include "utils/shared_ptr.h" -#include "smart_objects/smart_object.h" -#include "application_manager/smart_object_keys.h" -#include "application_manager/commands/commands_test.h" -#include "application_manager/mock_application_manager.h" -#include "application_manager/hmi_interfaces.h" -#include "application_manager/mock_hmi_interface.h" -#include "application_manager/mock_hmi_capabilities.h" - -namespace test { -namespace components { -namespace commands_test { -namespace hmi_commands_test { - -using ::testing::_; -using ::testing::ReturnRef; -namespace am = ::application_manager; -using am::commands::MessageSharedPtr; -using am::commands::VRIsReadyResponse; - -typedef SharedPtr<VRIsReadyResponse> VRIsReadyResponsePtr; - -class VRIsReadyResponseTest : public CommandsTest<CommandsTestMocks::kIsNice> { - public: - VRIsReadyResponseTest() - : message_(CreateMessage()) - , command_(CreateCommand<VRIsReadyResponse>(message_)) {} - - void SetUpExpectations(bool is_vr_cooperating_available) { - EXPECT_CALL(app_mngr_, hmi_capabilities()) - .WillOnce(ReturnRef(mock_hmi_capabilities_)); - EXPECT_CALL(mock_hmi_capabilities_, - set_is_vr_cooperating(is_vr_cooperating_available)); - } - - MessageSharedPtr message_; - VRIsReadyResponsePtr command_; - am::MockHmiInterfaces mock_hmi_interfaces_; - application_manager_test::MockHMICapabilities mock_hmi_capabilities_; -}; - -TEST_F(VRIsReadyResponseTest, - Run_NoKeyAvailableInMessage_HmiInterfacesIgnored) { - EXPECT_CALL(app_mngr_, hmi_interfaces()).Times(0); - EXPECT_CALL(mock_hmi_interfaces_, SetInterfaceState(_, _)).Times(0); - // VR cooperating by default is not available. - const bool is_vr_cooperating_available = false; - SetUpExpectations(is_vr_cooperating_available); - command_->Run(); -} - -TEST_F(VRIsReadyResponseTest, Run_KeyAvailableEqualToFalse_StateNotAvailable) { - const bool is_vr_cooperating_available = false; - (*message_)[am::strings::msg_params][am::strings::available] = - is_vr_cooperating_available; - - EXPECT_CALL(app_mngr_, hmi_interfaces()) - .WillOnce(ReturnRef(mock_hmi_interfaces_)); - EXPECT_CALL(mock_hmi_interfaces_, - SetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_VR, - am::HmiInterfaces::STATE_NOT_AVAILABLE)); - - SetUpExpectations(is_vr_cooperating_available); - - command_->Run(); -} - -TEST_F(VRIsReadyResponseTest, Run_KeyAvailableEqualToFalse_StateAvailable) { - const bool is_vr_cooperating_available = true; - (*message_)[am::strings::msg_params][am::strings::available] = - is_vr_cooperating_available; - - EXPECT_CALL(app_mngr_, hmi_interfaces()) - .WillOnce(ReturnRef(mock_hmi_interfaces_)); - EXPECT_CALL(mock_hmi_interfaces_, - SetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_VR, - am::HmiInterfaces::STATE_AVAILABLE)); - - SetUpExpectations(is_vr_cooperating_available); - - command_->Run(); -} - -} // namespace mobile_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/mobile/change_registration_test.cc b/src/components/application_manager/test/commands/mobile/change_registration_test.cc index 275bb3be8a..e5cdaa0f1c 100644 --- a/src/components/application_manager/test/commands/mobile/change_registration_test.cc +++ b/src/components/application_manager/test/commands/mobile/change_registration_test.cc @@ -50,6 +50,7 @@ #include "application_manager/mock_message_helper.h" #include "application_manager/mock_hmi_capabilities.h" #include "application_manager/event_engine/event.h" +#include "application_manager/mock_hmi_interface.h" namespace test { namespace components { @@ -61,6 +62,7 @@ using am::ApplicationManager; using am::commands::MessageSharedPtr; using am::ApplicationSharedPtr; using am::MockMessageHelper; +using am::MockHmiInterfaces; using ::testing::_; using ::utils::SharedPtr; using ::testing::Return; @@ -85,62 +87,81 @@ class ChangeRegistrationRequestTest sync_primitives::Lock app_set_lock_; sync_primitives::Lock lock_; - MessageSharedPtr CreateFullParamsVRSO() { + MessageSharedPtr CreateMsgFromMobile() { MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); (*msg)[strings::params][strings::connection_key] = kConnectionKey; smart_objects::SmartObject msg_params = smart_objects::SmartObject(smart_objects::SmartType_Map); - msg_params[strings::cmd_id] = kCmdId; - msg_params[strings::vr_commands] = - smart_objects::SmartObject(smart_objects::SmartType_Array); - msg_params[strings::vr_commands][0] = "lamer"; - msg_params[strings::type] = 34; - msg_params[strings::grammar_id] = 12; - msg_params[strings::app_id] = kAppId; + msg_params[strings::hmi_display_language] = mobile_apis::Language::EN_US; + msg_params[strings::language] = mobile_apis::Language::EN_US; (*msg)[strings::msg_params] = msg_params; - return msg; } + void PrepareExpectationBeforeRun() { + ON_CALL(app_mngr_, hmi_capabilities()) + .WillByDefault(ReturnRef(hmi_capabilities_)); + smart_objects::SmartObject supported_languages( + smart_objects::SmartType_Array); + supported_languages[0] = static_cast<int32_t>(mobile_apis::Language::EN_US); + EXPECT_CALL(hmi_capabilities_, ui_supported_languages()) + .WillOnce(Return(&supported_languages)); + EXPECT_CALL(hmi_capabilities_, vr_supported_languages()) + .WillOnce(Return(&supported_languages)); + EXPECT_CALL(hmi_capabilities_, tts_supported_languages()) + .WillOnce(Return(&supported_languages)); + + EXPECT_CALL(app_mngr_, hmi_interfaces()) + .WillRepeatedly(ReturnRef(hmi_interfaces_)); + EXPECT_CALL( + hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::UI_ChangeRegistration)) + .WillOnce(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); + EXPECT_CALL(hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillOnce(Return(am::HmiInterfaces::STATE_AVAILABLE)); + + EXPECT_CALL( + hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::VR_ChangeRegistration)) + .WillOnce(Return(am::HmiInterfaces::HMI_INTERFACE_VR)); + EXPECT_CALL(hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_VR)) + .WillOnce(Return(am::HmiInterfaces::STATE_AVAILABLE)); + + EXPECT_CALL( + hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::TTS_ChangeRegistration)) + .WillOnce(Return(am::HmiInterfaces::HMI_INTERFACE_TTS)); + EXPECT_CALL(hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_TTS)) + .WillOnce(Return(am::HmiInterfaces::STATE_AVAILABLE)); + } + + void CreateResponseFromHMI(MessageSharedPtr msg, + hmi_apis::Common_Result::eType result, + const std::string& info) { + (*msg)[strings::params][hmi_response::code] = static_cast<int32_t>(result); + (*msg)[strings::msg_params][strings::info] = info; + } + typedef TypeIf<kMocksAreNice, NiceMock<application_manager_test::MockHMICapabilities>, application_manager_test::MockHMICapabilities>::Result MockHMICapabilities; + MockHMICapabilities hmi_capabilities_; + MockHmiInterfaces hmi_interfaces_; }; typedef ChangeRegistrationRequestTest::MockHMICapabilities MockHMICapabilities; TEST_F(ChangeRegistrationRequestTest, OnEvent_VR_UNSUPPORTED_RESOURCE) { - MessageSharedPtr msg_vr = CreateFullParamsVRSO(); - - utils::SharedPtr<ChangeRegistrationRequest> req_vr = - CreateCommand<ChangeRegistrationRequest>(msg_vr); + MessageSharedPtr msg_from_mobile = CreateMsgFromMobile(); + utils::SharedPtr<ChangeRegistrationRequest> command = + CreateCommand<ChangeRegistrationRequest>(msg_from_mobile); MockAppPtr mock_app = CreateMockApp(); ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app)); ON_CALL(*mock_app, app_id()).WillByDefault(Return(1)); - - MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); - (*msg)[strings::params][hmi_response::code] = - hmi_apis::Common_Result::WARNINGS; - (*msg)[strings::params][strings::info] = "info"; - (*msg)[strings::msg_params][strings::cmd_id] = kCommandId; - - am::event_engine::Event event(hmi_apis::FunctionID::VR_ChangeRegistration); - event.set_smart_object(*msg); - - smart_objects::SmartObject* ptr = NULL; - ON_CALL(*mock_app, FindCommand(kCmdId)).WillByDefault(Return(ptr)); - EXPECT_EQ(NULL, ptr); - - am::CommandsMap commands_map; - ON_CALL(*mock_app, commands_map()) - .WillByDefault( - Return(DataAccessor<am::CommandsMap>(commands_map, lock_))); - - MockHMICapabilities hmi_capabilities; - ON_CALL(app_mngr_, hmi_capabilities()) - .WillByDefault(ReturnRef(hmi_capabilities)); - am::ApplicationSet application_set; const utils::custom_string::CustomString name("name"); MockAppPtr app = CreateMockApp(); @@ -152,32 +173,45 @@ TEST_F(ChangeRegistrationRequestTest, OnEvent_VR_UNSUPPORTED_RESOURCE) { EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(accessor)); EXPECT_CALL(*app, name()).WillOnce(ReturnRef(name)); - EXPECT_CALL( - app_mngr_, - ManageMobileCommand(_, am::commands::Command::CommandOrigin::ORIGIN_SDL)) - .WillOnce(Return(true)); + PrepareExpectationBeforeRun(); + command->Run(); + + MessageSharedPtr ui_response = CreateMessage(smart_objects::SmartType_Map); + MessageSharedPtr vr_response = CreateMessage(smart_objects::SmartType_Map); + MessageSharedPtr tts_response = CreateMessage(smart_objects::SmartType_Map); + CreateResponseFromHMI( + ui_response, hmi_apis::Common_Result::WARNINGS, "ui_info"); + CreateResponseFromHMI(vr_response, + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE, + "unsupported_resource"); + CreateResponseFromHMI( + tts_response, hmi_apis::Common_Result::SUCCESS, "tts_info"); + + am::event_engine::Event event_ui(hmi_apis::FunctionID::UI_ChangeRegistration); + event_ui.set_smart_object(*ui_response); + am::event_engine::Event event_vr(hmi_apis::FunctionID::VR_ChangeRegistration); + event_vr.set_smart_object(*vr_response); + am::event_engine::Event event_tts( + hmi_apis::FunctionID::TTS_ChangeRegistration); + event_tts.set_smart_object(*tts_response); + + MessageSharedPtr response_to_mobile; - req_vr->Run(); - - MessageSharedPtr vr_command_result; EXPECT_CALL( app_mngr_, ManageMobileCommand(_, am::commands::Command::CommandOrigin::ORIGIN_SDL)) - .WillOnce(DoAll(SaveArg<0>(&vr_command_result), Return(true))); + .WillOnce(DoAll(SaveArg<0>(&response_to_mobile), Return(true))); - req_vr->on_event(event); + command->on_event(event_ui); + command->on_event(event_vr); + command->on_event(event_tts); EXPECT_EQ( - (*vr_command_result)[strings::msg_params][strings::success].asBool(), - false); + (*response_to_mobile)[strings::msg_params][strings::success].asBool(), + true); EXPECT_EQ( - (*vr_command_result)[strings::msg_params][strings::result_code].asInt(), - static_cast<int32_t>(hmi_apis::Common_Result::WARNINGS)); - if ((*vr_command_result)[strings::msg_params].keyExists(strings::info)) { - EXPECT_EQ( - (*vr_command_result)[strings::msg_params][strings::info].asString(), - (*msg)[strings::msg_params][strings::info].asString()); - } + (*response_to_mobile)[strings::msg_params][strings::result_code].asInt(), + static_cast<int32_t>(mobile_apis::Result::UNSUPPORTED_RESOURCE)); } } // namespace commands_test diff --git a/src/components/application_manager/test/commands/mobile/perform_interaction_test.cc b/src/components/application_manager/test/commands/mobile/perform_interaction_test.cc index 417dc33586..3b6a66f112 100644 --- a/src/components/application_manager/test/commands/mobile/perform_interaction_test.cc +++ b/src/components/application_manager/test/commands/mobile/perform_interaction_test.cc @@ -84,39 +84,42 @@ class PerformInteractionRequestTest }; TEST_F(PerformInteractionRequestTest, OnTimeout_VR_GENERIC_ERROR) { - MessageSharedPtr msg_vr = CreateMessage(smart_objects::SmartType_Map); - - (*msg_vr)[strings::msg_params][strings::interaction_mode] = + MessageSharedPtr response_msg_vr = + CreateMessage(smart_objects::SmartType_Map); + (*response_msg_vr)[strings::params][hmi_response::code] = + static_cast<uint64_t>(hmi_apis::Common_Result::SUCCESS); + (*response_msg_vr)[strings::msg_params][strings::info] = "info"; + MessageSharedPtr request_msg = CreateMessage(smart_objects::SmartType_Map); + (*request_msg)[strings::msg_params][strings::interaction_mode] = mobile_apis::InteractionMode::BOTH; - (*msg_vr)[strings::msg_params][strings::result_code] = - am::mobile_api::Result::GENERIC_ERROR; - (*msg_vr)[strings::msg_params][strings::success] = false; - utils::SharedPtr<PerformInteractionRequest> req_vr = - CreateCommand<PerformInteractionRequest>(msg_vr); + utils::SharedPtr<PerformInteractionRequest> command = + CreateCommand<PerformInteractionRequest>(request_msg); MockAppPtr mock_app; - ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app)); - MockHmiInterfaces hmi_interfaces; - ON_CALL(app_mngr_, hmi_interfaces()).WillByDefault(ReturnRef(hmi_interfaces)); - Event event(hmi_apis::FunctionID::VR_PerformInteraction); - event.set_smart_object(*msg_vr); - req_vr->on_event(event); - req_vr->Init(); + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app)); + Event event(hmi_apis::FunctionID::VR_PerformInteraction); + event.set_smart_object(*response_msg_vr); + + command->Init(); + command->on_event(event); + MessageSharedPtr response_to_mobile = + CreateMessage(smart_objects::SmartType_Map); + (*response_to_mobile)[strings::msg_params][strings::result_code] = + static_cast<uint64_t>(am::mobile_api::Result::GENERIC_ERROR); MockMessageHelper* mock_message_helper = MockMessageHelper::message_helper_mock(); EXPECT_CALL( *mock_message_helper, CreateNegativeResponse(_, _, _, am::mobile_api::Result::GENERIC_ERROR)) - .WillOnce(Return(msg_vr)); + .WillOnce(Return(response_to_mobile)); MessageSharedPtr vr_command_result; EXPECT_CALL( app_mngr_, ManageMobileCommand(_, am::commands::Command::CommandOrigin::ORIGIN_SDL)) .WillOnce(DoAll(SaveArg<0>(&vr_command_result), Return(true))); - - req_vr->onTimeOut(); + command->onTimeOut(); EXPECT_EQ( (*vr_command_result)[strings::msg_params][strings::success].asBool(), @@ -127,62 +130,67 @@ TEST_F(PerformInteractionRequestTest, OnTimeout_VR_GENERIC_ERROR) { } TEST_F(PerformInteractionRequestTest, OnEvent_VR_UNSUPPORTED_RESOURCE) { - MessageSharedPtr msg_vr = CreateMessage(smart_objects::SmartType_Map); - (*msg_vr)[strings::params][strings::connection_key] = kConnectionKey; - (*msg_vr)[strings::msg_params][strings::interaction_mode] = + MessageSharedPtr msg_from_mobile = + CreateMessage(smart_objects::SmartType_Map); + (*msg_from_mobile)[strings::params][strings::connection_key] = kConnectionKey; + (*msg_from_mobile)[strings::msg_params][strings::interaction_mode] = mobile_apis::InteractionMode::VR_ONLY; - utils::SharedPtr<PerformInteractionRequest> req_vr = - CreateCommand<PerformInteractionRequest>(msg_vr); - req_vr->Init(); - MockAppPtr mock_app = CreateMockApp(); - ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app)); - ON_CALL(*mock_app, app_id()).WillByDefault(Return(1)); + utils::SharedPtr<PerformInteractionRequest> command = + CreateCommand<PerformInteractionRequest>(msg_from_mobile); + command->Init(); + + MockAppPtr mock_app; + EXPECT_CALL(app_mngr_, application(_)).WillRepeatedly(Return(mock_app)); + MockHmiInterfaces hmi_interfaces; - ON_CALL(app_mngr_, hmi_interfaces()).WillByDefault(ReturnRef(hmi_interfaces)); - ON_CALL(hmi_interfaces, GetInterfaceFromFunction(_)) - .WillByDefault( - Return(am::HmiInterfaces::HMI_INTERFACE_BasicCommunication)); - ON_CALL(hmi_interfaces, GetInterfaceState(_)) - .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); - - MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); - (*msg)[strings::params][hmi_response::code] = + EXPECT_CALL(app_mngr_, hmi_interfaces()) + .WillRepeatedly(ReturnRef(hmi_interfaces)); + + MessageSharedPtr response_msg_vr = + CreateMessage(smart_objects::SmartType_Map); + (*response_msg_vr)[strings::params][hmi_response::code] = hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; - (*msg)[strings::params][strings::info] = "info"; - (*msg)[strings::msg_params][strings::cmd_id] = kCommandId; + (*response_msg_vr)[strings::params][strings::info] = + "VR is not supported by system"; + (*response_msg_vr)[strings::msg_params][strings::cmd_id] = kCommandId; - am::event_engine::Event event(hmi_apis::FunctionID::VR_PerformInteraction); - event.set_smart_object(*msg); + am::event_engine::Event event_vr(hmi_apis::FunctionID::VR_PerformInteraction); + event_vr.set_smart_object(*response_msg_vr); - smart_objects::SmartObject* ptr = NULL; - ON_CALL(*mock_app, FindCommand(kCmdId)).WillByDefault(Return(ptr)); - EXPECT_EQ(NULL, ptr); + MessageSharedPtr response_msg_ui = + CreateMessage(smart_objects::SmartType_Map); + (*response_msg_ui)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; - am::CommandsMap commands_map; - ON_CALL(*mock_app, commands_map()) - .WillByDefault( - Return(DataAccessor<am::CommandsMap>(commands_map, lock_))); + am::event_engine::Event event_ui(hmi_apis::FunctionID::UI_PerformInteraction); + event_ui.set_smart_object(*response_msg_ui); + + EXPECT_CALL(hmi_interfaces, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillRepeatedly(Return(am::HmiInterfaces::STATE_AVAILABLE)); + EXPECT_CALL(hmi_interfaces, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_VR)) + .WillRepeatedly(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + + MessageSharedPtr response_to_mobile; - MessageSharedPtr vr_command_result; EXPECT_CALL( app_mngr_, ManageMobileCommand(_, am::commands::Command::CommandOrigin::ORIGIN_SDL)) - .WillOnce(Return(true)) - .WillOnce(DoAll(SaveArg<0>(&vr_command_result), Return(true))); + .WillOnce(DoAll(SaveArg<0>(&response_to_mobile), Return(true))); - req_vr->on_event(event); + command->on_event(event_vr); + command->on_event(event_ui); EXPECT_EQ( - (*vr_command_result)[strings::msg_params][strings::success].asBool(), + (*response_to_mobile)[strings::msg_params][strings::success].asBool(), true); EXPECT_EQ( - (*vr_command_result)[strings::msg_params][strings::result_code].asInt(), - static_cast<int32_t>(hmi_apis::Common_Result::SUCCESS)); - if ((*vr_command_result)[strings::msg_params].keyExists(strings::info)) { - EXPECT_EQ( - (*vr_command_result)[strings::msg_params][strings::info].asString(), - (*msg)[strings::msg_params][strings::info].asString()); - } + (*response_to_mobile)[strings::msg_params][strings::result_code].asInt(), + static_cast<int32_t>(mobile_apis::Result::UNSUPPORTED_RESOURCE)); + EXPECT_EQ( + (*response_to_mobile)[strings::msg_params][strings::info].asString(), + (*response_msg_vr)[strings::msg_params][strings::info].asString()); } } // namespace commands_test diff --git a/src/components/application_manager/test/hmi_capabilities_test.cc b/src/components/application_manager/test/hmi_capabilities_test.cc index 3f14981f7f..738797b122 100644 --- a/src/components/application_manager/test/hmi_capabilities_test.cc +++ b/src/components/application_manager/test/hmi_capabilities_test.cc @@ -353,52 +353,6 @@ TEST_F(HMICapabilitiesTest, LoadCapabilitiesFromFile) { EXPECT_EQ("SE", vehicle_type_so["trim"].asString()); } -TEST_F(HMICapabilitiesTest, - HmiCapabilitiesInitialized_UiVrTtsIviNotCooperating) { - // Precondition - hmi_capabilities_test->set_is_vr_cooperating(false); - hmi_capabilities_test->set_is_tts_cooperating(false); - - hmi_capabilities_test->set_is_ui_cooperating(false); - hmi_capabilities_test->set_is_navi_cooperating(false); - hmi_capabilities_test->set_is_ivi_cooperating(false); - EXPECT_TRUE(hmi_capabilities_test->is_hmi_capabilities_initialized()); -} - -TEST_F(HMICapabilitiesTest, HmiCapabilitiesInitialized) { - // Precondition - SetCooperating(); - smart_objects::SmartObjectSPtr language( - new smart_objects::SmartObject(smart_objects::SmartType_Map)); - - EXPECT_CALL(*(MockMessageHelper::message_helper_mock()), - CreateModuleInfoSO(_, _)).WillRepeatedly(Return(language)); - - hmi_capabilities_test->set_is_vr_cooperating(true); - smart_objects::SmartObject supported_languages; - supported_languages[0] = "EN_US"; - hmi_capabilities_test->set_vr_supported_languages(supported_languages); - hmi_capabilities_test->set_tts_supported_languages(supported_languages); - hmi_capabilities_test->set_ui_supported_languages(supported_languages); - hmi_capabilities_test->set_vehicle_type(supported_languages); - - hmi_capabilities_test->set_is_tts_cooperating(true); - hmi_capabilities_test->set_is_ui_cooperating(true); - hmi_capabilities_test->set_is_navi_cooperating(true); - hmi_capabilities_test->set_is_ivi_cooperating(true); - - hmi_capabilities_test->set_active_vr_language( - hmi_apis::Common_Language::EN_US); - SetCooperating(); - hmi_capabilities_test->set_active_tts_language( - hmi_apis::Common_Language::EN_US); - SetCooperating(); - hmi_capabilities_test->set_active_ui_language( - hmi_apis::Common_Language::EN_US); - - EXPECT_TRUE(hmi_capabilities_test->is_hmi_capabilities_initialized()); -} - TEST_F(HMICapabilitiesTest, VerifyImageType) { const int32_t image_type = 1; smart_objects::SmartObject sm_obj; @@ -419,88 +373,23 @@ void HMICapabilitiesTest::SetCooperating() { } TEST_F(HMICapabilitiesTest, SetVRCooperating) { - // Without sequence it is impossible to check correct call of ManageHMICommand - InSequence dummy; - smart_objects::SmartObjectSPtr language( - new smart_objects::SmartObject(smart_objects::SmartType_Map)); - EXPECT_CALL(*(MockMessageHelper::message_helper_mock()), - CreateModuleInfoSO(hmi_apis::FunctionID::VR_GetLanguage, _)) - .WillOnce(Return(language)); - EXPECT_CALL(app_mngr_, ManageHMICommand(language)); - - smart_objects::SmartObjectSPtr support_language; - EXPECT_CALL(*(MockMessageHelper::message_helper_mock()), - CreateModuleInfoSO(hmi_apis::FunctionID::VR_GetSupportedLanguages, - _)).WillOnce(Return(support_language)); - EXPECT_CALL(app_mngr_, ManageHMICommand(support_language)); - - smart_objects::SmartObjectSPtr capabilities; - EXPECT_CALL(*(MockMessageHelper::message_helper_mock()), - CreateModuleInfoSO(hmi_apis::FunctionID::VR_GetCapabilities, _)) - .WillOnce(Return(capabilities)); - EXPECT_CALL(app_mngr_, ManageHMICommand(capabilities)); - hmi_capabilities_test->set_is_vr_cooperating(true); + EXPECT_EQ(true, hmi_capabilities_test->is_vr_cooperating()); } TEST_F(HMICapabilitiesTest, SetTTSCooperating) { - smart_objects::SmartObjectSPtr language( - new smart_objects::SmartObject(smart_objects::SmartType_Map)); - InSequence dummy; - EXPECT_CALL(*(MockMessageHelper::message_helper_mock()), - CreateModuleInfoSO(hmi_apis::FunctionID::TTS_GetLanguage, _)) - .WillOnce(Return(language)); - EXPECT_CALL(app_mngr_, ManageHMICommand(language)); - - smart_objects::SmartObjectSPtr support_language; - EXPECT_CALL( - *(MockMessageHelper::message_helper_mock()), - CreateModuleInfoSO(hmi_apis::FunctionID::TTS_GetSupportedLanguages, _)) - .WillOnce(Return(support_language)); - EXPECT_CALL(app_mngr_, ManageHMICommand(support_language)); - - smart_objects::SmartObjectSPtr capabilities; - EXPECT_CALL(*(MockMessageHelper::message_helper_mock()), - CreateModuleInfoSO(hmi_apis::FunctionID::TTS_GetCapabilities, _)) - .WillOnce(Return(capabilities)); - EXPECT_CALL(app_mngr_, ManageHMICommand(capabilities)); - hmi_capabilities_test->set_is_tts_cooperating(true); + EXPECT_EQ(true, hmi_capabilities_test->is_tts_cooperating()); } TEST_F(HMICapabilitiesTest, SetUICooperating) { - InSequence dummy; - smart_objects::SmartObjectSPtr language( - new smart_objects::SmartObject(smart_objects::SmartType_Map)); - EXPECT_CALL(*(MockMessageHelper::message_helper_mock()), - CreateModuleInfoSO(hmi_apis::FunctionID::UI_GetLanguage, _)) - .WillOnce(Return(language)); - EXPECT_CALL(app_mngr_, ManageHMICommand(language)); - - smart_objects::SmartObjectSPtr support_language; - EXPECT_CALL(*(MockMessageHelper::message_helper_mock()), - CreateModuleInfoSO(hmi_apis::FunctionID::UI_GetSupportedLanguages, - _)).WillOnce(Return(support_language)); - EXPECT_CALL(app_mngr_, ManageHMICommand(support_language)); - - smart_objects::SmartObjectSPtr capabilities; - EXPECT_CALL(*(MockMessageHelper::message_helper_mock()), - CreateModuleInfoSO(hmi_apis::FunctionID::UI_GetCapabilities, _)) - .WillOnce(Return(capabilities)); - EXPECT_CALL(app_mngr_, ManageHMICommand(capabilities)); - hmi_capabilities_test->set_is_ui_cooperating(true); + EXPECT_EQ(true, hmi_capabilities_test->is_ui_cooperating()); } TEST_F(HMICapabilitiesTest, SetIviCooperating) { - smart_objects::SmartObjectSPtr ivi_type; - EXPECT_CALL( - *(MockMessageHelper::message_helper_mock()), - CreateModuleInfoSO(hmi_apis::FunctionID::VehicleInfo_GetVehicleType, _)) - .WillOnce(Return(ivi_type)); - EXPECT_CALL(app_mngr_, ManageHMICommand(ivi_type)); - hmi_capabilities_test->set_is_ivi_cooperating(true); + EXPECT_EQ(true, hmi_capabilities_test->is_ivi_cooperating()); } } // namespace application_manager_test diff --git a/src/components/application_manager/test/include/application_manager/mock_hmi_capabilities.h b/src/components/application_manager/test/include/application_manager/mock_hmi_capabilities.h index 236f3f6741..a8664f5e2c 100644 --- a/src/components/application_manager/test/include/application_manager/mock_hmi_capabilities.h +++ b/src/components/application_manager/test/include/application_manager/mock_hmi_capabilities.h @@ -44,7 +44,6 @@ namespace application_manager_test { class MockHMICapabilities : public ::application_manager::HMICapabilities { public: - MOCK_CONST_METHOD0(is_hmi_capabilities_initialized, bool()); MOCK_CONST_METHOD1(VerifyImageType, bool(const int32_t image_type)); MOCK_CONST_METHOD0(is_vr_cooperating, bool()); @@ -161,6 +160,8 @@ class MockHMICapabilities : public ::application_manager::HMICapabilities { MOCK_METHOD1(set_ccpu_version, void(const std::string& ccpu_version)); MOCK_METHOD0(get_hmi_language_handler, application_manager::HMILanguageHandler&()); + MOCK_METHOD1(set_handle_response_for, + void(const smart_objects::SmartObject& request)); protected: MOCK_CONST_METHOD2(check_existing_json_member, diff --git a/src/components/include/application_manager/hmi_capabilities.h b/src/components/include/application_manager/hmi_capabilities.h index d7bd7a6c05..39cedf3273 100644 --- a/src/components/include/application_manager/hmi_capabilities.h +++ b/src/components/include/application_manager/hmi_capabilities.h @@ -68,13 +68,6 @@ class HMICapabilities { */ virtual HMILanguageHandler& get_hmi_language_handler() = 0; - /** - * @brief Checks if all HMI capabilities received - * - * @return TRUE if all information received, otherwise FALSE - */ - virtual bool is_hmi_capabilities_initialized() const = 0; - /* * @brief Checks is image type(Static/Dynamic) requested by * Mobile Device is supported on current HMI. @@ -424,6 +417,13 @@ class HMICapabilities { virtual void Init(resumption::LastState* last_state) = 0; + /** + * @brief Trigger waiting for response + * @param request Request object + */ + virtual void set_handle_response_for( + const smart_objects::SmartObject& request) = 0; + protected: /* * @brief function checks if json member exists |