diff options
author | Hwankyu Jhun <h.jhun@samsung.com> | 2015-11-11 12:51:29 +0900 |
---|---|---|
committer | Hwankyu Jhun <h.jhun@samsung.com> | 2015-11-11 14:17:20 +0900 |
commit | 8f12d9cd323dfc9fc7ed5b4fa91c5d4d3ea80d2b (patch) | |
tree | 44a89b3714ee9b270b2b232573e22c6719540691 | |
parent | 5948dc6a3fc826aa89ee46c4e1d557e02b6988a7 (diff) | |
download | syspopup-8f12d9cd323dfc9fc7ed5b4fa91c5d4d3ea80d2b.tar.gz syspopup-8f12d9cd323dfc9fc7ed5b4fa91c5d4d3ea80d2b.tar.bz2 syspopup-8f12d9cd323dfc9fc7ed5b4fa91c5d4d3ea80d2b.zip |
Use GList instead of custom linked listsubmit/tizen/20151113.035610
- Fix terminate handler type
Change-Id: I31acaa7a1d74a7d63c0b6c298fdcfe52e91b78b5
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
-rwxr-xr-x | include/syspopup_core.h | 6 | ||||
-rwxr-xr-x | src/syspopup_core.c | 84 | ||||
-rw-r--r-- | syspopup/syspopup_wayland.c | 46 | ||||
-rw-r--r-- | syspopup/syspopup_x.c | 49 |
4 files changed, 82 insertions, 103 deletions
diff --git a/include/syspopup_core.h b/include/syspopup_core.h index d035dc0..a010c09 100755 --- a/include/syspopup_core.h +++ b/include/syspopup_core.h @@ -43,19 +43,17 @@ struct _syspopup { void *win; int (*rotate_cb) (void *, void *, void *); bundle *dupped_bundle; - struct _syspopup *next; }; typedef struct _syspopup syspopup; -syspopup *_syspopup_get_head(void); int _syspopup_add_new(syspopup *pinfo); syspopup *_syspopup_find(const char *name); syspopup *_syspopup_find_by_id(int id); void _syspopup_del(int id); -int _syspopup_init(void (*term_handler)(void *), - gboolean (*timeout_handler)(gpointer)); +int _syspopup_init(void (*term_handler)(gpointer, gpointer), + gboolean (*timeout_handler)(gpointer)); int _syspopup_reset_timeout(syspopup *sp, syspopup_info_t *info); int _syspopup_set_term_type(syspopup *sp, syspopup_info_t *info); int _syspopup_set_endkey_type(syspopup *sp, syspopup_info_t *info); diff --git a/src/syspopup_core.c b/src/syspopup_core.c index 7977c24..2fbefcb 100755 --- a/src/syspopup_core.c +++ b/src/syspopup_core.c @@ -38,43 +38,39 @@ #define SYSPOPUP_NAME "_INTERNAL_SYSPOPUP_NAME_" -static syspopup *syspopup_head = NULL; - +static GList *syspopup_list = NULL; static int initialized = 0; static int sp_id = 0; -static void (*_term_handler)(void *data); +static void (*_term_handler)(gpointer data, gpointer user_data); static gboolean (*_timeout_handler)(gpointer data); -syspopup *_syspopup_get_head(void) -{ - return syspopup_head; -} - int _syspopup_add_new(syspopup *sp) { if (sp == NULL) return -1; sp->id = sp_id++; - sp->next = syspopup_head; - syspopup_head = sp; + syspopup_list = g_list_append(syspopup_list, sp); return 0; } syspopup *_syspopup_find(const char *name) { - syspopup *tmp; + GList *list; + syspopup *sp; - tmp = syspopup_head; - while (tmp) { - if (tmp->name) { - if (strcmp(tmp->name, name) == 0) - return tmp; - } + if (syspopup_list == NULL) + return NULL; + + list = g_list_first(syspopup_list); + while (list) { + sp = list->data; + if (sp->name && strcmp(sp->name, name) == 0) + return sp; - tmp = tmp->next; + list = list->next; } return NULL; @@ -82,14 +78,19 @@ syspopup *_syspopup_find(const char *name) syspopup *_syspopup_find_by_id(int id) { - syspopup *tmp; + GList *list; + syspopup *sp; - tmp = syspopup_head; - while (tmp) { - if (tmp->id == id) - return tmp; + if (syspopup_list == NULL) + return NULL; + + list = g_list_first(syspopup_list); + while (list) { + sp = list->data; + if (sp->id == id) + return sp; - tmp = tmp->next; + list = list->next; } return NULL; @@ -108,31 +109,22 @@ static void __syspopup_free(syspopup *sp) void _syspopup_del(int id) { - syspopup *tmp; - syspopup *target; - - if (syspopup_head == NULL) - return; + GList *list; + syspopup *sp; - target = _syspopup_find_by_id(id); - if (target == NULL) + if (syspopup_list == NULL) return; - if (syspopup_head == target) { - syspopup_head = target->next; - __syspopup_free(target); - return; - } - - tmp = syspopup_head; - while (tmp) { - if (tmp->next == target) { - tmp->next = target->next; - __syspopup_free(target); + list = g_list_first(syspopup_list); + while (list) { + sp = list->data; + if (sp->id == id) { + syspopup_list = g_list_remove(syspopup_list, sp); + __syspopup_free(sp); return; } - tmp = tmp->next; + list = list->next; } } @@ -147,14 +139,14 @@ static void __syspopup_dbus_signal_filter(GDBusConnection *conn, if (signal_name && strcmp(signal_name, SYSPOPUP_DBUS_SP_TERM_SIGNAL) == 0) { if (_term_handler) - _term_handler(NULL); + g_list_foreach(syspopup_list, _term_handler, NULL); _D("term handler has been called"); } } -int _syspopup_init(void (*term_handler)(void *), - gboolean (*timeout_handler)(gpointer)) +int _syspopup_init(void (*term_handler)(gpointer, gpointer), + gboolean (*timeout_handler)(gpointer)) { GDBusConnection *conn = NULL; GError *err = NULL; diff --git a/syspopup/syspopup_wayland.c b/syspopup/syspopup_wayland.c index 070f11e..89d46bb 100644 --- a/syspopup/syspopup_wayland.c +++ b/syspopup/syspopup_wayland.c @@ -25,32 +25,28 @@ #include "syspopup_wayland.h" #include "simple_util.h" -static void __wl_syspopup_term_handler(void *data) +static void __wl_syspopup_term_handler(gpointer data, gpointer user_data) { - syspopup *tmp; - - tmp = _syspopup_get_head(); - while (tmp) { - _D("term action %d - %s", tmp->term_act, tmp->name); - - switch (tmp->term_act) { - case SYSPOPUP_TERM: - if (tmp->def_term_fn) - tmp->def_term_fn(tmp->dupped_bundle, - tmp->user_data); - break; - case SYSPOPUP_HIDE: - if (tmp->def_term_fn) - tmp->def_term_fn(tmp->dupped_bundle, - tmp->user_data); - - ecore_wl_window_hide((Ecore_Wl_Window *)tmp->internal_data); - break; - default: - _D("term action IGNORED: %s", tmp->name); - } - - tmp = tmp->next; + syspopup *sp = data; + + if (sp == NULL) + return; + + _D("term action %d - %s", sp->term_act, sp->name); + + switch (sp->term_act) { + case SYSPOPUP_TERM: + if (sp->def_term_fn) + sp->def_term_fn(sp->dupped_bundle, sp->user_data); + break; + case SYSPOPUP_HIDE: + if (sp->def_term_fn) + sp->def_term_fn(sp->dupped_bundle, sp->user_data); + ecore_wl_window_hide((Ecore_Wl_Window *)sp->internal_data); + break; + default: + _D("term action IGNORED: %s", sp->name); + break; } } diff --git a/syspopup/syspopup_x.c b/syspopup/syspopup_x.c index 543dd77..683b3c0 100644 --- a/syspopup/syspopup_x.c +++ b/syspopup/syspopup_x.c @@ -28,40 +28,33 @@ static void __x_rotation_set(Display *dpy, Window win, syspopup *sp); -static void __x_syspopup_term_handler(void *data) +static void __x_syspopup_term_handler(gpointer data, gpointer user_data) { - syspopup *tmp; + syspopup *sp = data; Display *dpy; Window win; - dpy = XOpenDisplay(NULL); - tmp = _syspopup_get_head(); - while (tmp) { - _D("term action %d - %s", tmp->term_act, tmp->name); - - switch (tmp->term_act) { - case SYSPOPUP_TERM: - win = (Window)tmp->internal_data; - - if (tmp->def_term_fn) - tmp->def_term_fn(tmp->dupped_bundle, - tmp->user_data); - - XKillClient(dpy, win); - break; - case SYSPOPUP_HIDE: - win = (Window)tmp->internal_data; + if (sp == NULL) + return; - if (tmp->def_term_fn) - tmp->def_term_fn(tmp->dupped_bundle, - tmp->user_data); - XUnmapWindow(dpy, win); - break; - default: - _D("term action IGNORED: %s", tmp->name); - } + dpy = XOpenDisplay(NULL); + win = (Window)sp->internal_data; + _D("term action %d - %s", sp->term_act, sp->name); - tmp = tmp->next; + switch (sp->term_act) { + case SYSPOPUP_TERM: + if (sp->def_term_fn) + sp->def_term_fn(sp->dupped_bundle, sp->user_data); + XKillClient(dpy, win); + break; + case SYSPOPUP_HIDE: + if (sp->def_term_fn) + sp->def_term_fn(sp->dupped_bundle, sp->user_data); + XUnmapWindow(dpy, win); + break; + default: + _D("term action IGNORED: %s", tmp->name); + break; } XCloseDisplay(dpy); |