- 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);
- appli = afm_udb_get_application_private(afudb, appid);
- if (appli == NULL) {
- jbus_reply_error_s(smsg, error_not_found);
- return;
- }
-
- /* launch the application */
- runid = afm_urun_once(appli);
- if (runid <= 0) {
- jbus_reply_error_s(smsg, error_cant_start);
- return;
- }
-
- /* returns the state */
- resp = afm_urun_state(afudb, runid);
- 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)) {
- status = afm_urun_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_urun_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_urun_terminate(runid);
- reply_status(smsg, status, error_not_found);
- }
-}
-
-/*
- * On query "runners" from 'smsg' with parameters of 'obj'.
- */
-static void on_runners(struct sd_bus_message *smsg, struct json_object *obj, void *unused)
-{
- struct json_object *resp;
- INFO("method runners called");
- resp = afm_urun_list(afudb);
- jbus_reply_j(smsg, resp);
- json_object_put(resp);
-}
-
-/*
- * On query "state" from 'smsg' with parameters of 'obj'.
- */
-static void on_state(struct sd_bus_message *smsg, struct json_object *obj, void *unused)
-{
- int runid;
- struct json_object *resp;
- if (onrunid(smsg, obj, "state", &runid)) {
- resp = afm_urun_state(afudb, runid);
- reply(smsg, resp, error_not_found);
- json_object_put(resp);
- }
-}
-
-/*
- * Calls the system daemon to achieve application management of
- * the 'method' gotten from 'smsg' with the parameter's string 'msg'.
- *
- * The principle is very simple: call the corresponding system method
- * and reply its response to the caller.
- *
- * The request and reply is synchronous and is blocking.
- * It is possible to implment it in an asynchrounous way but it
- * would brake the common behaviour. It would be a call like
- * jbus_call_ss(system_bus, method, msg, callback, smsg)
- */
-static void propagate(struct sd_bus_message *smsg, const char *msg, const char *method)
-{
- char *reply;
- INFO("method %s propagated with %s", method, msg);
- reply = jbus_call_ss_sync(system_bus, method, msg);
- if (reply) {
- jbus_reply_s(smsg, reply);
- free(reply);
- }