summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/widget_instance.c166
1 files changed, 112 insertions, 54 deletions
diff --git a/src/widget_instance.c b/src/widget_instance.c
index f8aeaaa..bf2e8a8 100644
--- a/src/widget_instance.c
+++ b/src/widget_instance.c
@@ -32,6 +32,7 @@
#include <widget_service.h>
#include <widget_service_internal.h>
#include <app.h>
+#include <bundle_internal.h>
#include "widget_errno.h"
#define USER_UID_MIN 5000
@@ -76,6 +77,13 @@ struct widget_app {
GList *instances;
};
+struct _sdk_util {
+ char *name;
+ char **args;
+ int argc;
+ char *caller;
+};
+
static char *wayland_display = NULL;
static char *xdg_runtime_dir = NULL;
@@ -89,10 +97,7 @@ static aul_app_com_connection_h conn_status;
static GHashTable *lifecycle_tbl;
static int is_status_handler_connected;
-static char *sdk_util = NULL;
-static char *sdk_util_path = NULL;
-static char *sdk_util_arg = NULL;
-static char *sdk_caller_pid = NULL;
+static struct _sdk_util sdk_util;
static char *package_id;
@@ -109,6 +114,7 @@ struct event_cb_s {
};
static int __fault_handler(int pid);
+static void __free_sdk_util(void);
static struct _widget_instance *__pick_instance(const char *instance_id)
{
@@ -395,7 +401,6 @@ EAPI int widget_instance_launch(const char *instance_id, char *content_info, int
bundle *b;
widget_instance_h instance;
-
_D("launch: %s", instance_id);
if (instance_id == NULL) {
@@ -439,21 +444,22 @@ EAPI int widget_instance_launch(const char *instance_id, char *content_info, int
bundle_add_str(b, AUL_K_WAYLAND_WORKING_DIR, xdg_runtime_dir);
bundle_add_str(b, WIDGET_K_OPERATION, "create");
- if (sdk_util != NULL) {
- bundle_add_str(b, AUL_K_ORG_CALLER_PID, sdk_caller_pid);
- if (strcmp(sdk_util, SDK_DEBUG) == 0) {
- bundle_add_str(b, AUL_K_SDK, SDK_DEBUG);
- if (sdk_util_path)
- bundle_add_str(b, DLP_K_GDBSERVER_PATH, sdk_util_path);
- if (sdk_util_arg)
- bundle_add_str(b, DLP_K_DEBUG_ARG, sdk_util_arg);
- } else if (strcmp(sdk_util, SDK_VALGRIND) == 0) {
- bundle_add_str(b, AUL_K_SDK, SDK_VALGRIND);
- if (sdk_util_path)
- bundle_add_str(b, DLP_K_VALGRIND_PATH, sdk_util_path);
- if (sdk_util_arg)
- bundle_add_str(b, DLP_K_VALGRIND_ARG, sdk_util_arg);
+ if (sdk_util.name) {
+ bundle_add_str(b, AUL_K_SDK, sdk_util.name);
+ if (sdk_util.caller)
+ bundle_add_str(b, AUL_K_ORG_CALLER_PID, sdk_util.caller);
+ if (strcmp(sdk_util.name, SDK_DEBUG) == 0) {
+ if (sdk_util.args) {
+ bundle_add_str_array(b, DLP_K_DEBUG_ARG,
+ (const char **)sdk_util.args, sdk_util.argc);
+ }
+ } else if (strcmp(sdk_util.name, SDK_VALGRIND) == 0) {
+ if (sdk_util.args) {
+ bundle_add_str_array(b, DLP_K_VALGRIND_ARG,
+ (const char **)sdk_util.args, sdk_util.argc);
+ }
}
+ __free_sdk_util();
}
if (content_info) {
@@ -1172,57 +1178,109 @@ EAPI int widget_instance_unlisten_status(const char *widget_id)
return 0;
}
-EAPI int widget_service_set_sdk_util(bundle *data)
+static void __free_sdk_util(void)
{
- char *util = NULL;
- char *util_path = NULL;
- char *util_arg = NULL;
- char *caller_pid = NULL;
+ int i;
- if (sdk_util) {
- free(sdk_util);
- sdk_util = NULL;
+ if (sdk_util.caller) {
+ free(sdk_util.caller);
+ sdk_util.caller = NULL;
}
- if (sdk_util_path) {
- free(sdk_util_path);
- sdk_util_path = NULL;
+ if (sdk_util.args) {
+ for (i = 0; i < sdk_util.argc; i++) {
+ if (sdk_util.args[i])
+ free(sdk_util.args[i]);
+ }
+ free(sdk_util.args);
+ sdk_util.args = NULL;
+ sdk_util.argc = 0;
}
- if (sdk_util_arg) {
- free(sdk_util_arg);
- sdk_util_arg = NULL;
+ if (sdk_util.name) {
+ free(sdk_util.name);
+ sdk_util.name = NULL;
}
+}
- if (sdk_caller_pid) {
- free(sdk_caller_pid);
- sdk_caller_pid = NULL;
- }
+EAPI int widget_service_set_sdk_util(bundle *data)
+{
+ const char *caller_pid;
+ const char *util;
+ const char *util_arg = NULL;
+ const char **util_arg_array = NULL;
+ int len = 0;
+ int ret;
+ int i;
- bundle_get_str(data, AUL_K_SDK, &util);
- bundle_get_str(data, AUL_K_ORG_CALLER_PID, &caller_pid);
+ __free_sdk_util();
+
+ caller_pid = bundle_get_val(data, AUL_K_ORG_CALLER_PID);
if (caller_pid == NULL)
- bundle_get_str(data, AUL_K_CALLER_PID, &caller_pid);
+ caller_pid = bundle_get_val(data, AUL_K_CALLER_PID);
- if (util) {
- sdk_util = strdup(util);
+ util = bundle_get_val(data, AUL_K_SDK);
+ if (util == NULL)
+ return -1;
- if (strcmp(util, SDK_DEBUG) == 0) {
- bundle_get_str(data, DLP_K_GDBSERVER_PATH, &util_path);
- bundle_get_str(data, DLP_K_DEBUG_ARG, &util_arg);
- } else if (strcmp(util, SDK_VALGRIND) == 0) {
- bundle_get_str(data, DLP_K_VALGRIND_PATH, &util_path);
- bundle_get_str(data, DLP_K_VALGRIND_ARG, &util_arg);
+ sdk_util.name = strdup(util);
+ if (sdk_util.name == NULL) {
+ _E("out of memory");
+ return -1;
+ }
+
+ if (strcmp(util, SDK_DEBUG) == 0) {
+ ret = bundle_get_type(data, DLP_K_DEBUG_ARG);
+ if (ret == BUNDLE_TYPE_STR_ARRAY) {
+ util_arg_array = bundle_get_str_array(data,
+ DLP_K_DEBUG_ARG, &len);
+ } else if (ret == BUNDLE_TYPE_STR) {
+ util_arg = bundle_get_val(data, DLP_K_DEBUG_ARG);
+ if (util_arg) {
+ util_arg_array = &util_arg;
+ len = 1;
+ }
+ }
+ } else if (strcmp(util, SDK_VALGRIND) == 0) {
+ ret = bundle_get_type(data, DLP_K_VALGRIND_ARG);
+ if (ret == BUNDLE_TYPE_STR_ARRAY) {
+ util_arg_array = bundle_get_str_array(data,
+ DLP_K_VALGRIND_ARG, &len);
+ } else if (ret == BUNDLE_TYPE_STR) {
+ util_arg = bundle_get_val(data, DLP_K_VALGRIND_ARG);
+ if (util_arg) {
+ util_arg_array = &util_arg;
+ len = 1;
+ }
}
+ }
- if (util_path)
- sdk_util_path = strdup(util_path);
+ if (util_arg_array) {
+ sdk_util.argc = len;
+ sdk_util.args = calloc(len + 1, sizeof(char *));
+ if (sdk_util.args == NULL) {
+ _E("out of memory");
+ __free_sdk_util();
+ return -1;
+ }
- if (util_arg)
- sdk_util_arg = strdup(util_arg);
+ for (i = 0; i < len; i++) {
+ sdk_util.args[i] = strdup(util_arg_array[i]);
+ if (sdk_util.args[i] == NULL) {
+ _E("out of memory");
+ __free_sdk_util();
+ return -1;
+ }
+ }
+ }
- if (caller_pid)
- sdk_caller_pid = strdup(caller_pid);
+ if (caller_pid) {
+ sdk_util.caller = strdup(caller_pid);
+ if (sdk_util.caller == NULL) {
+ _E("out of memory");
+ __free_sdk_util();
+ return -1;
+ }
}
return 0;