From 5e622b967bbcffd42a99ad5f56a0a2a83a20303b Mon Sep 17 00:00:00 2001 From: Junghyun Yeon Date: Tue, 30 Jul 2019 16:32:17 +0900 Subject: [PATCH] Add Foreach depdency API for Archiveinfo Related changes: [slp-pkgmgr] : https://review.tizen.org/gerrit/211114 [tpk-backend] : https://review.tizen.org/gerrit/211115 Change-Id: Ica6096e09c9fb5e124d12d2e85b41a2f0eefced9 Signed-off-by: Junghyun Yeon --- include/pkgmgr-info.h | 38 ++++++++++++++++++++++++++++++++++++++ include/pkgmgrinfo_type.h | 4 +++- src/pkgmgrinfo_archiveinfo.c | 29 +++++++++++++++++++++++++++++ src/pkgmgrinfo_private.h | 8 ++++++++ 4 files changed, 78 insertions(+), 1 deletion(-) diff --git a/include/pkgmgr-info.h b/include/pkgmgr-info.h index ef09573..8fac17b 100644 --- a/include/pkgmgr-info.h +++ b/include/pkgmgr-info.h @@ -6901,6 +6901,44 @@ int pkgmgrinfo_archiveinfo_get_icon(pkgmgrinfo_archiveinfo_h handle, const unsigned char **icon, size_t *size); /** + * @fn int pkgmgrinfo_archiveinfo_foreach_dependency(pkgmgrinfo_archiveinfo_h handle, pkgmgrinfo_dependency_cb callback, void *user_data) + * @brief This API retrieve the dependency information and invoke given callback for it. + * + * @par This API is for package-manager client application + * @par Sync (or) Async : Synchronous API + * + * @param[in] handle pointer to package archive info handle + * @param[in] callback callback to be invoked for each retrieved dependency information + * @param[in] user_data user data to be passed to callback + * @return 0 if success, error code(<0) if fail + * @retval PMINFO_R_OK success + * @retval PMINFO_R_EINVAL invalid argument + * @retval PMINFO_R_ERROR internal error + * @pre pkgmgrinfo_archiveinfo_get_archiveinfo() + * @post pkgmgrinfo_archiveinfo_destroy_archiveinfo() + * @code +static int get_pkg_archive_dependency(const char *path, pkgmgrinfo_pkg_dependency_list_cb callback) +{ + int ret = 0; + size_t icon_size = 0; + pkgmgrinfo_archiveinfo_h handle; + ret = pkgmgrinfo_archiveinfo_get_archiveinfo(path, &handle); + if (ret != PMINFO_R_OK) + return -1; + ret = pkgmgrinfo_archiveinfo_foreach_dependency(handle, callback, NULL); + if (ret != PMINFO_R_OK) { + pkgmgrinfo_archiveinfo_destroy_archiveinfo(handle); + return -1; + } + pkgmgrinfo_archiveinfo_destroy_archiveinfo(handle); + return 0; +} + * @endcode + */ +int pkgmgrinfo_archiveinfo_foreach_dependency(pkgmgrinfo_archiveinfo_h handle, + pkgmgrinfo_pkg_dependency_list_cb callback, void *user_data); + +/** * @pkgmgrinfo client API end **/ diff --git a/include/pkgmgrinfo_type.h b/include/pkgmgrinfo_type.h index 6e8c1f3..f65ad48 100644 --- a/include/pkgmgrinfo_type.h +++ b/include/pkgmgrinfo_type.h @@ -326,7 +326,7 @@ typedef int (*pkgmgrinfo_pkg_appdefined_privilege_list_cb) (const char *privileg /** * @fn int (*pkgmgrinfo_pkg_dependency_list_cb) (const char *from, const char *to, const char *type, const char *required_version, void *user_data) * - * @brief Specifies the dependency info of given package passed to pkgmgrinfo_pkginfo_foreach_dependency() or pkgmgrinfo_pkginfo_foreach_required_by() + * @brief Specifies the dependency info of given package passed to pkgmgrinfo_pkginfo_foreach_dependency(), pkgmgrinfo_pkginfo_foreach_required_by(), pkgmgrinfo_archiveinfo_foreach_dependency() * * @param[in] from the pkgid which depends other package * @param[in] to the pkgid which has dependency with given package @@ -449,6 +449,8 @@ typedef int (*pkgmgrinfo_app_splash_screen_list_cb)(const char *src, const char *indicatordisplay, const char *operation, const char *color_depth, void *user_data); + + /** * @brief Install Location Types */ diff --git a/src/pkgmgrinfo_archiveinfo.c b/src/pkgmgrinfo_archiveinfo.c index 33c5cd3..d020661 100644 --- a/src/pkgmgrinfo_archiveinfo.c +++ b/src/pkgmgrinfo_archiveinfo.c @@ -80,6 +80,8 @@ API int pkgmgrinfo_archiveinfo_destroy_archiveinfo( } free(info->icon_buf); + g_list_free_full(info->privilege_list, free); + g_list_free_full(info->dependency_list, free); free(info); return PMINFO_R_OK; @@ -226,3 +228,30 @@ API int pkgmgrinfo_archiveinfo_get_icon(pkgmgrinfo_archiveinfo_h handle, return PMINFO_R_OK; } + +API int pkgmgrinfo_archiveinfo_foreach_dependency( + pkgmgrinfo_archiveinfo_h handle, + pkgmgrinfo_pkg_dependency_list_cb callback, void *user_data) +{ + GList *tmp; + pkg_dependency_info_t *dependency_info; + package_manager_pkg_detail_info_t *info = + (package_manager_pkg_detail_info_t *)handle; + + if (info == NULL || callback == NULL) { + _LOGE("invalid parameter"); + return PMINFO_R_EINVAL; + } + + for (tmp = info->dependency_list; tmp != NULL; + tmp = g_list_next(tmp)) { + dependency_info = (pkg_dependency_info_t *)tmp->data; + if (callback(info->pkgid, + dependency_info->pkgid, + dependency_info->type, + dependency_info->required_version, + user_data) != 0) + return PMINFO_R_ERROR; + } + return PMINFO_R_OK; +} diff --git a/src/pkgmgrinfo_private.h b/src/pkgmgrinfo_private.h index 9d581b5..47746bd 100644 --- a/src/pkgmgrinfo_private.h +++ b/src/pkgmgrinfo_private.h @@ -238,6 +238,7 @@ typedef struct _db_handle { #define PKG_URL_STRING_LEN_MAX 1024 #define PKG_LABEL_STRING_LEN_MAX 128 #define PKG_PATH_STRING_LEN_MAX 512 +#define PKG_DEP_TYPE_STRING_LEN_MAX 128 typedef struct _package_manager_pkg_info_t { char pkg_type[PKG_TYPE_STRING_LEN_MAX]; @@ -247,6 +248,12 @@ typedef struct _package_manager_pkg_info_t { struct _package_manager_pkg_info_t *next; } package_manager_pkg_info_t; +typedef struct _package_manager_pkg_dependency_info_t { + char pkgid[PKG_NAME_STRING_LEN_MAX]; + char type[PKG_DEP_TYPE_STRING_LEN_MAX]; + char required_version[PKG_VERSION_STRING_LEN_MAX]; +} pkg_dependency_info_t; + typedef struct _package_manager_pkg_detail_info_t { char pkg_type[PKG_TYPE_STRING_LEN_MAX]; char pkg_name[PKG_NAME_STRING_LEN_MAX]; @@ -266,6 +273,7 @@ typedef struct _package_manager_pkg_detail_info_t { char *icon_buf; int icon_size; GList *privilege_list; + GList *dependency_list; } package_manager_pkg_detail_info_t; typedef void (*_pkg_plugin_unload)(void); -- 2.7.4