diff options
author | Andrey Oleynik (GitHub) <dev-gh@users.noreply.github.com> | 2017-01-05 15:39:37 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-05 15:39:37 +0200 |
commit | 980a945110ed1f58000de4ad178dc877a9372b80 (patch) | |
tree | a93877c94bebce1ff198c3222cfd6cca56b4bf8a /src/components/application_manager/include/application_manager | |
parent | 086097c4d8aac14cb425207f3392fe8ab3f28bf6 (diff) | |
parent | 059dae5f04ff38bd9f61827a9ed53b07e2adcbd7 (diff) | |
download | sdl_core-980a945110ed1f58000de4ad178dc877a9372b80.tar.gz |
Merge pull request #1149 from dev-gh/fix/Fix_max_requiests_constraint_check
Fixes logic of max requests per time scale constraint verification
Diffstat (limited to 'src/components/application_manager/include/application_manager')
3 files changed, 141 insertions, 85 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 479ebb217e..d3a5a0b821 100644 --- a/src/components/application_manager/include/application_manager/request_controller.h +++ b/src/components/application_manager/include/application_manager/request_controller.h @@ -49,6 +49,7 @@ #include "application_manager/request_info.h" #include "application_manager/request_controller_settings.h" +#include "application_manager/request_tracker.h" namespace application_manager { @@ -229,11 +230,15 @@ class RequestController { void terminateWaitingForResponseAppRequests(const uint32_t& app_id); /** - * @brief Check Posibility to add new requests, or limits was exceeded - * @param request - request to check possipility to Add - * @return True if new request could be added, false otherwise + * @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 constraints for + * @param level - HMI level in which request has been issued + * @return Appropriate result code of verification */ - TResult CheckPosibilitytoAdd(const RequestPtr request); + TResult CheckPosibilitytoAdd(const RequestPtr request, + const mobile_api::HMILevel::eType level); /** * @brief Check Posibility to add new requests, or limits was exceeded @@ -274,6 +279,12 @@ class RequestController { RequestInfoSet waiting_for_response_; /** + * @brief Tracker verifying time scale and maximum requests amount in + * different HMI levels + */ + RequestTracker request_tracker_; + + /** * @brief Set of HMI notifications with timeout. */ std::list<RequestPtr> notification_list_; diff --git a/src/components/application_manager/include/application_manager/request_info.h b/src/components/application_manager/include/application_manager/request_info.h index 193699be78..216eb86cc5 100644 --- a/src/components/application_manager/include/application_manager/request_info.h +++ b/src/components/application_manager/include/application_manager/request_info.h @@ -63,9 +63,7 @@ struct RequestInfo { RequestInfo(RequestPtr request, const RequestType requst_type, const uint64_t timeout_msec) - : request_(request) - , timeout_msec_(timeout_msec) - , hmi_level_(mobile_apis::HMILevel::INVALID_ENUM) { + : request_(request), timeout_msec_(timeout_msec) { start_time_ = date_time::DateTime::getCurrentTime(); updateEndTime(); requst_type_ = requst_type; @@ -106,14 +104,6 @@ struct RequestInfo { return app_id_; } - mobile_apis::HMILevel::eType hmi_level() { - return hmi_level_; - } - - void set_hmi_level(const mobile_apis::HMILevel::eType& level) { - hmi_level_ = level; - } - RequestType requst_type() const { return requst_type_; } @@ -135,7 +125,6 @@ struct RequestInfo { uint64_t timeout_msec_; TimevalStruct end_time_; uint32_t app_id_; - mobile_apis::HMILevel::eType hmi_level_; RequestType requst_type_; uint32_t correlation_id_; }; @@ -234,34 +223,6 @@ class RequestInfoSet { */ const size_t Size(); - /** - * @brief Check if this app is able to add new requests, - * or limits was exceeded - * @param app_id - application id - * @param app_time_scale - time scale (seconds) - * @param max_request_per_time_scale - maximum count of request - * that should be allowed for app_time_scale seconds - * @return True if new request could be added, false otherwise - */ - bool CheckTimeScaleMaxRequest(uint32_t app_id, - uint32_t app_time_scale, - uint32_t max_request_per_time_scale); - - /** - * @brief Check if this app is able to add new requests - * in current hmi_level, or limits was exceeded - * @param hmi_level - hmi level - * @param app_id - application id - * @param app_time_scale - time scale (seconds) - * @param max_request_per_time_scale - maximum count of request - * that should be allowed for app_time_scale seconds - * @return True if new request could be added, false otherwise - */ - bool CheckHMILevelTimeScaleMaxRequest(mobile_apis::HMILevel::eType hmi_level, - uint32_t app_id, - uint32_t app_time_scale, - uint32_t max_request_per_time_scale); - private: /* * @brief Comparator of connection key for std::find_if function @@ -329,47 +290,6 @@ struct TimeScale { uint32_t app_id_; }; -/** -* @brief Structure used in std algorithms to determine amount of request -* during time scale for application in defined hmi level -*/ -struct HMILevelTimeScale { - HMILevelTimeScale(const TimevalStruct& start, - const TimevalStruct& end, - const uint32_t& app_id, - const mobile_apis::HMILevel::eType& hmi_level) - : start_(start), end_(end), app_id_(app_id), hmi_level_(hmi_level) {} - - bool operator()(RequestInfoPtr setEntry) { - if (!setEntry.valid()) { - return false; - } - - if (setEntry->app_id() != app_id_) { - return false; - } - - if (setEntry->hmi_level() != hmi_level_) { - return false; - } - - if (date_time::DateTime::getSecs(setEntry->start_time()) < - date_time::DateTime::getSecs(start_) || - date_time::DateTime::getSecs(setEntry->start_time()) > - date_time::DateTime::getSecs(end_)) { - return false; - } - - return true; - } - - private: - TimevalStruct start_; - TimevalStruct end_; - uint32_t app_id_; - mobile_apis::HMILevel::eType hmi_level_; -}; - } // namespace request_controller } // namespace application_manager diff --git a/src/components/application_manager/include/application_manager/request_tracker.h b/src/components/application_manager/include/application_manager/request_tracker.h new file mode 100644 index 0000000000..36ab3eaefb --- /dev/null +++ b/src/components/application_manager/include/application_manager/request_tracker.h @@ -0,0 +1,125 @@ +/* + * 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_ + +#include <string> +#include <map> +#include <vector> +#include "application_manager/request_controller_settings.h" +#include "interfaces/MOBILE_API.h" +#include "utils/date_time.h" + +namespace application_manager { + +namespace request_controller { + +/** + * @brief The TrackResult enum defines results of application request tracking + */ +enum class TrackResult { + kSuccess, + kNoneLevelMaxRequestsExceeded, + kMaxRequestsExceeded +}; + +/** + * @brief The RequestTracker class tracks requests per time constraints. + * 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 + * cycle. + */ +class RequestTracker { + public: + typedef uint32_t ApplicationID; + + /** + * @brief RequestTracker class constructor + * @param settings Settings instance having time scale and maximum requests + * values + */ + explicit RequestTracker(const RequestControlerSettings& settings); + + /** + * @brief Tracks amount of requests per defined time considering HMI level + * Currently there is a separate restrictions can be set for NONE level. + * Other levels tracked by single constraint. + * @param app_id Unique application id + * @param level HMI level of request + * @return Success if constraints are not exceeded, otherwise - exceeded + * error code (depends on HMI level) + */ + TrackResult Track(const ApplicationID& app_id, + const mobile_apis::HMILevel::eType level); + + private: + typedef std::vector<TimevalStruct> RequestAddedAt; + typedef std::map<ApplicationID, RequestAddedAt> ApplicationsRequestsTracker; + + /** + * @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 + * @param max_requests Maximum requests number defined in configuration file + * @param tracker Container tracking applications requests amount and their + * time of addition into processing + * @return + */ + bool Track(const ApplicationID& app_id, + const uint32_t time_scale, + const uint32_t max_requests, + ApplicationsRequestsTracker& tracker); + + /** + * @brief settings_ having time scale and maximum requests values + */ + const RequestControlerSettings& settings_; + + /** + * @brief Tracker for applications requests done in NONE level + */ + ApplicationsRequestsTracker none_level_tracker_; + + /** + * @brief Tracker for applications requests done in other than NONE level + */ + ApplicationsRequestsTracker tracker_; +}; + +} // namespace request_controller +} // namespace application_manager +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_REQUEST_TRACKER_H_ |