-static void on_start(struct sd_bus_message *smsg, struct json_object *obj, void *unused)
-{
- const char *appid, *modestr;
- char *uri;
- struct json_object *appli, *resp;
- int runid;
- char runidstr[20];
- enum afm_launch_mode mode;
-
- /* get the parameters */
- mode = invalid_launch_mode;
- if (j_read_string(obj, &appid)) {
- mode = get_default_launch_mode();
- } else if (j_read_string_at(obj, "id", &appid)) {
- if (j_read_string_at(obj, "mode", &modestr)) {
- mode = launch_mode_of_name(modestr);
- } else {
- mode = get_default_launch_mode();
- }
- }
- 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));
-#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 */
- uri = NULL;
-#ifdef LEGACY_MODE_WITHOUT_SYSTEMD
- runid = afm_run_start(appli, mode, &uri);
-#else
- runid = afm_urun_start(appli);
-#endif
- 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 {
-#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);
+static void on_pws_hangup(void *closure);
+static void on_pws_reply(void *closure, void *request, struct json_object *obj, const char *error, const char *info);
+#if !defined(AFB_PROTO_WS_VERSION) || (AFB_PROTO_WS_VERSION < 3)
+static void on_pws_reply_success(void *closure, void *request, struct json_object *result, const char *info)
+ { on_pws_reply(closure, request, result, NULL, info); }
+static void on_pws_reply_fail(void *closure, void *request, const char *error, const char *info)
+ { on_pws_reply(closure, request, NULL, error, info); }