Add frame drop & manual sync mode.
authorSung-jae Park <nicesj.park@samsung.com>
Mon, 7 Oct 2013 09:37:47 +0000 (18:37 +0900)
committerSung-jae Park <nicesj.park@samsung.com>
Mon, 7 Oct 2013 09:38:11 +0000 (18:38 +0900)
Change-Id: I5600aa18e16d5526bec045ae7297c71990d4d805

CMakeLists.txt
include/conf.h
include/livebox.h
packaging/liblivebox-viewer.spec
src/client.c
src/conf.c [new file with mode: 0644]
src/fb.c
src/livebox.c

index 0933a34..505f8f3 100644 (file)
@@ -56,6 +56,7 @@ ADD_LIBRARY(${PROJECT_NAME} SHARED
        src/client.c
        src/critical_log.c
        src/file_service.c
+       src/conf.c
 )
 SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES SOVERSION ${VERSION_MAJOR})
 SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES VERSION ${VERSION})
index 57a8b92..7258093 100644 (file)
@@ -30,4 +30,9 @@
 #define VCONFKEY_MASTER_CLIENT_ADDR "db/data-provider-master/serveraddr"
 #endif
 
+extern void conf_set_manual_sync(int flag);
+extern int conf_manual_sync(void);
+extern void conf_set_frame_drop_for_resizing(int flag);
+extern int conf_frame_drop_for_resizing(void);
+
 /* End of a file */
index c57f193..b64c55c 100644 (file)
@@ -1413,6 +1413,18 @@ extern int livebox_set_update_mode(struct livebox *handler, int active_update, r
  */
 extern int livebox_is_active_update(struct livebox *handler);
 
+extern void livebox_set_manual_sync(int flag);
+
+extern int livebox_manual_sync(void);
+
+extern void livebox_set_frame_drop_for_resizing(int flag);
+
+extern int livebox_frame_drop_for_resizing(void);
+
+extern int livebox_sync_pd_fb(struct livebox *handler);
+
+extern int livebox_sync_lb_fb(struct livebox *handler);
+
 /*!
  * \}
  */
index ec545be..a05b31a 100644 (file)
@@ -1,6 +1,6 @@
 Name: liblivebox-viewer
 Summary: Library for developing the application.
-Version: 0.14.4
+Version: 0.14.5
 Release: 1
 Group: HomeTF/Livebox
 License: Flora License
index c94b92e..037a5d5 100644 (file)
@@ -284,7 +284,7 @@ static struct packet *master_lb_update_begin(pid_t pid, int handle, const struct
         * And then begin updating again after change its size.
         */
        if (lb_get_lb_fb(handler)) {
-               lb_set_lb_fb(handler, fbfile);
+               (void)lb_set_lb_fb(handler, fbfile);
 
                ret = fb_sync(lb_get_lb_fb(handler));
                if (ret != LB_STATUS_SUCCESS) {
@@ -326,7 +326,7 @@ static struct packet *master_pd_update_begin(pid_t pid, int handle, const struct
        }
 
        if (lb_get_pd_fb(handler)) {
-               lb_set_lb_fb(handler, fbfile);
+               (void)lb_set_lb_fb(handler, fbfile);
 
                ret = fb_sync(lb_get_lb_fb(handler));
                if (ret != LB_STATUS_SUCCESS) {
@@ -509,10 +509,21 @@ static struct packet *master_lb_updated(pid_t pid, int handle, const struct pack
                 */
                goto out;
        } else if (lb_get_lb_fb(handler)) {
-               lb_set_lb_fb(handler, fbfile);
-               ret = fb_sync(lb_get_lb_fb(handler));
-               if (ret != LB_STATUS_SUCCESS) {
-                       ErrPrint("Failed to do sync FB (%s - %s) (%d)\n", pkgname, util_basename(util_uri_to_path(id)), ret);
+               if (conf_frame_drop_for_resizing() && handler->size_changed_cb) {
+                       /* Just for skipping the update event callback call, After request to resize buffer, update event will be discarded */
+                       DbgPrint("Discards obsoloted update event\n");
+                       ret = LB_STATUS_ERROR_BUSY;
+               } else {
+                       (void)lb_set_lb_fb(handler, fbfile);
+
+                       if (!conf_manual_sync()) {
+                               ret = fb_sync(lb_get_lb_fb(handler));
+                               if (ret != LB_STATUS_SUCCESS) {
+                                       ErrPrint("Failed to do sync FB (%s - %s) (%d)\n", pkgname, util_basename(util_uri_to_path(id)), ret);
+                               }
+                       } else {
+                               ret = LB_STATUS_SUCCESS;
+                       }
                }
        } else {
                ret = LB_STATUS_SUCCESS;
@@ -685,13 +696,20 @@ static struct packet *master_pd_updated(pid_t pid, int handle, const struct pack
        if (lb_text_pd(handler)) {
                (void)parse_desc(handler, descfile, 1);
        } else {
-               (void)lb_set_pd_fb(handler, fbfile);
-
-               ret = fb_sync(lb_get_pd_fb(handler));
-               if (ret < 0) {
-                       ErrPrint("Failed to do sync FB (%s - %s), %d\n", pkgname, util_basename(util_uri_to_path(id)), ret);
+               if (conf_frame_drop_for_resizing() && handler->size_changed_cb) {
+                       /* Just for skipping the update event callback call, After request to resize buffer, update event will be discarded */
+                       DbgPrint("Discards obsoloted update event\n");
                } else {
-                       lb_invoke_event_handler(handler, LB_EVENT_PD_UPDATED);
+                       (void)lb_set_pd_fb(handler, fbfile);
+
+                        if (!conf_manual_sync()) {
+                                ret = fb_sync(lb_get_pd_fb(handler));
+                                if (ret < 0) {
+                                        ErrPrint("Failed to do sync FB (%s - %s), %d\n", pkgname, util_basename(util_uri_to_path(id)), ret);
+                                } else {
+                                        lb_invoke_event_handler(handler, LB_EVENT_PD_UPDATED);
+                                }
+                       }
                }
        }
 
@@ -811,7 +829,7 @@ static struct packet *master_size_changed(pid_t pid, int handle, const struct pa
                         * Update it too.
                         */
                        if (lb_get_lb_fb(handler)) {
-                               lb_set_lb_fb(handler, fbfile);
+                               (void)lb_set_lb_fb(handler, fbfile);
 
                                ret = fb_sync(lb_get_lb_fb(handler));
                                if (ret < 0) {
@@ -1079,7 +1097,8 @@ static struct packet *master_created(pid_t pid, int handle, const struct packet
                if (!strlen(lb_fname)) {
                        break;
                }
-               lb_set_lb_fb(handler, lb_fname);
+               (void)lb_set_lb_fb(handler, lb_fname);
+
                ret = fb_sync(lb_get_lb_fb(handler));
                if (ret < 0) {
                        ErrPrint("Failed to do sync FB (%s - %s)\n", pkgname, util_basename(util_uri_to_path(id)));
diff --git a/src/conf.c b/src/conf.c
new file mode 100644 (file)
index 0000000..9a9063b
--- /dev/null
@@ -0,0 +1,31 @@
+#include <stdio.h>
+
+static struct info {
+       int manual_sync;
+       int frame_drop_for_resizing;
+} s_info = {
+       .manual_sync = 0,
+       .frame_drop_for_resizing = 1,
+};
+
+void conf_set_manual_sync(int flag)
+{
+       s_info.manual_sync = flag;
+}
+
+int conf_manual_sync(void)
+{
+       return s_info.manual_sync;
+}
+
+void conf_set_frame_drop_for_resizing(int flag)
+{
+       s_info.frame_drop_for_resizing = flag;
+}
+
+int conf_frame_drop_for_resizing(void)
+{
+       return s_info.frame_drop_for_resizing;
+}
+
+/* End of a file */
index 1d9fc75..20bffc9 100644 (file)
--- a/src/fb.c
+++ b/src/fb.c
@@ -106,6 +106,11 @@ int fb_fini(void)
        return 0;
 }
 
+static inline void update_fb_size(struct fb_info *info)
+{
+       info->bufsz = info->w * info->h * s_info.depth;
+}
+
 static inline int sync_for_file(struct fb_info *info)
 {
        int fd;
@@ -208,6 +213,12 @@ static inline __attribute__((always_inline)) int sync_for_pixmap(struct fb_info
        }
 
        if (info->bufsz == 0) {
+               /*!
+                * If the client does not acquire the buffer,
+                * This function will do nothing.
+                * It will work only if the buffer is acquired.
+                * To sync its contents.
+                */
                DbgPrint("Nothing can be sync\n");
                return LB_STATUS_SUCCESS;
        }
@@ -386,7 +397,8 @@ void *fb_acquire_buffer(struct fb_info *info)
 
        if (!info->buffer) {
                if (!strncasecmp(info->id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP))) {
-                       info->bufsz = info->w * info->h * s_info.depth;
+                       update_fb_size(info);
+
                        buffer = calloc(1, sizeof(*buffer) + info->bufsz);
                        if (!buffer) {
                                CRITICAL_LOG("Heap: %s\n", strerror(errno));
@@ -406,7 +418,8 @@ void *fb_acquire_buffer(struct fb_info *info)
                         */
                        sync_for_pixmap(info);
                } else if (!strncasecmp(info->id, SCHEMA_FILE, strlen(SCHEMA_FILE))) {
-                       info->bufsz = info->w * info->h * s_info.depth;
+                       update_fb_size(info);
+
                        buffer = calloc(1, sizeof(*buffer) + info->bufsz);
                        if (!buffer) {
                                CRITICAL_LOG("Heap: %s\n", strerror(errno));
@@ -573,7 +586,8 @@ int fb_size(struct fb_info *info)
                return 0;
        }
 
-       info->bufsz = info->w * info->h * s_info.depth;
+       update_fb_size(info);
+
        return info->bufsz;
 }
 
index a139f7a..743ae95 100644 (file)
@@ -38,6 +38,7 @@
 #include "master_rpc.h"
 #include "client.h"
 #include "critical_log.h"
+#include "conf.h"
 
 #define EAPI __attribute__((visibility("default")))
 #define MINIMUM_EVENT  s_info.event_filter
@@ -2827,8 +2828,8 @@ void lb_set_id(struct livebox *handler, const char *id)
 void lb_set_filename(struct livebox *handler, const char *filename)
 {
        if (handler->filename) {
-               if (unlink(handler->filename) < 0) {
-                       ErrPrint("unlink: %s\n", strerror(errno));
+               if (handler->filename[0] && unlink(handler->filename) < 0) {
+                       ErrPrint("unlink: %s (%s)\n", strerror(errno), handler->filename);
                }
 
                free(handler->filename);
@@ -2836,7 +2837,7 @@ void lb_set_filename(struct livebox *handler, const char *filename)
 
        handler->filename = strdup(filename);
        if (!handler->filename) {
-               ErrPrint("Heap: %s\n", strerror(errno));
+               ErrPrint("Heap: %s (%s)\n", strerror(errno), handler->filename);
                return;
        }
 }
@@ -3140,4 +3141,34 @@ EAPI int livebox_client_resumed(void)
        return master_rpc_request_only(NULL, packet);
 }
 
+EAPI void livebox_set_manual_sync(int flag)
+{
+       conf_set_manual_sync(flag);
+}
+
+EAPI int livebox_manual_sync(void)
+{
+       return conf_manual_sync();
+}
+
+EAPI void livebox_set_frame_drop_for_resizing(int flag)
+{
+       conf_set_frame_drop_for_resizing(flag);
+}
+
+EAPI int livebox_frame_drop_for_resizing(void)
+{
+       return conf_frame_drop_for_resizing();
+}
+
+EAPI int livebox_sync_lb_fb(struct livebox *handler)
+{
+       return fb_sync(lb_get_lb_fb(handler));
+}
+
+EAPI int livebox_sync_pd_fb(struct livebox *handler)
+{
+       return fb_sync(lb_get_pd_fb(handler));
+}
+
 /* End of a file */