summaryrefslogtreecommitdiff
path: root/src/components/application_manager/src/hmi_state.cc
diff options
context:
space:
mode:
authorJackLivio <jack@livio.io>2018-08-22 14:33:20 -0400
committerJackLivio <jack@livio.io>2018-08-22 14:33:20 -0400
commit2b9dbd15a3170b89a2ba9752faf56d6a7ee0910c (patch)
treec4b5792cb861816ca9c12d42246f4ce333e39285 /src/components/application_manager/src/hmi_state.cc
parent203aedc01958fe8e0825f70599f8cda0f621ae5c (diff)
parent6a436addb2811c3fbc6ff155a8a142aa14c8ec45 (diff)
downloadsdl_core-2b9dbd15a3170b89a2ba9752faf56d6a7ee0910c.tar.gz
Merge remote-tracking branch 'origin/develop' into feature/PLAY_PAUSE_implementation
# Conflicts: # src/appMain/hmi_capabilities.json # src/components/application_manager/src/commands/mobile/subscribe_button_request.cc # src/components/application_manager/test/hmi_capabilities.json # src/components/interfaces/MOBILE_API.xml # src/components/interfaces/QT_HMI_API.xml # src/components/utils/test/test_generator/MOBILE_API.xml
Diffstat (limited to 'src/components/application_manager/src/hmi_state.cc')
-rw-r--r--src/components/application_manager/src/hmi_state.cc167
1 files changed, 119 insertions, 48 deletions
diff --git a/src/components/application_manager/src/hmi_state.cc b/src/components/application_manager/src/hmi_state.cc
index 80628f9f33..aa4c979ae7 100644
--- a/src/components/application_manager/src/hmi_state.cc
+++ b/src/components/application_manager/src/hmi_state.cc
@@ -1,3 +1,4 @@
+
/*
* Copyright (c) 2015, Ford Motor Company
* All rights reserved.
@@ -31,47 +32,60 @@
*/
#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 {
-HmiState::HmiState(uint32_t app_id,
+CREATE_LOGGERPTR_GLOBAL(logger_, "HmiState")
+
+HmiState::HmiState(std::shared_ptr<Application> app,
const ApplicationManager& app_mngr,
StateID state_id)
- : app_id_(app_id)
+ : app_(app)
, state_id_(state_id)
, 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(uint32_t app_id, const ApplicationManager& app_mngr)
- : app_id_(app_id)
+HmiState::HmiState(std::shared_ptr<Application> app,
+ const ApplicationManager& app_mngr)
+ : app_(app)
, state_id_(STATE_ID_REGULAR)
, 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);
+}
void HmiState::set_parent(HmiStatePtr parent) {
DCHECK_OR_RETURN_VOID(parent);
parent_ = parent;
}
-bool HmiState::is_navi_app(const uint32_t app_id) const {
- const ApplicationSharedPtr app = app_mngr_.application(app_id);
- return app ? app->is_navi() : false;
+bool HmiState::is_navi_app() const {
+ return app_->is_navi();
}
-bool HmiState::is_media_app(const uint32_t app_id) const {
- const ApplicationSharedPtr app = app_mngr_.application(app_id);
- return app ? app->is_media_application() : false;
+bool HmiState::is_media_app() const {
+ return app_->is_media_application();
}
-bool HmiState::is_voice_communication_app(const uint32_t app_id) const {
- const ApplicationSharedPtr app = app_mngr_.application(app_id);
- return app ? app->is_voice_communication_supported() : false;
+bool HmiState::is_voice_communication_app() const {
+ return app_->is_voice_communication_supported();
+}
+
+bool HmiState::is_mobile_projection_app() const {
+ return app_->mobile_projection_enabled();
}
mobile_apis::AudioStreamingState::eType VRHmiState::audio_streaming_state()
@@ -80,11 +94,13 @@ mobile_apis::AudioStreamingState::eType VRHmiState::audio_streaming_state()
return AudioStreamingState::NOT_AUDIBLE;
}
-VRHmiState::VRHmiState(uint32_t app_id, const ApplicationManager& app_mngr)
- : HmiState(app_id, app_mngr, STATE_ID_VR_SESSION) {}
+VRHmiState::VRHmiState(std::shared_ptr<Application> app,
+ const ApplicationManager& app_mngr)
+ : HmiState(app, app_mngr, STATE_ID_VR_SESSION) {}
-TTSHmiState::TTSHmiState(uint32_t app_id, const ApplicationManager& app_mngr)
- : HmiState(app_id, app_mngr, STATE_ID_TTS_SESSION) {}
+TTSHmiState::TTSHmiState(std::shared_ptr<Application> app,
+ const ApplicationManager& app_mngr)
+ : HmiState(app, app_mngr, STATE_ID_TTS_SESSION) {}
mobile_apis::AudioStreamingState::eType TTSHmiState::audio_streaming_state()
const {
@@ -101,9 +117,24 @@ mobile_apis::AudioStreamingState::eType TTSHmiState::audio_streaming_state()
return expected_state;
}
-NaviStreamingHmiState::NaviStreamingHmiState(uint32_t app_id,
+VideoStreamingHmiState::VideoStreamingHmiState(
+ std::shared_ptr<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(std::shared_ptr<Application> app,
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 {
@@ -111,19 +142,23 @@ NaviStreamingHmiState::audio_streaming_state() const {
using namespace mobile_apis;
AudioStreamingState::eType expected_state = parent()->audio_streaming_state();
- if (!is_navi_app(app_id_) && 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;
}
-PhoneCallHmiState::PhoneCallHmiState(uint32_t app_id,
+PhoneCallHmiState::PhoneCallHmiState(std::shared_ptr<Application> app,
const ApplicationManager& app_mngr)
- : HmiState(app_id, app_mngr, STATE_ID_PHONE_CALL) {}
+ : HmiState(app, app_mngr, STATE_ID_PHONE_CALL) {}
mobile_apis::HMILevel::eType PhoneCallHmiState::hmi_level() const {
using namespace helpers;
@@ -133,22 +168,22 @@ mobile_apis::HMILevel::eType PhoneCallHmiState::hmi_level() const {
HMILevel::HMI_NONE)) {
return parent()->hmi_level();
}
- if (is_navi_app(app_id_)) {
+ if (is_navi_app() || is_mobile_projection_app()) {
return HMILevel::HMI_LIMITED;
}
- if (!is_media_app(app_id_)) {
+ if (!is_media_app()) {
return parent()->hmi_level();
}
return HMILevel::HMI_BACKGROUND;
}
-SafetyModeHmiState::SafetyModeHmiState(uint32_t app_id,
+SafetyModeHmiState::SafetyModeHmiState(std::shared_ptr<Application> app,
const ApplicationManager& app_mngr)
- : HmiState(app_id, app_mngr, STATE_ID_SAFETY_MODE) {}
+ : HmiState(app, app_mngr, STATE_ID_SAFETY_MODE) {}
-DeactivateHMI::DeactivateHMI(uint32_t app_id,
+DeactivateHMI::DeactivateHMI(std::shared_ptr<Application> app,
const ApplicationManager& app_mngr)
- : HmiState(app_id, app_mngr, STATE_ID_DEACTIVATE_HMI) {}
+ : HmiState(app, app_mngr, STATE_ID_DEACTIVATE_HMI) {}
mobile_apis::HMILevel::eType DeactivateHMI::hmi_level() const {
using namespace helpers;
@@ -158,31 +193,30 @@ mobile_apis::HMILevel::eType DeactivateHMI::hmi_level() const {
HMILevel::HMI_NONE)) {
return parent()->hmi_level();
}
+
return HMILevel::HMI_BACKGROUND;
}
-AudioSource::AudioSource(uint32_t app_id, const ApplicationManager& app_mngr)
- : HmiState(app_id, app_mngr, STATE_ID_AUDIO_SOURCE) {}
+AudioSource::AudioSource(std::shared_ptr<Application> app,
+ const ApplicationManager& app_mngr)
+ : HmiState(app, 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(app_id_)) {
- return HMILevel::HMI_LIMITED;
+ if (mobile_apis::HMILevel::HMI_FULL == parent()->hmi_level()) {
+ return mobile_apis::HMILevel::HMI_FULL;
}
- return HMILevel::HMI_BACKGROUND;
+
+ return mobile_apis::HMILevel::HMI_BACKGROUND;
}
-EmbeddedNavi::EmbeddedNavi(uint32_t app_id, const ApplicationManager& app_mngr)
- : HmiState(app_id, app_mngr, STATE_ID_EMBEDDED_NAVI) {}
+EmbeddedNavi::EmbeddedNavi(std::shared_ptr<Application> app,
+ const ApplicationManager& app_mngr)
+ : HmiState(app, app_mngr, STATE_ID_EMBEDDED_NAVI) {}
mobile_apis::HMILevel::eType EmbeddedNavi::hmi_level() const {
using namespace mobile_apis;
@@ -192,9 +226,46 @@ mobile_apis::HMILevel::eType EmbeddedNavi::hmi_level() const {
HMILevel::HMI_NONE)) {
return parent()->hmi_level();
}
- if (is_media_app(app_id_)) {
- 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