Add new APIs retrieving package dependency info from archive 26/212226/8
authorIlho Kim <ilho159.kim@samsung.com>
Mon, 19 Aug 2019 05:16:14 +0000 (14:16 +0900)
committerilho kim <ilho159.kim@samsung.com>
Wed, 4 Sep 2019 08:09:25 +0000 (08:09 +0000)
Change-Id: I8ad177827d7f1c5b4799867f2de85f26f8e18fff
Signed-off-by: Ilho Kim <ilho159.kim@samsung.com>
include/package_archive_info.h
src/package_archive_info.c

index 761538a..44dd114 100644 (file)
@@ -17,6 +17,8 @@
 #ifndef __TIZEN_APPFW_PACKAGE_ARCHIVE_INFO_H
 #define __TIZEN_APPFW_PACKAGE_ARCHIVE_INFO_H
 
+#include <package_info.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -197,6 +199,34 @@ int package_archive_info_get_author(package_archive_info_h archive_info,
 int package_archive_info_get_icon(package_archive_info_h archive_info,
                unsigned char **icon, size_t *icon_size);
 
+/**
+ * @brief Retrieves direct dependencies of the given package.
+ * @details package_info_dependency_info_cb() is called for each direct dependency of the given package.
+ *          For example, if there are packages having the following relationship:
+ *
+ * <pre>
+ *                B --> E
+ *          A --> B --> C
+ *                D --> C
+ * </pre>
+ * A --> B means that A depends on B.
+ *
+ * If package_archive_info_foreach_direct_dependency(A) is called, the callback will be called once with the following argument values: @e from = A, @e to = B.
+ * @since_tizen 5.5
+ * @remarks The function provides the results synchronously. If there are no dependencies, this function will return PACKAGE_MANAGER_ERROR_NONE immediately and the callback will not be invoked.
+ * @param[in] archive_info The package archive information
+ * @param[in] callback     The iteration callback function
+ * @param[in] user_data    The user data to be passed to the callback function
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #PACKAGE_MANAGER_ERROR_NONE              Successful
+ * @retval #PACKAGE_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #PACKAGE_MANAGER_ERROR_SYSTEM_ERROR      Severe system error
+ */
+int package_archive_info_foreach_direct_dependency(
+               package_archive_info_h archive_info,
+               package_info_dependency_info_cb callback, void *user_data);
+
 
 /**
 * @}
index 19df899..153fe76 100644 (file)
@@ -26,6 +26,11 @@ struct package_archive_info_s {
        pkgmgrinfo_archiveinfo_h archive_info;
 };
 
+struct foreach_dependency_s {
+       package_info_dependency_info_cb callback;
+       void *user_data;
+};
+
 API int package_archive_info_create(const char *path,
                package_archive_info_h *archive_info)
 {
@@ -296,3 +301,44 @@ API int package_archive_info_get_icon(package_archive_info_h archive_info,
 
        return PACKAGE_MANAGER_ERROR_NONE;
 }
+
+static int package_archive_info_foreach_dependency_cb(const char *from,
+               const char *to, const char *type,
+               const char *required_version, void *user_data)
+{
+       struct foreach_dependency_s *foreach_dependency =
+                       (struct foreach_dependency_s *)user_data;
+
+       if (!foreach_dependency->callback(from, to, type,
+                       required_version, foreach_dependency->user_data))
+               return -1;
+       else
+               return 0;
+}
+
+API int package_archive_info_foreach_direct_dependency(
+               package_archive_info_h archive_info,
+               package_info_dependency_info_cb callback, void *user_data)
+{
+       int ret;
+       struct package_archive_info_s *info =
+                       (struct package_archive_info_s *)archive_info;
+       struct foreach_dependency_s foreach_dependency = {
+               .callback = callback,
+               .user_data = user_data,
+       };
+
+       if (archive_info == NULL || callback == NULL) {
+               _LOGE("Invalid parameter");
+               return PACKAGE_MANAGER_ERROR_INVALID_PARAMETER;
+       }
+
+       ret = pkgmgrinfo_archiveinfo_foreach_dependency(info->archive_info,
+                       package_archive_info_foreach_dependency_cb, &foreach_dependency);
+       if (ret == PMINFO_R_EINVAL)
+               return PACKAGE_MANAGER_ERROR_INVALID_PARAMETER;
+       else if (ret == PMINFO_R_ERROR)
+               return PACKAGE_MANAGER_ERROR_SYSTEM_ERROR;
+
+       return PACKAGE_MANAGER_ERROR_NONE;
+}