#include "lib/request/pending_item.hh"
#include <aul_cmd.h>
+
#include <ctime>
+#include <utility>
#include "lib/amd_socket.h"
#include "lib/amd_util.h"
}
bool PendingItem::AddRequestSimple(RequestPtr req) {
- timespec end{};
- clock_gettime(CLOCK_MONOTONIC, &end);
- auto interval = GetPendingInterval(req->GetStartTime(), end);
- req->SetTimer(interval);
+ req->SetTimer();
- _D("request(%s[%d]:%d:%u) is added on pending list",
+ _W("request(%s[%d]:%d:%u:%d) is added on pending list",
aul_cmd_convert_to_string(req->GetCmd()),
- req->GetCmd(), req->GetPID(), req->GetTargetUID());
+ req->GetCmd(), req->GetPID(), req->GetTargetUID(), req->GetID());
requests_.push_back(std::move(req));
return true;
req->SetTargetPID(getpid());
if (req->GetUID() >= REGULAR_UID_MIN || req->IsIndirectRequest()) {
- timespec end{};
- clock_gettime(CLOCK_MONOTONIC, &end);
- auto interval = GetPendingInterval(req->GetStartTime(), end);
- req->SetTimer(interval);
+ req->SetTimer();
} else {
req->SendResult(0);
req->SetTimer(kSystemRequestTimeout);
return requests_.empty() && reply_infos_.empty();
}
+bool PendingItem::Contains(unsigned int req_id) const {
+ return std::find_if(std::begin(requests_), std::end(requests_),
+ [req_id](const auto& request) -> bool {
+ return request->GetID() == static_cast<int>(req_id & INT_MAX);
+ }) != std::end(requests_);
+}
+
bool PendingItem::AddReplyInfo(ReplyInfoPtr info) {
reply_infos_.push_back(std::move(info));
return true;
bool RemoveReplyInfo(const ReplyInfoPtr& info);
void Flush();
bool IsEmpty() const;
+ bool Contains(unsigned int req_id) const;
std::list<std::shared_ptr<Request>>& GetRequests();
std::list<std::shared_ptr<ReplyInfo>>& GetReplyInfos();
return start_;
}
+void Request::SetTimer() {
+ timespec end{};
+ clock_gettime(CLOCK_MONOTONIC, &end);
+ auto interval = GetPendingIntervalWithTimeout(GetStartTime(), end,
+ GetTimeout());
+ SetTimer(interval);
+}
+
void Request::SetTimer(unsigned int timeout) {
if (timer_ != 0) {
_W("Already registered timeout event");
unsigned char* GetRaw() const;
const std::shared_ptr<tizen_base::Bundle>& GetBundle() const;
void SetBundle(std::shared_ptr<tizen_base::Bundle> b);
+ void SetTimer();
void SetTimer(unsigned int timeout);
void UnsetTimer();
void SetCritical();
return nullptr;
}
+std::shared_ptr<PendingItem> RequestManager::FindPendingItem(
+ unsigned int req_id) {
+ for (const auto& iter : pending_items_) {
+ auto& item = iter.second;
+ if (item->Contains(req_id))
+ return item;
+ }
+
+ return nullptr;
+}
+
std::shared_ptr<PendingItem> RequestManager::CreatePendingItem(
unsigned int req_id, const std::string& appid, pid_t caller_pid,
pid_t pid) {
if (request == nullptr)
return;
+ _E("Timed out. request(%s[%d]:%d:%u:%d)",
+ aul_cmd_convert_to_string(request->GetCmd()),
+ request->GetCmd(), request->GetPID(), request->GetTargetUID(),
+ request->GetID());
+
auto req = request->GetSharedPtr();
- auto pending_item = FindPendingItem(req->GetTargetPID());
+ auto pending_item = FindPendingItem(static_cast<unsigned int>(req->GetID()));
if (pending_item != nullptr) {
pending_item->RemoveRequest(req);
if (pending_item->IsEmpty())
_W("%s is waiting to be started. request_id: %u",
appid.c_str(), app_status ? app_status->GetRequestID() : 0);
req->SetCritical();
- req->SetTimer(kPendingRequestTimeout);
+ req->SetTimer();
}
}
const ucred& cr);
std::shared_ptr<PendingItem> GetPendingItem(const RequestPtr& req,
const std::string& appid);
+ std::shared_ptr<PendingItem> FindPendingItem(unsigned int req_id);
static gboolean ProcessRequest(gpointer data);
static void DispatchRequest(const RequestPtr& req);