/*
- * Copyright (C) 2015, 2016, 2017 IoT.bzh
+ * Copyright (C) 2015-2018 "IoT.bzh"
* Author "Fulup Ar Foll"
*
* Licensed under the Apache License, Version 2.0 (the "License");
#include "wgtpkg-uninstall.h"
#include "wrap-json.h"
+/*
+ * constant strings
+ */
static const char _added_[] = "added";
static const char _a_l_c_[] = "application-list-changed";
+static const char _bad_request_[] = "bad-request";
+static const char _cannot_start_[] = "cannot-start";
static const char _detail_[] = "detail";
static const char _id_[] = "id";
static const char _install_[] = "install";
+static const char _lang_[] = "lang";
static const char _not_found_[] = "not-found";
static const char _once_[] = "once";
static const char _pause_[] = "pause";
static const char _terminate_[] = "terminate";
static const char _uninstall_[] = "uninstall";
+/*
+ * default root
+ */
static const char *rootdir = FWK_APP_DIR;
-static struct afb_event applist_changed_event;
+
+/*
+ * the internal application database
+ */
static struct afm_udb *afudb;
+
+/*
+ * the event signalling that application list changed
+ */
+static struct afb_event applist_changed_event;
+
+/*
+ * the preallocated true json_object
+ */
static struct json_object *json_true;
+/* enforce daemon reload */
static void do_reloads()
{
- /* enforce daemon reload */
systemd_daemon_reload(0);
systemd_unit_restart_name(0, "sockets.target");
}
+/* common bad request reply */
static void bad_request(struct afb_req req)
{
- afb_req_fail(req, "bad-request", NULL);
+ afb_req_fail(req, _bad_request_, NULL);
}
+/* common not found reply */
static void not_found(struct afb_req req)
{
afb_req_fail(req, _not_found_, NULL);
}
+/* common can't start reply */
static void cant_start(struct afb_req req)
{
- afb_req_fail(req, "cannot-start", NULL);
+ afb_req_fail(req, _cannot_start_, NULL);
}
/*
afb_event_broadcast(applist_changed_event, e);
}
+/*
+ * Retrieve the required language from 'req'.
+ */
+static const char *get_lang(struct afb_req req)
+{
+ const char *lang;
+
+ /* get the optional language */
+ lang = afb_req_value(req, _lang_);
+
+ /* TODO use the req to get the lang of the session (if any) */
+
+ return lang;
+}
+
+
/*
* retrieves the 'appid' in parameters received with the
* request 'req' for the 'method'.
*/
static void runnables(struct afb_req req)
{
+ const char *lang;
struct json_object *resp;
- INFO("method runnables called");
- resp = afm_udb_applications_public(afudb, afb_req_get_uid(req));
+
+ /* get the language */
+ lang = get_lang(req);
+
+ /* get the details */
+ resp = afm_udb_applications_public(afudb, afb_req_get_uid(req), lang);
afb_req_success(req, resp, NULL);
}
*/
static void detail(struct afb_req req)
{
+ const char *lang;
const char *appid;
struct json_object *resp;
if (!onappid(req, _detail_, &appid))
return;
+ /* get the language */
+ lang = get_lang(req);
+
/* wants details for appid */
- resp = afm_udb_get_application_public(afudb, appid, afb_req_get_uid(req));
+ resp = afm_udb_get_application_public(afudb, appid, afb_req_get_uid(req), lang);
if (resp)
afb_req_success(req, resp, NULL);
else
static void runners(struct afb_req req)
{
struct json_object *resp;
- INFO("method runners called");
resp = afm_urun_list(afudb, afb_req_get_uid(req));
afb_req_success(req, resp, NULL);
}
}
}
+/*
+ * On querying installation of widget(s)
+ */
static void install(struct afb_req req)
{
const char *wgtfile;
}
}
+/*
+ * On querying uninstallation of widget(s)
+ */
static void uninstall(struct afb_req req)
{
const char *idaver;