- appli = af_db_get_application(afdb, appid);
- if (appli == NULL)
- jbus_reply_error_s(jreq, error_not_found);
- else {
- runid = af_run_start(appli);
- if (runid <= 0)
- jbus_reply_error_s(jreq, error_cant_start);
- else {
- snprintf(runidstr, sizeof runidstr, "%d", runid);
- runidstr[sizeof runidstr - 1] = 0;
- jbus_reply_s(jreq, runidstr);
- }
- }
+#ifdef LEGACY_MODE_WITHOUT_SYSTEMD
+ afm_run_terminate(runid);
+#else
+ afm_urun_terminate(runid);
+#endif
+ jbus_reply_error_s(smsg, error_system);
+ }
+ json_object_put(resp);
+ free(uri);
+}
+
+/*
+ * On query "once" from 'smsg' with parameters of 'obj'.
+ */
+static void on_once(struct sd_bus_message *smsg, struct json_object *obj, void *unused)
+{
+ const char *appid;
+ struct json_object *appli, *resp;
+ int runid;
+
+ /* get the parameters */
+ if (!j_read_string(obj, &appid) && !j_read_string_at(obj, "id", &appid)) {
+ jbus_reply_error_s(smsg, error_bad_request);
+ return;
+ }
+
+ /* get the application */
+ INFO("method once called for %s", appid);
+#ifdef LEGACY_MODE_WITHOUT_SYSTEMD
+ appli = afm_db_get_application(afdb, appid);
+#else
+ appli = afm_udb_get_application_private(afudb, appid);
+#endif
+ if (appli == NULL) {
+ jbus_reply_error_s(smsg, error_not_found);
+ return;
+ }
+
+ /* launch the application */
+#ifdef LEGACY_MODE_WITHOUT_SYSTEMD
+ runid = afm_run_once(appli);
+#else
+ runid = afm_urun_once(appli);
+#endif
+ if (runid <= 0) {
+ jbus_reply_error_s(smsg, error_cant_start);
+ return;
+ }
+
+ /* returns the state */
+#ifdef LEGACY_MODE_WITHOUT_SYSTEMD
+ resp = afm_run_state(runid);
+#else
+ resp = afm_urun_state(afudb, runid);
+#endif
+ reply(smsg, resp, error_not_found);
+ json_object_put(resp);
+}
+
+/*
+ * On query "pause" from 'smsg' with parameters of 'obj'.
+ */
+static void on_pause(struct sd_bus_message *smsg, struct json_object *obj, void *unused)
+{
+ int runid, status;
+ if (onrunid(smsg, obj, "pause", &runid)) {
+#ifdef LEGACY_MODE_WITHOUT_SYSTEMD
+ status = afm_run_pause(runid);
+#else
+ status = afm_urun_pause(runid);
+#endif
+ reply_status(smsg, status, error_not_found);
+ }
+}
+
+/*
+ * On query "resume" from 'smsg' with parameters of 'obj'.
+ */
+static void on_resume(struct sd_bus_message *smsg, struct json_object *obj, void *unused)
+{
+ int runid, status;
+ if (onrunid(smsg, obj, "resume", &runid)) {
+#ifdef LEGACY_MODE_WITHOUT_SYSTEMD
+ status = afm_run_resume(runid);
+#else
+ status = afm_urun_resume(runid);
+#endif
+ reply_status(smsg, status, error_not_found);