- }
- if (!is_valid_launch_mode(mode)) {
- jbus_reply_error_s(smsg, error_bad_request);
- return;
- }
-
- /* get the application */
- INFO("method start called for %s mode=%s", appid,
- name_of_launch_mode(mode));
- appli = afm_db_get_application(afdb, appid);
- if (appli == NULL) {
- jbus_reply_error_s(smsg, error_not_found);
- return;
- }
-
- /* launch the application */
- uri = NULL;
- runid = afm_run_start(appli, mode, &uri);
- if (runid <= 0) {
- jbus_reply_error_s(smsg, error_cant_start);
- free(uri);
- return;
- }
-
- if (uri == NULL) {
- /* returns only the runid */
- snprintf(runidstr, sizeof runidstr, "%d", runid);
- runidstr[sizeof runidstr - 1] = 0;
- jbus_reply_s(smsg, runidstr);
- return;
- }
-
- /* returns the runid and its uri */
- resp = json_object_new_object();
- if (resp != NULL && j_add_integer(resp, "runid", runid)
- && j_add_string(resp, "uri", uri))
- jbus_reply_j(smsg, resp);
- else {
- afm_run_terminate(runid);
- jbus_reply_error_s(smsg, error_system);
- }
- json_object_put(resp);
- free(uri);
-}
-
-/*
- * 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)) {
- status = afm_run_pause(runid);
- 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)) {
- status = afm_run_resume(runid);
- reply_status(smsg, status, error_not_found);
- }
-}
-
-/*
- * On query "stop" from 'smsg' with parameters of 'obj'.
- */
-static void on_stop(struct sd_bus_message *smsg, struct json_object *obj, void *unused)
-{
- NOTICE("call to obsolete 'stop'");
- on_pause(smsg, obj, unused);
-}
-
-/*
- * On query "continue" from 'smsg' with parameters of 'obj'.
- */
-static void on_continue(struct sd_bus_message *smsg, struct json_object *obj, void *unused)
-{
- NOTICE("call to obsolete 'continue'");
- on_resume(smsg, obj, unused);
-}
-
-/*
- * On query "terminate" from 'smsg' with parameters of 'obj'.
- */
-static void on_terminate(struct sd_bus_message *smsg, struct json_object *obj, void *unused)
-{
- int runid, status;
- if (onrunid(smsg, obj, "terminate", &runid)) {
- status = afm_run_terminate(runid);
- reply_status(smsg, status, error_not_found);