#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;
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);
}
}
static struct item *find_item(const char *pkgname, uid_t uid)
{
- Eina_List *l;
+ GList *l;
struct item *item;
if (!pkgname) {
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;
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;
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;
}
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);
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)
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;
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;
}
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;
}
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;