summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrii Kalinich <AKalinich@luxoft.com>2018-07-04 16:20:20 +0300
committerAndrii Kalinich <AKalinich@luxoft.com>2018-07-04 16:20:20 +0300
commit56b01ce0d32d1a4059125a350ad108d35c529c9f (patch)
treeda519afed6998a20ae6e2802935a3e08eb7bc6d1
parenta73efbdfe97eab17fd9541bd213a89af0a49e1d5 (diff)
downloadsdl_core-56b01ce0d32d1a4059125a350ad108d35c529c9f.tar.gz
Added lock for VRcommands map
Also renamed AddCommands function Added DeleteCommand function
-rw-r--r--src/components/application_manager/include/application_manager/help_prompt_manager_impl.h15
-rw-r--r--src/components/application_manager/src/help_prompt_manager_impl.cc48
2 files changed, 47 insertions, 16 deletions
diff --git a/src/components/application_manager/include/application_manager/help_prompt_manager_impl.h b/src/components/application_manager/include/application_manager/help_prompt_manager_impl.h
index f11f11c06d..a34f034e3e 100644
--- a/src/components/application_manager/include/application_manager/help_prompt_manager_impl.h
+++ b/src/components/application_manager/include/application_manager/help_prompt_manager_impl.h
@@ -34,6 +34,7 @@
#define SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_HELP_PROMPT_MANAGER_IMPL_H_
#include "application_manager/help_prompt_manager.h"
+#include "utils/lock.h"
#include "utils/timer.h"
namespace application_manager {
@@ -101,6 +102,19 @@ class HelpPromptManagerImpl : public HelpPromptManager {
private:
DISALLOW_COPY_AND_ASSIGN(HelpPromptManagerImpl);
/**
+ * @brief Add new smart object with VR command to the map
+ * @param cmd_id ID of VR command
+ * @param command smart object containing VR command structure
+ */
+ void AddCommand(const uint32_t cmd_id,
+ const smart_objects::SmartObject& command);
+ /**
+ * @brief Delete VR command from map by its cmd_id
+ * @param cmd_id ID of VR command
+ * @return true if command was successfully deleted otherwise returns false
+ */
+ bool DeleteCommand(const uint32_t cmd_id);
+ /**
* @brief Send TTS request to HMI
*/
void SendTTSRequest();
@@ -138,6 +152,7 @@ class HelpPromptManagerImpl : public HelpPromptManager {
Application& app_;
ApplicationManager& app_manager_;
VRCommandsMap vr_commands_;
+ sync_primitives::Lock vr_commands_lock_;
SendingType sending_type_;
std::size_t count_requests_commands_;
bool is_tts_send_;
diff --git a/src/components/application_manager/src/help_prompt_manager_impl.cc b/src/components/application_manager/src/help_prompt_manager_impl.cc
index 696733e9f0..d951470104 100644
--- a/src/components/application_manager/src/help_prompt_manager_impl.cc
+++ b/src/components/application_manager/src/help_prompt_manager_impl.cc
@@ -71,12 +71,13 @@ void HelpPromptManagerImpl::OnVrCommandAdded(
<< " will not be added");
return;
}
- AddCommands(cmd_id, command);
+ AddCommand(cmd_id, command);
SendRequests();
}
-void HelpPromptManagerImpl::AddCommands(
+void HelpPromptManagerImpl::AddCommand(
const uint32_t cmd_id, const smart_objects::SmartObject& command) {
+ sync_primitives::AutoLock lock(vr_commands_lock_);
auto it = vr_commands_.find(cmd_id);
if (vr_commands_.end() != it) {
LOG4CXX_DEBUG(logger_, "Commands with id:" << cmd_id << " already exists");
@@ -115,6 +116,26 @@ void HelpPromptManagerImpl::AddCommands(
count_requests_commands_ += count_new_commands;
}
+bool HelpPromptManagerImpl::DeleteCommand(const uint32_t cmd_id) {
+ LOG4CXX_AUTO_TRACE(logger_);
+ sync_primitives::AutoLock lock(vr_commands_lock_);
+
+ auto it = vr_commands_.find(cmd_id);
+ if (vr_commands_.end() == it) {
+ LOG4CXX_WARN(logger_, "VR command with id: " << cmd_id << " not found");
+ return false;
+ }
+
+ count_requests_commands_ -=
+ kLimitCommand == count_requests_commands_ ? 0 : it->second->length();
+
+ vr_commands_.erase(it);
+ LOG4CXX_DEBUG(logger_,
+ "VR command with id: " << cmd_id << " deleted for appID: "
+ << app_.app_id());
+ return true;
+}
+
void HelpPromptManagerImpl::OnVrCommandDeleted(const uint32_t cmd_id) {
LOG4CXX_AUTO_TRACE(logger_);
if (SendingType::kNoneSend == sending_type_) {
@@ -124,15 +145,7 @@ void HelpPromptManagerImpl::OnVrCommandDeleted(const uint32_t cmd_id) {
<< " will not be deleted");
return;
}
- auto it = vr_commands_.find(cmd_id);
- if (vr_commands_.end() != it) {
- count_requests_commands_ -=
- kLimitCommand == count_requests_commands_ ? 0 : it->second->length();
-
- vr_commands_.erase(it);
- LOG4CXX_DEBUG(logger_,
- "VR command with id: " << cmd_id << " deleted for appID: "
- << app_.app_id());
+ if (DeleteCommand(cmd_id)) {
SendRequests();
}
}
@@ -153,6 +166,7 @@ void HelpPromptManagerImpl::OnSetGlobalPropertiesReceived(
void HelpPromptManagerImpl::OnAppActivated(const bool is_restore) {
LOG4CXX_AUTO_TRACE(logger_);
LOG4CXX_DEBUG(logger_, "Activated for appID:" << app_.app_id());
+
if (is_restore) {
LOG4CXX_DEBUG(logger_, "restoring");
is_tts_send_ = (app_.help_prompt() && app_.help_prompt()->length());
@@ -166,16 +180,16 @@ void HelpPromptManagerImpl::OnAppActivated(const bool is_restore) {
" with the vrHelp and helpPrompt"
" has been sent");
return;
- }
- else {
+ } else {
sending_type_ = is_tts_send_ ? SendingType::kSendVRHelp : sending_type_;
- sending_type_ = is_ui_send_ ? SendingType::kSendHelpPrompt : sending_type_;
+ sending_type_ =
+ is_ui_send_ ? SendingType::kSendHelpPrompt : sending_type_;
is_tts_send_ = false;
is_ui_send_ = false;
const DataAccessor<CommandsMap> accessor = app_.commands_map();
const CommandsMap& commands = accessor.GetData();
for (auto& command : commands) {
- AddCommands(command.first, *command.second);
+ AddCommand(command.first, *command.second);
}
}
}
@@ -269,6 +283,8 @@ void HelpPromptManagerImpl::SendBothRequests() {
void HelpPromptManagerImpl::SendRequests() {
LOG4CXX_AUTO_TRACE(logger_);
+
+ sync_primitives::AutoLock lock(vr_commands_lock_);
if (vr_commands_.empty()) {
LOG4CXX_DEBUG(logger_, "vr_commands_ is empty");
return;
@@ -348,7 +364,7 @@ void HelpPromptManagerImpl::CreateVRMsg(
HelpPromptManagerImpl::SendingType HelpPromptManagerImpl::GetSendingType(
const smart_objects::SmartObject& msg, const bool is_response) {
LOG4CXX_AUTO_TRACE(logger_);
- if (false == is_response) {
+ if (!is_response) {
if (msg.keyExists(strings::help_prompt)) {
is_tts_send_ = true;
}