diff options
author | pjh9216 <jh9216.park@samsung.com> | 2024-11-06 16:51:14 +0900 |
---|---|---|
committer | pjh9216 <jh9216.park@samsung.com> | 2024-11-06 16:51:14 +0900 |
commit | bf0ddf6a42c08601563ac6f0d569af006705a8a0 (patch) | |
tree | 08c6f0ebd963fc6875769ec4836dd2fe3e964880 | |
parent | 1e2d973875bf794062c1e8569ff1a7d25f4d9f66 (diff) | |
download | slp-pkgmgr-bf0ddf6a42c08601563ac6f0d569af006705a8a0.tar.gz slp-pkgmgr-bf0ddf6a42c08601563ac6f0d569af006705a8a0.tar.bz2 slp-pkgmgr-bf0ddf6a42c08601563ac6f0d569af006705a8a0.zip |
Use libopener
Change-Id: Ibaea6afba98220ca3f9c68aee0a3338ba874b6d0
Signed-off-by: pjh9216 <jh9216.park@samsung.com>
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | client/CMakeLists.txt | 1 | ||||
-rw-r--r-- | client/src/PkgSignal.cc | 94 | ||||
-rw-r--r-- | installer/CMakeLists.txt | 1 | ||||
-rw-r--r-- | installer/src/PkgSignal.cc | 97 | ||||
-rw-r--r-- | packaging/pkgmgr.spec | 1 |
6 files changed, 39 insertions, 156 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index b4f02c2..023f9a3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,6 +30,7 @@ PKG_CHECK_MODULES(INIPARSER_DEPS REQUIRED iniparser) PKG_CHECK_MODULES(XDGMIME_DEPS REQUIRED xdgmime) PKG_CHECK_MODULES(PLATFORM_CONFIG_DEPS REQUIRED libtzplatform-config) PKG_CHECK_MODULES(MINIZIP_DEPS REQUIRED minizip) +PKG_CHECK_MODULES(TIZEN_LIBOPENER_DEPS REQUIRED tizen-libopener) ADD_DEFINITIONS("-DLIBDIR=\"${LIBDIR}\"") diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index e97eb4f..d186aed 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -21,6 +21,7 @@ APPLY_PKG_CONFIG(${PKGMGR_CLIENT} PUBLIC PLATFORM_CONFIG_DEPS MINIZIP_DEPS RPC_PORT_DEPS + TIZEN_LIBOPENER_DEPS ) TARGET_LINK_LIBRARIES(${PKGMGR_CLIENT} PUBLIC "dl") diff --git a/client/src/PkgSignal.cc b/client/src/PkgSignal.cc index 83494b3..9e56317 100644 --- a/client/src/PkgSignal.cc +++ b/client/src/PkgSignal.cc @@ -9,6 +9,8 @@ #include <dlog.h> #include <stdlib.h> +#include <libopener.hpp> + #ifdef LOG_TAG #undef LOG_TAG #endif @@ -62,68 +64,23 @@ using event_cb = void (*)(const char*, bundle*, void*); 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_); - } +tizen_base::LibOpener app_event_lib(kPathLibAppEventCore); - bool IsLoaded() { return loaded_; } +auto* event_add_event_handler = + app_event_lib.Bind<int (*)(const char*, event_cb, void*, event_handler_h*)>( + "event_add_event_handler"); +auto* event_remove_event_handler = + app_event_lib.Bind<int (*)(event_handler_h)>("event_remove_event_handler"); - private: - bool loaded_ = false; - void* handle_ = nullptr; -}; - -static AppEvent app_event; +auto* event_publish_app_event = + app_event_lib.Bind<int (*)(const char*, bundle*)>( + "event_publish_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) { +extern "C" int event_add_event_handler(const char* event_name, + event_cb callback, void* user_data, + event_handler_h* event_handler) { return 0; } @@ -131,8 +88,8 @@ 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) { +extern "C" int event_publish_app_event(const char* event_name, + bundle* event_data) { return 0; } @@ -309,10 +266,6 @@ PkgSignal::~PkgSignal() { Unsubscribe(); } void PkgSignal::Subscribe() { std::lock_guard<std::recursive_mutex> lock(mutex_); - if (!event_add_event_handler) { - _E("Function symbol(event_add_event_handler) did not initialized"); - throw InvalidIOException(); - } int ret = event_add_event_handler(GetEventName().c_str(), EventCb, this, &event_handler_); @@ -324,8 +277,7 @@ void PkgSignal::Subscribe() { void PkgSignal::Unsubscribe() { std::lock_guard<std::recursive_mutex> lock(mutex_); if (event_handler_) { - if (event_remove_event_handler) - event_remove_event_handler(event_handler_); + event_remove_event_handler(event_handler_); event_handler_ = nullptr; } } @@ -481,10 +433,6 @@ void PkgSignal::AsyncResult(std::string signal, int targetUid, } std::lock_guard<std::recursive_mutex> lock(mutex_); - if (!event_publish_app_event) { - _E("Function symbol(event_publish_app_event) did not initialized"); - throw InvalidIOException(); - } int ret = event_publish_app_event(GetEventName().c_str(), b); if (ret != 0) { _E("Failed to publish event. result(%d)", ret); @@ -523,10 +471,6 @@ void PkgSignal::AsyncResultForResource(std::string signal, int targetUid, } std::lock_guard<std::recursive_mutex> lock(mutex_); - if (!event_publish_app_event) { - _E("Function symbol(event_publish_app_event) did not initialized"); - throw InvalidIOException(); - } int ret = event_publish_app_event(GetEventName().c_str(), b); if (ret != 0) { _E("Failed to publish event. result(%d)", ret); @@ -559,10 +503,6 @@ void PkgSignal::AsyncResultForPkgUpgrade(std::string signal, int progress) { } std::lock_guard<std::recursive_mutex> lock(mutex_); - if (!event_publish_app_event) { - _E("Function symbol(event_publish_app_event) did not initialized"); - throw InvalidIOException(); - } int ret = event_publish_app_event(GetEventName().c_str(), b); if (ret != 0) { _E("Failed to publish event. result(%d)", ret); diff --git a/installer/CMakeLists.txt b/installer/CMakeLists.txt index 5a238d4..9332cff 100644 --- a/installer/CMakeLists.txt +++ b/installer/CMakeLists.txt @@ -9,6 +9,7 @@ PKG_CHECK_MODULES(INSTALLER_DEPS REQUIRED pkgmgr-info libtzplatform-config rpc-port + tizen-libopener ) FOREACH(FLAGS ${INSTALLER_DEPS_CFLAGS}) diff --git a/installer/src/PkgSignal.cc b/installer/src/PkgSignal.cc index 4267fda..91c2fc9 100644 --- a/installer/src/PkgSignal.cc +++ b/installer/src/PkgSignal.cc @@ -9,6 +9,8 @@ #include <dlog.h> #include <stdlib.h> +#include <libopener.hpp> + #ifdef LOG_TAG #undef LOG_TAG #endif @@ -62,68 +64,23 @@ using event_cb = void (*)(const char*, bundle*, void*); 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_); - } +tizen_base::LibOpener app_event_lib(kPathLibAppEventCore); - bool IsLoaded() { return loaded_; } +auto* event_add_event_handler = + app_event_lib.Bind<int (*)(const char*, event_cb, void*, event_handler_h*)>( + "event_add_event_handler"); +auto* event_remove_event_handler = + app_event_lib.Bind<int (*)(event_handler_h)>("event_remove_event_handler"); - private: - bool loaded_ = false; - void* handle_ = nullptr; -}; - -static AppEvent app_event; +auto* event_publish_app_event = + app_event_lib.Bind<int (*)(const char*, bundle*)>( + "event_publish_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) { +extern "C" int event_add_event_handler(const char* event_name, + event_cb callback, void* user_data, + event_handler_h* event_handler) { return 0; } @@ -131,8 +88,8 @@ 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) { +extern "C" int event_publish_app_event(const char* event_name, + bundle* event_data) { return 0; } @@ -301,17 +258,12 @@ rpc_port_parcel_h operator>>(rpc_port_parcel_h h, std::vector<PkgInfo>& param) { } PkgSignal::PkgSignal(std::string sender_appid, bool is_system) - : sender_appid_(std::move(sender_appid)), is_system_(is_system) { -} + : sender_appid_(std::move(sender_appid)), is_system_(is_system) {} PkgSignal::~PkgSignal() { Unsubscribe(); } void PkgSignal::Subscribe() { std::lock_guard<std::recursive_mutex> lock(mutex_); - if (!event_add_event_handler) { - _E("Function symbol(event_add_event_handler) did not initialized"); - throw InvalidIOException(); - } int ret = event_add_event_handler(GetEventName().c_str(), EventCb, this, &event_handler_); @@ -323,8 +275,7 @@ void PkgSignal::Subscribe() { void PkgSignal::Unsubscribe() { std::lock_guard<std::recursive_mutex> lock(mutex_); if (event_handler_) { - if (event_remove_event_handler) - event_remove_event_handler(event_handler_); + event_remove_event_handler(event_handler_); event_handler_ = nullptr; } } @@ -480,10 +431,6 @@ void PkgSignal::AsyncResult(std::string signal, int targetUid, } std::lock_guard<std::recursive_mutex> lock(mutex_); - if (!event_publish_app_event) { - _E("Function symbol(event_publish_app_event) did not initialized"); - throw InvalidIOException(); - } int ret = event_publish_app_event(GetEventName().c_str(), b); if (ret != 0) { _E("Failed to publish event. result(%d)", ret); @@ -522,10 +469,6 @@ void PkgSignal::AsyncResultForResource(std::string signal, int targetUid, } std::lock_guard<std::recursive_mutex> lock(mutex_); - if (!event_publish_app_event) { - _E("Function symbol(event_publish_app_event) did not initialized"); - throw InvalidIOException(); - } int ret = event_publish_app_event(GetEventName().c_str(), b); if (ret != 0) { _E("Failed to publish event. result(%d)", ret); @@ -558,10 +501,6 @@ void PkgSignal::AsyncResultForPkgUpgrade(std::string signal, int progress) { } std::lock_guard<std::recursive_mutex> lock(mutex_); - if (!event_publish_app_event) { - _E("Function symbol(event_publish_app_event) did not initialized"); - throw InvalidIOException(); - } int ret = event_publish_app_event(GetEventName().c_str(), b); if (ret != 0) { _E("Failed to publish event. result(%d)", ret); diff --git a/packaging/pkgmgr.spec b/packaging/pkgmgr.spec index 602a56b..41243ee 100644 --- a/packaging/pkgmgr.spec +++ b/packaging/pkgmgr.spec @@ -35,6 +35,7 @@ BuildRequires: pkgconfig(libsystemd) BuildRequires: pkgconfig(minizip) BuildRequires: pkgconfig(rpc-port) BuildRequires: pkgconfig(gmock) +BuildRequires: pkgconfig(tizen-libopener) BuildRequires: pkgmgr-info-parser-devel BuildRequires: pkgmgr-info-parser BuildRequires: fdupes |