diff options
4 files changed, 74 insertions, 67 deletions
diff --git a/src/components/application_manager/include/application_manager/request_controller.h b/src/components/application_manager/include/application_manager/request_controller.h index c4869e1a90..d3a5a0b821 100644 --- a/src/components/application_manager/include/application_manager/request_controller.h +++ b/src/components/application_manager/include/application_manager/request_controller.h @@ -233,7 +233,7 @@ class RequestController { * @brief Checks whether all constraints are met before adding of request into * processing queue. Verifies amount of pending requests, amount of requests * per time scale for different HMI levels - * @param request - request to check contraints for + * @param request - request to check constraints for * @param level - HMI level in which request has been issued * @return Appropriate result code of verification */ diff --git a/src/components/application_manager/include/application_manager/request_tracker.h b/src/components/application_manager/include/application_manager/request_tracker.h index c53057b773..36ab3eaefb 100644 --- a/src/components/application_manager/include/application_manager/request_tracker.h +++ b/src/components/application_manager/include/application_manager/request_tracker.h @@ -1,35 +1,34 @@ /* - * 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. -*/ - + * 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. + */ #ifndef SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_REQUEST_TRACKER_H_ #define SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_REQUEST_TRACKER_H_ @@ -47,7 +46,7 @@ namespace request_controller { /** * @brief The TrackResult enum defines results of application request tracking */ -enum TrackResult { +enum class TrackResult { kSuccess, kNoneLevelMaxRequestsExceeded, kMaxRequestsExceeded @@ -55,9 +54,11 @@ enum TrackResult { /** * @brief The RequestTracker class tracks requests per time constraints. - * There are several parameters in configuration file defining maximum requests + * There are several parameters in configuration file defining maximum + * requests * number and time scale for that number, so application must consider that, - * otherwise it will be disconnected and won't be registered till next ignition + * otherwise it will be disconnected and won't be registered till next + * ignition * cycle. */ class RequestTracker { @@ -88,7 +89,8 @@ class RequestTracker { typedef std::map<ApplicationID, RequestAddedAt> ApplicationsRequestsTracker; /** - * @brief Checks whether maximum requests number is exceeded per defined time + * @brief Checks whether maximum requests number is exceeded per defined + * time * scale. * @param app_id Unique application id * @param time_scale Time scale defined in configuration file @@ -119,6 +121,5 @@ class RequestTracker { }; } // namespace request_controller - } // namespace application_manager #endif // SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_REQUEST_TRACKER_H_ diff --git a/src/components/application_manager/src/request_tracker.cc b/src/components/application_manager/src/request_tracker.cc index 8097055e9f..71ef8b05b1 100644 --- a/src/components/application_manager/src/request_tracker.cc +++ b/src/components/application_manager/src/request_tracker.cc @@ -33,6 +33,7 @@ #include "utils/logger.h" #include "utils/macro.h" #include "application_manager/request_tracker.h" +#include "application_manager/message_helper.h" namespace application_manager { @@ -48,7 +49,9 @@ TrackResult RequestTracker::Track(const ApplicationID& app_id, LOG4CXX_AUTO_TRACE(logger_); bool track_result = false; - LOG4CXX_DEBUG(logger_, "Tracking request for level: " << level); + LOG4CXX_DEBUG(logger_, + "Tracking request for level: " + << MessageHelper::StringifiedHMILevel(level)); if (mobile_apis::HMILevel::HMI_NONE == level) { track_result = Track(app_id, @@ -56,7 +59,8 @@ TrackResult RequestTracker::Track(const ApplicationID& app_id, settings_.app_hmi_level_none_time_scale_max_requests(), none_level_tracker_); - return track_result ? kSuccess : kNoneLevelMaxRequestsExceeded; + return track_result ? TrackResult::kSuccess + : TrackResult::kNoneLevelMaxRequestsExceeded; } track_result = Track(app_id, @@ -64,7 +68,8 @@ TrackResult RequestTracker::Track(const ApplicationID& app_id, settings_.app_time_scale_max_requests(), tracker_); - return track_result ? kSuccess : kMaxRequestsExceeded; + return track_result ? TrackResult::kSuccess + : TrackResult::kMaxRequestsExceeded; } bool RequestTracker::Track(const ApplicationID& app_id, @@ -82,9 +87,9 @@ bool RequestTracker::Track(const ApplicationID& app_id, "Time scale is: " << time_scale << ". Max requests number is: " << max_requests); + LOG4CXX_DEBUG(logger_, "Tracking app id: " << app_id); ApplicationsRequestsTracker::iterator it_app = tracker.find(app_id); - LOG4CXX_DEBUG(logger_, "Tracking app id: " << app_id); if (tracker.end() == it_app) { LOG4CXX_DEBUG(logger_, "Adding new application into tracking."); tracker[app_id].push_back(date_time::DateTime::getCurrentTime()); diff --git a/src/components/application_manager/test/request_tracker_test.cc b/src/components/application_manager/test/request_tracker_test.cc index f666939adf..ee09e0a3e0 100644 --- a/src/components/application_manager/test/request_tracker_test.cc +++ b/src/components/application_manager/test/request_tracker_test.cc @@ -72,20 +72,20 @@ class RequestTrackerTestClass : public ::testing::Test { application_manager::request_controller::RequestTracker tracker_; - const uint32_t kDefaultAppHmiLevelNoneRequestsTimeScale = 10; + const uint32_t kDefaultAppHmiLevelNoneRequestsTimeScale = 10u; const uint32_t kDefaultAppHmiLevelNoneTimeScaleMaxRequests = 100u; - const uint32_t kDefaultAppTimeScaleMaxRequests = 5; + const uint32_t kDefaultAppTimeScaleMaxRequests = 5u; const uint32_t kDefaultAppRequestsTimeScale = 200u; }; TEST_F(RequestTrackerTestClass, TrackAppRequestInNone_ExpectSuccessTillLimit) { - const uint32_t app_id = 1; + const uint32_t app_id = 1u; const mobile_apis::HMILevel::eType none_level = mobile_apis::HMILevel::HMI_NONE; SetDefaultConstraints(); - for (size_t i = 0; i < kDefaultAppHmiLevelNoneTimeScaleMaxRequests; ++i) { + for (uint32_t i = 0; i < kDefaultAppHmiLevelNoneTimeScaleMaxRequests; ++i) { EXPECT_EQ(application_manager::request_controller::TrackResult::kSuccess, tracker_.Track(app_id, none_level)); } @@ -97,10 +97,6 @@ TEST_F(RequestTrackerTestClass, TrackAppRequestInNone_ExpectSuccessTillLimit) { TEST_F(RequestTrackerTestClass, TrackAppRequestInNone_NoLimits_ExpectAlwaysSuccess) { - const uint32_t app_id = 1; - const mobile_apis::HMILevel::eType none_level = - mobile_apis::HMILevel::HMI_NONE; - const uint32_t no_limit = 0; EXPECT_CALL(mock_request_controller_settings_, @@ -111,7 +107,11 @@ TEST_F(RequestTrackerTestClass, app_hmi_level_none_time_scale_max_requests()) .WillRepeatedly(ReturnRef(no_limit)); - for (size_t i = 0; i < kDefaultAppHmiLevelNoneTimeScaleMaxRequests; ++i) { + const uint32_t app_id = 1u; + const mobile_apis::HMILevel::eType none_level = + mobile_apis::HMILevel::HMI_NONE; + + for (uint32_t i = 0; i < kDefaultAppHmiLevelNoneTimeScaleMaxRequests; ++i) { EXPECT_EQ(application_manager::request_controller::TrackResult::kSuccess, tracker_.Track(app_id, none_level)); } @@ -122,13 +122,13 @@ TEST_F(RequestTrackerTestClass, TEST_F(RequestTrackerTestClass, TrackAppRequestInOtherThanNone_ExpectSuccessTillLimit) { - const uint32_t app_id = 1; + const uint32_t app_id = 1u; mobile_apis::HMILevel::eType hmi_level = mobile_apis::HMILevel::HMI_BACKGROUND; SetDefaultConstraints(); - for (size_t i = 0; i < kDefaultAppTimeScaleMaxRequests; ++i) { + for (uint32_t i = 0; i < kDefaultAppTimeScaleMaxRequests; ++i) { EXPECT_EQ(application_manager::request_controller::TrackResult::kSuccess, tracker_.Track(app_id, hmi_level)); if (i % 2) { @@ -145,10 +145,6 @@ TEST_F(RequestTrackerTestClass, TEST_F(RequestTrackerTestClass, TrackAppRequestInOtherThanNone_NoLimits_ExpectAlwaysSuccess) { - const uint32_t app_id = 1; - mobile_apis::HMILevel::eType hmi_level = - mobile_apis::HMILevel::HMI_BACKGROUND; - const uint32_t no_limit = 0; EXPECT_CALL(mock_request_controller_settings_, app_time_scale()) @@ -157,7 +153,11 @@ TEST_F(RequestTrackerTestClass, EXPECT_CALL(mock_request_controller_settings_, app_time_scale_max_requests()) .WillRepeatedly(ReturnRef(no_limit)); - for (size_t i = 0; i < kDefaultAppTimeScaleMaxRequests; ++i) { + const uint32_t app_id = 1u; + mobile_apis::HMILevel::eType hmi_level = + mobile_apis::HMILevel::HMI_BACKGROUND; + + for (uint32_t i = 0; i < kDefaultAppTimeScaleMaxRequests; ++i) { EXPECT_EQ(application_manager::request_controller::TrackResult::kSuccess, tracker_.Track(app_id, hmi_level)); if (i % 2) { @@ -173,15 +173,15 @@ TEST_F(RequestTrackerTestClass, TEST_F(RequestTrackerTestClass, TrackTwoAppsRequestInNone_ExpectSuccessTillLimit) { - const uint32_t app_id_1 = 1; - const uint32_t app_id_2 = 2; + const uint32_t app_id_1 = 1u; + const uint32_t app_id_2 = 2u; const mobile_apis::HMILevel::eType none_level = mobile_apis::HMILevel::HMI_NONE; SetDefaultConstraints(); - for (size_t i = 0; i < kDefaultAppHmiLevelNoneTimeScaleMaxRequests; ++i) { + for (uint32_t i = 0; i < kDefaultAppHmiLevelNoneTimeScaleMaxRequests; ++i) { if (i % 2) { EXPECT_EQ(application_manager::request_controller::TrackResult::kSuccess, tracker_.Track(app_id_1, none_level)); @@ -191,7 +191,8 @@ TEST_F(RequestTrackerTestClass, } } - for (size_t i = 0; i < kDefaultAppHmiLevelNoneTimeScaleMaxRequests / 2; ++i) { + for (uint32_t i = 0; i < kDefaultAppHmiLevelNoneTimeScaleMaxRequests / 2; + ++i) { EXPECT_EQ(application_manager::request_controller::TrackResult::kSuccess, tracker_.Track(app_id_1, none_level)); EXPECT_EQ(application_manager::request_controller::TrackResult::kSuccess, @@ -209,10 +210,6 @@ TEST_F(RequestTrackerTestClass, TEST_F(RequestTrackerTestClass, TrackAppRequestInNone_DoPause_TrackAgain_ExpectSuccessTillLimit) { - const uint32_t app_id = 1; - const mobile_apis::HMILevel::eType none_level = - mobile_apis::HMILevel::HMI_NONE; - const uint32_t max_requests = 5; const uint32_t time_scale_ms = 1; @@ -228,14 +225,18 @@ TEST_F(RequestTrackerTestClass, app_hmi_level_none_time_scale_max_requests()) .WillRepeatedly(ReturnRef(max_requests)); - for (size_t i = 0; i < max_requests; ++i) { + const uint32_t app_id = 1u; + const mobile_apis::HMILevel::eType none_level = + mobile_apis::HMILevel::HMI_NONE; + + for (uint32_t i = 0; i < max_requests; ++i) { EXPECT_EQ(application_manager::request_controller::TrackResult::kSuccess, tracker_.Track(app_id, none_level)); } awaiter.WaitFor(auto_lock, time_scale_ms * 2); - for (size_t i = 0; i < max_requests; ++i) { + for (uint32_t i = 0; i < max_requests; ++i) { EXPECT_EQ(application_manager::request_controller::TrackResult::kSuccess, tracker_.Track(app_id, none_level)); } |