summaryrefslogtreecommitdiffstats
path: root/src/afm-run.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/afm-run.c')
-rw-r--r--src/afm-run.c36
1 files changed, 36 insertions, 0 deletions
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
@@ -248,6 +248,25 @@ static struct apprun *getrunner(int runid)
}
/*
+ * 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'
*/
static void freerunner(struct apprun *runner)
@@ -593,6 +612,23 @@ int afm_run_start(struct json_object *appli, enum afm_launch_mode mode,
}
/*
+ * 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'
*
* Returns 0 in case of success or -1 in case of error