diff --git a/src/components/application_manager/include/application_manager/application_manager_impl.h b/src/components/application_manager/include/application_manager/application_manager_impl.h index e88c954c189..4330bdde067 100644 --- a/src/components/application_manager/include/application_manager/application_manager_impl.h +++ b/src/components/application_manager/include/application_manager/application_manager_impl.h @@ -828,6 +828,10 @@ class ApplicationManagerImpl bool result, std::vector& rejected_params) OVERRIDE; + bool SetNaviServiceStatus(uint32_t connection_key, + protocol_handler::ServiceType service_type, + bool is_started) FINAL; + /** * @brief Callback calls when application starts/stops data streaming * @param app_id Streaming application id diff --git a/src/components/application_manager/src/application_manager_impl.cc b/src/components/application_manager/src/application_manager_impl.cc index 8044e8b6cd1..7d75aecffb4 100644 --- a/src/components/application_manager/src/application_manager_impl.cc +++ b/src/components/application_manager/src/application_manager_impl.cc @@ -1790,23 +1790,6 @@ bool ApplicationManagerImpl::StartNaviService( LOG4CXX_AUTO_TRACE(logger_); if (HMILevelAllowsStreaming(app_id, service_type)) { - { - sync_primitives::AutoLock lock(navi_service_status_lock_); - - NaviServiceStatusMap::iterator it = navi_service_status_.find(app_id); - if (navi_service_status_.end() == it) { - std::pair res = - navi_service_status_.insert( - std::pair >( - app_id, std::make_pair(false, false))); - if (!res.second) { - LOG4CXX_WARN(logger_, "Navi service refused"); - return false; - } - it = res.first; - } - } - if (service_type == ServiceType::kMobileNav) { smart_objects::SmartObject converted_params(smart_objects::SmartType_Map); ConvertVideoParamsToSO(converted_params, params); @@ -1866,17 +1849,11 @@ void ApplicationManagerImpl::OnStreamingConfigured( sync_primitives::AutoLock lock(navi_service_status_lock_); NaviServiceStatusMap::iterator it = navi_service_status_.find(app_id); - if (navi_service_status_.end() == it) { + if (navi_service_status_.end() == it && !result) { LOG4CXX_WARN(logger_, "Application not found in navi status map"); connection_handler().NotifyServiceStartedResult(app_id, false, empty); return; } - - // Fill NaviServices map. Set true to first value of pair if - // we've started video service or to second value if we've - // started audio service - service_type == ServiceType::kMobileNav ? it->second.first = true - : it->second.second = true; } application(app_id)->StartStreaming(service_type); @@ -1889,26 +1866,56 @@ void ApplicationManagerImpl::OnStreamingConfigured( } } -void ApplicationManagerImpl::StopNaviService( - uint32_t app_id, protocol_handler::ServiceType service_type) { +bool ApplicationManagerImpl::SetNaviServiceStatus( + uint32_t connection_key, + protocol_handler::ServiceType service_type, + bool is_started) { using namespace protocol_handler; LOG4CXX_AUTO_TRACE(logger_); + auto app = application(connection_key); + if (!app) { + LOG4CXX_DEBUG( + logger_, + "Application with app_id: " << connection_key << " is not found"); + return false; + } + { sync_primitives::AutoLock lock(navi_service_status_lock_); - NaviServiceStatusMap::iterator it = navi_service_status_.find(app_id); - if (navi_service_status_.end() == it) { - LOG4CXX_WARN(logger_, - "No Information about navi service " << service_type); + NaviServiceStatusMap::iterator it = + navi_service_status_.find(app->app_id()); + if (navi_service_status_.end() == it && (is_started)) { + std::pair res = + navi_service_status_.insert( + std::pair >( + app->app_id(), std::make_pair(false, false))); + if (!res.second) { + LOG4CXX_WARN(logger_, "Navi service refused"); + return false; + } + it = res.first; } else { - // Fill NaviServices map. Set false to first value of pair if - // we've stopped video service or to second value if we've - // stopped audio service - service_type == ServiceType::kMobileNav ? it->second.first = false - : it->second.second = false; + LOG4CXX_DEBUG(logger_, + "Application with app_id: " + << app->app_id() << " is not found in navi status map"); + return false; } + + service_type == ServiceType::kMobileNav ? it->second.first = is_started + : it->second.second = is_started; + LOG4CXX_DEBUG(logger_, + "ServiceType: " << service_type << " is started: " + << std::boolalpha << is_started); + return true; } +} + +void ApplicationManagerImpl::StopNaviService( + uint32_t app_id, protocol_handler::ServiceType service_type) { + using namespace protocol_handler; + LOG4CXX_AUTO_TRACE(logger_); ApplicationSharedPtr app = application(app_id); if (!app) { @@ -1916,6 +1923,13 @@ void ApplicationManagerImpl::StopNaviService( return; } + if (!SetNaviServiceStatus(app->app_id(), service_type, false)) { + LOG4CXX_DEBUG(logger_, + "Application with app_id: " + << app->app_id() << " not found in navi status map"); + return; + } + app->StopStreaming(service_type); } @@ -2038,7 +2052,7 @@ void ApplicationManagerImpl::OnServiceEndedCallback( if (Compare( type, ServiceType::kMobileNav, ServiceType::kAudio)) { - StopNaviService(session_key, type); + StopNaviService(static_cast(session_key), type); } } @@ -3395,6 +3409,8 @@ void ApplicationManagerImpl::EndNaviServices(uint32_t app_id) { LOG4CXX_ERROR(logger_, "No info about navi servicies for app"); return; } + LOG4CXX_DEBUG(logger_, "VEDIO_KEK: " << it->second.first); + LOG4CXX_DEBUG(logger_, "AUDIO_KEK: " << it->second.second); end_video = it->second.first; end_audio = it->second.second; } diff --git a/src/components/protocol_handler/include/protocol_handler/service_status_update_handler.h b/src/components/protocol_handler/include/protocol_handler/service_status_update_handler.h index c94ddb91e4b..f62649c30fe 100644 --- a/src/components/protocol_handler/include/protocol_handler/service_status_update_handler.h +++ b/src/components/protocol_handler/include/protocol_handler/service_status_update_handler.h @@ -80,6 +80,10 @@ class ServiceStatusUpdateHandler { const protocol_handler::ServiceType service_type, const ServiceStatus service_status); + void SetNaviServiceStatus(uint32_t app_id, + protocol_handler::ServiceType service_type, + bool is_opened); + private: ServiceStatusUpdateHandlerListener* listener_; }; diff --git a/src/components/protocol_handler/include/protocol_handler/service_status_update_handler_listener.h b/src/components/protocol_handler/include/protocol_handler/service_status_update_handler_listener.h index 3c782f72f83..f4dcffb2069 100644 --- a/src/components/protocol_handler/include/protocol_handler/service_status_update_handler_listener.h +++ b/src/components/protocol_handler/include/protocol_handler/service_status_update_handler_listener.h @@ -70,6 +70,10 @@ class ServiceStatusUpdateHandlerListener { hmi_apis::Common_ServiceEvent::eType service_event, utils::Optional service_update_reason) = 0; + + virtual bool SetNaviServiceStatus(uint32_t connection_key, + protocol_handler::ServiceType service_type, + bool is_started) = 0; }; } // namespace protocol_handler diff --git a/src/components/protocol_handler/src/protocol_handler_impl.cc b/src/components/protocol_handler/src/protocol_handler_impl.cc index 3b216c273c1..e13e2cc6629 100644 --- a/src/components/protocol_handler/src/protocol_handler_impl.cc +++ b/src/components/protocol_handler/src/protocol_handler_impl.cc @@ -435,6 +435,16 @@ void ProtocolHandlerImpl::SendStartSessionAck( raw_ford_messages_to_mobile_.PostMessage( impl::RawFordMessageToMobile(ptr, false)); + if ((service_type == ServiceType::kAudio) || + (service_type == ServiceType::kMobileNav)) { + const uint32_t connection_key = + session_observer_.KeyFromPair(connection_id, session_id); + service_status_update_handler_->SetNaviServiceStatus( + connection_key, + static_cast(service_type), + true); + } + LOG4CXX_DEBUG(logger_, "SendStartSessionAck() for connection " << connection_id << " for service_type " @@ -509,6 +519,13 @@ void ProtocolHandlerImpl::SendStartSessionNAck( raw_ford_messages_to_mobile_.PostMessage( impl::RawFordMessageToMobile(ptr, false)); + const uint32_t connection_key = + session_observer_.KeyFromPair(connection_id, session_id); + service_status_update_handler_->SetNaviServiceStatus( + connection_key, + static_cast(service_type), + false); + LOG4CXX_DEBUG(logger_, "SendStartSessionNAck() for connection " << connection_id << " for service_type " @@ -572,6 +589,14 @@ void ProtocolHandlerImpl::SendEndSessionNAck( raw_ford_messages_to_mobile_.PostMessage( impl::RawFordMessageToMobile(ptr, false)); + const uint32_t connection_key = session_observer_.KeyFromPair( + connection_id, static_cast(session_id)); + + service_status_update_handler_->SetNaviServiceStatus( + connection_key, + static_cast(service_type), + false); + LOG4CXX_DEBUG(logger_, "SendEndSessionNAck() for connection " << connection_id << " for service_type " diff --git a/src/components/protocol_handler/src/service_status_update_handler.cc b/src/components/protocol_handler/src/service_status_update_handler.cc index 7b2c67ea23a..37968264fae 100644 --- a/src/components/protocol_handler/src/service_status_update_handler.cc +++ b/src/components/protocol_handler/src/service_status_update_handler.cc @@ -114,4 +114,10 @@ void ServiceStatusUpdateHandler::OnServiceUpdate( } } } + +void ServiceStatusUpdateHandler::SetNaviServiceStatus(uint32_t app_id, + ServiceType service_type, + bool is_opened) { + listener_->SetNaviServiceStatus(app_id, service_type, is_opened); +} } // namespace protocol_handler diff --git a/src/components/protocol_handler/test/include/protocol_handler/mock_service_status_update_handler_listener.h b/src/components/protocol_handler/test/include/protocol_handler/mock_service_status_update_handler_listener.h index ccbfeb84388..296c70019d3 100644 --- a/src/components/protocol_handler/test/include/protocol_handler/mock_service_status_update_handler_listener.h +++ b/src/components/protocol_handler/test/include/protocol_handler/mock_service_status_update_handler_listener.h @@ -49,6 +49,11 @@ class MockServiceStatusUpdateHandlerListener hmi_apis::Common_ServiceType::eType, hmi_apis::Common_ServiceEvent::eType, utils::Optional)); + + MOCK_METHOD3(SetNaviServiceStatus, + bool(uint32_t connection_key, + protocol_handler::ServiceType service_type, + bool is_started)); }; } // namespace protocol_handler_test } // namespace components