diff options
Diffstat (limited to 'src/components/application_manager/src/hmi_state.cc')
-rw-r--r-- | src/components/application_manager/src/hmi_state.cc | 103 |
1 files changed, 80 insertions, 23 deletions
diff --git a/src/components/application_manager/src/hmi_state.cc b/src/components/application_manager/src/hmi_state.cc index bc1ccd8f42..e1bc2b5125 100644 --- a/src/components/application_manager/src/hmi_state.cc +++ b/src/components/application_manager/src/hmi_state.cc @@ -32,11 +32,16 @@ */ #include "application_manager/hmi_state.h" +#include <ostream> +#include <boost/assign.hpp> +#include <boost/bimap.hpp> #include "application_manager/application_manager.h" #include "utils/helpers.h" namespace application_manager { +CREATE_LOGGERPTR_GLOBAL(logger_, "HmiState") + HmiState::HmiState(utils::SharedPtr<Application> app, const ApplicationManager& app_mngr, StateID state_id) @@ -45,7 +50,10 @@ HmiState::HmiState(utils::SharedPtr<Application> app, , app_mngr_(app_mngr) , hmi_level_(mobile_apis::HMILevel::INVALID_ENUM) , audio_streaming_state_(mobile_apis::AudioStreamingState::INVALID_ENUM) - , system_context_(mobile_apis::SystemContext::INVALID_ENUM) {} + , video_streaming_state_(mobile_apis::VideoStreamingState::INVALID_ENUM) + , system_context_(mobile_apis::SystemContext::INVALID_ENUM) { + LOG4CXX_DEBUG(logger_, *this); +} HmiState::HmiState(utils::SharedPtr<Application> app, const ApplicationManager& app_mngr) @@ -54,7 +62,10 @@ HmiState::HmiState(utils::SharedPtr<Application> app, , app_mngr_(app_mngr) , hmi_level_(mobile_apis::HMILevel::INVALID_ENUM) , audio_streaming_state_(mobile_apis::AudioStreamingState::INVALID_ENUM) - , system_context_(mobile_apis::SystemContext::INVALID_ENUM) {} + , video_streaming_state_(mobile_apis::VideoStreamingState::INVALID_ENUM) + , system_context_(mobile_apis::SystemContext::INVALID_ENUM) { + LOG4CXX_DEBUG(logger_, *this); +} DEPRECATED HmiState::HmiState(uint32_t app_id, const ApplicationManager& app_mngr, @@ -135,13 +146,24 @@ mobile_apis::AudioStreamingState::eType TTSHmiState::audio_streaming_state() return expected_state; } +VideoStreamingHmiState::VideoStreamingHmiState( + utils::SharedPtr<Application> app, const ApplicationManager& app_mngr) + : HmiState(app, app_mngr, STATE_ID_VIDEO_STREAMING) {} + +mobile_apis::VideoStreamingState::eType +VideoStreamingHmiState::video_streaming_state() const { + if (app_->IsVideoApplication()) { + return parent()->video_streaming_state(); + } + + return mobile_apis::VideoStreamingState::NOT_STREAMABLE; +} + NaviStreamingHmiState::NaviStreamingHmiState(utils::SharedPtr<Application> app, const ApplicationManager& app_mngr) - : HmiState(app, app_mngr, STATE_ID_NAVI_STREAMING) {} - -DEPRECATED NaviStreamingHmiState::NaviStreamingHmiState( - uint32_t app_id, const ApplicationManager& app_mngr) - : HmiState(app_id, app_mngr, STATE_ID_NAVI_STREAMING) {} + : VideoStreamingHmiState(app, app_mngr) { + set_state_id(STATE_ID_NAVI_STREAMING); +} mobile_apis::AudioStreamingState::eType NaviStreamingHmiState::audio_streaming_state() const { @@ -149,13 +171,17 @@ NaviStreamingHmiState::audio_streaming_state() const { using namespace mobile_apis; AudioStreamingState::eType expected_state = parent()->audio_streaming_state(); - if (!is_navi_app() && AudioStreamingState::AUDIBLE == expected_state) { + if (!is_navi_app() && Compare<AudioStreamingState::eType, EQ, ONE>( + expected_state, + AudioStreamingState::AUDIBLE, + AudioStreamingState::ATTENUATED)) { if (app_mngr_.is_attenuated_supported()) { expected_state = AudioStreamingState::ATTENUATED; } else { expected_state = AudioStreamingState::NOT_AUDIBLE; } } + return expected_state; } @@ -208,6 +234,7 @@ mobile_apis::HMILevel::eType DeactivateHMI::hmi_level() const { HMILevel::HMI_NONE)) { return parent()->hmi_level(); } + return HMILevel::HMI_BACKGROUND; } @@ -220,20 +247,13 @@ DEPRECATED AudioSource::AudioSource(uint32_t app_id, : HmiState(app_id, app_mngr, STATE_ID_AUDIO_SOURCE) {} mobile_apis::HMILevel::eType AudioSource::hmi_level() const { - using namespace mobile_apis; - using namespace helpers; - // TODO(AOleynik): That NONE check is necessary to avoid issue during + // Checking for NONE is necessary to avoid issue during // calculation of HMI level during setting default HMI level - // Should be investigated (used in multiple places here), since looks weird - if (Compare<HMILevel::eType, EQ, ONE>(parent()->hmi_level(), - HMILevel::HMI_BACKGROUND, - HMILevel::HMI_NONE)) { - return parent()->hmi_level(); + if (mobile_apis::HMILevel::HMI_NONE == parent()->hmi_level()) { + return mobile_apis::HMILevel::HMI_NONE; } - if (is_navi_app() || is_voice_communication_app()) { - return HMILevel::HMI_LIMITED; - } - return HMILevel::HMI_BACKGROUND; + + return mobile_apis::HMILevel::HMI_BACKGROUND; } EmbeddedNavi::EmbeddedNavi(utils::SharedPtr<Application> app, @@ -252,9 +272,46 @@ mobile_apis::HMILevel::eType EmbeddedNavi::hmi_level() const { HMILevel::HMI_NONE)) { return parent()->hmi_level(); } - if (is_media_app()) { - return HMILevel::HMI_LIMITED; - } return HMILevel::HMI_BACKGROUND; } + +namespace { +typedef boost::bimap<HmiState::StateID, std::string> StateID2StrMap; +const StateID2StrMap kStateID2StrMap = + boost::assign::list_of<StateID2StrMap::relation>( + HmiState::StateID::STATE_ID_CURRENT, "CURRENT")( + HmiState::StateID::STATE_ID_REGULAR, "REGULAR")( + HmiState::StateID::STATE_ID_POSTPONED, "POSTPONED")( + HmiState::StateID::STATE_ID_PHONE_CALL, "PHONE_CALL")( + HmiState::StateID::STATE_ID_SAFETY_MODE, "SAFETY_MODE")( + HmiState::StateID::STATE_ID_VR_SESSION, "VR_SESSION")( + HmiState::StateID::STATE_ID_TTS_SESSION, "TTS_SESSION")( + HmiState::StateID::STATE_ID_VIDEO_STREAMING, "VIDEO_STREAMING")( + HmiState::StateID::STATE_ID_NAVI_STREAMING, "NAVI_STREAMING")( + HmiState::StateID::STATE_ID_DEACTIVATE_HMI, "DEACTIVATE_HMI")( + HmiState::StateID::STATE_ID_AUDIO_SOURCE, "AUDIO_SOURCE")( + HmiState::StateID::STATE_ID_EMBEDDED_NAVI, "EMBEDDED_NAVI"); +} // anonymous namespace + +std::ostream& operator<<(std::ostream& os, const HmiState::StateID src) { + try { + os << kStateID2StrMap.left.at(src); + } catch (const std::exception&) { + // specified element have NOT been found + os << "UNRECOGNIZED(" << static_cast<int>(src) << ")"; + } + + return os; +} + +std::ostream& operator<<(std::ostream& os, const HmiState& src) { + os << "HMIState(app id:" << src.app_->app_id() << ", state:" << src.state_id() + << ", hmi_level:" << src.hmi_level() + << ", audio:" << src.audio_streaming_state() + << ", video:" << src.video_streaming_state() + << ", context:" << src.system_context() << ')'; + + return os; } + +} // namespace application_manager |