Apply Watch-Core feature.
authorSung-jae Park <nicesj.park@samsung.com>
Fri, 27 Mar 2015 13:14:59 +0000 (22:14 +0900)
committerSung-jae Park <nicesj.park@samsung.com>
Fri, 27 Mar 2015 13:14:59 +0000 (22:14 +0900)
Hello_sync is added

[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: I21a99c4708a0f7f7838fedfe75e350de13aef16b

include/instance.h
include/slave_rpc.h
src/instance.c
src/server.c
src/slave_life.c
src/slave_rpc.c
util_liveinfo/src/liveinfo.c

index 0d46c01..7f7ac78 100755 (executable)
@@ -264,4 +264,7 @@ extern void *instance_del_data(struct inst_info *inst, const char *tag);
 extern void *instance_get_data(struct inst_info *inst, const char *tag);
 
 extern void instance_reload_period(struct inst_info *inst, double period);
+extern struct packet *instance_duplicate_packet_create(struct inst_info *inst, struct pkg_info *info, int width, int height);
+
+extern struct packet *instance_watch_create(const char *pkgname, int width, int height);
 /* End of a file */
index 03675bc..6784b94 100644 (file)
@@ -17,7 +17,7 @@
 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, int urgent);
 extern int slave_rpc_request_only(struct slave_node *slave, const char *pkgname, struct packet *packet, int urgent);
 
-extern int slave_rpc_update_handle(struct slave_node *slave, int handle);
+extern int slave_rpc_update_handle(struct slave_node *slave, int handle, int delete_pending_packet);
 extern int slave_rpc_ping(struct slave_node *slave);
 extern void slave_rpc_request_update(const char *pkgname, const char *id, const char *cluster, const char *category, const char *content, int force);
 extern int slave_rpc_handle(struct slave_node *slave);
@@ -29,6 +29,4 @@ extern int slave_rpc_disconnect(struct slave_node *slave);
 extern int slave_rpc_init(struct slave_node *slave);
 extern int slave_rpc_fini(struct slave_node *slave);
 
-extern int slave_rpc_clear_pending_list(struct slave_node *slave);
-
 /* End of a file */
index 73aede9..dd4a362 100755 (executable)
@@ -835,6 +835,17 @@ static Eina_Bool update_timer_cb(void *data)
        return ECORE_CALLBACK_RENEW;
 }
 
+static inline void unfork_package(struct inst_info *inst)
+{
+       DbgFree(inst->id);
+       inst->id = NULL;
+
+       if (inst->update_timer) {
+               ecore_timer_del(inst->update_timer);
+               inst->update_timer = NULL;
+       }
+}
+
 static inline int fork_package(struct inst_info *inst, const char *pkgname)
 {
        struct pkg_info *info;
@@ -959,13 +970,25 @@ HAPI struct inst_info *instance_create(struct client_node *client, double timest
        instance_ref(inst);
 
        if (package_add_instance(inst->info, inst) < 0) {
-               instance_destroy(inst, WIDGET_DESTROY_TYPE_FAULT);
+               DbgFree(inst->widget.extra_buffer);
+               DbgFree(inst->gbar.extra_buffer);
+               unfork_package(inst);
+               (void)client_unref(inst->client);
+               DbgFree(inst->title);
+               DbgFree(inst->category);
+               DbgFree(inst->cluster);
+               DbgFree(inst->content);
+               DbgFree(inst);
                return NULL;
        }
 
        slave_load_instance(package_slave(inst->info));
 
-       // Before activate an instance, update its id first for client
+       /**
+        * @note
+        * Before activate an instance,
+        * Update its Id first for client.
+        */
        instance_send_update_id(inst);
 
        if (instance_activate(inst) < 0) {
@@ -3720,7 +3743,6 @@ HAPI struct packet *instance_watch_create(const char *pkgname, int width, int he
        struct inst_info *inst;
        struct packet *result;
        unsigned int cmd = CMD_NEW;
-       int ret;
 
        inst = calloc(1, sizeof(*inst));
        if (!inst) {
@@ -3728,6 +3750,11 @@ HAPI struct packet *instance_watch_create(const char *pkgname, int width, int he
                return NULL;
        }
 
+       /**
+        * @note
+        * This timestamp will not be used by viewer.
+        * So we can set it manually from here.
+        */
        inst->timestamp = util_timestamp();
        inst->widget.width = width;
        inst->widget.height = height;
@@ -3748,15 +3775,31 @@ HAPI struct packet *instance_watch_create(const char *pkgname, int width, int he
                        ErrPrint("Failed to allocate buffer for gbar extra buffer\n");
                }
        }
+
+       /**
+        * We don't need to set the state of this instance from here.
+        * But, in case of fail to add a new instance to package information(inst->info) data,
+        * the "instance_destroy" will be invoked.
+        * it will try to get the state of an instance.
+        */
+       inst->state = INST_INIT;
+       inst->requested_state = INST_INIT;
        instance_ref(inst);
+
+       /**
+        * @note
+        * We already create a slave object from caller.
+        * This will finds it and map it to package information object
+        */
        if (package_add_instance(inst->info, inst) < 0) {
                ErrPrint("Failed to package_add_instance\n");
-               instance_destroy(inst, WIDGET_DESTROY_TYPE_FAULT);
+               unfork_package(inst);
+               DbgFree(inst->widget.extra_buffer);
+               DbgFree(inst->gbar.extra_buffer);
+               DbgFree(inst);
                return NULL;
        }
 
-       slave_load_instance(package_slave(inst->info));
-
        /**
         * Before activate an instance, update its id first for client
        instance_send_update_id(inst);
@@ -3777,11 +3820,19 @@ HAPI struct packet *instance_watch_create(const char *pkgname, int width, int he
                        inst->widget.width,
                        inst->widget.height,
                        client_direct_addr(inst->client));
+
        if (!result) {
                ErrPrint("Failed to build a packet for %s\n", package_name(inst->info));
+               package_del_instance(inst->info, inst); /* This will reset the inst->info->slave */
+               unfork_package(inst);
+               DbgFree(inst->widget.extra_buffer);
+               DbgFree(inst->gbar.extra_buffer);
+               DbgFree(inst);
                return NULL;
        }
 
+       slave_load_instance(package_slave(inst->info));
+
        inst->requested_state = INST_ACTIVATED;
        inst->state = INST_ACTIVATED;
 
index 03b7c8f..686bec8 100755 (executable)
@@ -62,6 +62,8 @@
 #define LAZY_GBAR_OPEN_TAG "lazy,gbar,open"
 #define LAZY_GBAR_CLOSE_TAG "lazy,gbar,close"
 
+#define CATEGORY_WATCH_CLOCK   "com.samsung.wmanager.WATCH_CLOCK"
+
 #define ACCESS_TYPE_DOWN 0
 #define ACCESS_TYPE_MOVE 1
 #define ACCESS_TYPE_UP 2
@@ -76,12 +78,21 @@ static struct info {
        int service_fd;
        int slave_fd;
        int remote_client_fd;
+
+       struct hello_context {
+               int pid;
+               int handle;
+       } hello_ctx;
 } s_info = {
        .info_fd = -1,
        .client_fd = -1,
        .service_fd = -1,
        .slave_fd = -1,
        .remote_client_fd = -1,
+       .hello_ctx = {
+               .pid = -1,
+               .handle = -1,
+       },
 };
 
 struct access_info {
@@ -924,7 +935,7 @@ static int validate_request(pid_t pid, struct slave_node *slave, const char *pkg
 
        if (slave) {
                if (slave_valid(slave)) {
-                       inst = package_find_instance_by_id(widget_id, id);
+                       inst = package_find_instance_by_id(pkgname, id);
                } else {
                        ErrPrint("slave is not valid (%s)\n", id);
                        return WIDGET_STATUS_ERROR_INVALID_PARAMETER;
@@ -1878,7 +1889,6 @@ static int inst_del_cb(struct inst_info *inst, void *data)
        return -1; /* Delete this callback */
 }
 
-
 static struct packet *client_gbar_key_set(pid_t pid, int handle, const struct packet *packet)
 {
        struct client_node *client;
@@ -6584,7 +6594,7 @@ static struct packet *slave_hello(pid_t pid, int handle, const struct packet *pa
         * After updating handle,
         * slave activated callback will be called.
         */
-       slave_rpc_update_handle(slave, handle);
+       slave_rpc_update_handle(slave, handle, 0);
 
 out:
        return NULL;
@@ -7826,8 +7836,8 @@ static struct packet *slave_hello_sync_prepare(pid_t pid, int handle, const stru
        int ret;
        double timestamp;
 
-       if (s_slave_hello.pid > 0) {
-               ErrPrint("Process [%d] sent hello sync prepare. but hello sync is not called.\n", s_slave_hello.pid);
+       if (s_info.hello_ctx.pid > 0) {
+               ErrPrint("Process [%d] sent hello sync prepare. but hello sync is not called.\n", s_info.hello_ctx.pid);
        }
 
        ret = packet_get(packet, "d", &timestamp);
@@ -7837,12 +7847,12 @@ static struct packet *slave_hello_sync_prepare(pid_t pid, int handle, const stru
        }
 
        if (aul_app_get_pkgname_bypid(pid, pkgname, sizeof(pkgname)) != AUL_R_OK) {
-               ErrPrint("pid[%d] is not authroized provider package, try to find it using its name[%s]\n", pid, slavename);
+               ErrPrint("pid[%d] is not authroized provider package, try to find it using its name\n", pid);
                goto out;
        }
 
-       s_slave_hello.pid = pid;
-       s_slave_hello.handle = handle;
+       s_info.hello_ctx.pid = pid;
+       s_info.hello_ctx.handle = handle;
 
 out:
        return NULL;
@@ -7924,7 +7934,7 @@ static struct packet *slave_hello_sync(pid_t pid, int handle, const struct packe
                        if (!info) {
                                char *pkgid;
 
-                               pkgid = widget_service_package_id(widget_id);
+                               pkgid = widget_service_get_package_id(widget_id);
                                if (!pkgid) {
                                        DbgFree(widget_id);
                                        goto out;
@@ -7974,13 +7984,18 @@ static struct packet *slave_hello_sync(pid_t pid, int handle, const struct packe
                                ErrPrint("Failed to create a new slave for %s\n", slavename);
                                goto out;
                        }
+
                        slave_set_pid(slave, pid);
                        slave_set_valid(slave);
 
-                       if (s_slave_hello.pid == pid) {
-                               slave_rpc_update_handle(slave, s_slave_hello.handle);
+                       if (s_info.hello_ctx.pid == pid) {
+                               /**
+                                * @note
+                                * Delete all pending packets
+                                */
+                               slave_rpc_update_handle(slave, s_info.hello_ctx.handle, 1);
                        } else {
-                               ErrPrint("slave_hello pid[%d] != pid[%d]", s_slave_hello.pid,pid);
+                               ErrPrint("slave_hello pid[%d] != pid[%d]", s_info.hello_ctx.pid,pid);
                        }
 
                        DbgPrint("Slave is activated by request: %d (%s)/(%s)\n", pid, pkgname, slavename);
@@ -7999,6 +8014,9 @@ static struct packet *slave_hello_sync(pid_t pid, int handle, const struct packe
                        result = instance_watch_create(widget_id, width, height);
                        if (!result) {
                                ErrPrint("Failed to create a new instance\n");
+                               if (slave_unref(slave)) {
+                                       ErrPrint("Slave is not deleted yet\n");
+                               }
                        }
                        DbgFree(widget_id);
                }
@@ -8009,7 +8027,6 @@ static struct packet *slave_hello_sync(pid_t pid, int handle, const struct packe
                unsigned int widget_size;
                Eina_List *inst_list;
                Eina_List *inst_l;
-               int count = 0;
                const char *category;
 
                widget_id = is_valid_slave(pid, abi, pkgname);
@@ -8021,7 +8038,7 @@ static struct packet *slave_hello_sync(pid_t pid, int handle, const struct packe
                if (!info) {
                        char *pkgid;
 
-                       pkgid = widget_service_package_id(widget_id);
+                       pkgid = widget_service_get_package_id(widget_id);
                        if (!pkgid) {
                                DbgFree(widget_id);
                                goto out;
@@ -8035,7 +8052,7 @@ static struct packet *slave_hello_sync(pid_t pid, int handle, const struct packe
                inst_list = package_instance_list(info);
                inst = NULL;
                EINA_LIST_FOREACH(inst_list, inst_l, inst) {
-                       if (!strcmp(instance_package(inst), widget_id)) {
+                       if (!strcmp(package_name(instance_package(inst)), widget_id)) {
                                break;
                        }
                        inst = NULL;
@@ -8063,16 +8080,17 @@ static struct packet *slave_hello_sync(pid_t pid, int handle, const struct packe
                slave_set_valid(slave);
 
                if (strcmp(CATEGORY_WATCH_CLOCK, category) == 0) {
-                       //if the new provider is watch app, destroy the old watch app instance
+                       /**
+                        * @note
+                        * If a new provider is watch app, destroy the old watch app instance
+                        */
                        package_del_instance_by_category(CATEGORY_WATCH_CLOCK, widget_id);
                }
 
-               slave_rpc_clear_pending_list(slave);
-
-               if (s_slave_hello.pid == pid) {
-                       slave_rpc_update_handle(slave, s_slave_hello.handle);
+               if (s_info.hello_ctx.pid == pid) {
+                       slave_rpc_update_handle(slave, s_info.hello_ctx.handle, 0);
                } else {
-                       ErrPrint("slave_hello pid[%d] != pid[%d]", s_slave_hello.pid, pid);
+                       ErrPrint("slave_hello pid[%d] != pid[%d]", s_info.hello_ctx.pid, pid);
                }
 
                DbgPrint("Slave is activated by request: %d (%s)/(%s)\n", pid, pkgname, slavename);
@@ -8092,8 +8110,8 @@ static struct packet *slave_hello_sync(pid_t pid, int handle, const struct packe
                DbgFree(widget_id);
        }
 
-       s_slave_hello.pid = -1;
-       s_slave_hello.handle = -1;
+       s_info.hello_ctx.pid = -1;
+       s_info.hello_ctx.handle = -1;
 
 out:
        return result;
index 5e24f0e..04804ce 100755 (executable)
@@ -111,6 +111,7 @@ struct slave_node {
 #endif
 
        char *hw_acceleration;
+       int valid;
 };
 
 struct event {
index 7fe6d21..b429628 100755 (executable)
@@ -504,7 +504,7 @@ HAPI int slave_rpc_request_only(struct slave_node *slave, const char *pkgname, s
        return WIDGET_ERROR_NONE;
 }
 
-HAPI int slave_rpc_update_handle(struct slave_node *slave, int handle)
+HAPI int slave_rpc_update_handle(struct slave_node *slave, int handle, int delete_pending_packet)
 {
        struct slave_rpc *rpc;
        struct command *command;
@@ -534,7 +534,11 @@ HAPI int slave_rpc_update_handle(struct slave_node *slave, int handle)
        slave_activated(slave);
 
        EINA_LIST_FREE(rpc->pending_list, command) {
-               push_command(command);
+               if (delete_pending_packet) {
+                       destroy_command(command);
+               } else {
+                       push_command(command);
+               }
        }
 
        return WIDGET_ERROR_NONE;
@@ -705,27 +709,4 @@ HAPI int slave_rpc_disconnect(struct slave_node *slave)
        return slave_rpc_request_only(slave, NULL, packet, 0);
 }
 
-HAPI int slave_rpc_clear_pending_list(struct slave_node *slave)
-{
-    struct slave_rpc *rpc;
-    struct command *command;
-
-    rpc = slave_data(slave, "rpc");
-    if (!rpc) {
-        /*!
-         * \note
-         * Return negative value will remove this callback from the event list of the slave
-         */
-        return WIDGET_ERROR_INVALID_PARAMETER;
-    }
-
-    EINA_LIST_FREE(rpc->pending_list, command) {
-        assert(command->slave == slave);
-
-        destroy_command(command);
-    }
-
-    return WIDGET_ERROR_NONE;
-}
-
 /* End of a file */
index 0ebcf14..b5183ab 100755 (executable)
@@ -42,6 +42,7 @@
 #include <com-core.h>
 
 #include <widget_service.h>
+#include <widget_service_internal.h>
 
 #include <Ecore.h>