Implement the livebox show/hide feature
authorSung-jae Park <nicesj.park@samsung.com>
Thu, 6 Sep 2012 06:22:47 +0000 (15:22 +0900)
committerSung-jae Park <nicesj.park@samsung.com>
Thu, 6 Sep 2012 06:39:27 +0000 (15:39 +0900)
If the instance has owner(client) and is not shown,
Don't send updated event to the owner(client).

Change-Id: Ibae25e87858a2897489277d9fd42de91d8991ef7

include/instance.h
include/slave_rpc.h
src/instance.c
src/server.c
src/slave_rpc.c

index 71d0959..e7f8102 100644 (file)
@@ -34,7 +34,7 @@
  * It will change the instance's state to "ACTIVATED"
  * But now, the master will not send "created" event to the clients.
  *
- * Because the clients don't watn to know the re-created liveboxes.
+ * Because the clients don't want to know the re-created liveboxes.
  * They just want to know about fault liveboxes to display deactivated
  * message.
  *
@@ -53,7 +53,7 @@
  * Yes, it is right. But the instance cannot be deleted directly.
  * Because some callbacks still reference it to complete its job.
  * So the instance needs to keep this DESTROYED state for a while
- * until all callbacks are done to their jobs.
+ * until all callbacks are done for their remained jobs.
  *
  * To unload the instance from the slave,
  * The master should send a request to the slave,
@@ -87,6 +87,15 @@ enum instance_state {
        INST_REQUEST_TO_DESTROY, /*!< Sent a request to a slave, when the master receives deleted event, the master will delete this */
 };
 
+enum livebox_visible_state { /*!< Must be sync'd with livebox-viewer */
+       LB_SHOW = 0x00, /*!< Livebox is showed. Default state */
+       LB_HIDE = 0x01, /*!< Livebox is hide, with no update event, but keep update timer */
+
+       LB_HIDE_WITH_PAUSE = 0x02, /*!< Livebix is hide, it needs to be paused (with freezed update timer) */
+
+       LB_VISIBLE_ERROR = 0xFFFFFFFF, /* To enlarge the size of this enumeration type */
+};
+
 struct inst_info;
 struct pkg_info;
 struct script_handle;
@@ -122,6 +131,7 @@ extern int instance_set_period(struct inst_info *inst, double period);
 extern int instance_clicked(struct inst_info *inst, const char *event, double timestamp, double x, double y);
 extern int instance_text_signal_emit(struct inst_info *inst, const char *emission, const char *source, double sx, double sy, double ex, double ey);
 extern int instance_change_group(struct inst_info *inst, const char *cluster, const char *category);
+extern int instance_set_visible_state(struct inst_info *inst, enum livebox_visible_state state);
 
 /*!
  * \note
index 0d0db8f..e8a805f 100644 (file)
@@ -1,5 +1,5 @@
 extern int slave_rpc_async_request(struct slave_node *slave, const char *pkgname, struct packet *packet, void (*ret_cb)(struct slave_node *slave, const struct packet *packet, void *data), void *data);
-extern int slave_rpc_request_only(struct slave_node *slave, struct packet *packet);
+extern int slave_rpc_request_only(struct slave_node *slave, const char *pkgname, struct packet *packet);
 extern int slave_rpc_update_handle(struct slave_node *slave, int handle);
 extern int slave_rpc_ping(struct slave_node *slave);
 extern void slave_rpc_request_update(const char *pkgname, const char *cluster, const char *category);
index aa93873..c3b9765 100644 (file)
@@ -62,6 +62,8 @@ struct inst_info {
        char *category;
        char *title;
 
+       enum livebox_visible_state visible;
+
        struct {
                int width;
                int height;
@@ -97,6 +99,35 @@ struct inst_info {
 
 #define CLIENT_SEND_EVENT(instance, packet)    ((instance)->client ? client_rpc_async_request((instance)->client, (packet)) : client_rpc_broadcast((instance), (packet)))
 
+static inline int pause_livebox(struct inst_info *inst)
+{
+       struct packet *packet;
+       int ret;
+
+       packet = packet_create_noack("lb_pause", "ss", package_name(inst->info), inst->id);
+       if (!packet) {
+               ErrPrint("Failed to create a new packet\n");
+               return -EFAULT;
+       }
+
+       return slave_rpc_request_only(package_slave(inst->info), package_name(inst->info), packet);
+}
+
+/*! \TODO Wake up the freeze'd timer */
+static inline int resume_livebox(struct inst_info *inst)
+{
+       struct packet *packet;
+       int ret;
+
+       packet = packet_create_noack("lb_resume", "ss", package_name(inst->info), inst->id);
+       if (!packet) {
+               ErrPrint("Failed to create a new packet\n");
+               return -EFAULT;
+       }
+
+       return slave_rpc_request_only(package_slave(inst->info), package_name(inst->info), packet);
+}
+
 int instance_unicast_created_event(struct inst_info *inst, struct client_node *client)
 {
        struct packet *packet;
@@ -600,6 +631,21 @@ static void reactivate_cb(struct slave_node *slave, const struct packet *packet,
                        if (pd_type == PD_TYPE_SCRIPT && inst->pd.canvas.script && inst->pd.is_opened_for_reactivate)
                                script_handler_load(inst->pd.canvas.script, 1);
 
+                       switch (inst->visible) {
+                       case LB_SHOW:
+                               /* Do nothing */
+                               break;
+                       case LB_HIDE:
+                               /* Do nothing */
+                               break;
+                       case LB_HIDE_WITH_PAUSE:
+                               pause_livebox(inst);
+                               break;
+                       default:
+                               ErrPrint("Unknown visibility\n");
+                               break;
+                       }
+
                        /*!
                         * \note After recreated, send the update event to the client
                         */
@@ -1070,6 +1116,11 @@ void instance_lb_updated_by_instance(struct inst_info *inst)
        const char *title;
        const char *content;
 
+       if (inst->client && inst->visible != LB_SHOW) {
+               DbgPrint("Livebox is hidden. ignore update event\n");
+               return;
+       }
+
        lb_type = package_lb_type(inst->info);
        if (lb_type == LB_TYPE_SCRIPT)
                id = fb_id(script_handler_fb(inst->lb.canvas.script));
@@ -1105,6 +1156,11 @@ void instance_pd_updated_by_instance(struct inst_info *inst, const char *descfil
        enum pd_type pd_type;
        const char *id;
 
+       if (inst->client && inst->visible != LB_SHOW) {
+               DbgPrint("Livebox is hidden. ignore update event\n");
+               return;
+       }
+
        if (!descfile)
                descfile = inst->id;
 
@@ -1274,6 +1330,36 @@ int instance_set_pinup(struct inst_info *inst, int pinup)
        return slave_rpc_async_request(package_slave(inst->info), package_name(inst->info), packet, pinup_cb, cbdata);
 }
 
+int instance_set_visible_state(struct inst_info *inst, enum livebox_visible_state state)
+{
+       if (inst->visible == state) {
+               DbgPrint("Visibility has no changed\n");
+               return 0;
+       }
+
+       switch (state) {
+       case LB_SHOW:
+       case LB_HIDE:
+               if (inst->visible == LB_HIDE_WITH_PAUSE) {
+                       if (resume_livebox(inst) == 0)
+                               inst->visible = state;
+               } else {
+                       inst->visible = state;
+               }
+               break;
+
+       case LB_HIDE_WITH_PAUSE:
+               if (pause_livebox(inst) == 0)
+                       inst->visible = LB_HIDE_WITH_PAUSE;
+               break;
+
+       default:
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
 static void resize_cb(struct slave_node *slave, const struct packet *packet, void *data)
 {
        struct resize_cbdata *cbdata = data;
index 8be2790..5ad6a6c 100644 (file)
@@ -116,7 +116,6 @@ out:
 static struct packet *client_clicked(pid_t pid, int handle, const struct packet *packet)
 {
        struct client_node *client;
-       struct packet *result;
        const char *pkgname;
        const char *id;
        const char *event;
@@ -153,11 +152,7 @@ static struct packet *client_clicked(pid_t pid, int handle, const struct packet
                ret = instance_clicked(inst, event, timestamp, x, y);
 
 out:
-       result = packet_create_reply(packet, "i", ret);
-       if (!result)
-               ErrPrint("Failed to create a packet\n");
-
-       return result;
+       return NULL;
 }
 
 /* pid, pkgname, filename, emission, source, s, sy, ex, ey, ret */
@@ -366,6 +361,43 @@ out:
        return result;
 }
 
+static struct packet *client_change_visibility(pid_t pid, int handle, const struct packet *packet)
+{
+       struct client_node *client;
+       const char *pkgname;
+       const char *id;
+       enum livebox_visible_state state;
+       int ret;
+       struct inst_info *inst;
+
+       DbgPrint("Client[%d] request arrived\n", pid);
+
+       client = client_find_by_pid(pid);
+       if (!client) {
+               ErrPrint("Client %d is not exists\n", pid);
+               goto out;
+       }
+
+       ret = packet_get(packet, "ssi", &pkgname, &id, (int *)&state);
+       if (ret != 3) {
+               ErrPrint("Parameter is not matched\n");
+               goto out;
+       }
+
+       DbgPrint("pkgname[%s] id[%s] state[%d]\n", pkgname, id, state);
+
+       inst = package_find_instance_by_id(pkgname, id);
+       if (!inst)
+               goto out;
+       else if (package_is_fault(instance_package(inst)))
+               goto out;
+       else
+               ret = instance_set_visible_state(inst, state);
+
+out:
+       return NULL;
+}
+
 static struct packet *client_set_period(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, period, ret */
 {
        struct client_node *client;
@@ -532,7 +564,7 @@ static struct packet *client_pd_mouse_enter(pid_t pid, int handle, const struct
                        goto out;
                }
 
-               ret = slave_rpc_request_only(slave, packet);
+               ret = slave_rpc_request_only(slave, pkgname, packet);
        } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
                struct script_info *script;
                Evas *e;
@@ -637,7 +669,7 @@ static struct packet *client_pd_mouse_leave(pid_t pid, int handle, const struct
                        goto out;
                }
 
-               ret = slave_rpc_request_only(slave, packet);
+               ret = slave_rpc_request_only(slave, pkgname, packet);
        } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
                struct script_info *script;
                Evas *e;
@@ -742,7 +774,7 @@ static struct packet *client_pd_mouse_down(pid_t pid, int handle, const struct p
                        goto out;
                }
 
-               ret = slave_rpc_request_only(slave, packet);
+               ret = slave_rpc_request_only(slave, pkgname, packet);
        } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
                struct script_info *script;
                Evas *e;
@@ -848,7 +880,7 @@ static struct packet *client_pd_mouse_up(pid_t pid, int handle, const struct pac
                        goto out;
                }
 
-               ret = slave_rpc_request_only(slave, packet);
+               ret = slave_rpc_request_only(slave, pkgname, packet);
        } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
                struct script_info *script;
                Evas *e;
@@ -954,7 +986,7 @@ static struct packet *client_pd_mouse_move(pid_t pid, int handle, const struct p
                        goto out;
                }
 
-               ret = slave_rpc_request_only(slave, packet);
+               ret = slave_rpc_request_only(slave, pkgname, packet);
        } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
                struct script_info *script;
                Evas *e;
@@ -1059,7 +1091,7 @@ static struct packet *client_lb_mouse_move(pid_t pid, int handle, const struct p
                        goto out;
                }
 
-               ret = slave_rpc_request_only(slave, packet);
+               ret = slave_rpc_request_only(slave, pkgname, packet);
        } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
                struct script_info *script;
                Evas *e;
@@ -1164,7 +1196,7 @@ static struct packet *client_lb_mouse_enter(pid_t pid, int handle, const struct
                        goto out;
                }
 
-               ret = slave_rpc_request_only(slave, packet);
+               ret = slave_rpc_request_only(slave, pkgname, packet);
        } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
                struct script_info *script;
                Evas *e;
@@ -1269,7 +1301,7 @@ static struct packet *client_lb_mouse_leave(pid_t pid, int handle, const struct
                        goto out;
                }
 
-               ret = slave_rpc_request_only(slave, packet);
+               ret = slave_rpc_request_only(slave, pkgname, packet);
        } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
                struct script_info *script;
                Evas *e;
@@ -1374,7 +1406,7 @@ static struct packet *client_lb_mouse_down(pid_t pid, int handle, const struct p
                        goto out;
                }
 
-               ret = slave_rpc_request_only(slave, packet);
+               ret = slave_rpc_request_only(slave, pkgname, packet);
        } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
                struct script_info *script;
                Evas *e;
@@ -1480,7 +1512,7 @@ static struct packet *client_lb_mouse_up(pid_t pid, int handle, const struct pac
                        goto out;
                }
 
-               ret = slave_rpc_request_only(slave, packet);
+               ret = slave_rpc_request_only(slave, pkgname, packet);
        } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
                struct script_info *script;
                Evas *e;
@@ -1788,7 +1820,6 @@ static struct packet *client_subscribed(pid_t pid, int handle, const struct pack
        const char *cluster;
        const char *category;
        struct client_node *client;
-       struct packet *result;
        int ret;
 
        DbgPrint("Client[%d] request arrived\n", pid);
@@ -1819,11 +1850,7 @@ static struct packet *client_subscribed(pid_t pid, int handle, const struct pack
                package_alter_instances_to_client(client);
 
 out:
-       result = packet_create_reply(packet, "i", ret);
-       if (!result)
-               ErrPrint("Failed to create a packet\n");
-
-       return result;
+       return NULL;
 }
 
 static struct packet *client_delete_cluster(pid_t pid, int handle, const struct packet *packet)
@@ -1899,7 +1926,6 @@ static struct packet *client_refresh_group(pid_t pid, int handle, const struct p
        const char *cluster_id;
        const char *category_id;
        struct client_node *client;
-       struct packet *result;
        int ret;
        struct cluster *cluster;
        struct category *category;
@@ -1939,10 +1965,7 @@ static struct packet *client_refresh_group(pid_t pid, int handle, const struct p
        group_list_category_pkgs(category, update_pkg_cb, NULL);
 
 out:
-       result = packet_create_reply(packet, "i", ret);
-       if (!result)
-               ErrPrint("Failed to create a packet\n");
-       return result;
+       return NULL;
 }
 
 static struct packet *client_delete_category(pid_t pid, int handle, const struct packet *packet)
@@ -1988,7 +2011,6 @@ static struct packet *client_unsubscribed(pid_t pid, int handle, const struct pa
        const char *cluster;
        const char *category;
        struct client_node *client;
-       struct packet *result;
        int ret;
 
        DbgPrint("Client[%d] request arrived\n", pid);
@@ -2016,10 +2038,7 @@ static struct packet *client_unsubscribed(pid_t pid, int handle, const struct pa
        ret = client_unsubscribe(client, cluster, category);
 
 out:
-       result = packet_create_reply(packet, "i", ret);
-       if (!result)
-               ErrPrint("Failed to create a packet\n");
-       return result;
+       return NULL;
 }
 
 static struct packet *slave_hello(pid_t pid, int handle, const struct packet *packet) /* slave_name, ret */
@@ -2725,6 +2744,10 @@ static struct method s_table[] = {
                .cmd = "refresh_group",
                .handler = client_refresh_group,
        },
+       {
+               .cmd = "change,visibility",
+               .handler = client_change_visibility,
+       },
        /*!
         * \note services for slave
         */
index 66dbbed..d96dcd4 100644 (file)
@@ -366,12 +366,12 @@ int slave_rpc_async_request(struct slave_node *slave, const char *pkgname, struc
        return 0;
 }
 
-int slave_rpc_request_only(struct slave_node *slave, struct packet *packet)
+int slave_rpc_request_only(struct slave_node *slave, const char *pkgname, struct packet *packet)
 {
        struct command *command;
        struct slave_rpc *rpc;
 
-       command = create_command(slave, NULL, packet);
+       command = create_command(slave, pkgname, packet);
        if (!command) {
                ErrPrint("Failed to create a command\n");
                packet_unref(packet);