summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrey Oleynik (GitHub) <aoleynik@luxoft.com>2017-10-02 13:46:14 +0300
committerAndriy Byzhynar <AByzhynar@luxoft.com>2018-01-18 12:03:50 +0200
commitafbf4df6653fcb0d722b01da253acddaabba0d90 (patch)
treeaf11f20589105c7300245f26ccaceacc03dfe837 /src
parent35b49b9abf198963d165c618415c74bb0c59b31d (diff)
downloadsdl_core-afbf4df6653fcb0d722b01da253acddaabba0d90.tar.gz
Initial implementation of holding commands for switching apps
Diffstat (limited to 'src')
-rw-r--r--src/components/application_manager/include/application_manager/application_manager_impl.h26
-rw-r--r--src/components/application_manager/include/application_manager/command_holder.h72
-rw-r--r--src/components/application_manager/include/application_manager/command_holder_impl.h96
-rw-r--r--src/components/application_manager/src/application_manager_impl.cc19
-rw-r--r--src/components/application_manager/src/command_holder_impl.cc75
-rw-r--r--src/components/application_manager/src/commands/mobile/register_app_interface_request.cc2
-rw-r--r--src/components/include/application_manager/application_manager.h7
-rw-r--r--src/components/include/test/application_manager/mock_application_manager.h2
8 files changed, 281 insertions, 18 deletions
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 56ce55dec3..8d5bbd742e 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
@@ -354,6 +354,13 @@ class ApplicationManagerImpl
void OnApplicationRegistered(ApplicationSharedPtr app) OVERRIDE;
+ /**
+ * @brief OnApplicationSwitched starts processing of commands collected
+ * during device switching process
+ * @param app Application
+ */
+ void OnApplicationSwitched(ApplicationSharedPtr app) OVERRIDE;
+
HMICapabilities& hmi_capabilities() OVERRIDE;
const HMICapabilities& hmi_capabilities() const OVERRIDE;
@@ -523,28 +530,13 @@ class ApplicationManagerImpl
/**
* DEPRECATED
* @brief CreateRegularState create regular HMI state for application
- * @param app_id
- * @param hmi_level of returned state
- * @param audio_state of returned state
- * @param system_context of returned state
- * @return new regular HMI state
- */
- DEPRECATED HmiStatePtr CreateRegularState(
- uint32_t app_id,
- mobile_apis::HMILevel::eType hmi_level,
- mobile_apis::AudioStreamingState::eType audio_state,
- mobile_apis::SystemContext::eType system_context) const OVERRIDE;
-
- /**
- * DEPRECATED
- * @brief CreateRegularState create regular HMI state for application
* @param app_id Application id
* @param hmi_level of returned state
* @param audio_state of returned state
* @param system_context of returned state
* @return new regular HMI state
*/
- HmiStatePtr CreateRegularState(
+ DEPRECATED HmiStatePtr CreateRegularState(
uint32_t app_id,
mobile_apis::HMILevel::eType hmi_level,
mobile_apis::AudioStreamingState::eType audio_state,
@@ -1728,6 +1720,8 @@ class ApplicationManagerImpl
volatile bool is_stopping_;
+ CommandHolderImpl commands_holder_;
+
#ifdef BUILD_TESTS
public:
/**
diff --git a/src/components/application_manager/include/application_manager/command_holder.h b/src/components/application_manager/include/application_manager/command_holder.h
new file mode 100644
index 0000000000..ee9d9f34cb
--- /dev/null
+++ b/src/components/application_manager/include/application_manager/command_holder.h
@@ -0,0 +1,72 @@
+/*
+ * 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.
+ */
+
+#pragma once
+
+#include <string>
+#include "smart_objects/smart_object.h"
+#include "utils/shared_ptr.h"
+
+namespace application_manager {
+/**
+ * @brief The CommandsHolder class should hold commands for particular
+ * application specified by its id
+ */
+class CommandsHolder {
+ public:
+ /**
+ * @brief ~CommandsHolder destructor
+ */
+ virtual ~CommandsHolder() {}
+
+ /**
+ * @brief Hold collects command for specific application policy id internally
+ * @param policy_app_id Application policy id
+ * @param command Command
+ */
+ virtual void Hold(const std::string& policy_app_id,
+ utils::SharedPtr<smart_objects::SmartObject> command) = 0;
+
+ /**
+ * @brief Release send all collected commands for further processing and
+ * removes them afterward
+ * @param policy_app_id Application policy id
+ */
+ virtual void Release(const std::string& policy_app_id) = 0;
+
+ /**
+ * @brief Drop removes all collected commands w/o processing
+ * @param policy_app_id Application policy id
+ */
+ virtual void Drop(const std::string& policy_app_id) = 0;
+};
+} // application_manager
diff --git a/src/components/application_manager/include/application_manager/command_holder_impl.h b/src/components/application_manager/include/application_manager/command_holder_impl.h
new file mode 100644
index 0000000000..8e4edadbab
--- /dev/null
+++ b/src/components/application_manager/include/application_manager/command_holder_impl.h
@@ -0,0 +1,96 @@
+/*
+ * 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.
+ */
+
+#pragma once
+
+#include "application_manager/command_holder.h"
+
+#include <string>
+#include <vector>
+#include "smart_objects/smart_object.h"
+#include "utils/lock.h"
+#include "utils/shared_ptr.h"
+#include "utils/macro.h"
+
+namespace application_manager {
+class ApplicationManager;
+/**
+ * @brief The CommandHolderImpl class should hold HMI commands for particular
+ * application specified by its policy id during application transport switching
+ * process and sends for processing after switching is completed successfully
+ * or drop otherwise
+ */
+class CommandHolderImpl : public CommandsHolder {
+ public:
+ /**
+ * @brief CommandHolderImpl constructor
+ */
+ CommandHolderImpl();
+
+ /**
+ * @brief SetCommandsProcessor sets internal member to be able to
+ * process collected commands
+ * @param app_manager Applicaton manager
+ */
+ void SetCommandsProcessor(ApplicationManager* app_manager);
+
+ /**
+ * @brief Hold collects command for specific application id internally
+ * @param policy_app_id Policy id of application
+ * @param command Command
+ */
+ void Hold(const std::string& policy_app_id,
+ utils::SharedPtr<smart_objects::SmartObject> command) FINAL;
+
+ /**
+ * @brief Release sends all collected HMI commands to ApplicationManager
+ * for further processing
+ * @param policy_app_id Policy id of application
+ */
+ void Release(const std::string& policy_app_id) FINAL;
+
+ /**
+ * @brief Drop removes all commands collected for specific application id
+ * @param policy_app_id Policy application id
+ */
+ void Drop(const std::string& policy_app_id) FINAL;
+
+ private:
+ using AppCommands =
+ std::map<std::string,
+ std::vector<utils::SharedPtr<smart_objects::SmartObject> > >;
+
+ ApplicationManager* app_manager_;
+ sync_primitives::Lock commands_lock_;
+ AppCommands app_commands_;
+};
+} // application_manager
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;
}
diff --git a/src/components/include/application_manager/application_manager.h b/src/components/include/application_manager/application_manager.h
index be872109b3..17ccbb07c5 100644
--- a/src/components/include/application_manager/application_manager.h
+++ b/src/components/include/application_manager/application_manager.h
@@ -345,6 +345,13 @@ class ApplicationManager {
*/
virtual void OnApplicationRegistered(ApplicationSharedPtr app) = 0;
+ /**
+ * @brief OnApplicationSwitched starts activies postponed during application
+ * transport switching
+ * @param app Application
+ */
+ virtual void OnApplicationSwitched(ApplicationSharedPtr app) = 0;
+
virtual connection_handler::ConnectionHandler& connection_handler() const = 0;
virtual protocol_handler::ProtocolHandler& protocol_handler() const = 0;
virtual policy::PolicyHandlerInterface& GetPolicyHandler() = 0;
diff --git a/src/components/include/test/application_manager/mock_application_manager.h b/src/components/include/test/application_manager/mock_application_manager.h
index df360eaa94..1a7b0f94e3 100644
--- a/src/components/include/test/application_manager/mock_application_manager.h
+++ b/src/components/include/test/application_manager/mock_application_manager.h
@@ -151,6 +151,8 @@ class MockApplicationManager : public application_manager::ApplicationManager {
bool(application_manager::ApplicationConstSharedPtr app));
MOCK_METHOD1(OnApplicationRegistered,
void(application_manager::ApplicationSharedPtr app));
+ MOCK_METHOD1(OnApplicationSwitched,
+ void(application_manager::ApplicationSharedPtr app));
MOCK_CONST_METHOD0(connection_handler,
connection_handler::ConnectionHandler&());
MOCK_CONST_METHOD0(protocol_handler, protocol_handler::ProtocolHandler&());