Update the size changed callback handler.
[platform/framework/web/livebox-viewer.git] / src / livebox.c
index 798aab9..bfa4f41 100644 (file)
@@ -163,9 +163,11 @@ static void resize_cb(struct livebox *handler, const struct packet *result, void
         * after this request.
         */
        if (ret == 0) {
+               DbgPrint("Resize request is done, prepare the size changed event\n");
                handler->size_changed_cb = cb;
                handler->size_cbdata = cbdata;
        } else {
+               DbgPrint("Resize request is failed: %d\n", ret);
                cb(handler, ret, cbdata);
        }
 }
@@ -493,19 +495,20 @@ static void pinup_done_cb(struct livebox *handler, const struct packet *result,
        }
 }
 
-static int send_mouse_event(struct livebox *handler, const char *event, double x, double y, int w, int h)
+static int send_mouse_event(struct livebox *handler, const char *event, int x, int y)
 {
        struct packet *packet;
        double timestamp;
 
        timestamp = util_timestamp();
-       packet = packet_create_noack(event, "ssiiddd", handler->pkgname, handler->id, w, h,
-                                               timestamp, x, y);
+       packet = packet_create_noack(event, "ssdii", handler->pkgname, handler->id, timestamp, x, y);
        if (!packet) {
                ErrPrint("Failed to build param\n");
                return -EFAULT;
        }
 
+       DbgPrint("Send: %dx%d\n", x, y);
+
        return master_rpc_request_only(handler, packet);
 }
 
@@ -597,11 +600,6 @@ EAPI struct livebox *livebox_add_with_size(const char *pkgname, const char *cont
                return NULL;
        }
 
-       if (livebox_service_is_enabled(pkgname) == 0) {
-               DbgPrint("Livebox [%s] is disabled package\n", pkgname);
-               return NULL;
-       }
-
        if (type != LB_SIZE_TYPE_UNKNOWN)
                livebox_service_get_size(type, &width, &height);
 
@@ -618,6 +616,13 @@ EAPI struct livebox *livebox_add_with_size(const char *pkgname, const char *cont
                return NULL;
        }
 
+       if (livebox_service_is_enabled(handler->pkgname) == 0) {
+               DbgPrint("Livebox [%s](%s) is disabled package\n", handler->pkgname, pkgname);
+               free(handler->pkgname);
+               free(handler);
+               return NULL;
+       }
+
        if (content) {
                handler->content = strdup(content);
                if (!handler->content) {
@@ -715,6 +720,11 @@ EAPI int livebox_set_period(struct livebox *handler, double period, ret_cb_t cb,
                return -EINVAL;
        }
 
+       if (handler->period_changed_cb) {
+               ErrPrint("Previous request for changing period is not finished\n");
+               return -EBUSY;
+       }
+
        if (!handler->is_user) {
                ErrPrint("CA Livebox is not able to change the period\n");
                return -EPERM;
@@ -869,6 +879,11 @@ EAPI int livebox_resize(struct livebox *handler, int type, ret_cb_t cb, void *da
                return -EINVAL;
        }
 
+       if (handler->size_changed_cb) {
+               ErrPrint("Previous resize request is not finished yet\n");
+               return -EBUSY;
+       }
+
        if (!handler->is_user) {
                ErrPrint("CA Livebox is not able to be resized\n");
                return -EPERM;
@@ -913,7 +928,7 @@ EAPI int livebox_click(struct livebox *handler, double x, double y)
        }
 
        if (handler->lb.auto_launch)
-               if (aul_launch_app(handler->lb.auto_launch, NULL) < 0)
+               if (aul_open_app(handler->lb.auto_launch) < 0)
                        ErrPrint("Failed to launch app %s\n", handler->lb.auto_launch);
 
        timestamp = util_timestamp();
@@ -927,15 +942,15 @@ EAPI int livebox_click(struct livebox *handler, double x, double y)
 
        if (!handler->lb.mouse_event && (handler->lb.type == _LB_TYPE_BUFFER || handler->lb.type == _LB_TYPE_SCRIPT)) {
                int ret; /* Shadow variable */
-               ret = send_mouse_event(handler, "lb_mouse_down", x, y, handler->lb.width, handler->lb.height);
+               ret = send_mouse_event(handler, "lb_mouse_down", x * handler->lb.width, y * handler->lb.height);
                if (ret < 0)
                        DbgPrint("Failed to send Down: %d\n", ret);
 
-               ret = send_mouse_event(handler, "lb_mouse_move", x, y, handler->lb.width, handler->lb.height);
+               ret = send_mouse_event(handler, "lb_mouse_move", x * handler->lb.width, y * handler->lb.height);
                if (ret < 0)
                        DbgPrint("Failed to send Move: %d\n", ret);
 
-               ret = send_mouse_event(handler, "lb_mouse_up", x, y, handler->lb.width, handler->lb.height);
+               ret = send_mouse_event(handler, "lb_mouse_up", x * handler->lb.width, y * handler->lb.height);
                if (ret < 0)
                        DbgPrint("Failed to send Up: %d\n", ret);
        }
@@ -1009,6 +1024,34 @@ EAPI int livebox_create_pd_with_position(struct livebox *handler, double x, doub
        return master_rpc_async_request(handler, packet, 0, pd_create_cb, create_cb_info(cb, data));
 }
 
+EAPI int livebox_move_pd(struct livebox *handler, double x, double y)
+{
+       struct packet *packet;
+
+       if (!handler) {
+               ErrPrint("Handler is NIL\n");
+               return -EINVAL;
+       }
+
+       if (!handler->pd.data.fb || handler->state != CREATE || !handler->id) {
+               ErrPrint("Handler is not valid\n");
+               return -EINVAL;
+       }
+
+       if (!handler->is_pd_created) {
+               DbgPrint("PD is not created\n");
+               return -EINVAL;
+       }
+
+       packet = packet_create_noack("pd_move", "ssdd", handler->pkgname, handler->id, x, y);
+       if (!packet) {
+               ErrPrint("Failed to build param\n");
+               return -EFAULT;
+       }
+
+       return master_rpc_request_only(handler, packet);
+}
+
 EAPI int livebox_activate(const char *pkgname, ret_cb_t cb, void *data)
 {
        struct packet *packet;
@@ -1058,8 +1101,8 @@ EAPI int livebox_destroy_pd(struct livebox *handler, ret_cb_t cb, void *data)
 
 EAPI int livebox_content_event(struct livebox *handler, enum content_event_type type, double x, double y)
 {
-       int w;
-       int h;
+       int w = 1;
+       int h = 1;
        char cmd[20] = { '\0', };
        char *ptr = cmd;
 
@@ -1074,6 +1117,8 @@ EAPI int livebox_content_event(struct livebox *handler, enum content_event_type
        }
 
        if (type & CONTENT_EVENT_PD_MASK) {
+               int flag = 1;
+
                if (!handler->is_pd_created) {
                        ErrPrint("PD is not created\n");
                        return -EINVAL;
@@ -1088,16 +1133,22 @@ EAPI int livebox_content_event(struct livebox *handler, enum content_event_type
                        if (type & CONTENT_EVENT_MOUSE_MOVE) {
                                if (fabs(x - handler->pd.x) < MINIMUM_EVENT && fabs(y - handler->pd.y) < MINIMUM_EVENT)
                                        return -EBUSY;
+                       } else if (type & CONTENT_EVENT_MOUSE_SET) {
+                               flag = 0;
                        }
                }
 
-               w = handler->pd.width;
-               h = handler->pd.height;
-               handler->pd.x = x;
-               handler->pd.y = y;
+               if (flag) {
+                       w = handler->pd.width;
+                       h = handler->pd.height;
+                       handler->pd.x = x;
+                       handler->pd.y = y;
+               }
                *ptr++ = 'p';
                *ptr++ = 'd';
        } else {
+               int flag = 1;
+
                if (type & CONTENT_EVENT_MOUSE_MASK) {
                        if (!handler->lb.mouse_event) {
                                ErrPrint("Box is not support the mouse event\n");
@@ -1112,13 +1163,17 @@ EAPI int livebox_content_event(struct livebox *handler, enum content_event_type
                        if (type & CONTENT_EVENT_MOUSE_MOVE) {
                                if (fabs(x - handler->lb.x) < MINIMUM_EVENT && fabs(y - handler->lb.y) < MINIMUM_EVENT)
                                        return -EBUSY;
+                       } else if (type & CONTENT_EVENT_MOUSE_SET) {
+                               flag = 0;
                        }
                }
 
-               w = handler->lb.width;
-               h = handler->lb.height;
-               handler->lb.x = x;
-               handler->lb.y = y;
+               if (flag) {
+                       w = handler->lb.width;
+                       h = handler->lb.height;
+                       handler->lb.x = x;
+                       handler->lb.y = y;
+               }
                *ptr++ = 'l';
                *ptr++ = 'b';
        }
@@ -1157,6 +1212,12 @@ EAPI int livebox_content_event(struct livebox *handler, enum content_event_type
        case CONTENT_EVENT_MOUSE_MOVE | CONTENT_EVENT_MOUSE_MASK:
                strcpy(ptr, "_mouse_move");
                break;
+       case CONTENT_EVENT_MOUSE_SET | CONTENT_EVENT_MOUSE_MASK:
+               strcpy(ptr, "_mouse_set");
+               break;
+       case CONTENT_EVENT_MOUSE_UNSET | CONTENT_EVENT_MOUSE_MASK:
+               strcpy(ptr, "_mouse_unset");
+               break;
        case CONTENT_EVENT_KEY_DOWN | CONTENT_EVENT_KEY_MASK:
                strcpy(ptr, "_key_down");
                break;
@@ -1168,7 +1229,7 @@ EAPI int livebox_content_event(struct livebox *handler, enum content_event_type
                return -EINVAL;
        }
 
-       return send_mouse_event(handler, cmd, x, y, w, h);
+       return send_mouse_event(handler, cmd, x * w, y * h);
 }
 
 EAPI const char *livebox_filename(struct livebox *handler)
@@ -1210,20 +1271,13 @@ EAPI int livebox_get_pdsize(struct livebox *handler, int *w, int *h)
        if (!h)
                h = &_h;
 
-       *w = handler->pd.width;
-       *h = handler->pd.height;
-
-       switch (handler->pd.type) {
-       case _PD_TYPE_BUFFER:
-       case _PD_TYPE_SCRIPT:
-               if (!handler->is_pd_created) {
-                       DbgPrint("Buffer is not created yet - reset size\n");
-                       *w = 0;
-                       *h = 0;
-               }
-               break;
-       default:
-               break;
+       if (!handler->is_pd_created) {
+               DbgPrint("Buffer is not created yet [%dx%d]\n", *w, *h);
+               *w = handler->pd.default_width;
+               *h = handler->pd.default_height;
+       } else {
+               *w = handler->pd.width;
+               *h = handler->pd.height;
        }
 
        return 0;
@@ -1277,6 +1331,11 @@ EAPI int livebox_set_group(struct livebox *handler, const char *cluster, const c
                return -EINVAL;
        }
 
+       if (handler->group_changed_cb) {
+               ErrPrint("Previous group changing request is not finished yet\n");
+               return -EBUSY;
+       }
+
        if (!handler->is_user) {
                ErrPrint("CA Livebox is not able to change the group\n");
                return -EPERM;
@@ -1795,6 +1854,11 @@ EAPI int livebox_set_pinup(struct livebox *handler, int flag, ret_cb_t cb, void
                return -EINVAL;
        }
 
+       if (handler->pinup_cb) {
+               ErrPrint("Previous pinup request is not finished\n");
+               return -EBUSY;
+       }
+
        if (handler->is_pinned_up == flag) {
                DbgPrint("No changes\n");
                return -EALREADY;
@@ -2033,6 +2097,8 @@ EAPI int livebox_set_visibility(struct livebox *handler, enum livebox_visible_st
                }
        }
 
+       DbgPrint("Change the visibility %d <> %d, %s\n", handler->visible, state, handler->id);
+
        if (handler->visible == state)
                return 0;
 
@@ -2108,6 +2174,12 @@ void lb_set_pdsize(struct livebox *handler, int w, int h)
        handler->pd.height = h;
 }
 
+void lb_set_default_pdsize(struct livebox *handler, int w, int h)
+{
+       handler->pd.default_width = w;
+       handler->pd.default_height = h;
+}
+
 void lb_invoke_fault_handler(enum livebox_fault_type event, const char *pkgname, const char *file, const char *func)
 {
        struct dlist *l;
@@ -2518,4 +2590,30 @@ int lb_send_delete(struct livebox *handler, ret_cb_t cb, void *data)
        return master_rpc_async_request(handler, packet, 0, del_ret_cb, create_cb_info(cb, data));
 }
 
+EAPI int livebox_client_paused(void)
+{
+       struct packet *packet;
+
+       packet = packet_create_noack("client_paused", "d", util_timestamp());
+       if (!packet) {
+               ErrPrint("Failed to create a pause packet\n");
+               return -EFAULT;
+       }
+
+       return master_rpc_request_only(NULL, packet);
+}
+
+EAPI int livebox_client_resumed(void)
+{
+       struct packet *packet;
+
+       packet = packet_create_noack("client_resumed", "d", util_timestamp());
+       if (!packet) {
+               ErrPrint("Failed to create a resume packet\n");
+               return -EFAULT;
+       }
+
+       return master_rpc_request_only(NULL, packet);
+}
+
 /* End of a file */