/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2021 - 2022 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
}
bool CreateCacheRequest::SendData(unsigned char* data, int size) {
+ bool ret = static_cast<bool>(data[0]);
+ if (listener_ != nullptr)
+ listener_->OnCreateCacheDone(ret);
+
return true;
}
/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2021 - 2022 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
class EXPORT_API CreateCacheRequest : public PkgRequest {
public:
- CreateCacheRequest(uid_t uid) : uid_(uid) {}
+ class IEvent {
+ public:
+ virtual ~IEvent() {}
+ virtual void OnCreateCacheDone(bool success) = 0;
+ };
+
+ CreateCacheRequest(uid_t uid, IEvent* listener)
+ : uid_(uid), listener_(listener) {}
const unsigned char* GetData() override;
int GetSize() override;
pid_t GetSenderPID() override;
private:
uid_t uid_;
+ IEvent* listener_;
};
} // namespace pkgmgr_server
/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2021 - 2022 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* limitations under the License.
*/
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/signalfd.h>
-#include <signal.h>
#include <gio/gio.h>
#include <glib-unix.h>
+#include <signal.h>
+#include <sys/signalfd.h>
+#include <sys/stat.h>
+#include <sys/types.h>
#include <systemd/sd-daemon.h>
+#include <unistd.h>
#include <glib.h>
#include <dlog.h>
static void __pkgmgr_init() {
runner = new pkgmgr_server::Runner(5);
-
- g_idle_add([](gpointer data) -> gboolean {
- int fd = creat("/run/.pkginfo_server_ready",
- S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
- if (fd != -1)
- close(fd);
-
- sd_notify(0, "READY=1");
- return G_SOURCE_REMOVE;
- }, nullptr);
+ sd_notify(0, "READY=1");
}
int main() {
-// 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.
psd::CacheDBHandler db(GetUID(), GetPID());
db.SetLocale(locale);
- int ret = db.Execute();
-
- return ret == PMINFO_R_OK;
+ success_ = (db.Execute() == PMINFO_R_OK);
+ return success_;
}
std::vector<uint8_t> CreateCacheRequestHandler::ExtractResult() {
- return {};
+ return { static_cast<uint8_t>(success_) };
}
void CreateCacheRequestHandler::PreExec() {
-// 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.
};
private:
+ bool success_ = false;
std::shared_ptr<pkgmgr_common::parcel::ResultParcelable> result_;
Scheduler scheduler_;
};
/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2021 - 2022 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
thread_pool_->SetLocale(pkgmgr_common::SystemLocale::GetInst().Get());
if (CacheFlag::SetPreparing())
- QueueRequest(std::make_shared<CreateCacheRequest>(default_uid_));
+ QueueRequest(std::make_shared<CreateCacheRequest>(default_uid_, this));
LOGI("Start Runner");
}
if (CacheFlag::SetPreparing()) {
runner->QueueRequest(
- std::make_shared<CreateCacheRequest>(runner->default_uid_));
+ std::make_shared<CreateCacheRequest>(runner->default_uid_, runner));
}
runner->QueueRequest(std::move(req));
return true;
}
+void Runner::OnCreateCacheDone(bool success) {
+ static bool ready = false;
+ if (success && !ready) {
+ ready = true;
+ LOG(WARNING) << "pkginfo-server is ready";
+ g_idle_add(
+ [](gpointer data) -> gboolean {
+ int fd = creat("/run/.pkginfo_server_ready",
+ S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+ if (fd != -1)
+ close(fd);
+
+ return G_SOURCE_REMOVE;
+ },
+ nullptr);
+ }
+}
+
void Runner::SetCPUInheritance() {
int ret;
resource_pid_t resource_st = { 0, };
/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2021 - 2022 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <memory>
#include <unordered_map>
+#include "create_cache_request.hh"
#include "server_socket.hh"
-#include "worker_thread.hh"
#include "system_locale.hh"
+#include "worker_thread.hh"
namespace pkgmgr_server {
#define EXPORT_API __attribute__((visibility("default")))
#endif
-class EXPORT_API Runner
- : public pkgmgr_common::SystemLocale::IEvent {
+class EXPORT_API Runner : public pkgmgr_common::SystemLocale::IEvent,
+ public CreateCacheRequest::IEvent {
public:
- Runner(unsigned int thread_num);
+ explicit Runner(unsigned int thread_num);
~Runner();
bool QueueRequest(std::shared_ptr<PkgRequest> req);
void OnChanged(const std::string& locale) override;
+ void OnCreateCacheDone(bool success) override;
private:
static int OnReceiveRequest(int fd, GIOCondition cond, void* user_data);