diff options
author | Andrey Oleynik (GitHub) <aoleynik@luxoft.com> | 2017-10-02 13:46:14 +0300 |
---|---|---|
committer | Andriy Byzhynar <AByzhynar@luxoft.com> | 2018-01-18 12:03:50 +0200 |
commit | afbf4df6653fcb0d722b01da253acddaabba0d90 (patch) | |
tree | af11f20589105c7300245f26ccaceacc03dfe837 /src/components/application_manager/src | |
parent | 35b49b9abf198963d165c618415c74bb0c59b31d (diff) | |
download | sdl_core-afbf4df6653fcb0d722b01da253acddaabba0d90.tar.gz |
Initial implementation of holding commands for switching apps
Diffstat (limited to 'src/components/application_manager/src')
3 files changed, 94 insertions, 2 deletions
diff --git a/src/components/application_manager/src/application_manager_impl.cc b/src/components/application_manager/src/application_manager_impl.cc index 2755f04b94..113b6e826a 100644 --- a/src/components/application_manager/src/application_manager_impl.cc +++ b/src/components/application_manager/src/application_manager_impl.cc @@ -195,6 +195,7 @@ ApplicationManagerImpl::ApplicationManagerImpl( const uint32_t timeout_ms = 10000u; clearing_timer->Start(timeout_ms, timer::kSingleShot); timer_pool_.push_back(clearing_timer); + commands_holder_.SetCommandsProcessor(this); } ApplicationManagerImpl::~ApplicationManagerImpl() { @@ -388,6 +389,10 @@ void ApplicationManagerImpl::OnApplicationRegistered(ApplicationSharedPtr app) { event.raise(event_dispatcher()); } +void ApplicationManagerImpl::OnApplicationSwitched(ApplicationSharedPtr app) { + commands_holder_.Release(app->policy_app_id()); +} + bool ApplicationManagerImpl::IsAppTypeExistsInFullOrLimited( ApplicationConstSharedPtr app) const { bool voice_state = app->is_voice_communication_supported(); @@ -1077,7 +1082,9 @@ void ApplicationManagerImpl::OnDeviceSwitchingStart( for (auto i = reregister_wait_list_.begin(); reregister_wait_list_.end() != i; ++i) { - resume_ctrl_->SaveApplication(*i); + auto app = *i; + request_ctrl_.terminateAppRequests(app->app_id()); + resume_ctrl_->SaveApplication(app); } } @@ -1092,7 +1099,9 @@ void ApplicationManagerImpl::OnDeviceSwitchFinish( for (auto app_it = reregister_wait_list_.begin(); app_it != reregister_wait_list_.end(); ++app_it) { - UnregisterApplication((*app_it)->app_id(), + auto app = *app_it; + commands_holder_.Drop(app->policy_app_id()); + UnregisterApplication(app->app_id(), mobile_apis::Result::INVALID_ENUM, is_resuming, unexpected_disonnect); @@ -2040,6 +2049,12 @@ bool ApplicationManagerImpl::ManageHMICommand( return false; } + auto app = application(command->connection_key()); + if (app && IsAppInReconnectMode(app->policy_app_id())) { + commands_holder_.Hold(app->policy_app_id(), message); + return true; + } + int32_t message_type = (*(message.get()))[strings::params][strings::message_type].asInt(); diff --git a/src/components/application_manager/src/command_holder_impl.cc b/src/components/application_manager/src/command_holder_impl.cc new file mode 100644 index 0000000000..3bb3e8c190 --- /dev/null +++ b/src/components/application_manager/src/command_holder_impl.cc @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2017, 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/command_holder_impl.h" +#include "application_manager/application_manager.h" + +namespace application_manager { +CommandHolderImpl::CommandHolderImpl() + : app_manager_(nullptr), commands_lock_() {} + +void CommandHolderImpl::SetCommandsProcessor(ApplicationManager* app_manager) { + DCHECK_OR_RETURN_VOID(app_manager); + app_manager_ = app_manager; +} + +void CommandHolderImpl::Hold( + const std::string& policy_app_id, + utils::SharedPtr<smart_objects::SmartObject> command) { + sync_primitives::AutoLock lock(commands_lock_); + app_commands_[policy_app_id].push_back(command); +} + +void CommandHolderImpl::Release(const std::string& policy_app_id) { + sync_primitives::AutoLock lock(commands_lock_); + auto app_commands = app_commands_.find(policy_app_id); + if (app_commands_.end() == app_commands) { + return; + } + for (auto cmd : app_commands->second) { + DCHECK_OR_RETURN_VOID(app_manager_); + app_manager_->ManageHMICommand(cmd); + } + + app_commands_.erase(app_commands); +} + +void CommandHolderImpl::Drop(const std::string& policy_app_id) { + sync_primitives::AutoLock lock(commands_lock_); + auto app_commands = app_commands_.find(policy_app_id); + if (app_commands_.end() == app_commands) { + return; + } + + app_commands_.erase(app_commands); +} +} // application_manager 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 f29d5e1379..6088e46e06 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 @@ -1465,6 +1465,8 @@ bool RegisterAppInterfaceRequest::IsApplicationSwitched() { application_manager_.SendHMIStatusNotification(app); + application_manager_.OnApplicationSwitched(app); + return true; } |