Move initialization of hash table into db handlers
authorJunghyun Yeon <jungh.yeon@samsung.com>
Thu, 11 Mar 2021 02:08:00 +0000 (11:08 +0900)
committer연정현/Tizen Platform Lab(SR)/Staff Engineer/삼성전자 <jungh.yeon@samsung.com>
Thu, 11 Mar 2021 05:45:23 +0000 (14:45 +0900)
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
src/appinfo_internal.c
src/common/database/appinfo_db_handler.cc
src/pkgmgrinfo_internal.h

index d143c95..1ae8044 100644 (file)
 #include "pkgmgr_parser.h"
 #include "pkgmgrinfo_internal.h"
 
-static int __free_applications(gpointer key, gpointer value,
-                               gpointer user_data) {
-  pkgmgrinfo_basic_free_application((application_x *)value);
-  return 0;
-}
-
 static void __parse_appcontrol(GList **appcontrol, char *appcontrol_str,
                                char *visibility, char *id) {
   char *dup;
@@ -665,36 +659,25 @@ static int _appinfo_get_applications(sqlite3 *db, uid_t db_uid, uid_t uid,
 API int appinfo_internal_filter_get_list(sqlite3 *db,
                                          pkgmgrinfo_appinfo_filter_h filter,
                                          uid_t uid, const char *locale,
-                                         GHashTable **appinfo_list) {
+                                         GHashTable *appinfo_list) {
   int ret;
-  GHashTable *list;
 
   if (db == NULL || filter == NULL || appinfo_list == NULL) {
     // TODO: add log
     return PMINFO_R_EINVAL;
   }
 
-  list = g_hash_table_new(g_str_hash, g_str_equal);
-  if (list == NULL) return PMINFO_R_ERROR;
-
   ret = _appinfo_get_applications(db, uid, uid, locale, filter,
-                                  PMINFO_APPINFO_GET_ALL, list);
-  if (!g_hash_table_size(list) && uid != GLOBAL_USER)
+                                  PMINFO_APPINFO_GET_ALL, appinfo_list);
+  if (!g_hash_table_size(appinfo_list) && uid != GLOBAL_USER)
     ret = _appinfo_get_applications(db, GLOBAL_USER, uid, locale, filter,
-                                    PMINFO_APPINFO_GET_ALL, list);
+                                    PMINFO_APPINFO_GET_ALL, appinfo_list);
 
-  if (ret != PMINFO_R_OK) {
-    g_hash_table_foreach_remove(list, __free_applications, NULL);
-    g_hash_table_destroy(list);
+  if (ret != PMINFO_R_OK)
     return ret;
-  }
 
-  if (!g_hash_table_size(list)) {
-    // TODO: add logs that failed to find appid
-    g_hash_table_destroy(list);
+  if (!g_hash_table_size(appinfo_list))
     return PMINFO_R_ENOENT;
-  }
 
-  *appinfo_list = list;
   return ret;
 }
index 35c49bf..a31d67a 100644 (file)
@@ -18,6 +18,7 @@
 
 #include <vector>
 
+#include "pkgmgrinfo_basic.h"
 #include "pkgmgrinfo_internal.h"
 #include "pkgmgrinfo_debug.h"
 
@@ -53,14 +54,16 @@ int AppInfoDBHandler::Execute() {
   SetDBType(DB_TYPE_FILE_PKGDB);
   if (!Connect()) return PMINFO_R_ERROR;
 
-  GHashTable* list = nullptr;
+  GHashTable* list = g_hash_table_new_full(g_str_hash, g_str_equal,
+      NULL, NULL);
   std::vector<sqlite3*> conn_list = GetConnection();
   int ret = PMINFO_R_OK;
   for (auto conn : conn_list) {
     ret = appinfo_internal_filter_get_list(conn, filter_, uid_,
-                                             GetLocale().c_str(), &list);
+                                             GetLocale().c_str(), list);
     if (ret == PMINFO_R_ERROR) {
       _LOGE("Failed to appinfo_internal_filter_get_list (%d)", ret);
+      g_hash_table_destroy(list);
       break;
     }
   }
index ad499c2..5ec49aa 100644 (file)
@@ -33,7 +33,7 @@ extern "C" {
 
 // TODO: should we get sqlite handle as parameter??
 int pkginfo_internal_filter_get_list(sqlite3 *db, pkgmgrinfo_pkginfo_filter_h filter, uid_t uid, const char *locale, GHashTable **list);
-int appinfo_internal_filter_get_list(sqlite3 *db, pkgmgrinfo_appinfo_filter_h filter, uid_t uid, const char *locale, GHashTable **list);
+int appinfo_internal_filter_get_list(sqlite3 *db, pkgmgrinfo_appinfo_filter_h filter, uid_t uid, const char *locale, GHashTable *list);
 int certinfo_internal_get(sqlite3 *db, const char *pkgid, uid_t uid, pkgmgrinfo_certinfo_h certinfo);
 int certinfo_internal_set(sqlite3 *db, const char *pkgid, pkgmgrinfo_instcertinfo_h handle, uid_t uid);
 int certinfo_internal_delete(sqlite3 *db, const char *pkgid);