diff options
author | JackLivio <jack@livio.io> | 2020-02-17 13:05:54 -0500 |
---|---|---|
committer | JackLivio <jack@livio.io> | 2020-02-17 13:05:54 -0500 |
commit | 86dea8793023f986c7c10d7f9e5b7a932d89a49a (patch) | |
tree | bf44b0d5b6bf6b6c78dd2d0602b67f05ebe2a17c /src/components/application_manager/src/application_data_impl.cc | |
parent | 4310b2dfd5e1078df0df53138a73d49d000c9c62 (diff) | |
parent | ece258838a44a5461d718c5eeae380ad11a3769b (diff) | |
download | sdl_core-fix/3rd_party_build_issues.tar.gz |
Merge remote-tracking branch 'origin/develop' into fix/3rd_party_build_issuesfix/3rd_party_build_issues
Diffstat (limited to 'src/components/application_manager/src/application_data_impl.cc')
-rw-r--r-- | src/components/application_manager/src/application_data_impl.cc | 60 |
1 files changed, 52 insertions, 8 deletions
diff --git a/src/components/application_manager/src/application_data_impl.cc b/src/components/application_manager/src/application_data_impl.cc index 2bef887901..9f30c00014 100644 --- a/src/components/application_manager/src/application_data_impl.cc +++ b/src/components/application_manager/src/application_data_impl.cc @@ -39,6 +39,25 @@ namespace application_manager { CREATE_LOGGERPTR_GLOBAL(logger_, "ApplicationManager") +namespace { +struct CommandIdComparator { + CommandIdComparator(const std::string& key, const uint32_t id) + : key_(key), target_id_(id) {} + + bool operator()(const CommandsMap::value_type& new_command) const { + smart_objects::SmartObject& command = *(new_command.second); + if (command.keyExists(key_)) { + return command[key_].asUInt() == target_id_; + } + return false; + } + + private: + std::string key_; + uint32_t target_id_; +}; +} // namespace + InitialApplicationDataImpl::InitialApplicationDataImpl() : app_types_(NULL) , vr_synonyms_(NULL) @@ -724,28 +743,53 @@ void DynamicApplicationDataImpl::SetGlobalProperties( } void DynamicApplicationDataImpl::AddCommand( - uint32_t cmd_id, const smart_objects::SmartObject& command) { + const uint32_t internal_id, const smart_objects::SmartObject& command) { sync_primitives::AutoLock lock(commands_lock_ptr_); - CommandsMap::const_iterator it = commands_.find(cmd_id); + + CommandsMap::const_iterator it = commands_.find(internal_id); if (commands_.end() == it) { - commands_[cmd_id] = new smart_objects::SmartObject(command); + commands_[internal_id] = new smart_objects::SmartObject(command); + LOG4CXX_DEBUG(logger_, + "Command with internal number " + << internal_id << " and id " + << (*commands_[internal_id])[strings::cmd_id].asUInt() + << " is added."); } } -void DynamicApplicationDataImpl::RemoveCommand(uint32_t cmd_id) { +void DynamicApplicationDataImpl::RemoveCommand(const uint32_t cmd_id) { sync_primitives::AutoLock lock(commands_lock_ptr_); - CommandsMap::iterator it = commands_.find(cmd_id); - if (commands_.end() != it) { + + CommandIdComparator is_id_equal(strings::cmd_id, cmd_id); + CommandsMap::iterator it = + find_if(commands_.begin(), commands_.end(), is_id_equal); + + if (it != commands_.end()) { delete it->second; + LOG4CXX_DEBUG(logger_, + "Command with internal number " << (it->first) << " and id " + << cmd_id << " is removed."); commands_.erase(it); + + return; } + LOG4CXX_WARN( + logger_, + "Command with id " << cmd_id << " is not found. Removal skipped."); } smart_objects::SmartObject* DynamicApplicationDataImpl::FindCommand( - uint32_t cmd_id) { + const uint32_t cmd_id) { sync_primitives::AutoLock lock(commands_lock_ptr_); - CommandsMap::const_iterator it = commands_.find(cmd_id); + + CommandIdComparator is_id_equal(strings::cmd_id, cmd_id); + CommandsMap::const_iterator it = + find_if(commands_.begin(), commands_.end(), is_id_equal); + if (it != commands_.end()) { + LOG4CXX_DEBUG(logger_, + "Command with internal number " << (it->first) << " and id " + << cmd_id << " is found."); return it->second; } |