afm-user-daemon: prepare to launch with mode
[src/app-framework-main.git] / src / afm-run.c
index b9e1e7c..c414ceb 100644 (file)
@@ -32,8 +32,9 @@
 #include "verbose.h"
 #include "utils-dir.h"
 #include "utils-json.h"
-#include "afm-run.h"
+#include "afm-launch-mode.h"
 #include "afm-launch.h"
+#include "afm-run.h"
 
 enum appstate {
        as_starting,
@@ -239,19 +240,21 @@ static void on_sigchld(int signum, siginfo_t *info, void *uctxt)
 
 /**************** handle afm_launch_desc *********************/
 
-static int fill_launch_desc(struct json_object *appli, struct afm_launch_desc *desc)
+static int fill_launch_desc(struct json_object *appli, enum afm_launch_mode mode, struct afm_launch_desc *desc)
 {
        json_object *pub;
 
+       assert(launch_mode_is_valid(mode));
+
        /* main items */
-       if(!j_object(appli, "public", &pub)
-       || !j_string(appli, "path", &desc->path)
-       || !j_string(appli, "id", &desc->tag)
-       || !j_string(appli, "content", &desc->content)
-       || !j_string(appli, "type", &desc->type)
-       || !j_string(pub, "name", &desc->name)
-       || !j_integer(pub, "width", &desc->width)
-       || !j_integer(pub, "height", &desc->height)) {
+       if(!j_read_object_at(appli, "public", &pub)
+       || !j_read_string_at(appli, "path", &desc->path)
+       || !j_read_string_at(appli, "id", &desc->tag)
+       || !j_read_string_at(appli, "content", &desc->content)
+       || !j_read_string_at(appli, "type", &desc->type)
+       || !j_read_string_at(pub, "name", &desc->name)
+       || !j_read_integer_at(pub, "width", &desc->width)
+       || !j_read_integer_at(pub, "height", &desc->height)) {
                errno = EINVAL;
                return -1;
        }
@@ -265,20 +268,23 @@ static int fill_launch_desc(struct json_object *appli, struct afm_launch_desc *d
 
        /* finaly */
        desc->home = homeappdir;
+       desc->mode = mode;
        return 0;
 };
 
 /**************** API handling ************************/
 
-int afm_run_start(struct json_object *appli)
+int afm_run_start(struct json_object *appli, enum afm_launch_mode mode, char **uri)
 {
        static struct apprun *runner;
        struct afm_launch_desc desc;
        int rc;
        sigset_t saved, blocked;
 
+       assert(launch_mode_is_valid(mode));
+
        /* prepare to launch */
-       rc = fill_launch_desc(appli, &desc);
+       rc = fill_launch_desc(appli, mode, &desc);
        if (rc)
                return rc;
        runner = createrunner(appli);
@@ -291,7 +297,7 @@ int afm_run_start(struct json_object *appli)
        sigprocmask(SIG_BLOCK, &blocked, &saved);
 
        /* launch now */
-       rc = afm_launch(&desc, runner->pids);
+       rc = afm_launch(&desc, runner->pids, uri);
        if (rc < 0) {
                /* fork failed */
                sigprocmask(SIG_SETMASK, &saved, NULL);