-// Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+// Copyright (c) 2021 - 2022 Samsung Electronics Co., Ltd All Rights Reserved
// Use of this source code is governed by an apache-2.0 license that can be
// found in the LICENSE file.
#include "create_cache_request_handler.hh"
+#include <sys/resource.h>
+
#include <string>
#include "cache_db_handler.hh"
+#include "utils/logging.hh"
namespace psd = pkgmgr_server::database;
namespace pkgmgr_server {
namespace request_handler {
-bool CreateCacheRequestHandler::HandleRequest(unsigned char* data, int size,
- const std::string& locale) {
+CreateCacheRequestHandler::Scheduler::Scheduler(pid_t tid)
+ : tid_(tid), priority_(0) {
+ if (Get(&priority_) != 0)
+ priority_ = 0;
+}
+
+void CreateCacheRequestHandler::Scheduler::ChangePriority() {
+ if (Set(-10) != 0)
+ return;
+
+ int priority = 0;
+ if (Get(&priority) == 0)
+ LOG(WARNING) << "Current priority: " << priority;
+}
+
+void CreateCacheRequestHandler::Scheduler::ResetPriority() {
+ if (Set(priority_) != 0)
+ return;
+
+ int priority = 0;
+ if (Get(&priority) == 0)
+ LOG(WARNING) << "Current priority: " << priority;
+}
+
+int CreateCacheRequestHandler::Scheduler::Get(int* priority) {
+ errno = 0;
+ *priority = getpriority(PRIO_PROCESS, 0);
+ if (errno != 0) {
+ LOG(ERROR) << "getpriority() is failed. errno: " << errno;
+ return -1;
+ }
+
+ return 0;
+}
+
+int CreateCacheRequestHandler::Scheduler::Set(int priority) {
+ if (setpriority(PRIO_PROCESS, 0, priority) != 0) {
+ LOG(ERROR) << "setpriority() is failed. , errno: " << errno;
+ return -1;
+ }
+
+ LOG(WARNING) << "priority: " << priority;
+ return 0;
+}
+
+CreateCacheRequestHandler::CreateCacheRequestHandler(): scheduler_(gettid()) {
+}
+
+bool CreateCacheRequestHandler::HandleRequest(unsigned char* data, size_t size,
+ const std::string& locale) {
psd::CacheDBHandler db(GetUID(), GetPID());
db.SetLocale(locale);
- int ret = db.Execute();
+ success_ = (db.Execute() == PMINFO_R_OK);
+ return success_;
+}
+
+tizen_base::Parcel CreateCacheRequestHandler::ExtractResult() {
+ tizen_base::Parcel parcel;
+ parcel.WriteBool(success_);
+ return parcel;
+}
- return ret == PMINFO_R_OK;
+void CreateCacheRequestHandler::PreExec() {
+ scheduler_.ChangePriority();
}
-std::vector<uint8_t> CreateCacheRequestHandler::ExtractResult() {
- return {};
+void CreateCacheRequestHandler::PostExec() {
+ scheduler_.ResetPriority();
}
} // namespace request_handler