Porting from eina_list to g_list 44/168244/2
authorSeungha Son <seungha.son@samsung.com>
Thu, 25 Jan 2018 04:57:36 +0000 (13:57 +0900)
committerSeungha Son <seungha.son@samsung.com>
Thu, 25 Jan 2018 07:06:35 +0000 (16:06 +0900)
Signed-off-by: Seungha Son <seungha.son@samsung.com>
Change-Id: Iac02cee39e0ddc21890e34a4cfa83747065c706d

CMakeLists.txt
packaging/data-provider-master.spec
src/pkgmgr.c

index 561fe97..e32091e 100644 (file)
@@ -17,8 +17,6 @@ pkg_check_modules(pkg REQUIRED
        gio-2.0
        gio-unix-2.0
        bundle
-       ecore
-       eina
        pkgmgr
        notification
        badge
index f07d5f0..becd7c6 100755 (executable)
@@ -21,8 +21,6 @@ BuildRequires: pkgconfig(gio-unix-2.0)
 BuildRequires: pkgconfig(libsmack)
 BuildRequires: pkgconfig(bundle)
 BuildRequires: pkgconfig(capi-appfw-app-manager)
-BuildRequires: pkgconfig(ecore)
-BuildRequires: pkgconfig(eina)
 BuildRequires: pkgconfig(pkgmgr)
 BuildRequires: pkgconfig(pkgmgr-info)
 BuildRequires: pkgconfig(notification)
index 09f4495..56c3c1c 100755 (executable)
 #include <dlog.h>
 #include <package-manager.h>
 
-#include <Ecore.h>
 #include "service_common.h"
 #include "debug.h"
 #include "pkgmgr.h"
 #include "conf.h"
 
+#define PKGMGR_EVENT_MIN PKGMGR_EVENT_DOWNLOAD
+#define PKGMGR_EVENT_MAX PKGMGR_EVENT_APP_DISABLE
+
 struct item {
        uid_t uid;
        char *pkgname;
@@ -36,139 +38,31 @@ struct item {
        enum pkgmgr_status status;
 };
 
-static struct {
-       pkgmgr_client *listen_pc;
-       Eina_List *item_list;
-
-       Eina_List *install_event;
-       Eina_List *uninstall_event;
-       Eina_List *update_event;
-       Eina_List *download_event;
-       Eina_List *recover_event;
-       Eina_List *app_enable_event;
-       Eina_List *app_disable_event;
-} s_info = {
-       .listen_pc = NULL,
-       .item_list = NULL,
-
-       .install_event = NULL,
-       .uninstall_event = NULL,
-       .update_event = NULL,
-       .download_event = NULL,
-       .recover_event = NULL,
-       .app_enable_event = NULL,
-       .app_disable_event = NULL,
-};
-
 struct event_item {
        int (*cb)(uid_t uid, const char *pkgname, enum pkgmgr_status status, double value, void *data);
        void *data;
 };
 
-static inline void invoke_install_event_handler(uid_t uid, const char *pkgname, enum pkgmgr_status status, double value)
-{
-       Eina_List *l;
-       struct event_item *item;
-
-       EINA_LIST_FOREACH(s_info.install_event, l, item) {
-               if (item->cb)
-                       item->cb(uid, pkgname, status, value, item->data);
-       }
-}
-
-static inline void invoke_uninstall_event_handler(uid_t uid, const char *pkgname, enum pkgmgr_status status, double value)
-{
-       Eina_List *l;
-       struct event_item *item;
-
-       EINA_LIST_FOREACH(s_info.uninstall_event, l, item) {
-               if (item->cb)
-                       item->cb(uid, pkgname, status, value, item->data);
-       }
-}
-
-static inline void invoke_update_event_handler(uid_t uid, const char *pkgname, enum pkgmgr_status status, double value)
-{
-       Eina_List *l;
-       struct event_item *item;
-
-       EINA_LIST_FOREACH(s_info.update_event, l, item) {
-               if (item->cb)
-                       item->cb(uid, pkgname, status, value, item->data);
-       }
-}
-
-static inline void invoke_download_event_handler(uid_t uid, const char *pkgname, enum pkgmgr_status status, double value)
-{
-       Eina_List *l;
-       struct event_item *item;
-
-       EINA_LIST_FOREACH(s_info.download_event, l, item) {
-               if (item->cb)
-                       item->cb(uid, pkgname, status, value, item->data);
-       }
-}
-
-static inline void invoke_recover_event_handler(uid_t uid, const char *pkgname, enum pkgmgr_status status, double value)
-{
-       Eina_List *l;
-       struct event_item *item;
-
-       EINA_LIST_FOREACH(s_info.recover_event, l, item) {
-               if (item->cb)
-                       item->cb(uid, pkgname, status, value, item->data);
-       }
-}
-
-static inline void invoke_app_enable_event_handler(uid_t uid, const char *pkgname, enum pkgmgr_status status, double value)
-{
-       Eina_List *l;
-       struct event_item *item;
-
-       EINA_LIST_FOREACH(s_info.app_enable_event, l, item) {
-               if (item->cb)
-                       item->cb(uid, pkgname, status, value, item->data);
-       }
-}
+static struct {
+       pkgmgr_client *listen_pc;
+       GList *item_list;
 
-static inline void invoke_app_disable_event_handler(uid_t uid, const char *pkgname, enum pkgmgr_status status, double value)
-{
-       Eina_List *l;
-       struct event_item *item;
+} s_info = {
+       .listen_pc = NULL,
+       .item_list = NULL,
+};
 
-       EINA_LIST_FOREACH(s_info.app_disable_event, l, item) {
-               if (item->cb)
-                       item->cb(uid, pkgname, status, value, item->data);
-       }
-}
+static GList *event_list[PKGMGR_EVENT_MAX + 1];
 
 static inline void invoke_callback(uid_t uid, const char *pkgname, struct item *item, double value)
 {
-       switch (item->type) {
-       case PKGMGR_EVENT_DOWNLOAD:
-               invoke_download_event_handler(uid, pkgname, item->status, value);
-               break;
-       case PKGMGR_EVENT_UNINSTALL:
-               invoke_uninstall_event_handler(uid, pkgname, item->status, value);
-               break;
-       case PKGMGR_EVENT_INSTALL:
-               invoke_install_event_handler(uid, pkgname, item->status, value);
-               break;
-       case PKGMGR_EVENT_UPDATE:
-               invoke_update_event_handler(uid, pkgname, item->status, value);
-               break;
-       case PKGMGR_EVENT_RECOVER:
-               invoke_recover_event_handler(uid, pkgname, item->status, value);
-               break;
-       case PKGMGR_EVENT_APP_ENABLE:
-               invoke_app_enable_event_handler(uid, pkgname, item->status, value);
-               break;
-       case PKGMGR_EVENT_APP_DISABLE:
-               invoke_app_disable_event_handler(uid, pkgname, item->status, value);
-               break;
-       default:
-               ERR("Unknown type: %d", item->type);
-               break;
+       GList *l;
+       struct event_item *e_item;
+
+       for (l = event_list[item->type]; l != NULL; l = g_list_next(l)) {
+               e_item = (struct event_item *)g_list_nth_data(l, 0);
+               if (e_item->cb)
+                       e_item->cb(uid, pkgname, item->status, value, e_item->data);
        }
 }
 
@@ -207,7 +101,7 @@ static inline int is_valid_status(struct item *item, const char *status)
 
 static struct item *find_item(const char *pkgname, uid_t uid)
 {
-       Eina_List *l;
+       GList *l;
        struct item *item;
 
        if (!pkgname) {
@@ -215,7 +109,8 @@ static struct item *find_item(const char *pkgname, uid_t uid)
                return NULL;
        }
 
-       EINA_LIST_FOREACH(s_info.item_list, l, item) {
+       for (l = s_info.item_list; l != NULL; l = g_list_next(l)) {
+               item = g_list_nth_data(l, 0);
                if (uid != item->uid || strcmp(item->pkgname, pkgname))
                        continue;
 
@@ -268,7 +163,7 @@ static int start_cb(uid_t uid, const char *pkgname, const char *val, void *data)
                ERR("Invalid val [%s]", val);
                return SERVICE_COMMON_ERROR_INVALID_PARAMETER;
        }
-       s_info.item_list = eina_list_append(s_info.item_list, item);
+       s_info.item_list = g_list_append(s_info.item_list, item);
 
        invoke_callback(uid, pkgname, item, 0.0f);
        return SERVICE_COMMON_ERROR_NONE;
@@ -391,7 +286,7 @@ static int download_cb(uid_t uid, const char *pkgname, const char *val, void *da
                value = (double)SERVICE_COMMON_ERROR_INVALID_PARAMETER;
        }
 
-       invoke_download_event_handler(uid, pkgname, item->status, value);
+       invoke_callback(uid, pkgname, item, value);
        return SERVICE_COMMON_ERROR_NONE;
 }
 
@@ -443,7 +338,7 @@ static int end_cb(uid_t uid, const char *pkgname, const char *val, void *data)
 
        invoke_callback(uid, pkgname, item, 0.0f);
 
-       s_info.item_list = eina_list_remove(s_info.item_list, item);
+       s_info.item_list = g_list_remove(s_info.item_list, item);
        free(item->icon);
        free(item->pkgname);
        free(item);
@@ -507,6 +402,27 @@ static int app_status_cb(uid_t target_uid, int req_id, const char *pkg_type,
        return SERVICE_COMMON_ERROR_NONE;
 }
 
+static void __free_event_data(gpointer data)
+{
+       struct event_item *item = (struct event_item *)data;
+
+       if (item)
+               free(item);
+}
+
+static void __free_item_data(gpointer data)
+{
+       struct item *ctx = (struct item *)data;
+
+       if (ctx) {
+               if (ctx->pkgname)
+                       free(ctx->pkgname);
+               if (ctx->icon)
+                       free(ctx->icon);
+               free(ctx);
+       }
+}
+
 HAPI int pkgmgr_init(void)
 {
        if (s_info.listen_pc)
@@ -528,9 +444,7 @@ HAPI int pkgmgr_init(void)
 
 HAPI int pkgmgr_fini(void)
 {
-       struct event_item *item;
-       struct item *ctx;
-
+       int i;
        if (!s_info.listen_pc)
                return SERVICE_COMMON_ERROR_INVALID_PARAMETER;
 
@@ -539,39 +453,10 @@ HAPI int pkgmgr_fini(void)
 
        s_info.listen_pc = NULL;
 
-       EINA_LIST_FREE(s_info.download_event, item) {
-               free(item);
-       }
+       for (i = PKGMGR_EVENT_MIN; i <= PKGMGR_EVENT_MAX; i++)
+               g_list_free_full(event_list[i], __free_event_data);
 
-       EINA_LIST_FREE(s_info.uninstall_event, item) {
-               free(item);
-       }
-
-       EINA_LIST_FREE(s_info.install_event, item) {
-               free(item);
-       }
-
-       EINA_LIST_FREE(s_info.update_event, item) {
-               free(item);
-       }
-
-       EINA_LIST_FREE(s_info.recover_event, item) {
-               free(item);
-       }
-
-       EINA_LIST_FREE(s_info.app_enable_event, item) {
-               free(item);
-       }
-
-       EINA_LIST_FREE(s_info.app_disable_event, item) {
-               free(item);
-       }
-
-       EINA_LIST_FREE(s_info.item_list, ctx) {
-               free(ctx->pkgname);
-               free(ctx->icon);
-               free(ctx);
-       }
+       g_list_free_full(s_info.item_list, __free_item_data);
 
        return SERVICE_COMMON_ERROR_NONE;
 }
@@ -589,32 +474,7 @@ HAPI int pkgmgr_add_event_callback(enum pkgmgr_event_type type, int (*cb)(uid_t
        item->cb = cb;
        item->data = data;
 
-       switch (type) {
-       case PKGMGR_EVENT_DOWNLOAD:
-               s_info.download_event = eina_list_prepend(s_info.download_event, item);
-               break;
-       case PKGMGR_EVENT_UNINSTALL:
-               s_info.uninstall_event = eina_list_prepend(s_info.uninstall_event, item);
-               break;
-       case PKGMGR_EVENT_INSTALL:
-               s_info.install_event = eina_list_prepend(s_info.install_event, item);
-               break;
-       case PKGMGR_EVENT_UPDATE:
-               s_info.update_event = eina_list_prepend(s_info.update_event, item);
-               break;
-       case PKGMGR_EVENT_RECOVER:
-               s_info.recover_event = eina_list_prepend(s_info.recover_event, item);
-               break;
-       case PKGMGR_EVENT_APP_ENABLE:
-               s_info.app_enable_event = eina_list_prepend(s_info.app_enable_event, item);
-               break;
-       case PKGMGR_EVENT_APP_DISABLE:
-               s_info.app_disable_event = eina_list_prepend(s_info.app_disable_event, item);
-               break;
-       default:
-               free(item);
-               return SERVICE_COMMON_ERROR_INVALID_PARAMETER;
-       }
+       event_list[type] = g_list_prepend(event_list[type], item);
 
        return SERVICE_COMMON_ERROR_NONE;
 }
@@ -622,83 +482,17 @@ HAPI int pkgmgr_add_event_callback(enum pkgmgr_event_type type, int (*cb)(uid_t
 HAPI void *pkgmgr_del_event_callback(enum pkgmgr_event_type type, int (*cb)(uid_t uid, const char *pkgname, enum pkgmgr_status status, double value, void *data), void *data)
 {
        struct event_item *item;
-       Eina_List *l;
+       GList *l;
        void *cbdata = NULL;
 
-       switch (type) {
-       case PKGMGR_EVENT_DOWNLOAD:
-               EINA_LIST_FOREACH(s_info.download_event, l, item) {
-                       if (item->cb == cb && item->data == data) {
-                               s_info.download_event = eina_list_remove(s_info.download_event, item);
-                               cbdata = item->data;
-                               free(item);
-                               break;
-                       }
-               }
-               break;
-       case PKGMGR_EVENT_UNINSTALL:
-               EINA_LIST_FOREACH(s_info.uninstall_event, l, item) {
-                       if (item->cb == cb && item->data == data) {
-                               s_info.uninstall_event = eina_list_remove(s_info.uninstall_event, item);
-                               cbdata = item->data;
-                               free(item);
-                               break;
-                       }
+       for (l = event_list[type]; l != NULL; l = g_list_next(l)) {
+               item = g_list_nth_data(l, 0);
+               if (item->cb == cb && item->data == data) {
+                       event_list[type] = g_list_remove(event_list[type], item);
+                       cbdata = item->data;
+                       free(item);
+                       break;
                }
-               break;
-       case PKGMGR_EVENT_INSTALL:
-               EINA_LIST_FOREACH(s_info.install_event, l, item) {
-                       if (item->cb == cb && item->data == data) {
-                               s_info.install_event = eina_list_remove(s_info.install_event, item);
-                               cbdata = item->data;
-                               free(item);
-                               break;
-                       }
-               }
-               break;
-       case PKGMGR_EVENT_UPDATE:
-               EINA_LIST_FOREACH(s_info.update_event, l, item) {
-                       if (item->cb == cb && item->data == data) {
-                               s_info.update_event = eina_list_remove(s_info.update_event, item);
-                               cbdata = item->data;
-                               free(item);
-                               break;
-                       }
-               }
-               break;
-       case PKGMGR_EVENT_RECOVER:
-               EINA_LIST_FOREACH(s_info.recover_event, l, item) {
-                       if (item->cb == cb && item->data == data) {
-                               s_info.recover_event = eina_list_remove(s_info.recover_event, item);
-                               cbdata = item->data;
-                               free(item);
-                               break;
-                       }
-               }
-               break;
-       case PKGMGR_EVENT_APP_ENABLE:
-               EINA_LIST_FOREACH(s_info.app_enable_event, l, item) {
-                       if (item->cb == cb && item->data == data) {
-                               s_info.app_enable_event = eina_list_remove(s_info.app_enable_event, item);
-                               cbdata = item->data;
-                               free(item);
-                               break;
-                       }
-               }
-               break;
-       case PKGMGR_EVENT_APP_DISABLE:
-               EINA_LIST_FOREACH(s_info.app_disable_event, l, item) {
-                       if (item->cb == cb && item->data == data) {
-                               s_info.app_disable_event = eina_list_remove(s_info.app_disable_event, item);
-                               cbdata = item->data;
-                               free(item);
-                               break;
-                       }
-               }
-               break;
-       default:
-               ERR("Invalid type");
-               break;
        }
 
        return cbdata;