1 // Copyright (c) 2021 - 2022 Samsung Electronics Co., Ltd All Rights Reserved
2 // Use of this source code is governed by an apache-2.0 license that can be
3 // found in the LICENSE file.
5 #include "create_cache_request_handler.hh"
7 #include <sys/resource.h>
11 #include "cache_db_handler.hh"
12 #include "utils/logging.hh"
14 namespace psd = pkgmgr_server::database;
16 namespace pkgmgr_server {
17 namespace request_handler {
19 CreateCacheRequestHandler::Scheduler::Scheduler(pid_t tid)
20 : tid_(tid), priority_(0) {
21 if (Get(&priority_) != 0)
25 void CreateCacheRequestHandler::Scheduler::ChangePriority() {
30 if (Get(&priority) == 0)
31 LOG(WARNING) << "Current priority: " << priority;
34 void CreateCacheRequestHandler::Scheduler::ResetPriority() {
35 if (Set(priority_) != 0)
39 if (Get(&priority) == 0)
40 LOG(WARNING) << "Current priority: " << priority;
43 int CreateCacheRequestHandler::Scheduler::Get(int* priority) {
45 *priority = getpriority(PRIO_PROCESS, 0);
47 LOG(ERROR) << "getpriority() is failed. errno: " << errno;
54 int CreateCacheRequestHandler::Scheduler::Set(int priority) {
55 if (setpriority(PRIO_PROCESS, 0, priority) != 0) {
56 LOG(ERROR) << "setpriority() is failed. , errno: " << errno;
60 LOG(WARNING) << "priority: " << priority;
64 CreateCacheRequestHandler::CreateCacheRequestHandler(): scheduler_(gettid()) {
67 bool CreateCacheRequestHandler::HandleRequest(const unsigned char* data, int size,
68 const std::string& locale) {
69 psd::CacheDBHandler db(GetUID(), GetPID());
72 success_ = (db.Execute() == PMINFO_R_OK);
76 std::vector<uint8_t> CreateCacheRequestHandler::ExtractResult() {
77 return { static_cast<uint8_t>(success_) };
80 void CreateCacheRequestHandler::PreExec() {
81 scheduler_.ChangePriority();
84 void CreateCacheRequestHandler::PostExec() {
85 scheduler_.ResetPriority();
88 } // namespace request_handler
89 } // namespace pkgmgr_server