- {"runnables", AFB_SESSION_CHECK, (AFB_apiCB)call_void, "Get list of runnable applications"},
- {"detail" , AFB_SESSION_CHECK, (AFB_apiCB)call_appid, "Get the details for one application"},
- {"start" , AFB_SESSION_CHECK, (AFB_apiCB)call_appid, "Start an application"},
- {"terminate", AFB_SESSION_CHECK, (AFB_apiCB)call_runid, "Terminate a running application"},
- {"stop" , AFB_SESSION_CHECK, (AFB_apiCB)call_runid, "Stop (pause) a running application"},
- {"continue" , AFB_SESSION_CHECK, (AFB_apiCB)call_runid, "Continue (resume) a stopped application"},
- {"runners" , AFB_SESSION_CHECK, (AFB_apiCB)call_void, "Get the list of running applications"},
- {"state" , AFB_SESSION_CHECK, (AFB_apiCB)call_runid, "Get the state of a running application"},
- {NULL}
+ struct json_object *obj, *added;
+ char *query;
+ const char *filename;
+ struct afb_arg arg;
+
+ /* get the argument */
+ arg = afb_req_get(request, "widget");
+ filename = arg.path;
+ if (filename == NULL) {
+ afb_req_fail(request, "bad-request", "missing 'widget' file");
+ return;
+ }
+
+ /* makes the query */
+ if (0 >= asprintf(&query, "\"%s\"", filename)) {
+ afb_req_fail(request, "server-error", "out of memory");
+ return;
+ }
+
+ obj = jbus_call_sj_sync(jbus, _install_, query);
+ if (interface->verbosity)
+ fprintf(stderr, "(afm-main-plugin) install(%s) -> %s\n", query,
+ obj ? json_object_to_json_string(obj) : "NULL");
+ free(query);
+
+ /* check status */
+ if (obj == NULL) {
+ afb_req_fail(request, "failed", "framework daemon failure");
+ return;
+ }
+
+ /* embed if needed */
+ if (json_object_object_get_ex(obj, _added_, &added))
+ obj = added;
+ obj = json_object_get(obj);
+ obj = embed(_id_, obj);
+ afb_req_success(request, obj, NULL);
+}
+
+static void uninstall(struct afb_req request)
+{
+ call_appid(request, _uninstall_);
+}
+
+static const struct AFB_restapi plug_apis[] =
+{
+ {_runnables_, AFB_SESSION_CHECK, runnables, "Get list of runnable applications"},
+ {_detail_ , AFB_SESSION_CHECK, detail, "Get the details for one application"},
+ {_start_ , AFB_SESSION_CHECK, start, "Start an application"},
+ {_terminate_, AFB_SESSION_CHECK, terminate, "Terminate a running application"},
+ {_stop_ , AFB_SESSION_CHECK, stop, "Stop (pause) a running application"},
+ {_continue_ , AFB_SESSION_CHECK, continue_, "Continue (resume) a stopped application"},
+ {_runners_ , AFB_SESSION_CHECK, runners, "Get the list of running applications"},
+ {_state_ , AFB_SESSION_CHECK, state, "Get the state of a running application"},
+ {_install_ , AFB_SESSION_CHECK, install, "Install an application using a widget file"},
+ {_uninstall_, AFB_SESSION_CHECK, uninstall, "Uninstall an application"},
+ { NULL, 0, NULL, NULL }