diff options
author | dtrunov <dtrunov@luxoft.com> | 2016-09-15 14:14:11 +0300 |
---|---|---|
committer | dtrunov <dtrunov@luxoft.com> | 2016-09-29 11:36:10 +0300 |
commit | ff2bdeaf8a627fc698ff83f4987921b5773a3955 (patch) | |
tree | 7bb833bedf4af9bb8f8cdcaec7f686fbd147b7ca /src/components/application_manager | |
parent | 85c71b25bde1eaca791e94ee3f16bb37d389efce (diff) | |
download | sdl_core-ff2bdeaf8a627fc698ff83f4987921b5773a3955.tar.gz |
UI interface: SDL behavior in case HMI does not respond to IsReady request or respond with "available" = false
Added logic for processing case when HMI does not respond to IsReady request or respond with "available"=false.
Added logic to UI command in order to process UNSUPPORTED_RESOURCE result code.
Change logic for processing response IsReady for UI, VR, TTS, VI interfaces.
CRQ [APPLINK-25087](https://adc.luxoft.com/jira/browse/APPLINK-25087)
Diffstat (limited to 'src/components/application_manager')
51 files changed, 1394 insertions, 1105 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..7d2c444f4a 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,39 @@ class SmartObject; namespace application_manager { namespace commands { +struct response_info{ + 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,7 +184,56 @@ class CommandRequestImpl : public CommandImpl, */ bool HasDisallowedParams() const; - protected: + /** + * @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(response_info& first, + response_info& 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 info contain info for sending to application + * @param response_from_hmi contains response from HMI + */ + void GetInfo(HmiInterfaces::InterfaceID interface, + hmi_apis::Common_Result::eType result_code, + std::string& info, + const smart_objects::SmartObject& response_from_hmi); + + /** + * @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 response_info& first, + const response_info& second); + +protected: /** * @brief Returns policy parameters permissions * @return Parameters permissions struct reference 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..680f1e9d99 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,27 @@ 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..d30f900982 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 @@ -62,6 +63,21 @@ class TTSIsReadyRequest : 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(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..e8a6bd81b9 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 @@ -62,6 +63,21 @@ class UIIsReadyRequest : 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(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..93450a0ffc 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 @@ -62,7 +63,22 @@ class VIIsReadyRequest : public RequestToHMI { **/ virtual void Run(); - private: + /** + * @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(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..01492995db 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& response_info); + + /** + * @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..46c64c2ac9 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,30 @@ 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 +122,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 HasHmiResponsesToWait(); + + /* 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..3102785096 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,23 +88,23 @@ 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( + bool ProcessUIResponse( const smart_objects::SmartObject& message, smart_objects::SmartObject& msg_params); @@ -218,12 +219,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 +227,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..0fad215b74 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,12 @@ 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 +469,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..5048469247 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,44 @@ #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); +} + +void CreateInfoForUnsupportedResult(std::string& info, + HmiInterfaces::InterfaceID interface) { + switch (interface) { + case(HmiInterfaces::InterfaceID::HMI_INTERFACE_VR):{ + info = "VR is not supported by system"; + break; + } case(HmiInterfaces::InterfaceID::HMI_INTERFACE_TTS): { + info = "TTS is not supported by system"; + break; + } case(HmiInterfaces::InterfaceID::HMI_INTERFACE_UI): { + info = "UI is not supported by system"; + break; + } case(HmiInterfaces::InterfaceID::HMI_INTERFACE_Navigation): { + info = "Navi is not supported by system"; + break; + } + default: + break; + } +} + + struct DisallowedParamsInserter { DisallowedParamsInserter(smart_objects::SmartObject& response, mobile_apis::VehicleDataResultCode::eType code) @@ -66,6 +100,8 @@ struct DisallowedParamsInserter { mobile_apis::VehicleDataResultCode::eType code_; }; + + CommandRequestImpl::CommandRequestImpl(const MessageSharedPtr& message, ApplicationManager& application_manager) : CommandImpl(message, application_manager) @@ -207,23 +243,9 @@ 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; - } + std::string info; + CreateInfoForUnsupportedResult(info, interface); + msg_params[strings::info] = info; return response; } @@ -605,11 +627,128 @@ 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; + bool result = 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); + const HmiInterfaces::InterfaceState state = + application_manager_.hmi_interfaces().GetInterfaceState(interface); + result = result || (hmi_apis::Common_Result::UNSUPPORTED_RESOURCE == result_code && + HmiInterfaces::STATE_NOT_AVAILABLE != state); + return result; +} + +bool CommandRequestImpl::PrepareResultForMobileResponse( + response_info& first, + response_info& second) const { + using namespace helpers; + + first.is_ok = Compare<hmi_apis::Common_Result::eType, EQ, ONE>( + 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); + + second.is_ok = Compare<hmi_apis::Common_Result::eType, EQ, ONE>( + 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); + + first.is_invalid_enum = + hmi_apis::Common_Result::INVALID_ENUM == first.result_code; + + second.is_invalid_enum = + hmi_apis::Common_Result::INVALID_ENUM == second.result_code; + + first.is_unsupported_resource = + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE == first.result_code; + + second.is_unsupported_resource = + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE == second.result_code; + + first.interface_state = application_manager_.hmi_interfaces().GetInterfaceState( + first.interface); + second.interface_state = application_manager_.hmi_interfaces().GetInterfaceState( + second.interface); + + bool result = (first.is_ok && second.is_ok) || + (second.is_invalid_enum && first.is_ok) || + (first. is_invalid_enum && second.is_ok); + + result = result || (first.is_ok && second.is_unsupported_resource); + result = result || (second.is_ok && first.is_unsupported_resource); + result = result || (first.is_invalid_enum && second.is_unsupported_resource && + HmiInterfaces::STATE_NOT_AVAILABLE != second.interface_state); + result = result || (second.is_invalid_enum && first.is_unsupported_resource && + HmiInterfaces::STATE_NOT_AVAILABLE != first.interface_state); + return result; +} + +void CommandRequestImpl::GetInfo(HmiInterfaces::InterfaceID interface, + hmi_apis::Common_Result::eType result_code, + std::string& info, + const smart_objects::SmartObject& response_from_hmi) { + if (response_from_hmi[strings::msg_params].keyExists(strings::info)) { + 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) { + CreateInfoForUnsupportedResult(info, interface); + } + } + + } + +mobile_apis::Result::eType CommandRequestImpl::PrepareResultCodeForResponse( + const response_info& first, + const response_info& second) { + mobile_apis::Result::eType result_code = mobile_apis::Result::INVALID_ENUM; + if (((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)) { + result_code = mobile_apis::Result::UNSUPPORTED_RESOURCE; + } else { + //If esponse 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_; } + + } // namespace commands } // namespace application_manager 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..1e71ef7b88 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,11 @@ ClosePopupRequest::~ClosePopupRequest() {} void ClosePopupRequest::Run() { LOG4CXX_AUTO_TRACE(logger_); - + if(!CheckAvailabilityHMIInterfaces(application_manager_, + HmiInterfaces::HMI_INTERFACE_UI)) { + LOG4CXX_INFO(logger_, "HmiInterfaces::HMI_INTERFACE_UI isn't available"); + return; + } 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..febdeff319 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 ? true : false; +} + +bool ChangeInterfaceState(ApplicationManager& application_manager, + const smart_objects::SmartObject& response_from_hmi, + HmiInterfaces::InterfaceID interface) { + bool is_available = false; + if (response_from_hmi[strings::msg_params].keyExists(strings::available)) { + 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; +} + + RequestToHMI::RequestToHMI(const MessageSharedPtr& message, ApplicationManager& application_manager) : CommandImpl(message, application_manager) { @@ -56,10 +79,10 @@ bool RequestToHMI::CleanUp() { void RequestToHMI::Run() {} void RequestToHMI::SendRequest() { - (*message_)[strings::params][strings::protocol_type] = hmi_protocol_type_; - (*message_)[strings::params][strings::protocol_version] = protocol_version_; + (*message_)[strings::params][strings::protocol_type] = hmi_protocol_type_; + (*message_)[strings::params][strings::protocol_version] = protocol_version_; + application_manager_.SendMessageToHMI(message_); - application_manager_.SendMessageToHMI(message_); } } // namespace commands 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..a7e5a95fbb 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); + 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() { + //According wiht 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..d39ff001b5 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); + 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() { + //According wiht new requirment APPLINK-27957 + 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..5d3cafb2f0 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,61 @@ 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); + 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() { + //According wiht new requirment APPLINK-27958 + 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..71750e3738 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,68 @@ 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); + 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() { + //According wiht new requirment APPLINK-27957 + 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..43b5daf847 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,8 @@ 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_, + ui_info_, message); if (hmi_apis::Common_Result::SUCCESS != ui_result_) { (*message_)[strings::msg_params].erase(strings::menu_params); } @@ -326,7 +327,8 @@ 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_, + vr_info_, message); if (hmi_apis::Common_Result::SUCCESS != vr_result_) { (*message_)[strings::msg_params].erase(strings::vr_commands); } @@ -360,6 +362,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 +388,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 +464,17 @@ 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 +545,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..b33d9d3f47 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,17 @@ 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>( - 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); + 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, response_info, message); + const bool result = PrepareResultForMobileResponse(result_code, + HmiInterfaces::HMI_INTERFACE_UI); ApplicationSharedPtr application = application_manager_.application(connection_key()); @@ -125,7 +124,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..bf7af0614d 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,22 @@ 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_, + ui_response_info_, message); break; } case hmi_apis::FunctionID::TTS_Speak: { @@ -180,8 +174,10 @@ 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_, + tts_response_info_, message); break; } case hmi_apis::FunctionID::TTS_StopSpeaking: { @@ -200,56 +196,45 @@ 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) { + response_info ui_alert_info{alert_result_, HmiInterfaces::HMI_INTERFACE_UI, + HmiInterfaces::STATE_NOT_RESPONSE, + false, false, false}; + response_info tts_alert_info{tts_speak_result_, HmiInterfaces::HMI_INTERFACE_TTS, + HmiInterfaces::STATE_NOT_RESPONSE, + false, false, false}; + + 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 resive 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..69cd0301fc 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,8 @@ 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_, ui_response_info_, + message); break; } case hmi_apis::FunctionID::VR_ChangeRegistration: { @@ -202,6 +181,8 @@ 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_, vr_response_info_, + message); break; } case hmi_apis::FunctionID::TTS_ChangeRegistration: { @@ -209,6 +190,8 @@ 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_, tts_response_info_, + message); break; } default: { @@ -237,16 +220,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 +238,87 @@ 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 esponse 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..486cbd8082 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,61 @@ void DeleteCommandRequest::Run() { } } -bool DeleteCommandRequest::CalculateResult() { - 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); - - LOG4CXX_DEBUG(logger_, "Result is " << (result ? "true" : "false")); - - return result; +bool DeleteCommandRequest::PrepareResponseParameters( + mobile_apis::Result::eType& result_code, + std::string& info) { + using namespace helpers; + response_info ui_delete_info{ui_result_, HmiInterfaces::HMI_INTERFACE_UI, + HmiInterfaces::STATE_NOT_RESPONSE, + false, false, false}; + response_info vr_delete_info{vr_result_, HmiInterfaces::HMI_INTERFACE_VR, + HmiInterfaces::STATE_NOT_RESPONSE, + false, false, false}; + 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_, ui_info_, message); 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_, vr_info_, message); break; } default: { @@ -248,37 +202,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..c3117eaf79 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,17 @@ 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, + response_info, message); + const bool result = PrepareResultForMobileResponse(result_code, + HmiInterfaces::HMI_INTERFACE_UI); ApplicationSharedPtr application = application_manager_.application(connection_key()); @@ -168,7 +167,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..dc933ac352 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,12 @@ 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, response_info, message); + const bool result = PrepareResultForMobileResponse(result_code, + HmiInterfaces::HMI_INTERFACE_UI); if (result) { bool ended_successfully = application_manager_.EndAudioPassThrough(); if (ended_successfully) { @@ -68,7 +69,9 @@ 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..ede54f62e7 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,40 @@ 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_, ui_info_, message); // 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_, tts_info_, message); + 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 +174,46 @@ void PerformAudioPassThruRequest::on_event(const event_engine::Event& event) { return; } } + if (HasHmiResponsesToWait()) { + 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_); + + response_info ui_perform_info{result_ui_, HmiInterfaces::HMI_INTERFACE_UI, + HmiInterfaces::STATE_NOT_RESPONSE, + false, false, false}; + response_info tts_perform_info{result_tts_speak_, HmiInterfaces::HMI_INTERFACE_TTS, + HmiInterfaces::STATE_NOT_RESPONSE, + false, false, false}; + + 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,10 +223,7 @@ 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; + for (uint32_t i = 0; i < (*message_)[str::msg_params][str::initial_prompt].length(); ++i) { msg_params[hmi_request::tts_chunks][i][str::text] = @@ -208,9 +234,8 @@ void PerformAudioPassThruRequest::SendSpeakRequest() { // 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; + awaiting_tts_speak_response_ = true; SendHMIRequest(FunctionID::TTS_Speak, &msg_params, true); - } } void PerformAudioPassThruRequest::SendPerformAudioPassThruRequest() { @@ -333,37 +358,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::HasHmiResponsesToWait() { 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..38720555a2 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_, + ui_info_, message); + 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_, + vr_info_, message); + 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,39 @@ 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); + 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 +350,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 +368,39 @@ 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 +408,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 +423,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 +934,29 @@ 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; + response_info ui_perform_info{ui_result_code_, HmiInterfaces::HMI_INTERFACE_UI, + HmiInterfaces::STATE_NOT_RESPONSE, + false, false, false}; + response_info vr_perform_info{vr_result_code_, HmiInterfaces::HMI_INTERFACE_VR, + HmiInterfaces::STATE_NOT_RESPONSE, + false, false, false}; + + 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..a2c48d4606 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, response_info, + message); - HMICapabilities& hmi_capabilities = - application_manager_.hmi_capabilities(); + 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..67aadfa7f1 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>( - 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); - + hmi_apis::Common_Result::eType result_code = + static_cast<hmi_apis::Common_Result::eType>( + message[strings::params][hmi_response::code].asInt()); + const bool result = PrepareResultForMobileResponse(result_code, + HmiInterfaces::HMI_INTERFACE_UI); + std::string response_info; + GetInfo(HmiInterfaces::HMI_INTERFACE_UI, result_code, response_info, + message); 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..a9188e59f0 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, info, message); 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..9b3da9efd0 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,9 @@ 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_, + ui_response_info_, + message); break; } case hmi_apis::FunctionID::TTS_SetGlobalProperties: { @@ -233,6 +242,8 @@ 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_, tts_response_info_, message); break; } default: { @@ -245,54 +256,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; + 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 +279,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; + + response_info ui_properties_info{ui_result_, HmiInterfaces::HMI_INTERFACE_UI, + HmiInterfaces::STATE_NOT_RESPONSE, + false, false, false}; + response_info tts_properties_info{tts_result_, HmiInterfaces::HMI_INTERFACE_TTS, + HmiInterfaces::STATE_NOT_RESPONSE, + false, false, false}; + + 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 +397,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..014918a4aa 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,16 @@ 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, response_info, message); + + 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..13fa4a2c42 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, + response_info, + message); + 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..5c07056afb 100644 --- a/src/components/application_manager/src/commands/mobile/slider_request.cc +++ b/src/components/application_manager/src/commands/mobile/slider_request.cc @@ -133,7 +133,8 @@ void SliderRequest::on_event(const event_engine::Event& event) { LOG4CXX_DEBUG(logger_, "Received UI_Slider event"); - const Common_Result::eType response_code = static_cast<Common_Result::eType>( + const Common_Result::eType response_code = + static_cast<Common_Result::eType>( message[strings::params][hmi_response::code].asInt()); SmartObject response_msg_params = message[strings::msg_params]; @@ -154,13 +155,15 @@ void SliderRequest::on_event(const event_engine::Event& event) { response_msg_params[strings::slider_position] = 0; } } + std::string response_info; + GetInfo(HmiInterfaces::HMI_INTERFACE_UI, response_code, response_info, message); + const bool is_response_success = + PrepareResultForMobileResponse(response_code, HmiInterfaces::HMI_INTERFACE_UI); - const bool is_response_success = Compare<Common_Result::eType, EQ, ONE>( - response_code, Common_Result::SUCCESS, Common_Result::WARNINGS); 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..7735dbc0b9 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..01d599ce97 100644 --- a/src/components/application_manager/test/commands/hmi/CMakeLists.txt +++ b/src/components/application_manager/test/commands/hmi/CMakeLists.txt @@ -39,9 +39,8 @@ 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 + ) 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..f9de7131bd --- /dev/null +++ b/src/components/application_manager/test/commands/hmi/vi_is_ready_request_test.cc @@ -0,0 +1,177 @@ +/* + * 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/vr_is_ready_request_test.cc index e2a5aa56ea..311d78e1d4 100644 --- a/src/components/application_manager/test/commands/hmi/vi_is_ready_response_test.cc +++ b/src/components/application_manager/test/commands/hmi/vr_is_ready_request_test.cc @@ -34,13 +34,8 @@ #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 { @@ -49,7 +44,6 @@ namespace commands_test { namespace hmi_commands_test { using ::testing::_; -using ::testing::ReturnRef; namespace am = ::application_manager; using am::commands::MessageSharedPtr; using am::commands::VIIsReadyResponse; @@ -59,66 +53,17 @@ typedef SharedPtr<VIIsReadyResponse> VIIsReadyResponsePtr; class VIIsReadyResponseTest : public CommandsTest<CommandsTestMocks::kIsNice> { public: VIIsReadyResponseTest() - : message_(CreateMessage()) - , command_(CreateCommand<VIIsReadyResponse>(message_)) {} + : 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); - + Run_CheckCallOfOnVIIsReady_Success) { + EXPECT_CALL(app_mngr_, GetPolicyHandler()) + .WillOnce(ReturnRef(mock_policy_handler_interface_)); + EXPECT_CALL(mock_policy_handler_interface_, OnVIIsReady()); command_->Run(); } 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/hmi_capabilities_test.cc b/src/components/application_manager/test/hmi_capabilities_test.cc index 3f14981f7f..4d4cae30af 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); + 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..8875a6f4c5 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 @@ -43,8 +43,7 @@ namespace components { namespace application_manager_test { class MockHMICapabilities : public ::application_manager::HMICapabilities { - public: - MOCK_CONST_METHOD0(is_hmi_capabilities_initialized, bool()); + public: 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, |