Add debug feature for debugging apps purpose 64/28664/2
authorBaptiste DURAND <baptiste.durand@open.eurogiciel.org>
Mon, 13 Oct 2014 15:00:12 +0000 (17:00 +0200)
committerBaptiste DURAND <baptiste.durand@open.eurogiciel.org>
Mon, 13 Oct 2014 15:26:13 +0000 (17:26 +0200)
-d argument permits to enable debug on the apps.

xwalk deamon should be launched with remote-debbugging-port option

BUG-Tizen=TC-1666
Signed-off-by: Baptiste DURAND <baptiste.durand@open.eurogiciel.org>
Change-Id: I7f52a31a6d45237f022707f798d8d317c562719d

am_session_agent/agent.c
include/aul.h
test/open_app.c

index 1d1efd0..1125169 100644 (file)
@@ -210,6 +210,9 @@ _static_ void __real_launch(const char *app_path, bundle * kb)
        char **app_argv;
        int i;
 
+       if(bundle_get_val(kb, AUL_K_DEBUG) != NULL)
+               putenv("TIZEN_DEBUGGING_PORT=1");
+
        app_argv = __create_argc_argv(kb, &app_argc);
        app_argv[0] = strdup(app_path);
 
index cc417a9..6df6460 100755 (executable)
@@ -175,6 +175,9 @@ typedef enum _aul_type{
 /** AUL public key - To force launch app selector instead of lauchingn default app */
 #define AUL_K_FORCE_LAUNCH_APP_SELECTOR        "__AUL_FORCE_LAUNCH_APP_SELECTOR__"
 
+/** AUL public key - To support debug argument */
+#define AUL_K_DEBUG    "__AUL_DEBUG__"
+
 /** AUL public key - To support SDK */
 #define AUL_K_SDK      "__AUL_SDK__"
 
index 53616ca..b083dec 100755 (executable)
 static char **gargv;
 static int gargc;
 bundle *kb = NULL;
+static int debugFlag = 0;
 
 static GMainLoop *mainloop = NULL;
 
-static bundle *create_internal_bundle(int start)
+static bundle *create_internal_bundle()
 {
        bundle *kb;
        int i;
@@ -45,48 +46,31 @@ static bundle *create_internal_bundle(int start)
        char* val_array[128];
 
        kb = bundle_create();
-       for (i = start; i < gargc - 1; i++) {
-               if ((i + 1) > gargc - 1)
-                       bundle_add(kb, gargv[i], " ");
-               else {
-                       int j = 1;
-                       strncpy(arg, gargv[i + 1], 1023);
-                       val_array[0] = strtok(arg,",");
-                       while(1)
-                       {
-                               val_array[j] = strtok(NULL,",");
-                               if(val_array[j] == NULL)
-                                       break;
-                               j++;
-                       }
-                       if(j==1)
-                               bundle_add(kb, gargv[i], gargv[i + 1]);
-                       else if(j>1)
-                               bundle_add_str_array(kb, gargv[i],
-                                       (const char**)val_array, j);
-               }
-       }
-
+       bundle_add(kb, AUL_K_DEBUG, "1");
        return kb;
 }
 
-int launch()
+int launch(int debug_option)
 {
        int pid = -1;
 
-       kb = create_internal_bundle(2);
-       if (NULL == kb) {
-               printf("bundle creation fail\n");
-               return -1;
-       }
 
-       pid = aul_open_app(gargv[1]);
+       if(!debug_option)
+               pid = aul_open_app(gargv[1]);
+       else {
+               kb = create_internal_bundle();
+               if (NULL == kb) {
+                       printf("bundle creation fail\n");
+                       return -1;
+               }
+               pid = aul_launch_app(gargv[1], kb);
+       }
        return pid;
 }
 
 void print_usage(char *progname)
 {
-       printf("[usage] %s <appid>\n",
+       printf("[usage] %s <appid> [-d]\n",
               progname);
 }
 
@@ -104,24 +88,25 @@ static gboolean run_func(void *data)
 {
        int pid = -1;
        char *str = NULL;
-       if ((pid = launch()) > 0) {
+       if ((pid = launch(debugFlag)) > 0) {
                printf("... successfully launched\n");
        } else {
                printf("... launch failed\n");
        }
+       if (kb) {
+               str = bundle_get_val(kb, "__LAUNCH_APP_MODE__");
 
-       str = bundle_get_val(kb, "__LAUNCH_APP_MODE__");
-
-       if( str && strcmp(str, "SYNC") == 0 ) {
-               aul_listen_app_dead_signal(__launch_app_dead_handler, pid);
-       } else {
-               g_main_loop_quit(mainloop);
-       }
+               if( str && strcmp(str, "SYNC") == 0 ) {
+                       aul_listen_app_dead_signal(__launch_app_dead_handler, pid);
+               } else {
+                       g_main_loop_quit(mainloop);
+               }
 
-       if (kb) {
                bundle_free(kb);
                kb = NULL;
-       }
+       } else 
+               g_main_loop_quit(mainloop);
+
 
        return TRUE;
 }
@@ -129,7 +114,7 @@ static gboolean run_func(void *data)
 
 int main(int argc, char **argv)
 {
-       if (argc < 2) {
+       if ((argc < 2)||(argc > 3)) {
                print_usage(argv[0]);
                exit(EXIT_FAILURE);
        }
@@ -137,6 +122,14 @@ int main(int argc, char **argv)
        gargc = argc;
        gargv = argv;
 
+       if(argc == 3) {
+               if( (strcmp(argv[2],"-d")  != 0 ) && (strcmp(argv[1],"-d")  != 0 ) ) {
+                       printf("additionnal argument should be -d to enable debugging\n");
+                       print_usage(argv[0]);
+                       exit(EXIT_FAILURE);
+               }
+               debugFlag = 1;
+       }
        aul_launch_init(NULL, NULL);
 
        g_idle_add(run_func, NULL);