Support Widget Debugging mode for SDK
authorSung-jae Park <nicesj.park@samsung.com>
Wed, 20 May 2015 10:22:28 +0000 (19:22 +0900)
committerSung-jae Park <nicesj.park@samsung.com>
Wed, 20 May 2015 10:22:28 +0000 (19:22 +0900)
Change-Id: I924f3441ad1156c42ee19831d9e97d1dc220bb08

include/client_life.h
include/slave_life.h
src/client_life.c
src/instance.c
src/slave_life.c

index b7691a6..93d7cb6 100644 (file)
@@ -115,4 +115,7 @@ extern const char *client_direct_addr(const struct client_node *client);
 
 extern int client_orientation(const struct client_node *client);
 extern void client_set_orientation(struct client_node *client, int orientation);
+
+extern const char *client_appid(const struct client_node *client);
+extern int client_is_sdk_viewer(const struct client_node *client);
 /* End of a file */
index 4684d8d..0529ad4 100644 (file)
@@ -218,4 +218,7 @@ extern int slave_set_priority(struct slave_node *slave, int priority);
 extern int slave_valid(const struct slave_node *slave);
 extern void slave_set_valid(struct slave_node *slave);
 
+extern void slave_set_extra_bundle_data(struct slave_node *slave, const char *extra_bundle_data);
+extern const char *slave_extra_bundle_data(struct slave_node *slave);
+
 /* End of a file */
index 130d51c..0cc5b0d 100644 (file)
 #include <Eina.h>
 #include <Ecore.h>
 
+#include <aul.h>
 #include <dlog.h>
+
 #include <packet.h>
 #include <widget_errno.h>
 #include <widget_service.h>
 #include <widget_service_internal.h>
+#include <widget_conf.h>
 
 #include "client_life.h"
 #include "instance.h"
@@ -90,6 +93,7 @@ struct data_item {
 };
 
 struct client_node {
+       char *appid;
        pid_t pid;
        int refcnt;
 
@@ -110,6 +114,7 @@ struct client_node {
        int faulted;
        char *direct_addr;
        int orientation;
+       int is_sdk_viewer;
 };
 
 static inline void invoke_global_destroyed_cb(struct client_node *client)
@@ -259,6 +264,8 @@ static inline void destroy_client_data(struct client_node *client)
                DbgFree(client->direct_addr);
        }
 
+       DbgFree(client->appid);
+
        s_info.client_list = eina_list_remove(s_info.client_list, client);
        DbgFree(client);
 
@@ -273,6 +280,7 @@ static inline void destroy_client_data(struct client_node *client)
 static inline struct client_node *create_client_data(pid_t pid, const char *direct_addr)
 {
        struct client_node *client;
+       char pid_pkgname[pathconf("/", _PC_PATH_MAX)];
 
        client = calloc(1, sizeof(*client));
        if (!client) {
@@ -283,6 +291,17 @@ static inline struct client_node *create_client_data(pid_t pid, const char *dire
        client->pid = pid;
        client->refcnt = 1;
 
+       if (aul_app_get_pkgname_bypid(pid, pid_pkgname, sizeof(pid_pkgname)) == AUL_R_OK) {
+               client->appid = strdup(pid_pkgname);
+               if (client->appid) {
+                       if (WIDGET_CONF_SDK_VIEWER) {
+                               client->is_sdk_viewer = !strcmp(client->appid, WIDGET_CONF_SDK_VIEWER);
+                       }
+               } else {
+                       ErrPrint("strdup: %d\n", errno);
+               }
+       }
+
        if (direct_addr && direct_addr[0]) {
                client->direct_addr = strdup(direct_addr);
                if (!client->direct_addr) {
@@ -1034,4 +1053,14 @@ HAPI int client_orientation(const struct client_node *client)
        return client->orientation;
 }
 
+HAPI const char *client_appid(const struct client_node *client)
+{
+       return client->appid;
+}
+
+HAPI int client_is_sdk_viewer(const struct client_node *client)
+{
+       return client ? client->is_sdk_viewer : 0;
+}
+
 /* End of a file */
index 079887d..a7db644 100644 (file)
@@ -930,6 +930,7 @@ static inline int fork_package(struct inst_info *inst, const char *pkgname)
 HAPI struct inst_info *instance_create(struct client_node *client, double timestamp, const char *pkgname, const char *content, const char *cluster, const char *category, double period, int width, int height)
 {
        struct inst_info *inst;
+       char *extra_bundle_data = NULL;
 
        inst = calloc(1, sizeof(*inst));
        if (!inst) {
@@ -941,16 +942,47 @@ HAPI struct inst_info *instance_create(struct client_node *client, double timest
        inst->widget.width = width;
        inst->widget.height = height;
 
-       inst->content = strdup(content);
-       if (!inst->content) {
-               ErrPrint("strdup: %d\n", errno);
-               DbgFree(inst);
-               return NULL;
+       if (client_is_sdk_viewer(client)) {
+               char *tmp;
+
+               tmp = strdup(content);
+               if (tmp) {
+                       int length;
+
+                       if (sscanf(content, "%d:%s", &length, tmp) == 2) {
+                               extra_bundle_data = malloc(length + 1);
+                               if (extra_bundle_data) {
+                                       strncpy(extra_bundle_data, tmp, length);
+                                       extra_bundle_data[length] = '\0';
+                                       tmp += length;
+                                       DbgPrint("Extra Bundle Data extracted: [%s]\n", extra_bundle_data);
+                               }
+
+                               if (*tmp) {
+                                       inst->content = strdup(tmp);
+                                       if (!inst->content) {
+                                               ErrPrint("strdup: %d\n", errno);
+                                       }
+                                       DbgPrint("Content Info extracted: [%d]\n", inst->content);
+                               }
+                       }
+
+                       DbgFree(tmp);
+               }
+       } else {
+               inst->content = strdup(content);
+               if (!inst->content) {
+                       ErrPrint("strdup: %d\n", errno);
+                       DbgFree(extra_bundle_data);
+                       DbgFree(inst);
+                       return NULL;
+               }
        }
 
        inst->cluster = strdup(cluster);
        if (!inst->cluster) {
                ErrPrint("strdup: %d\n", errno);
+               DbgFree(extra_bundle_data);
                DbgFree(inst->content);
                DbgFree(inst);
                return NULL;
@@ -959,6 +991,7 @@ HAPI struct inst_info *instance_create(struct client_node *client, double timest
        inst->category = strdup(category);
        if (!inst->category) {
                ErrPrint("strdup: %d\n", errno);
+               DbgFree(extra_bundle_data);
                DbgFree(inst->cluster);
                DbgFree(inst->content);
                DbgFree(inst);
@@ -968,6 +1001,7 @@ HAPI struct inst_info *instance_create(struct client_node *client, double timest
        inst->title = strdup(WIDGET_CONF_DEFAULT_TITLE); /*!< Use the DEFAULT Title "" */
        if (!inst->title) {
                ErrPrint("strdup: %d\n", errno);
+               DbgFree(extra_bundle_data);
                DbgFree(inst->category);
                DbgFree(inst->cluster);
                DbgFree(inst->content);
@@ -985,6 +1019,7 @@ HAPI struct inst_info *instance_create(struct client_node *client, double timest
 
        if (fork_package(inst, pkgname) < 0) {
                (void)client_unref(inst->client);
+               DbgFree(extra_bundle_data);
                DbgFree(inst->title);
                DbgFree(inst->category);
                DbgFree(inst->cluster);
@@ -1010,6 +1045,7 @@ HAPI struct inst_info *instance_create(struct client_node *client, double timest
        instance_ref(inst);
 
        if (package_add_instance(inst->info, inst) < 0) {
+               DbgFree(extra_bundle_data);
                DbgFree(inst->widget.extra_buffer);
                DbgFree(inst->gbar.extra_buffer);
                unfork_package(inst);
@@ -1023,6 +1059,8 @@ HAPI struct inst_info *instance_create(struct client_node *client, double timest
        }
 
        slave_load_instance(package_slave(inst->info));
+       slave_set_extra_bundle_data(package_slave(inst->info), extra_bundle_data);
+       DbgFree(extra_bundle_data);
 
        /**
         * @note
index 62f60d8..9cbe2cd 100644 (file)
@@ -113,6 +113,7 @@ struct slave_node {
 
        char *hw_acceleration;
        int valid;
+       char *extra_bundle_data;
 };
 
 struct event {
@@ -426,6 +427,7 @@ static inline void destroy_slave_node(struct slave_node *slave)
        DbgFree(slave->name);
        DbgFree(slave->pkgname);
        DbgFree(slave->hw_acceleration);
+       DbgFree(slave->extra_bundle_data);
        DbgFree(slave);
        return;
 }
@@ -745,14 +747,23 @@ HAPI int slave_activate(struct slave_node *slave)
        if (WIDGET_CONF_DEBUG_MODE || g_conf.debug_mode) {
                DbgPrint("Debug Mode enabled. name[%s] secured[%d] abi[%s]\n", slave_name(slave), slave->secured, slave->abi);
        } else {
-               bundle *param;
+               bundle *param = NULL;
 
                slave->relaunch_count = WIDGET_CONF_SLAVE_RELAUNCH_COUNT;
 
-               param = bundle_create();
+               if (slave->extra_bundle_data) {
+                       param = bundle_decode(slave->extra_bundle_data, strlen(slave->extra_bundle_data));
+                       if (!param) {
+                               ErrPrint("Invalid extra_bundle_data[%s]\n", slave->extra_bundle_data);
+                       }
+               }
+
                if (!param) {
-                       ErrPrint("Failed to create a bundle\n");
-                       return WIDGET_ERROR_FAULT;
+                       param = bundle_create();
+                       if (!param) {
+                               ErrPrint("Failed to create a bundle\n");
+                               return WIDGET_ERROR_FAULT;
+                       }
                }
 
                bundle_add_str(param, BUNDLE_SLAVE_SVC_OP_TYPE, APP_CONTROL_OPERATION_MAIN);
@@ -1984,4 +1995,29 @@ HAPI void slave_set_valid(struct slave_node *slave)
     slave->valid = 1;
 }
 
+HAPI void slave_set_extra_bundle_data(struct slave_node *slave, const char *extra_bundle_data)
+{
+       char *tmp;
+
+       if (!slave) {
+               return;
+       }
+
+       if (extra_bundle_data) {
+               tmp = strdup(extra_bundle_data);
+               if (!tmp) {
+                       ErrPrint("strdup: %d\n", errno);
+                       return;
+               }
+       }
+
+       DbgFree(slave->extra_bundle_data);
+       slave->extra_bundle_data = tmp;
+}
+
+HAPI const char *slave_extra_bundle_data(struct slave_node *slave)
+{
+       return slave ? slave->extra_bundle_data : NULL;
+}
+
 /* End of a file */