summaryrefslogtreecommitdiff
path: root/src/components/application_manager/src/request_controller.cc
diff options
context:
space:
mode:
authorAlexandr Galiuzov <agaliuzov@luxoft.com>2015-08-31 01:46:36 +0300
committerAlexandr Galiuzov <agaliuzov@luxoft.com>2015-08-31 01:46:36 +0300
commita79769d21972f59277b7025573ebaa00e61b9778 (patch)
tree666ecab7f7d818829e4750836de5f15324d8c609 /src/components/application_manager/src/request_controller.cc
parent4c640bf11b8de4f74ce1e3a3ceb82a57de088723 (diff)
parentfeb79e262c6355a6a7d5b44e301a18bedf2d4160 (diff)
downloadsdl_core-a79769d21972f59277b7025573ebaa00e61b9778.tar.gz
Merge remote-tracking branch 'origin/release/4.0.0' into develop
Diffstat (limited to 'src/components/application_manager/src/request_controller.cc')
-rw-r--r--src/components/application_manager/src/request_controller.cc77
1 files changed, 44 insertions, 33 deletions
diff --git a/src/components/application_manager/src/request_controller.cc b/src/components/application_manager/src/request_controller.cc
index ccc4bc5873..f92615fb34 100644
--- a/src/components/application_manager/src/request_controller.cc
+++ b/src/components/application_manager/src/request_controller.cc
@@ -35,6 +35,7 @@
#include "application_manager/request_controller.h"
#include "application_manager/commands/command_request_impl.h"
#include "application_manager/commands/hmi/request_to_hmi.h"
+#include "utils/make_shared.h"
namespace application_manager {
@@ -77,7 +78,7 @@ void RequestController::InitializeThreadpool() {
void RequestController::DestroyThreadpool() {
LOG4CXX_AUTO_TRACE(logger_);
{
- AutoLock auto_lock(mobile_request_list_lock_);
+ AutoLock auto_lock(mobile_request_info_list_lock_);
pool_state_ = TPoolState::STOPPED;
LOG4CXX_DEBUG(logger_, "Broadcasting STOP signal to all threads...");
cond_var_.Broadcast(); // notify all threads we are shutting down
@@ -136,7 +137,7 @@ bool RequestController::CheckPendingRequestsAmount(
const uint32_t& pending_requests_amount) {
LOG4CXX_AUTO_TRACE(logger_);
if (pending_requests_amount > 0) {
- const size_t pending_requests_size = mobile_request_list_.size();
+ const size_t pending_requests_size = mobile_request_info_list_.size();
const bool available_to_add =
pending_requests_amount > pending_requests_size;
if (!available_to_add) {
@@ -162,10 +163,14 @@ RequestController::TResult RequestController::addMobileRequest(
<< "connection_key : " << request->connection_key());
RequestController::TResult result = CheckPosibilitytoAdd(request);
if (SUCCESS ==result) {
- AutoLock auto_lock_list(mobile_request_list_lock_);
- mobile_request_list_.push_back(request);
+ // Temporary set timeout to zero. Correct value will be set at the moment
+ // of processing start - in threadMain()
+ RequestInfoPtr request_info_ptr(utils::MakeShared<MobileRequestInfo>(request, 0u));
+ request_info_ptr->set_hmi_level(hmi_level);
+ AutoLock auto_lock_list(mobile_request_info_list_lock_);
+ mobile_request_info_list_.push_back(request_info_ptr);
LOG4CXX_DEBUG(logger_, "Waiting for execution: "
- << mobile_request_list_.size());
+ << mobile_request_info_list_.size());
// wake up one thread that is waiting for a task to be available
}
cond_var_.NotifyOne();
@@ -258,20 +263,21 @@ void RequestController::terminateWaitingForExecutionAppRequests(
const uint32_t& app_id) {
LOG4CXX_AUTO_TRACE(logger_);
LOG4CXX_DEBUG(logger_, "app_id: " << app_id
- << "Waiting for execution" << mobile_request_list_.size());
- AutoLock
- auto_lock(mobile_request_list_lock_);
- std::list<RequestPtr>::iterator request_it = mobile_request_list_.begin();
- while (mobile_request_list_.end() != request_it) {
- RequestPtr request = (*request_it);
- if ((request.valid()) && (request->connection_key() == app_id)) {
- mobile_request_list_.erase(request_it++);
+ << "Waiting for execution" << mobile_request_info_list_.size());
+ AutoLock auto_lock(mobile_request_info_list_lock_);
+ std::list<RequestInfoPtr>::iterator request_it =
+ mobile_request_info_list_.begin();
+ while (mobile_request_info_list_.end() != request_it) {
+ RequestInfoPtr request_info = (*request_it);
+ if ((request_info.valid()) &&
+ (request_info->request()->connection_key() == app_id)) {
+ mobile_request_info_list_.erase(request_it++);
} else {
++request_it;
}
}
LOG4CXX_DEBUG(logger_, "Waiting for execution "
- << mobile_request_list_.size());
+ << mobile_request_info_list_.size());
}
void RequestController::terminateWaitingForResponseAppRequests(
@@ -287,7 +293,7 @@ void RequestController::terminateAppRequests(
LOG4CXX_AUTO_TRACE(logger_);
LOG4CXX_DEBUG(logger_, "app_id : " << app_id
<< "Requests waiting for execution count : "
- << mobile_request_list_.size()
+ << mobile_request_info_list_.size()
<< "Requests waiting for response count : "
<< waiting_for_response_.Size());
@@ -305,8 +311,8 @@ void RequestController::terminateAllMobileRequests() {
LOG4CXX_AUTO_TRACE(logger_);
waiting_for_response_.RemoveMobileRequests();
LOG4CXX_DEBUG(logger_, "Mobile Requests waiting for response cleared");
- AutoLock waiting_execution_auto_lock(mobile_request_list_lock_);
- mobile_request_list_.clear();
+ AutoLock waiting_execution_auto_lock(mobile_request_info_list_lock_);
+ mobile_request_info_list_.clear();
LOG4CXX_DEBUG(logger_, "Mobile Requests waiting for execution cleared");
UpdateTimer();
}
@@ -411,10 +417,10 @@ void RequestController::Worker::threadMain() {
AutoLock auto_lock(thread_lock_);
while (!stop_flag_) {
// Try to pick a request
- AutoLock auto_lock(request_controller_->mobile_request_list_lock_);
+ AutoLock auto_lock(request_controller_->mobile_request_info_list_lock_);
while ((request_controller_->pool_state_ != TPoolState::STOPPED) &&
- (request_controller_->mobile_request_list_.empty())) {
+ (request_controller_->mobile_request_info_list_.empty())) {
// Wait until there is a task in the queue
// Unlock mutex while wait, then lock it back when signaled
LOG4CXX_INFO(logger_, "Unlocking and waiting");
@@ -427,37 +433,42 @@ void RequestController::Worker::threadMain() {
break;
}
- if (request_controller_->mobile_request_list_.empty()) {
+ if (request_controller_->mobile_request_info_list_.empty()) {
LOG4CXX_WARN(logger_, "Mobile request list is empty");
break;
}
- RequestPtr request(request_controller_->mobile_request_list_.front());
- request_controller_->mobile_request_list_.pop_front();
- bool init_res = request->Init(); // to setup specific default timeout
+ RequestInfoPtr request_info_ptr(
+ request_controller_->mobile_request_info_list_.front());
+ request_controller_->mobile_request_info_list_.pop_front();
+ bool init_res = request_info_ptr->request()->Init(); // to setup specific
+ // default timeout
const uint32_t timeout_in_seconds =
- request->default_timeout() / date_time::DateTime::MILLISECONDS_IN_SECOND;
- RequestInfoPtr request_info_ptr(new MobileRequestInfo(request,
- timeout_in_seconds));
+ request_info_ptr->request()->default_timeout() /
+ date_time::DateTime::MILLISECONDS_IN_SECOND;
+ // Start time, end time and timeout need to be updated to appropriate values
+ request_info_ptr->update_start_time(date_time::DateTime::getCurrentTime());
+ request_info_ptr->updateTimeOut(timeout_in_seconds);
request_controller_->waiting_for_response_.Add(request_info_ptr);
if (0 != timeout_in_seconds) {
- LOG4CXX_INFO(logger_, "Execute MobileRequest corr_id = "
- << request_info_ptr->requestId() <<
- " with timeout: " << timeout_in_seconds);
request_controller_->UpdateTimer();
} else {
- LOG4CXX_INFO(logger_, "Default timeout was set to 0."
- "RequestController will not track timeout of this request.");
+ LOG4CXX_DEBUG(logger_, "Default timeout was set to 0. "
+ "RequestController will not track timeout "
+ "of this request.");
}
AutoUnlock unlock(auto_lock);
// execute
if ((false == request_controller_->IsLowVoltage()) &&
- request->CheckPermissions() && init_res) {
- request->Run();
+ request_info_ptr->request()->CheckPermissions() && init_res) {
+ LOG4CXX_DEBUG(logger_, "Execute MobileRequest corr_id = "
+ << request_info_ptr->requestId()
+ << " with timeout: " << timeout_in_seconds);
+ request_info_ptr->request()->Run();
}
}
}