Event handler wrapper is introduced.
authorSung-jae Park <nicesj.park@samsung.com>
Fri, 31 May 2013 04:56:13 +0000 (13:56 +0900)
committerSung-jae Park <nicesj.park@samsung.com>
Fri, 31 May 2013 06:37:58 +0000 (15:37 +0900)
libprovider should be free from strict constraints.
- some codes are removed from the libprovider.
- instead of libprovider, liblivebox should do what it does.

Add event type for accessibility (buffer type)
- Add new event types for accessibility

Change-Id: I753c4a4c3fcfd0af7f6925b249fc88d02331c00c

include/livebox.h
packaging/liblivebox.spec
src/livebox.c
src/virtual_window.c

index 417f687..05dcfe6 100644 (file)
@@ -170,6 +170,17 @@ enum buffer_event {
 
        BUFFER_EVENT_KEY_DOWN, /*!< Key down */
        BUFFER_EVENT_KEY_UP, /*!< Key up */
+
+       BUFFER_EVENT_HIGHLIGHT,
+       BUFFER_EVENT_HIGHLIGHT_NEXT,
+       BUFFER_EVENT_HIGHLIGHT_PREV,
+       BUFFER_EVENT_ACTIVATE,
+       BUFFER_EVENT_ACTION_UP,
+       BUFFER_EVENT_ACTION_DOWN,
+       BUFFER_EVENT_SCROLL_UP,
+       BUFFER_EVENT_SCROLL_MOVE,
+       BUFFER_EVENT_SCROLL_DOWN,
+       BUFFER_EVENT_UNHIGHLIGHT,
 };
 #endif
 
index 3c3df9f..825a137 100644 (file)
@@ -1,6 +1,6 @@
 Name: liblivebox
 Summary: Library for the development of a livebox 
-Version: 0.3.0
+Version: 0.3.2
 Release: 1
 Group: HomeTF/Livebox
 License: Flora License
index d3d1810..f6abd2e 100644 (file)
@@ -66,6 +66,10 @@ struct livebox_desc {
 struct livebox_buffer_data {
        int is_pd;
        int accelerated;
+
+       /* for Buffer event wrapper */
+       int (*handler)(struct livebox_buffer *, enum buffer_event, double, double, double, void *);
+       void *cbdata;
 };
 
 PUBLIC const int DONE = 0x00;
@@ -472,6 +476,51 @@ PUBLIC int livebox_desc_del_block(struct livebox_desc *handle, int idx)
        return LB_STATUS_ERROR_NOT_EXIST;
 }
 
+/*!
+ * \note
+ * The last "data" argument is same with "user_data" which is managed by "provider_set_user_data).
+ */
+static inline int event_handler_wrapper(struct livebox_buffer *buffer, enum buffer_event event, double timestamp, double x, double y, void *data)
+{
+       const char *pkgname;
+       const char *id;
+       struct livebox_buffer_data *cbdata = data;
+       int ret;
+
+       pkgname = provider_buffer_pkgname(buffer);
+       id = provider_buffer_pkgname(buffer);
+
+       ret = cbdata->handler(buffer, event, timestamp, x, y, cbdata->cbdata);
+
+       switch (event) {
+       case BUFFER_EVENT_HIGHLIGHT:
+       case BUFFER_EVENT_HIGHLIGHT_NEXT:
+       case BUFFER_EVENT_HIGHLIGHT_PREV:
+       case BUFFER_EVENT_ACTIVATE:
+       case BUFFER_EVENT_ACTION_UP:
+       case BUFFER_EVENT_ACTION_DOWN:
+       case BUFFER_EVENT_SCROLL_UP:
+       case BUFFER_EVENT_SCROLL_MOVE:
+       case BUFFER_EVENT_SCROLL_DOWN:
+       case BUFFER_EVENT_UNHIGHLIGHT:
+               if (ret < 0)
+                       (void)provider_send_access_status(pkgname, id, LB_ACCESS_STATUS_ERROR);
+               else
+                       (void)provider_send_access_status(pkgname, id, ret);
+               break;
+       default:
+               break;
+       }
+
+       return ret;
+}
+
+static inline int default_event_handler(struct livebox_buffer *buffer, enum buffer_event event, double timestamp, double x, double y, void *data)
+{
+       /* NOP */
+       return 0;
+}
+
 PUBLIC struct livebox_buffer *livebox_acquire_buffer(const char *filename, int is_pd, int width, int height, int (*handler)(struct livebox_buffer *, enum buffer_event, double, double, double, void *), void *data)
 {
        struct livebox_buffer_data *user_data;
@@ -479,6 +528,7 @@ PUBLIC struct livebox_buffer *livebox_acquire_buffer(const char *filename, int i
        struct livebox_buffer *handle;
        char *uri;
        int uri_len;
+       struct event_cbdata *cbdata;
 
        if (!filename || !width || !height) {
                ErrPrint("Invalid argument: %p(%dx%d)\n", filename, width, height);
@@ -492,6 +542,8 @@ PUBLIC struct livebox_buffer *livebox_acquire_buffer(const char *filename, int i
        }
 
        user_data->is_pd = is_pd;
+       user_data->handler = handler ? handler : default_event_handler;
+       user_data->cbdata = data;
 
        uri_len = strlen(filename) + strlen(FILE_SCHEMA) + 1;
        uri = malloc(uri_len);
@@ -510,9 +562,13 @@ PUBLIC struct livebox_buffer *livebox_acquire_buffer(const char *filename, int i
                return NULL;
        }
 
-       handle = provider_buffer_acquire((!!is_pd) ? TYPE_PD : TYPE_LB, pkgname, uri, width, height, sizeof(int), handler, data);
+       handle = provider_buffer_acquire((!!is_pd) ? TYPE_PD : TYPE_LB, pkgname, uri, width, height, sizeof(int), event_handler_wrapper, user_data);
        DbgPrint("Acquire buffer for PD(%s), %s, %p\n", pkgname, uri, handle);
        free(uri);
+       if (!handle) {
+               free(user_data);
+               return NULL;
+       }
 
        (void)provider_buffer_set_user_data(handle, user_data);
        return handle;
index 30ffe40..2939295 100644 (file)
@@ -1,9 +1,11 @@
 #include <Elementary.h>
+#include <string.h>
 #include <Ecore_Evas.h>
 #include <Evas.h>
 
 #include <dlog.h>
 #include <livebox-errno.h>
+#include <livebox-service.h>
 
 #include "livebox.h"
 
@@ -21,8 +23,6 @@ struct info {
        struct livebox_buffer *handle; /*!< Livebox buffer handle */
        Evas_Object *window; /*!< Parent evas object - WARN: Incompatible with the elm_win object */
        int is_hw; /*!< 1 if a buffer is created on the H/W accelerated place or 0 */
-
-       Evas_Object *elm_parent;
 };
 
 /*!
@@ -31,12 +31,15 @@ struct info {
  */
 static int event_handler_cb(struct livebox_buffer *handler, enum buffer_event evt, double timestamp, double x, double y, void *data)
 {
-       Elm_Access_Action_Info *info;
-       Elm_Access_Action_Type action;
        struct info *info = data;
+       Elm_Access_Action_Info action_info;
+       Elm_Access_Action_Type action_type;
        Evas *e;
+       Ecore_Evas *ee;
+       Evas_Object *parent_elm;
        int ix;
        int iy;
+       int ret = 0;
 
        if (!info->handle) {
                /* Just ignore this event */
@@ -50,7 +53,11 @@ static int event_handler_cb(struct livebox_buffer *handler, enum buffer_event ev
        ix = info->width * x;
        iy = info->height * y;
 
+       memset(&action_info, 0, sizeof(action_info));
+
        e = evas_object_evas_get(info->window);
+       ee = ecore_evas_ecore_evas_get(e);
+       parent_elm = ecore_evas_data_get(ee, "parent,elm");
 
        /*!
         * \note
@@ -76,104 +83,110 @@ static int event_handler_cb(struct livebox_buffer *handler, enum buffer_event ev
                evas_event_feed_mouse_out(e, timestamp + 0.01f, NULL); /* + 0.1f just for fake event */
                break;
        case BUFFER_EVENT_HIGHLIGHT:
-               if (!info->elm_parent)
-                       return LB_ACCESS_STATUS_ERROR;
-
-               action = ELM_ACCESS_ACTION_HIGHLIGHT;
-               info->x = x;
-               info->y = y;
-               ret = elm_access_action(info->elm_parent, action, info);
-               DbgPrint("ACCESS_HIGHLIGHT: %dx%d returns %d\n", x, y, ret);
+               if (!parent_elm) {
+                       ret = LB_ACCESS_STATUS_ERROR;
+                       break;
+               }
+               action_type = ELM_ACCESS_ACTION_HIGHLIGHT;
+               action_info.x = ix;
+               action_info.y = iy;
+               ret = elm_access_action(parent_elm, action_type, &action_info);
                ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
                break;
        case BUFFER_EVENT_HIGHLIGHT_NEXT:
-               if (!info->elm_parent)
-                       return LB_ACCESS_STATUS_ERROR;
-               action = ELM_ACCESS_ACTION_HIGHLIGHT_NEXT;
-               info->highlight_cycle = EINA_FALSE;
-               ret = elm_access_action(info->elm_parent, action, info);
-               DbgPrint("ACCESS_HIGHLIGHT_NEXT, returns %d\n", ret);
+               if (!parent_elm) {
+                       ret = LB_ACCESS_STATUS_ERROR;
+                       break;
+               }
+               action_type = ELM_ACCESS_ACTION_HIGHLIGHT_NEXT;
+               action_info.highlight_cycle = EINA_FALSE;
+               ret = elm_access_action(parent_elm, action_type, &action_info);
                ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_LAST : LB_ACCESS_STATUS_DONE;
                break;
        case BUFFER_EVENT_HIGHLIGHT_PREV:
-               if (!info->elm_parent)
-                       return LB_ACCESS_STATUS_ERROR;
-               action = ELM_ACCESS_ACTION_HIGHLIGHT_PREV;
-               info->highlight_cycle = EINA_FALSE;
-               ret = elm_access_action(info->elm_parent, action, info);
-               DbgPrint("ACCESS_HIGHLIGHT_PREV, returns %d\n", ret);
+               if (!parent_elm) {
+                       ret = LB_ACCESS_STATUS_ERROR;
+                       break;
+               }
+               action_type = ELM_ACCESS_ACTION_HIGHLIGHT_PREV;
+               action_info.highlight_cycle = EINA_FALSE;
+               ret = elm_access_action(parent_elm, action_type, &action_info);
                ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_FIRST : LB_ACCESS_STATUS_DONE;
                break;
        case BUFFER_EVENT_ACTIVATE:
-               if (!info->elm_parent)
-                       return LB_ACCESS_STATUS_ERROR;
-               action = ELM_ACCESS_ACTION_ACTIVATE;
-               ret = elm_access_action(info->elm_parent, action, info);
-               DbgPrint("ACCESS_ACTIVATE, returns %d\n", ret);
+               if (!parent_elm) {
+                       ret = LB_ACCESS_STATUS_ERROR;
+                       break;
+               }
+               action_type = ELM_ACCESS_ACTION_ACTIVATE;
+               ret = elm_access_action(parent_elm, action_type, &action_info);
                ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
                break;
        case BUFFER_EVENT_ACTION_UP:
-               if (!info->elm_parent)
-                       return LB_ACCESS_STATUS_ERROR;
-               action = ELM_ACCESS_ACTION_UP;
-               ret = elm_access_action(info->elm_parent, action, info);
-               DbgPrint("ACCESS_ACTION(%d), returns %d\n", down, ret);
+               if (!parent_elm) {
+                       ret = LB_ACCESS_STATUS_ERROR;
+                       break;
+               }
+               action_type = ELM_ACCESS_ACTION_UP;
+               ret = elm_access_action(parent_elm, action_type, &action_info);
+               ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
                break;
        case BUFFER_EVENT_ACTION_DOWN:
-               if (!info->elm_parent)
-                       return LB_ACCESS_STATUS_ERROR;
-               action = ELM_ACCESS_ACTION_DOWN;
-               ret = elm_access_action(info->elm_parent, action, info);
-               DbgPrint("ACCESS_ACTION(%d), returns %d\n", down, ret);
+               if (!parent_elm) {
+                       ret = LB_ACCESS_STATUS_ERROR;
+                       break;
+               }
+               action_type = ELM_ACCESS_ACTION_DOWN;
+               ret = elm_access_action(parent_elm, action_type, &action_info);
                ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
                break;
        case BUFFER_EVENT_SCROLL_UP:
-               if (!info->elm_parent)
-                       return LB_ACCESS_STATUS_ERROR;
-               action = ELM_ACCESS_ACTION_SCROLL;
-               info->x = ix;
-               info->y = iy;
-               info->mouse_type = 0;
-               ret = elm_access_action(info->elm_parent, action, info);
-               DbgPrint("ACCESS_HIGHLIGHT_SCROLL, returns %d\n", ret);
+               if (!parent_elm) {
+                       ret = LB_ACCESS_STATUS_ERROR;
+                       break;
+               }
+               action_type = ELM_ACCESS_ACTION_SCROLL;
+               action_info.x = ix;
+               action_info.y = iy;
+               action_info.mouse_type = 0;
+               ret = elm_access_action(parent_elm, action_type, &action_info);
                ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
                break;
        case BUFFER_EVENT_SCROLL_MOVE:
-               if (!info->elm_parent)
-                       return LB_ACCESS_STATUS_ERROR;
-               action = ELM_ACCESS_ACTION_SCROLL;
-               info->x = ix;
-               info->y = iy;
-               info->mouse_type = -1;
-               ret = elm_access_action(info->elm_parent, action, info);
-               DbgPrint("ACCESS_HIGHLIGHT_SCROLL, returns %d\n", ret);
+               if (!parent_elm) {
+                       ret = LB_ACCESS_STATUS_ERROR;
+                       break;
+               }
+               action_info.x = ix;
+               action_info.y = iy;
+               action_info.mouse_type = 1;
+               ret = elm_access_action(parent_elm, action_type, &action_info);
                ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
                break;
        case BUFFER_EVENT_SCROLL_DOWN:
-               if (!info->elm_parent)
-                       return LB_ACCESS_STATUS_ERROR;
-               action = ELM_ACCESS_ACTION_SCROLL;
-               info->x = ix;
-               info->y = iy;
-               info->mouse_type = 1;
-               ret = elm_access_action(info->elm_parent, action, info);
-               DbgPrint("ACCESS_HIGHLIGHT_SCROLL, returns %d\n", ret);
+               if (!parent_elm) {
+                       ret = LB_ACCESS_STATUS_ERROR;
+                       break;
+               }
+               action_info.mouse_type = 2;
+               ret = elm_access_action(parent_elm, action_type, &action_info);
                ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
                break;
        case BUFFER_EVENT_UNHIGHLIGHT:
-               if (!info->elm_parent)
-                       return LB_ACCESS_STATUS_ERROR;
-               action = ELM_ACCESS_ACTION_UNHIGHLIGHT;
-               ret = elm_access_action(info->elm_parent, action, info);
-               DbgPrint("ACCESS_UNHIGHLIGHT, returns %d\n", ret);
+               if (!parent_elm) {
+                       ret = LB_ACCESS_STATUS_ERROR;
+                       break;
+               }
+               action_type = ELM_ACCESS_ACTION_UNHIGHLIGHT;
+               ret = elm_access_action(parent_elm, action_type, &action_info);
                ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
                break;
        default:
                LOGD("Unhandled buffer event (%d)\n", evt);
-               return -EINVAL;
+               break;
        }
 
-       return 0;
+       return ret;
 }
 
 static void *alloc_fb(void *data, int size)
@@ -262,17 +275,13 @@ static void del_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
        Ecore_Evas *ee;
        struct info *info = data;
 
-       evas_object_del(obj, "info");
-
        ee = ecore_evas_ecore_evas_get(e);
        if (!ee)
                return;
 
-       LOGD("Try to release the ECORE_EVAS\n");
        ecore_evas_free(ee);
        free(info->id);
        free(info);
-       LOGD("ECORE_EVAS is released\n");
 }
 
 static void pre_render_cb(void *data, Evas *e, void *event_info)
@@ -299,7 +308,7 @@ static void post_render_cb(void *data, Evas *e, void *event_info)
                livebox_sync_buffer(info->handle);
 }
 
-PUBLIC Evas_Object *livebox_virtual_window_add(const char *id, int width, int height)
+PUBLIC Evas_Object *virtual_window_create(const char *id, int width, int height)
 {
        Ecore_Evas *ee;
        Evas *e;
@@ -352,29 +361,28 @@ PUBLIC Evas_Object *livebox_virtual_window_add(const char *id, int width, int he
        evas_object_color_set(info->window, 0, 0, 0, 0);
        evas_object_event_callback_add(info->window, EVAS_CALLBACK_DEL, del_cb, info);
        evas_object_event_callback_add(info->window, EVAS_CALLBACK_RESIZE, resize_cb, info);
-       evas_object_data_set(info->window, "info", info);
 
        return info->window;
 }
 
-PUBLIC int livebox_virtual_window_set_parent_elm(Evas_Object *win, Evas_Object *parent_elm)
+PUBLIC int virtual_window_set_parent_elm(Evas_Object *win, Evas_Object *parent)
 {
-       struct info *info;
-       info = evas_object_data_get(win, "info");
-       if (!info)
+       Evas *e;
+       Ecore_Evas *ee;
+
+       if (!win)
                return LB_STATUS_ERROR_INVALID;
 
-       if (info->parent_elm)
-               DbgPrint("Parent object will be replaced: %p\n", info->parent_elm);
+       e = evas_object_evas_get(win);
+       if (!e)
+               return LB_STATUS_ERROR_FAULT;
 
-       info->parent_elm = parent_elm;
-       return 0;
-}
+       ee = ecore_evas_ecore_evas_get(e);
+       if (!ee)
+               return LB_STATUS_ERROR_FAULT;
 
-PUBLIC int livebox_virtual_window_del(Evas_Object *virtual_win)
-{
-       evas_object_del(virtual_win);
-       return LB_STATUS_SUCCESS;
+       ecore_evas_data_set(ee, "parent,elm", parent);
+       return 0;
 }
 
 /* End of a file */