Check the BUFFER file existence.
authorSung-jae Park <nicesj.park@samsung.com>
Tue, 5 Jun 2012 07:53:07 +0000 (16:53 +0900)
committerSung-jae Park <nicesj.park@samsung.com>
Thu, 7 Jun 2012 15:11:09 +0000 (00:11 +0900)
If it fails to create the buffer from a file,
Don't try to invoke the callbacks.

Change-Id: I1a34ebc4076990625e715721e63db608a577a225

13 files changed:
CMakeLists.txt
debian/changelog
include/dbus.h
include/livebox.h
include/livebox_internal.h
include/master_rpc.h [new file with mode: 0644]
include/util.h
packaging/liblivebox-viewer.spec
src/dbus.c
src/fb_file.c
src/livebox.c
src/master_rpc.c [new file with mode: 0644]
src/util.c

index 8899cdf..4d5d08b 100644 (file)
@@ -54,6 +54,7 @@ ADD_LIBRARY(${PROJECT_NAME} SHARED
        src/dbus.c
        src/fb_file.c
        src/desc_parser.c
+       src/master_rpc.c
 )
 SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES SOVERSION ${VERSION_MAJOR})
 SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES VERSION ${VERSION})
index c0dba06..38cd299 100644 (file)
@@ -1,3 +1,10 @@
+livebox-viewer (0.1.0) unstable; urgency=low
+
+  * Git: slp/pkgs/l/livebox-viewer
+  * Tag: livebox-viewer_0.1.0
+
+ -- Sung-jae Park <nicesj.park@samsung.com>  Fri, 08 Jun 2012 00:10:48 +0900
+
 livebox-viewer (0.0.8) unstable; urgency=low
 
   * Git: slp/pkgs/l/livebox-viewer
index 1e59c45..2c2bdff 100644 (file)
@@ -1,7 +1,6 @@
-
-extern GDBusProxy *dbus_get_proxy(void);
-extern int dbus_push_command(struct livebox *handler, const char *funcname, GVariant *param, void (*ret_cb)(struct livebox *handler, int ret, void *data), void *data);
-extern int dbus_sync_command(const char *funcname, GVariant *param);
+extern GDBusProxy *dbus_proxy(void);
+extern int dbus_async_request(struct livebox *handler, const char *funcname, GVariant *param, void (*ret_cb)(struct livebox *handler, int ret, void *data), void *data);
+extern int dbus_sync_request(struct livebox *handler, const char *func, GVariant *param);
 extern int dbus_init(void);
 extern int dbus_fini(void);
 
index 4f56ea4..0d7249f 100644 (file)
@@ -44,7 +44,7 @@ extern int livebox_init(void);
 extern int livebox_fini(void);
 
 extern struct livebox *livebox_add(const char *pkgname, const char *content, const char *cluster, const char *category, double period);
-extern int livebox_del(struct livebox *handler, int server);
+extern int livebox_del(struct livebox *handler, int unused);
 
 /*!
  * \note event list
index dadc6eb..58ac773 100644 (file)
@@ -24,18 +24,16 @@ extern void lb_set_text_pd(struct livebox *handler, int flag);
 extern int lb_text_lb(struct livebox *handler);
 extern int lb_text_pd(struct livebox *handler);
 extern void lb_set_period(struct livebox *handler, double period);
-extern void lb_ref(struct livebox *handler);
-extern void lb_unref(struct livebox *handler);
+extern struct livebox *lb_ref(struct livebox *handler);
+extern struct livebox *lb_unref(struct livebox *handler);
 extern int lb_send_delete(struct livebox *handler);
 
 struct livebox {
-       unsigned long magic;
        int refcnt;
        enum {
-               NOT_DELETED = 0x0,
-               DELETE_THIS = 0x01, /* Delete only for this client */
-               DELETE_ALL = 0x02, /* Delete for all clients */
-       } deleted;
+               CREATE = 0x0,
+               DELETE = 0x01, /* Delete only for this client */
+       } state;
 
        char *cluster;
        char *category;
diff --git a/include/master_rpc.h b/include/master_rpc.h
new file mode 100644 (file)
index 0000000..c82aebb
--- /dev/null
@@ -0,0 +1,4 @@
+extern int master_rpc_async_request(struct livebox *handler, const char *funcname, GVariant *param, void (*ret_cb)(struct livebox *handler, GVariant *result, void *data), void *data);
+extern int master_rpc_sync_request(struct livebox *handler, const char *func, GVariant *param);
+
+/* End of a file */
index 6202410..1f69875 100644 (file)
@@ -20,6 +20,6 @@
  */
 
 extern int util_check_extension(const char *filename, const char *check_ptr);
-extern double util_get_timestamp(void);
+extern double util_timestamp(void);
 
 /* End of a file */
index 3893240..692f895 100644 (file)
@@ -1,6 +1,6 @@
 Name: liblivebox-viewer
 Summary: Library for the development of a livebox viewer
-Version: 0.0.8
+Version: 0.1.0
 Release: 1
 Group: main/app
 License: Samsung Proprietary License
index 9157cfd..e393455 100644 (file)
 #include "livebox_internal.h"
 #include "dbus.h"
 #include "desc_parser.h"
-
-#define DEFAULT_TTL 5
+#include "master_rpc.h"
 
 static struct info {
        GDBusNodeInfo *node_info;
        GDBusProxy *proxy;
-       struct dlist *cmd_list;
-       guint cmd_timer;
        guint recon_timer;
        guint reg_id;
+       guint reacquire_timer;
        const gchar *xml_data;
 } s_info = {
        .proxy = NULL,
-       .cmd_list = NULL,
-       .cmd_timer = 0,
        .recon_timer = 0,
+       .reacquire_timer = 0,
        .reg_id = 0,
        .node_info = NULL,
        .xml_data = "<node>"
@@ -44,6 +41,7 @@ static struct info {
        " <method name='deleted'>"
        "  <arg type='s' name='pkgname' direction='in' />"
        "  <arg type='s' name='filename' direction='in' />"
+       "  <arg type='d' name='timestamp' direction='in' />"
        "  <arg type='i' name='result' direction='out' />"
        " </method>"
        " <method name='lb_updated'>"
@@ -89,184 +87,33 @@ static struct info {
        "</node>",
 };
 
-struct cmd_item {
-       int ttl;
-       char *funcname;
-       GVariant *param;
-       struct livebox *handler;
-       void (*ret_cb)(struct livebox *handler, int ret, void *data);
-       void *data;
-};
-
-GDBusProxy *dbus_get_proxy(void)
+GDBusProxy *dbus_proxy(void)
 {
        return s_info.proxy;
 }
 
-static inline int send_acquire(void)
-{
-       GVariant *result;
-       GError *err;
-       static int sent = 0;
-
-       if (sent == 1)
-               return 0;
-
-       err = NULL;
-       result = g_dbus_proxy_call_sync(s_info.proxy, "acquire", g_variant_new("(i)", getpid()),
-                                       G_DBUS_CALL_FLAGS_NO_AUTO_START, -1, NULL, &err);
-       if (!result) {
-               if (err) {
-                       ErrPrint("acquire Error: %s\n", err->message);
-                       g_error_free(err);
-               }
-
-               ErrPrint("Failed to send 'acquire'\n");
-               return -EIO;
-       }
-
-       g_variant_unref(result);
-       sent = 1;
-       return 0;
-}
-
-static inline int send_release(void)
-{
-       GVariant *result;
-       GError *err;
-
-       err = NULL;
-       result = g_dbus_proxy_call_sync(s_info.proxy, "release", g_variant_new("(i)", getpid()),
-                                       G_DBUS_CALL_FLAGS_NO_AUTO_START, -1, NULL, &err);
-
-       if (!result) {
-               if (err) {
-                       ErrPrint("release Error: %s\n", err->message);
-                       g_error_free(err);
-               }
-
-               return -EIO;
-       }
-
-       g_variant_unref(result);
-       return 0;
-}
-
-static void on_signal(GDBusProxy *proxy, gchar *sender, gchar *signame, GVariant *param, gpointer data)
-{
-       DbgPrint("Sender: %s\n", sender);
-       DbgPrint("SigName: %s\n", signame);
-}
-
-static void done_cb(GDBusProxy *proxy, GAsyncResult *res, void *data)
-{
-       GVariant *result;
-       GError *err;
-       int r;
-       struct cmd_item *item;
-
-       item = data;
-
-       err = NULL;
-       result = g_dbus_proxy_call_finish(proxy, res, &err);
-       if (!result) {
-               if (err) {
-                       ErrPrint("%s Error: %s\n", item->funcname, err->message);
-                       g_error_free(err);
-               }
-
-               /*! \NOTE:
-                * Release resource even if
-                * we failed to finish the method call
-                */
-               item->ttl--;
-               if (item->ttl > 0) {
-                       s_info.cmd_list = dlist_prepend(s_info.cmd_list, item);
-                       return;
-               }
-
-               goto out;
-       }
-
-       g_variant_get(result, "(i)", &r);
-       g_variant_unref(result);
-
-       DbgPrint("%s Returns: %d, handler: %p\n", item->funcname, r, item->handler);
-       if (item->ret_cb)
-               item->ret_cb(item->handler, r, item->data);
-
-out:
-       if (item->handler)
-               lb_unref(item->handler);
-       /* Decreate the item->param's refernece counter now. */
-       g_variant_unref(item->param);
-       free(item->funcname);
-       free(item);
-}
-
-static gboolean dbus_reconnect_cb(gpointer user_data)
-{
-       dbus_init();
-       s_info.recon_timer = 0;
-       return FALSE;
-}
-
-static gboolean cmd_consumer(gpointer user_data)
-{
-       struct dlist *l;
-       struct cmd_item *item;
-
-       if (!s_info.proxy) {
-               ErrPrint("Proxy is not valid yet, try again after 10ms\n");
-               return TRUE;
-       }
-
-       if (send_acquire() != 0) {
-               ErrPrint("Server is not ready to make connection, try again after 10ms\n");
-               return TRUE;
-       }
-
-       l = dlist_nth(s_info.cmd_list, 0);
-       if (l) {
-               item = dlist_data(l);
-
-               /*!
-                * \NOTE:
-                * Item will be deleted in the "done_cb"
-                *
-                * item->param be release by the g_dbus_proxy_call
-                * so to use it again from the done_cb function,
-                * increate the reference counter of the item->param
-                */
-               g_dbus_proxy_call(s_info.proxy,
-                       item->funcname,
-                       g_variant_ref(item->param),
-                       G_DBUS_CALL_FLAGS_NO_AUTO_START,
-                       -1, NULL, (GAsyncReadyCallback)done_cb, item);
-
-               s_info.cmd_list = dlist_remove(s_info.cmd_list, l);
-       }
-
-       if (!s_info.cmd_list) {
-               s_info.cmd_timer = 0;
-               return FALSE;
-       }
-
-       return TRUE;
-}
-
 static void method_fault_package(GDBusMethodInvocation *inv, GVariant *param)
 {
        const char *pkgname;
        const char *filename;
        const char *function;
+       char *_pkgname;
+       char *_filename;
+       char *_function;
 
        g_variant_get(param, "(&s&s&s)", &pkgname, &filename, &function);
 
-       DbgPrint("%s(%s) is deactivated\n", pkgname, filename);
-       lb_invoke_fault_handler("deactivated", pkgname, filename, function);
+       _pkgname = strdup(pkgname);
+       _filename = strdup(filename);
+       _function = strdup(function);
 
+       DbgPrint("%s(%s) is deactivated\n", pkgname, filename);
        g_dbus_method_invocation_return_value(inv, g_variant_new("(i)", 0));
+
+       lb_invoke_fault_handler("deactivated", _pkgname, _filename, _function);
+       free(_pkgname);
+       free(_filename);
+       free(_function);
 }
 
 static void method_pd_updated(GDBusMethodInvocation *inv, GVariant *param)
@@ -284,25 +131,19 @@ static void method_pd_updated(GDBusMethodInvocation *inv, GVariant *param)
 
        handler = lb_find_livebox(pkgname, filename);
        if (!handler) {
-               ret = -ENOENT;
-               goto out;
-       }
-
-       if (handler->magic != 0xbeefbeef) {
-               ErrPrint("Handler is not valid. magic: %lu\n", handler->magic);
-               ret = 0;
-               goto out;
+               g_dbus_method_invocation_return_value(inv, g_variant_new("(i)", -ENOENT));
+               return;
        }
 
-       if (handler->deleted != NOT_DELETED) {
+       if (handler->state == DELETE) {
                /*!
                 * \note
                 * This handler is already deleted by the user.
                 * So don't try to notice anything about this anymore.
                 * Just ignore all events.
                 */
-               ret = 0;
-               goto out;
+               g_dbus_method_invocation_return_value(inv, g_variant_new("(i)", 0));
+               return;
        }
 
        DbgPrint("Size of a PD is updated to [%dx%d]\n", pd_w, pd_h);
@@ -310,6 +151,7 @@ static void method_pd_updated(GDBusMethodInvocation *inv, GVariant *param)
 
        if (lb_text_pd(handler)) {
                ret = parse_desc(handler, filename, 1);
+               g_dbus_method_invocation_return_value(inv, g_variant_new("(i)", ret));
        } else {
                if (lb_get_pd_fb(handler)) {
                        lb_update_pd_fb(handler, pd_w, pd_h);
@@ -319,21 +161,22 @@ static void method_pd_updated(GDBusMethodInvocation *inv, GVariant *param)
                         * The return value of lb_get_pd_fb function can be change,
                         * So call lb_get_pd_fb again to get newly allocated pd buffer
                         */
-                       fb_sync(lb_get_pd_fb(handler));
+                       ret = fb_sync(lb_get_pd_fb(handler));
+                       if (ret < 0) {
+                               g_dbus_method_invocation_return_value(inv, g_variant_new("(i)", ret));
+                               return;
+                       }
                }
 
+               g_dbus_method_invocation_return_value(inv, g_variant_new("(i)", 0));
                lb_invoke_event_handler(handler, "pd,updated");
-               ret = 0;
        }
-out:
-       g_dbus_method_invocation_return_value(inv, g_variant_new("(i)", ret));
 }
 
 static void method_lb_updated(GDBusMethodInvocation *inv, GVariant *param)
 {
        const char *pkgname;
        const char *filename;
-       int ret;
        struct livebox *handler;
        int lb_w;
        int lb_h;
@@ -345,64 +188,71 @@ static void method_lb_updated(GDBusMethodInvocation *inv, GVariant *param)
 
        handler = lb_find_livebox(pkgname, filename);
        if (!handler) {
-               ret = -ENOENT;
-               goto out;
-       }
-
-       if (handler->magic != 0xbeefbeef) {
-               ErrPrint("Handler is not valid. magic: %lu\n", handler->magic);
-               ret = 0;
-               goto out;
+               g_dbus_method_invocation_return_value(inv, g_variant_new("(i)", -ENOENT));
+               return;
        }
 
-       if (handler->deleted != NOT_DELETED) {
+       if (handler->state == DELETE) {
                /*!
                 * \note
                 * Already deleted by the user.
                 * Don't try to notice anything with this, Just ignore all events
                 * Beacuse the user doesn't wants know about this anymore
                 */
-               ret = 0;
-               goto out;
+               g_dbus_method_invocation_return_value(inv, g_variant_new("(i)", 0));
+               return;
        }
 
        lb_set_priority(handler, priority);
        lb_set_size(handler, lb_w, lb_h);
 
        if (lb_text_lb(handler)) {
+               int ret;
                ret = parse_desc(handler, filename, 0);
+               g_dbus_method_invocation_return_value(inv, g_variant_new("(i)", ret));
        } else {
                if (lb_get_lb_fb(handler)) {
+                       int ret;
                        lb_update_lb_fb(handler, lb_w, lb_h);
-                       fb_sync(lb_get_lb_fb(handler));
+                       ret = fb_sync(lb_get_lb_fb(handler));
+                       if (ret < 0) {
+                               g_dbus_method_invocation_return_value(inv, g_variant_new("(i)", ret));
+                               return;
+                       }
                }
 
                DbgPrint("%s(%s) is updated\n", handler->pkgname, handler->filename);
+               g_dbus_method_invocation_return_value(inv, g_variant_new("(i)", 0));
+
                lb_invoke_event_handler(handler, "lb,updated");
-               ret = 0;
        }
-
-out:
-       g_dbus_method_invocation_return_value(inv, g_variant_new("(i)", ret));
 }
 
 static void method_created(GDBusMethodInvocation *inv, GVariant *param)
 {
        struct livebox *handler;
-       const char *pkgname;
-       const char *filename;
+
        int lb_w;
        int lb_h;
        int pd_w;
        int pd_h;
+       const char *pkgname;
+       const char *filename;
+
        const char *content;
        const char *cluster;
        const char *category;
        const char *lb_fname;
        const char *pd_fname;
+
+       char *_content;
+       char *_cluster;
+       char *_category;
+       char *_lb_fname;
+       char *_pd_fname;
+
        double timestamp;
        int auto_launch;
-       int ret;
        double priority;
        int size_list;
        int user;
@@ -435,53 +285,44 @@ static void method_created(GDBusMethodInvocation *inv, GVariant *param)
                handler = lb_new_livebox(pkgname, filename);
                if (!handler) {
                        ErrPrint("Failed to create a new livebox\n");
-                       ret = -EFAULT;
-                       goto out;
+                       g_dbus_method_invocation_return_value(inv, g_variant_new("(i)", -EFAULT));
+                       return;
                }
        } else {
-               if (handler->magic != 0xbeefbeef) {
-                       ErrPrint("Handler is not valid. magic: %lu\n", handler->magic);
-                       ret = -EINVAL;
-                       goto out;
-               }
-
                lb_set_filename(handler, filename);
 
-               if (handler->deleted != NOT_DELETED) {
-                       /*!
-                        * \note
-                        * before get this created event,
-                        * user delete this already.
-                        * So user doesn't wants to know about this anymore
-                        * just ignore created events
-                        */
-
-                       if (handler->deleted == DELETE_ALL)
-                               lb_send_delete(handler);
-
-                       /*!
-                        * \note
-                        * This will make the method_delete function could not 
-                        * find the handler object if the handler->deleted == DELETE_ALL
-                        * So the method_delete function will return -ENOENT
-                        */
-                       lb_unref(handler);
-                       ret = 0;
-                       goto out;
+               if (handler->state == DELETE) {
+                       lb_send_delete(handler);
+                       g_dbus_method_invocation_return_value(inv, g_variant_new("(i)", 0));
+                       return;
                }
        }
 
+       _lb_fname = strdup(lb_fname);
+       _pd_fname = strdup(pd_fname);
+       _cluster = strdup(cluster);
+       _category = strdup(category);
+       _content = strdup(content);
+       g_dbus_method_invocation_return_value(inv, g_variant_new("(i)", 0));
+
        lb_set_size(handler, lb_w, lb_h);
-       lb_set_lb_fb(handler, lb_fname);
+       lb_set_lb_fb(handler, _lb_fname);
+       free(_lb_fname);
 
        lb_set_pdsize(handler, pd_w, pd_h);
-       lb_set_pd_fb(handler, pd_fname);
+       lb_set_pd_fb(handler, _pd_fname);
+       free(_pd_fname);
 
        lb_set_priority(handler, priority);
 
        lb_set_size_list(handler, size_list);
-       lb_set_group(handler, cluster, category);
-       lb_set_content(handler, content);
+       lb_set_group(handler, _cluster, _category);
+       free(_cluster);
+       free(_category);
+
+       lb_set_content(handler, _content);
+       free(_content);
+
        lb_set_user(handler, user);
 
        lb_set_auto_launch(handler, auto_launch);
@@ -490,47 +331,34 @@ static void method_created(GDBusMethodInvocation *inv, GVariant *param)
        lb_set_period(handler, period);
 
        lb_invoke_event_handler(handler, "lb,created");
-
-       ret = 0;
-out:
-       g_dbus_method_invocation_return_value(inv, g_variant_new("(i)", ret));
 }
 
 static void method_deleted(GDBusMethodInvocation *inv, GVariant *param)
 {
        const char *pkgname;
        const char *filename;
+       double timestamp;
        struct livebox *handler;
-       int ret;
 
-       g_variant_get(param, "(&s&s)", &pkgname, &filename);
+       g_variant_get(param, "(&s&sd)", &pkgname, &filename, &timestamp);
 
-       handler = lb_find_livebox(pkgname, filename);
+       handler = lb_find_livebox_by_timestamp(timestamp);
        if (!handler) {
                /*!
                 * \note
                 * This can be happens only if the user delete a livebox
                 * right after create it before receive created event.
                 */
-               ret = -ENOENT;
-               goto out;
+               g_dbus_method_invocation_return_value(inv, g_variant_new("(i)", -ENOENT));
+               return;
        }
 
-       if (handler->magic != 0xbeefbeef) {
-               ErrPrint("Handler is not valid. magic: %lu\n", handler->magic);
-               ret = -EINVAL;
-               goto out;
-       }
+       DbgPrint("[%p] %s(%s) is deleted\n", handler, pkgname, filename);
+       g_dbus_method_invocation_return_value(inv, g_variant_new("(i)", 0));
 
-       DbgPrint("%s(%s) is deleted\n", pkgname, filename);
        lb_invoke_event_handler(handler, "lb,deleted");
-
        /* Just try to delete it, if a user didn't remove it from the live box list */
        lb_unref(handler);
-
-       ret = 0;
-out:
-       g_dbus_method_invocation_return_value(inv, g_variant_new("(i)", ret));
 }
 
 static void method_handler(GDBusConnection *conn,
@@ -580,9 +408,7 @@ static void method_handler(GDBusConnection *conn,
                                break;
                        }
 
-                       DbgPrint("Call %s [BEGIN]\n", method_table[i].name);
                        method_table[i].method(invocation, param);
-                       DbgPrint("Call %s [END]\n", method_table[i].name);
                        break;
                }
        }
@@ -638,8 +464,41 @@ errout:
        return;
 }
 
+static inline void unregister_dbus_object(void)
+{
+       GDBusConnection *conn;
+
+       conn = g_dbus_proxy_get_connection(s_info.proxy);
+       if (!conn)
+               return;
+
+       /* FIXME: Do I really need to do this? */
+       g_dbus_connection_unregister_object(conn, s_info.reg_id);
+       s_info.reg_id = 0;
+
+       if (s_info.node_info) {
+               g_dbus_node_info_unref(s_info.node_info);
+               s_info.node_info = NULL;
+       }
+
+}
+
+static void on_signal(GDBusProxy *proxy, gchar *sender, gchar *signame, GVariant *param, gpointer data)
+{
+       DbgPrint("Sender: %s\n", sender);
+       DbgPrint("SigName: %s\n", signame);
+}
+
+static gboolean dbus_reconnect_cb(gpointer user_data)
+{
+       dbus_init();
+       s_info.recon_timer = 0;
+       return FALSE;
+}
+
 static void got_proxy_cb(GObject *obj, GAsyncResult *res, gpointer user_data)
 {
+       GVariant *param;
        GError *err;
 
        err = NULL;
@@ -658,76 +517,15 @@ static void got_proxy_cb(GObject *obj, GAsyncResult *res, gpointer user_data)
        g_signal_connect(s_info.proxy, "g-signal", G_CALLBACK(on_signal), NULL);
        register_dbus_object();
 
-       if (s_info.cmd_list && !s_info.cmd_timer) {
-               s_info.cmd_timer = g_timeout_add(10, cmd_consumer, NULL);
-               if (!s_info.cmd_timer)
-                       ErrPrint("Failed to add timer\n");
-       }
-}
-
-int dbus_sync_command(const char *funcname, GVariant *param)
-{
-       GVariant *result;
-       GError *err;
-       int ret;
-
-       err = NULL;
-       result = g_dbus_proxy_call_sync(s_info.proxy, funcname, param,
-                                       G_DBUS_CALL_FLAGS_NO_AUTO_START, -1, NULL, &err);
-       if (!result) {
-               if (err) {
-                       ErrPrint("funcname: %s, Error: %s\n", funcname, err->message);
-                       g_error_free(err);
-               }
-
-               return -EIO;
-       }
-
-       g_variant_get(result, "(i)", &ret);
-       g_variant_unref(result);
-
-       return ret;
-}
-
-/*!
- * \note
- * "handler" could be NULL
- */
-int dbus_push_command(struct livebox *handler, const char *funcname, GVariant *param, void (*ret_cb)(struct livebox *handler, int ret, void *data), void *data)
-{
-       struct cmd_item *item;
-
-       item = malloc(sizeof(*item));
-       if (!item) {
-               ErrPrint("Failed to allocate mem for cmd_item\n");
-               return -ENOMEM;
-       }
-
-       item->funcname = strdup(funcname);
-       if (!item->funcname) {
-               ErrPrint("Failed to allocate mem for funcname - %s\n", funcname);
-               free(item);
-               return -ENOMEM;
-       }
-
-       if (handler)
-               lb_ref(handler);
-
-       item->param = param;
-       item->handler = handler;
-       item->ret_cb = ret_cb;
-       item->data = data;
-       item->ttl = DEFAULT_TTL;
-
-       s_info.cmd_list = dlist_append(s_info.cmd_list, item);
-
-       if (!s_info.cmd_timer && s_info.proxy) {
-               s_info.cmd_timer = g_timeout_add(10, cmd_consumer, NULL);
-               if (!s_info.cmd_timer)
-                       ErrPrint("Failed to add timer\n");
+       param = g_variant_new("(i)", getpid());
+       if (!param) {
+               unregister_dbus_object();
+               g_object_unref(s_info.proxy);
+               s_info.proxy = NULL;
+               return;
        }
 
-       return 0;
+       master_rpc_sync_request(NULL, "acquire", param);
 }
 
 int dbus_init(void)
@@ -746,26 +544,18 @@ int dbus_init(void)
 
 int dbus_fini(void)
 {
-       if (s_info.proxy) {
-               GDBusConnection *conn;
-
-               send_release();
+       GVariant *param;
 
-               conn = g_dbus_proxy_get_connection(s_info.proxy);
-               if (conn) {
-                       /* FIXME: Do I really need to do this? */
-                       g_dbus_connection_unregister_object(conn, s_info.reg_id);
-                       s_info.reg_id = 0;
-               }
+       if (!s_info.proxy)
+               return 0;
 
-               g_object_unref(s_info.proxy);
-               s_info.proxy = NULL;
-       }
+       param = g_variant_new("(i)", getpid());
+       if (param)
+               master_rpc_sync_request(NULL, "release", param);
 
-       if (s_info.node_info) {
-               g_dbus_node_info_unref(s_info.node_info);
-               s_info.node_info = NULL;
-       }
+       unregister_dbus_object();
+       g_object_unref(s_info.proxy);
+       s_info.proxy = NULL;
 
        return 0;
 }
index af61b97..efb8259 100644 (file)
@@ -20,7 +20,6 @@ struct fb_info {
        int w;
        int h;
        int bufsz;
-       int fd;
        void *buffer;
        int created;
 };
@@ -51,23 +50,34 @@ static inline struct flock *file_lock(short type, short whence)
 
 int fb_sync(struct fb_info *info)
 {
-       if (info->created != 1)
+       int fd;
+
+       if (!info || info->created != 1)
                return -EINVAL;
 
-//     fcntl(info->fd, F_SETLKW, file_lock(F_RDLCK, SEEK_SET));
-       if (lseek(info->fd, 0l, SEEK_SET) != 0) {
-               ErrPrint("seek: %s\n", strerror(errno));
-//             fcntl(info->fd, F_SETLKW, file_lock(F_UNLCK, SEEK_SET));
+       fd = open(info->filename, O_RDONLY);
+       if (fd < 0) {
+               ErrPrint("Open: %s\n", strerror(errno));
                return -EIO;
        }
 
-       if (read(info->fd, info->buffer, info->bufsz) != info->bufsz) {
+//     fcntl(info->fd, F_SETLKW, file_lock(F_RDLCK, SEEK_SET));
+//     if (lseek(fd, 0l, SEEK_SET) != 0) {
+//             ErrPrint("seek: %s\n", strerror(errno));
+//             fcntl(info->fd, F_SETLKW, file_lock(F_UNLCK, SEEK_SET));
+//             close(fd);
+//             return -EIO;
+//     }
+
+       if (read(fd, info->buffer, info->bufsz) != info->bufsz) {
                ErrPrint("read: %s\n", strerror(errno));
 //             fcntl(info->fd, F_SETLKW, file_lock(F_UNLCK, SEEK_SET));
+               close(fd);
                return -EIO;
        }
 //     fcntl(info->fd, F_SETLKW, file_lock(F_UNLCK, SEEK_SET));
 
+       close(fd);
        return 0;
 }
 
@@ -91,7 +101,6 @@ struct fb_info *fb_create(const char *filename, int w, int h)
                return NULL;
        }
 
-       info->fd = -EINVAL;
        info->bufsz = -EINVAL;
        info->buffer = NULL;
        info->w = w;
@@ -109,32 +118,11 @@ int fb_create_buffer(struct fb_info *info)
        if (info->created == 1)
                return -EALREADY;
 
-       info->fd = open(info->filename, O_RDWR);
-       if (info->fd < 0) {
-               ErrPrint("Open: %s\n", strerror(errno));
-               return -EIO;
-       }
-
        info->bufsz = info->w * info->h * sizeof(int);
 
-       /*
-       info->bufsz = lseek(info->fd, 0l, SEEK_END);
-       if (info->bufsz < 0) {
-               ErrPrint("lseek: %s\n", strerror(errno));
-               close(info->fd);
-               info->fd = -EINVAL;
-               return -EIO;
-       }
-
-       lseek(info->fd, 0l, SEEK_SET);
-       DbgPrint("Buffer size: %ld\n", info->bufsz);
-       */
-
        info->buffer = calloc(1, info->bufsz);
        if (!info->buffer) {
                ErrPrint("calloc: %s\n", strerror(errno));
-               close(info->fd);
-               info->fd = -EINVAL;
                return -ENOMEM;
        }
 
@@ -150,11 +138,6 @@ int fb_destroy_buffer(struct fb_info *info)
        if (info->created != 1)
                return -EINVAL;
 
-       if (info->fd > 0) {
-               close(info->fd);
-               info->fd = -EINVAL;
-       }
-
        if (info->buffer) {
                free(info->buffer);
                info->buffer = NULL;
index bd15310..b22b4dc 100644 (file)
@@ -16,6 +16,7 @@
 #include "dlist.h"
 #include "util.h"
 #include "dbus.h"
+#include "master_rpc.h"
 
 #define EAPI __attribute__((visibility("default")))
 #define EVENT_INTERVAL 0.05f
@@ -24,7 +25,7 @@
 FILE *__file_log_fp;
 #endif
 
-struct info {
+static struct info {
        struct dlist *livebox_list;
        struct dlist *event_list;
        struct dlist *fault_list;
@@ -54,7 +55,7 @@ static int update_event_timestamp(struct livebox *handler)
        double now;
        double interval;
 
-       now = util_get_timestamp();
+       now = util_timestamp();
        interval = now - handler->event_timestamp;
 
        if (interval < EVENT_INTERVAL)
@@ -64,98 +65,195 @@ static int update_event_timestamp(struct livebox *handler)
        return 0;
 }
 
-static void event_ret_cb(struct livebox *handler, int ret, void *data)
+static void mouse_event_cb(struct livebox *handler, GVariant *result, void *data)
 {
-       if (handler->magic != 0xbeefbeef)
+       int ret;
+
+       if (!result) {
+               lb_invoke_event_handler(handler, "event,ignored");
                return;
+       }
+
+       g_variant_get(result, "(i)", &ret);
+       g_variant_unref(result);
 
-       if (handler->deleted != NOT_DELETED)
+       if (ret < 0)
+               lb_invoke_event_handler(handler, "event,ingored");
+}
+
+static void resize_cb(struct livebox *handler, GVariant *result, void *data)
+{
+       int ret;
+
+       if (!result) {
+               lb_invoke_event_handler(handler, "event,ignored");
                return;
+       }
 
-       if (ret < 0) {
+       g_variant_get(result, "(i)", &ret);
+       g_variant_unref(result);
+
+       if (ret < 0)
                lb_invoke_event_handler(handler, "event,ignored");
-       } else {
+}
+
+static void clicked_cb(struct livebox *handler, GVariant *result, void *data)
+{
+       int ret;
+
+       if (!result) {
+               lb_invoke_event_handler(handler, "event,ignored");
+               return;
        }
+
+       g_variant_get(result, "(i)", &ret);
+       g_variant_unref(result);
+
+       if (ret < 0)
+               lb_invoke_event_handler(handler, "event,ignored");
+               
 }
 
-static void period_ret_cb(struct livebox *handler, int ret, void *data)
+static void text_signal_cb(struct livebox *handler, GVariant *result, void *data)
 {
-       double *period;
+       int ret;
 
-       if (handler->magic != 0xbeefbeef)
+       if (!result) {
+               lb_invoke_event_handler(handler, "event,ignored");
                return;
+       }
+
+       g_variant_get(result, "(i)", &ret);
+       g_variant_unref(result);
 
-       if (handler->deleted != NOT_DELETED) {
+       if (ret < 0)
+               lb_invoke_event_handler(handler, "event,ignored");
+
+       return;
+}
+
+static void set_group_cb(struct livebox *handler, GVariant *result, void *data)
+{
+       int ret;
+
+       if (!result) {
+               lb_invoke_event_handler(handler, "event,ignored");
+               return;
+       }
+
+       g_variant_get(result, "(i)", &ret);
+       g_variant_unref(result);
+
+       if (ret < 0)
+               lb_invoke_event_handler(handler, "event,ignored");
+
+       return;
+}
+
+static void period_ret_cb(struct livebox *handler, GVariant *result, void *data)
+{
+       double *period;
+       int ret;
+
+       if (!result) {
                free(data);
                return;
        }
 
+       g_variant_get(result, "(i)", &ret);
+       g_variant_unref(result);
+
        period = (double *)data;
 
-       if (ret < 0) {
+       if (ret < 0)
                lb_invoke_event_handler(handler, "event,ignored");
-       } else if (ret == 0) {
+       else if (ret == 0)
                lb_set_period(handler, *period);
-       } else {
+       else
                ErrPrint("Unknown returns %d\n", ret);
-       }
 
        free(data);
 }
 
-static void del_ret_cb(struct livebox *handler, int ret, void *data)
+static void del_ret_cb(struct livebox *handler, GVariant *result, void *data)
 {
-       /*
-       lb_invoke_event_handler(handler, "lb,deleted");
-       livebox_del(handler, 0);
-       */
-}
+       int ret;
 
-static void new_ret_cb(struct livebox *handler, int ret, void *data)
-{
-       if (handler->magic != 0xbeefbeef)
+       if (!result) {
+               lb_invoke_event_handler(handler, "event,ignored");
                return;
+       }
 
-       if (handler->deleted != NOT_DELETED)
-               return;
+       g_variant_get(result, "(i)", &ret);
+       g_variant_unref(result);
 
        if (ret < 0) {
-               /*!
-                * \note
-                * It means the current instance is not created,
-                * so user has to know about this.
-                * notice it to user using "deleted" event.
-                */
-               lb_invoke_event_handler(handler, "lb,deleted");
-               lb_unref(handler);
+               lb_invoke_event_handler(handler, "event,ignored");
+               return;
        }
-       /* lb,created will be receive from the master via dbus */
 }
 
-static void pd_created_cb(struct livebox *handler, int ret, void *data)
+static void new_ret_cb(struct livebox *handler, GVariant *result, void *data)
 {
-       if (handler->magic != 0xbeefbeef)
+       int ret;
+
+       if (!result)
                return;
 
-       if (handler->deleted != NOT_DELETED)
+       g_variant_get(result, "(i)", &ret);
+       g_variant_unref(result);
+
+       if (ret >= 0)
                return;
 
-       if (ret != 0) {
+       /*!
+        * \note
+        * It means the current instance is not created,
+        * so user has to know about this.
+        * notice it to user using "deleted" event.
+        */
+       lb_invoke_event_handler(handler, "lb,deleted");
+       lb_unref(handler);
+}
+
+static void pd_created_cb(struct livebox *handler, GVariant *result, void *data)
+{
+       int ret;
+
+       if (!result) {
+               lb_invoke_event_handler(handler, "pd,create,failed");
+               return;
+       }
+
+       g_variant_get(result, "(i)", &ret);
+       g_variant_unref(result);
+
+       if (ret < 0) {
                lb_invoke_event_handler(handler, "pd,create,failed");
                return;
        }
 
        ret = fb_create_buffer(handler->pd_fb);
        if (ret < 0)
-               ErrPrint("Failed to create a PD buffer\n");
-
-       lb_invoke_event_handler(handler, "pd,created");
+               lb_invoke_event_handler(handler, "pd,create,failed");
+       else
+               lb_invoke_event_handler(handler, "pd,created");
 }
 
-static void activated_cb(struct livebox *handler, int ret, void *data)
+static void activated_cb(struct livebox *handler, GVariant *result, void *data)
 {
+       int ret;
        char *pkgname = data;
 
+       if (!result) {
+               lb_invoke_fault_handler("activation,failed", pkgname, NULL, NULL);
+               free(pkgname);
+               return;
+       }
+
+       g_variant_get(result, "(i)", &ret);
+       g_variant_unref(result);
+
        if (ret == 0)
                lb_invoke_fault_handler("activated", pkgname, NULL, NULL);
        else if (ret == -EINVAL)
@@ -166,25 +264,38 @@ static void activated_cb(struct livebox *handler, int ret, void *data)
        free(pkgname);
 }
 
-static void pd_destroy_cb(struct livebox *handler, int ret, void *data)
+static void pd_destroy_cb(struct livebox *handler, GVariant *result, void *data)
 {
-       if (handler->magic != 0xbeefbeef)
+       int ret;
+
+       if (!result) {
+               lb_invoke_event_handler(handler, "event,ignored");
                return;
+       }
 
-       if (handler->deleted != NOT_DELETED)
+       g_variant_get(result, "(i)", &ret);
+       g_variant_unref(result);
+
+       if (ret < 0) {
+               lb_invoke_event_handler(handler, "event,ignored");
                return;
+       }
 
        fb_destroy_buffer(handler->pd_fb);
        lb_invoke_event_handler(handler, "pd,deleted");
 }
 
-static void pinup_done_cb(struct livebox *handler, int ret, void *data)
+static void pinup_done_cb(struct livebox *handler, GVariant *result, void *data)
 {
-       if (handler->magic != 0xbeefbeef)
-               return;
+       int ret;
 
-       if (handler->deleted != NOT_DELETED)
+       if (!result) {
+               lb_invoke_event_handler(handler, "event,ignored");
                return;
+       }
+
+       g_variant_get(result, "(i)", &ret);
+       g_variant_unref(result);
 
        if (ret != 0) {
                ErrPrint("Pinup is not changed: %s\n", strerror(ret));
@@ -203,14 +314,14 @@ static int send_mouse_event(struct livebox *handler, const char *event, double x
 
        DbgPrint("Send event [%s] with %lfx%lf\n", event, x, y);
 
-       timestamp = util_get_timestamp();
+       timestamp = util_timestamp();
        param = g_variant_new("(ssiiddd)", handler->pkgname, handler->filename,
                                                handler->pd_w, handler->pd_h,
                                                timestamp, x, y);
        if (!param)
                return -EFAULT;
 
-       ret = dbus_push_command(handler, event, param, event_ret_cb, NULL);
+       ret = master_rpc_async_request(handler, event, param, mouse_event_cb, NULL);
        if (ret < 0)
                g_variant_unref(param);
 
@@ -243,6 +354,9 @@ EAPI struct livebox *livebox_add(const char *pkgname, const char *content, const
        GVariant *param;
        int ret;
 
+       DbgPrint("pkgname[%s], content[%s], cluster[%s], category[%s], period[%lf]\n",
+                                               pkgname, content, cluster, category, period);
+
        if (!pkgname || !cluster || !category)
                return NULL;
 
@@ -294,10 +408,9 @@ EAPI struct livebox *livebox_add(const char *pkgname, const char *content, const
        /* Cluster infomration is not determined yet */
        handler->nr_of_sizes = 0x01;
 
-       handler->timestamp = util_get_timestamp();
+       handler->timestamp = util_timestamp();
        handler->period = period;
-       lb_ref(handler);
-       handler->magic = 0xbeefbeef;
+       handler->is_user = 1;
 
        s_info.livebox_list = dlist_append(s_info.livebox_list, handler);
 
@@ -311,7 +424,7 @@ EAPI struct livebox *livebox_add(const char *pkgname, const char *content, const
                return NULL;
        }
 
-       ret = dbus_push_command(handler, "new", param, new_ret_cb, NULL);
+       ret = master_rpc_async_request(handler, "new", param, new_ret_cb, NULL);
        if (ret < 0) {
                free(handler->category);
                free(handler->cluster);
@@ -322,36 +435,30 @@ EAPI struct livebox *livebox_add(const char *pkgname, const char *content, const
                return NULL;
        }
 
-       return handler;
+       handler->state = CREATE;
+       return lb_ref(handler);
 }
 
 EAPI double livebox_period(struct livebox *handler)
 {
-       if (!handler) {
-               ErrPrint("Handler is NIL\n");
+       if (!handler || handler->state == DELETE || !handler->filename) {
+               ErrPrint("Handler is not valid\n");
                return 0.0f;
        }
 
-       if (handler->magic != 0xbeefbeef || handler->deleted != NOT_DELETED || !handler->filename)
-               return 0.0f;
-
        return handler->period;
 }
 
 EAPI int livebox_set_period(struct livebox *handler, double period)
 {
        GVariant *param;
-       int ret;
        double *period_heap;
 
-       if (!handler) {
-               ErrPrint("Handler is NIL\n");
+       if (!handler || !handler->filename || handler->state == DELETE) {
+               ErrPrint("Handler is not valid\n");
                return -EINVAL;
        }
 
-       if (handler->magic != 0xbeefbeef || handler->deleted != NOT_DELETED || !handler->filename)
-               return -EINVAL;
-
        if (handler->period == period)
                return 0;
 
@@ -366,27 +473,22 @@ EAPI int livebox_set_period(struct livebox *handler, double period)
        }
 
        *period_heap = period;
-       ret = dbus_push_command(handler, "set_period", param, period_ret_cb, (void *)period_heap);
-       if (ret < 0) {
-               g_variant_unref(param);
-               free(period_heap);
-               return ret;
-       }
-
-       return 0;
+       return master_rpc_async_request(handler, "set_period", param, period_ret_cb, (void *)period_heap);
 }
 
-EAPI int livebox_del(struct livebox *handler, int server)
+EAPI int livebox_del(struct livebox *handler, int unused)
 {
        if (!handler) {
                ErrPrint("Handler is NIL\n");
                return -EINVAL;
        }
 
-       if (handler->magic != 0xbeefbeef || handler->deleted != NOT_DELETED)
+       if (handler->state == DELETE) {
+               ErrPrint("Handler is already deleted\n");
                return -EINVAL;
+       }
 
-       handler->deleted = server ? DELETE_ALL : DELETE_THIS;
+       handler->state = DELETE;
 
        if (!handler->filename) {
                /*!
@@ -399,11 +501,7 @@ EAPI int livebox_del(struct livebox *handler, int server)
                return 0;
        }
 
-       if (server)
-               return lb_send_delete(handler);
-
-       lb_unref(handler);
-       return 0;
+       return lb_send_delete(handler);
 }
 
 EAPI int livebox_fault_handler_set(int (*cb)(const char *, const char *, const char *, const char *, void *), void *data)
@@ -488,55 +586,53 @@ EAPI void *livebox_event_handler_unset(int (*cb)(struct livebox *, const char *,
 EAPI int livebox_resize(struct livebox *handler, int w, int h)
 {
        GVariant *param;
-       int ret;
 
        if (!handler) {
                ErrPrint("Handler is NIL\n");
                return -EINVAL;
        }
 
-       if (handler->magic != 0xbeefbeef || handler->deleted != NOT_DELETED || !handler->filename)
+       if (handler->state == DELETE || !handler->filename) {
+               ErrPrint("Handler is not valid\n");
                return -EINVAL;
+       }
 
        param = g_variant_new("(ssii)", handler->pkgname, handler->filename, w, h);
-       if (!param)
+       if (!param) {
+               ErrPrint("Failed to build param\n");
                return -EFAULT;
+       }
 
-       ret = dbus_push_command(handler, "resize", param, event_ret_cb, NULL);
-       if (ret < 0)
-               g_variant_unref(param);
-
-       return ret;
+       return master_rpc_async_request(handler, "resize", param, resize_cb, NULL);
 }
 
 EAPI int livebox_click(struct livebox *handler, double x, double y)
 {
        GVariant *param;
        double timestamp;
-       int ret;
 
        if (!handler) {
                ErrPrint("Handler is NIL\n");
                return -EINVAL;
        }
 
-       if (handler->magic != 0xbeefbeef || handler->deleted != NOT_DELETED || !handler->filename)
+       if (handler->state == DELETE || !handler->filename) {
+               ErrPrint("Handler is not valid\n");
                return -EINVAL;
+       }
 
        if (handler->auto_launch)
                if (aul_launch_app(handler->pkgname, NULL) < 0)
                        ErrPrint("Failed to launch app %s\n", handler->pkgname);
 
-       timestamp = util_get_timestamp();
+       timestamp = util_timestamp();
        param = g_variant_new("(sssddd)", handler->pkgname, handler->filename, "clicked", timestamp, x, y);
-       if (!param)
+       if (!param) {
+               ErrPrint("Failed to build param\n");
                return -EFAULT;
+       }
 
-       ret = dbus_push_command(handler, "clicked", param, event_ret_cb, NULL);
-       if (ret < 0)
-               g_variant_unref(param);
-
-       return ret;
+       return master_rpc_async_request(handler, "clicked", param, clicked_cb, NULL);
 }
 
 EAPI int livebox_has_pd(struct livebox *handler)
@@ -546,8 +642,10 @@ EAPI int livebox_has_pd(struct livebox *handler)
                return -EINVAL;
        }
 
-       if (handler->magic != 0xbeefbeef || handler->deleted != NOT_DELETED || !handler->filename)
+       if (handler->state == DELETE || !handler->filename) {
+               ErrPrint("Handler is not valid\n");
                return -EINVAL;
+       }
 
        DbgPrint("%s(%s) has PD: %d\n", handler->pkgname, handler->filename, !!handler->pd_fb);
        return !!handler->pd_fb;
@@ -560,8 +658,10 @@ EAPI int livebox_pd_is_created(struct livebox *handler)
                return -EINVAL;
        }
 
-       if (handler->magic != 0xbeefbeef || !handler->pd_fb || handler->deleted != NOT_DELETED || !handler->filename)
+       if (!handler->pd_fb || handler->state == DELETE || !handler->filename) {
+               ErrPrint("Handler is not valid\n");
                return -EINVAL;
+       }
 
        return fb_is_created(handler->pd_fb);
 }
@@ -569,74 +669,80 @@ EAPI int livebox_pd_is_created(struct livebox *handler)
 EAPI int livebox_create_pd(struct livebox *handler)
 {
        GVariant *param;
-       int ret;
 
        if (!handler) {
                ErrPrint("Handler is NIL\n");
                return -EINVAL;
        }
 
-       if (handler->magic != 0xbeefbeef || !handler->pd_fb || handler->deleted != NOT_DELETED || !handler->filename)
+       if (!handler->pd_fb || handler->state == DELETE || !handler->filename) {
+               ErrPrint("Handler is not valid\n");
                return -EINVAL;
+       }
 
-       if (fb_is_created(handler->pd_fb) == 1)
+       if (fb_is_created(handler->pd_fb) == 1) {
+               DbgPrint("PD is already created\n");
                return 0;
+       }
 
        param = g_variant_new("(ss)", handler->pkgname, handler->filename);
-       if (!param)
+       if (!param) {
+               ErrPrint("Failed to build param\n");
                return -EFAULT;
+       }
 
-       ret = dbus_push_command(handler, "create_pd", param, pd_created_cb, NULL);
-       if (ret < 0)
-               g_variant_unref(param);
-
-       return ret;
+       return master_rpc_async_request(handler, "create_pd", param, pd_created_cb, NULL);
 }
 
 EAPI int livebox_activate(const char *pkgname)
 {
        GVariant *param;
-       int ret;
+       char *str;
 
        if (!pkgname)
                return -EINVAL;
 
        param = g_variant_new("(s)", pkgname);
-       if (!param)
+       if (!param) {
+               ErrPrint("Failed to build a param\n");
                return -EFAULT;
+       }
 
-       ret = dbus_push_command(NULL, "activate_package", param, activated_cb, strdup(pkgname));
-       if (ret < 0)
-               g_variant_unref(param);
+       str = strdup(pkgname);
+       if (!str) {
+               ErrPrint("Heap: %s\n", strerror(errno));
+               return -ENOMEM;
+       }
 
-       return ret;
+       return master_rpc_async_request(NULL, "activate_package", param, activated_cb, str);
 }
 
 EAPI int livebox_destroy_pd(struct livebox *handler)
 {
        GVariant *param;
-       int ret;
 
        if (!handler) {
                ErrPrint("Handler is NIL\n");
                return -EINVAL;
        }
 
-       if (handler->magic != 0xbeefbeef || !handler->pd_fb || handler->deleted != NOT_DELETED || !handler->filename)
+       if (!handler->pd_fb || handler->state == DELETE || !handler->filename) {
+               ErrPrint("Handler is not valid\n");
                return -EINVAL;
+       }
 
-       if (fb_is_created(handler->pd_fb) != 1)
+       if (fb_is_created(handler->pd_fb) != 1) {
+               ErrPrint("PD is not created\n");
                return -EINVAL;
+       }
 
        param = g_variant_new("(ss)", handler->pkgname, handler->filename);
-       if (!param)
+       if (!param) {
+               ErrPrint("Failed to build a param\n");
                return -EFAULT;
+       }
 
-       ret = dbus_push_command(handler, "destroy_pd", param, pd_destroy_cb, NULL);
-       if (ret < 0)
-               g_variant_unref(param);
-
-       return ret;
+       return master_rpc_async_request(handler, "destroy_pd", param, pd_destroy_cb, NULL);
 }
 
 EAPI int livebox_pd_mouse_down(struct livebox *handler, double x, double y)
@@ -646,8 +752,10 @@ EAPI int livebox_pd_mouse_down(struct livebox *handler, double x, double y)
                return -EINVAL;
        }
 
-       if (handler->magic != 0xbeefbeef || !handler->pd_fb || handler->deleted != NOT_DELETED || !handler->filename)
+       if (!handler->pd_fb || handler->state == DELETE || !handler->filename) {
+               ErrPrint("Handler is not valid\n");
                return -EINVAL;
+       }
 
        return send_mouse_event(handler, "pd_mouse_down", x, y);
 }
@@ -659,8 +767,10 @@ EAPI int livebox_pd_mouse_up(struct livebox *handler, double x, double y)
                return -EINVAL;
        }
 
-       if (handler->magic != 0xbeefbeef || !handler->pd_fb || handler->deleted != NOT_DELETED || !handler->filename)
+       if (!handler->pd_fb || handler->state == DELETE || !handler->filename) {
+               ErrPrint("Handler is not valid\n");
                return -EINVAL;
+       }
 
        return send_mouse_event(handler, "pd_mouse_up", x, y);
 }
@@ -674,8 +784,10 @@ EAPI int livebox_pd_mouse_move(struct livebox *handler, double x, double y)
                return -EINVAL;
        }
 
-       if (handler->magic != 0xbeefbeef || !handler->pd_fb || handler->deleted != NOT_DELETED || !handler->filename)
+       if (!handler->pd_fb || handler->state == DELETE || !handler->filename) {
+               ErrPrint("Handler is not valid\n");
                return -EINVAL;
+       }
 
        ret = update_event_timestamp(handler);
        if (ret < 0)
@@ -691,8 +803,10 @@ EAPI int livebox_livebox_mouse_down(struct livebox *handler, double x, double y)
                return -EINVAL;
        }
 
-       if (handler->magic != 0xbeefbeef || !handler->lb_fb || handler->deleted != NOT_DELETED || !handler->filename)
+       if (!handler->lb_fb || handler->state == DELETE || !handler->filename) {
+               ErrPrint("Handler is not valid\n");
                return -EINVAL;
+       }
 
        return send_mouse_event(handler, "lb_mouse_down", x, y);
 }
@@ -704,8 +818,10 @@ EAPI int livebox_livebox_mouse_up(struct livebox *handler, double x, double y)
                return -EINVAL;
        }
 
-       if (handler->magic != 0xbeefbeef || !handler->lb_fb || handler->deleted != NOT_DELETED || !handler->filename)
+       if (!handler->lb_fb || handler->state == DELETE || !handler->filename) {
+               ErrPrint("Handler is not valid\n");
                return -EINVAL;
+       }
 
        return send_mouse_event(handler, "lb_mouse_up", x, y);
 }
@@ -719,8 +835,10 @@ EAPI int livebox_livebox_mouse_move(struct livebox *handler, double x, double y)
                return -EINVAL;
        }
 
-       if (handler->magic != 0xbeefbeef || !handler->lb_fb || handler->deleted != NOT_DELETED || !handler->filename)
+       if (!handler->lb_fb || handler->state == DELETE || !handler->filename) {
+               ErrPrint("Handler is not valid\n");
                return -EINVAL;
+       }
 
        ret = update_event_timestamp(handler);
        if (ret < 0)
@@ -736,8 +854,10 @@ EAPI const char *livebox_filename(struct livebox *handler)
                return NULL;
        }
 
-       if (handler->magic != 0xbeefbeef || handler->deleted != NOT_DELETED)
+       if (handler->state == DELETE) {
+               ErrPrint("Handler is not valid\n");
                return NULL;
+       }
 
        return handler->filename;
 }
@@ -752,8 +872,10 @@ EAPI int livebox_get_pdsize(struct livebox *handler, int *w, int *h)
                return -EINVAL;
        }
 
-       if (handler->magic != 0xbeefbeef || handler->deleted != NOT_DELETED || !handler->filename)
+       if (handler->state == DELETE || !handler->filename) {
+               ErrPrint("Handler is not valid\n");
                return -EINVAL;
+       }
 
        if (!w)
                w = &_w;
@@ -775,8 +897,10 @@ EAPI int livebox_get_size(struct livebox *handler, int *w, int *h)
                return -EINVAL;
        }
 
-       if (handler->magic != 0xbeefbeef || handler->deleted != NOT_DELETED || !handler->filename)
+       if (handler->state == DELETE || !handler->filename) {
+               ErrPrint("Handler is not valid\n");
                return -EINVAL;
+       }
 
        if (!w)
                w = &_w;
@@ -791,25 +915,24 @@ EAPI int livebox_get_size(struct livebox *handler, int *w, int *h)
 EAPI int livebox_set_group(struct livebox *handler, const char *cluster, const char *category)
 {
        GVariant *param;
-       int ret;
 
        if (!handler) {
                ErrPrint("Handler is NIL\n");
                return -EINVAL;
        }
 
-       if (handler->magic != 0xbeefbeef || !cluster || !category || handler->deleted != NOT_DELETED || !handler->filename)
+       if (!cluster || !category || handler->state == DELETE || !handler->filename) {
+               ErrPrint("Invalid argument\n");
                return -EINVAL;
+       }
 
        param = g_variant_new("(ssss)", handler->pkgname, handler->filename, cluster, category);
-       if (!param)
+       if (!param) {
+               ErrPrint("Failed to build a param\n");
                return -EFAULT;
+       }
 
-       ret = dbus_push_command(handler, "change_group", param, event_ret_cb, NULL);
-       if (ret < 0)
-               g_variant_unref(param);
-
-       return ret;
+       return master_rpc_async_request(handler, "change_group", param, set_group_cb, NULL);
 }
 
 EAPI int livebox_get_group(struct livebox *handler, char ** const cluster, char ** const category)
@@ -819,8 +942,10 @@ EAPI int livebox_get_group(struct livebox *handler, char ** const cluster, char
                return -EINVAL;
        }
 
-       if (handler->magic != 0xbeefbeef || !cluster || !category || handler->deleted != NOT_DELETED || !handler->filename)
+       if (!cluster || !category || handler->state == DELETE || !handler->filename) {
+               ErrPrint("Invalid argument\n");
                return -EINVAL;
+       }
 
        *cluster = handler->cluster;
        *category = handler->category;
@@ -837,8 +962,10 @@ EAPI int livebox_get_supported_sizes(struct livebox *handler, int *cnt, int *w,
                return -EINVAL;
        }
 
-       if (handler->magic != 0xbeefbeef || !cnt || handler->deleted != NOT_DELETED || !handler->filename)
+       if (!cnt || handler->state == DELETE || !handler->filename) {
+               ErrPrint("Handler is not valid\n");
                return -EINVAL;
+       }
 
        for (j = i = 0; i < NR_OF_SIZE_LIST; i++) {
                if (handler->size_list & (0x01 << i)) {
@@ -864,8 +991,10 @@ EAPI const char *livebox_pkgname(struct livebox *handler)
                return NULL;
        }
 
-       if (handler->magic != 0xbeefbeef || handler->deleted != NOT_DELETED)
+       if (handler->state == DELETE) {
+               ErrPrint("Handler is not valid\n");
                return NULL;
+       }
 
        return handler->pkgname;
 }
@@ -877,8 +1006,10 @@ EAPI double livebox_priority(struct livebox *handler)
                return 0.0f;
        }
 
-       if (handler->magic != 0xbeefbeef || handler->deleted != NOT_DELETED || !handler->filename)
-               return 0.0f;
+       if (handler->state == DELETE || !handler->filename) {
+               ErrPrint("Handler is not valid (%p)\n", handler);
+               return -1.0f;
+       }
 
        return handler->priority;
 }
@@ -902,8 +1033,10 @@ EAPI int livebox_is_file(struct livebox *handler)
                return -EINVAL;
        }
 
-       if (handler->magic != 0xbeefbeef || handler->deleted != NOT_DELETED || !handler->filename)
+       if (handler->state == DELETE || !handler->filename) {
+               ErrPrint("Handler is not valid\n");
                return -EINVAL;
+       }
 
        return handler->data_type == FILEDATA;
 }
@@ -915,8 +1048,10 @@ EAPI int livebox_is_text(struct livebox *handler)
                return -EINVAL;
        }
 
-       if (handler->magic != 0xbeefbeef || handler->deleted != NOT_DELETED || !handler->filename)
+       if (handler->state == DELETE || !handler->filename) {
+               ErrPrint("Handler is not valid\n");
                return -EINVAL;
+       }
 
        return handler->text_lb;
 }
@@ -928,8 +1063,10 @@ EAPI int livebox_pd_is_text(struct livebox *handler)
                return -EINVAL;
        }
 
-       if (handler->magic != 0xbeefbeef || handler->deleted != NOT_DELETED || !handler->filename)
+       if (handler->state == DELETE || !handler->filename) {
+               ErrPrint("Handler is not valid\n");
                return -EINVAL;
+       }
 
        return handler->text_pd;
 }
@@ -941,8 +1078,10 @@ EAPI int livebox_pd_set_text_handler(struct livebox *handler, struct livebox_scr
                return -EINVAL;
        }
 
-       if (handler->magic != 0xbeefbeef || handler->deleted != NOT_DELETED)
+       if (handler->state == DELETE) {
+               ErrPrint("Handler is not valid\n");
                return -EINVAL;
+       }
 
        memcpy(&handler->pd_ops, ops, sizeof(*ops));
        return 0;
@@ -955,8 +1094,10 @@ EAPI int livebox_set_text_handler(struct livebox *handler, struct livebox_script
                return -EINVAL;
        }
 
-       if (handler->magic != 0xbeefbeef || handler->deleted != NOT_DELETED)
+       if (handler->state == DELETE) {
+               ErrPrint("Handler is not valid\n");
                return -EINVAL;
+       }
 
        memcpy(&handler->ops, ops, sizeof(*ops));
        return 0;
@@ -969,13 +1110,12 @@ EAPI void *livebox_fb(struct livebox *handler)
                return NULL;
        }
 
-       if (handler->magic != 0xbeefbeef || handler->deleted != NOT_DELETED || !handler->filename)
+       if (handler->state == DELETE || !handler->filename || handler->data_type != FBDATA) {
+               ErrPrint("Handler is not valid\n");
                return NULL;
+       }
 
-       if (handler->data_type == FBDATA)
-               return fb_buffer(handler->lb_fb);
-
-       return NULL;
+       return fb_buffer(handler->lb_fb);
 }
 
 EAPI void *livebox_pdfb(struct livebox *handler)
@@ -985,8 +1125,10 @@ EAPI void *livebox_pdfb(struct livebox *handler)
                return NULL;
        }
 
-       if (handler->magic != 0xbeefbeef || handler->deleted != NOT_DELETED || !handler->filename)
+       if (handler->state == DELETE || !handler->filename) {
+               ErrPrint("Handler is not valid\n");
                return NULL;
+       }
 
        return fb_buffer(handler->pd_fb);
 }
@@ -998,8 +1140,10 @@ EAPI int livebox_pdfb_bufsz(struct livebox *handler)
                return -EINVAL;
        }
 
-       if (handler->magic != 0xbeefbeef || handler->deleted != NOT_DELETED || !handler->filename)
+       if (handler->state == DELETE || !handler->filename) {
+               ErrPrint("Handler is not valid\n");
                return -EINVAL;
+       }
 
        return fb_size(handler->pd_fb);
 }
@@ -1011,8 +1155,10 @@ EAPI int livebox_lbfb_bufsz(struct livebox *handler)
                return -EINVAL;
        }
 
-       if (handler->magic != 0xbeefbeef || handler->deleted != NOT_DELETED || !handler->filename)
+       if (handler->state == DELETE || !handler->filename) {
+               ErrPrint("Handler is not valid\n");
                return -EINVAL;
+       }
 
        return fb_size(handler->lb_fb);
 }
@@ -1024,8 +1170,10 @@ EAPI int livebox_is_user(struct livebox *handler)
                return -EINVAL;
        }
 
-       if (handler->magic != 0xbeefbeef || handler->deleted != NOT_DELETED || !handler->filename)
+       if (handler->state == DELETE) {
+               ErrPrint("Handler is invalid\n");
                return -EINVAL;
+       }
 
        return handler->is_user;
 }
@@ -1033,28 +1181,27 @@ EAPI int livebox_is_user(struct livebox *handler)
 EAPI int livebox_set_pinup(struct livebox *handler, int flag)
 {
        GVariant *param;
-       int ret;
 
        if (!handler) {
                ErrPrint("Handler is NIL\n");
                return -EINVAL;
        }
 
-       if (handler->magic != 0xbeefbeef || handler->deleted != NOT_DELETED || !handler->filename)
+       if (handler->state == DELETE || !handler->filename) {
+               ErrPrint("Handler is not valid\n");
                return -EINVAL;
+       }
 
        if (handler->is_pinned_up == flag)
                return 0;
 
        param = g_variant_new("(ssi)", handler->pkgname, handler->filename, flag);
-       if (!param)
+       if (!param) {
+               ErrPrint("Failed to build a param\n");
                return -EFAULT;
+       }
 
-       ret = dbus_push_command(handler, "pinup_changed", param, pinup_done_cb, (void *)flag);
-       if (ret < 0)
-               g_variant_unref(param);
-
-       return ret;
+       return master_rpc_async_request(handler, "pinup_changed", param, pinup_done_cb, (void *)flag);
 }
 
 EAPI int livebox_pinup(struct livebox *handler)
@@ -1064,7 +1211,7 @@ EAPI int livebox_pinup(struct livebox *handler)
                return -EINVAL;
        }
 
-       if (handler->magic != 0xbeefbeef || handler->deleted != NOT_DELETED || !handler->filename)
+       if (handler->state == DELETE || !handler->filename)
                return -EINVAL;
 
        return handler->is_pinned_up;
@@ -1077,7 +1224,7 @@ EAPI int livebox_has_pinup(struct livebox *handler)
                return -EINVAL;
        }
 
-       if (handler->magic != 0xbeefbeef || handler->deleted != NOT_DELETED || !handler->filename)
+       if (handler->state == DELETE || !handler->filename)
                return -EINVAL;
 
        return handler->pinup_supported;
@@ -1090,7 +1237,7 @@ EAPI int livebox_set_data(struct livebox *handler, void *data)
                return -EINVAL;
        }
 
-       if (handler->magic != 0xbeefbeef || handler->deleted != NOT_DELETED)
+       if (handler->state == DELETE)
                return -EINVAL;
 
        handler->data = data;
@@ -1104,7 +1251,7 @@ EAPI void *livebox_get_data(struct livebox *handler)
                return NULL;
        }
 
-       if (handler->magic != 0xbeefbeef || handler->deleted != NOT_DELETED)
+       if (handler->state == DELETE)
                return NULL;
 
        return handler->data;
@@ -1116,11 +1263,13 @@ EAPI int livebox_is_exists(const char *pkgname)
        int ret;
 
        param = g_variant_new("(s)", pkgname);
-       if (!param)
+       if (!param) {
+               ErrPrint("Failed to build a param\n");
                return -EFAULT;
+       }
 
-       ret = dbus_sync_command("livebox_is_exists", param);
-       return (ret == 0) ? 1 : ret;
+       ret = master_rpc_sync_request(NULL, "livebox_is_exists", param);
+       return ret == 0;
 }
 
 EAPI const char *livebox_content(struct livebox *handler)
@@ -1130,7 +1279,7 @@ EAPI const char *livebox_content(struct livebox *handler)
                return NULL;
        }
 
-       if (handler->magic != 0xbeefbeef || handler->deleted != NOT_DELETED)
+       if (handler->state == DELETE)
                return NULL;
 
        return handler->content;
@@ -1139,15 +1288,16 @@ EAPI const char *livebox_content(struct livebox *handler)
 EAPI int livebox_text_emit_signal(struct livebox *handler, const char *emission, const char *source, double sx, double sy, double ex, double ey)
 {
        GVariant *param;
-       int ret;
 
        if (!handler) {
                ErrPrint("Handler is NIL\n");
                return -EINVAL;
        }
 
-       if (handler->magic != 0xbeefbeef || (!handler->text_lb && !handler->text_pd) || handler->deleted != NOT_DELETED || !handler->filename)
+       if ((!handler->text_lb && !handler->text_pd) || handler->state == DELETE || !handler->filename) {
+               ErrPrint("Handler is not valid\n");
                return -EINVAL;
+       }
 
        if (!emission)
                emission = "";
@@ -1156,16 +1306,12 @@ EAPI int livebox_text_emit_signal(struct livebox *handler, const char *emission,
                source = "";
 
        param = g_variant_new("(ssssdddd)", handler->pkgname, handler->filename, emission, source, sx, sy, ex, ey);
-       if (!param)
+       if (!param) {
+               ErrPrint("Failed to build a param\n");
                return -EFAULT;
-
-       ret = dbus_push_command(handler, "text_signal", param, event_ret_cb, NULL);
-       if (ret < 0) {
-               g_variant_unref(param);
-               return -EIO;
        }
 
-       return 0;
+       return master_rpc_async_request(handler, "text_signal", param, text_signal_cb, NULL);
 }
 
 int lb_set_group(struct livebox *handler, const char *cluster, const char *category)
@@ -1287,7 +1433,6 @@ struct livebox *lb_new_livebox(const char *pkgname, const char *filename)
 
        s_info.livebox_list = dlist_append(s_info.livebox_list, handler);
        lb_ref(handler);
-       handler->magic = 0xbeefbeef;
        return handler;
 }
 
@@ -1458,6 +1603,7 @@ void lb_set_lb_fb(struct livebox *handler, const char *filename)
                return;
        }
 
+       fb_sync(handler->lb_fb);
        handler->data_type = FBDATA;
 }
 
@@ -1527,16 +1673,23 @@ void lb_set_period(struct livebox *handler, double period)
        handler->period = period;
 }
 
-void lb_ref(struct livebox *handler)
+struct livebox *lb_ref(struct livebox *handler)
 {
+       if (!handler)
+               return NULL;
+
        handler->refcnt++;
+       return handler;
 }
 
-void lb_unref(struct livebox *handler)
+struct livebox *lb_unref(struct livebox *handler)
 {
+       if (!handler)
+               return NULL;
+
        handler->refcnt--;
        if (handler->refcnt > 0)
-               return;
+               return handler;
 
        dlist_remove_data(s_info.livebox_list, handler);
 
@@ -1557,26 +1710,21 @@ void lb_unref(struct livebox *handler)
                handler->pd_fb = NULL;
        }
 
-       handler->magic = 0xdeaddead;
        free(handler);
+       return NULL;
 }
 
 int lb_send_delete(struct livebox *handler)
 {
        GVariant *param;
-       int ret;
 
        param = g_variant_new("(ss)", handler->pkgname, handler->filename);
-       if (!param)
+       if (!param) {
+               ErrPrint("Failed to build a param\n");
                return -EFAULT;
-
-       ret = dbus_push_command(handler, "delete", param, del_ret_cb, NULL);
-       if (ret < 0) {
-               g_variant_unref(param);
-               return ret;
        }
 
-       return 0;
+       return master_rpc_async_request(handler, "delete", param, del_ret_cb, NULL);
 }
 
 /* End of a file */
diff --git a/src/master_rpc.c b/src/master_rpc.c
new file mode 100644 (file)
index 0000000..7026fac
--- /dev/null
@@ -0,0 +1,227 @@
+#include <stdio.h>
+#include <gio/gio.h>
+#include <libgen.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <dlog.h>
+
+#include "debug.h"
+#include "dlist.h"
+#include "livebox.h"
+#include "livebox_internal.h"
+#include "dbus.h"
+#include "master_rpc.h"
+
+#define DEFAULT_TTL 10
+
+struct packet {
+       int ttl;
+       char *funcname;
+       GVariant *param;
+       struct livebox *handler;
+       void (*ret_cb)(struct livebox *handler, GVariant *result, void *data);
+       void *data;
+};
+
+int errno;
+
+static struct {
+       guint cmd_timer;
+       struct dlist *cmd_list;
+} s_info = {
+       .cmd_timer = 0,
+       .cmd_list = NULL,
+};
+
+static void done_cb(GDBusProxy *proxy, GAsyncResult *res, void *data);
+
+static inline struct packet *pop_packet(void)
+{
+       struct dlist *l;
+       struct packet *packet;
+
+       l = dlist_nth(s_info.cmd_list, 0);
+       if (!l)
+               return NULL;
+
+       packet = dlist_data(l);
+       s_info.cmd_list = dlist_remove(s_info.cmd_list, l);
+       return packet;
+}
+
+static inline struct packet *create_packet(struct livebox *handler, const char *funcname, GVariant *param)
+{
+       struct packet *packet;
+
+       packet = malloc(sizeof(*packet));
+       if (!packet) {
+               ErrPrint("Failed to allocate mem for packet\n");
+               return NULL;
+       }
+
+       packet->funcname = strdup(funcname);
+       if (!packet->funcname) {
+               ErrPrint("Failed to allocate mem for funcname - %s\n", funcname);
+               free(packet);
+               return NULL;
+       }
+
+       packet->handler = lb_ref(handler);
+       packet->param = g_variant_ref(param);
+       return packet;
+}
+
+static inline void destroy_packet(struct packet *packet)
+{
+       g_variant_unref(packet->param);
+       lb_unref(packet->handler);
+       free(packet->funcname);
+       free(packet);
+}
+
+static gboolean cmd_consumer(gpointer user_data)
+{
+       struct packet *packet;
+
+       if (!dbus_proxy())
+               return TRUE;
+
+       packet = pop_packet();
+       if (!packet) {
+               s_info.cmd_timer = 0;
+               return FALSE;
+       }
+
+       /*!
+        * \NOTE:
+        * Item will be deleted in the "done_cb"
+        *
+        * item->param be release by the g_dbus_proxy_call
+        * so to use it again from the done_cb function,
+        * increate the reference counter of the item->param
+        */
+       g_dbus_proxy_call(dbus_proxy(),
+               packet->funcname,
+               packet->param,
+               G_DBUS_CALL_FLAGS_NO_AUTO_START,
+               -1, NULL, (GAsyncReadyCallback)done_cb, packet);
+
+       return TRUE;
+}
+
+static inline void check_and_fire_consumer(void)
+{
+       if (!s_info.cmd_list || s_info.cmd_timer)
+               return;
+
+       s_info.cmd_timer = g_timeout_add(10, cmd_consumer, NULL);
+       if (!s_info.cmd_timer)
+               ErrPrint("Failed to add timer\n");
+}
+
+static inline void prepend_packet(struct packet *packet)
+{
+       DbgPrint("Re-send a packet: %s (ttl: %d)\n", packet->funcname, packet->ttl);
+       s_info.cmd_list = dlist_prepend(s_info.cmd_list, packet);
+       check_and_fire_consumer();
+}
+
+static void done_cb(GDBusProxy *proxy, GAsyncResult *res, void *data)
+{
+       GVariant *result;
+       GError *err;
+       struct packet *packet;
+
+       packet = data;
+
+       err = NULL;
+       result = g_dbus_proxy_call_finish(proxy, res, &err);
+       if (!result) {
+               if (err) {
+                       ErrPrint("%s Error: %s\n", packet->funcname, err->message);
+                       g_error_free(err);
+               }
+
+               /*! \NOTE:
+                * Release resource even if
+                * we failed to finish the method call
+                */
+               packet->ttl--;
+               if (packet->ttl > 0) {
+                       prepend_packet(packet);
+                       return;
+               }
+
+               if (packet->ret_cb)
+                       packet->ret_cb(packet->handler, NULL, packet->data);
+
+               goto out;
+       }
+
+       if (packet->ret_cb)
+               packet->ret_cb(packet->handler, result, packet->data);
+       else
+               g_variant_unref(result);
+
+out:
+       destroy_packet(packet);
+}
+
+static inline void push_packet(struct packet *packet)
+{
+       s_info.cmd_list = dlist_append(s_info.cmd_list, packet);
+       check_and_fire_consumer();
+}
+
+/*!
+ * \note
+ * "handler" could be NULL
+ */
+int master_rpc_async_request(struct livebox *handler, const char *funcname, GVariant *param, void (*ret_cb)(struct livebox *handler, GVariant *result, void *data), void *data)
+{
+       struct packet *packet;
+
+       packet = create_packet(handler, funcname, param);
+       if (!packet) {
+               if (ret_cb)
+                       ret_cb(handler, NULL, data);
+
+               g_variant_unref(param);
+               return -EFAULT;
+       }
+
+       packet->ret_cb = ret_cb;
+       packet->data = data;
+       packet->ttl = DEFAULT_TTL;
+
+       push_packet(packet);
+       return 0;
+}
+
+int master_rpc_sync_request(struct livebox *handler, const char *func, GVariant *param)
+{
+       GVariant *result;
+       GError *err;
+       int ret;
+
+       err = NULL;
+       result = g_dbus_proxy_call_sync(dbus_proxy(), func, param, G_DBUS_CALL_FLAGS_NO_AUTO_START, -1, NULL, &err);
+       if (!result) {
+               if (err) {
+                       ErrPrint("acquire Error: %s\n", err->message);
+                       g_error_free(err);
+               }
+
+               ErrPrint("Failed to send 'acquire'\n");
+               return -EIO;
+       }
+
+       g_variant_get(result, "(i)", &ret);
+       g_variant_unref(result);
+
+       return ret;
+}
+
+/* End of a file */
index 61d3a13..8baec93 100644 (file)
@@ -46,7 +46,7 @@ int util_check_extension(const char *filename, const char *check_ptr)
        return 0;
 }
 
-double util_get_timestamp(void)
+double util_timestamp(void)
 {
        struct timeval tv;