diff options
32 files changed, 684 insertions, 186 deletions
diff --git a/src/components/application_manager/include/application_manager/hmi_state.h b/src/components/application_manager/include/application_manager/hmi_state.h index e8c2f8b914..5b9e201391 100644 --- a/src/components/application_manager/include/application_manager/hmi_state.h +++ b/src/components/application_manager/include/application_manager/hmi_state.h @@ -63,18 +63,18 @@ class HmiState { * If no events occurred STATE_ID_DEFAULT should be presented */ enum StateID { - STATE_ID_CURRENT, - STATE_ID_REGULAR, - STATE_ID_POSTPONED, - STATE_ID_PHONE_CALL, - STATE_ID_SAFETY_MODE, - STATE_ID_VR_SESSION, - STATE_ID_TTS_SESSION, - STATE_ID_VIDEO_STREAMING, - STATE_ID_NAVI_STREAMING, - STATE_ID_DEACTIVATE_HMI, - STATE_ID_AUDIO_SOURCE, - STATE_ID_EMBEDDED_NAVI + STATE_ID_CURRENT = 1, + STATE_ID_REGULAR = 2, + STATE_ID_POSTPONED = 3, + STATE_ID_PHONE_CALL = 4, + STATE_ID_SAFETY_MODE = 5, + STATE_ID_VR_SESSION = 6, + STATE_ID_TTS_SESSION = 7, + STATE_ID_VIDEO_STREAMING = 8, + STATE_ID_NAVI_STREAMING = 9, + STATE_ID_DEACTIVATE_HMI = 10, + STATE_ID_AUDIO_SOURCE = 11, + STATE_ID_EMBEDDED_NAVI = 12 }; /** diff --git a/src/components/application_manager/include/application_manager/policies/policy_handler.h b/src/components/application_manager/include/application_manager/policies/policy_handler.h index 9ca7761426..61cf2cf480 100644 --- a/src/components/application_manager/include/application_manager/policies/policy_handler.h +++ b/src/components/application_manager/include/application_manager/policies/policy_handler.h @@ -864,7 +864,6 @@ class PolicyHandler : public PolicyHandlerInterface, mutable sync_primitives::RWLock policy_manager_lock_; std::shared_ptr<PolicyManager> policy_manager_; - void* dl_handle_; std::shared_ptr<PolicyEventObserver> event_observer_; uint32_t last_activated_app_id_; diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/app_service_rpc_plugin.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/app_service_rpc_plugin.cc index 79c6d9005e..0e739522d9 100644 --- a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/app_service_rpc_plugin.cc +++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/app_service_rpc_plugin.cc @@ -104,4 +104,5 @@ Create() { extern "C" __attribute__((visibility("default"))) void Delete( application_manager::plugin_manager::RPCPlugin* data) { delete data; -}
\ No newline at end of file + DELETE_THREAD_LOGGER(app_service_rpc_plugin::logger_); +} diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/interior_data_manager.h b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/interior_data_manager.h index 42ae7ea4fe..c1fe30fa4d 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/interior_data_manager.h +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/interior_data_manager.h @@ -49,6 +49,7 @@ typedef std::pair<std::string, std::string> ModuleUid; class InteriorDataManager { public: + virtual ~InteriorDataManager() {} /** * @brief OnPolicyEvent Processes policy related events * @param event Policy event diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_helpers.h b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_helpers.h index 7b249cb4b8..eed860fc7f 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_helpers.h +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_helpers.h @@ -146,6 +146,29 @@ class RCHelpers { */ static void RemoveRedundantGPSDataFromIVDataMsg( smart_objects::SmartObject& msg_params); + + /** + * @brief MergeModuleData all keys and values from first parameter and + * update and append keys and values from the second + * @param data1 - initial data + * @param data2 - updated data + * @return updated data1 with data2 keys and values + */ + static smart_objects::SmartObject MergeModuleData( + const smart_objects::SmartObject& data1, + const smart_objects::SmartObject& data2); + + /** + * @brief MergeArray merge two arrays if their elements contain an `id` + * parameter + * @param data1 - initial data + * @param data2 - updated data + * @return updated data1 with any values in data2 if the arrays can be merged, + * otherwise data2 + */ + static smart_objects::SmartObject MergeArray( + const smart_objects::SmartObject& data1, + const smart_objects::SmartObject& data2); }; } // namespace rc_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/interior_data_cache_impl.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/interior_data_cache_impl.cc index bcbc3ab11b..3e50818210 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/interior_data_cache_impl.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/interior_data_cache_impl.cc @@ -35,6 +35,7 @@ #include <iostream> #include <thread> #include "application_manager/smart_object_keys.h" +#include "rc_rpc_plugin/rc_helpers.h" #include "utils/date_time.h" #include "utils/logger.h" @@ -46,95 +47,6 @@ InteriorDataCacheImpl::InteriorDataCacheImpl() {} InteriorDataCacheImpl::~InteriorDataCacheImpl() {} -/** - * @brief MergeModuleData all keys and values from first parameter and - * update and append keys and values from the second - * @param data1 - initial data - * @param data2 - updated data - * @return updated data1 with data2 keys and values - */ -smart_objects::SmartObject MergeModuleData( - const smart_objects::SmartObject& data1, - const smart_objects::SmartObject& data2); - -/** - * @brief MergeArray merge two arrays if their elements contain an `id` - * parameter - * @param data1 - initial data - * @param data2 - updated data - * @return updated data1 with any values in data2 if the arrays can be merged, - * otherwise data2 - */ -smart_objects::SmartObject MergeArray(const smart_objects::SmartObject& data1, - const smart_objects::SmartObject& data2); - -smart_objects::SmartObject MergeModuleData( - const smart_objects::SmartObject& data1, - const smart_objects::SmartObject& data2) { - smart_objects::SmartObject result = data1; - auto it = data2.map_begin(); - for (; it != data2.map_end(); ++it) { - const std::string& key = it->first; - smart_objects::SmartObject& value = it->second; - if (!result.keyExists(key) || value.getType() != result[key].getType()) { - result[key] = value; - continue; - } - - // Merge maps and arrays with `id` param included, replace other types - if (value.getType() == smart_objects::SmartType::SmartType_Map) { - value = MergeModuleData(result[key], value); - } else if (value.getType() == smart_objects::SmartType::SmartType_Array) { - value = MergeArray(result[key], value); - } - result[key] = value; - } - return result; -} - -smart_objects::SmartObject MergeArray(const smart_objects::SmartObject& data1, - const smart_objects::SmartObject& data2) { - // Merge data only in the case where each value in the array is an Object with - // an ID included, otherwise replace - bool array_contains_objects = - !data2.empty() && - data2.getElement(0).getType() != smart_objects::SmartType::SmartType_Map; - bool can_merge_arrays = - array_contains_objects && - data2.getElement(0).keyExists(application_manager::strings::id); - if (!can_merge_arrays) { - return data2; - } - - smart_objects::SmartObject result = data1; - smart_objects::SmartArray* result_array = result.asArray(); - smart_objects::SmartArray* data_array = data2.asArray(); - auto data_it = data_array->begin(); - auto find_by_id = [](smart_objects::SmartArray* array, - const smart_objects::SmartObject& id) - -> smart_objects::SmartArray::iterator { - auto it = std::find_if(array->begin(), - array->end(), - [&id](smart_objects::SmartObject& obj) -> bool { - return obj[application_manager::strings::id] == id; - }); - return it; - }; - - for (; data_it != data_array->end(); ++data_it) { - const smart_objects::SmartObject element_id = - (*data_it)[application_manager::strings::id]; - auto result_it = find_by_id(result_array, element_id); - - if (result_it != result_array->end()) { - *result_it = MergeModuleData(*result_it, *data_it); - } else { - result_array->push_back(*data_it); - } - } - return result; -} - void InteriorDataCacheImpl::Add(const ModuleUid& module, const smart_objects::SmartObject& module_data) { LOG4CXX_TRACE( @@ -146,7 +58,7 @@ void InteriorDataCacheImpl::Add(const ModuleUid& module, cached_data_[module] = module_data; return; } - cached_data_[module] = MergeModuleData(it->second, module_data); + cached_data_[module] = RCHelpers::MergeModuleData(it->second, module_data); } smart_objects::SmartObject InteriorDataCacheImpl::Retrieve( diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_helpers.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_helpers.cc index e9e6620e25..8cf20948cf 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_helpers.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_helpers.cc @@ -276,4 +276,86 @@ void RCHelpers::RemoveRedundantGPSDataFromIVDataMsg( location_data = new_location_data; } } + +smart_objects::SmartObject RCHelpers::MergeModuleData( + const smart_objects::SmartObject& data1, + const smart_objects::SmartObject& data2) { + if (data1.getType() != smart_objects::SmartType::SmartType_Map || + data2.getType() != smart_objects::SmartType::SmartType_Map) { + return data2; + } + + smart_objects::SmartObject result = data1; + + for (auto it = data2.map_begin(); it != data2.map_end(); ++it) { + const std::string& key = it->first; + smart_objects::SmartObject& value = it->second; + if (!result.keyExists(key) || value.getType() != result[key].getType()) { + result[key] = value; + continue; + } + + // Merge maps and arrays with `id` param included, replace other types + if (value.getType() == smart_objects::SmartType::SmartType_Map) { + value = MergeModuleData(result[key], value); + } else if (value.getType() == smart_objects::SmartType::SmartType_Array) { + value = MergeArray(result[key], value); + } + result[key] = value; + } + return result; +} + +smart_objects::SmartObject RCHelpers::MergeArray( + const smart_objects::SmartObject& data1, + const smart_objects::SmartObject& data2) { + // Merge data only in the case where each value in the array is an Object with + // an ID included, otherwise replace + + if (data1.getType() != smart_objects::SmartType::SmartType_Array || + data2.getType() != smart_objects::SmartType::SmartType_Array || + data2.empty()) { + return data2; + } + + auto& data2_array = *data2.asArray(); + for (const auto& data_item : data2_array) { + if (data_item.getType() != smart_objects::SmartType_Map || + !data_item.keyExists(application_manager::strings::id)) { + return data2; + } + } + + smart_objects::SmartObject result = data1; + smart_objects::SmartArray* result_array = result.asArray(); + + auto find_by_id = [](smart_objects::SmartArray* array, + const smart_objects::SmartObject& id) + -> smart_objects::SmartArray::iterator { + return std::find_if(array->begin(), + array->end(), + [&id](const smart_objects::SmartObject& obj) -> bool { + return id == obj[application_manager::strings::id]; + }); + }; + + auto merge = [&result_array, + &find_by_id](const smart_objects::SmartObject& data) -> void { + auto element_id = data[application_manager::strings::id]; + auto result_it = find_by_id(result_array, element_id); + + if (result_array->end() != result_it) { + *result_it = RCHelpers::MergeModuleData(*result_it, data); + } else { + result_array->push_back(data); + } + }; + + for (const auto& data : data2_array) { + merge(data); + } + + return result; +} + } // namespace rc_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_rpc_plugin.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_rpc_plugin.cc index ed6b863e20..9005eb7fd0 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_rpc_plugin.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_rpc_plugin.cc @@ -170,4 +170,5 @@ Create() { extern "C" __attribute__((visibility("default"))) void Delete( application_manager::plugin_manager::RPCPlugin* data) { delete data; + DELETE_THREAD_LOGGER(rc_rpc_plugin::logger_); } diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/CMakeLists.txt b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/CMakeLists.txt index 00ddcd7379..bd46bdf11f 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/CMakeLists.txt +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/CMakeLists.txt @@ -41,11 +41,10 @@ include_directories ( ) set (RC_TEST_SOURCES -${CMAKE_CURRENT_SOURCE_DIR}/resource_allocation_manager_impl_test.cc ${CMAKE_CURRENT_SOURCE_DIR}/interior_data_cache_test.cc ${CMAKE_CURRENT_SOURCE_DIR}/rc_consent_manager_impl_test.cc ${CMAKE_CURRENT_SOURCE_DIR}/grid_test.cc -${CMAKE_CURRENT_SOURCE_DIR}/mock_rc_helpers.cc +${CMAKE_CURRENT_SOURCE_DIR}/rc_helpers_test.cc ) set(RC_COMMANDS_TEST_DIR ${CMAKE_CURRENT_SOURCE_DIR}/commands) @@ -71,3 +70,4 @@ endif() create_test("rc_commands_test" "${SOURCES}" "${LIBRARIES}" ) create_test("rc_plugin_test" "${RC_TEST_SOURCES}" "${LIBRARIES}") +add_subdirectory(resource_allocation_manager) diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/interior_data_cache_test.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/interior_data_cache_test.cc index e8d9f6e45d..40a6bdf41d 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/interior_data_cache_test.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/interior_data_cache_test.cc @@ -29,6 +29,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ +#include "application_manager/smart_object_keys.h" #include "gtest/gtest.h" #include "rc_rpc_plugin/interior_data_cache_impl.h" @@ -38,6 +39,8 @@ class InteriorDataCacheTest : public ::testing::Test {}; namespace { const uint32_t time_frame_alowed_requests = 1; +const std::string kValueKey = "value"; +const std::string kArray = "array"; } // namespace TEST_F(InteriorDataCacheTest, @@ -177,4 +180,47 @@ TEST_F(InteriorDataCacheTest, Exist2ModuleTypesRemoveOneAnotherOneLeft) { EXPECT_EQ(data2, retrieved_data2); } +TEST_F(InteriorDataCacheTest, CheckCacheDataMerge) { + using namespace smart_objects; + const std::string module_type_key = "random_module_type"; + const std::string module_id = "random_module_id"; + rc_rpc_plugin::ModuleUid module(module_type_key, module_id); + + auto gen_smart_object = [](const std::string& id, + const std::string& value) -> SmartObject { + SmartObject result(SmartType_Map); + result[application_manager::strings::id] = id; + result[kValueKey] = value; + return result; + }; + + SmartObject data1; + SmartObject data1_array(SmartType_Array); + (*data1_array.asArray()) = SmartArray{gen_smart_object("id1", "value1"), + gen_smart_object("id2", "value2")}; + data1[kArray] = data1_array; + + SmartObject data2(SmartType_Map); + SmartObject data2_array(SmartType_Array); + (*data2_array.asArray()) = SmartArray{gen_smart_object("id1", "value3"), + gen_smart_object("id3", "value4")}; + data2[kArray] = data2_array; + + SmartObject expected_data(SmartType_Map); + SmartObject expected_array(SmartType_Array); + (*expected_array.asArray()) = SmartArray{gen_smart_object("id1", "value3"), + gen_smart_object("id2", "value2"), + gen_smart_object("id3", "value4")}; + expected_data[kArray] = expected_array; + + rc_rpc_plugin::InteriorDataCacheImpl cache; + cache.Add(module, data1); + cache.Add(module, data2); + + const auto retrieved_data = cache.Retrieve(module); + + EXPECT_TRUE(cache.Contains(module)); + EXPECT_EQ(expected_data, retrieved_data); +} + } // namespace rc_rpc_plugin_test diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/rc_helpers_test.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/rc_helpers_test.cc new file mode 100644 index 0000000000..21876c4c19 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/rc_helpers_test.cc @@ -0,0 +1,285 @@ +/* + * Copyright (c) 2019, 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 "rc_rpc_plugin/rc_helpers.h" +#include <map> +#include <memory> +#include <string> +#include <type_traits> +#include <vector> +#include "gtest/gtest.h" +#include "rc_rpc_plugin/rc_module_constants.h" + +namespace { +const std::string kKeyId = "id"; +const std::string kKeyStatus = "status"; +const std::string kKeyDensity = "density"; +const std::string kKeyValue = "value"; +const std::string kArray = "array"; +} // namespace + +namespace rc_rpc_plugin_test { + +using namespace rc_rpc_plugin; +using namespace smart_objects; + +class RCHelpersTest : public ::testing::Test { + public: + /** + * @brief Generates smart object with next structure: + * { + * "status": "status<n>", + * "value": "value<n>", + * "id": "id<n>" + * } + * where <n> is number specified with 'object_number' param. + * + * @param int object_number - number of object + * @param bool use_id_key - defines, whether "id" key must be added to smart + * object + * + * @return smart_objects::SmartObject - generated smart object + */ + smart_objects::SmartObject gen_smart_object(int object_number, + bool use_id_key) { + smart_objects::SmartObject result(smart_objects::SmartType_Map); + result[kKeyStatus] = kKeyStatus + std::to_string(object_number); + result[kKeyValue] = kKeyValue + std::to_string(object_number); + if (use_id_key) { + result[kKeyId] = kKeyId + std::to_string(object_number); + } + return result; + } +}; + +TEST_F(RCHelpersTest, + MergeModuleData_OneOfParamsNotSmartMap_ExpectDataReplacedWithNewOne) { + SmartObject data1(SmartType_Map); + SmartObject data2(SmartType_Array); + + const auto result = RCHelpers::MergeModuleData(data1, data2); + EXPECT_NE(result, data1); + EXPECT_EQ(result, data2); +} + +TEST_F(RCHelpersTest, + MergeModuleData_FirstObjectDontContainKey_ExpectDataAppendedWithNewOne) { + SmartObject data1(SmartType_Map); + SmartObject data2(SmartType_Map); + + std::map<std::string, std::string> expected_keys_values = { + {"key1", "value1"}, {"key2", "value2"}}; + auto it = expected_keys_values.begin(); + + data1[it->first] = it->second; + ++it; + data2[it->first] = it->second; + + const auto result = RCHelpers::MergeModuleData(data1, data2); + for (auto& item : expected_keys_values) { + EXPECT_TRUE(result.keyExists(item.first)); + EXPECT_EQ(result[item.first], expected_keys_values[item.first]); + } +} + +TEST_F( + RCHelpersTest, + MergeModuleData_SecondObjectContainsDifferentValueType_ExpectDataReplacedWithNewOne) { + SmartObject data1(SmartType_Map); + SmartObject data2(SmartType_Map); + + data1["key1"] = "value1"; + data2["key1"] = 30; + + const auto result = RCHelpers::MergeModuleData(data1, data2); + EXPECT_EQ(data2["key1"], result["key1"]); +} + +TEST_F(RCHelpersTest, MergeModuleData_Recursive) { + SmartObject data1(SmartType_Map); + SmartObject data2(SmartType_Map); + + data1["key1"]["subkey1"] = "subvalue1"; + data2["key1"]["subkey2"] = 30; + + const auto result = RCHelpers::MergeModuleData(data1, data2); + EXPECT_EQ(result["key1"]["subkey1"], data1["key1"]["subkey1"]); + EXPECT_EQ(result["key1"]["subkey2"], data2["key1"]["subkey2"]); +} + +TEST_F( + RCHelpersTest, + MergeModuleData_MergeObjectsThatContainArrays_ExpectDataReplacedWithNewOne) { + SmartObject data1(SmartType_Map); + SmartObject data1_array(SmartType_Array); + (*data1_array.asArray()) = + SmartArray{gen_smart_object(1, true), gen_smart_object(2, false)}; + data1[kArray] = data1_array; + + SmartObject data2(SmartType_Map); + SmartObject data2_array(SmartType_Array); + (*data2_array.asArray()) = + SmartArray{gen_smart_object(3, true), gen_smart_object(4, false)}; + data2[kArray] = data2_array; + + SmartObject expected_result(SmartType_Map); + SmartObject expected_result_array(SmartType_Array); + (*expected_result_array.asArray()) = + SmartArray{data2[kArray].getElement(0), data2[kArray].getElement(1)}; + + expected_result[kArray] = expected_result_array; + + const auto result = RCHelpers::MergeModuleData(data1, data2); + EXPECT_EQ(expected_result, result); +} + +TEST_F(RCHelpersTest, + MergeArray_OneOfParamsNotSmartArray_ExpectDataReplacedWithSecond) { + SmartObject data1(SmartType_Array); + SmartObject data2(SmartType_Map); + + const auto result = RCHelpers::MergeArray(data1, data2); + EXPECT_NE(result, data1); + EXPECT_EQ(result, data2); +} + +TEST_F(RCHelpersTest, MergeArray_FirstArrayEmpty_ExpectDataReplacedWithSecond) { + SmartObject data1(SmartType_Array); + SmartObject data2(SmartType_Array); + for (int object : {0, 1}) { + data2.asArray()->emplace(data2.asArray()->begin(), SmartObject(object)); + } + + ASSERT_EQ(0u, data1.length()); + ASSERT_EQ(2u, data2.length()); + + const auto result = RCHelpers::MergeArray(data1, data2); + EXPECT_NE(result, data1); + EXPECT_EQ(result, data2); +} + +TEST_F(RCHelpersTest, + MergeArray_SecondArrayEmpty_ExpectDataReplacedWithSecond) { + SmartObject data1(SmartType_Array); + for (int object : {0, 1}) { + data1.asArray()->emplace(data1.asArray()->begin(), SmartObject(object)); + } + SmartObject data2(SmartType_Array); + + ASSERT_EQ(2u, data1.length()); + ASSERT_EQ(0u, data2.length()); + + const auto result = RCHelpers::MergeArray(data1, data2); + EXPECT_NE(result, data1); + EXPECT_EQ(result, data2); +} + +TEST_F(RCHelpersTest, MergeArray_SimpleArrays_ExpectDataReplacedWithSecond) { + SmartObject data1(SmartType_Array); + for (int object : {0, 1, 2, 3, 4, 5}) { + data1.asArray()->emplace(data1.asArray()->begin(), SmartObject(object)); + } + + SmartObject data2(SmartType_Array); + for (int object : {0, 1}) { + data2.asArray()->emplace(data2.asArray()->begin(), SmartObject(object)); + } + + ASSERT_EQ(6u, data1.length()); + ASSERT_EQ(2u, data2.length()); + + const auto result = RCHelpers::MergeArray(data1, data2); + EXPECT_NE(result, data1); + EXPECT_EQ(result, data2); +} + +TEST_F(RCHelpersTest, + MergeArray_ObjectsHaveNotEqualIds_ExpectDataAppendedWithNewOne) { + SmartObject data1 = gen_smart_object(1, true); + SmartObject data2 = gen_smart_object(2, true); + + SmartObject array1(SmartType_Array); + array1.asArray()->push_back(data1); + SmartObject array2(SmartType_Array); + array2.asArray()->push_back(data2); + + SmartObject expected_array(SmartType_Array); + expected_array.asArray()->push_back(data1); + expected_array.asArray()->push_back(data2); + ASSERT_EQ(2u, expected_array.length()); + + const auto result = RCHelpers::MergeArray(array1, array2); + EXPECT_EQ(expected_array, result); +} + +TEST_F(RCHelpersTest, + MergeArray_SomeObjectsDontHaveIdKey_ExpectDataReplacedWithSecond) { + int object_number = 1; + + SmartObject array1(SmartType_Array); + array1.asArray()->push_back(gen_smart_object(object_number++, true)); + + SmartObject array2(SmartType_Array); + array2.asArray()->push_back(gen_smart_object(object_number++, false)); + array2.asArray()->push_back(gen_smart_object(object_number++, true)); + + const auto result = RCHelpers::MergeArray(array1, array2); + EXPECT_EQ(array2, result); +} + +TEST_F( + RCHelpersTest, + MergeArray_SomeObjectsHaveEqualIds_ExpectDataWithSameIdUpdateValueOnlyNewDataAdded) { + SmartObject temp = gen_smart_object(1, true); + + SmartObject data1(SmartType_Array); + auto& data1_array = *data1.asArray(); + + data1_array.push_back(temp); + data1_array.push_back(gen_smart_object(2, true)); + + SmartObject data2(SmartType_Array); + auto& data2_array = *data2.asArray(); + + temp[kKeyValue] = "CUSTOM VALUE"; + data2_array.push_back(temp); + data2_array.push_back(gen_smart_object(3, true)); + + SmartObject expected_result(SmartType_Array); + expected_result.asArray()->push_back(temp); + expected_result.asArray()->push_back(data1_array[1]); + expected_result.asArray()->push_back(data2_array[1]); + + const auto result = RCHelpers::MergeArray(data1, data2); + EXPECT_EQ(expected_result, result); +} + +} // namespace rc_rpc_plugin_test diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/resource_allocation_manager/CMakeLists.txt b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/resource_allocation_manager/CMakeLists.txt new file mode 100644 index 0000000000..c665e98448 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/resource_allocation_manager/CMakeLists.txt @@ -0,0 +1,81 @@ +# Copyright (c) 2019, 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 copyright holders nor the names of their 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(${CMAKE_SOURCE_DIR}/tools/cmake/helpers/sources.cmake) + +include_directories ( + ${GMOCK_INCLUDE_DIRECTORY} + ${COMPONENTS_DIR}/application_manager/test/include + ${COMPONENTS_DIR}/application_manager/rpc_plugins/rc_rpc_plugin/include + ${COMPONENTS_DIR}/application_manager/rpc_plugins/rc_rpc_plugin/test/include/ + ${COMPONENTS_DIR}/include/test/application_manager/ + ${COMPONENTS_DIR}/rc_rpc_plugin/test/include +) + +set (RESOURCE_ALLOC_MANAGER_TEST_SOURCES +${COMPONENTS_DIR}/application_manager/rpc_plugins/rc_rpc_plugin/src/interior_data_manager_impl.cc +${COMPONENTS_DIR}/application_manager/rpc_plugins/rc_rpc_plugin/src/interior_data_cache_impl.cc +${COMPONENTS_DIR}/application_manager/rpc_plugins/rc_rpc_plugin/src/resource_allocation_manager_impl.cc +${COMPONENTS_DIR}/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_rpc_plugin.cc +${COMPONENTS_DIR}/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_app_extension.cc +${COMPONENTS_DIR}/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_consent_manager_impl.cc +${COMPONENTS_DIR}/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_capabilities_manager_impl.cc +${COMPONENTS_DIR}/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_command_factory.cc +${COMPONENTS_DIR}/application_manager/rpc_plugins/rc_rpc_plugin/test/mock_rc_helpers.cc +${CMAKE_CURRENT_SOURCE_DIR}/resource_allocation_manager_impl_test.cc +) + +set(RC_COMMANDS_TEST_SOURCE_DIR ${COMPONENTS_DIR}/application_manager/rpc_plugins/rc_rpc_plugin/test/commands) +set(RC_COMMANDS_SOURCE_DIR ${COMPONENTS_DIR}/application_manager/rpc_plugins/rc_rpc_plugin/src/commands) +collect_sources(COMMANDS_SOURCES "${RC_COMMANDS_TEST_DIR}" "${RC_COMMANDS_TEST_SOURCE_DIR}") + +set(LIBRARIES + ApplicationManager + connectionHandler + SmartObjects + ProtocolHandler + MessageHelper + connectionHandler + Utils + Resumption + jsoncpp + gmock_main + dl +) + +if(ENABLE_LOG) + list(APPEND LIBRARIES log4cxx -L${LOG4CXX_LIBS_DIRECTORY}) + list(APPEND LIBRARIES apr-1 -L${APR_LIBS_DIRECTORY}) + list(APPEND LIBRARIES aprutil-1 -L${APR_UTIL_LIBS_DIRECTORY}) + list(APPEND LIBRARIES expat -L${EXPAT_LIBS_DIRECTORY}) +endif() + +create_test("resource_allocation_manager_test" "${COMMANDS_SOURCES}" "${LIBRARIES}" "${RESOURCE_ALLOC_MANAGER_TEST_SOURCES}") + diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/resource_allocation_manager_impl_test.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/resource_allocation_manager/resource_allocation_manager_impl_test.cc index 70ed832cb1..70ed832cb1 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/resource_allocation_manager_impl_test.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/resource_allocation_manager/resource_allocation_manager_impl_test.cc diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_bc_system_capability_updated_notification_from_hmi.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_bc_system_capability_updated_notification_from_hmi.cc index 6077425c07..f32aef1102 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_bc_system_capability_updated_notification_from_hmi.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_bc_system_capability_updated_notification_from_hmi.cc @@ -106,20 +106,34 @@ void OnBCSystemCapabilityUpdatedNotificationFromHMI::Run() { const auto& system_capability = (*message_)[strings::msg_params][strings::system_capability]; - if (mobile_apis::SystemCapabilityType::DISPLAYS == - system_capability[strings::system_capability_type].asInt() && - system_capability.keyExists(strings::display_capabilities)) { - const auto result = ProcessSystemDisplayCapabilities( - system_capability[strings::display_capabilities]); - if (ProcessSystemDisplayCapabilitiesResult::FAIL == result) { - LOG4CXX_ERROR(logger_, - "Failed to process display capabilities. Notification will " - "be ignored"); - return; - } else if (ProcessSystemDisplayCapabilitiesResult::CAPABILITIES_CACHED == - result) { - LOG4CXX_TRACE(logger_, "Capabilities are being cached for resuming app"); - return; + + switch (system_capability[strings::system_capability_type].asInt()) { + case mobile_apis::SystemCapabilityType::DISPLAYS: { + if (system_capability.keyExists(strings::display_capabilities)) { + const auto result = ProcessSystemDisplayCapabilities( + system_capability[strings::display_capabilities]); + if (ProcessSystemDisplayCapabilitiesResult::FAIL == result) { + LOG4CXX_ERROR( + logger_, + "Failed to process display capabilities. Notification will " + "be ignored"); + return; + } else if (ProcessSystemDisplayCapabilitiesResult:: + CAPABILITIES_CACHED == result) { + LOG4CXX_TRACE(logger_, + "Capabilities are being cached for resuming app"); + return; + } + } + break; + } + case mobile_apis::SystemCapabilityType::REMOTE_CONTROL: { + if (system_capability.keyExists(strings::rc_capability)) { + LOG4CXX_DEBUG(logger_, "Updating RC Capabilities"); + hmi_capabilities_.set_rc_capability( + system_capability[strings::rc_capability]); + } + break; } } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/sdl_rpc_plugin.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/sdl_rpc_plugin.cc index 05ff794aee..35d3fbe2f6 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/sdl_rpc_plugin.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/sdl_rpc_plugin.cc @@ -101,4 +101,5 @@ Create() { extern "C" __attribute__((visibility("default"))) void Delete( application_manager::plugin_manager::RPCPlugin* data) { delete data; -}
\ No newline at end of file + DELETE_THREAD_LOGGER(sdl_rpc_plugin::logger_); +} diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/custom_vehicle_data_manager_impl.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/custom_vehicle_data_manager_impl.cc index 32cf2b957e..334c876d76 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/custom_vehicle_data_manager_impl.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/custom_vehicle_data_manager_impl.cc @@ -252,7 +252,7 @@ void CustomVehicleDataManagerImpl::UpdateVehicleDataItems() { auto vehicle_data_items = get_custom_vdi(); - auto get_ischema_item = [](VehicleDataItem item, + auto get_ischema_item = [](const VehicleDataItem& item, SMemberType type, std::vector<SMember> history = {}) -> SMember { switch (type) { @@ -336,7 +336,7 @@ void CustomVehicleDataManagerImpl::UpdateVehicleDataItems() { std::copy_if(vehicle_data_items.begin(), vehicle_data_items.end(), std::back_inserter(result), - [&name](VehicleDataItem item) { return item.name == name; }); + [&name](VehicleDataItem& item) { return item.name == name; }); std::sort(result.begin(), result.end(), diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/vehicle_info_plugin.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/vehicle_info_plugin.cc index aa45ee704a..4799af98b7 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/vehicle_info_plugin.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/vehicle_info_plugin.cc @@ -182,4 +182,5 @@ Create() { extern "C" __attribute__((visibility("default"))) void Delete( application_manager::plugin_manager::RPCPlugin* data) { delete data; -}
\ No newline at end of file + DELETE_THREAD_LOGGER(vehicle_info_plugin::logger_); +} diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/vehicle_data_item_schema_test.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/vehicle_data_item_schema_test.cc index 1fcd5a0a60..65fecd7d4e 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/vehicle_data_item_schema_test.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/vehicle_data_item_schema_test.cc @@ -35,6 +35,7 @@ #include <type_traits> #include "formatters/formatter_json_rpc.h" #include "formatters/generic_json_formatter.h" +#include "gmock/gmock.h" #include "gtest/gtest.h" #include "interfaces/HMI_API.h" #include "smart_objects/smart_object.h" @@ -52,7 +53,6 @@ using ::testing::NiceMock; using ::testing::Return; using ::testing::ReturnRef; -using application_manager::MockMessageHelper; using ErrorCode = smart_objects::errors::eType; namespace { diff --git a/src/components/application_manager/src/policies/policy_handler.cc b/src/components/application_manager/src/policies/policy_handler.cc index f88eaf47a5..8c27c44aae 100644 --- a/src/components/application_manager/src/policies/policy_handler.cc +++ b/src/components/application_manager/src/policies/policy_handler.cc @@ -298,7 +298,6 @@ const std::string PolicyHandler::kLibrary = "libPolicy.so"; PolicyHandler::PolicyHandler(const PolicySettings& settings, ApplicationManager& application_manager) : AsyncRunner("PolicyHandler async runner thread") - , dl_handle_(0) , last_activated_app_id_(0) , statistic_manager_impl_(std::make_shared<StatisticManagerImpl>(this)) , settings_(settings) @@ -325,36 +324,43 @@ bool PolicyHandler::LoadPolicyLibrary() { policy_manager_.reset(); return false; } - dl_handle_ = dlopen(kLibrary.c_str(), RTLD_LAZY); - const char* error = dlerror(); - if (!error) { - if (CreateManager()) { - policy_manager_->set_listener(this); - event_observer_ = - std::shared_ptr<PolicyEventObserver>(new PolicyEventObserver( - this, application_manager_.event_dispatcher())); - } - } else { - LOG4CXX_ERROR(logger_, error); + if (CreateManager()) { + policy_manager_->set_listener(this); + event_observer_ = std::shared_ptr<PolicyEventObserver>( + new PolicyEventObserver(this, application_manager_.event_dispatcher())); } return (policy_manager_.use_count() != 0); } bool PolicyHandler::CreateManager() { + void* policy_handle = dlopen(kLibrary.c_str(), RTLD_LAZY); + const char* error = dlerror(); + if (error) { + LOG4CXX_ERROR(logger_, error); + return false; + } + typedef PolicyManager* (*CreateManager)(); typedef void (*DeleteManager)(PolicyManager*); CreateManager create_manager = - reinterpret_cast<CreateManager>(dlsym(dl_handle_, "CreateManager")); + reinterpret_cast<CreateManager>(dlsym(policy_handle, "CreateManager")); DeleteManager delete_manager = - reinterpret_cast<DeleteManager>(dlsym(dl_handle_, "DeleteManager")); + reinterpret_cast<DeleteManager>(dlsym(policy_handle, "DeleteManager")); + auto policy_destroyer = [delete_manager, + policy_handle](PolicyManager* policy_manager) { + LOG4CXX_DEBUG(logger_, "Delete Policy Manager"); + delete_manager(policy_manager); + dlclose(policy_handle); + }; char* error_string = dlerror(); if (NULL == error_string) { policy_manager_ = - std::shared_ptr<PolicyManager>(create_manager(), delete_manager); + std::shared_ptr<PolicyManager>(create_manager(), policy_destroyer); } else { LOG4CXX_WARN(logger_, error_string); + dlclose(policy_handle); } return (policy_manager_.use_count() != 0); } @@ -1131,10 +1137,6 @@ bool PolicyHandler::UnloadPolicyLibrary() { if (policy_manager_) { policy_manager_.reset(); } - if (dl_handle_) { - ret = (dlclose(dl_handle_) == 0); - dl_handle_ = 0; - } LOG4CXX_TRACE(logger_, "exit"); return ret; } diff --git a/src/components/include/utils/logger.h b/src/components/include/utils/logger.h index 907f8f4db0..d492cfcb1b 100644 --- a/src/components/include/utils/logger.h +++ b/src/components/include/utils/logger.h @@ -65,6 +65,11 @@ void deinit_logger(); #define DEINIT_LOGGER() deinit_logger() +// Logger thread deinitilization macro that need to stop the thread of handling +// messages for the log4cxx +#define DELETE_THREAD_LOGGER(logger_var) \ + logger::delete_log_message_loop_thread(logger_var) + // special macros to dump logs from queue // it's need, for example, when crash happend #define FLUSH_LOGGER() logger::flush_logger() @@ -141,6 +146,8 @@ log4cxx_time_t time_now(); #define DEINIT_LOGGER() +#define DELETE_THREAD_LOGGER(logger_var) + #define FLUSH_LOGGER() #define LOG4CXX_IS_TRACE_ENABLED(logger) false diff --git a/src/components/include/utils/push_log.h b/src/components/include/utils/push_log.h index aaeaa83bae..f6c396ae71 100644 --- a/src/components/include/utils/push_log.h +++ b/src/components/include/utils/push_log.h @@ -51,7 +51,7 @@ bool logs_enabled(); void set_logs_enabled(bool state); void create_log_message_loop_thread(); -void delete_log_message_loop_thread(); +void delete_log_message_loop_thread(log4cxx::LoggerPtr& logger); } // namespace logger #endif // SRC_COMPONENTS_INCLUDE_UTILS_PUSH_LOG_H_ diff --git a/src/components/policy/policy_external/src/policy_helper.cc b/src/components/policy/policy_external/src/policy_helper.cc index 99e4450065..98e5b5b3c1 100644 --- a/src/components/policy/policy_external/src/policy_helper.cc +++ b/src/components/policy/policy_external/src/policy_helper.cc @@ -114,7 +114,7 @@ bool operator!=(const policy_table::ApplicationParams& first, for (; it_first != it_first_end; ++it_first) { CompareGroupName gp(*it_first); StringsConstItr it = std::find_if(it_second, it_second_end, gp); - if (it_first_end == it) { + if (it_second_end == it) { return true; } } diff --git a/src/components/policy/policy_external/src/policy_manager_impl.cc b/src/components/policy/policy_external/src/policy_manager_impl.cc index 95d3011b33..871d34df7c 100644 --- a/src/components/policy/policy_external/src/policy_manager_impl.cc +++ b/src/components/policy/policy_external/src/policy_manager_impl.cc @@ -54,14 +54,6 @@ #include "policy/access_remote_impl.h" #include "utils/timer_task_impl.h" -__attribute__((visibility("default"))) policy::PolicyManager* CreateManager() { - return new policy::PolicyManagerImpl(); -} - -__attribute__((visibility("default"))) void DeleteManager( - policy::PolicyManager* pm) { - delete pm; -} namespace { /** @@ -2012,6 +2004,7 @@ AppPermissions PolicyManagerImpl::GetAppPermissionsChanges( permissions.appPermissionsConsentNeeded = IsConsentNeeded(device_id, policy_app_id); permissions.appRevoked = IsApplicationRevoked(policy_app_id); + permissions.isSDLAllowed = false; GetPriority(permissions.application_id, &permissions.priority); } return permissions; @@ -2522,3 +2515,13 @@ const std::vector<std::string> PolicyManagerImpl::GetRPCsForFunctionGroup( } } // namespace policy + +__attribute__((visibility("default"))) policy::PolicyManager* CreateManager() { + return new policy::PolicyManagerImpl(); +} + +__attribute__((visibility("default"))) void DeleteManager( + policy::PolicyManager* pm) { + delete pm; + DELETE_THREAD_LOGGER(policy::logger_); +} diff --git a/src/components/policy/policy_regular/src/policy_helper.cc b/src/components/policy/policy_regular/src/policy_helper.cc index c6116584f8..b689ed81ba 100644 --- a/src/components/policy/policy_regular/src/policy_helper.cc +++ b/src/components/policy/policy_regular/src/policy_helper.cc @@ -113,7 +113,7 @@ bool operator!=(const policy_table::ApplicationParams& first, for (; it_first != it_first_end; ++it_first) { CompareGroupName gp(*it_first); StringsConstItr it = std::find_if(it_second, it_second_end, gp); - if (it_first_end == it) { + if (it_second_end == it) { return true; } } @@ -438,7 +438,7 @@ bool CheckAppPolicy::operator()(const AppPoliciesValueType& app_policy) { const auto& snapshot_app_policy_end = snapshot_->policy_table.app_policies_section.apps.end(); - auto find_app = [&app_id](AppPoliciesValueType app) { + auto find_app = [&app_id](AppPoliciesValueType& app) { return app_id == app.second.get_string(); }; diff --git a/src/components/policy/policy_regular/src/policy_manager_impl.cc b/src/components/policy/policy_regular/src/policy_manager_impl.cc index 9e5cf01493..52c5ac5706 100644 --- a/src/components/policy/policy_regular/src/policy_manager_impl.cc +++ b/src/components/policy/policy_regular/src/policy_manager_impl.cc @@ -53,15 +53,6 @@ #include "policy/access_remote.h" #include "policy/access_remote_impl.h" -__attribute__((visibility("default"))) policy::PolicyManager* CreateManager() { - return new policy::PolicyManagerImpl(); -} - -__attribute__((visibility("default"))) void DeleteManager( - policy::PolicyManager* pm) { - delete pm; -} - namespace { const uint32_t kDefaultRetryTimeoutInMSec = 60u * date_time::MILLISECONDS_IN_SECOND; @@ -1365,6 +1356,7 @@ AppPermissions PolicyManagerImpl::GetAppPermissionsChanges( permissions.appPermissionsConsentNeeded = IsConsentNeeded(device_id, policy_app_id); permissions.appRevoked = IsApplicationRevoked(policy_app_id); + permissions.isSDLAllowed = true; GetPriority(permissions.application_id, &permissions.priority); } return permissions; @@ -1813,3 +1805,13 @@ const std::vector<std::string> PolicyManagerImpl::GetRPCsForFunctionGroup( } } // namespace policy + +__attribute__((visibility("default"))) policy::PolicyManager* CreateManager() { + return new policy::PolicyManagerImpl(); +} + +__attribute__((visibility("default"))) void DeleteManager( + policy::PolicyManager* pm) { + delete pm; + DELETE_THREAD_LOGGER(policy::logger_); +} diff --git a/src/components/protocol_handler/src/protocol_handler_impl.cc b/src/components/protocol_handler/src/protocol_handler_impl.cc index 1df830908a..61b9afd7bc 100644 --- a/src/components/protocol_handler/src/protocol_handler_impl.cc +++ b/src/components/protocol_handler/src/protocol_handler_impl.cc @@ -493,8 +493,9 @@ void ProtocolHandlerImpl::SendStartSessionNAck( BsonArray rejectedParamsArr; bson_array_initialize(&rejectedParamsArr, rejectedParams.size()); for (std::string param : rejectedParams) { - char paramPtr[255]; - strncpy(paramPtr, param.c_str(), 255); + char paramPtr[256]; + strncpy(paramPtr, param.c_str(), sizeof(paramPtr)); + paramPtr[sizeof(paramPtr) - 1] = '\0'; bson_array_add_string(&rejectedParamsArr, paramPtr); } bson_object_put_array( @@ -555,8 +556,9 @@ void ProtocolHandlerImpl::SendEndSessionNAck( BsonArray rejectedParamsArr; bson_array_initialize(&rejectedParamsArr, rejectedParams.size()); for (std::string param : rejectedParams) { - char paramPtr[255]; - strncpy(paramPtr, param.c_str(), 255); + char paramPtr[256]; + strncpy(paramPtr, param.c_str(), sizeof(paramPtr)); + paramPtr[sizeof(paramPtr) - 1] = '\0'; bson_array_add_string(&rejectedParamsArr, paramPtr); } bson_object_put_array( diff --git a/src/components/security_manager/src/ssl_context_impl.cc b/src/components/security_manager/src/ssl_context_impl.cc index 357d9556fb..d5c892c07a 100644 --- a/src/components/security_manager/src/ssl_context_impl.cc +++ b/src/components/security_manager/src/ssl_context_impl.cc @@ -529,13 +529,18 @@ bool CryptoManagerImpl::SSLContextImpl::Decrypt(const uint8_t* const in_data, } size_t CryptoManagerImpl::SSLContextImpl::get_max_block_size(size_t mtu) const { + LOG4CXX_AUTO_TRACE(logger_); if (!max_block_size_) { // FIXME(EZamakhov): add correct logics for TLS1/1.2/SSL3 // For SSL3.0 set temporary value 90, old TLS1.2 value is 29 assert(mtu > 90); return mtu - 90; } - return max_block_size_(mtu); + + const auto max_allowed_block_size = + mtu > SSL3_RT_MAX_PLAIN_LENGTH ? SSL3_RT_MAX_PLAIN_LENGTH : mtu; + + return max_block_size_(max_allowed_block_size); } bool CryptoManagerImpl::SSLContextImpl::IsHandshakePending() const { diff --git a/src/components/transport_manager/include/transport_manager/cloud/cloud_device.h b/src/components/transport_manager/include/transport_manager/cloud/cloud_device.h index 9c25be2a3e..15d23bba7f 100644 --- a/src/components/transport_manager/include/transport_manager/cloud/cloud_device.h +++ b/src/components/transport_manager/include/transport_manager/cloud/cloud_device.h @@ -55,7 +55,7 @@ class CloudDevice : public Device { public: CloudDevice(std::string& host, std::string& port, std::string& name); - CloudDevice(CloudAppEndpoint endpoint, std::string& name); + CloudDevice(CloudAppEndpoint& endpoint, std::string& name); virtual const std::string& GetHost() const; diff --git a/src/components/transport_manager/src/cloud/cloud_device.cc b/src/components/transport_manager/src/cloud/cloud_device.cc index c1ad186ded..9225589d57 100644 --- a/src/components/transport_manager/src/cloud/cloud_device.cc +++ b/src/components/transport_manager/src/cloud/cloud_device.cc @@ -49,7 +49,7 @@ CloudDevice::CloudDevice(std::string& host, .query = "", .fragment = ""}) {} -CloudDevice::CloudDevice(CloudAppEndpoint endpoint, std::string& name) +CloudDevice::CloudDevice(CloudAppEndpoint& endpoint, std::string& name) : Device(name, std::string(name)), endpoint_(endpoint) {} bool CloudDevice::IsSameAs(const Device* other) const { diff --git a/src/components/transport_manager/src/usb/usb_device_scanner.cc b/src/components/transport_manager/src/usb/usb_device_scanner.cc index cff42123a4..51d521c1bf 100644 --- a/src/components/transport_manager/src/usb/usb_device_scanner.cc +++ b/src/components/transport_manager/src/usb/usb_device_scanner.cc @@ -182,12 +182,12 @@ AoaInitSequence::AoaInitSequence(const TransportManagerSettings& settings) auto uri = settings.aoa_filter_uri().c_str(); auto serial_num = settings.aoa_filter_serial_number().c_str(); AddTransfer(new AoaGetProtocolRequest); - AddTransfer(new AoaSendIdString(0, manufacturer, sizeof(manufacturer))); - AddTransfer(new AoaSendIdString(1, model_name, sizeof(model_name))); - AddTransfer(new AoaSendIdString(2, description, sizeof(description))); - AddTransfer(new AoaSendIdString(3, version, sizeof(version))); - AddTransfer(new AoaSendIdString(4, uri, sizeof(uri))); - AddTransfer(new AoaSendIdString(5, serial_num, sizeof(serial_num))); + AddTransfer(new AoaSendIdString(0, manufacturer, strlen(manufacturer))); + AddTransfer(new AoaSendIdString(1, model_name, strlen(model_name))); + AddTransfer(new AoaSendIdString(2, description, strlen(description))); + AddTransfer(new AoaSendIdString(3, version, strlen(version))); + AddTransfer(new AoaSendIdString(4, uri, strlen(uri))); + AddTransfer(new AoaSendIdString(5, serial_num, strlen(serial_num))); AddTransfer(new AoaTurnIntoAccessoryMode); } diff --git a/src/components/utils/src/logger.cc b/src/components/utils/src/logger.cc index 2a4b8eb108..5a7922afc4 100644 --- a/src/components/utils/src/logger.cc +++ b/src/components/utils/src/logger.cc @@ -39,11 +39,8 @@ void deinit_logger() { CREATE_LOGGERPTR_LOCAL(logger_, "Utils") LOG4CXX_DEBUG(logger_, "Logger deinitialization"); logger::set_logs_enabled(false); - if (logger::logger_status == logger::LoggerThreadCreated) { - logger::flush_logger(); - } - logger::delete_log_message_loop_thread(); log4cxx::LoggerPtr rootLogger = log4cxx::Logger::getRootLogger(); + logger::delete_log_message_loop_thread(rootLogger); log4cxx::spi::LoggerRepositoryPtr repository = rootLogger->getLoggerRepository(); log4cxx::LoggerList loggers = repository->getCurrentLoggers(); diff --git a/src/components/utils/src/push_log.cc b/src/components/utils/src/push_log.cc index dea0e75274..f9d1cd738a 100644 --- a/src/components/utils/src/push_log.cc +++ b/src/components/utils/src/push_log.cc @@ -41,7 +41,16 @@ struct __attribute__((visibility("default"))) LogsEnabled { }; std::atomic_bool LogsEnabled::logs_enabled_(false); -static std::unique_ptr<LogMessageLoopThread> log_message_loop_thread; + +template <typename T> +using logger_ptr = std::unique_ptr<T, std::function<void(T*)> >; + +static logger_ptr<LogMessageLoopThread> log_message_loop_thread; + +auto deinit_logger = [](LogMessageLoopThread* logMsgThread) { + delete logMsgThread; + logger::logger_status = logger::LoggerThreadNotCreated; +}; bool push_log(log4cxx::LoggerPtr logger, log4cxx::LevelPtr level, @@ -86,13 +95,37 @@ void set_logs_enabled(bool state) { void create_log_message_loop_thread() { if (!log_message_loop_thread) { - log_message_loop_thread = - std::unique_ptr<LogMessageLoopThread>(new LogMessageLoopThread); + log_message_loop_thread = logger_ptr<LogMessageLoopThread>( + new LogMessageLoopThread, deinit_logger); } } -void delete_log_message_loop_thread() { +void delete_log_message_loop_thread(log4cxx::LoggerPtr& logger) { + if (logger::logger_status == logger::LoggerThreadCreated) { + logger::flush_logger(); + } + log_message_loop_thread.reset(); + + if (LOG4CXX_UNLIKELY(logger->isDebugEnabled())) { + ::log4cxx::helpers::MessageBuffer oss_; + logger->forcedLog(::log4cxx::Level::getDebug(), + oss_.str(oss_ << "Logger loop thread deinitialized"), + LOG4CXX_LOCATION); + } + + if (logger->getRootLogger() == logger) { + return; + } + + if (LOG4CXX_UNLIKELY(logger->isDebugEnabled())) { + ::log4cxx::helpers::MessageBuffer oss_; + logger->forcedLog(::log4cxx::Level::getDebug(), + oss_.str(oss_ << "Logger calling removeAllAppenders"), + LOG4CXX_LOCATION); + } + + logger->removeAllAppenders(); } void flush_logger() { |