Use GList instead of custom linked list 98/51598/1 submit/tizen/20151113.035610
authorHwankyu Jhun <h.jhun@samsung.com>
Wed, 11 Nov 2015 03:51:29 +0000 (12:51 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Wed, 11 Nov 2015 05:17:20 +0000 (14:17 +0900)
- Fix terminate handler type

Change-Id: I31acaa7a1d74a7d63c0b6c298fdcfe52e91b78b5
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
include/syspopup_core.h
src/syspopup_core.c
syspopup/syspopup_wayland.c
syspopup/syspopup_x.c

index d035dc03c00d7b5810a4c9c6da1377eeea1d9b6f..a010c09a96cc907b8f335b28daa2a0a48cb3f6c6 100755 (executable)
@@ -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);
index 7977c24b326e450d3b8f62d23dfc1525921b6c38..2fbefcb2b0a4b9fddbd03743696fa5cadde6dd04 100755 (executable)
 
 #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;
index 070f11e1bfbfd3721a33f19d65e95127fe795a4f..89d46bb20582f827de0a9da4378af14aebd2c855 100644 (file)
 #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;
        }
 }
 
index 543dd7740eed029729b889e555e1087e97a19650..683b3c04ddd53189c25ab7d0d7c696fb95378b8a 100644 (file)
 
 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);