summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpjh9216 <jh9216.park@samsung.com>2024-09-30 10:11:57 +0900
committerpjh9216 <jh9216.park@samsung.com>2024-09-30 10:19:19 +0900
commitfca0e03509b51b5c162eea71a5d9aa9cf8975b94 (patch)
treed5d26b3f6818a3a9e6d0084fb420da381040a657
parent5967f8c5ef17e244d540ca1cfba761528389f482 (diff)
downloadslp-pkgmgr-fca0e03509b51b5c162eea71a5d9aa9cf8975b94.tar.gz
slp-pkgmgr-fca0e03509b51b5c162eea71a5d9aa9cf8975b94.tar.bz2
slp-pkgmgr-fca0e03509b51b5c162eea71a5d9aa9cf8975b94.zip
Remove app-event dependency
Change-Id: Iba9d74f8b04001a70941407093d75f0910e7d244 Signed-off-by: pjh9216 <jh9216.park@samsung.com>
-rw-r--r--CMakeLists.txt3
-rw-r--r--client/CMakeLists.txt1
-rw-r--r--client/src/PkgSignal.cc556
-rw-r--r--client/src/PkgSignal.h190
-rw-r--r--installer/CMakeLists.txt1
-rw-r--r--installer/src/PkgSignal.cc556
-rw-r--r--installer/src/PkgSignal.h190
-rw-r--r--packaging/pkgmgr.spec4
-rw-r--r--test/unit_tests/CMakeLists.txt2
-rw-r--r--test/unit_tests/mock/app_event_mock.cc37
-rw-r--r--test/unit_tests/mock/app_event_mock.hh36
-rw-r--r--test/unit_tests/test_client.cc2
12 files changed, 1495 insertions, 83 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2cbea2f..b4f02c2 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -24,7 +24,6 @@ PKG_CHECK_MODULES(GMOCK_DEPS REQUIRED gmock)
PKG_CHECK_MODULES(GLIB_DEPS REQUIRED glib-2.0)
PKG_CHECK_MODULES(GIO_DEPS REQUIRED gio-2.0)
PKG_CHECK_MODULES(RPC_PORT_DEPS REQUIRED rpc-port)
-PKG_CHECK_MODULES(CAPI_APPFW_EVENT_DEPS REQUIRED capi-appfw-event)
PKG_CHECK_MODULES(PKGMGR_PARSER_DEPS REQUIRED pkgmgr-parser)
PKG_CHECK_MODULES(PKGMGR_INFO_DEPS REQUIRED pkgmgr-info)
PKG_CHECK_MODULES(INIPARSER_DEPS REQUIRED iniparser)
@@ -32,6 +31,8 @@ PKG_CHECK_MODULES(XDGMIME_DEPS REQUIRED xdgmime)
PKG_CHECK_MODULES(PLATFORM_CONFIG_DEPS REQUIRED libtzplatform-config)
PKG_CHECK_MODULES(MINIZIP_DEPS REQUIRED minizip)
+ADD_DEFINITIONS("-DLIBDIR=\"${LIBDIR}\"")
+
ADD_SUBDIRECTORY(installer)
ADD_SUBDIRECTORY(client)
ADD_SUBDIRECTORY(types)
diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt
index fe06c79..e97eb4f 100644
--- a/client/CMakeLists.txt
+++ b/client/CMakeLists.txt
@@ -21,7 +21,6 @@ APPLY_PKG_CONFIG(${PKGMGR_CLIENT} PUBLIC
PLATFORM_CONFIG_DEPS
MINIZIP_DEPS
RPC_PORT_DEPS
- CAPI_APPFW_EVENT_DEPS
)
TARGET_LINK_LIBRARIES(${PKGMGR_CLIENT} PUBLIC "dl")
diff --git a/client/src/PkgSignal.cc b/client/src/PkgSignal.cc
new file mode 100644
index 0000000..dc28b37
--- /dev/null
+++ b/client/src/PkgSignal.cc
@@ -0,0 +1,556 @@
+/*
+ * Generated by tidlc 2.2.4.
+ */
+
+#include "PkgSignal.h"
+
+#include <assert.h>
+#include <dlfcn.h>
+#include <dlog.h>
+#include <stdlib.h>
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "RPC_PORT_GROUP"
+
+#ifdef _E
+#undef _E
+#endif
+
+#ifdef _W
+#undef _W
+#endif
+
+#ifdef _I
+#undef _I
+#endif
+
+#ifdef _D
+#undef _D
+#endif
+
+#define _E(fmt, ...) \
+ dlog_print(DLOG_ERROR, LOG_TAG, "%s: %s(%d) > " fmt, \
+ basename(const_cast<char*>(__FILE__)), __FUNCTION__, __LINE__, \
+ ##__VA_ARGS__)
+#define _W(fmt, ...) \
+ dlog_print(DLOG_WARN, LOG_TAG, "%s: %s(%d) > " fmt, \
+ basename(const_cast<char*>(__FILE__)), __FUNCTION__, __LINE__, \
+ ##__VA_ARGS__)
+#define _I(fmt, ...) \
+ dlog_print(DLOG_INFO, LOG_TAG, "%s: %s(%d) > " fmt, \
+ basename(const_cast<char*>(__FILE__)), __FUNCTION__, __LINE__, \
+ ##__VA_ARGS__)
+#define _D(fmt, ...) \
+ dlog_print(DLOG_DEBUG, LOG_TAG, "%s: %s(%d) > " fmt, \
+ basename(const_cast<char*>(__FILE__)), __FUNCTION__, __LINE__, \
+ ##__VA_ARGS__)
+
+#ifndef TIDL_VERSION
+#define TIDL_VERSION "2.2.4"
+#endif
+
+namespace {
+
+using event_handler_h = void*;
+using event_cb = void (*)(const char*, bundle*, void*);
+
+#ifndef UNIT_TEST
+
+constexpr const char kPathLibAppEventCore[] =
+ LIBDIR "/libcapi-appfw-event.so.0";
+
+using event_add_event_handler_t = int (*)(const char*, event_cb, void*,
+ event_handler_h*);
+using event_remove_event_handler_t = int (*)(event_handler_h);
+using event_publish_app_event_t = int (*)(const char*, bundle*);
+
+event_add_event_handler_t event_add_event_handler = nullptr;
+event_remove_event_handler_t event_remove_event_handler = nullptr;
+event_publish_app_event_t event_publish_app_event = nullptr;
+
+class AppEvent {
+ public:
+ AppEvent() {
+ handle_ = dlopen(kPathLibAppEventCore, RTLD_LAZY | RTLD_GLOBAL);
+ if (handle_ == nullptr) {
+ _E("dlopen() is failed. error(%s)", dlerror());
+ return;
+ }
+
+ std::string symbol = "event_add_event_handler";
+ event_add_event_handler = reinterpret_cast<event_add_event_handler_t>(
+ dlsym(handle_, symbol.c_str()));
+ if (event_add_event_handler == nullptr) {
+ _E("Failed to find symbol(%s)", symbol.c_str());
+ return;
+ }
+
+ symbol = "event_remove_event_handler";
+ event_remove_event_handler = reinterpret_cast<event_remove_event_handler_t>(
+ dlsym(handle_, symbol.c_str()));
+ if (event_remove_event_handler == nullptr) {
+ _E("Failed to find symbol(%s)", symbol.c_str());
+ return;
+ }
+
+ symbol = "event_publish_app_event";
+ event_publish_app_event = reinterpret_cast<event_publish_app_event_t>(
+ dlsym(handle_, symbol.c_str()));
+ if (event_publish_app_event == nullptr) {
+ _E("Failed to find symbol(%s)", symbol.c_str());
+ return;
+ }
+
+ loaded_ = true;
+ }
+
+ ~AppEvent() {
+ if (handle_) dlclose(handle_);
+ }
+
+ bool IsLoaded() { return loaded_; }
+
+ private:
+ bool loaded_ = false;
+ void* handle_ = nullptr;
+};
+
+static AppEvent app_event;
+
+#else
+
+extern "C" int event_add_event_handler(const char *event_name,
+ event_cb callback, void *user_data, event_handler_h *event_handler) {
+ return 0;
+}
+
+extern "C" int event_remove_event_handler(event_handler_h event_handler) {
+ return 0;
+}
+
+extern "C" int event_publish_app_event(const char *event_name,
+ bundle *event_data) {
+ return 0;
+}
+
+#endif
+
+} // namespace
+
+namespace rpc_port {
+namespace PkgSignal {
+
+PkgInfo::PkgInfo() {}
+
+PkgInfo::PkgInfo(std::string Pkgid, std::string Appid, std::string PkgType)
+ : Pkgid_(std::move(Pkgid)),
+ Appid_(std::move(Appid)),
+ PkgType_(std::move(PkgType)) {}
+
+PathInfo::PathInfo() {}
+
+PathInfo::PathInfo(std::string Path, int State)
+ : Path_(std::move(Path)), State_(std::move(State)) {}
+
+ExtraData::ExtraData() {}
+
+ExtraData::ExtraData(int ErrCode, std::vector<PathInfo> Paths)
+ : ErrCode_(std::move(ErrCode)), Paths_(std::move(Paths)) {}
+
+namespace group {
+
+rpc_port_parcel_h operator<<(rpc_port_parcel_h h, const PkgInfo& param);
+
+rpc_port_parcel_h operator>>(rpc_port_parcel_h h, PkgInfo& param);
+
+rpc_port_parcel_h operator<<(rpc_port_parcel_h h, const PathInfo& param);
+
+rpc_port_parcel_h operator>>(rpc_port_parcel_h h, PathInfo& param);
+
+rpc_port_parcel_h operator<<(rpc_port_parcel_h h, const ExtraData& param);
+
+rpc_port_parcel_h operator>>(rpc_port_parcel_h h, ExtraData& param);
+
+rpc_port_parcel_h operator<<(rpc_port_parcel_h h,
+ const std::vector<PathInfo>& param);
+
+rpc_port_parcel_h operator>>(rpc_port_parcel_h h, std::vector<PathInfo>& param);
+
+rpc_port_parcel_h operator<<(rpc_port_parcel_h h,
+ const std::vector<PkgInfo>& param);
+
+rpc_port_parcel_h operator>>(rpc_port_parcel_h h, std::vector<PkgInfo>& param);
+
+rpc_port_parcel_h operator<<(rpc_port_parcel_h h, const PkgInfo& param) {
+ rpc_port_parcel_write_string(h, param.GetPkgid().c_str());
+ rpc_port_parcel_write_string(h, param.GetAppid().c_str());
+ rpc_port_parcel_write_string(h, param.GetPkgType().c_str());
+ return h;
+}
+
+rpc_port_parcel_h operator<<(rpc_port_parcel_h h, const PathInfo& param) {
+ rpc_port_parcel_write_string(h, param.GetPath().c_str());
+ rpc_port_parcel_write_int32(h, param.GetState());
+ return h;
+}
+
+rpc_port_parcel_h operator<<(rpc_port_parcel_h h, const ExtraData& param) {
+ rpc_port_parcel_write_int32(h, param.GetErrCode());
+ h << param.GetPaths();
+ return h;
+}
+
+rpc_port_parcel_h operator>>(rpc_port_parcel_h h, PkgInfo& param) {
+ char* Pkgid_raw = nullptr;
+ rpc_port_parcel_read_string(h, &Pkgid_raw);
+ std::string Pkgid(Pkgid_raw);
+ free(Pkgid_raw);
+ param.SetPkgid(std::move(Pkgid));
+
+ char* Appid_raw = nullptr;
+ rpc_port_parcel_read_string(h, &Appid_raw);
+ std::string Appid(Appid_raw);
+ free(Appid_raw);
+ param.SetAppid(std::move(Appid));
+
+ char* PkgType_raw = nullptr;
+ rpc_port_parcel_read_string(h, &PkgType_raw);
+ std::string PkgType(PkgType_raw);
+ free(PkgType_raw);
+ param.SetPkgType(std::move(PkgType));
+
+ return h;
+}
+
+rpc_port_parcel_h operator>>(rpc_port_parcel_h h, PathInfo& param) {
+ char* Path_raw = nullptr;
+ rpc_port_parcel_read_string(h, &Path_raw);
+ std::string Path(Path_raw);
+ free(Path_raw);
+ param.SetPath(std::move(Path));
+
+ int State;
+ rpc_port_parcel_read_int32(h, &State);
+ param.SetState(State);
+
+ return h;
+}
+
+rpc_port_parcel_h operator>>(rpc_port_parcel_h h, ExtraData& param) {
+ int ErrCode;
+ rpc_port_parcel_read_int32(h, &ErrCode);
+ param.SetErrCode(ErrCode);
+
+ std::vector<PathInfo> Paths;
+ h >> Paths;
+ param.SetPaths(std::move(Paths));
+
+ return h;
+}
+
+rpc_port_parcel_h operator<<(rpc_port_parcel_h h,
+ const std::vector<PathInfo>& param) {
+ rpc_port_parcel_write_array_count(h, param.size());
+ for (const auto& i : param) {
+ h << i;
+ }
+
+ return h;
+}
+
+rpc_port_parcel_h operator>>(rpc_port_parcel_h h,
+ std::vector<PathInfo>& param) {
+ int l = 0;
+ rpc_port_parcel_read_array_count(h, &l);
+
+ for (int i = 0; i < l; i++) {
+ PathInfo v;
+ h >> v;
+
+ param.push_back(std::move(v));
+ }
+
+ return h;
+}
+
+rpc_port_parcel_h operator<<(rpc_port_parcel_h h,
+ const std::vector<PkgInfo>& param) {
+ rpc_port_parcel_write_array_count(h, param.size());
+ for (const auto& i : param) {
+ h << i;
+ }
+
+ return h;
+}
+
+rpc_port_parcel_h operator>>(rpc_port_parcel_h h, std::vector<PkgInfo>& param) {
+ int l = 0;
+ rpc_port_parcel_read_array_count(h, &l);
+
+ for (int i = 0; i < l; i++) {
+ PkgInfo v;
+ h >> v;
+
+ param.push_back(std::move(v));
+ }
+
+ return h;
+}
+
+PkgSignal::PkgSignal(std::string sender_appid, bool is_system)
+ : sender_appid_(std::move(sender_appid)), is_system_(is_system) {
+ Subscribe();
+}
+
+PkgSignal::~PkgSignal() { Unsubscribe(); }
+
+void PkgSignal::Subscribe() {
+ std::lock_guard<std::recursive_mutex> lock(mutex_);
+ int ret = event_add_event_handler(GetEventName().c_str(), EventCb, this,
+ &event_handler_);
+ if (ret != 0) {
+ throw InvalidIOException();
+ }
+}
+
+void PkgSignal::Unsubscribe() {
+ std::lock_guard<std::recursive_mutex> lock(mutex_);
+ if (event_handler_) {
+ event_remove_event_handler(event_handler_);
+ event_handler_ = nullptr;
+ }
+}
+
+bundle* PkgSignal::GetBundleFromParcel(rpc_port_parcel_h p, bundle* b) {
+ void* raw = nullptr;
+ unsigned int size = 0;
+
+ int ret = rpc_port_parcel_get_raw(p, &raw, &size);
+ if (ret != RPC_PORT_ERROR_NONE) return nullptr;
+
+ ret = bundle_add_byte(b, "TIDL_RAW", raw, size);
+ if (ret != BUNDLE_ERROR_NONE) return nullptr;
+
+ return b;
+}
+
+rpc_port_parcel_h PkgSignal::GetParcelFromBundle(bundle* b) {
+ void* raw = nullptr;
+ size_t size = 0;
+ rpc_port_parcel_h p;
+
+ int ret = bundle_get_byte(b, "TIDL_RAW", &raw, &size);
+ if (ret != BUNDLE_ERROR_NONE) return nullptr;
+
+ ret =
+ rpc_port_parcel_create_from_raw(&p, raw, static_cast<unsigned int>(size));
+ if (ret != RPC_PORT_ERROR_NONE) return nullptr;
+
+ return p;
+}
+
+std::string PkgSignal::GetEventName() {
+ if (is_system_) return "tizen.system.event.tidl_iface_PkgSignal";
+ return "event." + sender_appid_ + ".tidl_iface_PkgSignal";
+}
+
+void PkgSignal::EventCb(const char* event_name, bundle* event_data,
+ void* user_data) {
+ auto* ptr = static_cast<PkgSignal*>(user_data);
+ rpc_port_parcel_h p = ptr->GetParcelFromBundle(event_data);
+ if (p == nullptr) {
+ _E("Invalid bundle");
+ return;
+ }
+
+ std::unique_ptr<std::remove_pointer<rpc_port_parcel_h>::type,
+ decltype(rpc_port_parcel_destroy)*>
+ p_auto(p, rpc_port_parcel_destroy);
+
+ rpc_port_parcel_h header;
+ int seq_num = -1;
+ int cmd;
+ rpc_port_parcel_get_header(p, &header);
+ rpc_port_parcel_header_get_seq_num(header, &seq_num);
+
+ rpc_port_parcel_read_int32(p, &cmd);
+ switch (cmd) {
+ case static_cast<int>(MethodId::AsyncResult): {
+ char* param1_raw = nullptr;
+ rpc_port_parcel_read_string(p, &param1_raw);
+ std::string param1(param1_raw);
+ free(param1_raw);
+ int param2;
+ rpc_port_parcel_read_int32(p, &param2);
+ char* param3_raw = nullptr;
+ rpc_port_parcel_read_string(p, &param3_raw);
+ std::string param3(param3_raw);
+ free(param3_raw);
+ std::vector<PkgInfo> param4;
+ p >> param4;
+ char* param5_raw = nullptr;
+ rpc_port_parcel_read_string(p, &param5_raw);
+ std::string param5(param5_raw);
+ free(param5_raw);
+ char* param6_raw = nullptr;
+ rpc_port_parcel_read_string(p, &param6_raw);
+ std::string param6(param6_raw);
+ free(param6_raw);
+ ptr->OnAsyncResult(param1, param2, param3, param4, param5, param6);
+
+ } break;
+
+ case static_cast<int>(MethodId::AsyncResultForResource): {
+ char* param1_raw = nullptr;
+ rpc_port_parcel_read_string(p, &param1_raw);
+ std::string param1(param1_raw);
+ free(param1_raw);
+ int param2;
+ rpc_port_parcel_read_int32(p, &param2);
+ char* param3_raw = nullptr;
+ rpc_port_parcel_read_string(p, &param3_raw);
+ std::string param3(param3_raw);
+ free(param3_raw);
+ char* param4_raw = nullptr;
+ rpc_port_parcel_read_string(p, &param4_raw);
+ std::string param4(param4_raw);
+ free(param4_raw);
+ char* param5_raw = nullptr;
+ rpc_port_parcel_read_string(p, &param5_raw);
+ std::string param5(param5_raw);
+ free(param5_raw);
+ ExtraData param6;
+ p >> param6;
+ ptr->OnAsyncResultForResource(param1, param2, param3, param4, param5,
+ param6);
+
+ } break;
+
+ case static_cast<int>(MethodId::AsyncResultForPkgUpgrade): {
+ char* param1_raw = nullptr;
+ rpc_port_parcel_read_string(p, &param1_raw);
+ std::string param1(param1_raw);
+ free(param1_raw);
+ int param2;
+ rpc_port_parcel_read_int32(p, &param2);
+ ptr->OnAsyncResultForPkgUpgrade(param1, param2);
+
+ } break;
+
+ default:
+ _E("Unknown command(%d)", cmd);
+ }
+}
+
+void PkgSignal::AsyncResult(std::string signal, int targetUid,
+ std::string reqId, std::vector<PkgInfo> pkgs,
+ std::string key, std::string val) {
+ rpc_port_parcel_h p;
+ rpc_port_parcel_create(&p);
+ std::unique_ptr<std::remove_pointer<rpc_port_parcel_h>::type,
+ decltype(rpc_port_parcel_destroy)*>
+ p_auto(p, rpc_port_parcel_destroy);
+ rpc_port_parcel_header_h header_;
+ rpc_port_parcel_get_header(p, &header_);
+ rpc_port_parcel_header_set_tag(header_, TIDL_VERSION);
+ int seq_num_ = -1;
+ rpc_port_parcel_header_get_seq_num(header_, &seq_num_);
+ rpc_port_parcel_write_int32(p, static_cast<int>(MethodId::AsyncResult));
+ rpc_port_parcel_write_string(p, signal.c_str());
+ rpc_port_parcel_write_int32(p, targetUid);
+ rpc_port_parcel_write_string(p, reqId.c_str());
+ p << pkgs;
+ rpc_port_parcel_write_string(p, key.c_str());
+ rpc_port_parcel_write_string(p, val.c_str());
+
+ // Send
+ bundle* b = bundle_create();
+ std::unique_ptr<bundle, decltype(bundle_free)*> b_auto(b, bundle_free);
+ if (GetBundleFromParcel(p, b) == nullptr) {
+ _E("Failed to make bundle from parcel");
+ throw InvalidIOException();
+ }
+
+ std::lock_guard<std::recursive_mutex> lock(mutex_);
+ int ret = event_publish_app_event(GetEventName().c_str(), b);
+ if (ret != 0) {
+ _E("Failed to publish event. result(%d)", ret);
+ throw InvalidIOException();
+ }
+}
+
+void PkgSignal::AsyncResultForResource(std::string signal, int targetUid,
+ std::string reqId, std::string pkgid,
+ std::string status, ExtraData extra) {
+ rpc_port_parcel_h p;
+ rpc_port_parcel_create(&p);
+ std::unique_ptr<std::remove_pointer<rpc_port_parcel_h>::type,
+ decltype(rpc_port_parcel_destroy)*>
+ p_auto(p, rpc_port_parcel_destroy);
+ rpc_port_parcel_header_h header_;
+ rpc_port_parcel_get_header(p, &header_);
+ rpc_port_parcel_header_set_tag(header_, TIDL_VERSION);
+ int seq_num_ = -1;
+ rpc_port_parcel_header_get_seq_num(header_, &seq_num_);
+ rpc_port_parcel_write_int32(
+ p, static_cast<int>(MethodId::AsyncResultForResource));
+ rpc_port_parcel_write_string(p, signal.c_str());
+ rpc_port_parcel_write_int32(p, targetUid);
+ rpc_port_parcel_write_string(p, reqId.c_str());
+ rpc_port_parcel_write_string(p, pkgid.c_str());
+ rpc_port_parcel_write_string(p, status.c_str());
+ p << extra;
+
+ // Send
+ bundle* b = bundle_create();
+ std::unique_ptr<bundle, decltype(bundle_free)*> b_auto(b, bundle_free);
+ if (GetBundleFromParcel(p, b) == nullptr) {
+ _E("Failed to make bundle from parcel");
+ throw InvalidIOException();
+ }
+
+ std::lock_guard<std::recursive_mutex> lock(mutex_);
+ int ret = event_publish_app_event(GetEventName().c_str(), b);
+ if (ret != 0) {
+ _E("Failed to publish event. result(%d)", ret);
+ throw InvalidIOException();
+ }
+}
+
+void PkgSignal::AsyncResultForPkgUpgrade(std::string signal, int progress) {
+ rpc_port_parcel_h p;
+ rpc_port_parcel_create(&p);
+ std::unique_ptr<std::remove_pointer<rpc_port_parcel_h>::type,
+ decltype(rpc_port_parcel_destroy)*>
+ p_auto(p, rpc_port_parcel_destroy);
+ rpc_port_parcel_header_h header_;
+ rpc_port_parcel_get_header(p, &header_);
+ rpc_port_parcel_header_set_tag(header_, TIDL_VERSION);
+ int seq_num_ = -1;
+ rpc_port_parcel_header_get_seq_num(header_, &seq_num_);
+ rpc_port_parcel_write_int32(
+ p, static_cast<int>(MethodId::AsyncResultForPkgUpgrade));
+ rpc_port_parcel_write_string(p, signal.c_str());
+ rpc_port_parcel_write_int32(p, progress);
+
+ // Send
+ bundle* b = bundle_create();
+ std::unique_ptr<bundle, decltype(bundle_free)*> b_auto(b, bundle_free);
+ if (GetBundleFromParcel(p, b) == nullptr) {
+ _E("Failed to make bundle from parcel");
+ throw InvalidIOException();
+ }
+
+ std::lock_guard<std::recursive_mutex> lock(mutex_);
+ int ret = event_publish_app_event(GetEventName().c_str(), b);
+ if (ret != 0) {
+ _E("Failed to publish event. result(%d)", ret);
+ throw InvalidIOException();
+ }
+}
+} // namespace group
+} // namespace PkgSignal
+} // namespace rpc_port
diff --git a/client/src/PkgSignal.h b/client/src/PkgSignal.h
new file mode 100644
index 0000000..bd98946
--- /dev/null
+++ b/client/src/PkgSignal.h
@@ -0,0 +1,190 @@
+/*
+ * Generated by tidlc 2.2.4.
+ */
+
+#pragma once
+
+#include <bundle.h>
+#include <rpc-port-parcel.h>
+
+#include <atomic>
+#include <list>
+#include <memory>
+#include <mutex>
+#include <string>
+#include <vector>
+
+namespace rpc_port {
+namespace PkgSignal {
+
+class Bundle final {
+ public:
+ Bundle() { raw_ = bundle_create(); }
+
+ Bundle(bundle* b) { raw_ = b; }
+
+ ~Bundle() {
+ if (raw_) bundle_free(raw_);
+ }
+
+ Bundle(Bundle&& b) : raw_(b.raw_) { b.raw_ = nullptr; }
+
+ Bundle& operator=(Bundle&& b) {
+ if (this != &b) {
+ if (raw_) bundle_free(raw_);
+
+ raw_ = b.raw_;
+ b.raw_ = nullptr;
+ }
+ return *this;
+ }
+
+ Bundle(const Bundle& b) : raw_(bundle_dup(b.GetHandle())) {}
+
+ Bundle& operator=(const Bundle& b) {
+ if (this != &b) {
+ if (raw_) bundle_free(raw_);
+
+ raw_ = bundle_dup(b.GetHandle());
+ }
+ return *this;
+ }
+
+ bundle* GetHandle() const { return raw_; }
+
+ private:
+ bundle* raw_;
+};
+
+class File final {
+ public:
+ File() {}
+
+ File(std::string filename) { filename_ = filename; }
+
+ std::string GetFileName() const { return filename_; }
+
+ private:
+ std::string filename_;
+};
+
+class PkgInfo final {
+ public:
+ PkgInfo();
+ PkgInfo(std::string Pkgid, std::string Appid, std::string PkgType);
+
+ void SetPkgid(std::string Pkgid) { Pkgid_ = std::move(Pkgid); }
+
+ const std::string& GetPkgid() const { return Pkgid_; }
+
+ void SetAppid(std::string Appid) { Appid_ = std::move(Appid); }
+
+ const std::string& GetAppid() const { return Appid_; }
+
+ void SetPkgType(std::string PkgType) { PkgType_ = std::move(PkgType); }
+
+ const std::string& GetPkgType() const { return PkgType_; }
+
+ private:
+ std::string Pkgid_;
+ std::string Appid_;
+ std::string PkgType_;
+};
+
+class PathInfo final {
+ public:
+ PathInfo();
+ PathInfo(std::string Path, int State);
+
+ void SetPath(std::string Path) { Path_ = std::move(Path); }
+
+ const std::string& GetPath() const { return Path_; }
+
+ void SetState(int State) { State_ = State; }
+
+ int GetState() const { return State_; }
+
+ private:
+ std::string Path_;
+ int State_ = 0;
+};
+
+class ExtraData final {
+ public:
+ ExtraData();
+ ExtraData(int ErrCode, std::vector<PathInfo> Paths);
+
+ void SetErrCode(int ErrCode) { ErrCode_ = ErrCode; }
+
+ int GetErrCode() const { return ErrCode_; }
+
+ void SetPaths(std::vector<PathInfo> Paths) { Paths_ = std::move(Paths); }
+
+ const std::vector<PathInfo>& GetPaths() const { return Paths_; }
+
+ private:
+ int ErrCode_ = 0;
+ std::vector<PathInfo> Paths_;
+};
+
+namespace group {
+
+class Exception {};
+class NotConnectedSocketException : public Exception {};
+class InvalidProtocolException : public Exception {};
+class InvalidIOException : public Exception {};
+class PermissionDeniedException : public Exception {};
+class InvalidIDException : public Exception {};
+
+class PkgSignal {
+ public:
+ PkgSignal(std::string sender_appid, bool is_system = false);
+ virtual ~PkgSignal();
+
+ void AsyncResult(std::string signal, int targetUid, std::string reqId,
+ std::vector<PkgInfo> pkgs, std::string key, std::string val);
+
+ virtual void OnAsyncResult(std::string signal, int targetUid,
+ std::string reqId, std::vector<PkgInfo> pkgs,
+ std::string key, std::string val) {}
+
+ void AsyncResultForResource(std::string signal, int targetUid,
+ std::string reqId, std::string pkgid,
+ std::string status, ExtraData extra);
+
+ virtual void OnAsyncResultForResource(std::string signal, int targetUid,
+ std::string reqId, std::string pkgid,
+ std::string status, ExtraData extra) {}
+
+ void AsyncResultForPkgUpgrade(std::string signal, int progress);
+
+ virtual void OnAsyncResultForPkgUpgrade(std::string signal, int progress) {}
+
+ private:
+ enum class MethodId : int {
+ __Result = 0,
+ __Callback = 1,
+ AsyncResult = 2,
+ AsyncResultForResource = 3,
+ AsyncResultForPkgUpgrade = 4,
+
+ };
+
+ bundle* GetBundleFromParcel(rpc_port_parcel_h p, bundle* b);
+ rpc_port_parcel_h GetParcelFromBundle(bundle* b);
+ std::string GetEventName();
+ void Subscribe();
+ void Unsubscribe();
+ static void EventCb(const char* event_name, bundle* event_data,
+ void* user_data);
+
+ private:
+ void* event_handler_ = nullptr;
+ std::string sender_appid_;
+ std::recursive_mutex mutex_;
+ bool is_system_;
+};
+
+} // namespace group
+} // namespace PkgSignal
+} // namespace rpc_port
diff --git a/installer/CMakeLists.txt b/installer/CMakeLists.txt
index 8e3c230..5a238d4 100644
--- a/installer/CMakeLists.txt
+++ b/installer/CMakeLists.txt
@@ -9,7 +9,6 @@ PKG_CHECK_MODULES(INSTALLER_DEPS REQUIRED
pkgmgr-info
libtzplatform-config
rpc-port
- capi-appfw-event
)
FOREACH(FLAGS ${INSTALLER_DEPS_CFLAGS})
diff --git a/installer/src/PkgSignal.cc b/installer/src/PkgSignal.cc
new file mode 100644
index 0000000..dc28b37
--- /dev/null
+++ b/installer/src/PkgSignal.cc
@@ -0,0 +1,556 @@
+/*
+ * Generated by tidlc 2.2.4.
+ */
+
+#include "PkgSignal.h"
+
+#include <assert.h>
+#include <dlfcn.h>
+#include <dlog.h>
+#include <stdlib.h>
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "RPC_PORT_GROUP"
+
+#ifdef _E
+#undef _E
+#endif
+
+#ifdef _W
+#undef _W
+#endif
+
+#ifdef _I
+#undef _I
+#endif
+
+#ifdef _D
+#undef _D
+#endif
+
+#define _E(fmt, ...) \
+ dlog_print(DLOG_ERROR, LOG_TAG, "%s: %s(%d) > " fmt, \
+ basename(const_cast<char*>(__FILE__)), __FUNCTION__, __LINE__, \
+ ##__VA_ARGS__)
+#define _W(fmt, ...) \
+ dlog_print(DLOG_WARN, LOG_TAG, "%s: %s(%d) > " fmt, \
+ basename(const_cast<char*>(__FILE__)), __FUNCTION__, __LINE__, \
+ ##__VA_ARGS__)
+#define _I(fmt, ...) \
+ dlog_print(DLOG_INFO, LOG_TAG, "%s: %s(%d) > " fmt, \
+ basename(const_cast<char*>(__FILE__)), __FUNCTION__, __LINE__, \
+ ##__VA_ARGS__)
+#define _D(fmt, ...) \
+ dlog_print(DLOG_DEBUG, LOG_TAG, "%s: %s(%d) > " fmt, \
+ basename(const_cast<char*>(__FILE__)), __FUNCTION__, __LINE__, \
+ ##__VA_ARGS__)
+
+#ifndef TIDL_VERSION
+#define TIDL_VERSION "2.2.4"
+#endif
+
+namespace {
+
+using event_handler_h = void*;
+using event_cb = void (*)(const char*, bundle*, void*);
+
+#ifndef UNIT_TEST
+
+constexpr const char kPathLibAppEventCore[] =
+ LIBDIR "/libcapi-appfw-event.so.0";
+
+using event_add_event_handler_t = int (*)(const char*, event_cb, void*,
+ event_handler_h*);
+using event_remove_event_handler_t = int (*)(event_handler_h);
+using event_publish_app_event_t = int (*)(const char*, bundle*);
+
+event_add_event_handler_t event_add_event_handler = nullptr;
+event_remove_event_handler_t event_remove_event_handler = nullptr;
+event_publish_app_event_t event_publish_app_event = nullptr;
+
+class AppEvent {
+ public:
+ AppEvent() {
+ handle_ = dlopen(kPathLibAppEventCore, RTLD_LAZY | RTLD_GLOBAL);
+ if (handle_ == nullptr) {
+ _E("dlopen() is failed. error(%s)", dlerror());
+ return;
+ }
+
+ std::string symbol = "event_add_event_handler";
+ event_add_event_handler = reinterpret_cast<event_add_event_handler_t>(
+ dlsym(handle_, symbol.c_str()));
+ if (event_add_event_handler == nullptr) {
+ _E("Failed to find symbol(%s)", symbol.c_str());
+ return;
+ }
+
+ symbol = "event_remove_event_handler";
+ event_remove_event_handler = reinterpret_cast<event_remove_event_handler_t>(
+ dlsym(handle_, symbol.c_str()));
+ if (event_remove_event_handler == nullptr) {
+ _E("Failed to find symbol(%s)", symbol.c_str());
+ return;
+ }
+
+ symbol = "event_publish_app_event";
+ event_publish_app_event = reinterpret_cast<event_publish_app_event_t>(
+ dlsym(handle_, symbol.c_str()));
+ if (event_publish_app_event == nullptr) {
+ _E("Failed to find symbol(%s)", symbol.c_str());
+ return;
+ }
+
+ loaded_ = true;
+ }
+
+ ~AppEvent() {
+ if (handle_) dlclose(handle_);
+ }
+
+ bool IsLoaded() { return loaded_; }
+
+ private:
+ bool loaded_ = false;
+ void* handle_ = nullptr;
+};
+
+static AppEvent app_event;
+
+#else
+
+extern "C" int event_add_event_handler(const char *event_name,
+ event_cb callback, void *user_data, event_handler_h *event_handler) {
+ return 0;
+}
+
+extern "C" int event_remove_event_handler(event_handler_h event_handler) {
+ return 0;
+}
+
+extern "C" int event_publish_app_event(const char *event_name,
+ bundle *event_data) {
+ return 0;
+}
+
+#endif
+
+} // namespace
+
+namespace rpc_port {
+namespace PkgSignal {
+
+PkgInfo::PkgInfo() {}
+
+PkgInfo::PkgInfo(std::string Pkgid, std::string Appid, std::string PkgType)
+ : Pkgid_(std::move(Pkgid)),
+ Appid_(std::move(Appid)),
+ PkgType_(std::move(PkgType)) {}
+
+PathInfo::PathInfo() {}
+
+PathInfo::PathInfo(std::string Path, int State)
+ : Path_(std::move(Path)), State_(std::move(State)) {}
+
+ExtraData::ExtraData() {}
+
+ExtraData::ExtraData(int ErrCode, std::vector<PathInfo> Paths)
+ : ErrCode_(std::move(ErrCode)), Paths_(std::move(Paths)) {}
+
+namespace group {
+
+rpc_port_parcel_h operator<<(rpc_port_parcel_h h, const PkgInfo& param);
+
+rpc_port_parcel_h operator>>(rpc_port_parcel_h h, PkgInfo& param);
+
+rpc_port_parcel_h operator<<(rpc_port_parcel_h h, const PathInfo& param);
+
+rpc_port_parcel_h operator>>(rpc_port_parcel_h h, PathInfo& param);
+
+rpc_port_parcel_h operator<<(rpc_port_parcel_h h, const ExtraData& param);
+
+rpc_port_parcel_h operator>>(rpc_port_parcel_h h, ExtraData& param);
+
+rpc_port_parcel_h operator<<(rpc_port_parcel_h h,
+ const std::vector<PathInfo>& param);
+
+rpc_port_parcel_h operator>>(rpc_port_parcel_h h, std::vector<PathInfo>& param);
+
+rpc_port_parcel_h operator<<(rpc_port_parcel_h h,
+ const std::vector<PkgInfo>& param);
+
+rpc_port_parcel_h operator>>(rpc_port_parcel_h h, std::vector<PkgInfo>& param);
+
+rpc_port_parcel_h operator<<(rpc_port_parcel_h h, const PkgInfo& param) {
+ rpc_port_parcel_write_string(h, param.GetPkgid().c_str());
+ rpc_port_parcel_write_string(h, param.GetAppid().c_str());
+ rpc_port_parcel_write_string(h, param.GetPkgType().c_str());
+ return h;
+}
+
+rpc_port_parcel_h operator<<(rpc_port_parcel_h h, const PathInfo& param) {
+ rpc_port_parcel_write_string(h, param.GetPath().c_str());
+ rpc_port_parcel_write_int32(h, param.GetState());
+ return h;
+}
+
+rpc_port_parcel_h operator<<(rpc_port_parcel_h h, const ExtraData& param) {
+ rpc_port_parcel_write_int32(h, param.GetErrCode());
+ h << param.GetPaths();
+ return h;
+}
+
+rpc_port_parcel_h operator>>(rpc_port_parcel_h h, PkgInfo& param) {
+ char* Pkgid_raw = nullptr;
+ rpc_port_parcel_read_string(h, &Pkgid_raw);
+ std::string Pkgid(Pkgid_raw);
+ free(Pkgid_raw);
+ param.SetPkgid(std::move(Pkgid));
+
+ char* Appid_raw = nullptr;
+ rpc_port_parcel_read_string(h, &Appid_raw);
+ std::string Appid(Appid_raw);
+ free(Appid_raw);
+ param.SetAppid(std::move(Appid));
+
+ char* PkgType_raw = nullptr;
+ rpc_port_parcel_read_string(h, &PkgType_raw);
+ std::string PkgType(PkgType_raw);
+ free(PkgType_raw);
+ param.SetPkgType(std::move(PkgType));
+
+ return h;
+}
+
+rpc_port_parcel_h operator>>(rpc_port_parcel_h h, PathInfo& param) {
+ char* Path_raw = nullptr;
+ rpc_port_parcel_read_string(h, &Path_raw);
+ std::string Path(Path_raw);
+ free(Path_raw);
+ param.SetPath(std::move(Path));
+
+ int State;
+ rpc_port_parcel_read_int32(h, &State);
+ param.SetState(State);
+
+ return h;
+}
+
+rpc_port_parcel_h operator>>(rpc_port_parcel_h h, ExtraData& param) {
+ int ErrCode;
+ rpc_port_parcel_read_int32(h, &ErrCode);
+ param.SetErrCode(ErrCode);
+
+ std::vector<PathInfo> Paths;
+ h >> Paths;
+ param.SetPaths(std::move(Paths));
+
+ return h;
+}
+
+rpc_port_parcel_h operator<<(rpc_port_parcel_h h,
+ const std::vector<PathInfo>& param) {
+ rpc_port_parcel_write_array_count(h, param.size());
+ for (const auto& i : param) {
+ h << i;
+ }
+
+ return h;
+}
+
+rpc_port_parcel_h operator>>(rpc_port_parcel_h h,
+ std::vector<PathInfo>& param) {
+ int l = 0;
+ rpc_port_parcel_read_array_count(h, &l);
+
+ for (int i = 0; i < l; i++) {
+ PathInfo v;
+ h >> v;
+
+ param.push_back(std::move(v));
+ }
+
+ return h;
+}
+
+rpc_port_parcel_h operator<<(rpc_port_parcel_h h,
+ const std::vector<PkgInfo>& param) {
+ rpc_port_parcel_write_array_count(h, param.size());
+ for (const auto& i : param) {
+ h << i;
+ }
+
+ return h;
+}
+
+rpc_port_parcel_h operator>>(rpc_port_parcel_h h, std::vector<PkgInfo>& param) {
+ int l = 0;
+ rpc_port_parcel_read_array_count(h, &l);
+
+ for (int i = 0; i < l; i++) {
+ PkgInfo v;
+ h >> v;
+
+ param.push_back(std::move(v));
+ }
+
+ return h;
+}
+
+PkgSignal::PkgSignal(std::string sender_appid, bool is_system)
+ : sender_appid_(std::move(sender_appid)), is_system_(is_system) {
+ Subscribe();
+}
+
+PkgSignal::~PkgSignal() { Unsubscribe(); }
+
+void PkgSignal::Subscribe() {
+ std::lock_guard<std::recursive_mutex> lock(mutex_);
+ int ret = event_add_event_handler(GetEventName().c_str(), EventCb, this,
+ &event_handler_);
+ if (ret != 0) {
+ throw InvalidIOException();
+ }
+}
+
+void PkgSignal::Unsubscribe() {
+ std::lock_guard<std::recursive_mutex> lock(mutex_);
+ if (event_handler_) {
+ event_remove_event_handler(event_handler_);
+ event_handler_ = nullptr;
+ }
+}
+
+bundle* PkgSignal::GetBundleFromParcel(rpc_port_parcel_h p, bundle* b) {
+ void* raw = nullptr;
+ unsigned int size = 0;
+
+ int ret = rpc_port_parcel_get_raw(p, &raw, &size);
+ if (ret != RPC_PORT_ERROR_NONE) return nullptr;
+
+ ret = bundle_add_byte(b, "TIDL_RAW", raw, size);
+ if (ret != BUNDLE_ERROR_NONE) return nullptr;
+
+ return b;
+}
+
+rpc_port_parcel_h PkgSignal::GetParcelFromBundle(bundle* b) {
+ void* raw = nullptr;
+ size_t size = 0;
+ rpc_port_parcel_h p;
+
+ int ret = bundle_get_byte(b, "TIDL_RAW", &raw, &size);
+ if (ret != BUNDLE_ERROR_NONE) return nullptr;
+
+ ret =
+ rpc_port_parcel_create_from_raw(&p, raw, static_cast<unsigned int>(size));
+ if (ret != RPC_PORT_ERROR_NONE) return nullptr;
+
+ return p;
+}
+
+std::string PkgSignal::GetEventName() {
+ if (is_system_) return "tizen.system.event.tidl_iface_PkgSignal";
+ return "event." + sender_appid_ + ".tidl_iface_PkgSignal";
+}
+
+void PkgSignal::EventCb(const char* event_name, bundle* event_data,
+ void* user_data) {
+ auto* ptr = static_cast<PkgSignal*>(user_data);
+ rpc_port_parcel_h p = ptr->GetParcelFromBundle(event_data);
+ if (p == nullptr) {
+ _E("Invalid bundle");
+ return;
+ }
+
+ std::unique_ptr<std::remove_pointer<rpc_port_parcel_h>::type,
+ decltype(rpc_port_parcel_destroy)*>
+ p_auto(p, rpc_port_parcel_destroy);
+
+ rpc_port_parcel_h header;
+ int seq_num = -1;
+ int cmd;
+ rpc_port_parcel_get_header(p, &header);
+ rpc_port_parcel_header_get_seq_num(header, &seq_num);
+
+ rpc_port_parcel_read_int32(p, &cmd);
+ switch (cmd) {
+ case static_cast<int>(MethodId::AsyncResult): {
+ char* param1_raw = nullptr;
+ rpc_port_parcel_read_string(p, &param1_raw);
+ std::string param1(param1_raw);
+ free(param1_raw);
+ int param2;
+ rpc_port_parcel_read_int32(p, &param2);
+ char* param3_raw = nullptr;
+ rpc_port_parcel_read_string(p, &param3_raw);
+ std::string param3(param3_raw);
+ free(param3_raw);
+ std::vector<PkgInfo> param4;
+ p >> param4;
+ char* param5_raw = nullptr;
+ rpc_port_parcel_read_string(p, &param5_raw);
+ std::string param5(param5_raw);
+ free(param5_raw);
+ char* param6_raw = nullptr;
+ rpc_port_parcel_read_string(p, &param6_raw);
+ std::string param6(param6_raw);
+ free(param6_raw);
+ ptr->OnAsyncResult(param1, param2, param3, param4, param5, param6);
+
+ } break;
+
+ case static_cast<int>(MethodId::AsyncResultForResource): {
+ char* param1_raw = nullptr;
+ rpc_port_parcel_read_string(p, &param1_raw);
+ std::string param1(param1_raw);
+ free(param1_raw);
+ int param2;
+ rpc_port_parcel_read_int32(p, &param2);
+ char* param3_raw = nullptr;
+ rpc_port_parcel_read_string(p, &param3_raw);
+ std::string param3(param3_raw);
+ free(param3_raw);
+ char* param4_raw = nullptr;
+ rpc_port_parcel_read_string(p, &param4_raw);
+ std::string param4(param4_raw);
+ free(param4_raw);
+ char* param5_raw = nullptr;
+ rpc_port_parcel_read_string(p, &param5_raw);
+ std::string param5(param5_raw);
+ free(param5_raw);
+ ExtraData param6;
+ p >> param6;
+ ptr->OnAsyncResultForResource(param1, param2, param3, param4, param5,
+ param6);
+
+ } break;
+
+ case static_cast<int>(MethodId::AsyncResultForPkgUpgrade): {
+ char* param1_raw = nullptr;
+ rpc_port_parcel_read_string(p, &param1_raw);
+ std::string param1(param1_raw);
+ free(param1_raw);
+ int param2;
+ rpc_port_parcel_read_int32(p, &param2);
+ ptr->OnAsyncResultForPkgUpgrade(param1, param2);
+
+ } break;
+
+ default:
+ _E("Unknown command(%d)", cmd);
+ }
+}
+
+void PkgSignal::AsyncResult(std::string signal, int targetUid,
+ std::string reqId, std::vector<PkgInfo> pkgs,
+ std::string key, std::string val) {
+ rpc_port_parcel_h p;
+ rpc_port_parcel_create(&p);
+ std::unique_ptr<std::remove_pointer<rpc_port_parcel_h>::type,
+ decltype(rpc_port_parcel_destroy)*>
+ p_auto(p, rpc_port_parcel_destroy);
+ rpc_port_parcel_header_h header_;
+ rpc_port_parcel_get_header(p, &header_);
+ rpc_port_parcel_header_set_tag(header_, TIDL_VERSION);
+ int seq_num_ = -1;
+ rpc_port_parcel_header_get_seq_num(header_, &seq_num_);
+ rpc_port_parcel_write_int32(p, static_cast<int>(MethodId::AsyncResult));
+ rpc_port_parcel_write_string(p, signal.c_str());
+ rpc_port_parcel_write_int32(p, targetUid);
+ rpc_port_parcel_write_string(p, reqId.c_str());
+ p << pkgs;
+ rpc_port_parcel_write_string(p, key.c_str());
+ rpc_port_parcel_write_string(p, val.c_str());
+
+ // Send
+ bundle* b = bundle_create();
+ std::unique_ptr<bundle, decltype(bundle_free)*> b_auto(b, bundle_free);
+ if (GetBundleFromParcel(p, b) == nullptr) {
+ _E("Failed to make bundle from parcel");
+ throw InvalidIOException();
+ }
+
+ std::lock_guard<std::recursive_mutex> lock(mutex_);
+ int ret = event_publish_app_event(GetEventName().c_str(), b);
+ if (ret != 0) {
+ _E("Failed to publish event. result(%d)", ret);
+ throw InvalidIOException();
+ }
+}
+
+void PkgSignal::AsyncResultForResource(std::string signal, int targetUid,
+ std::string reqId, std::string pkgid,
+ std::string status, ExtraData extra) {
+ rpc_port_parcel_h p;
+ rpc_port_parcel_create(&p);
+ std::unique_ptr<std::remove_pointer<rpc_port_parcel_h>::type,
+ decltype(rpc_port_parcel_destroy)*>
+ p_auto(p, rpc_port_parcel_destroy);
+ rpc_port_parcel_header_h header_;
+ rpc_port_parcel_get_header(p, &header_);
+ rpc_port_parcel_header_set_tag(header_, TIDL_VERSION);
+ int seq_num_ = -1;
+ rpc_port_parcel_header_get_seq_num(header_, &seq_num_);
+ rpc_port_parcel_write_int32(
+ p, static_cast<int>(MethodId::AsyncResultForResource));
+ rpc_port_parcel_write_string(p, signal.c_str());
+ rpc_port_parcel_write_int32(p, targetUid);
+ rpc_port_parcel_write_string(p, reqId.c_str());
+ rpc_port_parcel_write_string(p, pkgid.c_str());
+ rpc_port_parcel_write_string(p, status.c_str());
+ p << extra;
+
+ // Send
+ bundle* b = bundle_create();
+ std::unique_ptr<bundle, decltype(bundle_free)*> b_auto(b, bundle_free);
+ if (GetBundleFromParcel(p, b) == nullptr) {
+ _E("Failed to make bundle from parcel");
+ throw InvalidIOException();
+ }
+
+ std::lock_guard<std::recursive_mutex> lock(mutex_);
+ int ret = event_publish_app_event(GetEventName().c_str(), b);
+ if (ret != 0) {
+ _E("Failed to publish event. result(%d)", ret);
+ throw InvalidIOException();
+ }
+}
+
+void PkgSignal::AsyncResultForPkgUpgrade(std::string signal, int progress) {
+ rpc_port_parcel_h p;
+ rpc_port_parcel_create(&p);
+ std::unique_ptr<std::remove_pointer<rpc_port_parcel_h>::type,
+ decltype(rpc_port_parcel_destroy)*>
+ p_auto(p, rpc_port_parcel_destroy);
+ rpc_port_parcel_header_h header_;
+ rpc_port_parcel_get_header(p, &header_);
+ rpc_port_parcel_header_set_tag(header_, TIDL_VERSION);
+ int seq_num_ = -1;
+ rpc_port_parcel_header_get_seq_num(header_, &seq_num_);
+ rpc_port_parcel_write_int32(
+ p, static_cast<int>(MethodId::AsyncResultForPkgUpgrade));
+ rpc_port_parcel_write_string(p, signal.c_str());
+ rpc_port_parcel_write_int32(p, progress);
+
+ // Send
+ bundle* b = bundle_create();
+ std::unique_ptr<bundle, decltype(bundle_free)*> b_auto(b, bundle_free);
+ if (GetBundleFromParcel(p, b) == nullptr) {
+ _E("Failed to make bundle from parcel");
+ throw InvalidIOException();
+ }
+
+ std::lock_guard<std::recursive_mutex> lock(mutex_);
+ int ret = event_publish_app_event(GetEventName().c_str(), b);
+ if (ret != 0) {
+ _E("Failed to publish event. result(%d)", ret);
+ throw InvalidIOException();
+ }
+}
+} // namespace group
+} // namespace PkgSignal
+} // namespace rpc_port
diff --git a/installer/src/PkgSignal.h b/installer/src/PkgSignal.h
new file mode 100644
index 0000000..bd98946
--- /dev/null
+++ b/installer/src/PkgSignal.h
@@ -0,0 +1,190 @@
+/*
+ * Generated by tidlc 2.2.4.
+ */
+
+#pragma once
+
+#include <bundle.h>
+#include <rpc-port-parcel.h>
+
+#include <atomic>
+#include <list>
+#include <memory>
+#include <mutex>
+#include <string>
+#include <vector>
+
+namespace rpc_port {
+namespace PkgSignal {
+
+class Bundle final {
+ public:
+ Bundle() { raw_ = bundle_create(); }
+
+ Bundle(bundle* b) { raw_ = b; }
+
+ ~Bundle() {
+ if (raw_) bundle_free(raw_);
+ }
+
+ Bundle(Bundle&& b) : raw_(b.raw_) { b.raw_ = nullptr; }
+
+ Bundle& operator=(Bundle&& b) {
+ if (this != &b) {
+ if (raw_) bundle_free(raw_);
+
+ raw_ = b.raw_;
+ b.raw_ = nullptr;
+ }
+ return *this;
+ }
+
+ Bundle(const Bundle& b) : raw_(bundle_dup(b.GetHandle())) {}
+
+ Bundle& operator=(const Bundle& b) {
+ if (this != &b) {
+ if (raw_) bundle_free(raw_);
+
+ raw_ = bundle_dup(b.GetHandle());
+ }
+ return *this;
+ }
+
+ bundle* GetHandle() const { return raw_; }
+
+ private:
+ bundle* raw_;
+};
+
+class File final {
+ public:
+ File() {}
+
+ File(std::string filename) { filename_ = filename; }
+
+ std::string GetFileName() const { return filename_; }
+
+ private:
+ std::string filename_;
+};
+
+class PkgInfo final {
+ public:
+ PkgInfo();
+ PkgInfo(std::string Pkgid, std::string Appid, std::string PkgType);
+
+ void SetPkgid(std::string Pkgid) { Pkgid_ = std::move(Pkgid); }
+
+ const std::string& GetPkgid() const { return Pkgid_; }
+
+ void SetAppid(std::string Appid) { Appid_ = std::move(Appid); }
+
+ const std::string& GetAppid() const { return Appid_; }
+
+ void SetPkgType(std::string PkgType) { PkgType_ = std::move(PkgType); }
+
+ const std::string& GetPkgType() const { return PkgType_; }
+
+ private:
+ std::string Pkgid_;
+ std::string Appid_;
+ std::string PkgType_;
+};
+
+class PathInfo final {
+ public:
+ PathInfo();
+ PathInfo(std::string Path, int State);
+
+ void SetPath(std::string Path) { Path_ = std::move(Path); }
+
+ const std::string& GetPath() const { return Path_; }
+
+ void SetState(int State) { State_ = State; }
+
+ int GetState() const { return State_; }
+
+ private:
+ std::string Path_;
+ int State_ = 0;
+};
+
+class ExtraData final {
+ public:
+ ExtraData();
+ ExtraData(int ErrCode, std::vector<PathInfo> Paths);
+
+ void SetErrCode(int ErrCode) { ErrCode_ = ErrCode; }
+
+ int GetErrCode() const { return ErrCode_; }
+
+ void SetPaths(std::vector<PathInfo> Paths) { Paths_ = std::move(Paths); }
+
+ const std::vector<PathInfo>& GetPaths() const { return Paths_; }
+
+ private:
+ int ErrCode_ = 0;
+ std::vector<PathInfo> Paths_;
+};
+
+namespace group {
+
+class Exception {};
+class NotConnectedSocketException : public Exception {};
+class InvalidProtocolException : public Exception {};
+class InvalidIOException : public Exception {};
+class PermissionDeniedException : public Exception {};
+class InvalidIDException : public Exception {};
+
+class PkgSignal {
+ public:
+ PkgSignal(std::string sender_appid, bool is_system = false);
+ virtual ~PkgSignal();
+
+ void AsyncResult(std::string signal, int targetUid, std::string reqId,
+ std::vector<PkgInfo> pkgs, std::string key, std::string val);
+
+ virtual void OnAsyncResult(std::string signal, int targetUid,
+ std::string reqId, std::vector<PkgInfo> pkgs,
+ std::string key, std::string val) {}
+
+ void AsyncResultForResource(std::string signal, int targetUid,
+ std::string reqId, std::string pkgid,
+ std::string status, ExtraData extra);
+
+ virtual void OnAsyncResultForResource(std::string signal, int targetUid,
+ std::string reqId, std::string pkgid,
+ std::string status, ExtraData extra) {}
+
+ void AsyncResultForPkgUpgrade(std::string signal, int progress);
+
+ virtual void OnAsyncResultForPkgUpgrade(std::string signal, int progress) {}
+
+ private:
+ enum class MethodId : int {
+ __Result = 0,
+ __Callback = 1,
+ AsyncResult = 2,
+ AsyncResultForResource = 3,
+ AsyncResultForPkgUpgrade = 4,
+
+ };
+
+ bundle* GetBundleFromParcel(rpc_port_parcel_h p, bundle* b);
+ rpc_port_parcel_h GetParcelFromBundle(bundle* b);
+ std::string GetEventName();
+ void Subscribe();
+ void Unsubscribe();
+ static void EventCb(const char* event_name, bundle* event_data,
+ void* user_data);
+
+ private:
+ void* event_handler_ = nullptr;
+ std::string sender_appid_;
+ std::recursive_mutex mutex_;
+ bool is_system_;
+};
+
+} // namespace group
+} // namespace PkgSignal
+} // namespace rpc_port
diff --git a/packaging/pkgmgr.spec b/packaging/pkgmgr.spec
index f337011..3d1668c 100644
--- a/packaging/pkgmgr.spec
+++ b/packaging/pkgmgr.spec
@@ -34,7 +34,6 @@ BuildRequires: pkgconfig(libsmack)
BuildRequires: pkgconfig(libsystemd)
BuildRequires: pkgconfig(minizip)
BuildRequires: pkgconfig(rpc-port)
-BuildRequires: pkgconfig(capi-appfw-event)
BuildRequires: pkgconfig(gmock)
BuildRequires: pkgmgr-info-parser-devel
BuildRequires: pkgmgr-info-parser
@@ -92,9 +91,6 @@ Package Manager client types develpoment package for packaging
cp %{SOURCE1001} %{SOURCE1002} %{SOURCE1003} %{SOURCE1004} %{SOURCE1005} %{SOURCE1006} .
tidlc -p -l C++ -i ./tidl/PkgMgr.tidl -o PkgMgrProxy
mv PkgMgrProxy.* ./client/src/
-tidlc -g -l C++ -i ./tidl/PkgSignal.tidl -o PkgSignal
-cp PkgSignal.* ./client/src/
-mv PkgSignal.* ./installer/src/
%build
MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
diff --git a/test/unit_tests/CMakeLists.txt b/test/unit_tests/CMakeLists.txt
index d328392..5c82451 100644
--- a/test/unit_tests/CMakeLists.txt
+++ b/test/unit_tests/CMakeLists.txt
@@ -1,3 +1,4 @@
+ADD_DEFINITIONS("-DUNIT_TEST=1")
AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/ UNIT_TESTS_SRCS)
AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/mock UNIT_TESTS_MOCK_SRCS)
AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../../client/src CLIENT_SRCS)
@@ -18,7 +19,6 @@ APPLY_PKG_CONFIG(${TARGET_PKGMGR_UNIT_TEST} PUBLIC
GMOCK_DEPS
GLIB_DEPS
RPC_PORT_DEPS
- CAPI_APPFW_EVENT_DEPS
DLOG_DEPS
BUNDLE_DEPS
)
diff --git a/test/unit_tests/mock/app_event_mock.cc b/test/unit_tests/mock/app_event_mock.cc
deleted file mode 100644
index 165caa3..0000000
--- a/test/unit_tests/mock/app_event_mock.cc
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#include "mock/app_event_mock.hh"
-#include "mock/mock_hook.hh"
-#include "mock/test_fixture.hh"
-
-extern "C" int event_add_event_handler(const char *event_name,
- event_cb callback, void *user_data, event_handler_h *event_handler) {
- return MOCK_HOOK_P4(AppEventMock, event_add_event_handler,
- event_name, callback, user_data, event_handler);
-}
-
-extern "C" int event_remove_event_handler(event_handler_h event_handler) {
- return MOCK_HOOK_P1(AppEventMock, event_remove_event_handler,
- event_handler);
-}
-
-extern "C" int event_publish_app_event(const char *event_name,
- bundle *event_data) {
- return MOCK_HOOK_P2(AppEventMock, event_publish_app_event,
- event_name, event_data);
-}
diff --git a/test/unit_tests/mock/app_event_mock.hh b/test/unit_tests/mock/app_event_mock.hh
deleted file mode 100644
index fe6af4b..0000000
--- a/test/unit_tests/mock/app_event_mock.hh
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef UNIT_TESTS_MOCK_APP_EVENT_MOCK_HH_
-#define UNIT_TESTS_MOCK_APP_EVENT_MOCK_HH_
-
-#include <app_event.h>
-#include <gmock/gmock.h>
-
-#include "mock/module_mock.hh"
-
-class AppEventMock : public virtual ModuleMock {
- public:
- AppEventMock() {}
- virtual ~AppEventMock() {}
-
- MOCK_METHOD(int, event_add_event_handler, (const char*,
- event_cb, void*, event_handler_h*));
- MOCK_METHOD(int, event_remove_event_handler, (event_handler_h));
- MOCK_METHOD(int, event_publish_app_event, (const char*, bundle*));
-};
-
-#endif // UNIT_TESTS_MOCK_APP_EVENT_MOCK_HH_
diff --git a/test/unit_tests/test_client.cc b/test/unit_tests/test_client.cc
index b9eb289..035976e 100644
--- a/test/unit_tests/test_client.cc
+++ b/test/unit_tests/test_client.cc
@@ -3,7 +3,6 @@
#include <gtest/gtest.h>
#include <gmock/gmock.h>
-#include "unit_tests/mock/app_event_mock.hh"
#include "unit_tests/mock/rpc_port_mock.hh"
#include "unit_tests/mock/test_fixture.hh"
#include "unit_tests/mock/unistd_mock.hh"
@@ -13,7 +12,6 @@ using ::testing::Invoke;
namespace {
class Mocks : public ::testing::NiceMock<RpcPortMock>,
- virtual public ::testing::NiceMock<AppEventMock>,
virtual public ::testing::NiceMock<UnistdMock> {};
} // namespace