Event handler wrapper is introduced.
authorSung-jae Park <nicesj.park@samsung.com>
Fri, 31 May 2013 04:30:31 +0000 (13:30 +0900)
committerSung-jae Park <nicesj.park@samsung.com>
Fri, 31 May 2013 04:55:17 +0000 (13:55 +0900)
[model] Redwood
[binary_type] AP
[customer] Docomo/Orange/Open
[issue#] N/A
[problem] libprovider should be free from strict constraints.
[cause] some codes are removed from the libprovider.
[solution] instead of libprovider, liblivebox should do what it does.
[team] HomeTF
[request]
[horizontal_expansion]

Change-Id: I008e7f1f53b6fa386fec520ca83cdb8730d40e73

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

index be71a5b..4fdc767 100644 (file)
@@ -1,6 +1,6 @@
 Name: liblivebox
 Summary: Library for the development of a livebox 
-Version: 0.3.1
+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 6f6d658..d2ed2e0 100644 (file)
@@ -38,6 +38,7 @@ static int event_handler_cb(struct livebox_buffer *handler, enum buffer_event ev
        Evas_Object *parent_elm;
        int ix;
        int iy;
+       int ret = 0;
 
        if (!info->handle) {
                /* Just ignore this event */
@@ -86,39 +87,45 @@ static int event_handler_cb(struct livebox_buffer *handler, enum buffer_event ev
                action_type = ELM_ACCESS_ACTION_HIGHLIGHT;
                action_info.x = ix;
                action_info.y = iy;
-               (void)elm_access_action(parent_elm, action_type, &action_info);
+               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 (!parent_elm)
                        break;
                action_type = ELM_ACCESS_ACTION_HIGHLIGHT_NEXT;
                action_info.highlight_cycle = EINA_FALSE;
-               (void)elm_access_action(parent_elm, action_type, &action_info);
+               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 (!parent_elm)
                        break;
                action_type = ELM_ACCESS_ACTION_HIGHLIGHT_PREV;
                action_info.highlight_cycle = EINA_FALSE;
-               (void)elm_access_action(parent_elm, action_type, &action_info);
+               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 (!parent_elm)
                        break;
                action_type = ELM_ACCESS_ACTION_ACTIVATE;
-               (void)elm_access_action(parent_elm, action_type, &action_info);
+               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 (!parent_elm)
                        break;
                action_type = ELM_ACCESS_ACTION_UP;
-               (void)elm_access_action(parent_elm, action_type, &action_info);
+               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 (!parent_elm)
                        break;
                action_type = ELM_ACCESS_ACTION_DOWN;
-               (void)elm_access_action(parent_elm, action_type, &action_info);
+               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 (!parent_elm)
@@ -127,7 +134,8 @@ static int event_handler_cb(struct livebox_buffer *handler, enum buffer_event ev
                action_info.x = ix;
                action_info.y = iy;
                action_info.mouse_type = 0;
-               (void)elm_access_action(parent_elm, action_type, &action_info);
+               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 (!parent_elm)
@@ -135,25 +143,29 @@ static int event_handler_cb(struct livebox_buffer *handler, enum buffer_event ev
                action_info.x = ix;
                action_info.y = iy;
                action_info.mouse_type = 1;
-               (void)elm_access_action(parent_elm, action_type, &action_info);
+               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 (!parent_elm)
                        break;
                action_info.mouse_type = 2;
-               (void)elm_access_action(parent_elm, action_type, &action_info);
+               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 (!parent_elm)
                        break;
                action_type = ELM_ACCESS_ACTION_UNHIGHLIGHT;
-               (void)elm_access_action(parent_elm, action_type, &action_info);
+               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);
                break;
+       }
 
-       return 0;
+       return ret;
 }
 
 static void *alloc_fb(void *data, int size)