diff options
author | Artem Nosach <ANosach@luxoft.com> | 2015-04-06 22:28:23 +0300 |
---|---|---|
committer | Artem Nosach <ANosach@luxoft.com> | 2015-04-23 15:33:23 +0300 |
commit | d2160c7044072e21dd9182756e37c9d26f6e7128 (patch) | |
tree | 20a56afaa17bae18a34eb21f7bb5cd759e8eebce | |
parent | abf0e0f76025f11fb046b5f92fc3d59c7966ba3c (diff) | |
download | sdl_core-d2160c7044072e21dd9182756e37c9d26f6e7128.tar.gz |
Rework application.
3 files changed, 213 insertions, 77 deletions
diff --git a/src/components/application_manager/include/application_manager/application.h b/src/components/application_manager/include/application_manager/application.h index b00aae3a4d..c8048f61f3 100644 --- a/src/components/application_manager/include/application_manager/application.h +++ b/src/components/application_manager/include/application_manager/application.h @@ -43,14 +43,17 @@ #include "connection_handler/device.h" #include "application_manager/message.h" #include "application_manager/hmi_state.h" +#include "protocol/service_type.h" namespace NsSmartDeviceLink { namespace NsSmartObjects { + class SmartObject; } } namespace application_manager { +using protocol_handler::ServiceType; namespace mobile_api = mobile_apis; @@ -400,19 +403,38 @@ class Application : public virtual InitialApplicationData, virtual void CloseActiveMessage() = 0; virtual bool IsFullscreen() const = 0; virtual void ChangeSupportingAppHMIType() = 0; + virtual bool is_navi() const = 0; virtual void set_is_navi(bool allow) = 0; - virtual void StartVideoStartStreamRetryTimer() = 0; - virtual void StartAudioStartStreamRetryTimer() = 0; - virtual bool hmi_supports_navi_video_streaming() const = 0; - virtual void set_hmi_supports_navi_video_streaming(bool supports) = 0; - virtual bool hmi_supports_navi_audio_streaming() const = 0; - virtual void set_hmi_supports_navi_audio_streaming(bool supports) = 0; - - bool is_streaming_allowed() const { return can_stream_;} - void set_streaming_allowed(bool can_stream) { can_stream_ = can_stream;} - bool streaming() const {return streaming_;} - void set_streaming(bool can_stream) { streaming_ = can_stream;} + + virtual bool video_streaming_started() const = 0; + virtual void set_video_streaming_started(bool state) = 0; + virtual bool audio_streaming_started() const = 0; + virtual void set_audio_streaming_started(bool state) = 0; + + /** + * @brief Starts streaming service for application + * @param service_type Type of streaming service + */ + virtual void StartStreaming(ServiceType service_type) = 0; + + /** + * @brief Stops streaming service for application + * @param service_type Type of streaming service + */ + virtual void StopStreaming(ServiceType service_type) = 0; + + /** + * @brief Suspends streaming process for application + * @param service_type Type of streaming service + */ + virtual void SuspendStreaming(ServiceType service_type) = 0; + + /** + * @brief Wakes up streaming process for application + * @param service_type Type of streaming service + */ + virtual void WakeUpStreaming(ServiceType service_type) = 0; virtual bool is_voice_communication_supported() const = 0; virtual void set_voice_communication_supported( @@ -682,8 +704,6 @@ class Application : public virtual InitialApplicationData, std::string url_; std::string package_name_; std::string device_id_; - bool can_stream_; - bool streaming_; ssize_t connection_id_; bool is_greyed_out_; }; diff --git a/src/components/application_manager/include/application_manager/application_impl.h b/src/components/application_manager/include/application_manager/application_impl.h index 5f15bbfd60..d5e9222724 100644 --- a/src/components/application_manager/include/application_manager/application_impl.h +++ b/src/components/application_manager/include/application_manager/application_impl.h @@ -47,11 +47,17 @@ #include "connection_handler/device.h" #include "utils/timer_thread.h" #include "utils/lock.h" +#include "protocol/service_type.h" + namespace usage_statistics { + class StatisticsManager; } // namespace usage_statistics namespace application_manager { +using namespace utils; +using namespace timer; +using protocol_handler::ServiceType; namespace mobile_api = mobile_apis; @@ -79,15 +85,19 @@ class ApplicationImpl : public virtual InitialApplicationDataImpl, */ virtual void ChangeSupportingAppHMIType(); - // navi inline bool is_navi() const { return is_navi_; } void set_is_navi(bool allow); - bool hmi_supports_navi_video_streaming() const; - void set_hmi_supports_navi_video_streaming(bool supports); - bool hmi_supports_navi_audio_streaming() const; - void set_hmi_supports_navi_audio_streaming(bool supports); - void StartVideoStartStreamRetryTimer(); - void StartAudioStartStreamRetryTimer(); + + bool video_streaming_started() const; + void set_video_streaming_started(bool state); + bool audio_streaming_started() const; + void set_audio_streaming_started(bool state); + + void StartStreaming(ServiceType service_type); + void StopStreaming(ServiceType service_type); + + void SuspendStreaming(ServiceType service_type); + void WakeUpStreaming(ServiceType service_type); virtual bool is_voice_communication_supported() const; virtual void set_voice_communication_supported( @@ -234,15 +244,35 @@ class ApplicationImpl : public virtual InitialApplicationDataImpl, void LoadPersistentFiles(); private: + typedef SharedPtr<TimerThread<ApplicationImpl>> ApplicationTimerPtr; - // interfaces for NAVI retry sequence + /** + * @brief Callback for video start stream retry timer. + * Sends start video stream request to HMI + */ void OnVideoStartStreamRetry(); + + /** + * @brief Callback for audio start stream retry timer. + * Sends start audio stream request to HMI + */ void OnAudioStartStreamRetry(); + /** + * @brief Callback for video streaming suspend timer. + * Suspends video streaming process for application + */ + void OnVideoStreamSuspend(); + + /** + * @brief Callback for audio streaming suspend timer. + * Suspends audio streaming process for application + */ + void OnAudioStreamSuspend(); + std::string hash_val_; uint32_t grammar_id_; - Version version_; std::string app_name_; uint32_t hmi_app_id_; @@ -250,8 +280,14 @@ class ApplicationImpl : public virtual InitialApplicationDataImpl, smart_objects::SmartObject* active_message_; bool is_media_; bool is_navi_; - bool hmi_supports_navi_video_streaming_; - bool hmi_supports_navi_audio_streaming_; + + bool video_streaming_started_; + bool audio_streaming_started_; + bool video_streaming_suspended_; + bool audio_streaming_suspended_; + sync_primitives::Lock video_streaming_suspended_lock_; + sync_primitives::Lock audio_streaming_suspended_lock_; + bool is_app_allowed_; bool has_been_activated_; bool tts_properties_in_none_; @@ -269,11 +305,15 @@ class ApplicationImpl : public virtual InitialApplicationDataImpl, UsageStatistics usage_report_; ProtocolVersion protocol_version_; bool is_voice_communication_application_; - // NAVI retry stream + uint32_t video_stream_retry_number_; uint32_t audio_stream_retry_number_; - utils::SharedPtr<timer::TimerThread<ApplicationImpl>> video_stream_retry_timer_; - utils::SharedPtr<timer::TimerThread<ApplicationImpl>> audio_stream_retry_timer_; + uint32_t video_stream_suspend_timeout_; + uint32_t audio_stream_suspend_timeout_; + ApplicationTimerPtr video_stream_retry_timer_; + ApplicationTimerPtr audio_stream_retry_timer_; + ApplicationTimerPtr video_stream_suspend_timer_; + ApplicationTimerPtr audio_stream_suspend_timer_; /** * @brief Defines number per time in seconds limits diff --git a/src/components/application_manager/src/application_impl.cc b/src/components/application_manager/src/application_impl.cc index 23f1798c60..81c9fe23d1 100644 --- a/src/components/application_manager/src/application_impl.cc +++ b/src/components/application_manager/src/application_impl.cc @@ -85,8 +85,10 @@ ApplicationImpl::ApplicationImpl(uint32_t application_id, active_message_(NULL), is_media_(false), is_navi_(false), - hmi_supports_navi_video_streaming_(false), - hmi_supports_navi_audio_streaming_(false), + video_streaming_started_(false), + audio_streaming_started_(false), + video_streaming_suspended_(true), + audio_streaming_suspended_(true), is_app_allowed_(true), has_been_activated_(false), tts_properties_in_none_(false), @@ -106,7 +108,6 @@ ApplicationImpl::ApplicationImpl(uint32_t application_id, cmd_number_to_time_limits_[mobile_apis::FunctionID::GetVehicleDataID] = {date_time::DateTime::getCurrentTime(), 0}; - set_mobile_app_id(mobile_app_id); set_name(app_name); @@ -122,6 +123,29 @@ ApplicationImpl::ApplicationImpl(uint32_t application_id, mobile_apis::AudioStreamingState::INVALID_ENUM, mobile_api::SystemContext::SYSCTXT_MAIN); hmi_states_.push_back(initial_state); + + video_stream_suspend_timeout_ = + profile::Profile::instance()->video_data_stopped_timeout() / 1000; + audio_stream_suspend_timeout_ = + profile::Profile::instance()->audio_data_stopped_timeout() / 1000; + + video_stream_retry_timer_ = ApplicationTimerPtr( + new timer::TimerThread<ApplicationImpl>( + "VideoStartStreamRetry", this, + &ApplicationImpl::OnVideoStartStreamRetry, true)); + audio_stream_retry_timer_ = ApplicationTimerPtr( + new timer::TimerThread<ApplicationImpl>( + "AudioStartStreamRetry", this, + &ApplicationImpl::OnAudioStartStreamRetry, true)); + + video_stream_suspend_timer_ = ApplicationTimerPtr( + new timer::TimerThread<ApplicationImpl>( + "VideoStreamSuspend", this, + &ApplicationImpl::OnVideoStreamSuspend, true)); + audio_stream_suspend_timer_ = ApplicationTimerPtr( + new timer::TimerThread<ApplicationImpl>( + "AudioStreamSuspend", this, + &ApplicationImpl::OnAudioStreamSuspend, true)); } ApplicationImpl::~ApplicationImpl() { @@ -362,72 +386,110 @@ bool ApplicationImpl::tts_properties_in_full() { return tts_properties_in_full_; } -void ApplicationImpl::StartVideoStartStreamRetryTimer() { - LOG4CXX_AUTO_TRACE(logger_); - if (video_stream_retry_timer_ && video_stream_retry_timer_->isRunning()) { - LOG4CXX_INFO(logger_, "Video start stream retry timer is already running"); - return; +void ApplicationImpl::set_video_streaming_started(bool state) { + if (state) { + if (video_stream_retry_timer_->isRunning()) { + video_stream_retry_timer_->stop(); + video_streaming_started_ = state; + } + } else { + video_streaming_started_ = state; } +} - std::pair<uint32_t, int32_t> stream_retry = - profile::Profile::instance()->start_stream_retry_amount(); - video_stream_retry_number_ = stream_retry.first; - if (!video_stream_retry_timer_) { - video_stream_retry_timer_ = - utils::SharedPtr<timer::TimerThread<ApplicationImpl>>( - new timer::TimerThread<ApplicationImpl>( - "VideoStartStreamRetry", this, - &ApplicationImpl::OnVideoStartStreamRetry, true)); +bool ApplicationImpl::video_streaming_started() const { + return video_streaming_started_; +} + +void ApplicationImpl::set_audio_streaming_started(bool state) { + if (state) { + if (audio_stream_retry_timer_->isRunning()) { + audio_stream_retry_timer_->stop(); + audio_streaming_started_ = state; + } + } else { + audio_streaming_started_ = state; } - video_stream_retry_timer_->start(stream_retry.second); - LOG4CXX_INFO(logger_, "Video start stream retry timer started"); } -void ApplicationImpl::StartAudioStartStreamRetryTimer() { +bool ApplicationImpl::audio_streaming_started() const { + return audio_streaming_started_; +} + +void ApplicationImpl::StartStreaming(ServiceType service_type) { LOG4CXX_AUTO_TRACE(logger_); - if (audio_stream_retry_timer_ && audio_stream_retry_timer_->isRunning()) { - LOG4CXX_INFO(logger_, "Audio start stream retry timer is already running"); - return; - } std::pair<uint32_t, int32_t> stream_retry = profile::Profile::instance()->start_stream_retry_amount(); - audio_stream_retry_number_ = stream_retry.first; - if (!audio_stream_retry_timer_) { - audio_stream_retry_timer_ = - utils::SharedPtr<timer::TimerThread<ApplicationImpl>>( - new timer::TimerThread<ApplicationImpl>( - "AudioStartStreamRetry", this, - &ApplicationImpl::OnAudioStartStreamRetry, true)); + + if (ServiceType::kMobileNav == service_type) { + if (!video_streaming_started()) { + MessageHelper::SendNaviStartStream(app_id()); + video_stream_retry_number_ = stream_retry.first; + video_stream_retry_timer_->start(stream_retry.second); + } + } else if (ServiceType::kAudio == service_type) { + if (!audio_streaming_started()) { + MessageHelper::SendAudioStartStream(app_id()); + audio_stream_retry_number_ = stream_retry.first; + audio_stream_retry_timer_->start(stream_retry.second); + } } - audio_stream_retry_timer_->start(stream_retry.second); - LOG4CXX_INFO(logger_, "Audio start stream retry timer started"); } -void ApplicationImpl::set_hmi_supports_navi_video_streaming(bool supports) { - hmi_supports_navi_video_streaming_ = supports; +void ApplicationImpl::StopStreaming(ServiceType service_type) { + LOG4CXX_AUTO_TRACE(logger_); - if (supports && video_stream_retry_timer_ && - video_stream_retry_timer_->isRunning()) { + if (ServiceType::kMobileNav == service_type) { video_stream_retry_timer_->stop(); + if (video_streaming_started()) { + video_stream_suspend_timer_->stop(); + MessageHelper::SendNaviStopStream(app_id()); + set_video_streaming_started(false); + } + } else if (ServiceType::kAudio == service_type) { + audio_stream_retry_timer_->stop(); + if (audio_streaming_started()) { + audio_stream_suspend_timer_->stop(); + MessageHelper::SendAudioStopStream(app_id()); + set_audio_streaming_started(false); + } } } -bool ApplicationImpl::hmi_supports_navi_video_streaming() const { - return hmi_supports_navi_video_streaming_; -} - -void ApplicationImpl::set_hmi_supports_navi_audio_streaming(bool supports) { - hmi_supports_navi_audio_streaming_ = supports; +void ApplicationImpl::SuspendStreaming(ServiceType service_type) { + LOG4CXX_AUTO_TRACE(logger_); - if (supports && audio_stream_retry_timer_ && - audio_stream_retry_timer_->isRunning()) { - audio_stream_retry_timer_->stop(); + if (ServiceType::kMobileNav == service_type) { + video_stream_suspend_timer_->suspend(); + sync_primitives::AutoLock lock(video_streaming_suspended_lock_); + video_streaming_suspended_ = true; + } else if (ServiceType::kAudio == service_type) { + audio_stream_suspend_timer_->suspend(); + sync_primitives::AutoLock lock(audio_streaming_suspended_lock_); + audio_streaming_suspended_ = true; } + MessageHelper::SendOnDataStreaming(service_type, false); } -bool ApplicationImpl::hmi_supports_navi_audio_streaming() const { - return hmi_supports_navi_audio_streaming_; +void ApplicationImpl::WakeUpStreaming(ServiceType service_type) { + LOG4CXX_AUTO_TRACE(logger_); + + if (ServiceType::kMobileNav == service_type) { + sync_primitives::AutoLock lock(video_streaming_suspended_lock_); + if (video_streaming_suspended_) { + MessageHelper::SendOnDataStreaming(ServiceType::kMobileNav, true); + video_streaming_suspended_ = false; + } + video_stream_suspend_timer_->start(video_stream_suspend_timeout_); + } else if (ServiceType::kAudio == service_type) { + sync_primitives::AutoLock lock(audio_streaming_suspended_lock_); + if (audio_streaming_suspended_) { + MessageHelper::SendOnDataStreaming(ServiceType::kAudio, true); + audio_streaming_suspended_ = false; + } + audio_stream_suspend_timer_->start(audio_stream_suspend_timeout_); + } } void ApplicationImpl::OnVideoStartStreamRetry() { @@ -436,10 +498,11 @@ void ApplicationImpl::OnVideoStartStreamRetry() { LOG4CXX_INFO(logger_, "Send video start stream retry " << video_stream_retry_number_); - application_manager::MessageHelper::SendNaviStartStream(app_id()); + MessageHelper::SendNaviStartStream(app_id()); --video_stream_retry_number_; } else { video_stream_retry_timer_->suspend(); + ApplicationManagerImpl::instance()->EndNaviServices(app_id()); LOG4CXX_INFO(logger_, "Video start stream retry timer stopped"); } } @@ -450,14 +513,27 @@ void ApplicationImpl::OnAudioStartStreamRetry() { LOG4CXX_INFO(logger_, "Send audio start stream retry " << audio_stream_retry_number_); - application_manager::MessageHelper::SendAudioStartStream(app_id()); + MessageHelper::SendAudioStartStream(app_id()); --audio_stream_retry_number_; } else { audio_stream_retry_timer_->suspend(); + ApplicationManagerImpl::instance()->EndNaviServices(app_id()); LOG4CXX_INFO(logger_, "Audio start stream retry timer stopped"); } } +void ApplicationImpl::OnVideoStreamSuspend() { + LOG4CXX_AUTO_TRACE(logger_); + LOG4CXX_INFO(logger_, "Suspend video streaming by timer"); + SuspendStreaming(ServiceType::kMobileNav); +} + +void ApplicationImpl::OnAudioStreamSuspend() { + LOG4CXX_AUTO_TRACE(logger_); + LOG4CXX_INFO(logger_, "Suspend audio streaming by timer"); + SuspendStreaming(ServiceType::kAudio); +} + void ApplicationImpl::increment_put_file_in_none_count() { ++put_file_in_none_count_; } |