X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fafm-run.c;fp=src%2Fafm-run.c;h=f4f55e5851c6cdd42c5f7fbc91aafa4d876298fa;hb=a1f7f7d2cd79c9391368d0c017452566a5edc44c;hp=537ba62cab93d5eb4c0d680f631b8ecd38ffb722;hpb=b6ac54640c918aecaf2f28edf82f8217154b12f3;p=src%2Fapp-framework-main.git diff --git a/src/afm-run.c b/src/afm-run.c index 537ba62..f4f55e5 100644 --- a/src/afm-run.c +++ b/src/afm-run.c @@ -247,6 +247,25 @@ static struct apprun *getrunner(int runid) return result; } +/* + * Get first runner of 'appli' (NULL if not found) + */ +static struct apprun *getrunner_appli(json_object *appli) +{ + int i; + struct apprun *result; + + for (i = 0 ; i < ROOT_RUNNERS_COUNT ; i++) { + result = runners_by_pgid[i]; + while (result != NULL) { + if (result->appli == appli) + return result; + result = result->next_by_pgid; + } + } + return NULL; +} + /* * Free an existing 'runner' */ @@ -592,6 +611,23 @@ int afm_run_start(struct json_object *appli, enum afm_launch_mode mode, return rc; } +/* + * Returns the runid of a previously started application 'appli' + * or if none is running, starts the application described by 'appli' + * in local mode. + * + * A reference to 'appli' is kept during the live of the + * runner. This is made using json_object_get. Thus be aware + * that further modifications to 'appli' might create errors. + * + * Returns the runid in case of success or -1 in case of error + */ +int afm_run_once(struct json_object *appli) +{ + struct apprun *runner = getrunner_appli(appli); + return runner && is_alive(runner) ? runner->runid : afm_run_start(appli, mode_local, NULL); +} + /* * Terminates the runner of 'runid' *