- if (!is_valid_launch_mode(mode)) {
- jbus_reply_error_s(jreq, 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(jreq, error_not_found);
- return;
- }
-
- /* launch the application */
- uri = NULL;
- runid = afm_run_start(appli, mode, &uri);
- if (runid <= 0) {
- jbus_reply_error_s(jreq, 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(jreq, 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(jreq, resp);
- else {
- afm_run_stop(runid);
- jbus_reply_error_s(jreq, error_cant_start);
- }
- json_object_put(resp);
- free(uri);