Replace impelementation.
authorSung-jae Park <nicesj.park@samsung.com>
Sun, 24 Aug 2014 12:26:01 +0000 (21:26 +0900)
committerSung-jae Park <nicesj.park@samsung.com>
Sun, 24 Aug 2014 12:26:01 +0000 (21:26 +0900)
[model] Redwood,Kiran,B3(Wearable)
[binary_type] AP
[customer] Docomo/Orange/ATT/Open
[issue#] N/A
[problem]
[cause]
[solution]
[team] HomeTF
[request]
[horizontal_expansion]

Change-Id: Ia48ab2e4c49fb488a2f39f405845fc9b3a5a6d12

CMakeLists.txt
include/dynamicbox.h
src/client.c
src/desc_parser.c
src/dynamicbox.c
src/file_service.c
src/livebox.c [deleted file]
src/master_rpc.c
src/util.c

index 08adf20..270c909 100644 (file)
@@ -26,6 +26,17 @@ pkg_check_modules(pkgs REQUIRED
        vconf
 )
 
+SET(BUILD_SOURCE
+       src/client.c
+       src/conf.c
+       src/desc_parser.c
+       src/dlist.c
+       src/dynamicbox.c
+       src/file_service.c
+       src/master_rpc.c
+       src/util.c
+)
+
 IF (X11_SUPPORT)
 pkg_check_modules(pkgs_extra REQUIRED
        x11
index df2c3d1..9d68147 100644 (file)
@@ -799,7 +799,6 @@ extern void *dynamicbox_acquire_fb(struct dynamicbox *handler, int gbar);
  * @brief Releases the buffer of a dynamicbox (only for the buffer type).
  * @since_tizen 2.3
  * @param[in] buffer Buffer
- * @param[in] gbar 1 for Glance Bar or 0
  * @privlevel public
  * @privilege %http://tizen.org/privilege/dynamicbox.viewer
  * @return int
@@ -807,20 +806,19 @@ extern void *dynamicbox_acquire_fb(struct dynamicbox *handler, int gbar);
  * @retval #DBOX_STATUS_ERROR_NONE Successfully done
  * @see dynamicbox_acquire_fb()
  */
-extern int dynamicbox_release_fb(void *buffer, int gbar);
+extern int dynamicbox_release_fb(void *buffer);
 
 /**
  * @internal
  * @brief Gets the reference count of Dynamicbox buffer (only for the buffer type).
  * @since_tizen 2.3
  * @param[in] buffer Buffer
- * @param[in] gbar 1 for Glance Bar or 0
  * @return int
  * @retval #DBOX_STATUS_ERROR_INVALID_PARAMETER Invalid argument
  * @retval #DBOX_STATUS_ERROR_FAULT Unrecoverable error occurred
  * @retval refcnt Positive integer including ZERO
  */
-extern int dynamicbox_fb_refcnt(void *buffer, int gbar);
+extern int dynamicbox_fb_refcnt(void *buffer);
 
 /**
  * @internal
index 2ad3d75..cbd9df4 100644 (file)
 #include <packet.h>
 #include <com-core.h>
 #include <com-core_packet.h>
-#include <livebox-errno.h>
-#include <livebox-service.h>
+#include <dynamicbox_errno.h>
+#include <dynamicbox_service.h>
 #include <secure_socket.h>
 
 #include "debug.h"
 #include "client.h"
-#include "livebox.h"
-#include "livebox_internal.h"
+#include "dynamicbox.h"
+#include "dynamicbox_internal.h"
 #include "desc_parser.h"
 #include "fb.h"
 #include "util.h"
@@ -133,7 +133,7 @@ static struct packet *master_pinup(pid_t pid, int handle, const struct packet *p
                goto out;
        }
 
-       if (status == (int)LB_STATUS_SUCCESS) {
+       if (status == (int)DBOX_STATUS_ERROR_NONE) {
                new_content = strdup(content);
                if (new_content) {
                        free(common->content);
@@ -141,7 +141,7 @@ static struct packet *master_pinup(pid_t pid, int handle, const struct packet *p
                        common->is_pinned_up = pinup;
                } else {
                        ErrPrint("Heap: %s\n", strerror(errno));
-                       status = LB_STATUS_ERROR_MEMORY;
+                       status = DBOX_STATUS_ERROR_OUT_OF_MEMORY;
                }
        }
 
@@ -160,7 +160,7 @@ static struct packet *master_pinup(pid_t pid, int handle, const struct packet *p
                        handler->cbs.pinup.data = NULL;
 
                        cb(handler, status, cbdata);
-               } else if (status == (int)LB_STATUS_SUCCESS) {
+               } else if (status == (int)DBOX_STATUS_ERROR_NONE) {
                        lb_invoke_event_handler(handler, LB_EVENT_PINUP_CHANGED);
                }
        }
@@ -249,8 +249,8 @@ static struct packet *master_deleted(pid_t pid, int handle, const struct packet
                        handler->cbs.created.cb = NULL;
                        handler->cbs.created.data = NULL;
 
-                       if (reason == (int)LB_STATUS_SUCCESS) {
-                               reason = LB_STATUS_ERROR_CANCEL;
+                       if (reason == (int)DBOX_STATUS_ERROR_NONE) {
+                               reason = DBOX_STATUS_ERROR_CANCEL;
                        }
 
                        cb(handler, reason, cbdata);
@@ -324,7 +324,7 @@ static struct packet *master_lb_update_begin(pid_t pid, int handle, const struct
 
                ret = lb_sync_lb_fb(common);
 
-               if (ret != (int)LB_STATUS_SUCCESS) {
+               if (ret != (int)DBOX_STATUS_ERROR_NONE) {
                        ErrPrint("Failed to do sync FB (%s - %s) (%d)\n", pkgname, fbfile, ret);
                } else {
                        struct dlist *l;
@@ -370,7 +370,7 @@ static struct packet *master_pd_update_begin(pid_t pid, int handle, const struct
                (void)lb_set_pd_fb(common, fbfile);
 
                ret = lb_sync_pd_fb(common);
-               if (ret != (int)LB_STATUS_SUCCESS) {
+               if (ret != (int)DBOX_STATUS_ERROR_NONE) {
                        ErrPrint("Failed to do sync FB (%s - %s) (%d)\n", pkgname, fbfile, ret);
                } else {
                        struct dlist *l;
@@ -711,24 +711,24 @@ static struct packet *master_lb_updated(pid_t pid, int handle, const struct pack
                if (conf_frame_drop_for_resizing() && common->request.size_changed) {
                        /* 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;
+                       ret = DBOX_STATUS_ERROR_BUSY;
                } else {
                        (void)lb_set_lb_fb(common, fbfile);
 
                        if (!conf_manual_sync()) {
                                ret = lb_sync_lb_fb(common);
-                               if (ret != (int)LB_STATUS_SUCCESS) {
+                               if (ret != (int)DBOX_STATUS_ERROR_NONE) {
                                        ErrPrint("Failed to do sync FB (%s - %s) (%d)\n", pkgname, util_basename(util_uri_to_path(id)), ret);
                                }
                        } else {
-                               ret = LB_STATUS_SUCCESS;
+                               ret = DBOX_STATUS_ERROR_NONE;
                        }
                }
        } else {
-               ret = LB_STATUS_SUCCESS;
+               ret = DBOX_STATUS_ERROR_NONE;
        }
 
-       if (ret == (int)LB_STATUS_SUCCESS) {
+       if (ret == (int)DBOX_STATUS_ERROR_NONE) {
                struct dlist *l;
                struct dlist *n;
 
@@ -778,7 +778,7 @@ static struct packet *master_pd_created(pid_t pid, int handle, const struct pack
                goto out;
        }
 
-       common->is_pd_created = (status == (int)LB_STATUS_SUCCESS);
+       common->is_pd_created = (status == (int)DBOX_STATUS_ERROR_NONE);
        common->request.pd_created = 0;
 
        if (common->is_pd_created) {
@@ -833,7 +833,7 @@ static struct packet *master_pd_created(pid_t pid, int handle, const struct pack
                         * Because, in the create callback, user can call create_pd function again.
                         */
                        cb(handler, status, cbdata);
-               } else if (status == (int)LB_STATUS_SUCCESS) {
+               } else if (status == (int)DBOX_STATUS_ERROR_NONE) {
                        lb_invoke_event_handler(handler, LB_EVENT_PD_CREATED);
                } 
        }
@@ -895,7 +895,7 @@ static struct packet *master_pd_destroyed(pid_t pid, int handle, const struct pa
                         * Because, in the create callback, user can call destroy_pd function again.
                         */
                        cb(handler, status, cbdata);
-               } else if (status == (int)LB_STATUS_SUCCESS) {
+               } else if (status == (int)DBOX_STATUS_ERROR_NONE) {
                        lb_invoke_event_handler(handler, LB_EVENT_PD_DESTROYED);
                }
        }
@@ -1034,7 +1034,7 @@ static struct packet *master_update_mode(pid_t pid, int handle, const struct pac
                goto out;
        }
 
-       if (status == (int)LB_STATUS_SUCCESS) {
+       if (status == (int)DBOX_STATUS_ERROR_NONE) {
                lb_set_update_mode(common, active_mode);
        }
 
@@ -1051,7 +1051,7 @@ static struct packet *master_update_mode(pid_t pid, int handle, const struct pac
                        handler->cbs.update_mode.data = NULL;
 
                        cb(handler, status, cbdata);
-               } else if (status == (int)LB_STATUS_SUCCESS) {
+               } else if (status == (int)DBOX_STATUS_ERROR_NONE) {
                        lb_invoke_event_handler(handler, LB_EVENT_UPDATE_MODE_CHANGED);
                }
        }
@@ -1104,7 +1104,7 @@ static struct packet *master_size_changed(pid_t pid, int handle, const struct pa
                 * So the PD has no private resized event handler.
                 * Notify it via global event handler only.
                 */
-               if (status == (int)LB_STATUS_SUCCESS) {
+               if (status == (int)DBOX_STATUS_ERROR_NONE) {
                        struct dlist *l;
 
                        lb_set_pdsize(common, w, h);
@@ -1118,7 +1118,7 @@ static struct packet *master_size_changed(pid_t pid, int handle, const struct pa
                struct dlist *l;
                struct dlist *n;
 
-               if (status == (int)LB_STATUS_SUCCESS) {
+               if (status == (int)DBOX_STATUS_ERROR_NONE) {
                        lb_set_size(common, w, h);
 
                        /*!
@@ -1155,7 +1155,7 @@ static struct packet *master_size_changed(pid_t pid, int handle, const struct pa
                                handler->cbs.size_changed.data = NULL;
 
                                cb(handler, status, cbdata);
-                       } else if (status == (int)LB_STATUS_SUCCESS) {
+                       } else if (status == (int)DBOX_STATUS_ERROR_NONE) {
                                lb_invoke_event_handler(handler, LB_EVENT_LB_SIZE_CHANGED);
                        }
                }
@@ -1194,7 +1194,7 @@ static struct packet *master_period_changed(pid_t pid, int handle, const struct
                goto out;
        }
 
-       if (status == (int)LB_STATUS_SUCCESS) {
+       if (status == (int)DBOX_STATUS_ERROR_NONE) {
                lb_set_period(common, period);
        }
 
@@ -1212,7 +1212,7 @@ static struct packet *master_period_changed(pid_t pid, int handle, const struct
                        handler->cbs.period_changed.data = NULL;
 
                        cb(handler, status, cbdata);
-               } else if (status == (int)LB_STATUS_SUCCESS) {
+               } else if (status == (int)DBOX_STATUS_ERROR_NONE) {
                        lb_invoke_event_handler(handler, LB_EVENT_PERIOD_CHANGED);
                }
        }
@@ -1256,7 +1256,7 @@ static struct packet *master_group_changed(pid_t pid, int handle, const struct p
                goto out;
        }
 
-       if (status == (int)LB_STATUS_SUCCESS) {
+       if (status == (int)DBOX_STATUS_ERROR_NONE) {
                (void)lb_set_group(common, cluster, category);
        }
 
@@ -1274,7 +1274,7 @@ static struct packet *master_group_changed(pid_t pid, int handle, const struct p
                        handler->cbs.group_changed.data = NULL;
 
                        cb(handler, status, cbdata);
-               } else if (status == (int)LB_STATUS_SUCCESS) {
+               } else if (status == (int)DBOX_STATUS_ERROR_NONE) {
                        lb_invoke_event_handler(handler, LB_EVENT_GROUP_CHANGED);
                }
        }
@@ -1327,7 +1327,7 @@ static struct packet *master_created(pid_t pid, int handle, const struct packet
                        &lb_type, &pd_type, &period, &title, &is_pinned_up);
        if (ret != 22) {
                ErrPrint("Invalid argument\n");
-               ret = LB_STATUS_ERROR_INVALID;
+               ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
                goto out;
        }
 
@@ -1347,7 +1347,7 @@ static struct packet *master_created(pid_t pid, int handle, const struct packet
                handler = lb_new_livebox(pkgname, id, timestamp, cluster, category);
                if (!handler) {
                        ErrPrint("Failed to create a new livebox\n");
-                       ret = LB_STATUS_ERROR_FAULT;
+                       ret = DBOX_STATUS_ERROR_FAULT;
                        goto out;
                }
                common = handler->common;
@@ -1360,7 +1360,7 @@ static struct packet *master_created(pid_t pid, int handle, const struct packet
                                 * This is not possible!!!
                                 */
                                ErrPrint("Invalid handler\n");
-                               ret = LB_STATUS_ERROR_INVALID;
+                               ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
                                goto out;
                        }
 
@@ -1381,7 +1381,7 @@ static struct packet *master_created(pid_t pid, int handle, const struct packet
                                        content, cluster, category,
                                        lb_fname, pd_fname);
 
-                       ret = LB_STATUS_ERROR_ALREADY;
+                       ret = DBOX_STATUS_ERROR_ALREADY;
                        goto out;
                }
 
@@ -1523,7 +1523,7 @@ out:
                                                 */
                                        }
                                } else if (handler->state != DELETE) {
-                                       handler->cbs.created.cb(handler, LB_STATUS_ERROR_CANCEL, handler->cbs.created.data);
+                                       handler->cbs.created.cb(handler, DBOX_STATUS_ERROR_CANCEL, handler->cbs.created.data);
                                        lb_unref(handler, 1);
                                }
                        } else {
@@ -1540,7 +1540,7 @@ out:
                 * Do not clear this to use this from the deleted event callback.
                 * if this value is not cleared when the deleted event callback check it,
                 * it means that the created function is not called yet.
-                * Then the call the deleted event callback with LB_STATUS_ERROR_CANCEL errno.
+                * Then the call the deleted event callback with DBOX_STATUS_ERROR_CANCEL errno.
                 */
        }
 
@@ -1670,14 +1670,14 @@ static inline int make_connection(void)
        s_info.fd = com_core_packet_client_init(client_addr(), 0, s_table);
        if (s_info.fd < 0) {
                ErrPrint("Try this again later\n");
-               return LB_STATUS_ERROR_IO;
+               return DBOX_STATUS_ERROR_IO_ERROR;
        }
 
        packet = packet_create("acquire", "d", util_timestamp());
        if (!packet) {
                com_core_packet_client_fini(s_info.fd);
                s_info.fd = -1;
-               return LB_STATUS_ERROR_FAULT;
+               return DBOX_STATUS_ERROR_FAULT;
        }
 
        ret = master_rpc_async_request(NULL, packet, 1, acquire_cb, NULL);
@@ -1685,10 +1685,10 @@ static inline int make_connection(void)
                ErrPrint("Master RPC returns %d\n", ret);
                com_core_packet_client_fini(s_info.fd);
                s_info.fd = -1;
-               return LB_STATUS_ERROR_IO;
+               return DBOX_STATUS_ERROR_IO_ERROR;
        }
 
-       return LB_STATUS_SUCCESS;
+       return DBOX_STATUS_ERROR_NONE;
 }
 
 static int connected_cb(int handle, void *data)
@@ -1706,7 +1706,7 @@ static void master_started_cb(keynode_t *node, void *data)
        }
 
        DbgPrint("Master state: %d\n", state);
-       if (state == 1 && make_connection() == (int)LB_STATUS_SUCCESS) {
+       if (state == 1 && make_connection() == (int)DBOX_STATUS_ERROR_NONE) {
                int ret;
                ret = vconf_ignore_key_changed(VCONFKEY_MASTER_STARTED, master_started_cb);
                if (ret < 0) {
@@ -1767,7 +1767,7 @@ int client_init(int use_thread)
                s_info.client_addr = strdup(CLIENT_SOCKET);
                if (!s_info.client_addr) {
                        ErrPrint("Heap: %s\n", strerror(errno));
-                       return LB_STATUS_ERROR_MEMORY;
+                       return DBOX_STATUS_ERROR_OUT_OF_MEMORY;
                }
        }
 
@@ -1784,7 +1784,7 @@ int client_init(int use_thread)
        }
 
        master_started_cb(NULL, NULL);
-       return LB_STATUS_SUCCESS;
+       return DBOX_STATUS_ERROR_NONE;
 }
 
 int client_fd(void)
@@ -1814,7 +1814,7 @@ int client_fini(void)
        s_info.fd = -1;
        free(s_info.client_addr);
        s_info.client_addr = NULL;
-       return LB_STATUS_SUCCESS;
+       return DBOX_STATUS_ERROR_NONE;
 }
 
 /* End of a file */
index 686e9c3..8705e3d 100644 (file)
@@ -106,7 +106,7 @@ static int update_text(struct livebox *handle, struct block *block, int is_pd)
 
        if (!block || !block->part || !block->data) {
                ErrPrint("Invalid argument\n");
-               return LB_STATUS_ERROR_INVALID;
+               return DBOX_STATUS_ERROR_INVALID_PARAMETER;
        }
 
        ops = is_pd ? &handle->cbs.pd_ops : &handle->cbs.lb_ops;
@@ -123,7 +123,7 @@ static int update_image(struct livebox *handle, struct block *block, int is_pd)
 
        if (!block || !block->part) {
                ErrPrint("Invalid argument\n");
-               return LB_STATUS_ERROR_INVALID;
+               return DBOX_STATUS_ERROR_INVALID_PARAMETER;
        }
 
        ops = is_pd ? &handle->cbs.pd_ops : &handle->cbs.lb_ops;
@@ -140,7 +140,7 @@ static int update_script(struct livebox *handle, struct block *block, int is_pd)
 
        if (!block || !block->part) {
                ErrPrint("Invalid argument\n");
-               return LB_STATUS_ERROR_INVALID;
+               return DBOX_STATUS_ERROR_INVALID_PARAMETER;
        }
 
        ops = is_pd ? &handle->cbs.pd_ops : &handle->cbs.lb_ops;
@@ -157,7 +157,7 @@ static int update_signal(struct livebox *handle, struct block *block, int is_pd)
 
        if (!block) {
                ErrPrint("Invalid argument\n");
-               return LB_STATUS_ERROR_INVALID;
+               return DBOX_STATUS_ERROR_INVALID_PARAMETER;
        }
 
        ops = is_pd ? &handle->cbs.pd_ops : &handle->cbs.lb_ops;
@@ -175,12 +175,12 @@ static int update_drag(struct livebox *handle, struct block *block, int is_pd)
 
        if (!block || !block->data || !block->part) {
                ErrPrint("Invalid argument\n");
-               return LB_STATUS_ERROR_INVALID;
+               return DBOX_STATUS_ERROR_INVALID_PARAMETER;
        }
 
        if (sscanf(block->data, "%lfx%lf", &dx, &dy) != 2) {
                ErrPrint("Invalid format of data\n");
-               return LB_STATUS_ERROR_INVALID;
+               return DBOX_STATUS_ERROR_INVALID_PARAMETER;
        }
 
        ops = is_pd ? &handle->cbs.pd_ops : &handle->cbs.lb_ops;
@@ -197,7 +197,7 @@ static int update_info(struct livebox *handle, struct block *block, int is_pd)
 
        if (!block || !block->part || !block->data) {
                ErrPrint("Invalid argument\n");
-               return LB_STATUS_ERROR_INVALID;
+               return DBOX_STATUS_ERROR_INVALID_PARAMETER;
        }
 
        ops = is_pd ? &handle->cbs.pd_ops : &handle->cbs.lb_ops;
@@ -206,7 +206,7 @@ static int update_info(struct livebox *handle, struct block *block, int is_pd)
 
                if (sscanf(block->data, "%dx%d", &w, &h) != 2) {
                        ErrPrint("Invalid format (%s)\n", block->data);
-                       return LB_STATUS_ERROR_INVALID;
+                       return DBOX_STATUS_ERROR_INVALID_PARAMETER;
                }
 
                if (ops->update_info_size) {
@@ -227,7 +227,7 @@ static int update_access(struct livebox *handle, struct block *block, int is_pd)
 
        if (!block) {
                ErrPrint("Invalid argument\n");
-               return LB_STATUS_ERROR_INVALID;
+               return DBOX_STATUS_ERROR_INVALID_PARAMETER;
        }
 
        ops = is_pd ? &handle->cbs.pd_ops : &handle->cbs.lb_ops;
@@ -244,7 +244,7 @@ static int operate_access(struct livebox *handle, struct block *block, int is_pd
 
        if (!block) {
                ErrPrint("Invalid argument\n");
-               return LB_STATUS_ERROR_INVALID;
+               return DBOX_STATUS_ERROR_INVALID_PARAMETER;
        }
 
        ops = is_pd ? &handle->cbs.pd_ops : &handle->cbs.lb_ops;
@@ -261,7 +261,7 @@ static int update_color(struct livebox *handle, struct block *block, int is_pd)
 
        if (!block) {
                ErrPrint("Invalid argument\n");
-               return LB_STATUS_ERROR_INVALID;
+               return DBOX_STATUS_ERROR_INVALID_PARAMETER;
        }
 
        ops = is_pd ? &handle->cbs.pd_ops : &handle->cbs.lb_ops;
@@ -416,7 +416,7 @@ int parse_desc(struct livebox_common *common, const char *filename, int is_pd)
 
        filebuf = load_file(filename);
        if (!filebuf) {
-               return LB_STATUS_ERROR_IO;
+               return DBOX_STATUS_ERROR_IO_ERROR;
        }
 
        fileptr = filebuf;
@@ -660,7 +660,7 @@ int parse_desc(struct livebox_common *common, const char *filename, int is_pd)
                        block_list = dlist_remove(block_list, l);
                }
 
-               return LB_STATUS_ERROR_FAULT;
+               return DBOX_STATUS_ERROR_FAULT;
        }
 
                
@@ -691,7 +691,7 @@ int parse_desc(struct livebox_common *common, const char *filename, int is_pd)
        }
        ErrPrint("End: Set content for object\n");
 
-       return LB_STATUS_SUCCESS;
+       return DBOX_STATUS_ERROR_NONE;
 }
 
 /* End of a file */
index be9e66a..1fe5614 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2013  Samsung Electronics Co., Ltd
+ * Copyright 2014  Samsung Electronics Co., Ltd
  *
  * Licensed under the Flora License, Version 1.1 (the "License");
  * you may not use this file except in compliance with the License.
  * limitations under the License.
  */
 
+#include <stdio.h>
+#include <errno.h>
+#include <stdlib.h> /* malloc */
+#include <string.h> /* strdup */
+#include <math.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#include <gio/gio.h>
+#include <aul.h>
+#include <dlog.h>
+
+#include <com-core_packet.h>
+#include <packet.h>
+#include <dynamicbox_service.h>
+#include <dynamicbox_errno.h>
+
+#include "debug.h"
+#include "fb.h"
 #include "dynamicbox.h"
-#include "livebox.h"
-#include "livebox-errno.h"
+#include "dynamicbox_internal.h"
+#include "dlist.h"
+#include "util.h"
+#include "master_rpc.h"
+#include "client.h"
+#include "conf.h"
+
+#define EAPI __attribute__((visibility("default")))
+
+#if defined(FLOG)
+FILE *__file_log_fp;
+#endif
 
+#define ACCESS_TYPE_DOWN 0
+#define ACCESS_TYPE_MOVE 1
+#define ACCESS_TYPE_UP 2
+#define ACCESS_TYPE_CUR 0
+#define ACCESS_TYPE_NEXT 1
+#define ACCESS_TYPE_PREV 2
+#define ACCESS_TYPE_OFF 3
 
 #define EAPI __attribute__((visibility("default")))
 
-EAPI int dynamicbox_init(void *disp, int prevent_overwrite, double event_filter, int use_thread)
-{
-       return livebox_init_with_options(disp, prevent_overwrite, event_filter, use_thread);
-}
+static struct info {
+       struct dlist *livebox_list;
+       struct dlist *livebox_common_list;
 
-EAPI int dynamicbox_fini(void)
-{
-       return livebox_fini();
-}
+       struct dlist *event_list;
+       struct dlist *fault_list;
 
-EAPI struct dynamicbox *dynamicbox_add(const char *pkgname, const char *content, const char *cluster, const char *category, double period, int type, dynamicbox_ret_cb_t cb, void *data)
-{
-       return (struct dynamicbox*)livebox_add(pkgname, content, cluster, category, period, type, (ret_cb_t)cb, data);
-}
+       int init_count;
+       int prevent_overwrite;
+       enum event_state event_state;
+       enum event_state fault_state;
+       guint job_timer;
+       struct dlist *job_list;
 
-EAPI double dynamicbox_period(struct dynamicbox *handler)
-{
-       return livebox_period((struct livebox*)handler);
-}
+       struct launch {
+               int (*handler)(struct livebox *handler, const char *appid, void *data);
+               void *data;
+       } launch;
+} s_info = {
+       .livebox_list = NULL,
+       .event_list = NULL,
+       .fault_list = NULL,
+       .init_count = 0,
+       .prevent_overwrite = 0,
+       .event_state = INFO_STATE_CALLBACK_IN_IDLE,
+       .fault_state = INFO_STATE_CALLBACK_IN_IDLE,
+       .job_timer = 0,
+       .job_list = NULL,
+       .launch = {
+               .handler = default_launch_handler,
+               .data = NULL,
+       },
+};
 
-EAPI int dynamicbox_set_period(struct dynamicbox *handler, double period, dynamicbox_ret_cb_t cb, void *data)
+struct cb_info {
+       ret_cb_t cb;
+       void *data;
+};
+
+struct event_info {
+       int is_deleted;
+       int (*handler)(struct livebox *handler, enum livebox_event_type event, void *data);
+       void *user_data;
+};
+
+struct fault_info {
+       int is_deleted;
+       int (*handler)(enum livebox_fault_type event, const char *pkgname, const char *filename, const char *func, void *data);
+       void *user_data;
+};
+
+static int default_launch_handler(struct livebox *handler, const char *appid, void *data);
+static void lb_pixmap_acquired_cb(struct livebox *handler, const struct packet *result, void *data);
+static void pd_pixmap_acquired_cb(struct livebox *handler, const struct packet *result, void *data);
+
+static int default_launch_handler(struct livebox *handler, const char *appid, void *data)
 {
-       return livebox_set_period((struct livebox*)handler, period, (ret_cb_t)cb, data);
+       int ret;
+
+       ret = aul_launch_app(appid, NULL);
+       if (ret <= 0) {
+               ErrPrint("Failed to launch an app %s (%d)\n", appid, ret);
+       }
+
+/*
+       app_control_h service;
+
+       DbgPrint("AUTO_LAUNCH [%s]\n", handler->common->lb.auto_launch);
+
+       ret = app_control_create(&service);
+       if (ret == APP_CONTROL_ERROR_NONE) {
+               app_control_set_package(service, handler->common->lb.auto_launch);
+               app_control_send_launch_request(service, NULL, NULL);
+               app_control_destroy(service);
+       } else {
+               ErrPrint("Failed to launch an app %s (%d)\n", handler->common->lb.auto_launch, ret);
+       }
+*/
+
+       return ret > 0 ? LB_STATUS_SUCCESS : LB_STATUS_ERROR_FAULT;
 }
 
-EAPI int dynamicbox_del(struct dynamicbox *handler, int type, dynamicbox_ret_cb_t cb, void *data)
+static inline void default_create_cb(struct livebox *handler, int ret, void *data)
 {
-       return livebox_del(((struct livebox*) handler), type, (ret_cb_t)cb, data);
+       DbgPrint("Default created event handler: %d\n", ret);
 }
 
-EAPI int dynamicbox_set_fault_handler(int (*dbox_cb)(enum dynamicbox_fault_type, const char *, const char *, const char *, void *), void *data)
+static inline void default_delete_cb(struct livebox *handler, int ret, void *data)
 {
-       typedef int (*set_fault_handler_cb)(enum livebox_fault_type, const char *, const char *, const char *, void *);
-
-       return livebox_set_fault_handler((set_fault_handler_cb)dbox_cb, data);
+       DbgPrint("Default deleted event handler: %d\n", ret);
 }
 
-EAPI void *dynamicbox_unset_fault_handler(int (*dbox_cb)(enum dynamicbox_fault_type, const char *, const char *, const char *, void *))
+static inline void default_pinup_cb(struct livebox *handler, int ret, void *data)
 {
-       typedef int (*cb)(enum livebox_fault_type, const char *, const char *, const char *, void *);
-
-       return livebox_unset_fault_handler((cb)dbox_cb);
+       DbgPrint("Default pinup event handler: %d\n", ret);
 }
 
-EAPI int dynamicbox_set_event_handler(int (*dbox_cb)(struct dynamicbox *, enum dynamicbox_event_type, void *), void *data)
+static inline void default_group_changed_cb(struct livebox *handler, int ret, void *data)
 {
-       typedef int (*cb)(struct livebox *, enum livebox_event_type, void *);
-
-       return livebox_set_event_handler((cb)dbox_cb, data);
+       DbgPrint("Default group changed event handler: %d\n", ret);
 }
 
-EAPI void *dynamicbox_unset_event_handler(int (*dbox_cb)(struct dynamicbox *, enum dynamicbox_event_type, void *))
+static inline void default_period_changed_cb(struct livebox *handler, int ret, void *data)
 {
-       typedef int (*cb)(struct livebox *, enum livebox_event_type, void *);
-
-       return livebox_unset_event_handler((cb)dbox_cb);
+       DbgPrint("Default period changed event handler: %d\n", ret);
 }
 
-EAPI int dynamicbox_set_update_mode(struct dynamicbox *handler, int active_update, dynamicbox_ret_cb_t cb, void *data)
+static inline void default_pd_created_cb(struct livebox *handler, int ret, void *data)
 {
-       return livebox_set_update_mode((struct livebox*)handler, active_update, (ret_cb_t)cb, data);
+       DbgPrint("Default PD created event handler: %d\n", ret);
 }
 
-EAPI int dynamicbox_is_active_update(struct dynamicbox *handler)
+static inline void default_pd_destroyed_cb(struct livebox *handler, int ret, void *data)
 {
-       return livebox_is_active_update((struct livebox*)handler);
+       DbgPrint("Default PD destroyed event handler: %d\n", ret);
 }
 
-EAPI int dynamicbox_resize(struct dynamicbox *handler, int type, dynamicbox_ret_cb_t cb, void *data)
+static inline void default_lb_size_changed_cb(struct livebox *handler, int ret, void *data)
 {
-       return livebox_resize((struct livebox*)handler, type, (ret_cb_t)cb, data);
+       DbgPrint("Default LB size changed event handler: %d\n", ret);
 }
 
-EAPI int dynamicbox_click(struct dynamicbox *handler, double x, double y)
+static inline void default_update_mode_cb(struct livebox *handler, int ret, void *data)
 {
-       return livebox_click((struct livebox*)handler, x, y);
+       DbgPrint("Default update mode set event handler: %d\n", ret);
 }
 
-EAPI int dynamicbox_has_pd(struct dynamicbox *handler)
+static inline void default_access_event_cb(struct livebox *handler, int ret, void *data)
 {
-       return livebox_has_pd((struct livebox*)handler);
+       DbgPrint("Default access event handler: %d\n", ret);
 }
 
-EAPI int dynamicbox_glance_bar_is_created(struct dynamicbox *handler)
+static inline void default_key_event_cb(struct livebox *handler, int ret, void *data)
 {
-       return livebox_pd_is_created((struct livebox*)handler);
+       DbgPrint("Default key event handler: %d\n", ret);
 }
 
-EAPI int dynamicbox_create_glance_bar(struct dynamicbox *handler, double x, double y, dynamicbox_ret_cb_t cb, void *data)
+static inline __attribute__((always_inline)) struct cb_info *create_cb_info(ret_cb_t cb, void *data)
 {
-       return livebox_create_pd_with_position((struct livebox*)handler, x, y, (ret_cb_t)cb, data);
+       struct cb_info *info;
+
+       info = malloc(sizeof(*info));
+       if (!info) {
+               ErrPrint("Heap: %s\n", strerror(errno));
+               return NULL;
+       }
+
+       info->cb = cb;
+       info->data = data;
+       return info;
 }
 
-EAPI int dynamicbox_move_glance_bar(struct dynamicbox *handler, double x, double y)
+static inline void destroy_cb_info(struct cb_info *info)
 {
-       return livebox_move_pd((struct livebox*)handler, x, y);
+       free(info);
 }
 
-EAPI int dynamicbox_activate(const char *pkgname, dynamicbox_ret_cb_t cb, void *data)
+static int do_fb_lock(int fd)
 {
-       return livebox_activate(pkgname, (ret_cb_t)cb, data);
+        struct flock flock;
+       int ret;
+
+       flock.l_type = F_RDLCK;
+       flock.l_whence = SEEK_SET;
+       flock.l_start = 0;
+       flock.l_len = 0;
+       flock.l_pid = getpid();
+
+       do {
+               ret = fcntl(fd, F_SETLKW, &flock);
+               if (ret < 0) {
+                       ret = errno;
+                       ErrPrint("fcntl: %s\n", strerror(errno));
+               }
+       } while (ret == EINTR);
+
+       return ret;
 }
 
-EAPI int dynamicbox_destroy_glance_bar(struct dynamicbox *handler, dynamicbox_ret_cb_t cb, void *data)
+static int do_fb_unlock(int fd)
 {
-       return livebox_destroy_pd((struct livebox*)handler, (ret_cb_t)cb, data);
+       struct flock flock;
+       int ret;
+
+       flock.l_type = F_UNLCK;
+       flock.l_whence = SEEK_SET;
+       flock.l_start = 0;
+       flock.l_len = 0;
+       flock.l_pid = getpid();
+
+       do {
+               ret = fcntl(fd, F_SETLKW, &flock);
+               if (ret < 0) {
+                       ret = errno;
+                       ErrPrint("fcntl: %s\n", strerror(errno));
+               }
+       } while (ret == EINTR);
+
+       return ret;
 }
 
-EAPI int dynamicbox_feed_access_event(struct dynamicbox *handler, enum dynamicbox_access_event_type type, struct dynamicbox_access_event_info *info, dynamicbox_ret_cb_t cb, void *data)
+int lb_destroy_lock_file(struct livebox_common *common, int is_pd)
 {
-       enum access_event_type _type;
-       switch (type) {
-       case DBOX_ACCESS_HIGHLIGHT:
-               switch (info->type) {
-               case DBOX_ACCESS_TYPE_HIGHLIGHT:
-                       _type = LB_ACCESS_HIGHLIGHT;
-                       break;
-               case DBOX_ACCESS_TYPE_HIGHLIGHT_NEXT:
-                       _type = LB_ACCESS_HIGHLIGHT_NEXT;
-                       break;
-               case DBOX_ACCESS_TYPE_HIGHLIGHT_PREV:
-                       _type = LB_ACCESS_HIGHLIGHT_PREV;
-                       break;
-               case DBOX_ACCESS_TYPE_UNHIGHLIGHT:
-                       _type = LB_ACCESS_UNHIGHLIGHT;
-                       break;
-               default:
-                       return LB_STATUS_ERROR_INVALID; //DBOX_STATUS_ERROR_INVALID_PARAMETER;
+       if (is_pd) {
+               if (!common->pd.lock) {
+                       return LB_STATUS_ERROR_INVALID;
                }
-               break;
-       case DBOX_ACCESS_ACTIVATE:
-               _type = LB_ACCESS_ACTIVATE;
-               break;
-       case DBOX_ACCESS_ACTION:
-               switch (info->type) {
-               case DBOX_ACCESS_TYPE_UP:
-                       _type = LB_ACCESS_ACTION_UP;
-                       break;
-               case DBOX_ACCESS_TYPE_DOWN:
-                       _type = LB_ACCESS_ACTION_DOWN;
-                       break;
-               default:
-                       return LB_STATUS_ERROR_INVALID; //DBOX_STATUS_ERROR_INVALID_PARAMETER;
+
+               if (close(common->pd.lock_fd) < 0) {
+                       ErrPrint("close: %s\n", strerror(errno));
                }
-               break;
-       case DBOX_ACCESS_SCROLL:
-               switch (info->type) {
-               case DBOX_ACCESS_TYPE_UP:
-                       _type = LB_ACCESS_SCROLL_UP;
-                       break;
-               case DBOX_ACCESS_TYPE_MOVE:
-                       _type = LB_ACCESS_SCROLL_MOVE;
-                       break;
-               case DBOX_ACCESS_TYPE_DOWN:
-                       _type = LB_ACCESS_SCROLL_DOWN;
-                       break;
-               default:
-                       return LB_STATUS_ERROR_INVALID; //DBOX_STATUS_ERROR_INVALID_PARAMETER;
+               common->pd.lock_fd = -1;
+
+               if (unlink(common->pd.lock) < 0) {
+                       ErrPrint("unlink: %s\n", strerror(errno));
                }
-               break;
-       case DBOX_ACCESS_VALUE_CHANGE:
-               _type = LB_ACCESS_VALUE_CHANGE;
-               break;
-       case DBOX_ACCESS_MOUSE:
-               // DOWN, MOVE, UP is not supported from old version, it's a BUG!
-               _type = LB_ACCESS_MOUSE;
-               break;
-       case DBOX_ACCESS_BACK:
-               _type = LB_ACCESS_BACK;
-               break;
-       case DBOX_ACCESS_OVER:
-               _type = LB_ACCESS_OVER;
-               break;
-       case DBOX_ACCESS_READ:
-               _type = LB_ACCESS_READ;
-               break;
-       case DBOX_ACCESS_ENABLE:
-               if (info->type == DBOX_ACCESS_TYPE_DISABLE) {
-                       _type = LB_ACCESS_DISABLE;
-               } else {
-                       _type = LB_ACCESS_ENABLE;
+
+               free(common->pd.lock);
+               common->pd.lock = NULL;
+       } else {
+               if (!common->lb.lock) {
+                       return LB_STATUS_ERROR_INVALID;
                }
-               break;
-       case DBOX_GBAR_ACCESS_HIGHLIGHT:
-               switch (info->type) {
-               case DBOX_ACCESS_TYPE_HIGHLIGHT:
-                       _type = PD_ACCESS_HIGHLIGHT;
-                       break;
-               case DBOX_ACCESS_TYPE_HIGHLIGHT_NEXT:
-                       _type = PD_ACCESS_HIGHLIGHT_NEXT;
-                       break;
-               case DBOX_ACCESS_TYPE_HIGHLIGHT_PREV:
-                       _type = PD_ACCESS_HIGHLIGHT_PREV;
-                       break;
-               case DBOX_ACCESS_TYPE_UNHIGHLIGHT:
-                       _type = PD_ACCESS_UNHIGHLIGHT;
-                       break;
-               default:
-                       return LB_STATUS_ERROR_INVALID; //DBOX_STATUS_ERROR_INVALID_PARAMETER;
+
+               if (close(common->lb.lock_fd) < 0) {
+                       ErrPrint("close: %s\n", strerror(errno));
                }
-               break;
-       case DBOX_GBAR_ACCESS_ACTIVATE:
-               _type = PD_ACCESS_ACTIVATE;
-               break;
-       case DBOX_GBAR_ACCESS_ACTION:
-               switch (info->type) {
-               case DBOX_ACCESS_TYPE_UP:
-                       _type = PD_ACCESS_ACTION_UP;
-                       break;
-               case DBOX_ACCESS_TYPE_DOWN:
-                       _type = PD_ACCESS_ACTION_DOWN;
-                       break;
-               default:
-                       return LB_STATUS_ERROR_INVALID; //DBOX_STATUS_ERROR_INVALID_PARAMETER;
+               common->lb.lock_fd = -1;
+
+               if (unlink(common->lb.lock) < 0) {
+                       ErrPrint("unlink: %s\n", strerror(errno));
                }
-               break;
-       case DBOX_GBAR_ACCESS_SCROLL:
-               switch (info->type) {
-               case DBOX_ACCESS_TYPE_UP:
-                       _type = PD_ACCESS_SCROLL_UP;
-                       break;
-               case DBOX_ACCESS_TYPE_MOVE:
-                       _type = PD_ACCESS_SCROLL_MOVE;
-                       break;
-               case DBOX_ACCESS_TYPE_DOWN:
-                       _type = PD_ACCESS_SCROLL_DOWN;
-                       break;
-               default:
-                       return LB_STATUS_ERROR_INVALID; //DBOX_STATUS_ERROR_INVALID_PARAMETER;
+
+               free(common->lb.lock);
+               common->lb.lock = NULL;
+       }
+
+       return LB_STATUS_SUCCESS;
+}
+
+int lb_create_lock_file(struct livebox_common *common, int is_pd)
+{
+       int len;
+       char *file;
+
+       len = strlen(common->id);
+       file = malloc(len + 20);
+       if (!file) {
+               ErrPrint("Heap: %s\n", strerror(errno));
+               return LB_STATUS_ERROR_MEMORY;
+       }
+
+       snprintf(file, len + 20, "%s.%s.lck", util_uri_to_path(common->id), is_pd ? "pd" : "lb");
+
+       if (is_pd) {
+               common->pd.lock_fd = open(file, O_RDONLY);
+               if (common->pd.lock_fd < 0) {
+                       ErrPrint("open: %s\n", strerror(errno));
+                       free(file);
+                       return LB_STATUS_ERROR_IO;
                }
-               break;
-       case DBOX_GBAR_ACCESS_VALUE_CHANGE:
-               _type = PD_ACCESS_VALUE_CHANGE;
-               break;
-       case DBOX_GBAR_ACCESS_MOUSE:
-               /* down, move, up is not supported, it's a BUG! */
-               _type = PD_ACCESS_MOUSE;
-               break;
-       case DBOX_GBAR_ACCESS_BACK:
-               _type = PD_ACCESS_BACK;
-               break;
-       case DBOX_GBAR_ACCESS_OVER:
-               _type = PD_ACCESS_OVER;
-               break;
-       case DBOX_GBAR_ACCESS_READ:
-               _type = PD_ACCESS_READ;
-               break;
-       case DBOX_GBAR_ACCESS_ENABLE:
-               break;
-       default:
-               if (info->type == DBOX_ACCESS_TYPE_DISABLE) {
-                       _type = LB_ACCESS_DISABLE;
-               } else {
-                       _type = LB_ACCESS_ENABLE;
+
+               common->pd.lock = file;
+       } else {
+               common->lb.lock_fd = open(file, O_RDONLY);
+               if (common->lb.lock_fd < 0) {
+                       ErrPrint("open: %s\n", strerror(errno));
+                       free(file);
+                       return LB_STATUS_ERROR_IO;
                }
-               break;
+
+               common->lb.lock = file;
        }
 
-       /*
-        * Need to send event_type to the provider.
-        */
-       return livebox_access_event((struct livebox*)handler, _type, info->x, info->y, (ret_cb_t)cb, data);
+       return LB_STATUS_SUCCESS;
 }
 
-EAPI int dynamicbox_feed_mouse_event(struct dynamicbox *handler, enum dynamicbox_mouse_event_type type, struct dynamicbox_mouse_event_info *info)
+static void update_mode_cb(struct livebox *handler, const struct packet *result, void *data)
 {
-       return livebox_mouse_event((struct livebox*)handler, (enum content_event_type)type, info->x, info->y);
+       int ret;
+
+       if (!result) {
+               ret = LB_STATUS_ERROR_FAULT;
+               goto errout;
+       } else if (packet_get(result, "i", &ret) != 1) {
+               ErrPrint("Invalid argument\n");
+               ret = LB_STATUS_ERROR_INVALID;
+               goto errout;
+       }
+
+       if (ret < 0) {
+               ErrPrint("Resize request is failed: %d\n", ret);
+               goto errout;
+       }
+
+       return;
+
+errout:
+       handler->cbs.update_mode.cb(handler, ret, handler->cbs.update_mode.data);
+       handler->cbs.update_mode.cb = NULL;
+       handler->cbs.update_mode.data = NULL;
+       handler->common->request.update_mode = 0;
+
+       if (ret == (int)LB_STATUS_ERROR_NOT_EXIST && handler->refcnt == 2) {
+               lb_invoke_event_handler(handler, LB_EVENT_DELETED);
+               lb_unref(handler, 1);
+       }
 }
 
-EAPI int dynamicbox_feed_key_event(struct dynamicbox *handler, enum dynamicbox_key_event_type type, struct dynamicbox_key_event_info *info, dynamicbox_ret_cb_t cb, void *data)
+static void resize_cb(struct livebox *handler, const struct packet *result, void *data)
 {
-       return livebox_key_event((struct livebox*) handler, (enum content_event_type)type, info->keycode, (ret_cb_t)cb, data);
+       int ret;
+
+       if (!result) {
+               ret = LB_STATUS_ERROR_FAULT;
+               goto errout;
+       } else if (packet_get(result, "i", &ret) != 1) {
+               ErrPrint("Invalid argument\n");
+               ret = LB_STATUS_ERROR_INVALID;
+               goto errout;
+       }
+
+       /*!
+        * \note
+        * In case of resize request,
+        * The livebox handler will not have resized value right after this callback,
+        * It can only get the new size when it makes updates.
+        *
+        * So the user can only get the resized value(result) from the first update event
+        * after this request.
+        */
+       if (ret < 0) {
+               ErrPrint("Resize request is failed: %d\n", ret);
+               goto errout;
+       }
+
+       return;
+
+errout:
+       handler->cbs.size_changed.cb(handler, ret, handler->cbs.size_changed.data);
+       handler->cbs.size_changed.cb = NULL;
+       handler->cbs.size_changed.data = NULL;
+       handler->common->request.size_changed = 0;
+
+       if (ret == (int)LB_STATUS_ERROR_NOT_EXIST && handler->refcnt == 2) {
+               lb_invoke_event_handler(handler, LB_EVENT_DELETED);
+               lb_unref(handler, 1);
+       }
 }
 
-EAPI const char *dynamicbox_filename(struct dynamicbox *handler)
+static void text_signal_cb(struct livebox *handler, const struct packet *result, void *data)
 {
-       return livebox_filename((struct livebox*)handler);
+       int ret;
+       void *cbdata;
+       struct cb_info *info = data;
+       ret_cb_t cb;
+
+       cbdata = info->data;
+       cb = info->cb;
+       destroy_cb_info(info);
+
+       if (!result) {
+               ret = LB_STATUS_ERROR_FAULT;
+       } else if (packet_get(result, "i", &ret) != 1) {
+               ErrPrint("Invalid argument\n");
+               ret = LB_STATUS_ERROR_INVALID;
+       }
+
+       if (cb) {
+               cb(handler, ret, cbdata);
+       }
+       return;
 }
 
-EAPI int dynamicbox_get_glance_bar_size(struct dynamicbox *handler, int *w, int *h)
+static void set_group_ret_cb(struct livebox *handler, const struct packet *result, void *data)
 {
-       return livebox_get_pdsize((struct livebox*) handler, w, h);
+       int ret;
+
+       if (!result) {
+               ret = LB_STATUS_ERROR_FAULT;
+               goto errout;
+       } else if (packet_get(result, "i", &ret) != 1) {
+               ErrPrint("Invalid argument\n");
+               ret = LB_STATUS_ERROR_INVALID;
+               goto errout;
+       }
+
+       if (ret < 0) {
+               goto errout;
+       }
+
+       return;
+
+errout:
+       handler->cbs.group_changed.cb(handler, ret, handler->cbs.group_changed.data);
+       handler->cbs.group_changed.cb = NULL;
+       handler->cbs.group_changed.data = NULL;
+       handler->common->request.group_changed = 0;
+
+       if (ret == (int)LB_STATUS_ERROR_NOT_EXIST && handler->refcnt == 2) {
+               lb_invoke_event_handler(handler, LB_EVENT_DELETED);
+               lb_unref(handler, 1);
+       }
 }
 
-EAPI int dynamicbox_size(struct dynamicbox *handler)
+static void period_ret_cb(struct livebox *handler, const struct packet *result, void *data)
 {
-       return livebox_size((struct livebox*) handler);
+       int ret;
+
+       if (!result) {
+               ret = LB_STATUS_ERROR_FAULT;
+               goto errout;
+       } else if (packet_get(result, "i", &ret) != 1) {
+               ErrPrint("Invalid argument\n");
+               ret = LB_STATUS_ERROR_INVALID;
+               goto errout;
+       }
+
+       if (ret < 0) {
+               goto errout;
+       }
+
+       return;
+
+errout:
+       handler->cbs.period_changed.cb(handler, ret, handler->cbs.period_changed.data);
+       handler->cbs.period_changed.cb = NULL;
+       handler->cbs.period_changed.data = NULL;
+       handler->common->request.period_changed = 0;
+
+       if (ret == (int)LB_STATUS_ERROR_NOT_EXIST && handler->refcnt == 2) {
+               lb_invoke_event_handler(handler, LB_EVENT_DELETED);
+               lb_unref(handler, 1);
+       }
 }
 
-EAPI int dynamicbox_set_group(struct dynamicbox *handler, const char *cluster, const char *category, dynamicbox_ret_cb_t cb, void *data)
+static void del_ret_cb(struct livebox *handler, const struct packet *result, void *data)
 {
-       return livebox_set_group((struct livebox*) handler, cluster, category, (ret_cb_t)cb, data);
+       struct cb_info *info = data;
+       int ret;
+       ret_cb_t cb;
+       void *cbdata;
+
+       cb = info->cb;
+       cbdata = info->data;
+       destroy_cb_info(info);
+
+       if (!result) {
+               ErrPrint("Connection lost?\n");
+               ret = LB_STATUS_ERROR_FAULT;
+       } else if (packet_get(result, "i", &ret) != 1) {
+               ErrPrint("Invalid argument\n");
+               ret = LB_STATUS_ERROR_INVALID;
+       }
+
+       if (ret == 0) {
+               handler->cbs.deleted.cb = cb;
+               handler->cbs.deleted.data = cbdata;
+       } else if (cb) {
+               cb(handler, ret, cbdata);
+       }
+
+       /*!
+        * \note
+        * Do not call the deleted callback from here.
+        * master will send the "deleted" event.
+        * Then invoke this callback.
+        *
+        * if (handler->cbs.deleted.cb)
+        *      handler->cbs.deleted.cb(handler, ret, handler->cbs.deleted.data);
+        */
 }
 
-EAPI int dynamicbox_get_group(struct dynamicbox *handler, const char **cluster, const char **category)
+static void new_ret_cb(struct livebox *handler, const struct packet *result, void *data)
 {
-       return livebox_get_group((struct livebox*) handler, cluster, category);
+       int ret;
+       struct cb_info *info = data;
+       ret_cb_t cb;
+       void *cbdata;
+
+       cb = info->cb;
+       cbdata = info->data;
+       destroy_cb_info(info);
+
+       if (!result) {
+               ret = LB_STATUS_ERROR_FAULT;
+       } else if (packet_get(result, "i", &ret) != 1) {
+               ret = LB_STATUS_ERROR_INVALID;
+       }
+
+       if (ret >= 0) {
+               handler->cbs.created.cb = cb;
+               handler->cbs.created.data = cbdata;
+
+               /*!
+                * \note
+                * Don't go anymore ;)
+                */
+               return;
+       } else if (cb) {
+               /*!
+                * \note
+                * It means the current instance is not created,
+                * so user has to know about this.
+                * notice it to user using "deleted" event.
+                */
+               cb(handler, ret, cbdata);
+       }
+
+       lb_unref(handler, 1);
 }
 
-EAPI int dynamicbox_get_supported_sizes(struct dynamicbox *handler, int *cnt, int *size_list)
+static void pd_create_cb(struct livebox *handler, const struct packet *result, void *data)
 {
-       return livebox_get_supported_sizes((struct livebox*) handler, cnt, size_list);
+       int ret;
+
+       if (!result) {
+               ret = LB_STATUS_ERROR_FAULT;
+               goto errout;
+       } else if (packet_get(result, "i", &ret) != 1) {
+               ret = LB_STATUS_ERROR_INVALID;
+               goto errout;
+       }
+
+       if (ret < 0) {
+               ErrPrint("Failed to create a PD[%d]\n", ret);
+               goto errout;
+       }
+
+       return;
+
+errout:
+       handler->cbs.pd_created.cb(handler, ret, handler->cbs.pd_created.data);
+       handler->cbs.pd_created.cb = NULL;
+       handler->cbs.pd_created.data = NULL;
+       handler->common->request.pd_created = 0;
+
+       if (ret == (int)LB_STATUS_ERROR_NOT_EXIST && handler->refcnt == 2) {
+               lb_invoke_event_handler(handler, LB_EVENT_DELETED);
+               lb_unref(handler, 1);
+       }
 }
 
-EAPI const char *dynamicbox_pkgname(struct dynamicbox *handler)
+static void activated_cb(struct livebox *handler, const struct packet *result, void *data)
 {
-       return livebox_pkgname((struct livebox*) handler);
+       int ret;
+       struct cb_info *info = data;
+       void *cbdata;
+       ret_cb_t cb;
+       const char *pkgname = "";
+
+       cbdata = info->data;
+       cb = info->cb;
+       destroy_cb_info(info);
+
+       if (!result) {
+               ret = LB_STATUS_ERROR_FAULT;
+       } else if (packet_get(result, "is", &ret, &pkgname) != 2) {
+               ret = LB_STATUS_ERROR_INVALID;
+       }
+
+       if (cb) {
+               cb(handler, ret, cbdata);
+       }
 }
 
-EAPI double dynamicbox_priority(struct dynamicbox *handler)
+static void pd_destroy_cb(struct livebox *handler, const struct packet *result, void *data)
 {
-       return livebox_priority((struct livebox*) handler);
+       int ret;
+       ret_cb_t cb;
+       void *cbdata;
+       struct cb_info *info = data;
+
+       cbdata = info->data;
+       cb = info->cb;
+       destroy_cb_info(info);
+
+       if (!result) {
+               ErrPrint("Result is NIL (may connection lost)\n");
+               ret = LB_STATUS_ERROR_FAULT;
+       } else if (packet_get(result, "i", &ret) != 1) {
+               ErrPrint("Invalid parameter\n");
+               ret = LB_STATUS_ERROR_INVALID;
+       }
+
+       if (ret == (int)LB_STATUS_SUCCESS) {
+               handler->cbs.pd_destroyed.cb = cb;
+               handler->cbs.pd_destroyed.data = cbdata;
+       } else {
+               handler->common->is_pd_created = 0;
+               handler->common->request.pd_destroyed = 0;
+
+               if (cb) {
+                       cb(handler, ret, cbdata);
+               }
+       }
 }
 
-#if 0 // those are unused functions
-EAPI int dynamicbox_delete_cluster(const char *cluster, dynamicbox_ret_cb_t cb, void *data)
+static void delete_cluster_cb(struct livebox *handler, const struct packet *result, void *data)
 {
-       return livebox_delete_cluster(cluster, (ret_cb_t)cb, data);
+       struct cb_info *info = data;
+       int ret;
+       ret_cb_t cb;
+       void *cbdata;
+
+       cb = info->cb;
+       cbdata = info->data;
+       destroy_cb_info(info);
+
+       if (!result) {
+               ret = LB_STATUS_ERROR_FAULT;
+       } else if (packet_get(result, "i", &ret) != 1) {
+               ret = LB_STATUS_ERROR_INVALID;
+       }
+
+       if (cb) {
+               cb(handler, ret, cbdata);
+       }
 }
 
-EAPI int dynamicbox_delete_category(const char *cluster, const char *category, dynamicbox_ret_cb_t cb, void *data)
+static void delete_category_cb(struct livebox *handler, const struct packet *result, void *data)
 {
-       return livebox_delete_category(cluster, category, (ret_cb_t)cb, data);
+       struct cb_info *info = data;
+       int ret;
+       ret_cb_t cb;
+       void *cbdata;
+
+       cb = info->cb;
+       cbdata = info->data;
+       destroy_cb_info(info);
+
+       if (!result) {
+               ret = LB_STATUS_ERROR_FAULT;
+       } else if (packet_get(result, "i", &ret) != 1) {
+               ret = LB_STATUS_ERROR_INVALID;
+       }
+
+       if (cb) {
+               cb(handler, ret, cbdata);
+       }
 }
-#endif
 
-EAPI enum dynamicbox_type dynamicbox_type(struct dynamicbox *handler, int gbar)
+static int lb_acquire_lb_pixmap(struct livebox *handler, ret_cb_t cb, void *data)
 {
-       enum dynamicbox_type type;
+       struct packet *packet;
+       struct cb_info *cbinfo;
+       const char *id;
+       int ret;
 
-       if (gbar) {
-               enum livebox_pd_type ptype;
-               ptype = livebox_pd_type((struct livebox *)handler);
-               switch (ptype) {
-               case PD_TYPE_BUFFER:
-                       type = DBOX_TYPE_BUFFER;
-                       break;
-               case PD_TYPE_TEXT:
-                       type = DBOX_TYPE_TEXT;
-                       break;
-               case PD_TYPE_PIXMAP:
-                       type = DBOX_TYPE_RESOURCE_ID;
-                       break;
-               case PD_TYPE_ELEMENTARY:
-                       type = DBOX_TYPE_UIFW;
-                       break;
-               case PD_TYPE_INVALID:
-               default:
-                       type = DBOX_TYPE_INVALID;
-                       break;
-               }
-       } else {
-               enum livebox_lb_type ltype;
-               ltype = livebox_lb_type((struct livebox *)handler);
-               type = (enum dynamicbox_type)ltype;
+       id = fb_id(handler->common->lb.fb);
+       if (!id || strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP))) {
+               return LB_STATUS_ERROR_INVALID;
        }
 
-       return type;
+       packet = packet_create("lb_acquire_pixmap", "ss", handler->common->pkgname, handler->common->id);
+       if (!packet) {
+               ErrPrint("Failed to build a param\n");
+               return LB_STATUS_ERROR_FAULT;
+       }
+
+       cbinfo = create_cb_info(cb, data);
+       if (!cbinfo) {
+               packet_destroy(packet);
+               return LB_STATUS_ERROR_FAULT;
+       }
+
+       ret = master_rpc_async_request(handler, packet, 0, lb_pixmap_acquired_cb, cbinfo);
+       if (ret < 0) {
+               destroy_cb_info(cbinfo);
+       }
+
+       return ret;
 }
 
-EAPI int dynamicbox_set_text_handler(struct dynamicbox *handler, int gbar, struct dynamicbox_script_operators *ops)
+static void lb_pixmap_acquired_cb(struct livebox *handler, const struct packet *result, void *data)
 {
-       if (gbar) {
-               return livebox_set_pd_text_handler((struct livebox*) handler, (struct livebox_script_operators*) ops);
+       int pixmap;
+       int ret = LB_STATUS_ERROR_INVALID;
+       ret_cb_t cb;
+       void *cbdata;
+       struct cb_info *info = data;
+
+       cb = info->cb;
+       cbdata = info->data;
+       destroy_cb_info(info);
+
+       if (!result) {
+               pixmap = 0; /* PIXMAP 0 means error */
+       } else if (packet_get(result, "ii", &pixmap, &ret) != 2) {
+               pixmap = 0;
+       }
+
+       if (ret == (int)LB_STATUS_ERROR_BUSY) {
+               ret = lb_acquire_lb_pixmap(handler, cb, cbdata);
+               DbgPrint("Busy, Try again: %d\n", ret);
+               /* Try again */
+       } else if (ret == (int)LB_STATUS_ERROR_NOT_EXIST && handler->refcnt == 2) {
+               if (cb) {
+                       cb(handler, pixmap, cbdata);
+               }
+
+               lb_invoke_event_handler(handler, LB_EVENT_DELETED);
+               lb_unref(handler, 1);
        } else {
-               return livebox_set_text_handler((struct livebox*) handler, (struct livebox_script_operators*) ops);
+               if (cb) {
+                       cb(handler, pixmap, cbdata);
+               }
        }
 }
 
-EAPI unsigned int dynamicbox_acquire_resource_id(struct dynamicbox *handler, int gbar, dynamicbox_ret_cb_t cb, void *data)
+static int lb_acquire_pd_pixmap(struct livebox *handler, ret_cb_t cb, void *data)
+{
+       struct packet *packet;
+       struct cb_info *cbinfo;
+       const char *id;
+       int ret;
+
+       id = fb_id(handler->common->pd.fb);
+       if (!id || strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP))) {
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       packet = packet_create("pd_acquire_pixmap", "ss", handler->common->pkgname, handler->common->id);
+       if (!packet) {
+               ErrPrint("Failed to build a param\n");
+               return LB_STATUS_ERROR_FAULT;
+       }
+
+       cbinfo = create_cb_info(cb, data);
+       if (!cbinfo) {
+               packet_destroy(packet);
+               return LB_STATUS_ERROR_FAULT;
+       }
+
+       ret = master_rpc_async_request(handler, packet, 0, pd_pixmap_acquired_cb, cbinfo);
+       if (ret < 0) {
+               /*!
+                * \note
+                * Packet will be destroyed by master_rpc_async_request
+                */
+               destroy_cb_info(cbinfo);
+       }
+
+       return ret;
+}
+
+static void pd_pixmap_acquired_cb(struct livebox *handler, const struct packet *result, void *data)
+{
+       int pixmap;
+       int ret;
+       ret_cb_t cb;
+       void *cbdata;
+       struct cb_info *info = data;
+
+       cb = info->cb;
+       cbdata = info->data;
+       destroy_cb_info(info);
+
+       if (!result) {
+               pixmap = 0; /* PIXMAP 0 means error */
+               ret = LB_STATUS_ERROR_FAULT;
+       } else if (packet_get(result, "ii", &pixmap, &ret) != 2) {
+               pixmap = 0;
+               ret = LB_STATUS_ERROR_INVALID;
+       }
+
+       if (ret == (int)LB_STATUS_ERROR_BUSY) {
+               ret = lb_acquire_pd_pixmap(handler, cb, cbdata);
+               DbgPrint("Busy, Try again: %d\n", ret);
+               /* Try again */
+       } else if (ret == (int)LB_STATUS_ERROR_NOT_EXIST && handler->refcnt == 2) {
+               if (cb) {
+                       cb(handler, pixmap, cbdata);
+               }
+               lb_invoke_event_handler(handler, LB_EVENT_DELETED);
+               lb_unref(handler, 1);
+       } else {
+               if (cb) {
+                       DbgPrint("ret: %d, pixmap: %d\n", ret, pixmap);
+                       cb(handler, pixmap, cbdata);
+               }
+       }
+}
+
+static void pinup_done_cb(struct livebox *handler, const struct packet *result, void *data)
+{
+       int ret;
+
+       if (!result) {
+               ret = LB_STATUS_ERROR_FAULT;
+               goto errout;
+       } else if (packet_get(result, "i", &ret) != 1) {
+               goto errout;
+       }
+
+       if (ret < 0) {
+               goto errout;
+       }
+
+       return;
+
+errout:
+       handler->cbs.pinup.cb(handler, ret, handler->cbs.pinup.data);
+       handler->cbs.pinup.cb = NULL;
+       handler->cbs.pinup.data = NULL;
+       handler->common->request.pinup = 0;
+
+       if (ret == (int)LB_STATUS_ERROR_NOT_EXIST && handler->refcnt == 2) {
+               lb_invoke_event_handler(handler, LB_EVENT_DELETED);
+               lb_unref(handler, 1);
+       }
+}
+
+static void key_ret_cb(struct livebox *handler, const struct packet *result, void *data)
+{
+       int ret;
+
+       if (!result) {
+               ret = LB_STATUS_ERROR_FAULT;
+               return;
+       }
+
+       if (packet_get(result, "i", &ret) != 1) {
+               ret = LB_STATUS_ERROR_INVALID;
+               return;
+       }
+
+       if (ret != LB_STATUS_SUCCESS) {
+               goto errout;
+       }
+
+       return;
+errout:
+       handler->cbs.key_event.cb(handler, ret, handler->cbs.key_event.data);
+       handler->cbs.key_event.cb = NULL;
+       handler->cbs.key_event.data = NULL;
+       handler->common->request.key_event = 0;
+
+       if (ret == (int)LB_STATUS_ERROR_NOT_EXIST && handler->refcnt == 2) {
+               lb_invoke_event_handler(handler, LB_EVENT_DELETED);
+               lb_unref(handler, 1);
+       }
+}
+
+static void access_ret_cb(struct livebox *handler, const struct packet *result, void *data)
+{
+       int ret;
+
+       if (!result) {
+               ret = LB_STATUS_ERROR_FAULT;
+               return;
+       }
+
+       if (packet_get(result, "i", &ret) != 1) {
+               ret = LB_STATUS_ERROR_INVALID;
+               return;
+       }
+
+       if (ret != LB_STATUS_SUCCESS) {
+               goto errout;
+       }
+
+       return;
+
+errout:
+       handler->cbs.access_event.cb(handler, ret, handler->cbs.access_event.data);
+       handler->cbs.access_event.cb = NULL;
+       handler->cbs.access_event.data = NULL;
+       handler->common->request.access_event = 0;
+
+       if (ret == (int)LB_STATUS_ERROR_NOT_EXIST && handler->refcnt == 2) {
+               lb_invoke_event_handler(handler, LB_EVENT_DELETED);
+               lb_unref(handler, 1);
+       }
+}
+
+static int send_access_event(struct livebox *handler, const char *event, int x, int y, int type)
+{
+       struct packet *packet;
+       double timestamp;
+
+       timestamp = util_timestamp();
+
+       packet = packet_create(event, "ssdiii", handler->common->pkgname, handler->common->id, timestamp, x, y, type);
+       if (!packet) {
+               ErrPrint("Failed to build packet\n");
+               return LB_STATUS_ERROR_FAULT;
+       }
+
+       return master_rpc_async_request(handler, packet, 0, access_ret_cb, NULL);
+}
+
+static int send_key_event(struct livebox *handler, const char *event, unsigned int keycode)
+{
+       struct packet *packet;
+       double timestamp;
+
+       timestamp = util_timestamp();
+       packet = packet_create(event, "ssdi", handler->common->pkgname, handler->common->id, timestamp, keycode);
+       if (!packet) {
+               ErrPrint("Failed to build packet\n");
+               return LB_STATUS_ERROR_FAULT;
+       }
+
+       return master_rpc_async_request(handler, packet, 0, key_ret_cb, NULL);
+}
+
+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, "ssdii", handler->common->pkgname, handler->common->id, timestamp, x, y);
+       if (!packet) {
+               ErrPrint("Failed to build param\n");
+               return LB_STATUS_ERROR_FAULT;
+       }
+
+       return master_rpc_request_only(handler, packet);
+}
+
+static int initialize_livebox(void *disp, int use_thread)
+{
+       int ret;
+#if defined(FLOG)
+       char filename[BUFSIZ];
+       snprintf(filename, sizeof(filename), "/tmp/%d.box.log", getpid());
+       __file_log_fp = fopen(filename, "w+t");
+       if (!__file_log_fp) {
+               __file_log_fp = fdopen(1, "w+t");
+       }
+#endif
+       ret = livebox_service_init();
+       if (ret != LB_STATUS_SUCCESS) {
+               return ret;
+       }
+
+       ret = fb_init(disp);
+       if (ret != LB_STATUS_SUCCESS) {
+               livebox_service_fini();
+               return ret;
+       }
+
+       ret = client_init(use_thread);
+       if (ret != LB_STATUS_SUCCESS) {
+               fb_fini();
+               livebox_service_fini();
+               return ret;
+       }
+
+       s_info.init_count++;
+       return ret;
+}
+
+static inline char *lb_pkgname(const char *pkgname)
+{
+       char *lb;
+
+       lb = livebox_service_pkgname(pkgname);
+       if (!lb) {
+               if (util_validate_livebox_package(pkgname) == 0) {
+                       return strdup(pkgname);
+               }
+       }
+
+       return lb;
+}
+
+static struct livebox_common *find_sharable_common_handle(const char *pkgname, const char *content, int w, int h, const char *cluster, const char *category)
+{
+       struct dlist *l;
+       struct livebox_common *common;
+
+       if (!conf_shared_content()) {
+               /*!
+                * Shared content option is turnned off.
+                */
+               return NULL;
+       }
+
+       dlist_foreach(s_info.livebox_common_list, l, common) {
+               if (common->state != CREATE) {
+                       continue;
+               }
+
+               if (strcmp(common->pkgname, pkgname)) {
+                       continue;
+               }
+
+               if (strcmp(common->cluster, cluster)) {
+                       DbgPrint("Cluster mismatched\n");
+                       continue;
+               }
+
+               if (strcmp(common->category, category)) {
+                       DbgPrint("Category mismatched\n");
+                       continue;
+               }
+
+               if (common->content && content) {
+                       if (strcmp(common->content, content)) {
+                               DbgPrint("%s Content ([%s] <> [%s])\n", common->pkgname, common->content, content);
+                               continue;       
+                       }
+               } else {
+                       int c1_len;
+                       int c2_len;
+
+                       /*!
+                        * \note
+                        * We assumes "" (ZERO length string) to NULL
+                        */
+                       c1_len = common->content ? strlen(common->content) : 0;
+                       c2_len = content ? strlen(content) : 0;
+                       if (c1_len != c2_len) {
+                               DbgPrint("%s Content %p <> %p\n", common->pkgname, common->content, content);
+                               continue;
+                       }
+               }
+
+               if (common->request.size_changed) {
+                       DbgPrint("Changing size\n");
+                       /*!
+                        * \note
+                        * Do not re-use resizing instance.
+                        * We will not use predicted size.
+                        */
+                       continue;
+               }
+
+               if (common->request.created) {
+                       DbgPrint("Creating now but re-use it (%s)\n", common->pkgname);
+               }
+
+               if (common->lb.width != w || common->lb.height != h) {
+                       DbgPrint("Size mismatched\n");
+                       continue;
+               }
+
+               DbgPrint("common handle is found: %p\n", common);
+               return common;
+       }
+
+       return NULL;
+}
+
+static gboolean job_execute_cb(void *data)
+{
+       struct job_item *item;
+       struct dlist *l;
+
+       l = dlist_nth(s_info.job_list, 0);
+       if (!l) {
+               s_info.job_timer = 0;
+               return FALSE;
+       }
+
+       item = dlist_data(l);
+       s_info.job_list = dlist_remove(s_info.job_list, l);
+
+       if (item) {
+               item->cb(item->handle, item->ret, item->data);
+               lb_unref(item->handle, 1);
+               free(item);
+       }
+
+       return TRUE;
+}
+
+static int job_add(struct livebox *handle, ret_cb_t job_cb, int ret, void *data)
+{
+       struct job_item *item;
+
+       if (!job_cb) {
+               ErrPrint("Invalid argument\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       item = malloc(sizeof(*item));
+       if (!item) {
+               ErrPrint("Heap: %s\n", strerror(errno));
+               return LB_STATUS_ERROR_MEMORY;
+       }
+
+       item->handle = lb_ref(handle);
+       item->cb = job_cb;
+       item->data = data;
+       item->ret = ret;
+
+       s_info.job_list = dlist_append(s_info.job_list, item);
+
+       if (!s_info.job_timer) {
+               s_info.job_timer = g_timeout_add(1, job_execute_cb, NULL);
+               if (!s_info.job_timer) {
+                       ErrPrint("Failed to create a job timer\n");
+               }
+       }
+
+       return LB_STATUS_SUCCESS;
+}
+
+static int create_real_instance(struct livebox *handler, ret_cb_t cb, void *data)
+{
+       struct cb_info *cbinfo;
+       struct packet *packet;
+       struct livebox_common *common;
+       int ret;
+
+       common = handler->common;
+
+       packet = packet_create("new", "dssssdii",
+                               common->timestamp, common->pkgname, common->content,
+                               common->cluster, common->category,
+                               common->lb.period, common->lb.width, common->lb.height);
+       if (!packet) {
+               ErrPrint("Failed to create a new packet\n");
+               return LB_STATUS_ERROR_FAULT;
+       }
+
+       cbinfo = create_cb_info(cb, data);
+       if (!cbinfo) {
+               ErrPrint("Failed to create a cbinfo\n");
+               packet_destroy(packet);
+               return LB_STATUS_ERROR_MEMORY;
+       }
+
+       /*!
+        * \note
+        * master_rpc_async_request will destroy the packet (decrease the refcnt)
+        * So be aware the packet object after return from master_rpc_async_request.
+        */
+       ret = master_rpc_async_request(handler, packet, 0, new_ret_cb, cbinfo);
+       if (ret < 0) {
+               ErrPrint("Failed to send a new packet\n");
+               destroy_cb_info(cbinfo);
+               return LB_STATUS_ERROR_FAULT;
+       }
+       handler->common->request.created = 1;
+       return LB_STATUS_SUCCESS;
+}
+
+static void create_cb(struct livebox *handle, int ret, void *data)
+{
+       struct cb_info *cbinfo = data;
+
+       if (cbinfo->cb) {
+               cbinfo->cb(handle, ret, cbinfo->data);
+       }
+
+       destroy_cb_info(cbinfo);
+
+       /*!
+        * \note
+        * Forcely generate "updated" event
+        */
+       lb_invoke_event_handler(handle, LB_EVENT_LB_UPDATED);
+}
+
+static int create_fake_instance(struct livebox *handler, ret_cb_t cb, void *data)
+{
+       struct cb_info *cbinfo;
+
+       cbinfo = create_cb_info(cb, data);
+       if (!cbinfo) {
+               ErrPrint("Failed to create a cbinfo\n");
+               return LB_STATUS_ERROR_MEMORY;
+       }
+
+       if (job_add(handler, create_cb, LB_STATUS_SUCCESS, cbinfo) != LB_STATUS_SUCCESS) {
+               destroy_cb_info(cbinfo);
+       }
+
+       return LB_STATUS_SUCCESS;
+}
+
+struct livebox_common *lb_create_common_handle(struct livebox *handle, const char *pkgname, const char *cluster, const char *category)
+{
+       struct livebox_common *common;
+
+       common = calloc(1, sizeof(*common));
+       if (!common) {
+               ErrPrint("Heap: %s\n", strerror(errno));
+               return NULL;
+       }
+
+       common->pkgname = strdup(pkgname);
+       if (!common->pkgname) {
+               free(common);
+               return NULL;
+       }
+
+       common->cluster = strdup(cluster);
+       if (!common->cluster) {
+               ErrPrint("Error: %s\n", strerror(errno));
+               free(common->pkgname);
+               free(common);
+               return NULL;
+       }
+
+       common->category = strdup(category);
+       if (!common->category) {
+               ErrPrint("Error: %s\n", strerror(errno));
+               free(common->cluster);
+               free(common->pkgname);
+               free(common);
+               return NULL;
+       }
+
+       /* Data provider will set this */
+       common->lb.type = _LB_TYPE_FILE;
+       common->pd.type = _PD_TYPE_SCRIPT;
+
+       /* Used for handling the mouse event on a box */
+       common->lb.mouse_event = 0;
+
+       /* Cluster infomration is not determined yet */
+       common->nr_of_sizes = 0x01;
+
+       common->timestamp = util_timestamp();
+       common->is_user = 1;
+       common->delete_type = LB_DELETE_PERMANENTLY;
+       common->pd.lock = NULL;
+       common->pd.lock_fd = -1;
+       common->lb.lock = NULL;
+       common->lb.lock_fd = -1;
+
+       common->state = CREATE;
+       common->visible = LB_SHOW;
+
+       s_info.livebox_common_list = dlist_append(s_info.livebox_common_list, common);
+       return common;
+}
+
+int lb_destroy_common_handle(struct livebox_common *common)
+{
+       dlist_remove_data(s_info.livebox_common_list, common);
+
+       common->state = DESTROYED;
+
+       if (common->filename) {
+               (void)util_unlink(common->filename);
+       }
+
+       free(common->cluster);
+       free(common->category);
+       free(common->id);
+       free(common->pkgname);
+       free(common->filename);
+       free(common->lb.auto_launch);
+       free(common->alt.icon);
+       free(common->alt.name);
+
+       if (common->lb.fb) {
+               fb_destroy(common->lb.fb);
+               common->lb.fb = NULL;
+       }
+
+       if (common->pd.fb) {
+               fb_destroy(common->pd.fb);
+               common->pd.fb = NULL;
+       }
+
+       return 0;
+}
+
+int lb_common_ref(struct livebox_common *common, struct livebox *handle)
+{
+       common->livebox_list = dlist_append(common->livebox_list, handle);
+       common->refcnt++;
+
+       return common->refcnt;
+}
+
+int lb_common_unref(struct livebox_common *common, struct livebox *handle)
+{
+       int refcnt;
+       dlist_remove_data(common->livebox_list, handle);
+       refcnt = --common->refcnt;
+
+       return refcnt;
+}
+
+static void refresh_for_paused_updating_cb(struct livebox *handle, int ret, void *data)
+{
+       if (handle->paused_updating == 0) {
+               DbgPrint("Paused updates are cleared\n");
+               return;
+       }
+
+       DbgPrint("Pending updates are found\n");
+       lb_invoke_event_handler(handle, LB_EVENT_LB_UPDATED);
+}
+
+static int lb_set_visibility(struct livebox *handler, enum livebox_visible_state state)
+{
+       struct packet *packet;
+       int need_to_add_job = 0;
+       int ret;
+
+       if (handler->common->visible != LB_SHOW && state == LB_SHOW) {
+               need_to_add_job = !!handler->paused_updating;
+       } else if (handler->common->visible == LB_SHOW && state != LB_SHOW) {
+               struct dlist *l;
+               struct livebox *item;
+
+               dlist_foreach(handler->common->livebox_list, l, item) {
+                       if (item->visible == LB_SHOW) {
+                               DbgPrint("%s visibility is not changed\n", handler->common->pkgname);
+                               return LB_STATUS_SUCCESS;
+                       }
+               }
+       } else if (handler->common->visible == LB_SHOW && state == LB_SHOW && handler->paused_updating) {
+               if (job_add(handler, refresh_for_paused_updating_cb, LB_STATUS_SUCCESS, NULL) < 0) {
+                       ErrPrint("Unable to add a new job for refreshing box\n");
+               }
+
+               return LB_STATUS_SUCCESS;
+       } else {
+               /*!
+                * \brief
+                * No need to send this to the master
+                */
+               return LB_STATUS_SUCCESS;
+       }
+
+       packet = packet_create_noack("change,visibility", "ssi", handler->common->pkgname, handler->common->id, (int)state);
+       if (!packet) {
+               ErrPrint("Failed to create a packet\n");
+               return LB_STATUS_ERROR_FAULT;
+       }
+
+       ret = master_rpc_request_only(handler, packet);
+       if (ret == (int)LB_STATUS_SUCCESS) {
+               DbgPrint("[%s] visibility is changed 0x[%x]\n", handler->common->pkgname, state);
+               handler->common->visible = state;
+
+               if (need_to_add_job) {
+                       if (job_add(handler, refresh_for_paused_updating_cb, LB_STATUS_SUCCESS, NULL) < 0) {
+                               ErrPrint("Unable to add a new job for refreshing box\n");
+                       }
+               }
+       }
+
+       return ret;
+}
+
+static void lb_update_visibility(struct livebox_common *old_common)
+{
+       struct dlist *l;
+       struct livebox *item;
+
+       item = NULL;
+       dlist_foreach(old_common->livebox_list, l, item) {
+               if (item->visible == LB_SHOW) {
+                       break;
+               }
+
+               item = NULL;
+       }
+
+       if (!item) {
+               l = dlist_nth(old_common->livebox_list, 0);
+               item = dlist_data(l);
+
+               if (item) {
+                       lb_set_visibility(item, LB_HIDE_WITH_PAUSE);
+               } else {
+                       ErrPrint("Unable to get the valid handle from common handler\n");
+               }
+       } else {
+               lb_set_visibility(item, LB_SHOW);
+       }
+}
+
+/*!
+ * \note
+ * The second parameter should be the "return value",
+ * But in this case, we will use it for "type of deleting instance".
+ */
+static void job_del_cb(struct livebox *handle, int type, void *data)
+{
+       struct cb_info *cbinfo = data;
+       ret_cb_t cb;
+
+       if (handle->visible == LB_SHOW) {
+               lb_update_visibility(handle->common);
+       }
+
+       cb = cbinfo->cb;
+       data = cbinfo->data;
+       destroy_cb_info(cbinfo);
+
+       if (handle->common->state != CREATE) {
+               DbgPrint("[%s] %d\n", handle->common->pkgname, handle->refcnt);
+               if (cb) {
+                       cb(handle, LB_STATUS_SUCCESS, data);
+               }
+
+               return;
+       }
+
+       if (handle->common->refcnt == 1) {
+               handle->common->delete_type = type;
+               handle->common->state = DELETE;
+
+               if (!handle->common->id) {
+                       /*!
+                        * \note
+                        * The id is not determined yet.
+                        * It means a user didn't receive created event yet.
+                        * Then just stop to delete procedure from here.
+                        * Because the "created" event handle will release this.
+                        * By the way, if the user adds any callback for getting return status of this,
+                        * call it at here.
+                        */
+                       if (cb) {
+                               cb(handle, LB_STATUS_SUCCESS, data);
+                       }
+               }
+
+               DbgPrint("Send delete request\n");
+               lb_send_delete(handle, type, cb, data);
+       } else {
+               if (cb) {
+                       cb(handle, LB_STATUS_SUCCESS, data);
+               }
+
+               DbgPrint("Before unref: %d\n", handle->common->refcnt);
+               lb_unref(handle, 1);
+       }
+}
+
+static void resize_job_cb(struct livebox *handler, int ret, void *data)
+{
+       struct cb_info *info = data;
+
+       if (info->cb) {
+               info->cb(handler, ret, info->data);
+       }
+
+       free(info);
+
+       /*!
+        * \note
+        * Forcely update the box
+        */
+       lb_invoke_event_handler(handler, LB_EVENT_LB_UPDATED);
+}
+
+static void turn_off_pd_destroyed_flag_cb(struct livebox *handler, int ret, void *data)
+{
+       if (handler->common->request.pd_destroyed) {
+               ret_cb_t cb;
+               void *data;
+
+               DbgPrint("pd_destroyed request is canceled\n");
+               handler->common->request.pd_destroyed = 0;
+               cb = handler->cbs.pd_destroyed.cb;
+               data = handler->cbs.pd_destroyed.data;
+               handler->cbs.pd_destroyed.cb = NULL;
+               handler->cbs.pd_destroyed.data = NULL;
+
+               if (cb) {
+                       cb(handler, ret, data);
+               }
+       }
+}
+
+static void turn_off_pd_created_flag_cb(struct livebox *handler, int ret, void *data)
+{
+       if (handler->common->request.pd_created) {
+               ret_cb_t cb;
+               void *data;
+
+               DbgPrint("pd_created request is canceled\n");
+               handler->common->request.pd_created = 0;
+               cb = handler->cbs.pd_created.cb;
+               data = handler->cbs.pd_created.data;
+               handler->cbs.pd_created.cb = NULL;
+               handler->cbs.pd_created.data = NULL;
+
+               if (cb) {
+                       cb(handler, ret, data);
+               }
+       }
+}
+
+int lb_set_group(struct livebox_common *common, const char *cluster, const char *category)
+{
+       void *pc = NULL;
+       void *ps = NULL;
+
+       if (cluster) {
+               pc = strdup(cluster);
+               if (!pc) {
+                       ErrPrint("Heap: %s (cluster: %s)\n", strerror(errno), cluster);
+                       return LB_STATUS_ERROR_MEMORY;
+               }
+       }
+
+       if (category) {
+               ps = strdup(category);
+               if (!ps) {
+                       ErrPrint("Heap: %s (category: %s)\n", strerror(errno), category);
+                       free(pc);
+                       return LB_STATUS_ERROR_MEMORY;
+               }
+       }
+
+       if (common->cluster) {
+               free(common->cluster);
+       }
+
+       if (common->category) {
+               free(common->category);
+       }
+
+       common->cluster = pc;
+       common->category = ps;
+
+       return LB_STATUS_SUCCESS;
+}
+
+void lb_set_size(struct livebox_common *common, int w, int h)
+{
+       int size_type;
+
+       common->lb.width = w;
+       common->lb.height = h;
+
+       size_type = livebox_service_size_type(w, h);
+       if (size_type != LB_SIZE_TYPE_UNKNOWN) {
+               common->lb.mouse_event = livebox_service_mouse_event(common->pkgname, size_type);
+       }
+}
+
+void lb_set_update_mode(struct livebox_common *common, int active_mode)
+{
+       common->is_active_update = active_mode;
+}
+
+void lb_set_pdsize(struct livebox_common *common, int w, int h)
+{
+       common->pd.width = w;
+       common->pd.height = h;
+}
+
+void lb_set_default_pdsize(struct livebox_common *common, int w, int h)
+{
+       common->pd.default_width = w;
+       common->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;
+       struct dlist *n;
+       struct fault_info *info;
+
+       s_info.fault_state = INFO_STATE_CALLBACK_IN_PROCESSING;
+
+       dlist_foreach_safe(s_info.fault_list, l, n, info) {
+               if (!info->is_deleted && info->handler(event, pkgname, file, func, info->user_data) == EXIT_FAILURE) {
+                       info->is_deleted = 1;
+               }
+
+               if (info->is_deleted) {
+                       s_info.fault_list = dlist_remove(s_info.fault_list, l);
+                       free(info);
+               }
+       }
+
+       s_info.fault_state &= ~INFO_STATE_CALLBACK_IN_PROCESSING;
+}
+
+void lb_invoke_event_handler(struct livebox *handler, enum livebox_event_type event)
+{
+       struct dlist *l;
+       struct dlist *n;
+       struct event_info *info;
+
+       if (event == LB_EVENT_LB_UPDATED && handler->common->refcnt > 1) {
+               if (handler->visible != LB_SHOW) {
+                       DbgPrint("Update requested(pending) - %s\n", handler->common->pkgname);
+                       handler->paused_updating++;
+                       return;
+               } else {
+                       handler->paused_updating = 0;
+               }
+       }
+
+       s_info.event_state = INFO_STATE_CALLBACK_IN_PROCESSING;
+
+       dlist_foreach_safe(s_info.event_list, l, n, info) {
+               if (!info->is_deleted && info->handler(handler, event, info->user_data) == EXIT_FAILURE) {
+                       DbgPrint("Event handler returns EXIT_FAILURE\n");
+                       info->is_deleted = 1;
+               }
+
+               if (info->is_deleted) {
+                       s_info.event_list = dlist_remove(s_info.event_list, l);
+                       free(info);
+               }
+       }
+
+       s_info.event_state &= ~INFO_STATE_CALLBACK_IN_PROCESSING;
+}
+
+struct livebox_common *lb_find_common_handle(const char *pkgname, const char *id)
+{
+       struct dlist *l;
+       struct livebox_common *common;
+
+       dlist_foreach(s_info.livebox_common_list, l, common) {
+               if (!common->id) {
+                       continue;
+               }
+
+               if (!strcmp(common->pkgname, pkgname) && !strcmp(common->id, id)) {
+                       return common;
+               }
+       }
+
+       return NULL;
+}
+
+struct livebox_common *lb_find_common_handle_by_timestamp(double timestamp)
+{
+       struct dlist *l;
+       struct livebox_common *common;
+
+       dlist_foreach(s_info.livebox_common_list, l, common) {
+               if (common->timestamp == timestamp) {
+                       return common;
+               }
+       }
+
+       return NULL;
+}
+
+struct livebox *lb_new_livebox(const char *pkgname, const char *id, double timestamp, const char *cluster, const char *category)
+{
+       struct livebox *handler;
+
+       handler = calloc(1, sizeof(*handler));
+       if (!handler) {
+               ErrPrint("Failed to create a new livebox\n");
+               return NULL;
+       }
+
+       handler->common = lb_create_common_handle(handler, pkgname, cluster, category);
+       if (!handler->common) {
+               ErrPrint("Heap: %s\n", strerror(errno));
+               free(handler);
+               return NULL;
+       }
+
+       lb_common_ref(handler->common, handler);
+       lb_set_id(handler->common, id);
+       handler->common->timestamp = timestamp;
+       handler->common->state = CREATE;
+       handler->visible = LB_SHOW;
+       s_info.livebox_list = dlist_append(s_info.livebox_list, handler);
+
+       return lb_ref(handler);
+}
+
+int lb_delete_all(void)
+{
+       struct dlist *l;
+       struct dlist *n;
+       struct livebox *handler;
+
+       dlist_foreach_safe(s_info.livebox_list, l, n, handler) {
+               lb_invoke_event_handler(handler, LB_EVENT_DELETED);
+               lb_unref(handler, 1);
+       }
+
+       return LB_STATUS_SUCCESS;
+}
+
+int lb_set_content(struct livebox_common *common, const char *content)
+{
+       char *pc = NULL;
+
+       if (content) {
+               pc = strdup(content);
+               if (!pc) {
+                       ErrPrint("heap: %s [%s]\n", strerror(errno), content);
+                       return LB_STATUS_ERROR_MEMORY;
+               }
+       }
+
+       free(common->content);
+       common->content = pc;
+       return LB_STATUS_SUCCESS;
+}
+
+int lb_set_title(struct livebox_common *common, const char *title)
+{
+       char *pt = NULL;
+
+       if (title) {
+               pt = strdup(title);
+               if (!pt) {
+                       ErrPrint("heap: %s [%s]\n", strerror(errno), title);
+                       return LB_STATUS_ERROR_MEMORY;
+               }
+       }
+
+       free(common->title);
+       common->title = pt;
+       return LB_STATUS_SUCCESS;
+}
+
+void lb_set_size_list(struct livebox_common *common, int size_list)
+{
+       common->lb.size_list = size_list;
+}
+
+void lb_set_auto_launch(struct livebox_common *common, const char *auto_launch)
+{
+       char *pa = NULL;
+
+       if (!auto_launch || !strlen(auto_launch)) {
+               return;
+       }
+
+       pa = strdup(auto_launch);
+       if (!pa) {
+               ErrPrint("heap: %s, [%s]\n", strerror(errno), auto_launch);
+               return;
+       }
+
+       free(common->lb.auto_launch);
+       common->lb.auto_launch = pa;
+}
+
+void lb_set_priority(struct livebox_common *common, double priority)
+{
+       common->lb.priority = priority;
+}
+
+void lb_set_id(struct livebox_common *common, const char *id)
+{
+       char *pi = NULL;
+
+       if (id) {
+               pi = strdup(id);
+               if (!pi) {
+                       ErrPrint("heap: %s [%s]\n", strerror(errno), pi);
+                       return;
+               }
+       }
+
+       free(common->id);
+       common->id = pi;
+}
+
+void lb_set_filename(struct livebox_common *common, const char *filename)
+{
+       if (common->filename) {
+               if (common->lb.type == _LB_TYPE_FILE || common->lb.type == _LB_TYPE_TEXT) {
+                       if (common->filename[0] && unlink(common->filename) < 0) {
+                               ErrPrint("unlink: %s (%s)\n", strerror(errno), common->filename);
+                       }
+               }
+
+               free(common->filename);
+       }
+
+       common->filename = strdup(filename);
+       if (!common->filename) {
+               ErrPrint("Heap: %s\n", strerror(errno));
+       }
+}
+
+void lb_set_alt_icon(struct livebox_common *common, const char *icon)
+{
+       char *_icon = NULL;
+
+       if (icon && strlen(icon)) {
+               _icon = strdup(icon);
+               if (!_icon) {
+                       ErrPrint("Heap: %s\n", strerror(errno));
+               }
+       }
+
+       free(common->alt.icon);
+       common->alt.icon = _icon;
+}
+
+void lb_set_alt_name(struct livebox_common *common, const char *name)
+{
+       char *_name = NULL;
+
+       if (name && strlen(name)) {
+               _name = strdup(name);
+               if (!_name) {
+                       ErrPrint("Heap: %s\n", strerror(errno));
+               }
+       }
+
+       free(common->alt.name);
+       common->alt.name = _name;
+}
+
+int lb_set_lb_fb(struct livebox_common *common, const char *filename)
+{
+       struct fb_info *fb;
+
+       if (!common) {
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       fb = common->lb.fb;
+       if (fb && !strcmp(fb_id(fb), filename)) { /*!< BUFFER is not changed, */
+               return LB_STATUS_SUCCESS;
+       }
+
+       common->lb.fb = NULL;
+
+       if (!filename || filename[0] == '\0') {
+               if (fb) {
+                       fb_destroy(fb);
+               }
+               return LB_STATUS_SUCCESS;
+       }
+
+       common->lb.fb = fb_create(filename, common->lb.width, common->lb.height);
+       if (!common->lb.fb) {
+               ErrPrint("Faield to create a FB\n");
+               if (fb) {
+                       fb_destroy(fb);
+               }
+               return LB_STATUS_ERROR_FAULT;
+       }
+
+       if (fb) {
+               fb_destroy(fb);
+       }
+
+       return LB_STATUS_SUCCESS;
+}
+
+int lb_set_pd_fb(struct livebox_common *common, const char *filename)
+{
+       struct fb_info *fb;
+
+       if (!common || common->state != CREATE) {
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       fb = common->pd.fb;
+       if (fb && !strcmp(fb_id(fb), filename)) {
+               /* BUFFER is not changed, just update the content */
+               return LB_STATUS_ERROR_EXIST;
+       }
+       common->pd.fb = NULL;
+
+       if (!filename || filename[0] == '\0') {
+               if (fb) {
+                       fb_destroy(fb);
+               }
+               return LB_STATUS_SUCCESS;
+       }
+
+       common->pd.fb = fb_create(filename, common->pd.width, common->pd.height);
+       if (!common->pd.fb) {
+               ErrPrint("Failed to create a FB\n");
+               if (fb) {
+                       fb_destroy(fb);
+               }
+               return LB_STATUS_ERROR_FAULT;
+       }
+
+       if (fb) {
+               fb_destroy(fb);
+       }
+       return LB_STATUS_SUCCESS;
+}
+
+struct fb_info *lb_get_lb_fb(struct livebox_common *common)
+{
+       return common->lb.fb;
+}
+
+struct fb_info *lb_get_pd_fb(struct livebox_common *common)
+{
+       return common->pd.fb;
+}
+
+void lb_set_user(struct livebox_common *common, int user)
+{
+       common->is_user = user;
+}
+
+void lb_set_pinup(struct livebox_common *common, int pinup_supported)
+{
+       common->lb.pinup_supported = pinup_supported;
+}
+
+void lb_set_text_lb(struct livebox_common *common)
+{
+       common->lb.type = _LB_TYPE_TEXT;
+}
+
+void lb_set_text_pd(struct livebox_common *common)
+{
+       common->pd.type = _PD_TYPE_TEXT;
+}
+
+int lb_text_lb(struct livebox_common *common)
+{
+       return common->lb.type == _LB_TYPE_TEXT;
+}
+
+int lb_text_pd(struct livebox_common *common)
+{
+       return common->pd.type == _PD_TYPE_TEXT;
+}
+
+void lb_set_period(struct livebox_common *common, double period)
+{
+       common->lb.period = period;
+}
+
+struct livebox *lb_ref(struct livebox *handler)
+{
+       if (!handler) {
+               return NULL;
+       }
+
+       handler->refcnt++;
+       return handler;
+}
+
+struct livebox *lb_unref(struct livebox *handler, int destroy_common)
+{
+       if (!handler) {
+               return NULL;
+       }
+
+       handler->refcnt--;
+       if (handler->refcnt > 0) {
+               return handler;
+       }
+
+       if (handler->cbs.created.cb) {
+               handler->cbs.created.cb(handler, LB_STATUS_ERROR_FAULT, handler->cbs.created.data);
+               handler->cbs.created.cb = NULL;
+               handler->cbs.created.data = NULL;
+       }
+
+       if (handler->cbs.deleted.cb) {
+               handler->cbs.deleted.cb(handler, LB_STATUS_ERROR_FAULT, handler->cbs.deleted.data);
+               handler->cbs.deleted.cb = NULL;
+               handler->cbs.deleted.data = NULL;
+       }
+
+       if (handler->cbs.pinup.cb) {
+               handler->cbs.pinup.cb(handler, LB_STATUS_ERROR_FAULT, handler->cbs.pinup.data);
+               handler->cbs.pinup.cb = NULL;
+               handler->cbs.pinup.data = NULL;
+       }
+
+       if (handler->cbs.group_changed.cb) {
+               handler->cbs.group_changed.cb(handler, LB_STATUS_ERROR_FAULT, handler->cbs.group_changed.data);
+               handler->cbs.group_changed.cb = NULL;
+               handler->cbs.group_changed.data = NULL;
+       }
+
+       if (handler->cbs.period_changed.cb) {
+               handler->cbs.period_changed.cb(handler, LB_STATUS_ERROR_FAULT, handler->cbs.period_changed.data);
+               handler->cbs.period_changed.cb = NULL;
+               handler->cbs.period_changed.data = NULL;
+       }
+
+       if (handler->cbs.size_changed.cb) {
+               handler->cbs.size_changed.cb(handler, LB_STATUS_ERROR_FAULT, handler->cbs.size_changed.data);
+               handler->cbs.size_changed.cb = NULL;
+               handler->cbs.size_changed.data = NULL;
+       }
+
+       if (handler->cbs.pd_created.cb) {
+               handler->cbs.pd_created.cb(handler, LB_STATUS_ERROR_FAULT, handler->cbs.pd_created.data);
+               handler->cbs.pd_created.cb = NULL;
+               handler->cbs.pd_created.data = NULL;
+       }
+
+       if (handler->cbs.pd_destroyed.cb) {
+               handler->cbs.pd_destroyed.cb(handler, LB_STATUS_ERROR_FAULT, handler->cbs.pd_destroyed.data);
+               handler->cbs.pd_destroyed.cb = NULL;
+               handler->cbs.pd_destroyed.data = NULL;
+       }
+
+       if (handler->cbs.update_mode.cb) {
+               handler->cbs.update_mode.cb(handler, LB_STATUS_ERROR_FAULT, handler->cbs.update_mode.data);
+               handler->cbs.update_mode.cb = NULL;
+               handler->cbs.update_mode.data = NULL;
+       }
+
+       if (handler->cbs.access_event.cb) {
+               handler->cbs.access_event.cb(handler, LB_ACCESS_STATUS_ERROR, handler->cbs.access_event.data);
+               handler->cbs.access_event.cb = NULL;
+               handler->cbs.access_event.data = NULL;
+       }
+
+       if (handler->cbs.key_event.cb) {
+               handler->cbs.key_event.cb(handler, LB_KEY_STATUS_ERROR, handler->cbs.key_event.data);
+               handler->cbs.key_event.cb = NULL;
+               handler->cbs.key_event.data = NULL;
+       }
+
+       dlist_remove_data(s_info.livebox_list, handler);
+
+       handler->state = DESTROYED;
+       if (lb_common_unref(handler->common, handler) == 0) {
+               if (destroy_common) {
+                       /*!
+                        * \note
+                        * Lock file should be deleted after all callbacks are processed.
+                        */
+                       lb_destroy_lock_file(handler->common, 0);
+                       lb_destroy_common_handle(handler->common);
+               }
+       }
+       free(handler);
+       DbgPrint("Handler is released\n");
+       return NULL;
+}
+
+int lb_send_delete(struct livebox *handler, int type, ret_cb_t cb, void *data)
+{
+       struct packet *packet;
+       struct cb_info *cbinfo;
+       int ret;
+
+       if (handler->common->request.deleted) {
+               ErrPrint("Already in-progress\n");
+               if (cb) {
+                       cb(handler, LB_STATUS_SUCCESS, data);
+               }
+               return LB_STATUS_ERROR_BUSY;
+       }
+
+       if (!cb) {
+               cb = default_delete_cb;
+       }
+
+       packet = packet_create("delete", "ssid", handler->common->pkgname, handler->common->id, type, handler->common->timestamp);
+       if (!packet) {
+               ErrPrint("Failed to build a param\n");
+               if (cb) {
+                       cb(handler, LB_STATUS_ERROR_FAULT, data);
+               }
+
+               return LB_STATUS_ERROR_FAULT;
+       }
+
+       cbinfo = create_cb_info(cb, data);
+       if (!cbinfo) {
+               packet_destroy(packet);
+               ErrPrint("Failed to create cbinfo\n");
+               if (cb) {
+                       cb(handler, LB_STATUS_ERROR_FAULT, data);
+               }
+
+               return LB_STATUS_ERROR_FAULT;
+       }
+
+       ret = master_rpc_async_request(handler, packet, 0, del_ret_cb, cbinfo);
+       if (ret < 0) {
+               /*!
+                * Packet is destroyed by master_rpc_async_request.
+                */
+               destroy_cb_info(cbinfo);
+
+               if (cb) {
+                       cb(handler, LB_STATUS_ERROR_FAULT, data);
+               }
+       } else {
+               handler->common->request.deleted = 1;
+       }
+
+       return ret;
+}
+
+int lb_sync_lb_fb(struct livebox_common *common)
+{
+       int ret;
+
+       if (fb_type(lb_get_lb_fb(common)) == BUFFER_TYPE_FILE && common->lb.lock_fd >= 0) {
+               (void)do_fb_lock(common->lb.lock_fd);
+               ret = fb_sync(lb_get_lb_fb(common));
+               (void)do_fb_unlock(common->lb.lock_fd);
+       } else {
+               ret = fb_sync(lb_get_lb_fb(common));
+       }
+
+       return ret;
+}
+
+int lb_sync_pd_fb(struct livebox_common *common)
+{
+       int ret;
+
+       if (fb_type(lb_get_pd_fb(common)) == BUFFER_TYPE_FILE && common->pd.lock_fd >= 0) {
+               (void)do_fb_lock(common->pd.lock_fd);
+               ret = fb_sync(lb_get_pd_fb(common));
+               (void)do_fb_unlock(common->pd.lock_fd);
+       } else {
+               ret = fb_sync(lb_get_pd_fb(common));
+       }
+
+       return ret;
+}
+
+EAPI int dynamicbox_init(void *disp, int prevent_overwrite, double event_filter, int use_thread)
+{
+       if (s_info.init_count > 0) {
+               s_info.init_count++;
+               return LB_STATUS_SUCCESS;
+       }
+
+       /*!
+        * \note
+        * Some application doesn't want to use the environment value.
+        * So set them using arguments.
+        */
+       s_info.prevent_overwrite = prevent_overwrite;
+       conf_set_event_filter(event_filter);
+
+       return initialize_livebox(disp, use_thread);
+}
+
+EAPI int dynamicbox_fini(void)
+{
+       if (s_info.init_count <= 0) {
+               ErrPrint("Doesn't initialized\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       s_info.init_count--;
+       if (s_info.init_count > 0) {
+               ErrPrint("init count : %d\n", s_info.init_count);
+               return LB_STATUS_SUCCESS;
+       }
+
+       client_fini();
+       fb_fini();
+       livebox_service_fini();
+       return LB_STATUS_SUCCESS;
+}
+
+EAPI struct dynamicbox *dynamicbox_add(const char *pkgname, const char *content, const char *cluster, const char *category, double period, int type, dynamicbox_ret_cb_t cb, void *data)
+{
+       char *lbid;
+       struct livebox *handler;
+       int w = 0;
+       int h = 0;
+
+       if (!pkgname || !cluster || !category) {
+               ErrPrint("Invalid arguments: pkgname[%p], cluster[%p], category[%p]\n",
+                                                               pkgname, cluster, category);
+               return NULL;
+       }
+
+       lbid = lb_pkgname(pkgname);
+       if (!lbid) {
+               ErrPrint("Invalid package: %s\n", pkgname);
+               return NULL;
+       }
+
+       if (livebox_service_is_enabled(lbid) == 0) {
+               DbgPrint("Livebox [%s](%s) is disabled package\n", lbid, pkgname);
+               free(lbid);
+               return NULL;
+       }
+
+       if (type != LB_SIZE_TYPE_UNKNOWN) {
+               (void)livebox_service_get_size(type, &w, &h);
+       }
+
+       handler = calloc(1, sizeof(*handler));
+       if (!handler) {
+               ErrPrint("Error: %s\n", strerror(errno));
+               free(lbid);
+               return NULL;
+       }
+
+       if (!cb) {
+               cb = default_create_cb;
+       }
+
+       handler->common = find_sharable_common_handle(lbid, content, w, h, cluster, category);
+       if (!handler->common) {
+               handler->common = lb_create_common_handle(handler, lbid, cluster, category);
+               free(lbid);
+               if (!handler->common) {
+                       ErrPrint("Failed to find common handle\n");
+                       free(handler);
+                       return NULL;
+               }
+
+               if (!content || !strlen(content)) {
+                       char *pc;
+                       /*!
+                        * \note
+                        * I know the content should not be modified. use it temporarly without "const"
+                        */
+                       pc = livebox_service_content(handler->common->pkgname);
+                       lb_set_content(handler->common, pc);
+                       free(pc);
+               } else {
+                       lb_set_content(handler->common, content);
+               }
+
+               lb_set_period(handler->common, period);
+               lb_set_size(handler->common, w, h);
+               lb_common_ref(handler->common, handler);
+
+               if (create_real_instance(handler, cb, data) < 0) {
+                       if (lb_common_unref(handler->common, handler) == 0) {
+                               /*!
+                                * Delete common
+                                */
+                               lb_destroy_common_handle(handler->common);
+                               handler->common = NULL;
+                       }
+                       free(handler);
+                       return NULL;
+               }
+       } else {
+               free(lbid);
+
+               lb_common_ref(handler->common, handler);
+
+               if (handler->common->request.created) {
+                       /*!
+                        * If a box is in creating, wait its result too
+                        */
+                       handler->cbs.created.cb = cb;
+                       handler->cbs.created.data = data;
+               } else {
+                       /*!
+                        * or fire the fake created_event
+                        */
+                       if (create_fake_instance(handler, cb, data) < 0) {
+                               if (lb_common_unref(handler->common, handler) == 0) {
+                                       /*!
+                                        * Delete common
+                                        */
+                                       lb_destroy_common_handle(handler->common);
+                               }
+                               free(handler);
+                               return NULL;
+                       }
+               }
+       }
+
+       handler->visible = LB_SHOW;
+       handler->state = CREATE;
+       handler = lb_ref(handler);
+
+       if (handler->common->visible != LB_SHOW) {
+               lb_set_visibility(handler, LB_SHOW);
+       }
+
+       return handler;
+}
+
+EAPI double dynamicbox_period(struct dynamicbox *handler)
+{
+       if (!handler || handler->state != CREATE) {
+               ErrPrint("Handler is not valid\n");
+               return 0.0f;
+       }
+
+       if (!handler->common || handler->common->state != CREATE) {
+               ErrPrint("Invalid handle\n");
+               return 0.0f;
+       }
+
+       if (!handler->common->id) {
+               ErrPrint("Hnalder is not valid\n");
+               return 0.0f;
+       }
+
+       return handler->common->lb.period;
+}
+
+EAPI int dynamicbox_set_period(struct dynamicbox *handler, double period, dynamicbox_ret_cb_t cb, void *data)
+{
+       struct packet *packet;
+       int ret;
+
+       if (!handler || handler->state != CREATE) {
+               ErrPrint("Handler is not valid\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (!handler->common || handler->common->state != CREATE) {
+               ErrPrint("Invalid handle\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (!handler->common->id) {
+               ErrPrint("Handler is not valid\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (handler->common->request.period_changed) {
+               ErrPrint("Previous request for changing period is not finished\n");
+               return LB_STATUS_ERROR_BUSY;
+       }
+
+       if (!handler->common->is_user) {
+               ErrPrint("CA Livebox is not able to change the period\n");
+               return LB_STATUS_ERROR_PERMISSION;
+       }
+
+       if (handler->common->lb.period == period) {
+               DbgPrint("No changes\n");
+               return LB_STATUS_ERROR_ALREADY;
+       }
+
+       packet = packet_create("set_period", "ssd", handler->common->pkgname, handler->common->id, period);
+       if (!packet) {
+               ErrPrint("Failed to build a packet %s\n", handler->common->pkgname);
+               return LB_STATUS_ERROR_FAULT;
+       }
+
+       if (!cb) {
+               cb = default_period_changed_cb;
+       }
+
+       ret = master_rpc_async_request(handler, packet, 0, period_ret_cb, NULL);
+       if (ret == (int)LB_STATUS_SUCCESS) {
+               handler->cbs.period_changed.cb = cb;
+               handler->cbs.period_changed.data = data;
+               handler->common->request.period_changed = 1;
+       }
+
+       return ret;
+}
+
+EAPI int dynamicbox_del(struct dynamicbox *handler, int type, dynamicbox_ret_cb_t cb, void *data)
+{
+       struct cb_info *cbinfo;
+
+       if (!handler) {
+               ErrPrint("Handler is NIL\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (handler->state != CREATE) {
+               ErrPrint("Handler is already deleted\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       handler->state = DELETE;
+
+       cbinfo = create_cb_info(cb, data);
+       if (!cbinfo) {
+               ErrPrint("Failed to create a cbinfo\n");
+               return LB_STATUS_ERROR_MEMORY;
+       }
+
+       if (job_add(handler, job_del_cb, type, cbinfo) != LB_STATUS_SUCCESS) {
+               ErrPrint("Failed to add a new job\n");
+               destroy_cb_info(cbinfo);
+               return LB_STATUS_ERROR_FAULT;
+       }
+
+       return LB_STATUS_SUCCESS;
+}
+
+EAPI int dynamicbox_set_fault_handler(int (*dbox_cb)(enum dynamicbox_fault_type, const char *, const char *, const char *, void *), void *data)
+{
+       struct fault_info *info;
+
+       if (!cb) {
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       info = malloc(sizeof(*info));
+       if (!info) {
+               ErrPrint("Heap: %s\n", strerror(errno));
+               return LB_STATUS_ERROR_MEMORY;
+       }
+
+       info->handler = cb;
+       info->user_data = data;
+       info->is_deleted = 0;
+
+       s_info.fault_list = dlist_append(s_info.fault_list, info);
+       return LB_STATUS_SUCCESS;
+}
+
+EAPI void *dynamicbox_unset_fault_handler(int (*dbox_cb)(enum dynamicbox_fault_type, const char *, const char *, const char *, void *))
+{
+       struct fault_info *info;
+       struct dlist *l;
+
+       dlist_foreach(s_info.fault_list, l, info) {
+               if (info->handler == cb) {
+                       void *data;
+
+                       data = info->user_data;
+
+                       if (s_info.fault_state == INFO_STATE_CALLBACK_IN_PROCESSING) {
+                               info->is_deleted = 1;
+                       } else {
+                               s_info.fault_list = dlist_remove(s_info.fault_list, l);
+                               free(info);
+                       }
+
+                       return data;
+               }
+       }
+
+       return NULL;
+}
+
+EAPI int dynamicbox_set_event_handler(int (*dbox_cb)(struct dynamicbox *, enum dynamicbox_event_type, void *), void *data)
+{
+       struct event_info *info;
+
+       if (!cb) {
+               ErrPrint("Invalid argument cb is nil\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       info = malloc(sizeof(*info));
+       if (!info) {
+               ErrPrint("Heap: %s\n", strerror(errno));
+               return LB_STATUS_ERROR_MEMORY;
+       }
+
+       info->handler = cb;
+       info->user_data = data;
+       info->is_deleted = 0;
+
+       s_info.event_list = dlist_append(s_info.event_list, info);
+       return LB_STATUS_SUCCESS;
+}
+
+EAPI void *dynamicbox_unset_event_handler(int (*dbox_cb)(struct dynamicbox *, enum dynamicbox_event_type, void *))
+{
+       struct event_info *info;
+       struct dlist *l;
+
+       dlist_foreach(s_info.event_list, l, info) {
+               if (info->handler == cb) {
+                       void *data;
+
+                       data = info->user_data;
+
+                       if (s_info.event_state == INFO_STATE_CALLBACK_IN_PROCESSING) {
+                               info->is_deleted = 1;
+                       } else {
+                               s_info.event_list = dlist_remove(s_info.event_list, l);
+                               free(info);
+                       }
+
+                       return data;
+               }
+       }
+
+       return NULL;
+}
+
+EAPI int dynamicbox_set_update_mode(struct dynamicbox *handler, int active_update, dynamicbox_ret_cb_t cb, void *data)
+{
+       struct packet *packet;
+       int ret;
+
+       if (!handler || handler->state != CREATE) {
+               ErrPrint("Handler is Invalid\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (!handler->common || handler->common->state != CREATE) {
+               ErrPrint("Handler is Invalid\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (!handler->common->id) {
+               ErrPrint("Handler is Invalid\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (handler->common->request.update_mode) {
+               ErrPrint("Previous update_mode cb is not finished yet\n");
+               return LB_STATUS_ERROR_BUSY;
+       }
+
+       if (handler->common->is_active_update == active_update) {
+               return LB_STATUS_ERROR_ALREADY;
+       }
+
+       if (!handler->common->is_user) {
+               return LB_STATUS_ERROR_PERMISSION;
+       }
+
+       packet = packet_create("update_mode", "ssi", handler->common->pkgname, handler->common->id, active_update);
+       if (!packet) {
+               return LB_STATUS_ERROR_FAULT;
+       }
+
+       if (!cb) {
+               cb = default_update_mode_cb;
+       }
+
+       ret = master_rpc_async_request(handler, packet, 0, update_mode_cb, NULL);
+       if (ret == (int)LB_STATUS_SUCCESS) {
+               handler->cbs.update_mode.cb = cb;
+               handler->cbs.update_mode.data = data;
+               handler->common->request.update_mode = 1;
+       }
+
+       return ret;
+}
+
+EAPI int dynamicbox_is_active_update(struct dynamicbox *handler)
+{
+       if (!handler || handler->state != CREATE) {
+               ErrPrint("Handler is Invalid\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (!handler->common || handler->common->state != CREATE) {
+               ErrPrint("Handler is Invalid\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (!handler->common->id) {
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       return handler->common->is_active_update;
+}
+
+EAPI int dynamicbox_resize(struct dynamicbox *handler, int type, dynamicbox_ret_cb_t cb, void *data)
+{
+       struct livebox_common *common;
+       int w;
+       int h;
+       int ret;
+
+       /*!
+        * \TODO
+        * If this handle is host instance or link instance,
+        * Create a new instance or find another linkable instance.
+        */
+
+       if (!handler || handler->state != CREATE) {
+               ErrPrint("Handler is not valid\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (!handler->common || handler->common->state != CREATE) {
+               ErrPrint("Invalid handle\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (!handler->common->id) {
+               ErrPrint("Handler is not valid\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       /*!
+        * \note
+        * resize operation should be separated by each handler.
+        * If a handler is resizing, the other handler can request resize too.
+        * So we should not use the common->request.size_changed flag.
+        */
+       if (handler->cbs.size_changed.cb) {
+               ErrPrint("Previous resize request is not finished yet\n");
+               return LB_STATUS_ERROR_BUSY;
+       }
+
+       if (livebox_service_get_size(type, &w, &h) != 0) {
+               ErrPrint("Invalid size type\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (handler->common->lb.width == w && handler->common->lb.height == h) {
+               DbgPrint("No changes\n");
+               return LB_STATUS_ERROR_ALREADY;
+       }
+
+       if (!handler->common->is_user) {
+               ErrPrint("CA Livebox is not able to be resized\n");
+               return LB_STATUS_ERROR_PERMISSION;
+       }
+
+       if (handler->common->refcnt <= 1) {
+               struct packet *packet;
+
+               /* Only 1 instance */
+               packet = packet_create("resize", "ssii", handler->common->pkgname, handler->common->id, w, h);
+               if (!packet) {
+                       ErrPrint("Failed to build param\n");
+                       return LB_STATUS_ERROR_FAULT;
+               }
+
+               if (!cb) {
+                       cb = default_lb_size_changed_cb;
+               }
+
+               ret = master_rpc_async_request(handler, packet, 0, resize_cb, NULL);
+               if (ret == (int)LB_STATUS_SUCCESS) {
+                       handler->cbs.size_changed.cb = cb;
+                       handler->cbs.size_changed.data = data;
+                       handler->common->request.size_changed = 1;
+               }
+       } else {
+               common = find_sharable_common_handle(handler->common->pkgname, handler->common->content, w, h, handler->common->cluster, handler->common->category);
+               if (!common) {
+                       struct livebox_common *old_common;
+                       /*!
+                        * \note
+                        * If the common handler is in resizing,
+                        * if user tries to resize a hander, then simply create new one even if the requested size is same with this.
+
+                       if (handler->common->request.size_changed) {
+                       }
+
+                        */
+
+                       old_common = handler->common;
+
+                       common = lb_create_common_handle(handler, old_common->pkgname, old_common->cluster, old_common->category);
+                       if (!common) {
+                               ErrPrint("Failed to create common handle\n");
+                               return LB_STATUS_ERROR_FAULT;
+                       }
+
+                       lb_set_size(common, w, h);
+                       lb_set_content(common, old_common->content);
+                       lb_set_period(common, old_common->lb.period);
+
+                       /*!
+                        * \note
+                        * Disconnecting from old one.
+                        */
+                       if (lb_common_unref(old_common, handler) == 0) {
+                               /*!
+                                * \note
+                                * Impossible
+                                */
+                               ErrPrint("Common has no associated handler\n");
+                       }
+
+                       lb_common_ref(common, handler);
+
+                       /*!
+                        * Connect to a new one
+                        */
+                       handler->common = common;
+
+                       /*!
+                        * \TODO
+                        * Need to care, if it fails to create a common handle,
+                        * the resize operation will be failed.
+                        * in that case, we should reuse the old common handle
+                        */
+                       ret = create_real_instance(handler, cb, data);
+                       if (ret < 0) {
+                               lb_common_unref(common, handler);
+                               lb_destroy_common_handle(common);
+
+                               lb_common_ref(old_common, handler);
+                               handler->common = old_common;
+                       } else {
+                               /*!
+                                * In this case, we should update visibility of old_common's liveboxes
+                                */
+                               if (handler->visible == LB_SHOW) {
+                                       lb_update_visibility(old_common);
+                               }
+                       }
+               } else {
+                       struct cb_info *cbinfo;
+
+                       cbinfo = create_cb_info(cb, data);
+                       if (!cbinfo) {
+                               ErrPrint("Failed to create a cbinfo\n");
+                               ret = LB_STATUS_ERROR_MEMORY;
+                       } else {
+                               ret = job_add(handler, resize_job_cb, LB_STATUS_SUCCESS, cbinfo);
+                               if (ret == (int)LB_STATUS_SUCCESS) {
+                                       struct livebox_common *old_common;
+
+                                       old_common = handler->common;
+
+                                       if (lb_common_unref(handler->common, handler) == 0) {
+                                               ErrPrint("Old common has no associated handler\n");
+                                       }
+
+                                       lb_common_ref(common, handler);
+                                       handler->common = common;
+
+                                       if (handler->visible == LB_SHOW) {
+                                               lb_update_visibility(old_common); /* To update visibility: Show --> Paused */
+                                               lb_update_visibility(common);   /* To update visibility: Paused --> Show */
+                                       }
+                               } else {
+                                       destroy_cb_info(cbinfo);
+                               }
+                       }
+               }
+       }
+
+       return ret;
+}
+
+EAPI int dynamicbox_click(struct dynamicbox *handler, double x, double y)
+{
+       struct packet *packet;
+       double timestamp;
+       int ret;
+
+       if (!handler || handler->state != CREATE) {
+               ErrPrint("Handler is invalid\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (!handler->common || handler->common->state != CREATE) {
+               ErrPrint("Handler is invalid\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (!handler->common->id) {
+               ErrPrint("Handler is not valid\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (handler->common->lb.auto_launch) {
+               if (s_info.launch.handler) {
+                       ret = s_info.launch.handler(handler, handler->common->lb.auto_launch, s_info.launch.data);
+                       if (ret < 0) {
+                               ErrPrint("launch handler app %s (%d)\n", handler->common->lb.auto_launch, ret);
+                       }
+               }
+       }
+
+       timestamp = util_timestamp();
+       DbgPrint("CLICKED: %lf\n", timestamp);
+
+       packet = packet_create_noack("clicked", "sssddd", handler->common->pkgname, handler->common->id, "clicked", timestamp, x, y);
+       if (!packet) {
+               ErrPrint("Failed to build param\n");
+               return LB_STATUS_ERROR_FAULT;
+       }
+
+       ret = master_rpc_request_only(handler, packet);
+
+       if (!handler->common->lb.mouse_event && (handler->common->lb.type == _LB_TYPE_BUFFER || handler->common->lb.type == _LB_TYPE_SCRIPT)) {
+               int ret; /* Shadow variable */
+               ret = send_mouse_event(handler, "lb_mouse_down", x * handler->common->lb.width, y * handler->common->lb.height);
+               if (ret < 0) {
+                       ErrPrint("Failed to send Down: %d\n", ret);
+               }
+
+               ret = send_mouse_event(handler, "lb_mouse_move", x * handler->common->lb.width, y * handler->common->lb.height);
+               if (ret < 0) {
+                       ErrPrint("Failed to send Move: %d\n", ret);
+               }
+
+               ret = send_mouse_event(handler, "lb_mouse_up", x * handler->common->lb.width, y * handler->common->lb.height);
+               if (ret < 0) {
+                       ErrPrint("Failed to send Up: %d\n", ret);
+               }
+       }
+
+       return ret;
+}
+
+EAPI int dynamicbox_has_pd(struct dynamicbox *handler)
+{
+       if (!handler || handler->state != CREATE) {
+               ErrPrint("Handler is invalid\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (!handler->common || handler->common->state != CREATE) {
+               ErrPrint("Handler is invalid\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (!handler->common->id) {
+               ErrPrint("Handler is not valid\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       return !!handler->common->pd.fb;
+}
+
+EAPI int dynamicbox_glance_bar_is_created(struct dynamicbox *handler)
+{
+       if (!handler || handler->state != CREATE) {
+               ErrPrint("Handler is invalid\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (!handler->common || handler->common->state != CREATE) {
+               ErrPrint("Handler is invalid\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (!handler->common->pd.fb || !handler->common->id) {
+               ErrPrint("Handler is not valid\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       return handler->common->is_pd_created;
+}
+
+EAPI int dynamicbox_create_glance_bar(struct dynamicbox *handler, double x, double y, dynamicbox_ret_cb_t cb, void *data)
+{
+       struct packet *packet;
+       int ret;
+
+       if (!handler || handler->state != CREATE) {
+               ErrPrint("Handler is invalid\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (!handler->common || handler->common->state != CREATE) {
+               ErrPrint("Handler is invalid\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (!handler->common->pd.fb || !handler->common->id) {
+               ErrPrint("Handler is not valid\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       /*!
+        * \note
+        * Only one handler can have a PD
+        */
+       if (handler->common->is_pd_created) {
+               DbgPrint("PD is already created\n");
+               return LB_STATUS_SUCCESS;
+       }
+
+       if (handler->common->request.pd_created) {
+               ErrPrint("Previous request is not completed yet\n");
+               return LB_STATUS_ERROR_BUSY;
+       }
+
+       /*!
+        * \note
+        * Turn off the pd_destroyed request flag
+        */
+       if (handler->common->request.pd_destroyed) {
+               if (job_add(handler, turn_off_pd_destroyed_flag_cb, LB_STATUS_ERROR_CANCEL, NULL) < 0) {
+                       ErrPrint("Failed to add pd_destroyed job\n");
+               }
+       }
+
+       packet = packet_create("create_pd", "ssdd", handler->common->pkgname, handler->common->id, x, y);
+       if (!packet) {
+               ErrPrint("Failed to build param\n");
+               return LB_STATUS_ERROR_FAULT;
+       }
+
+       if (!cb) {
+               cb = default_pd_created_cb;
+       }
+
+       DbgPrint("PERF_DBOX\n");
+       ret = master_rpc_async_request(handler, packet, 0, pd_create_cb, NULL);
+       if (ret == (int)LB_STATUS_SUCCESS) {
+               handler->cbs.pd_created.cb = cb;
+               handler->cbs.pd_created.data = data;
+               handler->common->request.pd_created = 1;
+       }
+
+       return ret;
+}
+
+EAPI int dynamicbox_move_glance_bar(struct dynamicbox *handler, double x, double y)
+{
+       struct packet *packet;
+
+       if (!handler || handler->state != CREATE) {
+               ErrPrint("Handler is invalid\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (!handler->common || handler->common->state != CREATE) {
+               ErrPrint("Handler is invalid\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (!handler->common->pd.fb || !handler->common->id) {
+               ErrPrint("Handler is not valid\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (!handler->common->is_pd_created) {
+               ErrPrint("PD is not created\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       packet = packet_create_noack("pd_move", "ssdd", handler->common->pkgname, handler->common->id, x, y);
+       if (!packet) {
+               ErrPrint("Failed to build param\n");
+               return LB_STATUS_ERROR_FAULT;
+       }
+
+       return master_rpc_request_only(handler, packet);
+}
+
+EAPI int dynamicbox_activate(const char *pkgname, dynamicbox_ret_cb_t cb, void *data)
+{
+       struct packet *packet;
+       struct cb_info *cbinfo;
+       int ret;
+
+       if (!pkgname) {
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       packet = packet_create("activate_package", "s", pkgname);
+       if (!packet) {
+               ErrPrint("Failed to build a param\n");
+               return LB_STATUS_ERROR_FAULT;
+       }
+
+       cbinfo = create_cb_info(cb, data);
+       if (!cbinfo) {
+               ErrPrint("Unable to create cbinfo\n");
+               packet_destroy(packet);
+               return LB_STATUS_ERROR_FAULT;
+       }
+
+       ret = master_rpc_async_request(NULL, packet, 0, activated_cb, cbinfo);
+       if (ret < 0) {
+               destroy_cb_info(cbinfo);
+       }
+
+       return ret;
+}
+
+EAPI int dynamicbox_destroy_glance_bar(struct dynamicbox *handler, dynamicbox_ret_cb_t cb, void *data)
+{
+       struct packet *packet;
+       struct cb_info *cbinfo;
+       int ret;
+
+       if (!handler || handler->state != CREATE) {
+               ErrPrint("Handler is invalid\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (!handler->common || handler->common->state != CREATE) {
+               ErrPrint("Handler is invalid\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (!handler->common->pd.fb || !handler->common->id) {
+               ErrPrint("Handler is not valid\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       /*!
+        * \FIXME
+        * Replace the callback check code.
+        * Use the flag instead of callback.
+        * the flag should be in the ADT "common"
+        */
+       if (!handler->common->is_pd_created && !handler->common->request.pd_created) {
+               ErrPrint("PD is not created\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (handler->common->request.pd_destroyed) {
+               ErrPrint("PD destroy request is already sent\n");
+               return LB_STATUS_ERROR_ALREADY;
+       }
+
+       /*!
+        * \note
+        * Disable the pd_created request flag
+        */
+       if (handler->common->request.pd_created) {
+               if (job_add(handler, turn_off_pd_created_flag_cb, LB_STATUS_ERROR_CANCEL, NULL) < 0) {
+                       ErrPrint("Failed to add a new job\n");
+               }
+       }
+
+       DbgPrint("[%s]\n", handler->common->pkgname);
+
+       packet = packet_create("destroy_pd", "ss", handler->common->pkgname, handler->common->id);
+       if (!packet) {
+               ErrPrint("Failed to build a param\n");
+               return LB_STATUS_ERROR_FAULT;
+       }
+
+       if (!cb) {
+               cb = default_pd_destroyed_cb;
+       }
+
+       cbinfo = create_cb_info(cb, data);
+       if (!cbinfo) {
+               packet_destroy(packet);
+               return LB_STATUS_ERROR_FAULT;
+       }
+
+       ret = master_rpc_async_request(handler, packet, 0, pd_destroy_cb, cbinfo);
+       if (ret < 0) {
+               destroy_cb_info(cbinfo);
+       } else {
+               handler->common->request.pd_destroyed = 1;
+       }
+
+       return ret;
+}
+
+EAPI int dynamicbox_feed_access_event(struct dynamicbox *handler, enum dynamicbox_access_event_type type, struct dynamicbox_access_event_info *info, dynamicbox_ret_cb_t cb, void *data)
+{
+       int w = 1;
+       int h = 1;
+       char cmd[32] = { '\0', };
+       char *ptr = cmd;
+       int ret = 0;    /* re-used for sending event type */
+
+       if (!handler || handler->state != CREATE) {
+               ErrPrint("Handler is invalid\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (!handler->common || handler->common->state != CREATE) {
+               ErrPrint("Handler is invalid\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (!handler->common->id) {
+               ErrPrint("Handler is not valid\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (handler->common->request.access_event) {
+               ErrPrint("Previous access event is not yet done\n");
+               return LB_STATUS_ERROR_BUSY;
+       }
+
+       if (type & ACCESS_EVENT_PD_MASK) {
+               if (!handler->common->is_pd_created) {
+                       ErrPrint("PD is not created\n");
+                       return LB_STATUS_ERROR_INVALID;
+               }
+               *ptr++ = 'p';
+               *ptr++ = 'd';
+               w = handler->common->pd.width;
+               h = handler->common->pd.height;
+       } else if (type & ACCESS_EVENT_LB_MASK) {
+               *ptr++ = 'l';
+               *ptr++ = 'b';
+               w = handler->common->lb.width;
+               h = handler->common->lb.height;
+       } else {
+               ErrPrint("Invalid event type\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       switch (type & ~(ACCESS_EVENT_PD_MASK | ACCESS_EVENT_LB_MASK)) {
+       case ACCESS_EVENT_HIGHLIGHT:
+               strcpy(ptr, "_access_hl");
+               ret = ACCESS_TYPE_CUR;
+               break;
+       case ACCESS_EVENT_HIGHLIGHT_NEXT:
+               strcpy(ptr, "_access_hl");
+               ret = ACCESS_TYPE_NEXT;
+               break;
+       case ACCESS_EVENT_HIGHLIGHT_PREV:
+               strcpy(ptr, "_access_hl");
+               ret = ACCESS_TYPE_PREV;
+               break;
+       case ACCESS_EVENT_UNHIGHLIGHT:
+               strcpy(ptr, "_access_hl");
+               ret = ACCESS_TYPE_OFF;
+               break;
+       case ACCESS_EVENT_ACTIVATE:
+               strcpy(ptr, "_access_activate");
+               break;
+       case ACCESS_EVENT_ACTION_DOWN:
+               strcpy(ptr, "_access_action");
+               ret = ACCESS_TYPE_DOWN;
+               break;
+       case ACCESS_EVENT_ACTION_UP:
+               strcpy(ptr, "_access_action");
+               ret = ACCESS_TYPE_UP;
+               break;
+       case ACCESS_EVENT_SCROLL_DOWN:
+               strcpy(ptr, "_access_scroll");
+               ret = ACCESS_TYPE_DOWN;
+               break;
+       case ACCESS_EVENT_SCROLL_MOVE:
+               strcpy(ptr, "_access_scroll");
+               ret = ACCESS_TYPE_MOVE;
+               break;
+       case ACCESS_EVENT_SCROLL_UP:
+               strcpy(ptr, "_access_scroll");
+               ret = ACCESS_TYPE_UP;
+               break;
+       case ACCESS_EVENT_VALUE_CHANGE:
+               strcpy(ptr, "_access_value_change");
+               break;
+       case ACCESS_EVENT_MOUSE:
+               strcpy(ptr, "_access_mouse");
+               break;
+       case ACCESS_EVENT_BACK:
+               strcpy(ptr, "_access_back");
+               break;
+       case ACCESS_EVENT_OVER:
+               strcpy(ptr, "_access_over");
+               break;
+       case ACCESS_EVENT_READ:
+               strcpy(ptr, "_access_read");
+               break;
+       case ACCESS_EVENT_ENABLE:
+               strcpy(ptr, "_access_enable");
+               ret = 1;
+               break;
+       case ACCESS_EVENT_DISABLE:
+               strcpy(ptr, "_access_enable");
+               ret = 0;
+               break;
+       default:
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (!cb) {
+               cb = default_access_event_cb;
+       }
+
+       ret = send_access_event(handler, cmd, x * w, y * h, ret);
+       if (ret == (int)LB_STATUS_SUCCESS) {
+               handler->cbs.access_event.cb = cb;
+               handler->cbs.access_event.data = data;
+               handler->common->request.access_event = 1;
+       }
+
+       return ret;
+}
+
+EAPI int dynamicbox_feed_mouse_event(struct dynamicbox *handler, enum dynamicbox_mouse_event_type type, struct dynamicbox_mouse_event_info *info)
+{
+       int w = 1;
+       int h = 1;
+       char cmd[32] = { '\0', };
+       char *ptr = cmd;
+
+       if (!handler || handler->state != CREATE) {
+               ErrPrint("Handler is invalid\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (!handler->common || handler->common->state != CREATE) {
+               ErrPrint("Handler is invalid\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (!handler->common->id) {
+               ErrPrint("Handler is not valid\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (!(type & CONTENT_EVENT_MOUSE_MASK)) {
+               ErrPrint("Invalid content event is used\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (type & CONTENT_EVENT_PD_MASK) {
+               int flag = 1;
+
+               if (!handler->common->is_pd_created) {
+                       ErrPrint("PD is not created\n");
+                       return LB_STATUS_ERROR_INVALID;
+               }
+
+               if (!handler->common->pd.fb) {
+                       ErrPrint("Handler is not valid\n");
+                       return LB_STATUS_ERROR_INVALID;
+               }
+
+               if (type & CONTENT_EVENT_MOUSE_MOVE) {
+                       if (fabs(x - handler->common->pd.x) < conf_event_filter() && fabs(y - handler->common->pd.y) < conf_event_filter()) {
+                               return LB_STATUS_ERROR_BUSY;
+                       }
+               } else if (type & CONTENT_EVENT_MOUSE_SET) {
+                       flag = 0;
+               }
+
+               if (flag) {
+                       w = handler->common->pd.width;
+                       h = handler->common->pd.height;
+                       handler->common->pd.x = x;
+                       handler->common->pd.y = y;
+               }
+               *ptr++ = 'p';
+               *ptr++ = 'd';
+       } else if (type & CONTENT_EVENT_LB_MASK) {
+               int flag = 1;
+
+               if (!handler->common->lb.mouse_event) {
+                       return LB_STATUS_ERROR_INVALID;
+               }
+
+               if (!handler->common->lb.fb) {
+                       ErrPrint("Handler is not valid\n");
+                       return LB_STATUS_ERROR_INVALID;
+               }
+
+               if (type & CONTENT_EVENT_MOUSE_MOVE) {
+                       if (fabs(x - handler->common->lb.x) < conf_event_filter() && fabs(y - handler->common->lb.y) < conf_event_filter()) {
+                               return LB_STATUS_ERROR_BUSY;
+                       }
+               } else if (type & CONTENT_EVENT_MOUSE_SET) {
+                       flag = 0;
+               }
+
+               if (flag) {
+                       w = handler->common->lb.width;
+                       h = handler->common->lb.height;
+                       handler->common->lb.x = x;
+                       handler->common->lb.y = y;
+               }
+               *ptr++ = 'l';
+               *ptr++ = 'b';
+       } else {
+               ErrPrint("Invalid event type\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       /*!
+        * Must be shorter than 29 bytes.
+        */
+       switch ((type & ~(CONTENT_EVENT_PD_MASK | CONTENT_EVENT_LB_MASK))) {
+       case CONTENT_EVENT_MOUSE_ENTER | CONTENT_EVENT_MOUSE_MASK:
+               strcpy(ptr, "_mouse_enter");
+               break;
+       case CONTENT_EVENT_MOUSE_LEAVE | CONTENT_EVENT_MOUSE_MASK:
+               strcpy(ptr, "_mouse_leave");
+               break;
+       case CONTENT_EVENT_MOUSE_UP | CONTENT_EVENT_MOUSE_MASK:
+               strcpy(ptr, "_mouse_up");
+               break;
+       case CONTENT_EVENT_MOUSE_DOWN | CONTENT_EVENT_MOUSE_MASK:
+               strcpy(ptr, "_mouse_down");
+               break;
+       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_ON_SCROLL | CONTENT_EVENT_MOUSE_MASK:
+               strcpy(ptr, "_mouse_on_scroll");
+               break;
+       case CONTENT_EVENT_ON_HOLD | CONTENT_EVENT_MOUSE_MASK:
+               strcpy(ptr, "_mouse_on_hold");
+               break;
+       case CONTENT_EVENT_OFF_SCROLL | CONTENT_EVENT_MOUSE_MASK:
+               strcpy(ptr, "_mouse_off_scroll");
+               break;
+       case CONTENT_EVENT_OFF_HOLD | CONTENT_EVENT_MOUSE_MASK:
+               strcpy(ptr, "_mouse_off_hold");
+               break;
+       default:
+               ErrPrint("Invalid event type\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       return send_mouse_event(handler, cmd, x * w, y * h);
+}
+
+EAPI int dynamicbox_feed_key_event(struct dynamicbox *handler, enum dynamicbox_key_event_type type, struct dynamicbox_key_event_info *info, dynamicbox_ret_cb_t cb, void *data)
+{
+       char cmd[32] = { '\0', };
+       char *ptr = cmd;
+       int ret;
+
+       if (!handler || handler->state != CREATE) {
+               ErrPrint("Handler is invalid\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (!handler->common || handler->common->state != CREATE) {
+               ErrPrint("Handler is invalid\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (!handler->common->id) {
+               ErrPrint("Handler is not valid\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (!(type & CONTENT_EVENT_KEY_MASK)) {
+               ErrPrint("Invalid key event is used\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (handler->common->request.key_event) {
+               ErrPrint("Previous key event is not completed yet\n");
+               return LB_STATUS_ERROR_BUSY;
+       }
+
+       if (type & CONTENT_EVENT_PD_MASK) {
+               if (!handler->common->is_pd_created) {
+                       ErrPrint("PD is not created\n");
+                       return LB_STATUS_ERROR_INVALID;
+               }
+
+               if (!handler->common->pd.fb) {
+                       ErrPrint("Handler is not valid\n");
+                       return LB_STATUS_ERROR_INVALID;
+               }
+
+               if (type & CONTENT_EVENT_KEY_DOWN) {
+                       /*!
+                        * \TODO
+                        * filtering the reproduced events if it is too fast
+                        */
+               } else if (type & CONTENT_EVENT_KEY_SET) {
+                       /*!
+                        * \TODO
+                        * What can I do for this case?
+                        */
+               }
+
+               *ptr++ = 'p';
+               *ptr++ = 'd';
+       } else if (type & CONTENT_EVENT_LB_MASK) {
+               if (!handler->common->lb.mouse_event) {
+                       return LB_STATUS_ERROR_INVALID;
+               }
+
+               if (!handler->common->lb.fb) {
+                       ErrPrint("Handler is not valid\n");
+                       return LB_STATUS_ERROR_INVALID;
+               }
+
+               if (type & CONTENT_EVENT_KEY_DOWN) {
+                       /*!
+                        * \TODO
+                        * filtering the reproduced events if it is too fast
+                        */
+               } else if (type & CONTENT_EVENT_KEY_SET) {
+                       /*!
+                        * What can I do for this case?
+                        */
+               }
+
+               *ptr++ = 'l';
+               *ptr++ = 'b';
+       } else {
+               ErrPrint("Invalid event type\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       /*!
+        * Must be short than 29 bytes.
+        */
+       switch ((type & ~(CONTENT_EVENT_PD_MASK | CONTENT_EVENT_LB_MASK))) {
+       case CONTENT_EVENT_KEY_FOCUS_IN | CONTENT_EVENT_KEY_MASK:
+               strcpy(ptr, "_key_focus_in");
+               break;
+       case CONTENT_EVENT_KEY_FOCUS_OUT | CONTENT_EVENT_KEY_MASK:
+               strcpy(ptr, "_key_focus_out");
+               break;
+       case CONTENT_EVENT_KEY_UP | CONTENT_EVENT_KEY_MASK:
+               strcpy(ptr, "_key_up");
+               break;
+       case CONTENT_EVENT_KEY_DOWN | CONTENT_EVENT_KEY_MASK:
+               strcpy(ptr, "_key_down");
+               break;
+       case CONTENT_EVENT_KEY_SET | CONTENT_EVENT_KEY_MASK:
+               strcpy(ptr, "_key_set");
+               break;
+       case CONTENT_EVENT_KEY_UNSET | CONTENT_EVENT_KEY_MASK:
+               strcpy(ptr, "_key_unset");
+               break;
+       default:
+               ErrPrint("Invalid event type\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (!cb) {
+               cb = default_key_event_cb;
+       }
+
+       ret = send_key_event(handler, cmd, keycode);
+       if (ret == (int)LB_STATUS_SUCCESS) {
+               handler->cbs.key_event.cb = cb;
+               handler->cbs.key_event.data = data;
+               handler->common->request.key_event = 1;
+       }
+
+       return ret;
+}
+
+EAPI const char *dynamicbox_filename(struct dynamicbox *handler)
+{
+       if (!handler || handler->state != CREATE) {
+               ErrPrint("Handler is invalid\n");
+               return NULL;
+       }
+
+       if (!handler->common || handler->common->state != CREATE) {
+               ErrPrint("Handler is invalid\n");
+               return NULL;
+       }
+
+       if (!handler->common->id) {
+               ErrPrint("Handler is not valid\n");
+               return NULL;
+       }
+
+       if (handler->common->filename) {
+               return handler->common->filename;
+       }
+
+       /* Oooops */
+       return util_uri_to_path(handler->common->id);
+}
+
+EAPI int dynamicbox_get_glance_bar_size(struct dynamicbox *handler, int *w, int *h)
+{
+       int _w;
+       int _h;
+
+       if (!handler || handler->state != CREATE) {
+               ErrPrint("Handler is invalid\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (!handler->common || handler->common->state != CREATE) {
+               ErrPrint("Handler is invalid\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (!handler->common->id) {
+               ErrPrint("Handler is not valid\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (!w) {
+               w = &_w;
+       }
+       if (!h) {
+               h = &_h;
+       }
+
+       if (!handler->common->is_pd_created) {
+               *w = handler->common->pd.default_width;
+               *h = handler->common->pd.default_height;
+       } else {
+               *w = handler->common->pd.width;
+               *h = handler->common->pd.height;
+       }
+
+       return LB_STATUS_SUCCESS;
+}
+
+EAPI int dynamicbox_size(struct dynamicbox *handler)
+{
+       int w;
+       int h;
+
+       if (!handler || handler->state != CREATE) {
+               ErrPrint("Handler is invalid\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (!handler->common || handler->common->state != CREATE) {
+               ErrPrint("Handler is invalid\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (!handler->common->id) {
+               ErrPrint("Handler is not valid\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       w = handler->common->lb.width;
+       h = handler->common->lb.height;
+
+       switch (handler->common->lb.type) {
+       case _LB_TYPE_BUFFER:
+       case _LB_TYPE_SCRIPT:
+               if (!fb_is_created(handler->common->lb.fb)) {
+                       w = 0;
+                       h = 0;
+               }
+               break;
+       default:
+               break;
+       }
+
+       return livebox_service_size_type(w, h);
+}
+
+EAPI int dynamicbox_set_group(struct dynamicbox *handler, const char *cluster, const char *category, dynamicbox_ret_cb_t cb, void *data)
+{
+       struct packet *packet;
+       int ret;
+
+       if (!handler) {
+               ErrPrint("Handler is NIL\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (!cluster || !category || handler->state != CREATE) {
+               ErrPrint("Invalid argument\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (!handler->common || handler->common->state != CREATE) {
+               ErrPrint("Invalid argument\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (!handler->common->id) {
+               ErrPrint("Invalid argument\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (handler->common->request.group_changed) {
+               ErrPrint("Previous group changing request is not finished yet\n");
+               return LB_STATUS_ERROR_BUSY;
+       }
+
+       if (!handler->common->is_user) {
+               ErrPrint("CA Livebox is not able to change the group\n");
+               return LB_STATUS_ERROR_PERMISSION;
+       }
+
+       if (!strcmp(handler->common->cluster, cluster) && !strcmp(handler->common->category, category)) {
+               DbgPrint("No changes\n");
+               return LB_STATUS_ERROR_ALREADY;
+       }
+
+       packet = packet_create("change_group", "ssss", handler->common->pkgname, handler->common->id, cluster, category);
+       if (!packet) {
+               ErrPrint("Failed to build a param\n");
+               return LB_STATUS_ERROR_FAULT;
+       }
+
+       if (!cb) {
+               cb = default_group_changed_cb;
+       }
+
+       ret = master_rpc_async_request(handler, packet, 0, set_group_ret_cb, NULL);
+       if (ret == (int)LB_STATUS_SUCCESS) {
+               handler->cbs.group_changed.cb = cb;
+               handler->cbs.group_changed.data = data; 
+               handler->common->request.group_changed = 1;
+       }
+
+       return ret;
+}
+
+EAPI int dynamicbox_get_group(struct dynamicbox *handler, const char **cluster, const char **category)
+{
+       if (!handler) {
+               ErrPrint("Handler is NIL\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (!cluster || !category || handler->state != CREATE) {
+               ErrPrint("Invalid argument\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (!handler->common || handler->common->state != CREATE) {
+               ErrPrint("Invalid argument\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (!handler->common->id) {
+               ErrPrint("Invalid argument\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       *cluster = handler->common->cluster;
+       *category = handler->common->category;
+       return LB_STATUS_SUCCESS;
+}
+
+EAPI int dynamicbox_get_supported_sizes(struct dynamicbox *handler, int *cnt, int *size_list)
+{
+       register int i;
+       register int j;
+
+       if (!handler || !size_list) {
+               ErrPrint("Invalid argument, handler(%p), size_list(%p)\n", handler, size_list);
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (!cnt || handler->state != CREATE) {
+               ErrPrint("Handler is not valid\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (!handler->common || handler->common->state != CREATE) {
+               ErrPrint("Handler is not valid\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (!handler->common->id) {
+               ErrPrint("Handler is not valid\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       for (j = i = 0; i < NR_OF_SIZE_LIST; i++) {
+               if (handler->common->lb.size_list & (0x01 << i)) {
+                       if (j == *cnt) {
+                               break;
+                       }
+
+                       size_list[j++] = (0x01 << i);
+               }
+       }
+
+       *cnt = j;
+       return LB_STATUS_SUCCESS;
+}
+
+EAPI const char *dynamicbox_pkgname(struct dynamicbox *handler)
+{
+       if (!handler) {
+               ErrPrint("Handler is NIL\n");
+               return NULL;
+       }
+
+       if (handler->state != CREATE) {
+               ErrPrint("Handler is not valid\n");
+               return NULL;
+       }
+
+       if (!handler->common || handler->common->state != CREATE) {
+               ErrPrint("Handler is not valid\n");
+               return NULL;
+       }
+
+       return handler->common->pkgname;
+}
+
+EAPI double dynamicbox_priority(struct dynamicbox *handler)
+{
+       if (!handler || handler->state != CREATE) {
+               ErrPrint("Handler is invalid\n");
+               return -1.0f;
+       }
+
+       if (!handler->common || handler->common->state != CREATE) {
+               ErrPrint("Handler is invalid\n");
+               return -1.0f;
+       }
+
+       if (!handler->common->id) {
+               ErrPrint("Handler is not valid (%p)\n", handler);
+               return -1.0f;
+       }
+
+       return handler->common->lb.priority;
+}
+
+EAPI int dynamicbox_delete_cluster(const char *cluster, dynamicbox_ret_cb_t cb, void *data)
+{
+       struct packet *packet;
+       struct cb_info *cbinfo;
+       int ret;
+
+       packet = packet_create("delete_cluster", "s", cluster);
+       if (!packet) {
+               ErrPrint("Failed to build a param\n");
+               return LB_STATUS_ERROR_FAULT;
+       }
+
+       cbinfo = create_cb_info(cb, data);
+       if (!cbinfo) {
+               packet_destroy(packet);
+               return LB_STATUS_ERROR_FAULT;
+       }
+
+       ret = master_rpc_async_request(NULL, packet, 0, delete_cluster_cb, cbinfo);
+       if (ret < 0) {
+               destroy_cb_info(cbinfo);
+       }
+
+       return ret;
+}
+
+EAPI int dynamicbox_delete_category(const char *cluster, const char *category, dynamicbox_ret_cb_t cb, void *data)
+{
+       struct packet *packet;
+       struct cb_info *cbinfo;
+       int ret;
+
+       packet = packet_create("delete_category", "ss", cluster, category);
+       if (!packet) {
+               ErrPrint("Failed to build a param\n");
+               return LB_STATUS_ERROR_FAULT;
+       }
+
+       cbinfo = create_cb_info(cb, data);
+       if (!cbinfo) {
+               packet_destroy(packet);
+               return LB_STATUS_ERROR_FAULT;
+       }
+
+       ret = master_rpc_async_request(NULL, packet, 0, delete_category_cb, cbinfo);
+       if (ret < 0) {
+               destroy_cb_info(cbinfo);
+       }
+
+       return ret;
+}
+
+EAPI enum dynamicbox_type dynamicbox_type(struct dynamicbox *handler, int gbar)
+{
+       enum dynamicbox_type type;
+
+       if (!handler || handler->state != CREATE) {
+               ErrPrint("Handler is invalid\n");
+               return PD_TYPE_INVALID;
+       }
+
+       if (!handler->common || handler->common->state != CREATE) {
+               ErrPrint("Handler is invalid\n");
+               return PD_TYPE_INVALID;
+       }
+
+       if (!handler->common->id) {
+               ErrPrint("Handler is not valid\n");
+               return PD_TYPE_INVALID;
+       }
+
+       if (gbar) {
+               switch (handler->common->pd.type) {
+               case _PD_TYPE_TEXT:
+                       return PD_TYPE_TEXT;
+               case _PD_TYPE_BUFFER:
+               case _PD_TYPE_SCRIPT:
+                       {
+                               const char *id;
+                               id = fb_id(handler->common->pd.fb);
+                               if (id && !strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP))) {
+                                       return PD_TYPE_PIXMAP;
+                               }
+                       }
+                       return PD_TYPE_BUFFER;
+               case _PD_TYPE_ELEMENTARY:
+                       return PD_TYPE_ELEMENTARY;
+               default:
+                       break;
+               }
+
+               return PD_TYPE_INVALID;
+       } else {
+               switch (handler->common->lb.type) {
+               case _LB_TYPE_FILE:
+                       return LB_TYPE_IMAGE;
+               case _LB_TYPE_BUFFER:
+               case _LB_TYPE_SCRIPT:
+                       {
+                               const char *id;
+                               id = fb_id(handler->common->lb.fb);
+                               if (id && !strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP))) {
+                                       return LB_TYPE_PIXMAP;
+                               }
+                       }
+                       return LB_TYPE_BUFFER;
+               case _LB_TYPE_TEXT:
+                       return LB_TYPE_TEXT;
+               case _LB_TYPE_ELEMENTARY:
+                       return LB_TYPE_ELEMENTARY;
+               default:
+                       break;
+               }
+
+               return LB_TYPE_INVALID;
+       }
+
+       return type;
+}
+
+EAPI int dynamicbox_set_text_handler(struct dynamicbox *handler, int gbar, struct dynamicbox_script_operators *ops)
+{
+       if (!handler) {
+               ErrPrint("Handler is NIL\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (handler->state != CREATE) {
+               ErrPrint("Handler is not valid\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (gbar) {
+               memcpy(&handler->cbs.pd_ops, ops, sizeof(*ops));
+       } else {
+               memcpy(&handler->cbs.lb_ops, ops, sizeof(*ops));
+       }
+
+       return LB_STATUS_SUCCESS;
+}
+
+EAPI unsigned int dynamicbox_acquire_resource_id(struct dynamicbox *handler, int gbar, dynamicbox_ret_cb_t cb, void *data)
 {
        if (gbar) {
-               return (unsigned int)livebox_acquire_pd_pixmap((struct livebox*) handler, (ret_cb_t)cb, data);
+               if (!handler || handler->state != CREATE) {
+                       ErrPrint("Handler is invalid\n");
+                       return LB_STATUS_ERROR_INVALID;
+               }
+
+               if (!handler->common || handler->common->state != CREATE) {
+                       ErrPrint("Handler is invalid\n");
+                       return LB_STATUS_ERROR_INVALID;
+               }
+
+               if (!handler->common->id) {
+                       ErrPrint("Invalid handle\n");
+                       return LB_STATUS_ERROR_INVALID;
+               }
+
+               if (handler->common->pd.type != _PD_TYPE_SCRIPT && handler->common->pd.type != _PD_TYPE_BUFFER) {
+                       ErrPrint("Handler is not valid type\n");
+                       return LB_STATUS_ERROR_INVALID;
+               }
+
+               return lb_acquire_pd_pixmap(handler, cb, data);
        } else {
-               return (unsigned int)livebox_acquire_lb_pixmap((struct livebox*) handler, (ret_cb_t)cb, data);
+               if (!handler || handler->state != CREATE) {
+                       ErrPrint("Handler is invalid\n");
+                       return LB_STATUS_ERROR_INVALID;
+               }
+
+               if (!handler->common || handler->common->state != CREATE) {
+                       ErrPrint("Handler is invalid\n");
+                       return LB_STATUS_ERROR_INVALID;
+               }
+
+               if (!handler->common->id) {
+                       ErrPrint("Invalid handle\n");
+                       return LB_STATUS_ERROR_INVALID;
+               }
+
+               if (handler->common->lb.type != _LB_TYPE_SCRIPT && handler->common->lb.type != _LB_TYPE_BUFFER) {
+                       ErrPrint("Handler is not valid type\n");
+                       return LB_STATUS_ERROR_INVALID;
+               }
+
+               return lb_acquire_lb_pixmap(handler, cb, data);
        }
 }
 
+/*!
+ * \note
+ * Do not check the state of handler and common-handler.
+ * If this function is used in the deleted callback,
+ * the handler and common-handler's state would be DELETE
+ * if this function check the state of handles,
+ * user cannot release the pixmap.
+ */
 EAPI int dynamicbox_release_resource_id(struct dynamicbox *handler, int gbar, unsigned int resource_id)
 {
+       struct packet *packet;
+       const char *pkgname;
+       const char *id;
+
+       if (pixmap == 0 /* || handler->state != CREATE */) {
+               ErrPrint("Pixmap is invalid [%d]\n", pixmap);
+               return LB_STATUS_ERROR_INVALID;
+       }
+
        if (gbar) {
-               return livebox_release_pd_pixmap((struct livebox*) handler, (int)resource_id);
+               if (!handler) {
+                       /*!
+                        * \note
+                        * Even though the handler is NULL, we should send the release request to the master.
+                        * Because the pixmap resource can be released after the handler is destroyed.
+                        * Pixmap resource is used by client. and it cannot be guaranteed to release pixmap.
+                        * In some cases, the pixmap can be released after the handler is deleted.
+                        *
+                        * Its implementation is up to the viewer app.
+                        * But we cannot force it to use only with valid handler.
+                        */
+                       DbgPrint("Using NULL handler\n");
+                       pkgname = NULL;
+                       id = NULL;
+                       /*!
+                        * \note
+                        * Master will try to find the buffer handler using given pixmap. if the pkgname and id is not valid.
+                        */
+               } else {
+                       if (!handler->common /* || handler-common->state != CREATE */) {
+                               ErrPrint("Handler is invalid\n");
+                               return LB_STATUS_ERROR_INVALID;
+                       }
+
+                       if (!handler->common->id) {
+                               ErrPrint("Invalid handle\n");
+                               return LB_STATUS_ERROR_INVALID;
+                       }
+
+                       if (handler->common->pd.type != _PD_TYPE_SCRIPT && handler->common->pd.type != _PD_TYPE_BUFFER) {
+                               ErrPrint("Handler is not valid type\n");
+                               return LB_STATUS_ERROR_INVALID;
+                       }
+
+                       pkgname = handler->common->pkgname;
+                       id = handler->common->id;
+               }
+
+               packet = packet_create_noack("pd_release_pixmap", "ssi", pkgname, id, pixmap);
+               if (!packet) {
+                       ErrPrint("Failed to build a param\n");
+                       return LB_STATUS_ERROR_FAULT;
+               }
        } else {
-               return livebox_release_lb_pixmap((struct livebox*) handler, (int)resource_id);
+               if (!handler) {
+                       /*!
+                        * \note
+                        * Even though the handler is NULL, we should send the release request to the master.
+                        * Because the pixmap resource can be released after the handler is destroyed.
+                        * Pixmap resource is used by client. and it cannot be guaranteed to release pixmap.
+                        * In some cases, the pixmap can be released after the handler is deleted.
+                        *
+                        * Its implementation is up to the viewer app.
+                        * But we cannot force it to use only with valid handler.
+                        */
+                       DbgPrint("Using NULL handler\n");
+                       pkgname = NULL;
+                       id = NULL;
+                       /*!
+                        * \note
+                        * Master will try to find the buffer handler using given pixmap. if the pkgname and id is not valid.
+                        */
+               } else {
+                       if (!handler->common /* || handler->common->state != CREATE */) {
+                               ErrPrint("Handler is invalid\n");
+                               return LB_STATUS_ERROR_INVALID;
+                       }
+
+                       if (!handler->common->id) {
+                               ErrPrint("Invalid handle\n");
+                               return LB_STATUS_ERROR_INVALID;
+                       }
+
+                       if (handler->common->lb.type != _LB_TYPE_SCRIPT && handler->common->lb.type != _LB_TYPE_BUFFER) {
+                               ErrPrint("Handler is not valid type\n");
+                               return LB_STATUS_ERROR_INVALID;
+                       }
+
+                       pkgname = handler->common->pkgname;
+                       id = handler->common->id;
+               }
+
+               packet = packet_create_noack("lb_release_pixmap", "ssi", pkgname, id, pixmap);
+               if (!packet) {
+                       ErrPrint("Failed to build a param\n");
+                       return LB_STATUS_ERROR_INVALID;
+               }
+
        }
+
+       return master_rpc_request_only(handler, packet);
 }
 
 EAPI unsigned int dynamicbox_resource_id(const struct dynamicbox *handler, int gbar)
 {
+       const char *id;
+       int pixmap = 0;
+
        if (gbar) {
-               return (unsigned int)livebox_pd_pixmap((const struct livebox*) handler);
+               if (!handler || handler->state != CREATE) {
+                       ErrPrint("Handler is invalid\n");
+                       return 0;
+               }
+
+               if (!handler->common || handler->common->state != CREATE) {
+                       ErrPrint("Handler is invalid\n");
+                       return 0;
+               }
+
+               if (!handler->common->id) {
+                       ErrPrint("Invalid handler\n");
+                       return 0;
+               }
+
+               if (handler->common->pd.type != _PD_TYPE_SCRIPT && handler->common->pd.type != _PD_TYPE_BUFFER) {
+                       ErrPrint("Invalid handler\n");
+                       return 0;
+               }
+
+               id = fb_id(handler->common->pd.fb);
+               if (id && sscanf(id, SCHEMA_PIXMAP "%u", (unsigned int *)&pixmap) != 1) {
+                       ErrPrint("PIXMAP Id is not valid\n");
+                       return 0;
+               }
        } else {
-               return (unsigned int)livebox_lb_pixmap((const struct livebox*) handler);
+               if (!handler || handler->state != CREATE) {
+                       ErrPrint("Handler is invalid\n");
+                       return 0;
+               }
+
+               if (!handler->common || handler->common->state != CREATE) {
+                       ErrPrint("Handler is invalid\n");
+                       return 0;
+               }
+
+               if (!handler->common->id) {
+                       ErrPrint("Invalid handler\n");
+                       return 0;
+               }
+
+               if (handler->common->lb.type != _LB_TYPE_SCRIPT && handler->common->lb.type != _LB_TYPE_BUFFER) {
+                       ErrPrint("Invalid handler\n");
+                       return 0;
+               }
+
+               id = fb_id(handler->common->lb.fb);
+               if (id && sscanf(id, SCHEMA_PIXMAP "%u", (unsigned int *)&pixmap) != 1) {
+                       ErrPrint("PIXMAP Id is not valid\n");
+                       return 0;
+               }
+
        }
+
+       return pixmap;
 }
 
 EAPI void *dynamicbox_acquire_fb(struct dynamicbox *handler, int gbar)
 {
        if (gbar) {
-               return livebox_acquire_pdfb((struct livebox*) handler);
+               if (!handler || handler->state != CREATE) {
+                       ErrPrint("Handler is invalid\n");
+                       return NULL;
+               }
+
+               if (!handler->common || handler->common->state != CREATE) {
+                       ErrPrint("Handler is invalid\n");
+                       return NULL;
+               }
+
+               if (!handler->common->id) {
+                       ErrPrint("Invalid handler\n");
+                       return NULL;
+               }
+
+               if (handler->common->pd.type != _PD_TYPE_SCRIPT && handler->common->pd.type != _PD_TYPE_BUFFER) {
+                       ErrPrint("Handler is not valid type\n");
+                       return NULL;
+               }
+
+               return fb_acquire_buffer(handler->common->pd.fb);
        } else {
-               return livebox_acquire_fb((struct livebox*) handler);
+               if (!handler || handler->state != CREATE) {
+                       ErrPrint("Handler is invalid\n");
+                       return NULL;
+               }
+
+               if (!handler->common || handler->common->state != CREATE) {
+                       ErrPrint("Handler is invalid\n");
+                       return NULL;
+               }
+
+               if (!handler->common->id) {
+                       ErrPrint("Invalid handle\n");
+                       return NULL;
+               }
+
+               if (handler->common->lb.type != _LB_TYPE_SCRIPT && handler->common->lb.type != _LB_TYPE_BUFFER) {
+                       ErrPrint("Handler is not valid type\n");
+                       return NULL;
+               }
+
+               return fb_acquire_buffer(handler->common->lb.fb);
        }
 }
 
-EAPI int dynamicbox_release_fb(void *buffer, int gbar)
+EAPI int dynamicbox_release_fb(void *buffer)
 {
-       if (gbar) {
-               return livebox_release_pdfb(buffer);
-       } else {
-               return livebox_release_fb(buffer);
-       }
+       return fb_release_buffer(buffer);
 }
 
-EAPI int dynamicbox_fb_refcnt(void *buffer, int gbar)
+EAPI int dynamicbox_fb_refcnt(void *buffer)
 {
-       if (gbar) {
-               return livebox_pdfb_refcnt(buffer);
-       } else {
-               return livebox_fb_refcnt(buffer);
-       }
+       return fb_refcnt(buffer);
 }
 
 EAPI int dynamicbox_fb_bufsz(struct dynamicbox *handler, int gbar)
 {
+       if (!handler || handler->state != CREATE) {
+               ErrPrint("Handler is invalid\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (!handler->common || handler->common->state != CREATE) {
+               ErrPrint("Handler is invalid\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (!handler->common->id) {
+               ErrPrint("Invalid handler\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
        if (gbar) {
-               return livebox_pdfb_bufsz((struct livebox*) handler);
+               return fb_size(handler->common->pd.fb);
        } else {
-               return livebox_lbfb_bufsz((struct livebox*) handler);
+               return fb_size(handler->common->lb.fb);
        }
 }
 
 EAPI int dynamicbox_is_created_by_user(struct dynamicbox *handler)
 {
-       return livebox_is_user((struct livebox*) handler);
+       if (!handler || handler->state != CREATE) {
+               ErrPrint("Handler is invalid\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (!handler->common || handler->common->state != CREATE) {
+               ErrPrint("Handler is invalid\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (!handler->common->id) {
+               ErrPrint("Invalid handler\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       return handler->common->is_user;
 }
 
 EAPI int dynamicbox_set_pinup(struct dynamicbox *handler, int flag, dynamicbox_ret_cb_t cb, void *data)
 {
-       return livebox_set_pinup((struct livebox*) handler, flag, (ret_cb_t)cb, data);
+       struct packet *packet;
+       int ret;
+
+       if (!handler || handler->state != CREATE) {
+               ErrPrint("Handler is invalid\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (!handler->common || handler->common->state != CREATE) {
+               ErrPrint("Handler is invalid\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (!handler->common->id) {
+               ErrPrint("Invalid handler\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (handler->common->request.pinup) {
+               ErrPrint("Previous pinup request is not finished\n");
+               return LB_STATUS_ERROR_BUSY;
+       }
+
+       if (handler->common->is_pinned_up == flag) {
+               DbgPrint("No changes\n");
+               return LB_STATUS_ERROR_ALREADY;
+       }
+
+       packet = packet_create("pinup_changed", "ssi", handler->common->pkgname, handler->common->id, flag);
+       if (!packet) {
+               ErrPrint("Failed to build a param\n");
+               return LB_STATUS_ERROR_FAULT;
+       }
+
+       if (!cb) {
+               cb = default_pinup_cb;
+       }
+
+       ret = master_rpc_async_request(handler, packet, 0, pinup_done_cb, NULL);
+       if (ret == (int)LB_STATUS_SUCCESS) {
+               handler->cbs.pinup.cb = cb;
+               handler->cbs.pinup.data = data;
+               handler->common->request.pinup = 1;
+       }
+
+       return ret;
 }
 
 EAPI int dynamicbox_is_pinned_up(struct dynamicbox *handler)
 {
-       return livebox_is_pinned_up((struct livebox*) handler);
+       if (!handler || handler->state != CREATE) {
+               ErrPrint("Handler is invalid\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (!handler->common || handler->common->state != CREATE) {
+               ErrPrint("Handler is invalid\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (!handler->common->id) {
+               ErrPrint("Invalid handler\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       return handler->common->is_pinned_up;
 }
 
 EAPI int dynamicbox_has_pinup(struct dynamicbox *handler)
 {
-       return livebox_has_pinup((struct livebox*) handler);
+       if (!handler || handler->state != CREATE) {
+               ErrPrint("Handler is invalid\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (!handler->common || handler->common->state != CREATE) {
+               ErrPrint("Handler is invalid\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (!handler->common->id) {
+               ErrPrint("Invalid handler\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       return handler->common->lb.pinup_supported;
 }
 
 EAPI int dynamicbox_set_data(struct dynamicbox *handler, void *data)
 {
-       return livebox_set_data((struct livebox*) handler, data);
+       if (!handler) {
+               ErrPrint("Handler is NIL\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (handler->state != CREATE) {
+               ErrPrint("Handler is invalid\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       handler->data = data;
+       return LB_STATUS_SUCCESS;
 }
 
 EAPI void *dynamicbox_data(struct dynamicbox *handler)
 {
-       return livebox_get_data((struct livebox*) handler);
+       if (!handler) {
+               ErrPrint("Handler is NIL\n");
+               return NULL;
+       }
+
+       if (handler->state != CREATE) {
+               ErrPrint("Handler is invalid\n");
+               return NULL;
+       }
+
+       return handler->data;
 }
 
 EAPI const char *dynamicbox_content(struct dynamicbox *handler)
 {
-       return livebox_content((struct livebox*) handler);
+       if (!handler || handler->state != CREATE) {
+               ErrPrint("Handler is invalid\n");
+               return NULL;
+       }
+
+       if (!handler->common || handler->common->state != CREATE) {
+               ErrPrint("Invalid handle\n");
+               return NULL;
+       }
+
+       return handler->common->content;
 }
 
 EAPI const char *dynamicbox_title(struct dynamicbox *handler)
 {
-       return livebox_category_title((struct livebox*) handler);
+       if (!handler || handler->state != CREATE) {
+               ErrPrint("Handler is invalid\n");
+               return NULL;
+       }
+
+       if (!handler->common || handler->common->state != CREATE) {
+               ErrPrint("Invalid handle\n");
+               return NULL;
+       }
+
+       return handler->common->title;
 }
 
 EAPI int dynamicbox_emit_text_signal(struct dynamicbox *handler, const char *emission, const char *source, double sx, double sy, double ex, double ey, dynamicbox_ret_cb_t cb, void *data)
 {
-       return livebox_emit_text_signal((struct livebox*) handler, emission, source, sx, sy, ex, ey, (ret_cb_t)cb, data);
+       struct packet *packet;
+       struct cb_info *cbinfo;
+       int ret;
+
+       if (!handler || handler->state != CREATE) {
+               ErrPrint("Handler is invalid\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (!handler->common || handler->common->state != CREATE) {
+               ErrPrint("Handler is invalid\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if ((handler->common->lb.type != _LB_TYPE_TEXT && handler->common->pd.type != _PD_TYPE_TEXT) || !handler->common->id) {
+               ErrPrint("Handler is not valid\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (!emission) {
+               emission = "";
+       }
+
+       if (!source) {
+               source = "";
+       }
+
+       packet = packet_create("text_signal", "ssssdddd",
+                               handler->common->pkgname, handler->common->id, emission, source, sx, sy, ex, ey);
+       if (!packet) {
+               ErrPrint("Failed to build a param\n");
+               return LB_STATUS_ERROR_FAULT;
+       }
+
+       cbinfo = create_cb_info(cb, data);
+       if (!cbinfo) {
+               packet_destroy(packet);
+               return LB_STATUS_ERROR_FAULT;
+       }
+
+       ret = master_rpc_async_request(handler, packet, 0, text_signal_cb, cbinfo);
+       if (ret < 0) {
+               destroy_cb_info(cbinfo);
+       }
+
+       return ret;
 }
 
 EAPI int dynamicbox_subscribe_group(const char *cluster, const char *category)
 {
-       return livebox_subscribe_group(cluster, category);
+       struct packet *packet;
+
+       /*!
+        * \todo
+        * Validate the group info using DB
+        * If the group info is not valid, do not send this request
+        */
+
+       packet = packet_create_noack("subscribe", "ss", cluster ? cluster : "", category ? category : "");
+       if (!packet) {
+               ErrPrint("Failed to create a packet\n");
+               return LB_STATUS_ERROR_FAULT;
+       }
+
+       return master_rpc_request_only(NULL, packet);
 }
 
 EAPI int dynamicbox_unsubscribe_group(const char *cluster, const char *category)
 {
-       return livebox_unsubscribe_group(cluster, category);
+       struct packet *packet;
+
+       /*!
+        * \todo
+        * Validate the group info using DB
+        * If the group info is not valid, do not send this request
+        * AND Check the subscribed or not too
+        */
+
+       packet = packet_create_noack("unsubscribe", "ss", cluster ? cluster : "", category ? category : "");
+       if (!packet) {
+               ErrPrint("Failed to create a packet\n");
+               return LB_STATUS_ERROR_FAULT;
+       }
+
+       return master_rpc_request_only(NULL, packet);
 }
 
 EAPI int dynamicbox_refresh(struct dynamicbox *handler, int force)
 {
-       return livebox_refresh((struct livebox*) handler, force);
+       struct packet *packet;
+
+       if (!handler || handler->state != CREATE) {
+               ErrPrint("Handler is invalid\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (!handler->common || handler->common->state != CREATE) {
+               ErrPrint("Handler is not valid\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (!handler->common->id) {
+               ErrPrint("Handler is not valid\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       packet = packet_create_noack("update", "ssi", handler->common->pkgname, handler->common->id, force);
+       if (!packet) {
+               ErrPrint("Failed to create a packet\n");
+               return LB_STATUS_ERROR_FAULT;
+       }
+
+       return master_rpc_request_only(handler, packet);
 }
 
 EAPI int dynamicbox_refresh_group(const char *cluster, const char *category, int force)
 {
-       return livebox_refresh_group(cluster, category, force);
+       struct packet *packet;
+
+       if (!cluster || !category) {
+               ErrPrint("Invalid argument\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       packet = packet_create_noack("refresh_group", "ssi", cluster, category, force);
+       if (!packet) {
+               ErrPrint("Failed to create a packet\n");
+               return LB_STATUS_ERROR_FAULT;
+       }
+
+       return master_rpc_request_only(NULL, packet);
 }
 
 EAPI int dynamicbox_set_visibility(struct dynamicbox *handler, enum dynamicbox_visible_state state)
 {
-       return livebox_set_visibility((struct livebox*) handler, state);
+       int old_state;
+       int ret;
+
+       if (!handler || handler->state != CREATE) {
+               ErrPrint("Handler is invalid\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (!handler->common || handler->common->state != CREATE) {
+               ErrPrint("Handler is not valid\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (!handler->common->id) {
+               ErrPrint("Handler is not valid\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (!handler->common->is_user) {
+               /* System cluster livebox cannot be changed its visible states */
+               if (state == LB_HIDE_WITH_PAUSE) {
+                       ErrPrint("CA Livebox is not able to change the visibility\n");
+                       return LB_STATUS_ERROR_PERMISSION;
+               }
+       }
+
+       if (handler->visible == state) {
+               DbgPrint("%s has no changes\n", handler->common->pkgname);
+               return LB_STATUS_ERROR_ALREADY;
+       }
+
+       old_state = handler->visible;
+       handler->visible = state;
+
+       ret = lb_set_visibility(handler, state);
+       if (ret < 0) {
+               handler->visible = old_state;
+       }
+
+       return ret;
 }
 
 EAPI enum dynamicbox_visible_state dynamicbox_visibility(struct dynamicbox *handler)
 {
-       return livebox_visibility((struct livebox*) handler);
+       if (!handler || handler->state != CREATE) {
+               ErrPrint("Handler is invalid\n");
+               return LB_VISIBLE_ERROR;
+       }
+
+       if (!handler->common || handler->common->state != CREATE) {
+               ErrPrint("Handler is not valid\n");
+               return LB_VISIBLE_ERROR;
+       }
+
+       if (!handler->common->id) {
+               ErrPrint("Handler is not valid\n");
+               return LB_VISIBLE_ERROR;
+       }
+
+       return handler->visible;
 }
 
 EAPI int dynamicbox_viewer_set_paused(void)
 {
-       return livebox_client_paused();
+       struct packet *packet;
+
+       packet = packet_create_noack("client_paused", "d", util_timestamp());
+       if (!packet) {
+               ErrPrint("Failed to create a pause packet\n");
+               return LB_STATUS_ERROR_FAULT;
+       }
+
+       return master_rpc_request_only(NULL, packet);
 }
 
 EAPI int dynamicbox_viewer_set_resumed(void)
 {
-       return livebox_client_resumed();
+       struct packet *packet;
+
+       packet = packet_create_noack("client_resumed", "d", util_timestamp());
+       if (!packet) {
+               ErrPrint("Failed to create a resume packet\n");
+               return LB_STATUS_ERROR_FAULT;
+       }
+
+       return master_rpc_request_only(NULL, packet);
 }
 
 EAPI int dynamicbox_sync_fb(struct dynamicbox *handler, int gbar)
 {
+       if (!handler || handler->state != CREATE) {
+               ErrPrint("Invalid handle\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (!handler->common || handler->common->state != CREATE) {
+               ErrPrint("Invalid handle\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (!handler->common->id) {
+               ErrPrint("Invalid handle\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
        if (gbar) {
-               return livebox_sync_pd_fb((struct livebox*) handler);
+               return lb_sync_pd_fb(handler->common);
        } else {
-               return livebox_sync_lb_fb((struct livebox*) handler);
+               return lb_sync_lb_fb(handler->common);
        }
 }
 
 EAPI const char *dynamicbox_alt_icon(struct dynamicbox *handler)
 {
-       return livebox_alt_icon((struct livebox*) handler);
+       if (!handler || handler->state != CREATE) {
+               ErrPrint("Handler is not valid[%p]\n", handler);
+               return NULL;
+       }
+
+       if (!handler->common || handler->common->state != CREATE) {
+               ErrPrint("Handler is not valid\n");
+               return NULL;
+       }
+
+       return handler->common->alt.icon;
 }
 
 EAPI const char *dynamicbox_alt_name(struct dynamicbox *handler)
 {
-       return livebox_alt_name((struct livebox*) handler);
+       if (!handler || handler->state != CREATE) {
+               ErrPrint("Handler is not valid[%p]\n", handler);
+               return NULL;
+       }
+
+       if (!handler->common || handler->common->state != CREATE) {
+               ErrPrint("Handler is not valid\n");
+               return NULL;
+       }
+
+       return handler->common->alt.name;
 }
 
 EAPI int dynamicbox_acquire_fb_lock(struct dynamicbox *handler, int gbar)
 {
-       return livebox_acquire_fb_lock((struct livebox*) handler, gbar);
+       int ret = LB_STATUS_SUCCESS;
+       int fd;
+
+       if (!handler || handler->state != CREATE) {
+               ErrPrint("Handler is not valid[%p]\n", handler);
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (!handler->common || handler->common->state != CREATE) {
+               ErrPrint("Handler is not valid\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (!handler->common->id) {
+               ErrPrint("Handler is not valid[%p]\n", handler);
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (is_pd) {
+               if (!handler->common->pd.lock || handler->common->pd.lock_fd < 0) {
+                       DbgPrint("Lock: %s (%d)\n", handler->common->pd.lock, handler->common->pd.lock_fd);
+                       return LB_STATUS_ERROR_INVALID;
+               }
+
+               if (fb_type(lb_get_pd_fb(handler->common)) == BUFFER_TYPE_FILE) {
+                       return LB_STATUS_SUCCESS;
+               }
+
+               fd = handler->common->pd.lock_fd;
+       } else {
+               if (!handler->common->lb.lock || handler->common->lb.lock_fd < 0) {
+                       DbgPrint("Lock: %s (%d)\n", handler->common->lb.lock, handler->common->lb.lock_fd);
+                       return LB_STATUS_ERROR_INVALID;
+               }
+
+               if (fb_type(lb_get_lb_fb(handler->common)) == BUFFER_TYPE_FILE) {
+                       return LB_STATUS_SUCCESS;
+               }
+
+               fd = handler->common->lb.lock_fd;
+       }
+
+       ret = do_fb_lock(fd);
+
+       return ret == 0 ? LB_STATUS_SUCCESS : LB_STATUS_ERROR_FAULT;
 }
 
 EAPI int dynamicbox_release_fb_lock(struct dynamicbox *handler, int gbar)
 {
-       return livebox_release_fb_lock((struct livebox*) handler, gbar);
+       int ret = LB_STATUS_SUCCESS;
+       int fd;
+
+       if (!handler || handler->state != CREATE) {
+               ErrPrint("Invalid handle\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (!handler->common || handler->common->state != CREATE) {
+               ErrPrint("Invalid handle\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (!handler->common->id) {
+               ErrPrint("Handler is not valid[%p]\n", handler);
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (is_pd) {
+               if (!handler->common->pd.lock || handler->common->pd.lock_fd < 0) {
+                       DbgPrint("Unlock: %s (%d)\n", handler->common->pd.lock, handler->common->pd.lock_fd);
+                       return LB_STATUS_ERROR_INVALID;
+               }
+
+               if (fb_type(lb_get_pd_fb(handler->common)) == BUFFER_TYPE_FILE) {
+                       return LB_STATUS_SUCCESS;
+               }
+
+               fd = handler->common->pd.lock_fd;
+       } else {
+               if (!handler->common->lb.lock || handler->common->lb.lock_fd < 0) {
+                       DbgPrint("Unlock: %s (%d)\n", handler->common->lb.lock, handler->common->lb.lock_fd);
+                       return LB_STATUS_ERROR_INVALID;
+               }
+
+               if (fb_type(lb_get_lb_fb(handler->common)) == BUFFER_TYPE_FILE) {
+                       return LB_STATUS_SUCCESS;
+               }
+
+               fd = handler->common->lb.lock_fd;
+       }
+
+       ret = do_fb_unlock(fd);
+
+       return ret == 0 ? LB_STATUS_SUCCESS : LB_STATUS_ERROR_FAULT;
 }
 
 EAPI int dynamicbox_set_option(enum dynamicbox_option_type option, int state)
 {
-       return livebox_set_option(option, state);
+       int ret = LB_STATUS_SUCCESS;
+
+       switch (option) {
+       case LB_OPTION_MANUAL_SYNC:
+               conf_set_manual_sync(state);
+               break;
+       case LB_OPTION_FRAME_DROP_FOR_RESIZE:
+               conf_set_frame_drop_for_resizing(state);
+               break;
+       case LB_OPTION_SHARED_CONTENT:
+               conf_set_shared_content(state);
+               break;
+       default:
+               ret = LB_STATUS_ERROR_INVALID;
+               break;
+       }
+
+       return ret;
 }
 
 EAPI int dynamicbox_option(enum dynamicbox_option_type option)
 {
-       return livebox_option(option);
+       int ret;
+
+       switch (option) {
+       case LB_OPTION_MANUAL_SYNC:
+               ret = conf_manual_sync();
+               break;
+       case LB_OPTION_FRAME_DROP_FOR_RESIZE:
+               ret = conf_frame_drop_for_resizing();
+               break;
+       case LB_OPTION_SHARED_CONTENT:
+               ret = conf_shared_content();
+               break;
+       default:
+               ret = LB_STATUS_ERROR_INVALID;
+               break;
+       }
+
+       return ret;
 }
 
 EAPI int dynamicbox_set_auto_launch_handler(int (*dbox_launch_handler)(struct dynamicbox *handler, const char *appid, void *data), void *data)
 {
-       typedef int (*launch_handler)(struct livebox *handler, const char *appid, void *data);
+       s_info.launch.handler = launch_handler;
+       s_info.launch.data = data;
 
-       return livebox_set_auto_launch_handler((launch_handler)dbox_launch_handler, data);
+       return LB_STATUS_SUCCESS;
 }
 
 /* End of a file */
index e890d0b..04d75da 100644 (file)
@@ -31,7 +31,7 @@
 
 #include <dlog.h>
 #include <secure_socket.h>
-#include <livebox-errno.h>
+#include <dynamicbox_errno.h>
 
 #include "client.h"
 #include "debug.h"
@@ -207,7 +207,7 @@ static inline int file_service_open(void)
  */
 static void write_item_to_pipe(struct request_item *item, int ret)
 {
-       item->ret = LB_STATUS_ERROR_FAULT;
+       item->ret = DBOX_STATUS_ERROR_FAULT;
        if (write(s_info.evt_pipe[PIPE_WRITE], &item, sizeof(item)) != sizeof(item)) {
                ErrPrint("write: %s\n", strerror(errno));
                free(item->filename);
@@ -275,7 +275,7 @@ static void *file_service_main(void *data)
                                        head = malloc(recvsz);
                                        if (!head) {
                                                ErrPrint("Heap: %s\n", strerror(errno));
-                                               ret = LB_STATUS_ERROR_MEMORY;
+                                               ret = DBOX_STATUS_ERROR_OUT_OF_MEMORY;
                                                write_item_to_pipe(item, ret);
                                                item = NULL;
                                                break;
@@ -293,7 +293,7 @@ static void *file_service_main(void *data)
                                                free(head);
                                                head = NULL;
                                                recv_state = RECV_INIT;
-                                               ret = LB_STATUS_ERROR_FAULT;
+                                               ret = DBOX_STATUS_ERROR_FAULT;
                                                write_item_to_pipe(item, ret);
                                                item = NULL;
                                                break;
@@ -313,7 +313,7 @@ static void *file_service_main(void *data)
                                                head = NULL;
                                                recv_state = RECV_INIT;
 
-                                               ret = LB_STATUS_ERROR_MEMORY;
+                                               ret = DBOX_STATUS_ERROR_OUT_OF_MEMORY;
                                                write_item_to_pipe(item, ret);
                                                item = NULL;
                                                break;
@@ -328,7 +328,7 @@ static void *file_service_main(void *data)
                                                free(head);
                                                head = NULL;
                                                recv_state = RECV_INIT;
-                                               ret = LB_STATUS_ERROR_FAULT;
+                                               ret = DBOX_STATUS_ERROR_FAULT;
                                                write_item_to_pipe(item, ret);
                                                item = NULL;
                                                break;
@@ -341,7 +341,7 @@ static void *file_service_main(void *data)
                                                head = NULL;
                                                recv_state = RECV_INIT;
 
-                                               ret = LB_STATUS_ERROR_IO;
+                                               ret = DBOX_STATUS_ERROR_IO_ERROR;
                                                write_item_to_pipe(item, ret);
                                                item = NULL;
                                                break;
@@ -355,7 +355,7 @@ static void *file_service_main(void *data)
                                        free(head);
                                        head = NULL;
                                        recv_state = RECV_INIT;
-                                       ret = LB_STATUS_ERROR_INVALID;
+                                       ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
                                        write_item_to_pipe(item, ret);
                                        item = NULL;
                                }
@@ -367,7 +367,7 @@ static void *file_service_main(void *data)
                                                free(head);
                                                head = NULL;
                                                recv_state = RECV_INIT;
-                                               ret = LB_STATUS_ERROR_MEMORY;
+                                               ret = DBOX_STATUS_ERROR_OUT_OF_MEMORY;
                                                write_item_to_pipe(item, ret);
                                                item = NULL;
                                                break;
@@ -386,7 +386,7 @@ static void *file_service_main(void *data)
                                        free(body);
                                        body = NULL;
                                        recv_state = RECV_INIT;
-                                       ret = LB_STATUS_ERROR_FAULT;
+                                       ret = DBOX_STATUS_ERROR_FAULT;
                                        write_item_to_pipe(item, ret);
                                        item = NULL;
                                        break;
@@ -402,7 +402,7 @@ static void *file_service_main(void *data)
                                                free(body);
                                                body = NULL;
                                                recv_state = RECV_INIT;
-                                               ret = LB_STATUS_ERROR_FAULT;
+                                               ret = DBOX_STATUS_ERROR_FAULT;
                                                write_item_to_pipe(item, ret);
                                                item = NULL;
                                                break;
@@ -420,7 +420,7 @@ static void *file_service_main(void *data)
                                                body = NULL;
                                                recv_state = RECV_INIT;
 
-                                               ret = LB_STATUS_ERROR_MEMORY;
+                                               ret = DBOX_STATUS_ERROR_OUT_OF_MEMORY;
                                                write_item_to_pipe(item, ret);
                                                item = NULL;
                                                break;
@@ -437,7 +437,7 @@ static void *file_service_main(void *data)
                                                body = NULL;
                                                recv_state = RECV_INIT;
 
-                                               ret = LB_STATUS_ERROR_IO;
+                                               ret = DBOX_STATUS_ERROR_IO_ERROR;
                                                write_item_to_pipe(item, ret);
                                                item = NULL;
                                                break;
@@ -452,7 +452,7 @@ static void *file_service_main(void *data)
                                                        if (close(file_fd) < 0) {
                                                                ErrPrint("close: %s\n", strerror(errno));
                                                        }
-                                                       ret = LB_STATUS_SUCCESS;
+                                                       ret = DBOX_STATUS_ERROR_NONE;
                                                        write_item_to_pipe(item, ret);
                                                        item = NULL;
                                                }
@@ -475,14 +475,14 @@ static void *file_service_main(void *data)
                                        head = NULL;
                                        recv_state = RECV_INIT;
 
-                                       ret = LB_STATUS_ERROR_FAULT;
+                                       ret = DBOX_STATUS_ERROR_FAULT;
                                        write_item_to_pipe(item, ret);
                                        item = NULL;
                                }
                                break;
                        default:
                                ErrPrint("Unknown event: %d\n", recv_state);
-                               ret = LB_STATUS_ERROR_FAULT;
+                               ret = DBOX_STATUS_ERROR_FAULT;
                                write_item_to_pipe(item, ret);
                                item = NULL;
                                break;
diff --git a/src/livebox.c b/src/livebox.c
deleted file mode 100644 (file)
index df76ead..0000000
+++ /dev/null
@@ -1,4928 +0,0 @@
-/*
- * Copyright 2013  Samsung Electronics Co., Ltd
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdio.h>
-#include <errno.h>
-#include <stdlib.h> /* malloc */
-#include <string.h> /* strdup */
-#include <math.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-#include <gio/gio.h>
-#include <aul.h>
-#include <dlog.h>
-
-#include <com-core_packet.h>
-#include <packet.h>
-#include <dynamicbox_service.h>
-#include <dynamicbox_errno.h>
-
-#include "debug.h"
-#include "fb.h"
-#include "livebox.h"
-#include "livebox_internal.h"
-#include "dlist.h"
-#include "util.h"
-#include "master_rpc.h"
-#include "client.h"
-#include "conf.h"
-
-#define EAPI __attribute__((visibility("default")))
-
-#if defined(FLOG)
-FILE *__file_log_fp;
-#endif
-
-#define ACCESS_TYPE_DOWN 0
-#define ACCESS_TYPE_MOVE 1
-#define ACCESS_TYPE_UP 2
-#define ACCESS_TYPE_CUR 0
-#define ACCESS_TYPE_NEXT 1
-#define ACCESS_TYPE_PREV 2
-#define ACCESS_TYPE_OFF 3
-
-static int default_launch_handler(struct livebox *handler, const char *appid, void *data);
-
-enum event_state {
-       INFO_STATE_CALLBACK_IN_IDLE = 0x00,
-       INFO_STATE_CALLBACK_IN_PROCESSING = 0x01,
-};
-
-static struct info {
-       struct dlist *livebox_list;
-       struct dlist *livebox_common_list;
-
-       struct dlist *event_list;
-       struct dlist *fault_list;
-
-       int init_count;
-       int prevent_overwrite;
-       enum event_state event_state;
-       enum event_state fault_state;
-       guint job_timer;
-       struct dlist *job_list;
-
-       struct launch {
-               int (*handler)(struct livebox *handler, const char *appid, void *data);
-               void *data;
-       } launch;
-} s_info = {
-       .livebox_list = NULL,
-       .event_list = NULL,
-       .fault_list = NULL,
-       .init_count = 0,
-       .prevent_overwrite = 0,
-       .event_state = INFO_STATE_CALLBACK_IN_IDLE,
-       .fault_state = INFO_STATE_CALLBACK_IN_IDLE,
-       .job_timer = 0,
-       .job_list = NULL,
-       .launch = {
-               .handler = default_launch_handler,
-               .data = NULL,
-       },
-};
-
-struct cb_info {
-       ret_cb_t cb;
-       void *data;
-};
-
-struct event_info {
-       int is_deleted;
-       int (*handler)(struct livebox *handler, enum livebox_event_type event, void *data);
-       void *user_data;
-};
-
-struct fault_info {
-       int is_deleted;
-       int (*handler)(enum livebox_fault_type event, const char *pkgname, const char *filename, const char *func, void *data);
-       void *user_data;
-};
-
-static void lb_pixmap_acquired_cb(struct livebox *handler, const struct packet *result, void *data);
-static void pd_pixmap_acquired_cb(struct livebox *handler, const struct packet *result, void *data);
-
-static int default_launch_handler(struct livebox *handler, const char *appid, void *data)
-{
-       int ret;
-
-       ret = aul_launch_app(appid, NULL);
-       if (ret <= 0) {
-               ErrPrint("Failed to launch an app %s (%d)\n", appid, ret);
-       }
-
-/*
-       app_control_h service;
-
-       DbgPrint("AUTO_LAUNCH [%s]\n", handler->common->lb.auto_launch);
-
-       ret = app_control_create(&service);
-       if (ret == APP_CONTROL_ERROR_NONE) {
-               app_control_set_package(service, handler->common->lb.auto_launch);
-               app_control_send_launch_request(service, NULL, NULL);
-               app_control_destroy(service);
-       } else {
-               ErrPrint("Failed to launch an app %s (%d)\n", handler->common->lb.auto_launch, ret);
-       }
-*/
-
-       return ret > 0 ? LB_STATUS_SUCCESS : LB_STATUS_ERROR_FAULT;
-}
-
-static inline void default_create_cb(struct livebox *handler, int ret, void *data)
-{
-       DbgPrint("Default created event handler: %d\n", ret);
-}
-
-static inline void default_delete_cb(struct livebox *handler, int ret, void *data)
-{
-       DbgPrint("Default deleted event handler: %d\n", ret);
-}
-
-static inline void default_pinup_cb(struct livebox *handler, int ret, void *data)
-{
-       DbgPrint("Default pinup event handler: %d\n", ret);
-}
-
-static inline void default_group_changed_cb(struct livebox *handler, int ret, void *data)
-{
-       DbgPrint("Default group changed event handler: %d\n", ret);
-}
-
-static inline void default_period_changed_cb(struct livebox *handler, int ret, void *data)
-{
-       DbgPrint("Default period changed event handler: %d\n", ret);
-}
-
-static inline void default_pd_created_cb(struct livebox *handler, int ret, void *data)
-{
-       DbgPrint("Default PD created event handler: %d\n", ret);
-}
-
-static inline void default_pd_destroyed_cb(struct livebox *handler, int ret, void *data)
-{
-       DbgPrint("Default PD destroyed event handler: %d\n", ret);
-}
-
-static inline void default_lb_size_changed_cb(struct livebox *handler, int ret, void *data)
-{
-       DbgPrint("Default LB size changed event handler: %d\n", ret);
-}
-
-static inline void default_update_mode_cb(struct livebox *handler, int ret, void *data)
-{
-       DbgPrint("Default update mode set event handler: %d\n", ret);
-}
-
-static inline void default_access_event_cb(struct livebox *handler, int ret, void *data)
-{
-       DbgPrint("Default access event handler: %d\n", ret);
-}
-
-static inline void default_key_event_cb(struct livebox *handler, int ret, void *data)
-{
-       DbgPrint("Default key event handler: %d\n", ret);
-}
-
-static inline __attribute__((always_inline)) struct cb_info *create_cb_info(ret_cb_t cb, void *data)
-{
-       struct cb_info *info;
-
-       info = malloc(sizeof(*info));
-       if (!info) {
-               ErrPrint("Heap: %s\n", strerror(errno));
-               return NULL;
-       }
-
-       info->cb = cb;
-       info->data = data;
-       return info;
-}
-
-static inline void destroy_cb_info(struct cb_info *info)
-{
-       free(info);
-}
-
-static int do_fb_lock(int fd)
-{
-        struct flock flock;
-       int ret;
-
-       flock.l_type = F_RDLCK;
-       flock.l_whence = SEEK_SET;
-       flock.l_start = 0;
-       flock.l_len = 0;
-       flock.l_pid = getpid();
-
-       do {
-               ret = fcntl(fd, F_SETLKW, &flock);
-               if (ret < 0) {
-                       ret = errno;
-                       ErrPrint("fcntl: %s\n", strerror(errno));
-               }
-       } while (ret == EINTR);
-
-       return ret;
-}
-
-static int do_fb_unlock(int fd)
-{
-       struct flock flock;
-       int ret;
-
-       flock.l_type = F_UNLCK;
-       flock.l_whence = SEEK_SET;
-       flock.l_start = 0;
-       flock.l_len = 0;
-       flock.l_pid = getpid();
-
-       do {
-               ret = fcntl(fd, F_SETLKW, &flock);
-               if (ret < 0) {
-                       ret = errno;
-                       ErrPrint("fcntl: %s\n", strerror(errno));
-               }
-       } while (ret == EINTR);
-
-       return ret;
-}
-
-int lb_destroy_lock_file(struct livebox_common *common, int is_pd)
-{
-       if (is_pd) {
-               if (!common->pd.lock) {
-                       return LB_STATUS_ERROR_INVALID;
-               }
-
-               if (close(common->pd.lock_fd) < 0) {
-                       ErrPrint("close: %s\n", strerror(errno));
-               }
-               common->pd.lock_fd = -1;
-
-               if (unlink(common->pd.lock) < 0) {
-                       ErrPrint("unlink: %s\n", strerror(errno));
-               }
-
-               free(common->pd.lock);
-               common->pd.lock = NULL;
-       } else {
-               if (!common->lb.lock) {
-                       return LB_STATUS_ERROR_INVALID;
-               }
-
-               if (close(common->lb.lock_fd) < 0) {
-                       ErrPrint("close: %s\n", strerror(errno));
-               }
-               common->lb.lock_fd = -1;
-
-               if (unlink(common->lb.lock) < 0) {
-                       ErrPrint("unlink: %s\n", strerror(errno));
-               }
-
-               free(common->lb.lock);
-               common->lb.lock = NULL;
-       }
-
-       return LB_STATUS_SUCCESS;
-}
-
-int lb_create_lock_file(struct livebox_common *common, int is_pd)
-{
-       int len;
-       char *file;
-
-       len = strlen(common->id);
-       file = malloc(len + 20);
-       if (!file) {
-               ErrPrint("Heap: %s\n", strerror(errno));
-               return LB_STATUS_ERROR_MEMORY;
-       }
-
-       snprintf(file, len + 20, "%s.%s.lck", util_uri_to_path(common->id), is_pd ? "pd" : "lb");
-
-       if (is_pd) {
-               common->pd.lock_fd = open(file, O_RDONLY);
-               if (common->pd.lock_fd < 0) {
-                       ErrPrint("open: %s\n", strerror(errno));
-                       free(file);
-                       return LB_STATUS_ERROR_IO;
-               }
-
-               common->pd.lock = file;
-       } else {
-               common->lb.lock_fd = open(file, O_RDONLY);
-               if (common->lb.lock_fd < 0) {
-                       ErrPrint("open: %s\n", strerror(errno));
-                       free(file);
-                       return LB_STATUS_ERROR_IO;
-               }
-
-               common->lb.lock = file;
-       }
-
-       return LB_STATUS_SUCCESS;
-}
-
-static void update_mode_cb(struct livebox *handler, const struct packet *result, void *data)
-{
-       int ret;
-
-       if (!result) {
-               ret = LB_STATUS_ERROR_FAULT;
-               goto errout;
-       } else if (packet_get(result, "i", &ret) != 1) {
-               ErrPrint("Invalid argument\n");
-               ret = LB_STATUS_ERROR_INVALID;
-               goto errout;
-       }
-
-       if (ret < 0) {
-               ErrPrint("Resize request is failed: %d\n", ret);
-               goto errout;
-       }
-
-       return;
-
-errout:
-       handler->cbs.update_mode.cb(handler, ret, handler->cbs.update_mode.data);
-       handler->cbs.update_mode.cb = NULL;
-       handler->cbs.update_mode.data = NULL;
-       handler->common->request.update_mode = 0;
-
-       if (ret == (int)LB_STATUS_ERROR_NOT_EXIST && handler->refcnt == 2) {
-               lb_invoke_event_handler(handler, LB_EVENT_DELETED);
-               lb_unref(handler, 1);
-       }
-}
-
-static void resize_cb(struct livebox *handler, const struct packet *result, void *data)
-{
-       int ret;
-
-       if (!result) {
-               ret = LB_STATUS_ERROR_FAULT;
-               goto errout;
-       } else if (packet_get(result, "i", &ret) != 1) {
-               ErrPrint("Invalid argument\n");
-               ret = LB_STATUS_ERROR_INVALID;
-               goto errout;
-       }
-
-       /*!
-        * \note
-        * In case of resize request,
-        * The livebox handler will not have resized value right after this callback,
-        * It can only get the new size when it makes updates.
-        *
-        * So the user can only get the resized value(result) from the first update event
-        * after this request.
-        */
-       if (ret < 0) {
-               ErrPrint("Resize request is failed: %d\n", ret);
-               goto errout;
-       }
-
-       return;
-
-errout:
-       handler->cbs.size_changed.cb(handler, ret, handler->cbs.size_changed.data);
-       handler->cbs.size_changed.cb = NULL;
-       handler->cbs.size_changed.data = NULL;
-       handler->common->request.size_changed = 0;
-
-       if (ret == (int)LB_STATUS_ERROR_NOT_EXIST && handler->refcnt == 2) {
-               lb_invoke_event_handler(handler, LB_EVENT_DELETED);
-               lb_unref(handler, 1);
-       }
-}
-
-static void text_signal_cb(struct livebox *handler, const struct packet *result, void *data)
-{
-       int ret;
-       void *cbdata;
-       struct cb_info *info = data;
-       ret_cb_t cb;
-
-       cbdata = info->data;
-       cb = info->cb;
-       destroy_cb_info(info);
-
-       if (!result) {
-               ret = LB_STATUS_ERROR_FAULT;
-       } else if (packet_get(result, "i", &ret) != 1) {
-               ErrPrint("Invalid argument\n");
-               ret = LB_STATUS_ERROR_INVALID;
-       }
-
-       if (cb) {
-               cb(handler, ret, cbdata);
-       }
-       return;
-}
-
-static void set_group_ret_cb(struct livebox *handler, const struct packet *result, void *data)
-{
-       int ret;
-
-       if (!result) {
-               ret = LB_STATUS_ERROR_FAULT;
-               goto errout;
-       } else if (packet_get(result, "i", &ret) != 1) {
-               ErrPrint("Invalid argument\n");
-               ret = LB_STATUS_ERROR_INVALID;
-               goto errout;
-       }
-
-       if (ret < 0) {
-               goto errout;
-       }
-
-       return;
-
-errout:
-       handler->cbs.group_changed.cb(handler, ret, handler->cbs.group_changed.data);
-       handler->cbs.group_changed.cb = NULL;
-       handler->cbs.group_changed.data = NULL;
-       handler->common->request.group_changed = 0;
-
-       if (ret == (int)LB_STATUS_ERROR_NOT_EXIST && handler->refcnt == 2) {
-               lb_invoke_event_handler(handler, LB_EVENT_DELETED);
-               lb_unref(handler, 1);
-       }
-}
-
-static void period_ret_cb(struct livebox *handler, const struct packet *result, void *data)
-{
-       int ret;
-
-       if (!result) {
-               ret = LB_STATUS_ERROR_FAULT;
-               goto errout;
-       } else if (packet_get(result, "i", &ret) != 1) {
-               ErrPrint("Invalid argument\n");
-               ret = LB_STATUS_ERROR_INVALID;
-               goto errout;
-       }
-
-       if (ret < 0) {
-               goto errout;
-       }
-
-       return;
-
-errout:
-       handler->cbs.period_changed.cb(handler, ret, handler->cbs.period_changed.data);
-       handler->cbs.period_changed.cb = NULL;
-       handler->cbs.period_changed.data = NULL;
-       handler->common->request.period_changed = 0;
-
-       if (ret == (int)LB_STATUS_ERROR_NOT_EXIST && handler->refcnt == 2) {
-               lb_invoke_event_handler(handler, LB_EVENT_DELETED);
-               lb_unref(handler, 1);
-       }
-}
-
-static void del_ret_cb(struct livebox *handler, const struct packet *result, void *data)
-{
-       struct cb_info *info = data;
-       int ret;
-       ret_cb_t cb;
-       void *cbdata;
-
-       cb = info->cb;
-       cbdata = info->data;
-       destroy_cb_info(info);
-
-       if (!result) {
-               ErrPrint("Connection lost?\n");
-               ret = LB_STATUS_ERROR_FAULT;
-       } else if (packet_get(result, "i", &ret) != 1) {
-               ErrPrint("Invalid argument\n");
-               ret = LB_STATUS_ERROR_INVALID;
-       }
-
-       if (ret == 0) {
-               handler->cbs.deleted.cb = cb;
-               handler->cbs.deleted.data = cbdata;
-       } else if (cb) {
-               cb(handler, ret, cbdata);
-       }
-
-       /*!
-        * \note
-        * Do not call the deleted callback from here.
-        * master will send the "deleted" event.
-        * Then invoke this callback.
-        *
-        * if (handler->cbs.deleted.cb)
-        *      handler->cbs.deleted.cb(handler, ret, handler->cbs.deleted.data);
-        */
-}
-
-static void new_ret_cb(struct livebox *handler, const struct packet *result, void *data)
-{
-       int ret;
-       struct cb_info *info = data;
-       ret_cb_t cb;
-       void *cbdata;
-
-       cb = info->cb;
-       cbdata = info->data;
-       destroy_cb_info(info);
-
-       if (!result) {
-               ret = LB_STATUS_ERROR_FAULT;
-       } else if (packet_get(result, "i", &ret) != 1) {
-               ret = LB_STATUS_ERROR_INVALID;
-       }
-
-       if (ret >= 0) {
-               handler->cbs.created.cb = cb;
-               handler->cbs.created.data = cbdata;
-
-               /*!
-                * \note
-                * Don't go anymore ;)
-                */
-               return;
-       } else if (cb) {
-               /*!
-                * \note
-                * It means the current instance is not created,
-                * so user has to know about this.
-                * notice it to user using "deleted" event.
-                */
-               cb(handler, ret, cbdata);
-       }
-
-       lb_unref(handler, 1);
-}
-
-static void pd_create_cb(struct livebox *handler, const struct packet *result, void *data)
-{
-       int ret;
-
-       if (!result) {
-               ret = LB_STATUS_ERROR_FAULT;
-               goto errout;
-       } else if (packet_get(result, "i", &ret) != 1) {
-               ret = LB_STATUS_ERROR_INVALID;
-               goto errout;
-       }
-
-       if (ret < 0) {
-               ErrPrint("Failed to create a PD[%d]\n", ret);
-               goto errout;
-       }
-
-       return;
-
-errout:
-       handler->cbs.pd_created.cb(handler, ret, handler->cbs.pd_created.data);
-       handler->cbs.pd_created.cb = NULL;
-       handler->cbs.pd_created.data = NULL;
-       handler->common->request.pd_created = 0;
-
-       if (ret == (int)LB_STATUS_ERROR_NOT_EXIST && handler->refcnt == 2) {
-               lb_invoke_event_handler(handler, LB_EVENT_DELETED);
-               lb_unref(handler, 1);
-       }
-}
-
-static void activated_cb(struct livebox *handler, const struct packet *result, void *data)
-{
-       int ret;
-       struct cb_info *info = data;
-       void *cbdata;
-       ret_cb_t cb;
-       const char *pkgname = "";
-
-       cbdata = info->data;
-       cb = info->cb;
-       destroy_cb_info(info);
-
-       if (!result) {
-               ret = LB_STATUS_ERROR_FAULT;
-       } else if (packet_get(result, "is", &ret, &pkgname) != 2) {
-               ret = LB_STATUS_ERROR_INVALID;
-       }
-
-       if (cb) {
-               cb(handler, ret, cbdata);
-       }
-}
-
-static void pd_destroy_cb(struct livebox *handler, const struct packet *result, void *data)
-{
-       int ret;
-       ret_cb_t cb;
-       void *cbdata;
-       struct cb_info *info = data;
-
-       cbdata = info->data;
-       cb = info->cb;
-       destroy_cb_info(info);
-
-       if (!result) {
-               ErrPrint("Result is NIL (may connection lost)\n");
-               ret = LB_STATUS_ERROR_FAULT;
-       } else if (packet_get(result, "i", &ret) != 1) {
-               ErrPrint("Invalid parameter\n");
-               ret = LB_STATUS_ERROR_INVALID;
-       }
-
-       if (ret == (int)LB_STATUS_SUCCESS) {
-               handler->cbs.pd_destroyed.cb = cb;
-               handler->cbs.pd_destroyed.data = cbdata;
-       } else {
-               handler->common->is_pd_created = 0;
-               handler->common->request.pd_destroyed = 0;
-
-               if (cb) {
-                       cb(handler, ret, cbdata);
-               }
-       }
-}
-
-static void delete_cluster_cb(struct livebox *handler, const struct packet *result, void *data)
-{
-       struct cb_info *info = data;
-       int ret;
-       ret_cb_t cb;
-       void *cbdata;
-
-       cb = info->cb;
-       cbdata = info->data;
-       destroy_cb_info(info);
-
-       if (!result) {
-               ret = LB_STATUS_ERROR_FAULT;
-       } else if (packet_get(result, "i", &ret) != 1) {
-               ret = LB_STATUS_ERROR_INVALID;
-       }
-
-       if (cb) {
-               cb(handler, ret, cbdata);
-       }
-}
-
-static void delete_category_cb(struct livebox *handler, const struct packet *result, void *data)
-{
-       struct cb_info *info = data;
-       int ret;
-       ret_cb_t cb;
-       void *cbdata;
-
-       cb = info->cb;
-       cbdata = info->data;
-       destroy_cb_info(info);
-
-       if (!result) {
-               ret = LB_STATUS_ERROR_FAULT;
-       } else if (packet_get(result, "i", &ret) != 1) {
-               ret = LB_STATUS_ERROR_INVALID;
-       }
-
-       if (cb) {
-               cb(handler, ret, cbdata);
-       }
-}
-
-static int lb_acquire_lb_pixmap(struct livebox *handler, ret_cb_t cb, void *data)
-{
-       struct packet *packet;
-       struct cb_info *cbinfo;
-       const char *id;
-       int ret;
-
-       id = fb_id(handler->common->lb.fb);
-       if (!id || strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP))) {
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       packet = packet_create("lb_acquire_pixmap", "ss", handler->common->pkgname, handler->common->id);
-       if (!packet) {
-               ErrPrint("Failed to build a param\n");
-               return LB_STATUS_ERROR_FAULT;
-       }
-
-       cbinfo = create_cb_info(cb, data);
-       if (!cbinfo) {
-               packet_destroy(packet);
-               return LB_STATUS_ERROR_FAULT;
-       }
-
-       ret = master_rpc_async_request(handler, packet, 0, lb_pixmap_acquired_cb, cbinfo);
-       if (ret < 0) {
-               destroy_cb_info(cbinfo);
-       }
-
-       return ret;
-}
-
-static void lb_pixmap_acquired_cb(struct livebox *handler, const struct packet *result, void *data)
-{
-       int pixmap;
-       int ret = LB_STATUS_ERROR_INVALID;
-       ret_cb_t cb;
-       void *cbdata;
-       struct cb_info *info = data;
-
-       cb = info->cb;
-       cbdata = info->data;
-       destroy_cb_info(info);
-
-       if (!result) {
-               pixmap = 0; /* PIXMAP 0 means error */
-       } else if (packet_get(result, "ii", &pixmap, &ret) != 2) {
-               pixmap = 0;
-       }
-
-       if (ret == (int)LB_STATUS_ERROR_BUSY) {
-               ret = lb_acquire_lb_pixmap(handler, cb, cbdata);
-               DbgPrint("Busy, Try again: %d\n", ret);
-               /* Try again */
-       } else if (ret == (int)LB_STATUS_ERROR_NOT_EXIST && handler->refcnt == 2) {
-               if (cb) {
-                       cb(handler, pixmap, cbdata);
-               }
-
-               lb_invoke_event_handler(handler, LB_EVENT_DELETED);
-               lb_unref(handler, 1);
-       } else {
-               if (cb) {
-                       cb(handler, pixmap, cbdata);
-               }
-       }
-}
-
-static int lb_acquire_pd_pixmap(struct livebox *handler, ret_cb_t cb, void *data)
-{
-       struct packet *packet;
-       struct cb_info *cbinfo;
-       const char *id;
-       int ret;
-
-       id = fb_id(handler->common->pd.fb);
-       if (!id || strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP))) {
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       packet = packet_create("pd_acquire_pixmap", "ss", handler->common->pkgname, handler->common->id);
-       if (!packet) {
-               ErrPrint("Failed to build a param\n");
-               return LB_STATUS_ERROR_FAULT;
-       }
-
-       cbinfo = create_cb_info(cb, data);
-       if (!cbinfo) {
-               packet_destroy(packet);
-               return LB_STATUS_ERROR_FAULT;
-       }
-
-       ret = master_rpc_async_request(handler, packet, 0, pd_pixmap_acquired_cb, cbinfo);
-       if (ret < 0) {
-               /*!
-                * \note
-                * Packet will be destroyed by master_rpc_async_request
-                */
-               destroy_cb_info(cbinfo);
-       }
-
-       return ret;
-}
-
-static void pd_pixmap_acquired_cb(struct livebox *handler, const struct packet *result, void *data)
-{
-       int pixmap;
-       int ret;
-       ret_cb_t cb;
-       void *cbdata;
-       struct cb_info *info = data;
-
-       cb = info->cb;
-       cbdata = info->data;
-       destroy_cb_info(info);
-
-       if (!result) {
-               pixmap = 0; /* PIXMAP 0 means error */
-               ret = LB_STATUS_ERROR_FAULT;
-       } else if (packet_get(result, "ii", &pixmap, &ret) != 2) {
-               pixmap = 0;
-               ret = LB_STATUS_ERROR_INVALID;
-       }
-
-       if (ret == (int)LB_STATUS_ERROR_BUSY) {
-               ret = lb_acquire_pd_pixmap(handler, cb, cbdata);
-               DbgPrint("Busy, Try again: %d\n", ret);
-               /* Try again */
-       } else if (ret == (int)LB_STATUS_ERROR_NOT_EXIST && handler->refcnt == 2) {
-               if (cb) {
-                       cb(handler, pixmap, cbdata);
-               }
-               lb_invoke_event_handler(handler, LB_EVENT_DELETED);
-               lb_unref(handler, 1);
-       } else {
-               if (cb) {
-                       DbgPrint("ret: %d, pixmap: %d\n", ret, pixmap);
-                       cb(handler, pixmap, cbdata);
-               }
-       }
-}
-
-static void pinup_done_cb(struct livebox *handler, const struct packet *result, void *data)
-{
-       int ret;
-
-       if (!result) {
-               ret = LB_STATUS_ERROR_FAULT;
-               goto errout;
-       } else if (packet_get(result, "i", &ret) != 1) {
-               goto errout;
-       }
-
-       if (ret < 0) {
-               goto errout;
-       }
-
-       return;
-
-errout:
-       handler->cbs.pinup.cb(handler, ret, handler->cbs.pinup.data);
-       handler->cbs.pinup.cb = NULL;
-       handler->cbs.pinup.data = NULL;
-       handler->common->request.pinup = 0;
-
-       if (ret == (int)LB_STATUS_ERROR_NOT_EXIST && handler->refcnt == 2) {
-               lb_invoke_event_handler(handler, LB_EVENT_DELETED);
-               lb_unref(handler, 1);
-       }
-}
-
-static void key_ret_cb(struct livebox *handler, const struct packet *result, void *data)
-{
-       int ret;
-
-       if (!result) {
-               ret = LB_STATUS_ERROR_FAULT;
-               return;
-       }
-
-       if (packet_get(result, "i", &ret) != 1) {
-               ret = LB_STATUS_ERROR_INVALID;
-               return;
-       }
-
-       if (ret != LB_STATUS_SUCCESS) {
-               goto errout;
-       }
-
-       return;
-errout:
-       handler->cbs.key_event.cb(handler, ret, handler->cbs.key_event.data);
-       handler->cbs.key_event.cb = NULL;
-       handler->cbs.key_event.data = NULL;
-       handler->common->request.key_event = 0;
-
-       if (ret == (int)LB_STATUS_ERROR_NOT_EXIST && handler->refcnt == 2) {
-               lb_invoke_event_handler(handler, LB_EVENT_DELETED);
-               lb_unref(handler, 1);
-       }
-}
-
-static void access_ret_cb(struct livebox *handler, const struct packet *result, void *data)
-{
-       int ret;
-
-       if (!result) {
-               ret = LB_STATUS_ERROR_FAULT;
-               return;
-       }
-
-       if (packet_get(result, "i", &ret) != 1) {
-               ret = LB_STATUS_ERROR_INVALID;
-               return;
-       }
-
-       if (ret != LB_STATUS_SUCCESS) {
-               goto errout;
-       }
-
-       return;
-
-errout:
-       handler->cbs.access_event.cb(handler, ret, handler->cbs.access_event.data);
-       handler->cbs.access_event.cb = NULL;
-       handler->cbs.access_event.data = NULL;
-       handler->common->request.access_event = 0;
-
-       if (ret == (int)LB_STATUS_ERROR_NOT_EXIST && handler->refcnt == 2) {
-               lb_invoke_event_handler(handler, LB_EVENT_DELETED);
-               lb_unref(handler, 1);
-       }
-}
-
-static int send_access_event(struct livebox *handler, const char *event, int x, int y, int type)
-{
-       struct packet *packet;
-       double timestamp;
-
-       timestamp = util_timestamp();
-
-       packet = packet_create(event, "ssdiii", handler->common->pkgname, handler->common->id, timestamp, x, y, type);
-       if (!packet) {
-               ErrPrint("Failed to build packet\n");
-               return LB_STATUS_ERROR_FAULT;
-       }
-
-       return master_rpc_async_request(handler, packet, 0, access_ret_cb, NULL);
-}
-
-static int send_key_event(struct livebox *handler, const char *event, unsigned int keycode)
-{
-       struct packet *packet;
-       double timestamp;
-
-       timestamp = util_timestamp();
-       packet = packet_create(event, "ssdi", handler->common->pkgname, handler->common->id, timestamp, keycode);
-       if (!packet) {
-               ErrPrint("Failed to build packet\n");
-               return LB_STATUS_ERROR_FAULT;
-       }
-
-       return master_rpc_async_request(handler, packet, 0, key_ret_cb, NULL);
-}
-
-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, "ssdii", handler->common->pkgname, handler->common->id, timestamp, x, y);
-       if (!packet) {
-               ErrPrint("Failed to build param\n");
-               return LB_STATUS_ERROR_FAULT;
-       }
-
-       return master_rpc_request_only(handler, packet);
-}
-
-static int initialize_livebox(void *disp, int use_thread)
-{
-       int ret;
-#if defined(FLOG)
-       char filename[BUFSIZ];
-       snprintf(filename, sizeof(filename), "/tmp/%d.box.log", getpid());
-       __file_log_fp = fopen(filename, "w+t");
-       if (!__file_log_fp) {
-               __file_log_fp = fdopen(1, "w+t");
-       }
-#endif
-       ret = livebox_service_init();
-       if (ret != LB_STATUS_SUCCESS) {
-               return ret;
-       }
-
-       ret = fb_init(disp);
-       if (ret != LB_STATUS_SUCCESS) {
-               livebox_service_fini();
-               return ret;
-       }
-
-       ret = client_init(use_thread);
-       if (ret != LB_STATUS_SUCCESS) {
-               fb_fini();
-               livebox_service_fini();
-               return ret;
-       }
-
-       s_info.init_count++;
-       return ret;
-}
-
-EAPI int livebox_init_with_options(void *disp, int prevent_overwrite, double event_filter, int use_thread)
-{
-       if (s_info.init_count > 0) {
-               s_info.init_count++;
-               return LB_STATUS_SUCCESS;
-       }
-
-       /*!
-        * \note
-        * Some application doesn't want to use the environment value.
-        * So set them using arguments.
-        */
-       s_info.prevent_overwrite = prevent_overwrite;
-       conf_set_event_filter(event_filter);
-
-       return initialize_livebox(disp, use_thread);
-}
-
-EAPI int livebox_init(void *disp)
-{
-       const char *env;
-
-       if (s_info.init_count > 0) {
-               s_info.init_count++;
-               return LB_STATUS_SUCCESS;
-       }
-
-       env = getenv("PROVIDER_DISABLE_PREVENT_OVERWRITE");
-       if (env && !strcasecmp(env, "true")) {
-               s_info.prevent_overwrite = 1;
-       }
-
-       env = getenv("PROVIDER_EVENT_FILTER");
-       if (env) {
-               double event_filter;
-               if (sscanf(env, "%lf", &event_filter) == 1) {
-                       conf_set_event_filter(event_filter);
-               }
-       }
-
-       return initialize_livebox(disp, 0);
-}
-
-EAPI int livebox_fini(void)
-{
-       if (s_info.init_count <= 0) {
-               ErrPrint("Doesn't initialized\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       s_info.init_count--;
-       if (s_info.init_count > 0) {
-               ErrPrint("init count : %d\n", s_info.init_count);
-               return LB_STATUS_SUCCESS;
-       }
-
-       client_fini();
-       fb_fini();
-       livebox_service_fini();
-       return LB_STATUS_SUCCESS;
-}
-
-static inline char *lb_pkgname(const char *pkgname)
-{
-       char *lb;
-
-       lb = livebox_service_pkgname(pkgname);
-       if (!lb) {
-               if (util_validate_livebox_package(pkgname) == 0) {
-                       return strdup(pkgname);
-               }
-       }
-
-       return lb;
-}
-
-static struct livebox_common *find_sharable_common_handle(const char *pkgname, const char *content, int w, int h, const char *cluster, const char *category)
-{
-       struct dlist *l;
-       struct livebox_common *common;
-
-       if (!conf_shared_content()) {
-               /*!
-                * Shared content option is turnned off.
-                */
-               return NULL;
-       }
-
-       dlist_foreach(s_info.livebox_common_list, l, common) {
-               if (common->state != CREATE) {
-                       continue;
-               }
-
-               if (strcmp(common->pkgname, pkgname)) {
-                       continue;
-               }
-
-               if (strcmp(common->cluster, cluster)) {
-                       DbgPrint("Cluster mismatched\n");
-                       continue;
-               }
-
-               if (strcmp(common->category, category)) {
-                       DbgPrint("Category mismatched\n");
-                       continue;
-               }
-
-               if (common->content && content) {
-                       if (strcmp(common->content, content)) {
-                               DbgPrint("%s Content ([%s] <> [%s])\n", common->pkgname, common->content, content);
-                               continue;       
-                       }
-               } else {
-                       int c1_len;
-                       int c2_len;
-
-                       /*!
-                        * \note
-                        * We assumes "" (ZERO length string) to NULL
-                        */
-                       c1_len = common->content ? strlen(common->content) : 0;
-                       c2_len = content ? strlen(content) : 0;
-                       if (c1_len != c2_len) {
-                               DbgPrint("%s Content %p <> %p\n", common->pkgname, common->content, content);
-                               continue;
-                       }
-               }
-
-               if (common->request.size_changed) {
-                       DbgPrint("Changing size\n");
-                       /*!
-                        * \note
-                        * Do not re-use resizing instance.
-                        * We will not use predicted size.
-                        */
-                       continue;
-               }
-
-               if (common->request.created) {
-                       DbgPrint("Creating now but re-use it (%s)\n", common->pkgname);
-               }
-
-               if (common->lb.width != w || common->lb.height != h) {
-                       DbgPrint("Size mismatched\n");
-                       continue;
-               }
-
-               DbgPrint("common handle is found: %p\n", common);
-               return common;
-       }
-
-       return NULL;
-}
-
-static gboolean job_execute_cb(void *data)
-{
-       struct job_item *item;
-       struct dlist *l;
-
-       l = dlist_nth(s_info.job_list, 0);
-       if (!l) {
-               s_info.job_timer = 0;
-               return FALSE;
-       }
-
-       item = dlist_data(l);
-       s_info.job_list = dlist_remove(s_info.job_list, l);
-
-       if (item) {
-               item->cb(item->handle, item->ret, item->data);
-               lb_unref(item->handle, 1);
-               free(item);
-       }
-
-       return TRUE;
-}
-
-static int job_add(struct livebox *handle, ret_cb_t job_cb, int ret, void *data)
-{
-       struct job_item *item;
-
-       if (!job_cb) {
-               ErrPrint("Invalid argument\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       item = malloc(sizeof(*item));
-       if (!item) {
-               ErrPrint("Heap: %s\n", strerror(errno));
-               return LB_STATUS_ERROR_MEMORY;
-       }
-
-       item->handle = lb_ref(handle);
-       item->cb = job_cb;
-       item->data = data;
-       item->ret = ret;
-
-       s_info.job_list = dlist_append(s_info.job_list, item);
-
-       if (!s_info.job_timer) {
-               s_info.job_timer = g_timeout_add(1, job_execute_cb, NULL);
-               if (!s_info.job_timer) {
-                       ErrPrint("Failed to create a job timer\n");
-               }
-       }
-
-       return LB_STATUS_SUCCESS;
-}
-
-static int create_real_instance(struct livebox *handler, ret_cb_t cb, void *data)
-{
-       struct cb_info *cbinfo;
-       struct packet *packet;
-       struct livebox_common *common;
-       int ret;
-
-       common = handler->common;
-
-       packet = packet_create("new", "dssssdii",
-                               common->timestamp, common->pkgname, common->content,
-                               common->cluster, common->category,
-                               common->lb.period, common->lb.width, common->lb.height);
-       if (!packet) {
-               ErrPrint("Failed to create a new packet\n");
-               return LB_STATUS_ERROR_FAULT;
-       }
-
-       cbinfo = create_cb_info(cb, data);
-       if (!cbinfo) {
-               ErrPrint("Failed to create a cbinfo\n");
-               packet_destroy(packet);
-               return LB_STATUS_ERROR_MEMORY;
-       }
-
-       /*!
-        * \note
-        * master_rpc_async_request will destroy the packet (decrease the refcnt)
-        * So be aware the packet object after return from master_rpc_async_request.
-        */
-       ret = master_rpc_async_request(handler, packet, 0, new_ret_cb, cbinfo);
-       if (ret < 0) {
-               ErrPrint("Failed to send a new packet\n");
-               destroy_cb_info(cbinfo);
-               return LB_STATUS_ERROR_FAULT;
-       }
-       handler->common->request.created = 1;
-       return LB_STATUS_SUCCESS;
-}
-
-static void create_cb(struct livebox *handle, int ret, void *data)
-{
-       struct cb_info *cbinfo = data;
-
-       if (cbinfo->cb) {
-               cbinfo->cb(handle, ret, cbinfo->data);
-       }
-
-       destroy_cb_info(cbinfo);
-
-       /*!
-        * \note
-        * Forcely generate "updated" event
-        */
-       lb_invoke_event_handler(handle, LB_EVENT_LB_UPDATED);
-}
-
-static int create_fake_instance(struct livebox *handler, ret_cb_t cb, void *data)
-{
-       struct cb_info *cbinfo;
-
-       cbinfo = create_cb_info(cb, data);
-       if (!cbinfo) {
-               ErrPrint("Failed to create a cbinfo\n");
-               return LB_STATUS_ERROR_MEMORY;
-       }
-
-       if (job_add(handler, create_cb, LB_STATUS_SUCCESS, cbinfo) != LB_STATUS_SUCCESS) {
-               destroy_cb_info(cbinfo);
-       }
-
-       return LB_STATUS_SUCCESS;
-}
-
-struct livebox_common *lb_create_common_handle(struct livebox *handle, const char *pkgname, const char *cluster, const char *category)
-{
-       struct livebox_common *common;
-
-       common = calloc(1, sizeof(*common));
-       if (!common) {
-               ErrPrint("Heap: %s\n", strerror(errno));
-               return NULL;
-       }
-
-       common->pkgname = strdup(pkgname);
-       if (!common->pkgname) {
-               free(common);
-               return NULL;
-       }
-
-       common->cluster = strdup(cluster);
-       if (!common->cluster) {
-               ErrPrint("Error: %s\n", strerror(errno));
-               free(common->pkgname);
-               free(common);
-               return NULL;
-       }
-
-       common->category = strdup(category);
-       if (!common->category) {
-               ErrPrint("Error: %s\n", strerror(errno));
-               free(common->cluster);
-               free(common->pkgname);
-               free(common);
-               return NULL;
-       }
-
-       /* Data provider will set this */
-       common->lb.type = _LB_TYPE_FILE;
-       common->pd.type = _PD_TYPE_SCRIPT;
-
-       /* Used for handling the mouse event on a box */
-       common->lb.mouse_event = 0;
-
-       /* Cluster infomration is not determined yet */
-       common->nr_of_sizes = 0x01;
-
-       common->timestamp = util_timestamp();
-       common->is_user = 1;
-       common->delete_type = LB_DELETE_PERMANENTLY;
-       common->pd.lock = NULL;
-       common->pd.lock_fd = -1;
-       common->lb.lock = NULL;
-       common->lb.lock_fd = -1;
-
-       common->state = CREATE;
-       common->visible = LB_SHOW;
-
-       s_info.livebox_common_list = dlist_append(s_info.livebox_common_list, common);
-       return common;
-}
-
-int lb_destroy_common_handle(struct livebox_common *common)
-{
-       dlist_remove_data(s_info.livebox_common_list, common);
-
-       common->state = DESTROYED;
-
-       if (common->filename) {
-               (void)util_unlink(common->filename);
-       }
-
-       free(common->cluster);
-       free(common->category);
-       free(common->id);
-       free(common->pkgname);
-       free(common->filename);
-       free(common->lb.auto_launch);
-       free(common->alt.icon);
-       free(common->alt.name);
-
-       if (common->lb.fb) {
-               fb_destroy(common->lb.fb);
-               common->lb.fb = NULL;
-       }
-
-       if (common->pd.fb) {
-               fb_destroy(common->pd.fb);
-               common->pd.fb = NULL;
-       }
-
-       return 0;
-}
-
-int lb_common_ref(struct livebox_common *common, struct livebox *handle)
-{
-       common->livebox_list = dlist_append(common->livebox_list, handle);
-       common->refcnt++;
-
-       return common->refcnt;
-}
-
-int lb_common_unref(struct livebox_common *common, struct livebox *handle)
-{
-       int refcnt;
-       dlist_remove_data(common->livebox_list, handle);
-       refcnt = --common->refcnt;
-
-       return refcnt;
-}
-
-static void refresh_for_paused_updating_cb(struct livebox *handle, int ret, void *data)
-{
-       if (handle->paused_updating == 0) {
-               DbgPrint("Paused updates are cleared\n");
-               return;
-       }
-
-       DbgPrint("Pending updates are found\n");
-       lb_invoke_event_handler(handle, LB_EVENT_LB_UPDATED);
-}
-
-static int lb_set_visibility(struct livebox *handler, enum livebox_visible_state state)
-{
-       struct packet *packet;
-       int need_to_add_job = 0;
-       int ret;
-
-       if (handler->common->visible != LB_SHOW && state == LB_SHOW) {
-               need_to_add_job = !!handler->paused_updating;
-       } else if (handler->common->visible == LB_SHOW && state != LB_SHOW) {
-               struct dlist *l;
-               struct livebox *item;
-
-               dlist_foreach(handler->common->livebox_list, l, item) {
-                       if (item->visible == LB_SHOW) {
-                               DbgPrint("%s visibility is not changed\n", handler->common->pkgname);
-                               return LB_STATUS_SUCCESS;
-                       }
-               }
-       } else if (handler->common->visible == LB_SHOW && state == LB_SHOW && handler->paused_updating) {
-               if (job_add(handler, refresh_for_paused_updating_cb, LB_STATUS_SUCCESS, NULL) < 0) {
-                       ErrPrint("Unable to add a new job for refreshing box\n");
-               }
-
-               return LB_STATUS_SUCCESS;
-       } else {
-               /*!
-                * \brief
-                * No need to send this to the master
-                */
-               return LB_STATUS_SUCCESS;
-       }
-
-       packet = packet_create_noack("change,visibility", "ssi", handler->common->pkgname, handler->common->id, (int)state);
-       if (!packet) {
-               ErrPrint("Failed to create a packet\n");
-               return LB_STATUS_ERROR_FAULT;
-       }
-
-       ret = master_rpc_request_only(handler, packet);
-       if (ret == (int)LB_STATUS_SUCCESS) {
-               DbgPrint("[%s] visibility is changed 0x[%x]\n", handler->common->pkgname, state);
-               handler->common->visible = state;
-
-               if (need_to_add_job) {
-                       if (job_add(handler, refresh_for_paused_updating_cb, LB_STATUS_SUCCESS, NULL) < 0) {
-                               ErrPrint("Unable to add a new job for refreshing box\n");
-                       }
-               }
-       }
-
-       return ret;
-}
-
-EAPI struct livebox *livebox_add(const char *pkgname, const char *content, const char *cluster, const char *category, double period, int type, ret_cb_t cb, void *data)
-{
-       char *lbid;
-       struct livebox *handler;
-       int w = 0;
-       int h = 0;
-
-       if (!pkgname || !cluster || !category) {
-               ErrPrint("Invalid arguments: pkgname[%p], cluster[%p], category[%p]\n",
-                                                               pkgname, cluster, category);
-               return NULL;
-       }
-
-       lbid = lb_pkgname(pkgname);
-       if (!lbid) {
-               ErrPrint("Invalid package: %s\n", pkgname);
-               return NULL;
-       }
-
-       if (livebox_service_is_enabled(lbid) == 0) {
-               DbgPrint("Livebox [%s](%s) is disabled package\n", lbid, pkgname);
-               free(lbid);
-               return NULL;
-       }
-
-       if (type != LB_SIZE_TYPE_UNKNOWN) {
-               (void)livebox_service_get_size(type, &w, &h);
-       }
-
-       handler = calloc(1, sizeof(*handler));
-       if (!handler) {
-               ErrPrint("Error: %s\n", strerror(errno));
-               free(lbid);
-               return NULL;
-       }
-
-       if (!cb) {
-               cb = default_create_cb;
-       }
-
-       handler->common = find_sharable_common_handle(lbid, content, w, h, cluster, category);
-       if (!handler->common) {
-               handler->common = lb_create_common_handle(handler, lbid, cluster, category);
-               free(lbid);
-               if (!handler->common) {
-                       ErrPrint("Failed to find common handle\n");
-                       free(handler);
-                       return NULL;
-               }
-
-               if (!content || !strlen(content)) {
-                       char *pc;
-                       /*!
-                        * \note
-                        * I know the content should not be modified. use it temporarly without "const"
-                        */
-                       pc = livebox_service_content(handler->common->pkgname);
-                       lb_set_content(handler->common, pc);
-                       free(pc);
-               } else {
-                       lb_set_content(handler->common, content);
-               }
-
-               lb_set_period(handler->common, period);
-               lb_set_size(handler->common, w, h);
-               lb_common_ref(handler->common, handler);
-
-               if (create_real_instance(handler, cb, data) < 0) {
-                       if (lb_common_unref(handler->common, handler) == 0) {
-                               /*!
-                                * Delete common
-                                */
-                               lb_destroy_common_handle(handler->common);
-                               handler->common = NULL;
-                       }
-                       free(handler);
-                       return NULL;
-               }
-       } else {
-               free(lbid);
-
-               lb_common_ref(handler->common, handler);
-
-               if (handler->common->request.created) {
-                       /*!
-                        * If a box is in creating, wait its result too
-                        */
-                       handler->cbs.created.cb = cb;
-                       handler->cbs.created.data = data;
-               } else {
-                       /*!
-                        * or fire the fake created_event
-                        */
-                       if (create_fake_instance(handler, cb, data) < 0) {
-                               if (lb_common_unref(handler->common, handler) == 0) {
-                                       /*!
-                                        * Delete common
-                                        */
-                                       lb_destroy_common_handle(handler->common);
-                               }
-                               free(handler);
-                               return NULL;
-                       }
-               }
-       }
-
-       handler->visible = LB_SHOW;
-       handler->state = CREATE;
-       handler = lb_ref(handler);
-
-       if (handler->common->visible != LB_SHOW) {
-               lb_set_visibility(handler, LB_SHOW);
-       }
-
-       return handler;
-}
-
-EAPI double livebox_period(struct livebox *handler)
-{
-       if (!handler || handler->state != CREATE) {
-               ErrPrint("Handler is not valid\n");
-               return 0.0f;
-       }
-
-       if (!handler->common || handler->common->state != CREATE) {
-               ErrPrint("Invalid handle\n");
-               return 0.0f;
-       }
-
-       if (!handler->common->id) {
-               ErrPrint("Hnalder is not valid\n");
-               return 0.0f;
-       }
-
-       return handler->common->lb.period;
-}
-
-EAPI int livebox_set_period(struct livebox *handler, double period, ret_cb_t cb, void *data)
-{
-       struct packet *packet;
-       int ret;
-
-       if (!handler || handler->state != CREATE) {
-               ErrPrint("Handler is not valid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!handler->common || handler->common->state != CREATE) {
-               ErrPrint("Invalid handle\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!handler->common->id) {
-               ErrPrint("Handler is not valid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (handler->common->request.period_changed) {
-               ErrPrint("Previous request for changing period is not finished\n");
-               return LB_STATUS_ERROR_BUSY;
-       }
-
-       if (!handler->common->is_user) {
-               ErrPrint("CA Livebox is not able to change the period\n");
-               return LB_STATUS_ERROR_PERMISSION;
-       }
-
-       if (handler->common->lb.period == period) {
-               DbgPrint("No changes\n");
-               return LB_STATUS_ERROR_ALREADY;
-       }
-
-       packet = packet_create("set_period", "ssd", handler->common->pkgname, handler->common->id, period);
-       if (!packet) {
-               ErrPrint("Failed to build a packet %s\n", handler->common->pkgname);
-               return LB_STATUS_ERROR_FAULT;
-       }
-
-       if (!cb) {
-               cb = default_period_changed_cb;
-       }
-
-       ret = master_rpc_async_request(handler, packet, 0, period_ret_cb, NULL);
-       if (ret == (int)LB_STATUS_SUCCESS) {
-               handler->cbs.period_changed.cb = cb;
-               handler->cbs.period_changed.data = data;
-               handler->common->request.period_changed = 1;
-       }
-
-       return ret;
-}
-
-static void lb_update_visibility(struct livebox_common *old_common)
-{
-       struct dlist *l;
-       struct livebox *item;
-
-       item = NULL;
-       dlist_foreach(old_common->livebox_list, l, item) {
-               if (item->visible == LB_SHOW) {
-                       break;
-               }
-
-               item = NULL;
-       }
-
-       if (!item) {
-               l = dlist_nth(old_common->livebox_list, 0);
-               item = dlist_data(l);
-
-               if (item) {
-                       lb_set_visibility(item, LB_HIDE_WITH_PAUSE);
-               } else {
-                       ErrPrint("Unable to get the valid handle from common handler\n");
-               }
-       } else {
-               lb_set_visibility(item, LB_SHOW);
-       }
-}
-
-/*!
- * \note
- * The second parameter should be the "return value",
- * But in this case, we will use it for "type of deleting instance".
- */
-static void job_del_cb(struct livebox *handle, int type, void *data)
-{
-       struct cb_info *cbinfo = data;
-       ret_cb_t cb;
-
-       if (handle->visible == LB_SHOW) {
-               lb_update_visibility(handle->common);
-       }
-
-       cb = cbinfo->cb;
-       data = cbinfo->data;
-       destroy_cb_info(cbinfo);
-
-       if (handle->common->state != CREATE) {
-               DbgPrint("[%s] %d\n", handle->common->pkgname, handle->refcnt);
-               if (cb) {
-                       cb(handle, LB_STATUS_SUCCESS, data);
-               }
-
-               return;
-       }
-
-       if (handle->common->refcnt == 1) {
-               handle->common->delete_type = type;
-               handle->common->state = DELETE;
-
-               if (!handle->common->id) {
-                       /*!
-                        * \note
-                        * The id is not determined yet.
-                        * It means a user didn't receive created event yet.
-                        * Then just stop to delete procedure from here.
-                        * Because the "created" event handle will release this.
-                        * By the way, if the user adds any callback for getting return status of this,
-                        * call it at here.
-                        */
-                       if (cb) {
-                               cb(handle, LB_STATUS_SUCCESS, data);
-                       }
-               }
-
-               DbgPrint("Send delete request\n");
-               lb_send_delete(handle, type, cb, data);
-       } else {
-               if (cb) {
-                       cb(handle, LB_STATUS_SUCCESS, data);
-               }
-
-               DbgPrint("Before unref: %d\n", handle->common->refcnt);
-               lb_unref(handle, 1);
-       }
-}
-
-EAPI int livebox_del(struct livebox *handler, int type, ret_cb_t cb, void *data)
-{
-       struct cb_info *cbinfo;
-
-       if (!handler) {
-               ErrPrint("Handler is NIL\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (handler->state != CREATE) {
-               ErrPrint("Handler is already deleted\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       handler->state = DELETE;
-
-       cbinfo = create_cb_info(cb, data);
-       if (!cbinfo) {
-               ErrPrint("Failed to create a cbinfo\n");
-               return LB_STATUS_ERROR_MEMORY;
-       }
-
-       if (job_add(handler, job_del_cb, type, cbinfo) != LB_STATUS_SUCCESS) {
-               ErrPrint("Failed to add a new job\n");
-               destroy_cb_info(cbinfo);
-               return LB_STATUS_ERROR_FAULT;
-       }
-
-       return LB_STATUS_SUCCESS;
-}
-
-EAPI int livebox_set_fault_handler(int (*cb)(enum livebox_fault_type, const char *, const char *, const char *, void *), void *data)
-{
-       struct fault_info *info;
-
-       if (!cb) {
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       info = malloc(sizeof(*info));
-       if (!info) {
-               ErrPrint("Heap: %s\n", strerror(errno));
-               return LB_STATUS_ERROR_MEMORY;
-       }
-
-       info->handler = cb;
-       info->user_data = data;
-       info->is_deleted = 0;
-
-       s_info.fault_list = dlist_append(s_info.fault_list, info);
-       return LB_STATUS_SUCCESS;
-}
-
-EAPI void *livebox_unset_fault_handler(int (*cb)(enum livebox_fault_type, const char *, const char *, const char *, void *))
-{
-       struct fault_info *info;
-       struct dlist *l;
-
-       dlist_foreach(s_info.fault_list, l, info) {
-               if (info->handler == cb) {
-                       void *data;
-
-                       data = info->user_data;
-
-                       if (s_info.fault_state == INFO_STATE_CALLBACK_IN_PROCESSING) {
-                               info->is_deleted = 1;
-                       } else {
-                               s_info.fault_list = dlist_remove(s_info.fault_list, l);
-                               free(info);
-                       }
-
-                       return data;
-               }
-       }
-
-       return NULL;
-}
-
-EAPI int livebox_set_event_handler(int (*cb)(struct livebox *, enum livebox_event_type, void *), void *data)
-{
-       struct event_info *info;
-
-       if (!cb) {
-               ErrPrint("Invalid argument cb is nil\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       info = malloc(sizeof(*info));
-       if (!info) {
-               ErrPrint("Heap: %s\n", strerror(errno));
-               return LB_STATUS_ERROR_MEMORY;
-       }
-
-       info->handler = cb;
-       info->user_data = data;
-       info->is_deleted = 0;
-
-       s_info.event_list = dlist_append(s_info.event_list, info);
-       return LB_STATUS_SUCCESS;
-}
-
-EAPI void *livebox_unset_event_handler(int (*cb)(struct livebox *, enum livebox_event_type, void *))
-{
-       struct event_info *info;
-       struct dlist *l;
-
-       dlist_foreach(s_info.event_list, l, info) {
-               if (info->handler == cb) {
-                       void *data;
-
-                       data = info->user_data;
-
-                       if (s_info.event_state == INFO_STATE_CALLBACK_IN_PROCESSING) {
-                               info->is_deleted = 1;
-                       } else {
-                               s_info.event_list = dlist_remove(s_info.event_list, l);
-                               free(info);
-                       }
-
-                       return data;
-               }
-       }
-
-       return NULL;
-}
-
-EAPI int livebox_set_update_mode(struct livebox *handler, int active_update, ret_cb_t cb, void *data)
-{
-       struct packet *packet;
-       int ret;
-
-       if (!handler || handler->state != CREATE) {
-               ErrPrint("Handler is Invalid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!handler->common || handler->common->state != CREATE) {
-               ErrPrint("Handler is Invalid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!handler->common->id) {
-               ErrPrint("Handler is Invalid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (handler->common->request.update_mode) {
-               ErrPrint("Previous update_mode cb is not finished yet\n");
-               return LB_STATUS_ERROR_BUSY;
-       }
-
-       if (handler->common->is_active_update == active_update) {
-               return LB_STATUS_ERROR_ALREADY;
-       }
-
-       if (!handler->common->is_user) {
-               return LB_STATUS_ERROR_PERMISSION;
-       }
-
-       packet = packet_create("update_mode", "ssi", handler->common->pkgname, handler->common->id, active_update);
-       if (!packet) {
-               return LB_STATUS_ERROR_FAULT;
-       }
-
-       if (!cb) {
-               cb = default_update_mode_cb;
-       }
-
-       ret = master_rpc_async_request(handler, packet, 0, update_mode_cb, NULL);
-       if (ret == (int)LB_STATUS_SUCCESS) {
-               handler->cbs.update_mode.cb = cb;
-               handler->cbs.update_mode.data = data;
-               handler->common->request.update_mode = 1;
-       }
-
-       return ret;
-}
-
-EAPI int livebox_is_active_update(struct livebox *handler)
-{
-       if (!handler || handler->state != CREATE) {
-               ErrPrint("Handler is Invalid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!handler->common || handler->common->state != CREATE) {
-               ErrPrint("Handler is Invalid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!handler->common->id) {
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       return handler->common->is_active_update;
-}
-
-static void resize_job_cb(struct livebox *handler, int ret, void *data)
-{
-       struct cb_info *info = data;
-
-       if (info->cb) {
-               info->cb(handler, ret, info->data);
-       }
-
-       free(info);
-
-       /*!
-        * \note
-        * Forcely update the box
-        */
-       lb_invoke_event_handler(handler, LB_EVENT_LB_UPDATED);
-}
-
-EAPI int livebox_resize(struct livebox *handler, int type, ret_cb_t cb, void *data)
-{
-       struct livebox_common *common;
-       int w;
-       int h;
-       int ret;
-
-       /*!
-        * \TODO
-        * If this handle is host instance or link instance,
-        * Create a new instance or find another linkable instance.
-        */
-
-       if (!handler || handler->state != CREATE) {
-               ErrPrint("Handler is not valid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!handler->common || handler->common->state != CREATE) {
-               ErrPrint("Invalid handle\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!handler->common->id) {
-               ErrPrint("Handler is not valid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       /*!
-        * \note
-        * resize operation should be separated by each handler.
-        * If a handler is resizing, the other handler can request resize too.
-        * So we should not use the common->request.size_changed flag.
-        */
-       if (handler->cbs.size_changed.cb) {
-               ErrPrint("Previous resize request is not finished yet\n");
-               return LB_STATUS_ERROR_BUSY;
-       }
-
-       if (livebox_service_get_size(type, &w, &h) != 0) {
-               ErrPrint("Invalid size type\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (handler->common->lb.width == w && handler->common->lb.height == h) {
-               DbgPrint("No changes\n");
-               return LB_STATUS_ERROR_ALREADY;
-       }
-
-       if (!handler->common->is_user) {
-               ErrPrint("CA Livebox is not able to be resized\n");
-               return LB_STATUS_ERROR_PERMISSION;
-       }
-
-       if (handler->common->refcnt <= 1) {
-               struct packet *packet;
-
-               /* Only 1 instance */
-               packet = packet_create("resize", "ssii", handler->common->pkgname, handler->common->id, w, h);
-               if (!packet) {
-                       ErrPrint("Failed to build param\n");
-                       return LB_STATUS_ERROR_FAULT;
-               }
-
-               if (!cb) {
-                       cb = default_lb_size_changed_cb;
-               }
-
-               ret = master_rpc_async_request(handler, packet, 0, resize_cb, NULL);
-               if (ret == (int)LB_STATUS_SUCCESS) {
-                       handler->cbs.size_changed.cb = cb;
-                       handler->cbs.size_changed.data = data;
-                       handler->common->request.size_changed = 1;
-               }
-       } else {
-               common = find_sharable_common_handle(handler->common->pkgname, handler->common->content, w, h, handler->common->cluster, handler->common->category);
-               if (!common) {
-                       struct livebox_common *old_common;
-                       /*!
-                        * \note
-                        * If the common handler is in resizing,
-                        * if user tries to resize a hander, then simply create new one even if the requested size is same with this.
-
-                       if (handler->common->request.size_changed) {
-                       }
-
-                        */
-
-                       old_common = handler->common;
-
-                       common = lb_create_common_handle(handler, old_common->pkgname, old_common->cluster, old_common->category);
-                       if (!common) {
-                               ErrPrint("Failed to create common handle\n");
-                               return LB_STATUS_ERROR_FAULT;
-                       }
-
-                       lb_set_size(common, w, h);
-                       lb_set_content(common, old_common->content);
-                       lb_set_period(common, old_common->lb.period);
-
-                       /*!
-                        * \note
-                        * Disconnecting from old one.
-                        */
-                       if (lb_common_unref(old_common, handler) == 0) {
-                               /*!
-                                * \note
-                                * Impossible
-                                */
-                               ErrPrint("Common has no associated handler\n");
-                       }
-
-                       lb_common_ref(common, handler);
-
-                       /*!
-                        * Connect to a new one
-                        */
-                       handler->common = common;
-
-                       /*!
-                        * \TODO
-                        * Need to care, if it fails to create a common handle,
-                        * the resize operation will be failed.
-                        * in that case, we should reuse the old common handle
-                        */
-                       ret = create_real_instance(handler, cb, data);
-                       if (ret < 0) {
-                               lb_common_unref(common, handler);
-                               lb_destroy_common_handle(common);
-
-                               lb_common_ref(old_common, handler);
-                               handler->common = old_common;
-                       } else {
-                               /*!
-                                * In this case, we should update visibility of old_common's liveboxes
-                                */
-                               if (handler->visible == LB_SHOW) {
-                                       lb_update_visibility(old_common);
-                               }
-                       }
-               } else {
-                       struct cb_info *cbinfo;
-
-                       cbinfo = create_cb_info(cb, data);
-                       if (!cbinfo) {
-                               ErrPrint("Failed to create a cbinfo\n");
-                               ret = LB_STATUS_ERROR_MEMORY;
-                       } else {
-                               ret = job_add(handler, resize_job_cb, LB_STATUS_SUCCESS, cbinfo);
-                               if (ret == (int)LB_STATUS_SUCCESS) {
-                                       struct livebox_common *old_common;
-
-                                       old_common = handler->common;
-
-                                       if (lb_common_unref(handler->common, handler) == 0) {
-                                               ErrPrint("Old common has no associated handler\n");
-                                       }
-
-                                       lb_common_ref(common, handler);
-                                       handler->common = common;
-
-                                       if (handler->visible == LB_SHOW) {
-                                               lb_update_visibility(old_common); /* To update visibility: Show --> Paused */
-                                               lb_update_visibility(common);   /* To update visibility: Paused --> Show */
-                                       }
-                               } else {
-                                       destroy_cb_info(cbinfo);
-                               }
-                       }
-               }
-       }
-
-       return ret;
-}
-
-EAPI int livebox_click(struct livebox *handler, double x, double y)
-{
-       struct packet *packet;
-       double timestamp;
-       int ret;
-
-       if (!handler || handler->state != CREATE) {
-               ErrPrint("Handler is invalid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!handler->common || handler->common->state != CREATE) {
-               ErrPrint("Handler is invalid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!handler->common->id) {
-               ErrPrint("Handler is not valid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (handler->common->lb.auto_launch) {
-               if (s_info.launch.handler) {
-                       ret = s_info.launch.handler(handler, handler->common->lb.auto_launch, s_info.launch.data);
-                       if (ret < 0) {
-                               ErrPrint("launch handler app %s (%d)\n", handler->common->lb.auto_launch, ret);
-                       }
-               }
-       }
-
-       timestamp = util_timestamp();
-       DbgPrint("CLICKED: %lf\n", timestamp);
-
-       packet = packet_create_noack("clicked", "sssddd", handler->common->pkgname, handler->common->id, "clicked", timestamp, x, y);
-       if (!packet) {
-               ErrPrint("Failed to build param\n");
-               return LB_STATUS_ERROR_FAULT;
-       }
-
-       ret = master_rpc_request_only(handler, packet);
-
-       if (!handler->common->lb.mouse_event && (handler->common->lb.type == _LB_TYPE_BUFFER || handler->common->lb.type == _LB_TYPE_SCRIPT)) {
-               int ret; /* Shadow variable */
-               ret = send_mouse_event(handler, "lb_mouse_down", x * handler->common->lb.width, y * handler->common->lb.height);
-               if (ret < 0) {
-                       ErrPrint("Failed to send Down: %d\n", ret);
-               }
-
-               ret = send_mouse_event(handler, "lb_mouse_move", x * handler->common->lb.width, y * handler->common->lb.height);
-               if (ret < 0) {
-                       ErrPrint("Failed to send Move: %d\n", ret);
-               }
-
-               ret = send_mouse_event(handler, "lb_mouse_up", x * handler->common->lb.width, y * handler->common->lb.height);
-               if (ret < 0) {
-                       ErrPrint("Failed to send Up: %d\n", ret);
-               }
-       }
-
-       return ret;
-}
-
-EAPI int livebox_has_pd(struct livebox *handler)
-{
-       if (!handler || handler->state != CREATE) {
-               ErrPrint("Handler is invalid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!handler->common || handler->common->state != CREATE) {
-               ErrPrint("Handler is invalid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!handler->common->id) {
-               ErrPrint("Handler is not valid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       return !!handler->common->pd.fb;
-}
-
-EAPI int livebox_pd_is_created(struct livebox *handler)
-{
-       if (!handler || handler->state != CREATE) {
-               ErrPrint("Handler is invalid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!handler->common || handler->common->state != CREATE) {
-               ErrPrint("Handler is invalid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!handler->common->pd.fb || !handler->common->id) {
-               ErrPrint("Handler is not valid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       return handler->common->is_pd_created;
-}
-
-EAPI int livebox_create_pd(struct livebox *handler, ret_cb_t cb, void *data)
-{
-       return livebox_create_pd_with_position(handler, -1.0, -1.0, cb, data);
-}
-
-static void turn_off_pd_destroyed_flag_cb(struct livebox *handler, int ret, void *data)
-{
-       if (handler->common->request.pd_destroyed) {
-               ret_cb_t cb;
-               void *data;
-
-               DbgPrint("pd_destroyed request is canceled\n");
-               handler->common->request.pd_destroyed = 0;
-               cb = handler->cbs.pd_destroyed.cb;
-               data = handler->cbs.pd_destroyed.data;
-               handler->cbs.pd_destroyed.cb = NULL;
-               handler->cbs.pd_destroyed.data = NULL;
-
-               if (cb) {
-                       cb(handler, ret, data);
-               }
-       }
-}
-
-EAPI int livebox_create_pd_with_position(struct livebox *handler, double x, double y, ret_cb_t cb, void *data)
-{
-       struct packet *packet;
-       int ret;
-
-       if (!handler || handler->state != CREATE) {
-               ErrPrint("Handler is invalid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!handler->common || handler->common->state != CREATE) {
-               ErrPrint("Handler is invalid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!handler->common->pd.fb || !handler->common->id) {
-               ErrPrint("Handler is not valid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       /*!
-        * \note
-        * Only one handler can have a PD
-        */
-       if (handler->common->is_pd_created) {
-               DbgPrint("PD is already created\n");
-               return LB_STATUS_SUCCESS;
-       }
-
-       if (handler->common->request.pd_created) {
-               ErrPrint("Previous request is not completed yet\n");
-               return LB_STATUS_ERROR_BUSY;
-       }
-
-       /*!
-        * \note
-        * Turn off the pd_destroyed request flag
-        */
-       if (handler->common->request.pd_destroyed) {
-               if (job_add(handler, turn_off_pd_destroyed_flag_cb, LB_STATUS_ERROR_CANCEL, NULL) < 0) {
-                       ErrPrint("Failed to add pd_destroyed job\n");
-               }
-       }
-
-       packet = packet_create("create_pd", "ssdd", handler->common->pkgname, handler->common->id, x, y);
-       if (!packet) {
-               ErrPrint("Failed to build param\n");
-               return LB_STATUS_ERROR_FAULT;
-       }
-
-       if (!cb) {
-               cb = default_pd_created_cb;
-       }
-
-       DbgPrint("PERF_DBOX\n");
-       ret = master_rpc_async_request(handler, packet, 0, pd_create_cb, NULL);
-       if (ret == (int)LB_STATUS_SUCCESS) {
-               handler->cbs.pd_created.cb = cb;
-               handler->cbs.pd_created.data = data;
-               handler->common->request.pd_created = 1;
-       }
-
-       return ret;
-}
-
-EAPI int livebox_move_pd(struct livebox *handler, double x, double y)
-{
-       struct packet *packet;
-
-       if (!handler || handler->state != CREATE) {
-               ErrPrint("Handler is invalid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!handler->common || handler->common->state != CREATE) {
-               ErrPrint("Handler is invalid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!handler->common->pd.fb || !handler->common->id) {
-               ErrPrint("Handler is not valid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!handler->common->is_pd_created) {
-               ErrPrint("PD is not created\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       packet = packet_create_noack("pd_move", "ssdd", handler->common->pkgname, handler->common->id, x, y);
-       if (!packet) {
-               ErrPrint("Failed to build param\n");
-               return LB_STATUS_ERROR_FAULT;
-       }
-
-       return master_rpc_request_only(handler, packet);
-}
-
-EAPI int livebox_activate(const char *pkgname, ret_cb_t cb, void *data)
-{
-       struct packet *packet;
-       struct cb_info *cbinfo;
-       int ret;
-
-       if (!pkgname) {
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       packet = packet_create("activate_package", "s", pkgname);
-       if (!packet) {
-               ErrPrint("Failed to build a param\n");
-               return LB_STATUS_ERROR_FAULT;
-       }
-
-       cbinfo = create_cb_info(cb, data);
-       if (!cbinfo) {
-               ErrPrint("Unable to create cbinfo\n");
-               packet_destroy(packet);
-               return LB_STATUS_ERROR_FAULT;
-       }
-
-       ret = master_rpc_async_request(NULL, packet, 0, activated_cb, cbinfo);
-       if (ret < 0) {
-               destroy_cb_info(cbinfo);
-       }
-
-       return ret;
-}
-
-static void turn_off_pd_created_flag_cb(struct livebox *handler, int ret, void *data)
-{
-       if (handler->common->request.pd_created) {
-               ret_cb_t cb;
-               void *data;
-
-               DbgPrint("pd_created request is canceled\n");
-               handler->common->request.pd_created = 0;
-               cb = handler->cbs.pd_created.cb;
-               data = handler->cbs.pd_created.data;
-               handler->cbs.pd_created.cb = NULL;
-               handler->cbs.pd_created.data = NULL;
-
-               if (cb) {
-                       cb(handler, ret, data);
-               }
-       }
-}
-
-EAPI int livebox_destroy_pd(struct livebox *handler, ret_cb_t cb, void *data)
-{
-       struct packet *packet;
-       struct cb_info *cbinfo;
-       int ret;
-
-       if (!handler || handler->state != CREATE) {
-               ErrPrint("Handler is invalid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!handler->common || handler->common->state != CREATE) {
-               ErrPrint("Handler is invalid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!handler->common->pd.fb || !handler->common->id) {
-               ErrPrint("Handler is not valid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       /*!
-        * \FIXME
-        * Replace the callback check code.
-        * Use the flag instead of callback.
-        * the flag should be in the ADT "common"
-        */
-       if (!handler->common->is_pd_created && !handler->common->request.pd_created) {
-               ErrPrint("PD is not created\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (handler->common->request.pd_destroyed) {
-               ErrPrint("PD destroy request is already sent\n");
-               return LB_STATUS_ERROR_ALREADY;
-       }
-
-       /*!
-        * \note
-        * Disable the pd_created request flag
-        */
-       if (handler->common->request.pd_created) {
-               if (job_add(handler, turn_off_pd_created_flag_cb, LB_STATUS_ERROR_CANCEL, NULL) < 0) {
-                       ErrPrint("Failed to add a new job\n");
-               }
-       }
-
-       DbgPrint("[%s]\n", handler->common->pkgname);
-
-       packet = packet_create("destroy_pd", "ss", handler->common->pkgname, handler->common->id);
-       if (!packet) {
-               ErrPrint("Failed to build a param\n");
-               return LB_STATUS_ERROR_FAULT;
-       }
-
-       if (!cb) {
-               cb = default_pd_destroyed_cb;
-       }
-
-       cbinfo = create_cb_info(cb, data);
-       if (!cbinfo) {
-               packet_destroy(packet);
-               return LB_STATUS_ERROR_FAULT;
-       }
-
-       ret = master_rpc_async_request(handler, packet, 0, pd_destroy_cb, cbinfo);
-       if (ret < 0) {
-               destroy_cb_info(cbinfo);
-       } else {
-               handler->common->request.pd_destroyed = 1;
-       }
-
-       return ret;
-}
-
-EAPI int livebox_access_event(struct livebox *handler, enum access_event_type type, double x, double y, ret_cb_t cb, void *data)
-{
-       int w = 1;
-       int h = 1;
-       char cmd[32] = { '\0', };
-       char *ptr = cmd;
-       int ret = 0;    /* re-used for sending event type */
-
-       if (!handler || handler->state != CREATE) {
-               ErrPrint("Handler is invalid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!handler->common || handler->common->state != CREATE) {
-               ErrPrint("Handler is invalid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!handler->common->id) {
-               ErrPrint("Handler is not valid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (handler->common->request.access_event) {
-               ErrPrint("Previous access event is not yet done\n");
-               return LB_STATUS_ERROR_BUSY;
-       }
-
-       if (type & ACCESS_EVENT_PD_MASK) {
-               if (!handler->common->is_pd_created) {
-                       ErrPrint("PD is not created\n");
-                       return LB_STATUS_ERROR_INVALID;
-               }
-               *ptr++ = 'p';
-               *ptr++ = 'd';
-               w = handler->common->pd.width;
-               h = handler->common->pd.height;
-       } else if (type & ACCESS_EVENT_LB_MASK) {
-               *ptr++ = 'l';
-               *ptr++ = 'b';
-               w = handler->common->lb.width;
-               h = handler->common->lb.height;
-       } else {
-               ErrPrint("Invalid event type\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       switch (type & ~(ACCESS_EVENT_PD_MASK | ACCESS_EVENT_LB_MASK)) {
-       case ACCESS_EVENT_HIGHLIGHT:
-               strcpy(ptr, "_access_hl");
-               ret = ACCESS_TYPE_CUR;
-               break;
-       case ACCESS_EVENT_HIGHLIGHT_NEXT:
-               strcpy(ptr, "_access_hl");
-               ret = ACCESS_TYPE_NEXT;
-               break;
-       case ACCESS_EVENT_HIGHLIGHT_PREV:
-               strcpy(ptr, "_access_hl");
-               ret = ACCESS_TYPE_PREV;
-               break;
-       case ACCESS_EVENT_UNHIGHLIGHT:
-               strcpy(ptr, "_access_hl");
-               ret = ACCESS_TYPE_OFF;
-               break;
-       case ACCESS_EVENT_ACTIVATE:
-               strcpy(ptr, "_access_activate");
-               break;
-       case ACCESS_EVENT_ACTION_DOWN:
-               strcpy(ptr, "_access_action");
-               ret = ACCESS_TYPE_DOWN;
-               break;
-       case ACCESS_EVENT_ACTION_UP:
-               strcpy(ptr, "_access_action");
-               ret = ACCESS_TYPE_UP;
-               break;
-       case ACCESS_EVENT_SCROLL_DOWN:
-               strcpy(ptr, "_access_scroll");
-               ret = ACCESS_TYPE_DOWN;
-               break;
-       case ACCESS_EVENT_SCROLL_MOVE:
-               strcpy(ptr, "_access_scroll");
-               ret = ACCESS_TYPE_MOVE;
-               break;
-       case ACCESS_EVENT_SCROLL_UP:
-               strcpy(ptr, "_access_scroll");
-               ret = ACCESS_TYPE_UP;
-               break;
-       case ACCESS_EVENT_VALUE_CHANGE:
-               strcpy(ptr, "_access_value_change");
-               break;
-       case ACCESS_EVENT_MOUSE:
-               strcpy(ptr, "_access_mouse");
-               break;
-       case ACCESS_EVENT_BACK:
-               strcpy(ptr, "_access_back");
-               break;
-       case ACCESS_EVENT_OVER:
-               strcpy(ptr, "_access_over");
-               break;
-       case ACCESS_EVENT_READ:
-               strcpy(ptr, "_access_read");
-               break;
-       case ACCESS_EVENT_ENABLE:
-               strcpy(ptr, "_access_enable");
-               ret = 1;
-               break;
-       case ACCESS_EVENT_DISABLE:
-               strcpy(ptr, "_access_enable");
-               ret = 0;
-               break;
-       default:
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!cb) {
-               cb = default_access_event_cb;
-       }
-
-       ret = send_access_event(handler, cmd, x * w, y * h, ret);
-       if (ret == (int)LB_STATUS_SUCCESS) {
-               handler->cbs.access_event.cb = cb;
-               handler->cbs.access_event.data = data;
-               handler->common->request.access_event = 1;
-       }
-
-       return ret;
-}
-
-EAPI int livebox_mouse_event(struct livebox *handler, enum content_event_type type, double x, double y)
-{
-       int w = 1;
-       int h = 1;
-       char cmd[32] = { '\0', };
-       char *ptr = cmd;
-
-       if (!handler || handler->state != CREATE) {
-               ErrPrint("Handler is invalid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!handler->common || handler->common->state != CREATE) {
-               ErrPrint("Handler is invalid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!handler->common->id) {
-               ErrPrint("Handler is not valid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!(type & CONTENT_EVENT_MOUSE_MASK)) {
-               ErrPrint("Invalid content event is used\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (type & CONTENT_EVENT_PD_MASK) {
-               int flag = 1;
-
-               if (!handler->common->is_pd_created) {
-                       ErrPrint("PD is not created\n");
-                       return LB_STATUS_ERROR_INVALID;
-               }
-
-               if (!handler->common->pd.fb) {
-                       ErrPrint("Handler is not valid\n");
-                       return LB_STATUS_ERROR_INVALID;
-               }
-
-               if (type & CONTENT_EVENT_MOUSE_MOVE) {
-                       if (fabs(x - handler->common->pd.x) < conf_event_filter() && fabs(y - handler->common->pd.y) < conf_event_filter()) {
-                               return LB_STATUS_ERROR_BUSY;
-                       }
-               } else if (type & CONTENT_EVENT_MOUSE_SET) {
-                       flag = 0;
-               }
-
-               if (flag) {
-                       w = handler->common->pd.width;
-                       h = handler->common->pd.height;
-                       handler->common->pd.x = x;
-                       handler->common->pd.y = y;
-               }
-               *ptr++ = 'p';
-               *ptr++ = 'd';
-       } else if (type & CONTENT_EVENT_LB_MASK) {
-               int flag = 1;
-
-               if (!handler->common->lb.mouse_event) {
-                       return LB_STATUS_ERROR_INVALID;
-               }
-
-               if (!handler->common->lb.fb) {
-                       ErrPrint("Handler is not valid\n");
-                       return LB_STATUS_ERROR_INVALID;
-               }
-
-               if (type & CONTENT_EVENT_MOUSE_MOVE) {
-                       if (fabs(x - handler->common->lb.x) < conf_event_filter() && fabs(y - handler->common->lb.y) < conf_event_filter()) {
-                               return LB_STATUS_ERROR_BUSY;
-                       }
-               } else if (type & CONTENT_EVENT_MOUSE_SET) {
-                       flag = 0;
-               }
-
-               if (flag) {
-                       w = handler->common->lb.width;
-                       h = handler->common->lb.height;
-                       handler->common->lb.x = x;
-                       handler->common->lb.y = y;
-               }
-               *ptr++ = 'l';
-               *ptr++ = 'b';
-       } else {
-               ErrPrint("Invalid event type\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       /*!
-        * Must be shorter than 29 bytes.
-        */
-       switch ((type & ~(CONTENT_EVENT_PD_MASK | CONTENT_EVENT_LB_MASK))) {
-       case CONTENT_EVENT_MOUSE_ENTER | CONTENT_EVENT_MOUSE_MASK:
-               strcpy(ptr, "_mouse_enter");
-               break;
-       case CONTENT_EVENT_MOUSE_LEAVE | CONTENT_EVENT_MOUSE_MASK:
-               strcpy(ptr, "_mouse_leave");
-               break;
-       case CONTENT_EVENT_MOUSE_UP | CONTENT_EVENT_MOUSE_MASK:
-               strcpy(ptr, "_mouse_up");
-               break;
-       case CONTENT_EVENT_MOUSE_DOWN | CONTENT_EVENT_MOUSE_MASK:
-               strcpy(ptr, "_mouse_down");
-               break;
-       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_ON_SCROLL | CONTENT_EVENT_MOUSE_MASK:
-               strcpy(ptr, "_mouse_on_scroll");
-               break;
-       case CONTENT_EVENT_ON_HOLD | CONTENT_EVENT_MOUSE_MASK:
-               strcpy(ptr, "_mouse_on_hold");
-               break;
-       case CONTENT_EVENT_OFF_SCROLL | CONTENT_EVENT_MOUSE_MASK:
-               strcpy(ptr, "_mouse_off_scroll");
-               break;
-       case CONTENT_EVENT_OFF_HOLD | CONTENT_EVENT_MOUSE_MASK:
-               strcpy(ptr, "_mouse_off_hold");
-               break;
-       default:
-               ErrPrint("Invalid event type\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       return send_mouse_event(handler, cmd, x * w, y * h);
-}
-
-EAPI int livebox_key_event(struct livebox *handler, enum content_event_type type, unsigned int keycode, ret_cb_t cb, void *data)
-{
-       char cmd[32] = { '\0', };
-       char *ptr = cmd;
-       int ret;
-
-       if (!handler || handler->state != CREATE) {
-               ErrPrint("Handler is invalid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!handler->common || handler->common->state != CREATE) {
-               ErrPrint("Handler is invalid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!handler->common->id) {
-               ErrPrint("Handler is not valid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!(type & CONTENT_EVENT_KEY_MASK)) {
-               ErrPrint("Invalid key event is used\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (handler->common->request.key_event) {
-               ErrPrint("Previous key event is not completed yet\n");
-               return LB_STATUS_ERROR_BUSY;
-       }
-
-       if (type & CONTENT_EVENT_PD_MASK) {
-               if (!handler->common->is_pd_created) {
-                       ErrPrint("PD is not created\n");
-                       return LB_STATUS_ERROR_INVALID;
-               }
-
-               if (!handler->common->pd.fb) {
-                       ErrPrint("Handler is not valid\n");
-                       return LB_STATUS_ERROR_INVALID;
-               }
-
-               if (type & CONTENT_EVENT_KEY_DOWN) {
-                       /*!
-                        * \TODO
-                        * filtering the reproduced events if it is too fast
-                        */
-               } else if (type & CONTENT_EVENT_KEY_SET) {
-                       /*!
-                        * \TODO
-                        * What can I do for this case?
-                        */
-               }
-
-               *ptr++ = 'p';
-               *ptr++ = 'd';
-       } else if (type & CONTENT_EVENT_LB_MASK) {
-               if (!handler->common->lb.mouse_event) {
-                       return LB_STATUS_ERROR_INVALID;
-               }
-
-               if (!handler->common->lb.fb) {
-                       ErrPrint("Handler is not valid\n");
-                       return LB_STATUS_ERROR_INVALID;
-               }
-
-               if (type & CONTENT_EVENT_KEY_DOWN) {
-                       /*!
-                        * \TODO
-                        * filtering the reproduced events if it is too fast
-                        */
-               } else if (type & CONTENT_EVENT_KEY_SET) {
-                       /*!
-                        * What can I do for this case?
-                        */
-               }
-
-               *ptr++ = 'l';
-               *ptr++ = 'b';
-       } else {
-               ErrPrint("Invalid event type\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       /*!
-        * Must be short than 29 bytes.
-        */
-       switch ((type & ~(CONTENT_EVENT_PD_MASK | CONTENT_EVENT_LB_MASK))) {
-       case CONTENT_EVENT_KEY_FOCUS_IN | CONTENT_EVENT_KEY_MASK:
-               strcpy(ptr, "_key_focus_in");
-               break;
-       case CONTENT_EVENT_KEY_FOCUS_OUT | CONTENT_EVENT_KEY_MASK:
-               strcpy(ptr, "_key_focus_out");
-               break;
-       case CONTENT_EVENT_KEY_UP | CONTENT_EVENT_KEY_MASK:
-               strcpy(ptr, "_key_up");
-               break;
-       case CONTENT_EVENT_KEY_DOWN | CONTENT_EVENT_KEY_MASK:
-               strcpy(ptr, "_key_down");
-               break;
-       case CONTENT_EVENT_KEY_SET | CONTENT_EVENT_KEY_MASK:
-               strcpy(ptr, "_key_set");
-               break;
-       case CONTENT_EVENT_KEY_UNSET | CONTENT_EVENT_KEY_MASK:
-               strcpy(ptr, "_key_unset");
-               break;
-       default:
-               ErrPrint("Invalid event type\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!cb) {
-               cb = default_key_event_cb;
-       }
-
-       ret = send_key_event(handler, cmd, keycode);
-       if (ret == (int)LB_STATUS_SUCCESS) {
-               handler->cbs.key_event.cb = cb;
-               handler->cbs.key_event.data = data;
-               handler->common->request.key_event = 1;
-       }
-
-       return ret;
-}
-
-EAPI const char *livebox_filename(struct livebox *handler)
-{
-       if (!handler || handler->state != CREATE) {
-               ErrPrint("Handler is invalid\n");
-               return NULL;
-       }
-
-       if (!handler->common || handler->common->state != CREATE) {
-               ErrPrint("Handler is invalid\n");
-               return NULL;
-       }
-
-       if (!handler->common->id) {
-               ErrPrint("Handler is not valid\n");
-               return NULL;
-       }
-
-       if (handler->common->filename) {
-               return handler->common->filename;
-       }
-
-       /* Oooops */
-       return util_uri_to_path(handler->common->id);
-}
-
-EAPI int livebox_get_pdsize(struct livebox *handler, int *w, int *h)
-{
-       int _w;
-       int _h;
-
-       if (!handler || handler->state != CREATE) {
-               ErrPrint("Handler is invalid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!handler->common || handler->common->state != CREATE) {
-               ErrPrint("Handler is invalid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!handler->common->id) {
-               ErrPrint("Handler is not valid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!w) {
-               w = &_w;
-       }
-       if (!h) {
-               h = &_h;
-       }
-
-       if (!handler->common->is_pd_created) {
-               *w = handler->common->pd.default_width;
-               *h = handler->common->pd.default_height;
-       } else {
-               *w = handler->common->pd.width;
-               *h = handler->common->pd.height;
-       }
-
-       return LB_STATUS_SUCCESS;
-}
-
-EAPI int livebox_size(struct livebox *handler)
-{
-       int w;
-       int h;
-
-       if (!handler || handler->state != CREATE) {
-               ErrPrint("Handler is invalid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!handler->common || handler->common->state != CREATE) {
-               ErrPrint("Handler is invalid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!handler->common->id) {
-               ErrPrint("Handler is not valid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       w = handler->common->lb.width;
-       h = handler->common->lb.height;
-
-       switch (handler->common->lb.type) {
-       case _LB_TYPE_BUFFER:
-       case _LB_TYPE_SCRIPT:
-               if (!fb_is_created(handler->common->lb.fb)) {
-                       w = 0;
-                       h = 0;
-               }
-               break;
-       default:
-               break;
-       }
-
-       return livebox_service_size_type(w, h);
-}
-
-EAPI int livebox_set_group(struct livebox *handler, const char *cluster, const char *category, ret_cb_t cb, void *data)
-{
-       struct packet *packet;
-       int ret;
-
-       if (!handler) {
-               ErrPrint("Handler is NIL\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!cluster || !category || handler->state != CREATE) {
-               ErrPrint("Invalid argument\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!handler->common || handler->common->state != CREATE) {
-               ErrPrint("Invalid argument\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!handler->common->id) {
-               ErrPrint("Invalid argument\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (handler->common->request.group_changed) {
-               ErrPrint("Previous group changing request is not finished yet\n");
-               return LB_STATUS_ERROR_BUSY;
-       }
-
-       if (!handler->common->is_user) {
-               ErrPrint("CA Livebox is not able to change the group\n");
-               return LB_STATUS_ERROR_PERMISSION;
-       }
-
-       if (!strcmp(handler->common->cluster, cluster) && !strcmp(handler->common->category, category)) {
-               DbgPrint("No changes\n");
-               return LB_STATUS_ERROR_ALREADY;
-       }
-
-       packet = packet_create("change_group", "ssss", handler->common->pkgname, handler->common->id, cluster, category);
-       if (!packet) {
-               ErrPrint("Failed to build a param\n");
-               return LB_STATUS_ERROR_FAULT;
-       }
-
-       if (!cb) {
-               cb = default_group_changed_cb;
-       }
-
-       ret = master_rpc_async_request(handler, packet, 0, set_group_ret_cb, NULL);
-       if (ret == (int)LB_STATUS_SUCCESS) {
-               handler->cbs.group_changed.cb = cb;
-               handler->cbs.group_changed.data = data; 
-               handler->common->request.group_changed = 1;
-       }
-
-       return ret;
-}
-
-EAPI int livebox_get_group(struct livebox *handler, const char **cluster, const char **category)
-{
-       if (!handler) {
-               ErrPrint("Handler is NIL\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!cluster || !category || handler->state != CREATE) {
-               ErrPrint("Invalid argument\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!handler->common || handler->common->state != CREATE) {
-               ErrPrint("Invalid argument\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!handler->common->id) {
-               ErrPrint("Invalid argument\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       *cluster = handler->common->cluster;
-       *category = handler->common->category;
-       return LB_STATUS_SUCCESS;
-}
-
-EAPI int livebox_get_supported_sizes(struct livebox *handler, int *cnt, int *size_list)
-{
-       register int i;
-       register int j;
-
-       if (!handler || !size_list) {
-               ErrPrint("Invalid argument, handler(%p), size_list(%p)\n", handler, size_list);
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!cnt || handler->state != CREATE) {
-               ErrPrint("Handler is not valid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!handler->common || handler->common->state != CREATE) {
-               ErrPrint("Handler is not valid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!handler->common->id) {
-               ErrPrint("Handler is not valid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       for (j = i = 0; i < NR_OF_SIZE_LIST; i++) {
-               if (handler->common->lb.size_list & (0x01 << i)) {
-                       if (j == *cnt) {
-                               break;
-                       }
-
-                       size_list[j++] = (0x01 << i);
-               }
-       }
-
-       *cnt = j;
-       return LB_STATUS_SUCCESS;
-}
-
-EAPI const char *livebox_pkgname(struct livebox *handler)
-{
-       if (!handler) {
-               ErrPrint("Handler is NIL\n");
-               return NULL;
-       }
-
-       if (handler->state != CREATE) {
-               ErrPrint("Handler is not valid\n");
-               return NULL;
-       }
-
-       if (!handler->common || handler->common->state != CREATE) {
-               ErrPrint("Handler is not valid\n");
-               return NULL;
-       }
-
-       return handler->common->pkgname;
-}
-
-EAPI double livebox_priority(struct livebox *handler)
-{
-       if (!handler || handler->state != CREATE) {
-               ErrPrint("Handler is invalid\n");
-               return -1.0f;
-       }
-
-       if (!handler->common || handler->common->state != CREATE) {
-               ErrPrint("Handler is invalid\n");
-               return -1.0f;
-       }
-
-       if (!handler->common->id) {
-               ErrPrint("Handler is not valid (%p)\n", handler);
-               return -1.0f;
-       }
-
-       return handler->common->lb.priority;
-}
-
-EAPI int livebox_delete_cluster(const char *cluster, ret_cb_t cb, void *data)
-{
-       struct packet *packet;
-       struct cb_info *cbinfo;
-       int ret;
-
-       packet = packet_create("delete_cluster", "s", cluster);
-       if (!packet) {
-               ErrPrint("Failed to build a param\n");
-               return LB_STATUS_ERROR_FAULT;
-       }
-
-       cbinfo = create_cb_info(cb, data);
-       if (!cbinfo) {
-               packet_destroy(packet);
-               return LB_STATUS_ERROR_FAULT;
-       }
-
-       ret = master_rpc_async_request(NULL, packet, 0, delete_cluster_cb, cbinfo);
-       if (ret < 0) {
-               destroy_cb_info(cbinfo);
-       }
-
-       return ret;
-}
-
-EAPI int livebox_delete_category(const char *cluster, const char *category, ret_cb_t cb, void *data)
-{
-       struct packet *packet;
-       struct cb_info *cbinfo;
-       int ret;
-
-       packet = packet_create("delete_category", "ss", cluster, category);
-       if (!packet) {
-               ErrPrint("Failed to build a param\n");
-               return LB_STATUS_ERROR_FAULT;
-       }
-
-       cbinfo = create_cb_info(cb, data);
-       if (!cbinfo) {
-               packet_destroy(packet);
-               return LB_STATUS_ERROR_FAULT;
-       }
-
-       ret = master_rpc_async_request(NULL, packet, 0, delete_category_cb, cbinfo);
-       if (ret < 0) {
-               destroy_cb_info(cbinfo);
-       }
-
-       return ret;
-}
-
-EAPI enum livebox_lb_type livebox_lb_type(struct livebox *handler)
-{
-       if (!handler || handler->state != CREATE) {
-               ErrPrint("Handler is invalid\n");
-               return LB_TYPE_INVALID;
-       }
-
-       if (!handler->common || handler->common->state != CREATE) {
-               ErrPrint("Handler is invalid\n");
-               return LB_TYPE_INVALID;
-       }
-
-       if (!handler->common->id) {
-               ErrPrint("Handler is not valid\n");
-               return LB_TYPE_INVALID;
-       }
-
-       switch (handler->common->lb.type) {
-       case _LB_TYPE_FILE:
-               return LB_TYPE_IMAGE;
-       case _LB_TYPE_BUFFER:
-       case _LB_TYPE_SCRIPT:
-               {
-                       const char *id;
-                       id = fb_id(handler->common->lb.fb);
-                       if (id && !strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP))) {
-                               return LB_TYPE_PIXMAP;
-                       }
-               }
-               return LB_TYPE_BUFFER;
-       case _LB_TYPE_TEXT:
-               return LB_TYPE_TEXT;
-       case _LB_TYPE_ELEMENTARY:
-               return LB_TYPE_ELEMENTARY;
-       default:
-               break;
-       }
-
-       return LB_TYPE_INVALID;
-}
-
-EAPI enum livebox_pd_type livebox_pd_type(struct livebox *handler)
-{
-       if (!handler || handler->state != CREATE) {
-               ErrPrint("Handler is invalid\n");
-               return PD_TYPE_INVALID;
-       }
-
-       if (!handler->common || handler->common->state != CREATE) {
-               ErrPrint("Handler is invalid\n");
-               return PD_TYPE_INVALID;
-       }
-
-       if (!handler->common->id) {
-               ErrPrint("Handler is not valid\n");
-               return PD_TYPE_INVALID;
-       }
-
-       switch (handler->common->pd.type) {
-       case _PD_TYPE_TEXT:
-               return PD_TYPE_TEXT;
-       case _PD_TYPE_BUFFER:
-       case _PD_TYPE_SCRIPT:
-               {
-                       const char *id;
-                       id = fb_id(handler->common->pd.fb);
-                       if (id && !strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP))) {
-                               return PD_TYPE_PIXMAP;
-                       }
-               }
-               return PD_TYPE_BUFFER;
-       case _PD_TYPE_ELEMENTARY:
-               return PD_TYPE_ELEMENTARY;
-       default:
-               break;
-       }
-
-       return PD_TYPE_INVALID;
-}
-
-EAPI int livebox_set_pd_text_handler(struct livebox *handler, struct livebox_script_operators *ops)
-{
-       if (!handler) {
-               ErrPrint("Handler is NIL\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (handler->state != CREATE) {
-               ErrPrint("Handler is not valid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       memcpy(&handler->cbs.pd_ops, ops, sizeof(*ops));
-       return LB_STATUS_SUCCESS;
-}
-
-EAPI int livebox_set_text_handler(struct livebox *handler, struct livebox_script_operators *ops)
-{
-       if (!handler) {
-               ErrPrint("Handler is NIL\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (handler->state != CREATE) {
-               ErrPrint("Handler is not valid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       memcpy(&handler->cbs.lb_ops, ops, sizeof(*ops));
-       return LB_STATUS_SUCCESS;
-}
-
-EAPI int livebox_acquire_lb_pixmap(struct livebox *handler, ret_cb_t cb, void *data)
-{
-       if (!handler || handler->state != CREATE) {
-               ErrPrint("Handler is invalid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!handler->common || handler->common->state != CREATE) {
-               ErrPrint("Handler is invalid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!handler->common->id) {
-               ErrPrint("Invalid handle\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (handler->common->lb.type != _LB_TYPE_SCRIPT && handler->common->lb.type != _LB_TYPE_BUFFER) {
-               ErrPrint("Handler is not valid type\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       return lb_acquire_lb_pixmap(handler, cb, data);
-}
-
-/*!
- * \note
- * Do not check the state of handler and common-handler.
- * If this function is used in the deleted callback,
- * the handler and common-handler's state would be DELETE
- * if this function check the state of handles,
- * user cannot release the pixmap.
- */
-EAPI int livebox_release_lb_pixmap(struct livebox *handler, int pixmap)
-{
-       struct packet *packet;
-       const char *pkgname;
-       const char *id;
-
-       if (pixmap == 0 /* || handler->state != CREATE */ ) {
-               ErrPrint("Handler is invalid [%d]\n", pixmap);
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!handler) {
-               /*!
-                * \note
-                * Even though the handler is NULL, we should send the release request to the master.
-                * Because the pixmap resource can be released after the handler is destroyed.
-                * Pixmap resource is used by client. and it cannot be guaranteed to release pixmap.
-                * In some cases, the pixmap can be released after the handler is deleted.
-                *
-                * Its implementation is up to the viewer app.
-                * But we cannot force it to use only with valid handler.
-                */
-               DbgPrint("Using NULL handler\n");
-               pkgname = NULL;
-               id = NULL;
-               /*!
-                * \note
-                * Master will try to find the buffer handler using given pixmap. if the pkgname and id is not valid.
-                */
-       } else {
-               if (!handler->common /* || handler->common->state != CREATE */) {
-                       ErrPrint("Handler is invalid\n");
-                       return LB_STATUS_ERROR_INVALID;
-               }
-
-               if (!handler->common->id) {
-                       ErrPrint("Invalid handle\n");
-                       return LB_STATUS_ERROR_INVALID;
-               }
-
-               if (handler->common->lb.type != _LB_TYPE_SCRIPT && handler->common->lb.type != _LB_TYPE_BUFFER) {
-                       ErrPrint("Handler is not valid type\n");
-                       return LB_STATUS_ERROR_INVALID;
-               }
-
-               pkgname = handler->common->pkgname;
-               id = handler->common->id;
-       }
-
-       packet = packet_create_noack("lb_release_pixmap", "ssi", pkgname, id, pixmap);
-       if (!packet) {
-               ErrPrint("Failed to build a param\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       return master_rpc_request_only(handler, packet);
-}
-
-EAPI int livebox_acquire_pd_pixmap(struct livebox *handler, ret_cb_t cb, void *data)
-{
-       if (!handler || handler->state != CREATE) {
-               ErrPrint("Handler is invalid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!handler->common || handler->common->state != CREATE) {
-               ErrPrint("Handler is invalid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!handler->common->id) {
-               ErrPrint("Invalid handle\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (handler->common->pd.type != _PD_TYPE_SCRIPT && handler->common->pd.type != _PD_TYPE_BUFFER) {
-               ErrPrint("Handler is not valid type\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       return lb_acquire_pd_pixmap(handler, cb, data);
-}
-
-EAPI int livebox_pd_pixmap(const struct livebox *handler)
-{
-       const char *id;
-       int pixmap = 0;
-
-       if (!handler || handler->state != CREATE) {
-               ErrPrint("Handler is invalid\n");
-               return 0;
-       }
-
-       if (!handler->common || handler->common->state != CREATE) {
-               ErrPrint("Handler is invalid\n");
-               return 0;
-       }
-
-       if (!handler->common->id) {
-               ErrPrint("Invalid handler\n");
-               return 0;
-       }
-
-       if (handler->common->pd.type != _PD_TYPE_SCRIPT && handler->common->pd.type != _PD_TYPE_BUFFER) {
-               ErrPrint("Invalid handler\n");
-               return 0;
-       }
-
-       id = fb_id(handler->common->pd.fb);
-       if (id && sscanf(id, SCHEMA_PIXMAP "%u", (unsigned int *)&pixmap) != 1) {
-               ErrPrint("PIXMAP Id is not valid\n");
-               return 0;
-       }
-
-       return pixmap;
-}
-
-EAPI int livebox_lb_pixmap(const struct livebox *handler)
-{
-       const char *id;
-       int pixmap = 0;
-
-       if (!handler || handler->state != CREATE) {
-               ErrPrint("Handler is invalid\n");
-               return 0;
-       }
-
-       if (!handler->common || handler->common->state != CREATE) {
-               ErrPrint("Handler is invalid\n");
-               return 0;
-       }
-
-       if (!handler->common->id) {
-               ErrPrint("Invalid handler\n");
-               return 0;
-       }
-
-       if (handler->common->lb.type != _LB_TYPE_SCRIPT && handler->common->lb.type != _LB_TYPE_BUFFER) {
-               ErrPrint("Invalid handler\n");
-               return 0;
-       }
-
-       id = fb_id(handler->common->lb.fb);
-       if (id && sscanf(id, SCHEMA_PIXMAP "%u", (unsigned int *)&pixmap) != 1) {
-               ErrPrint("PIXMAP Id is not valid\n");
-               return 0;
-       }
-
-       return pixmap;
-}
-
-/*!
- * \note
- * Do not check the state of handler and common-handler.
- * If this function is used in the deleted callback,
- * the handler and common-handler's state would be DELETE
- * if this function check the state of handles,
- * user cannot release the pixmap.
- */
-EAPI int livebox_release_pd_pixmap(struct livebox *handler, int pixmap)
-{
-       struct packet *packet;
-       const char *pkgname;
-       const char *id;
-
-       if (pixmap == 0 /* || handler->state != CREATE */) {
-               ErrPrint("Pixmap is invalid [%d]\n", pixmap);
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!handler) {
-               /*!
-                * \note
-                * Even though the handler is NULL, we should send the release request to the master.
-                * Because the pixmap resource can be released after the handler is destroyed.
-                * Pixmap resource is used by client. and it cannot be guaranteed to release pixmap.
-                * In some cases, the pixmap can be released after the handler is deleted.
-                *
-                * Its implementation is up to the viewer app.
-                * But we cannot force it to use only with valid handler.
-                */
-               DbgPrint("Using NULL handler\n");
-               pkgname = NULL;
-               id = NULL;
-               /*!
-                * \note
-                * Master will try to find the buffer handler using given pixmap. if the pkgname and id is not valid.
-                */
-       } else {
-               if (!handler->common /* || handler-common->state != CREATE */) {
-                       ErrPrint("Handler is invalid\n");
-                       return LB_STATUS_ERROR_INVALID;
-               }
-
-               if (!handler->common->id) {
-                       ErrPrint("Invalid handle\n");
-                       return LB_STATUS_ERROR_INVALID;
-               }
-
-               if (handler->common->pd.type != _PD_TYPE_SCRIPT && handler->common->pd.type != _PD_TYPE_BUFFER) {
-                       ErrPrint("Handler is not valid type\n");
-                       return LB_STATUS_ERROR_INVALID;
-               }
-
-               pkgname = handler->common->pkgname;
-               id = handler->common->id;
-       }
-
-       packet = packet_create_noack("pd_release_pixmap", "ssi", pkgname, id, pixmap);
-       if (!packet) {
-               ErrPrint("Failed to build a param\n");
-               return LB_STATUS_ERROR_FAULT;
-       }
-
-       return master_rpc_request_only(handler, packet);
-}
-
-EAPI void *livebox_acquire_fb(struct livebox *handler)
-{
-       if (!handler || handler->state != CREATE) {
-               ErrPrint("Handler is invalid\n");
-               return NULL;
-       }
-
-       if (!handler->common || handler->common->state != CREATE) {
-               ErrPrint("Handler is invalid\n");
-               return NULL;
-       }
-
-       if (!handler->common->id) {
-               ErrPrint("Invalid handle\n");
-               return NULL;
-       }
-
-       if (handler->common->lb.type != _LB_TYPE_SCRIPT && handler->common->lb.type != _LB_TYPE_BUFFER) {
-               ErrPrint("Handler is not valid type\n");
-               return NULL;
-       }
-
-       return fb_acquire_buffer(handler->common->lb.fb);
-}
-
-EAPI int livebox_release_fb(void *buffer)
-{
-       return fb_release_buffer(buffer);
-}
-
-EAPI int livebox_fb_refcnt(void *buffer)
-{
-       return fb_refcnt(buffer);
-}
-
-EAPI void *livebox_acquire_pdfb(struct livebox *handler)
-{
-       if (!handler || handler->state != CREATE) {
-               ErrPrint("Handler is invalid\n");
-               return NULL;
-       }
-
-       if (!handler->common || handler->common->state != CREATE) {
-               ErrPrint("Handler is invalid\n");
-               return NULL;
-       }
-
-       if (!handler->common->id) {
-               ErrPrint("Invalid handler\n");
-               return NULL;
-       }
-
-       if (handler->common->pd.type != _PD_TYPE_SCRIPT && handler->common->pd.type != _PD_TYPE_BUFFER) {
-               ErrPrint("Handler is not valid type\n");
-               return NULL;
-       }
-
-       return fb_acquire_buffer(handler->common->pd.fb);
-}
-
-EAPI int livebox_release_pdfb(void *buffer)
-{
-       return fb_release_buffer(buffer);
-}
-
-EAPI int livebox_pdfb_refcnt(void *buffer)
-{
-       return fb_refcnt(buffer);
-}
-
-EAPI int livebox_pdfb_bufsz(struct livebox *handler)
-{
-       if (!handler || handler->state != CREATE) {
-               ErrPrint("Handler is invalid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!handler->common || handler->common->state != CREATE) {
-               ErrPrint("Handler is invalid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!handler->common->id) {
-               ErrPrint("Invalid handler\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       return fb_size(handler->common->pd.fb);
-}
-
-EAPI int livebox_lbfb_bufsz(struct livebox *handler)
-{
-       if (!handler || handler->state != CREATE) {
-               ErrPrint("Handler is invalid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!handler->common || handler->common->state != CREATE) {
-               ErrPrint("Handler is invalid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!handler->common->id) {
-               ErrPrint("Invalid handler\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       return fb_size(handler->common->lb.fb);
-}
-
-EAPI int livebox_is_user(struct livebox *handler)
-{
-       if (!handler || handler->state != CREATE) {
-               ErrPrint("Handler is invalid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!handler->common || handler->common->state != CREATE) {
-               ErrPrint("Handler is invalid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!handler->common->id) {
-               ErrPrint("Invalid handler\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       return handler->common->is_user;
-}
-
-EAPI int livebox_set_pinup(struct livebox *handler, int flag, ret_cb_t cb, void *data)
-{
-       struct packet *packet;
-       int ret;
-
-       if (!handler || handler->state != CREATE) {
-               ErrPrint("Handler is invalid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!handler->common || handler->common->state != CREATE) {
-               ErrPrint("Handler is invalid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!handler->common->id) {
-               ErrPrint("Invalid handler\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (handler->common->request.pinup) {
-               ErrPrint("Previous pinup request is not finished\n");
-               return LB_STATUS_ERROR_BUSY;
-       }
-
-       if (handler->common->is_pinned_up == flag) {
-               DbgPrint("No changes\n");
-               return LB_STATUS_ERROR_ALREADY;
-       }
-
-       packet = packet_create("pinup_changed", "ssi", handler->common->pkgname, handler->common->id, flag);
-       if (!packet) {
-               ErrPrint("Failed to build a param\n");
-               return LB_STATUS_ERROR_FAULT;
-       }
-
-       if (!cb) {
-               cb = default_pinup_cb;
-       }
-
-       ret = master_rpc_async_request(handler, packet, 0, pinup_done_cb, NULL);
-       if (ret == (int)LB_STATUS_SUCCESS) {
-               handler->cbs.pinup.cb = cb;
-               handler->cbs.pinup.data = data;
-               handler->common->request.pinup = 1;
-       }
-
-       return ret;
-}
-
-EAPI int livebox_is_pinned_up(struct livebox *handler)
-{
-       if (!handler || handler->state != CREATE) {
-               ErrPrint("Handler is invalid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!handler->common || handler->common->state != CREATE) {
-               ErrPrint("Handler is invalid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!handler->common->id) {
-               ErrPrint("Invalid handler\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       return handler->common->is_pinned_up;
-}
-
-EAPI int livebox_has_pinup(struct livebox *handler)
-{
-       if (!handler || handler->state != CREATE) {
-               ErrPrint("Handler is invalid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!handler->common || handler->common->state != CREATE) {
-               ErrPrint("Handler is invalid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!handler->common->id) {
-               ErrPrint("Invalid handler\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       return handler->common->lb.pinup_supported;
-}
-
-EAPI int livebox_set_data(struct livebox *handler, void *data)
-{
-       if (!handler) {
-               ErrPrint("Handler is NIL\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (handler->state != CREATE) {
-               ErrPrint("Handler is invalid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       handler->data = data;
-       return LB_STATUS_SUCCESS;
-}
-
-EAPI void *livebox_get_data(struct livebox *handler)
-{
-       if (!handler) {
-               ErrPrint("Handler is NIL\n");
-               return NULL;
-       }
-
-       if (handler->state != CREATE) {
-               ErrPrint("Handler is invalid\n");
-               return NULL;
-       }
-
-       return handler->data;
-}
-
-EAPI int livebox_is_exists(const char *pkgname)
-{
-       char *lb;
-
-       lb = lb_pkgname(pkgname);
-       if (lb) {
-               free(lb);
-               return 1;
-       }
-
-       return 0;
-}
-
-EAPI const char *livebox_content(struct livebox *handler)
-{
-       if (!handler || handler->state != CREATE) {
-               ErrPrint("Handler is invalid\n");
-               return NULL;
-       }
-
-       if (!handler->common || handler->common->state != CREATE) {
-               ErrPrint("Invalid handle\n");
-               return NULL;
-       }
-
-       return handler->common->content;
-}
-
-EAPI const char *livebox_category_title(struct livebox *handler)
-{
-       if (!handler || handler->state != CREATE) {
-               ErrPrint("Handler is invalid\n");
-               return NULL;
-       }
-
-       if (!handler->common || handler->common->state != CREATE) {
-               ErrPrint("Invalid handle\n");
-               return NULL;
-       }
-
-       return handler->common->title;
-}
-
-EAPI int livebox_emit_text_signal(struct livebox *handler, const char *emission, const char *source, double sx, double sy, double ex, double ey, ret_cb_t cb, void *data)
-{
-       struct packet *packet;
-       struct cb_info *cbinfo;
-       int ret;
-
-       if (!handler || handler->state != CREATE) {
-               ErrPrint("Handler is invalid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!handler->common || handler->common->state != CREATE) {
-               ErrPrint("Handler is invalid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if ((handler->common->lb.type != _LB_TYPE_TEXT && handler->common->pd.type != _PD_TYPE_TEXT) || !handler->common->id) {
-               ErrPrint("Handler is not valid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!emission) {
-               emission = "";
-       }
-
-       if (!source) {
-               source = "";
-       }
-
-       packet = packet_create("text_signal", "ssssdddd",
-                               handler->common->pkgname, handler->common->id, emission, source, sx, sy, ex, ey);
-       if (!packet) {
-               ErrPrint("Failed to build a param\n");
-               return LB_STATUS_ERROR_FAULT;
-       }
-
-       cbinfo = create_cb_info(cb, data);
-       if (!cbinfo) {
-               packet_destroy(packet);
-               return LB_STATUS_ERROR_FAULT;
-       }
-
-       ret = master_rpc_async_request(handler, packet, 0, text_signal_cb, cbinfo);
-       if (ret < 0) {
-               destroy_cb_info(cbinfo);
-       }
-
-       return ret;
-}
-
-EAPI int livebox_subscribe_group(const char *cluster, const char *category)
-{
-       struct packet *packet;
-
-       /*!
-        * \todo
-        * Validate the group info using DB
-        * If the group info is not valid, do not send this request
-        */
-
-       packet = packet_create_noack("subscribe", "ss", cluster ? cluster : "", category ? category : "");
-       if (!packet) {
-               ErrPrint("Failed to create a packet\n");
-               return LB_STATUS_ERROR_FAULT;
-       }
-
-       return master_rpc_request_only(NULL, packet);
-}
-
-EAPI int livebox_unsubscribe_group(const char *cluster, const char *category)
-{
-       struct packet *packet;
-
-       /*!
-        * \todo
-        * Validate the group info using DB
-        * If the group info is not valid, do not send this request
-        * AND Check the subscribed or not too
-        */
-
-       packet = packet_create_noack("unsubscribe", "ss", cluster ? cluster : "", category ? category : "");
-       if (!packet) {
-               ErrPrint("Failed to create a packet\n");
-               return LB_STATUS_ERROR_FAULT;
-       }
-
-       return master_rpc_request_only(NULL, packet);
-}
-
-EAPI int livebox_refresh(struct livebox *handler, int force)
-{
-       struct packet *packet;
-
-       if (!handler || handler->state != CREATE) {
-               ErrPrint("Handler is invalid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!handler->common || handler->common->state != CREATE) {
-               ErrPrint("Handler is not valid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!handler->common->id) {
-               ErrPrint("Handler is not valid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       packet = packet_create_noack("update", "ssi", handler->common->pkgname, handler->common->id, force);
-       if (!packet) {
-               ErrPrint("Failed to create a packet\n");
-               return LB_STATUS_ERROR_FAULT;
-       }
-
-       return master_rpc_request_only(handler, packet);
-}
-
-EAPI int livebox_refresh_group(const char *cluster, const char *category, int force)
-{
-       struct packet *packet;
-
-       if (!cluster || !category) {
-               ErrPrint("Invalid argument\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       packet = packet_create_noack("refresh_group", "ssi", cluster, category, force);
-       if (!packet) {
-               ErrPrint("Failed to create a packet\n");
-               return LB_STATUS_ERROR_FAULT;
-       }
-
-       return master_rpc_request_only(NULL, packet);
-}
-
-EAPI int livebox_set_visibility(struct livebox *handler, enum livebox_visible_state state)
-{
-       int old_state;
-       int ret;
-
-       if (!handler || handler->state != CREATE) {
-               ErrPrint("Handler is invalid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!handler->common || handler->common->state != CREATE) {
-               ErrPrint("Handler is not valid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!handler->common->id) {
-               ErrPrint("Handler is not valid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!handler->common->is_user) {
-               /* System cluster livebox cannot be changed its visible states */
-               if (state == LB_HIDE_WITH_PAUSE) {
-                       ErrPrint("CA Livebox is not able to change the visibility\n");
-                       return LB_STATUS_ERROR_PERMISSION;
-               }
-       }
-
-       if (handler->visible == state) {
-               DbgPrint("%s has no changes\n", handler->common->pkgname);
-               return LB_STATUS_ERROR_ALREADY;
-       }
-
-       old_state = handler->visible;
-       handler->visible = state;
-
-       ret = lb_set_visibility(handler, state);
-       if (ret < 0) {
-               handler->visible = old_state;
-       }
-
-       return ret;
-}
-
-EAPI enum livebox_visible_state livebox_visibility(struct livebox *handler)
-{
-       if (!handler || handler->state != CREATE) {
-               ErrPrint("Handler is invalid\n");
-               return LB_VISIBLE_ERROR;
-       }
-
-       if (!handler->common || handler->common->state != CREATE) {
-               ErrPrint("Handler is not valid\n");
-               return LB_VISIBLE_ERROR;
-       }
-
-       if (!handler->common->id) {
-               ErrPrint("Handler is not valid\n");
-               return LB_VISIBLE_ERROR;
-       }
-
-       return handler->visible;
-}
-
-int lb_set_group(struct livebox_common *common, const char *cluster, const char *category)
-{
-       void *pc = NULL;
-       void *ps = NULL;
-
-       if (cluster) {
-               pc = strdup(cluster);
-               if (!pc) {
-                       ErrPrint("Heap: %s (cluster: %s)\n", strerror(errno), cluster);
-                       return LB_STATUS_ERROR_MEMORY;
-               }
-       }
-
-       if (category) {
-               ps = strdup(category);
-               if (!ps) {
-                       ErrPrint("Heap: %s (category: %s)\n", strerror(errno), category);
-                       free(pc);
-                       return LB_STATUS_ERROR_MEMORY;
-               }
-       }
-
-       if (common->cluster) {
-               free(common->cluster);
-       }
-
-       if (common->category) {
-               free(common->category);
-       }
-
-       common->cluster = pc;
-       common->category = ps;
-
-       return LB_STATUS_SUCCESS;
-}
-
-void lb_set_size(struct livebox_common *common, int w, int h)
-{
-       int size_type;
-
-       common->lb.width = w;
-       common->lb.height = h;
-
-       size_type = livebox_service_size_type(w, h);
-       if (size_type != LB_SIZE_TYPE_UNKNOWN) {
-               common->lb.mouse_event = livebox_service_mouse_event(common->pkgname, size_type);
-       }
-}
-
-void lb_set_update_mode(struct livebox_common *common, int active_mode)
-{
-       common->is_active_update = active_mode;
-}
-
-void lb_set_pdsize(struct livebox_common *common, int w, int h)
-{
-       common->pd.width = w;
-       common->pd.height = h;
-}
-
-void lb_set_default_pdsize(struct livebox_common *common, int w, int h)
-{
-       common->pd.default_width = w;
-       common->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;
-       struct dlist *n;
-       struct fault_info *info;
-
-       s_info.fault_state = INFO_STATE_CALLBACK_IN_PROCESSING;
-
-       dlist_foreach_safe(s_info.fault_list, l, n, info) {
-               if (!info->is_deleted && info->handler(event, pkgname, file, func, info->user_data) == EXIT_FAILURE) {
-                       info->is_deleted = 1;
-               }
-
-               if (info->is_deleted) {
-                       s_info.fault_list = dlist_remove(s_info.fault_list, l);
-                       free(info);
-               }
-       }
-
-       s_info.fault_state &= ~INFO_STATE_CALLBACK_IN_PROCESSING;
-}
-
-void lb_invoke_event_handler(struct livebox *handler, enum livebox_event_type event)
-{
-       struct dlist *l;
-       struct dlist *n;
-       struct event_info *info;
-
-       if (event == LB_EVENT_LB_UPDATED && handler->common->refcnt > 1) {
-               if (handler->visible != LB_SHOW) {
-                       DbgPrint("Update requested(pending) - %s\n", handler->common->pkgname);
-                       handler->paused_updating++;
-                       return;
-               } else {
-                       handler->paused_updating = 0;
-               }
-       }
-
-       s_info.event_state = INFO_STATE_CALLBACK_IN_PROCESSING;
-
-       dlist_foreach_safe(s_info.event_list, l, n, info) {
-               if (!info->is_deleted && info->handler(handler, event, info->user_data) == EXIT_FAILURE) {
-                       DbgPrint("Event handler returns EXIT_FAILURE\n");
-                       info->is_deleted = 1;
-               }
-
-               if (info->is_deleted) {
-                       s_info.event_list = dlist_remove(s_info.event_list, l);
-                       free(info);
-               }
-       }
-
-       s_info.event_state &= ~INFO_STATE_CALLBACK_IN_PROCESSING;
-}
-
-struct livebox_common *lb_find_common_handle(const char *pkgname, const char *id)
-{
-       struct dlist *l;
-       struct livebox_common *common;
-
-       dlist_foreach(s_info.livebox_common_list, l, common) {
-               if (!common->id) {
-                       continue;
-               }
-
-               if (!strcmp(common->pkgname, pkgname) && !strcmp(common->id, id)) {
-                       return common;
-               }
-       }
-
-       return NULL;
-}
-
-struct livebox_common *lb_find_common_handle_by_timestamp(double timestamp)
-{
-       struct dlist *l;
-       struct livebox_common *common;
-
-       dlist_foreach(s_info.livebox_common_list, l, common) {
-               if (common->timestamp == timestamp) {
-                       return common;
-               }
-       }
-
-       return NULL;
-}
-
-struct livebox *lb_new_livebox(const char *pkgname, const char *id, double timestamp, const char *cluster, const char *category)
-{
-       struct livebox *handler;
-
-       handler = calloc(1, sizeof(*handler));
-       if (!handler) {
-               ErrPrint("Failed to create a new livebox\n");
-               return NULL;
-       }
-
-       handler->common = lb_create_common_handle(handler, pkgname, cluster, category);
-       if (!handler->common) {
-               ErrPrint("Heap: %s\n", strerror(errno));
-               free(handler);
-               return NULL;
-       }
-
-       lb_common_ref(handler->common, handler);
-       lb_set_id(handler->common, id);
-       handler->common->timestamp = timestamp;
-       handler->common->state = CREATE;
-       handler->visible = LB_SHOW;
-       s_info.livebox_list = dlist_append(s_info.livebox_list, handler);
-
-       return lb_ref(handler);
-}
-
-int lb_delete_all(void)
-{
-       struct dlist *l;
-       struct dlist *n;
-       struct livebox *handler;
-
-       dlist_foreach_safe(s_info.livebox_list, l, n, handler) {
-               lb_invoke_event_handler(handler, LB_EVENT_DELETED);
-               lb_unref(handler, 1);
-       }
-
-       return LB_STATUS_SUCCESS;
-}
-
-int lb_set_content(struct livebox_common *common, const char *content)
-{
-       char *pc = NULL;
-
-       if (content) {
-               pc = strdup(content);
-               if (!pc) {
-                       ErrPrint("heap: %s [%s]\n", strerror(errno), content);
-                       return LB_STATUS_ERROR_MEMORY;
-               }
-       }
-
-       free(common->content);
-       common->content = pc;
-       return LB_STATUS_SUCCESS;
-}
-
-int lb_set_title(struct livebox_common *common, const char *title)
-{
-       char *pt = NULL;
-
-       if (title) {
-               pt = strdup(title);
-               if (!pt) {
-                       ErrPrint("heap: %s [%s]\n", strerror(errno), title);
-                       return LB_STATUS_ERROR_MEMORY;
-               }
-       }
-
-       free(common->title);
-       common->title = pt;
-       return LB_STATUS_SUCCESS;
-}
-
-void lb_set_size_list(struct livebox_common *common, int size_list)
-{
-       common->lb.size_list = size_list;
-}
-
-void lb_set_auto_launch(struct livebox_common *common, const char *auto_launch)
-{
-       char *pa = NULL;
-
-       if (!auto_launch || !strlen(auto_launch)) {
-               return;
-       }
-
-       pa = strdup(auto_launch);
-       if (!pa) {
-               ErrPrint("heap: %s, [%s]\n", strerror(errno), auto_launch);
-               return;
-       }
-
-       free(common->lb.auto_launch);
-       common->lb.auto_launch = pa;
-}
-
-void lb_set_priority(struct livebox_common *common, double priority)
-{
-       common->lb.priority = priority;
-}
-
-void lb_set_id(struct livebox_common *common, const char *id)
-{
-       char *pi = NULL;
-
-       if (id) {
-               pi = strdup(id);
-               if (!pi) {
-                       ErrPrint("heap: %s [%s]\n", strerror(errno), pi);
-                       return;
-               }
-       }
-
-       free(common->id);
-       common->id = pi;
-}
-
-void lb_set_filename(struct livebox_common *common, const char *filename)
-{
-       if (common->filename) {
-               if (common->lb.type == _LB_TYPE_FILE || common->lb.type == _LB_TYPE_TEXT) {
-                       if (common->filename[0] && unlink(common->filename) < 0) {
-                               ErrPrint("unlink: %s (%s)\n", strerror(errno), common->filename);
-                       }
-               }
-
-               free(common->filename);
-       }
-
-       common->filename = strdup(filename);
-       if (!common->filename) {
-               ErrPrint("Heap: %s\n", strerror(errno));
-       }
-}
-
-void lb_set_alt_icon(struct livebox_common *common, const char *icon)
-{
-       char *_icon = NULL;
-
-       if (icon && strlen(icon)) {
-               _icon = strdup(icon);
-               if (!_icon) {
-                       ErrPrint("Heap: %s\n", strerror(errno));
-               }
-       }
-
-       free(common->alt.icon);
-       common->alt.icon = _icon;
-}
-
-void lb_set_alt_name(struct livebox_common *common, const char *name)
-{
-       char *_name = NULL;
-
-       if (name && strlen(name)) {
-               _name = strdup(name);
-               if (!_name) {
-                       ErrPrint("Heap: %s\n", strerror(errno));
-               }
-       }
-
-       free(common->alt.name);
-       common->alt.name = _name;
-}
-
-int lb_set_lb_fb(struct livebox_common *common, const char *filename)
-{
-       struct fb_info *fb;
-
-       if (!common) {
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       fb = common->lb.fb;
-       if (fb && !strcmp(fb_id(fb), filename)) { /*!< BUFFER is not changed, */
-               return LB_STATUS_SUCCESS;
-       }
-
-       common->lb.fb = NULL;
-
-       if (!filename || filename[0] == '\0') {
-               if (fb) {
-                       fb_destroy(fb);
-               }
-               return LB_STATUS_SUCCESS;
-       }
-
-       common->lb.fb = fb_create(filename, common->lb.width, common->lb.height);
-       if (!common->lb.fb) {
-               ErrPrint("Faield to create a FB\n");
-               if (fb) {
-                       fb_destroy(fb);
-               }
-               return LB_STATUS_ERROR_FAULT;
-       }
-
-       if (fb) {
-               fb_destroy(fb);
-       }
-
-       return LB_STATUS_SUCCESS;
-}
-
-int lb_set_pd_fb(struct livebox_common *common, const char *filename)
-{
-       struct fb_info *fb;
-
-       if (!common || common->state != CREATE) {
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       fb = common->pd.fb;
-       if (fb && !strcmp(fb_id(fb), filename)) {
-               /* BUFFER is not changed, just update the content */
-               return LB_STATUS_ERROR_EXIST;
-       }
-       common->pd.fb = NULL;
-
-       if (!filename || filename[0] == '\0') {
-               if (fb) {
-                       fb_destroy(fb);
-               }
-               return LB_STATUS_SUCCESS;
-       }
-
-       common->pd.fb = fb_create(filename, common->pd.width, common->pd.height);
-       if (!common->pd.fb) {
-               ErrPrint("Failed to create a FB\n");
-               if (fb) {
-                       fb_destroy(fb);
-               }
-               return LB_STATUS_ERROR_FAULT;
-       }
-
-       if (fb) {
-               fb_destroy(fb);
-       }
-       return LB_STATUS_SUCCESS;
-}
-
-struct fb_info *lb_get_lb_fb(struct livebox_common *common)
-{
-       return common->lb.fb;
-}
-
-struct fb_info *lb_get_pd_fb(struct livebox_common *common)
-{
-       return common->pd.fb;
-}
-
-void lb_set_user(struct livebox_common *common, int user)
-{
-       common->is_user = user;
-}
-
-void lb_set_pinup(struct livebox_common *common, int pinup_supported)
-{
-       common->lb.pinup_supported = pinup_supported;
-}
-
-void lb_set_text_lb(struct livebox_common *common)
-{
-       common->lb.type = _LB_TYPE_TEXT;
-}
-
-void lb_set_text_pd(struct livebox_common *common)
-{
-       common->pd.type = _PD_TYPE_TEXT;
-}
-
-int lb_text_lb(struct livebox_common *common)
-{
-       return common->lb.type == _LB_TYPE_TEXT;
-}
-
-int lb_text_pd(struct livebox_common *common)
-{
-       return common->pd.type == _PD_TYPE_TEXT;
-}
-
-void lb_set_period(struct livebox_common *common, double period)
-{
-       common->lb.period = period;
-}
-
-struct livebox *lb_ref(struct livebox *handler)
-{
-       if (!handler) {
-               return NULL;
-       }
-
-       handler->refcnt++;
-       return handler;
-}
-
-struct livebox *lb_unref(struct livebox *handler, int destroy_common)
-{
-       if (!handler) {
-               return NULL;
-       }
-
-       handler->refcnt--;
-       if (handler->refcnt > 0) {
-               return handler;
-       }
-
-       if (handler->cbs.created.cb) {
-               handler->cbs.created.cb(handler, LB_STATUS_ERROR_FAULT, handler->cbs.created.data);
-               handler->cbs.created.cb = NULL;
-               handler->cbs.created.data = NULL;
-       }
-
-       if (handler->cbs.deleted.cb) {
-               handler->cbs.deleted.cb(handler, LB_STATUS_ERROR_FAULT, handler->cbs.deleted.data);
-               handler->cbs.deleted.cb = NULL;
-               handler->cbs.deleted.data = NULL;
-       }
-
-       if (handler->cbs.pinup.cb) {
-               handler->cbs.pinup.cb(handler, LB_STATUS_ERROR_FAULT, handler->cbs.pinup.data);
-               handler->cbs.pinup.cb = NULL;
-               handler->cbs.pinup.data = NULL;
-       }
-
-       if (handler->cbs.group_changed.cb) {
-               handler->cbs.group_changed.cb(handler, LB_STATUS_ERROR_FAULT, handler->cbs.group_changed.data);
-               handler->cbs.group_changed.cb = NULL;
-               handler->cbs.group_changed.data = NULL;
-       }
-
-       if (handler->cbs.period_changed.cb) {
-               handler->cbs.period_changed.cb(handler, LB_STATUS_ERROR_FAULT, handler->cbs.period_changed.data);
-               handler->cbs.period_changed.cb = NULL;
-               handler->cbs.period_changed.data = NULL;
-       }
-
-       if (handler->cbs.size_changed.cb) {
-               handler->cbs.size_changed.cb(handler, LB_STATUS_ERROR_FAULT, handler->cbs.size_changed.data);
-               handler->cbs.size_changed.cb = NULL;
-               handler->cbs.size_changed.data = NULL;
-       }
-
-       if (handler->cbs.pd_created.cb) {
-               handler->cbs.pd_created.cb(handler, LB_STATUS_ERROR_FAULT, handler->cbs.pd_created.data);
-               handler->cbs.pd_created.cb = NULL;
-               handler->cbs.pd_created.data = NULL;
-       }
-
-       if (handler->cbs.pd_destroyed.cb) {
-               handler->cbs.pd_destroyed.cb(handler, LB_STATUS_ERROR_FAULT, handler->cbs.pd_destroyed.data);
-               handler->cbs.pd_destroyed.cb = NULL;
-               handler->cbs.pd_destroyed.data = NULL;
-       }
-
-       if (handler->cbs.update_mode.cb) {
-               handler->cbs.update_mode.cb(handler, LB_STATUS_ERROR_FAULT, handler->cbs.update_mode.data);
-               handler->cbs.update_mode.cb = NULL;
-               handler->cbs.update_mode.data = NULL;
-       }
-
-       if (handler->cbs.access_event.cb) {
-               handler->cbs.access_event.cb(handler, LB_ACCESS_STATUS_ERROR, handler->cbs.access_event.data);
-               handler->cbs.access_event.cb = NULL;
-               handler->cbs.access_event.data = NULL;
-       }
-
-       if (handler->cbs.key_event.cb) {
-               handler->cbs.key_event.cb(handler, LB_KEY_STATUS_ERROR, handler->cbs.key_event.data);
-               handler->cbs.key_event.cb = NULL;
-               handler->cbs.key_event.data = NULL;
-       }
-
-       dlist_remove_data(s_info.livebox_list, handler);
-
-       handler->state = DESTROYED;
-       if (lb_common_unref(handler->common, handler) == 0) {
-               if (destroy_common) {
-                       /*!
-                        * \note
-                        * Lock file should be deleted after all callbacks are processed.
-                        */
-                       lb_destroy_lock_file(handler->common, 0);
-                       lb_destroy_common_handle(handler->common);
-               }
-       }
-       free(handler);
-       DbgPrint("Handler is released\n");
-       return NULL;
-}
-
-int lb_send_delete(struct livebox *handler, int type, ret_cb_t cb, void *data)
-{
-       struct packet *packet;
-       struct cb_info *cbinfo;
-       int ret;
-
-       if (handler->common->request.deleted) {
-               ErrPrint("Already in-progress\n");
-               if (cb) {
-                       cb(handler, LB_STATUS_SUCCESS, data);
-               }
-               return LB_STATUS_ERROR_BUSY;
-       }
-
-       if (!cb) {
-               cb = default_delete_cb;
-       }
-
-       packet = packet_create("delete", "ssid", handler->common->pkgname, handler->common->id, type, handler->common->timestamp);
-       if (!packet) {
-               ErrPrint("Failed to build a param\n");
-               if (cb) {
-                       cb(handler, LB_STATUS_ERROR_FAULT, data);
-               }
-
-               return LB_STATUS_ERROR_FAULT;
-       }
-
-       cbinfo = create_cb_info(cb, data);
-       if (!cbinfo) {
-               packet_destroy(packet);
-               ErrPrint("Failed to create cbinfo\n");
-               if (cb) {
-                       cb(handler, LB_STATUS_ERROR_FAULT, data);
-               }
-
-               return LB_STATUS_ERROR_FAULT;
-       }
-
-       ret = master_rpc_async_request(handler, packet, 0, del_ret_cb, cbinfo);
-       if (ret < 0) {
-               /*!
-                * Packet is destroyed by master_rpc_async_request.
-                */
-               destroy_cb_info(cbinfo);
-
-               if (cb) {
-                       cb(handler, LB_STATUS_ERROR_FAULT, data);
-               }
-       } else {
-               handler->common->request.deleted = 1;
-       }
-
-       return ret;
-}
-
-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 LB_STATUS_ERROR_FAULT;
-       }
-
-       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 LB_STATUS_ERROR_FAULT;
-       }
-
-       return master_rpc_request_only(NULL, packet);
-}
-
-EAPI int livebox_sync_lb_fb(struct livebox *handler)
-{
-       if (!handler || handler->state != CREATE) {
-               ErrPrint("Invalid handle\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!handler->common || handler->common->state != CREATE) {
-               ErrPrint("Invalid handle\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!handler->common->id) {
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       return lb_sync_lb_fb(handler->common);
-}
-
-int lb_sync_lb_fb(struct livebox_common *common)
-{
-       int ret;
-
-       if (fb_type(lb_get_lb_fb(common)) == BUFFER_TYPE_FILE && common->lb.lock_fd >= 0) {
-               (void)do_fb_lock(common->lb.lock_fd);
-               ret = fb_sync(lb_get_lb_fb(common));
-               (void)do_fb_unlock(common->lb.lock_fd);
-       } else {
-               ret = fb_sync(lb_get_lb_fb(common));
-       }
-
-       return ret;
-}
-
-int lb_sync_pd_fb(struct livebox_common *common)
-{
-       int ret;
-
-       if (fb_type(lb_get_pd_fb(common)) == BUFFER_TYPE_FILE && common->pd.lock_fd >= 0) {
-               (void)do_fb_lock(common->pd.lock_fd);
-               ret = fb_sync(lb_get_pd_fb(common));
-               (void)do_fb_unlock(common->pd.lock_fd);
-       } else {
-               ret = fb_sync(lb_get_pd_fb(common));
-       }
-
-       return ret;
-}
-
-EAPI int livebox_sync_pd_fb(struct livebox *handler)
-{
-       if (!handler || handler->state != CREATE) {
-               ErrPrint("Invalid handle\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!handler->common || handler->common->state != CREATE) {
-               ErrPrint("Invalid handle\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!handler->common->id) {
-               ErrPrint("Invalid handle\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       return lb_sync_pd_fb(handler->common);
-}
-
-EAPI const char *livebox_alt_icon(struct livebox *handler)
-{
-       if (!handler || handler->state != CREATE) {
-               ErrPrint("Handler is not valid[%p]\n", handler);
-               return NULL;
-       }
-
-       if (!handler->common || handler->common->state != CREATE) {
-               ErrPrint("Handler is not valid\n");
-               return NULL;
-       }
-
-       return handler->common->alt.icon;
-}
-
-EAPI const char *livebox_alt_name(struct livebox *handler)
-{
-       if (!handler || handler->state != CREATE) {
-               ErrPrint("Handler is not valid[%p]\n", handler);
-               return NULL;
-       }
-
-       if (!handler->common || handler->common->state != CREATE) {
-               ErrPrint("Handler is not valid\n");
-               return NULL;
-       }
-
-       return handler->common->alt.name;
-}
-
-EAPI int livebox_acquire_fb_lock(struct livebox *handler, int is_pd)
-{
-       int ret = LB_STATUS_SUCCESS;
-       int fd;
-
-       if (!handler || handler->state != CREATE) {
-               ErrPrint("Handler is not valid[%p]\n", handler);
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!handler->common || handler->common->state != CREATE) {
-               ErrPrint("Handler is not valid\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!handler->common->id) {
-               ErrPrint("Handler is not valid[%p]\n", handler);
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (is_pd) {
-               if (!handler->common->pd.lock || handler->common->pd.lock_fd < 0) {
-                       DbgPrint("Lock: %s (%d)\n", handler->common->pd.lock, handler->common->pd.lock_fd);
-                       return LB_STATUS_ERROR_INVALID;
-               }
-
-               if (fb_type(lb_get_pd_fb(handler->common)) == BUFFER_TYPE_FILE) {
-                       return LB_STATUS_SUCCESS;
-               }
-
-               fd = handler->common->pd.lock_fd;
-       } else {
-               if (!handler->common->lb.lock || handler->common->lb.lock_fd < 0) {
-                       DbgPrint("Lock: %s (%d)\n", handler->common->lb.lock, handler->common->lb.lock_fd);
-                       return LB_STATUS_ERROR_INVALID;
-               }
-
-               if (fb_type(lb_get_lb_fb(handler->common)) == BUFFER_TYPE_FILE) {
-                       return LB_STATUS_SUCCESS;
-               }
-
-               fd = handler->common->lb.lock_fd;
-       }
-
-       ret = do_fb_lock(fd);
-
-       return ret == 0 ? LB_STATUS_SUCCESS : LB_STATUS_ERROR_FAULT;
-}
-
-EAPI int livebox_release_fb_lock(struct livebox *handler, int is_pd)
-{
-       int ret = LB_STATUS_SUCCESS;
-       int fd;
-
-       if (!handler || handler->state != CREATE) {
-               ErrPrint("Invalid handle\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!handler->common || handler->common->state != CREATE) {
-               ErrPrint("Invalid handle\n");
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (!handler->common->id) {
-               ErrPrint("Handler is not valid[%p]\n", handler);
-               return LB_STATUS_ERROR_INVALID;
-       }
-
-       if (is_pd) {
-               if (!handler->common->pd.lock || handler->common->pd.lock_fd < 0) {
-                       DbgPrint("Unlock: %s (%d)\n", handler->common->pd.lock, handler->common->pd.lock_fd);
-                       return LB_STATUS_ERROR_INVALID;
-               }
-
-               if (fb_type(lb_get_pd_fb(handler->common)) == BUFFER_TYPE_FILE) {
-                       return LB_STATUS_SUCCESS;
-               }
-
-               fd = handler->common->pd.lock_fd;
-       } else {
-               if (!handler->common->lb.lock || handler->common->lb.lock_fd < 0) {
-                       DbgPrint("Unlock: %s (%d)\n", handler->common->lb.lock, handler->common->lb.lock_fd);
-                       return LB_STATUS_ERROR_INVALID;
-               }
-
-               if (fb_type(lb_get_lb_fb(handler->common)) == BUFFER_TYPE_FILE) {
-                       return LB_STATUS_SUCCESS;
-               }
-
-               fd = handler->common->lb.lock_fd;
-       }
-
-       ret = do_fb_unlock(fd);
-
-       return ret == 0 ? LB_STATUS_SUCCESS : LB_STATUS_ERROR_FAULT;
-}
-
-EAPI int livebox_set_option(enum livebox_option_type option, int state)
-{
-       int ret = LB_STATUS_SUCCESS;
-
-       switch (option) {
-       case LB_OPTION_MANUAL_SYNC:
-               conf_set_manual_sync(state);
-               break;
-       case LB_OPTION_FRAME_DROP_FOR_RESIZE:
-               conf_set_frame_drop_for_resizing(state);
-               break;
-       case LB_OPTION_SHARED_CONTENT:
-               conf_set_shared_content(state);
-               break;
-       default:
-               ret = LB_STATUS_ERROR_INVALID;
-               break;
-       }
-
-       return ret;
-}
-
-EAPI int livebox_option(enum livebox_option_type option)
-{
-       int ret;
-
-       switch (option) {
-       case LB_OPTION_MANUAL_SYNC:
-               ret = conf_manual_sync();
-               break;
-       case LB_OPTION_FRAME_DROP_FOR_RESIZE:
-               ret = conf_frame_drop_for_resizing();
-               break;
-       case LB_OPTION_SHARED_CONTENT:
-               ret = conf_shared_content();
-               break;
-       default:
-               ret = LB_STATUS_ERROR_INVALID;
-               break;
-       }
-
-       return ret;
-}
-
-EAPI int livebox_set_auto_launch_handler(int (*launch_handler)(struct livebox *handler, const char *appid, void *data), void *data)
-{
-       s_info.launch.handler = launch_handler;
-       s_info.launch.data = data;
-
-       return LB_STATUS_SUCCESS;
-}
-
-/* End of a file */
index 2b5cd15..2298c9d 100644 (file)
@@ -176,7 +176,7 @@ static int done_cb(pid_t pid, int handle, const struct packet *packet, void *dat
 
        if (packet_get(packet, "i", &ret) != 1) {
                ErrPrint("Invalid result packet\n");
-               ret = LB_STATUS_ERROR_INVALID;
+               ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
        }
 
 out:
@@ -206,7 +206,7 @@ int master_rpc_async_request(struct livebox *handler, struct packet *packet, int
        if (!command) {
                ErrPrint("Failed to create a command\n");
                packet_unref(packet);
-               return LB_STATUS_ERROR_FAULT;
+               return DBOX_STATUS_ERROR_FAULT;
        }
 
        command->ret_cb = ret_cb;
@@ -221,7 +221,7 @@ int master_rpc_async_request(struct livebox *handler, struct packet *packet, int
        }
 
        packet_unref(packet);
-       return LB_STATUS_SUCCESS;
+       return DBOX_STATUS_ERROR_NONE;
 }
 
 int master_rpc_request_only(struct livebox *handler, struct packet *packet)
@@ -232,7 +232,7 @@ int master_rpc_request_only(struct livebox *handler, struct packet *packet)
        if (!command) {
                ErrPrint("Failed to create a command\n");
                packet_unref(packet);
-               return LB_STATUS_ERROR_FAULT;
+               return DBOX_STATUS_ERROR_FAULT;
        }
 
        command->ret_cb = NULL;
@@ -242,7 +242,7 @@ int master_rpc_request_only(struct livebox *handler, struct packet *packet)
 
        push_command(command);
        packet_unref(packet);
-       return LB_STATUS_SUCCESS;
+       return DBOX_STATUS_ERROR_NONE;
 }
 
 int master_rpc_clear_fault_package(const char *pkgname)
@@ -252,7 +252,7 @@ int master_rpc_clear_fault_package(const char *pkgname)
        struct command *command;
 
        if (!pkgname) {
-               return LB_STATUS_ERROR_INVALID;
+               return DBOX_STATUS_ERROR_INVALID_PARAMETER;
        }
 
        dlist_foreach_safe(s_info.cmd_list, l, n, command) {
@@ -301,13 +301,13 @@ int master_rpc_sync_request(struct packet *packet)
        if (result) {
                if (packet_get(result, "i", &ret) != 1) {
                        ErrPrint("Invalid result packet\n");
-                       ret = LB_STATUS_ERROR_INVALID;
+                       ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
                }
 
                packet_unref(result);
        } else {
                ErrPrint("Failed to send a sync request\n");
-               ret = LB_STATUS_ERROR_FAULT;
+               ret = DBOX_STATUS_ERROR_FAULT;
        }
 
        packet_unref(packet);
index 66431c6..e0ab833 100644 (file)
@@ -23,7 +23,7 @@
 #include <time.h>
 
 #include <dlog.h>
-#include <livebox-errno.h> /* For error code */
+#include <dynamicbox_errno.h> /* For error code */
 
 #include "debug.h"
 #include "util.h"
@@ -44,7 +44,7 @@ int util_check_extension(const char *filename, const char *check_ptr)
        name_len = strlen(filename);
        while (--name_len >= 0 && *check_ptr) {
                if (filename[name_len] != *check_ptr) {
-                       return LB_STATUS_ERROR_INVALID;
+                       return DBOX_STATUS_ERROR_INVALID_PARAMETER;
                }
 
                check_ptr ++;
@@ -115,14 +115,14 @@ static inline int check_native_livebox(const char *pkgname)
        path = malloc(len + 1);
        if (!path) {
                ErrPrint("Heap: %s\n", strerror(errno));
-               return LB_STATUS_ERROR_MEMORY;
+               return DBOX_STATUS_ERROR_OUT_OF_MEMORY;
        }
 
        snprintf(path, len, "/opt/usr/live/%s/libexec/liblive-%s.so", pkgname, pkgname);
        if (access(path, F_OK | R_OK) != 0) {
                ErrPrint("%s is not a valid package\n", pkgname);
                free(path);
-               return LB_STATUS_ERROR_INVALID;
+               return DBOX_STATUS_ERROR_INVALID_PARAMETER;
        }
 
        free(path);
@@ -140,14 +140,14 @@ static inline int check_web_livebox(const char *pkgname)
        path = malloc(len + 1);
        if (!path) {
                ErrPrint("Heap: %s\n", strerror(errno));
-               return LB_STATUS_ERROR_MEMORY;
+               return DBOX_STATUS_ERROR_OUT_OF_MEMORY;
        }
 
        snprintf(path, len, "/opt/usr/apps/%s/res/wgt/livebox/index.html", pkgname);
        if (access(path, F_OK | R_OK) != 0) {
                ErrPrint("%s is not a valid package\n", pkgname);
                free(path);
-               return LB_STATUS_ERROR_INVALID;
+               return DBOX_STATUS_ERROR_INVALID_PARAMETER;
        }
 
        free(path);
@@ -158,14 +158,14 @@ int util_validate_livebox_package(const char *pkgname)
 {
        if (!pkgname) {
                ErrPrint("Invalid argument\n");
-               return LB_STATUS_ERROR_INVALID;
+               return DBOX_STATUS_ERROR_INVALID_PARAMETER;
        }
 
        if (!check_native_livebox(pkgname) || !check_web_livebox(pkgname)) {
                return 0;
        }
 
-       return LB_STATUS_ERROR_INVALID;
+       return DBOX_STATUS_ERROR_INVALID_PARAMETER;
 }
 
 const char *util_uri_to_path(const char *uri)
@@ -187,28 +187,28 @@ int util_unlink(const char *filename)
        int ret;
 
        if (!filename) {
-               return LB_STATUS_ERROR_INVALID;
+               return DBOX_STATUS_ERROR_INVALID_PARAMETER;
        }
 
        desclen = strlen(filename) + 6; /* .desc */
        descfile = malloc(desclen);
        if (!descfile) {
                ErrPrint("Heap: %s\n", strerror(errno));
-               return LB_STATUS_ERROR_MEMORY;
+               return DBOX_STATUS_ERROR_OUT_OF_MEMORY;
        }
 
        ret = snprintf(descfile, desclen, "%s.desc", filename);
        if (ret < 0) {
                ErrPrint("Error: %s\n", strerror(errno));
                free(descfile);
-               return LB_STATUS_ERROR_FAULT;
+               return DBOX_STATUS_ERROR_FAULT;
        }
 
        (void)unlink(descfile);
        free(descfile);
        (void)unlink(filename);
 
-       return LB_STATUS_SUCCESS;
+       return DBOX_STATUS_ERROR_NONE;
 }
 
 /* End of a file */