/*
- Copyright 2015, 2016 IoT.bzh
+ Copyright 2015, 2016, 2017 IoT.bzh
author: José Bollo <jose.bollo@iot.bzh>
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'
*/
|| !j_read_string_at(pub, "name", &desc->name)
|| !j_read_integer_at(pub, "width", &desc->width)
|| !j_read_integer_at(pub, "height", &desc->height)) {
+ ERROR("bad internal description of the application to launch: %s", json_object_get_string(appli));
errno = EINVAL;
return -1;
}
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'
*