Fix build error
[platform/core/appfw/pkgmgr-info.git] / src / pkgmgrinfo_pkginfo.c
index 439a59e..32de01c 100644 (file)
@@ -39,6 +39,7 @@
 #include "pkgmgrinfo_private.h"
 #include "pkgmgrinfo_debug.h"
 #include "pkgmgr-info.h"
+#include "manager/pkginfo_manager.h"
 
 static bool _get_bool_value(const char *str)
 {
@@ -151,19 +152,23 @@ static int _pkginfo_get_filtered_foreach_pkginfo(uid_t uid,
                if (ret != PMINFO_R_OK) {
                        _LOGE("Failed to add filter");
                        g_hash_table_destroy(list);
-                       if (filter == NULL)
-                               pkgmgrinfo_pkginfo_filter_destroy(filter);
                        return PMINFO_R_ERROR;
                }
        }
 
-       // TODO: use pkginfo-client APIs.
+       ret = _pkginfo_get_packages(uid, filter, flag, list);
+       pkgmgrinfo_pkginfo_filter_destroy(filter);
+       if (ret != PMINFO_R_OK) {
+               g_hash_table_destroy(list);
+               return PMINFO_R_ERROR;
+       }
+
        g_hash_table_iter_init(&iter, list);
        while (g_hash_table_iter_next(&iter, NULL, &value)) {
                pkg = (package_x *)value;
                info.uid = uid;
                info.pkg_info = pkg;
-               //info.locale = locale;
+               info.locale = pkg->locale;
                if (pkg_list_cb(&info, user_data) < 0)
                        break;
        }
@@ -173,13 +178,68 @@ static int _pkginfo_get_filtered_foreach_pkginfo(uid_t uid,
        return PMINFO_R_OK;
 }
 
+static int _pkgmgrinfo_get_pkginfo(const char *pkgid, uid_t uid,
+       pkgmgrinfo_pkginfo_filter_h filter, pkgmgrinfo_pkginfo_h *handle)
+{
+       int ret;
+       GHashTable *list;
+       pkgmgr_pkginfo_x *info;
+
+       if (pkgid == NULL || filter == NULL || handle == NULL) {
+                       LOGE("invalid parameter");
+                       return PMINFO_R_EINVAL;
+       }
+
+       list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
+                       __free_packages);
+       if (list == NULL)
+               return PMINFO_R_ERROR;
+
+       ret = _pkginfo_get_packages(uid, filter, PMINFO_PKGINFO_GET_ALL, list);
+       if (ret != PMINFO_R_OK) {
+               g_hash_table_destroy(list);
+               return ret;
+       }
+
+       if (!g_hash_table_size(list)) {
+               _LOGD("pkginfo for [%s] is not existed for user [%d]",
+                               pkgid, uid);
+               g_hash_table_destroy(list);
+               return PMINFO_R_ENOENT;
+       }
+
+       info = calloc(1, sizeof(pkgmgr_pkginfo_x));
+       if (info == NULL) {
+               _LOGE("out of memory");
+               g_hash_table_destroy(list);
+               return PMINFO_R_ERROR;
+       }
+
+       info->uid = uid;
+       info->pkg_info = (package_x *)g_hash_table_lookup(list, pkgid);
+       info->locale = strdup(info->pkg_info->locale);
+       if (info->locale == NULL) {
+               _LOGE("Out of memory");
+               g_hash_table_destroy(list);
+               free(info);
+               return PMINFO_R_ERROR;
+       }
+
+       /* just free list only */
+       g_hash_table_steal(list, (gconstpointer)pkgid);
+       g_hash_table_destroy(list);
+
+       *handle = info;
+
+       return ret;
+}
+
 API int pkgmgrinfo_pkginfo_get_usr_pkginfo(const char *pkgid, uid_t uid,
                pkgmgrinfo_pkginfo_h *handle)
 {
        int ret;
        pkgmgrinfo_pkginfo_filter_h filter;
        GHashTable *list;
-       pkgmgr_pkginfo_x *info;
 
        if (pkgid == NULL || handle == NULL) {
                LOGE("invalid parameter");
@@ -208,33 +268,9 @@ API int pkgmgrinfo_pkginfo_get_usr_pkginfo(const char *pkgid, uid_t uid,
                pkgmgrinfo_pkginfo_filter_destroy(filter);
                return PMINFO_R_ERROR;
        }
-
-       /* TODO: use pkginfo-client APIs to get pkginfo using filter. */
-
-
-
-
+       ret = _pkgmgrinfo_get_pkginfo(pkgid, uid, filter, handle);
        pkgmgrinfo_pkginfo_filter_destroy(filter);
 
-       info = calloc(1, sizeof(pkgmgr_pkginfo_x));
-       if (info == NULL) {
-               _LOGE("out of memory");
-               g_hash_table_destroy(list);
-               return PMINFO_R_ERROR;
-       }
-
-       info->uid = uid;
-       info->pkg_info = (package_x *)g_hash_table_lookup(list, pkgid);
-
-       // TODO: Each parcel will have locale. Use pkginfo-client APIs to get it.
-       //info->locale = locale;
-
-       /* just free list only */
-       g_hash_table_steal(list, (gconstpointer)pkgid);
-       g_hash_table_destroy(list);
-
-       *handle = info;
-
        return ret;
 }
 
@@ -248,9 +284,7 @@ API int pkgmgrinfo_pkginfo_get_usr_disabled_pkginfo(const char *pkgid,
                uid_t uid, pkgmgrinfo_pkginfo_h *handle)
 {
        int ret;
-       GHashTable *list;
        pkgmgrinfo_pkginfo_filter_h filter;
-       pkgmgr_pkginfo_x *info;
 
        if (pkgid == NULL || handle == NULL) {
                LOGE("invalid parameter");
@@ -276,40 +310,11 @@ API int pkgmgrinfo_pkginfo_get_usr_disabled_pkginfo(const char *pkgid,
                return PMINFO_R_ERROR;
        }
 
-       list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
-                       __free_packages);
-       if (list == NULL) {
-               pkgmgrinfo_pkginfo_filter_destroy(filter);
-               return PMINFO_R_ERROR;
-       }
-
-       // TODO: use pkginfo-client APIs.
-
-       pkgmgrinfo_pkginfo_filter_destroy(filter);
-       if (!g_hash_table_size(list)) {
-               _LOGD("disabled pkginfo for [%s] is not existed for user [%d]",
+       ret = _pkgmgrinfo_get_pkginfo(pkgid, uid, filter, handle);
+       if (ret == PMINFO_R_ENOENT)
+               LOGE("disabled pkginfo for [%s] is not existed for user [%d]",
                                pkgid, uid);
-               g_hash_table_destroy(list);
-               return PMINFO_R_ENOENT;
-       }
-
-       info = calloc(1, sizeof(pkgmgr_pkginfo_x));
-       if (info == NULL) {
-               _LOGE("out of memory");
-               g_hash_table_destroy(list);
-               return PMINFO_R_ERROR;
-       }
-
-       info->uid = uid;
-       info->pkg_info = (package_x *)g_hash_table_lookup(list, pkgid);
-       //info->locale = locale;
-
-       /* just free list only */
-       g_hash_table_steal(list, (gconstpointer)pkgid);
-       g_hash_table_destroy(list);
-
-       *handle = info;
-
+       pkgmgrinfo_pkginfo_filter_destroy(filter);
        return ret;
 }
 
@@ -342,7 +347,7 @@ API int pkgmgrinfo_pkginfo_get_usr_all_pkginfo(const char *pkgid, uid_t uid,
                return PMINFO_R_ERROR;
        }
 
-       // TODO: use pkginfo-client APIs.
+       ret = _pkgmgrinfo_get_pkginfo(pkgid, uid, filter, handle);
        pkgmgrinfo_pkginfo_filter_destroy(filter);
 
        return ret;
@@ -1320,7 +1325,11 @@ API int pkgmgrinfo_pkginfo_usr_filter_count(pkgmgrinfo_pkginfo_filter_h handle,
                }
        }
 
-       // TODO: use pkginfo-client APIs to get pkginfo list
+       ret = _pkginfo_get_packages(uid, handle, PMINFO_PKGINFO_GET_BASICINFO, list);
+       if (ret != PMINFO_R_OK) {
+               g_hash_table_destroy(list);
+               return PMINFO_R_ERROR;
+       }
        *count = g_hash_table_size(list);
 
        g_hash_table_destroy(list);