-appfwk
+af-usrd
wgtpkg-installer
wgtpkg-pack
wgtpkg-sign
secmgr-wrap.c
APPFWK = \
- appfwk.c
+ appfwk.c \
+ appfwk-run.c
AM_CFLAGS = -Wall -Wno-pointer-sign
#include "verbose.h"
#include "utils-jbus.h"
#include "appfwk.h"
+#include "appfwk-run.h"
static struct jbus *jbus;
static struct appfwk *appfwk;
const char error_nothing[] = "[]";
+const char error_bad_request[] = "{\"status\":\"error: bad request\"}";
const char error_not_found[] = "{\"status\":\"error: not found\"}";
static const char *getappid(struct json_object *obj)
return json_object_get_string(obj);
}
-static const char *getrunid(struct json_object *obj)
+static int getrunid(struct json_object *obj)
{
- return json_object_get_string(obj);
+ return json_object_get_int(obj);
}
static void reply(struct jreq *jreq, struct json_object *resp, const char *errstr)
{
- if (obj)
+ if (resp)
jbus_reply(jreq, resp);
else
jbus_replyj(jreq, errstr);
static void on_start(struct jreq *jreq, struct json_object *obj)
{
const char *appid = getappid(obj);
- const char *runid = appfwk_start(appfwk, appid);
+ struct json_object *appli = appid ? appfwk_get_application_public(appfwk, appid) : NULL;
+ int runid = appfwk_run_start(appli);
+ if (runid <= 0) {
+
jbus_replyj(jreq, runid ? runid : error_not_found);
json_object_put(obj);
}
+}
static void on_stop(struct jreq *jreq, struct json_object *obj)
{
- const char *runid = getrunid(obj);
- int status = appfwk_stop(appfwk, runid);
+ int runid = getrunid(obj);
+ int status = appfwk_run_stop(runid);
jbus_replyj(jreq, status ? error_not_found : "true");
json_object_put(obj);
}
static void on_suspend(struct jreq *jreq, struct json_object *obj)
{
- const char *runid = getrunid(obj);
- int status = appfwk_suspend(appfwk, runid);
+ int runid = getrunid(obj);
+ int status = appfwk_run_suspend(runid);
jbus_replyj(jreq, status ? error_not_found : "true");
json_object_put(obj);
}
static void on_resume(struct jreq *jreq, struct json_object *obj)
{
- const char *runid = getrunid(obj);
- int status = appfwk_resume(appfwk, runid);
+ int runid = getrunid(obj);
+ int status = appfwk_run_resume(runid);
jbus_replyj(jreq, status ? error_not_found : "true");
json_object_put(obj);
}
static void on_runners(struct jreq *jreq, struct json_object *obj)
{
- struct json_object *resp = appfwk_running_list(appfwk);
+ struct json_object *resp = appfwk_run_list();
jbus_reply(jreq, resp);
+ json_object_put(resp);
json_object_put(obj);
}
static void on_state(struct jreq *jreq, struct json_object *obj)
{
- const char *runid = getrunid(obj);
- int status = appfwk_state(appfwk, runid);
- jbus_replyj(jreq, status ? error_not_found : "true");
+ int runid = getrunid(obj);
+ struct json_object *resp = appfwk_run_state(runid);
+ reply(jreq, resp, error_not_found);
json_object_put(obj);
+ json_object_put(resp);
}
int main(int ac, char **av)
}
if(jbus_add_service(jbus, "runnables", on_runnables)
|| jbus_add_service(jbus, "detail", on_detail)
- || jbus_add_service(jbus, "start", on_run)
+ || jbus_add_service(jbus, "start", on_start)
|| jbus_add_service(jbus, "stop", on_stop)
|| jbus_add_service(jbus, "suspend", on_suspend)
|| jbus_add_service(jbus, "resume", on_resume)
struct apprun {
struct apprun *next;
- int runid;
+ int id;
enum appstate state;
pid_t backend;
pid_t frontend;
static void freerunner(struct apprun *runner)
{
- struct apprun **prev = &[runner->id & (ROOT_RUNNERS_COUNT - 1)];
+ struct apprun **prev = &runners[runner->id & (ROOT_RUNNERS_COUNT - 1)];
assert(*prev);
while(*prev != runner) {
prev = &(*prev)->next;
int appfwk_run_start(struct json_object *appli)
{
+ return -1;
}
-int appfwk_run_stop()
+int appfwk_run_stop(int runid)
{
+ return -1;
}
+int appfwk_run_suspend(int runid)
+{
+ return -1;
+}
+
+int appfwk_run_resume(int runid)
+{
+ return -1;
+}
+
+struct json_object *appfwk_run_list()
+{
+ return NULL;
+}
+
+struct json_object *appfwk_run_state(int runid)
+{
+ return NULL;
+}
+
+#if 0
static struct json_object *mkrunner(const char *appid, const char *runid)
{
}
/* prepare the execution */
- snprintf(buffer, sizeof buffer, "{\"id\":\"%s\",\"runid\":\"%s\"
+ snprintf(buffer, sizeof buffer, "{\"id\":\"%s\",\"runid\":\"%s\""
}
int appfwk_stop(struct appfwk *af, const char *runid)
}
#endif
+static struct json_object *mkrunner(const char *appid, const char *runid)
+{
+ struct json_object *result = json_object_new_object();
+ if (result) {
+ if(json_add_str(result, "id", appid)
+ || json_add_str(result, "runid", runid)
+ || json_add_str(result, "state", NULL)) {
+ json_object_put(result);
+ result = NULL;
+ }
+ }
+ return result;
+}
+
+const char *appfwk_start(struct appfwk *af, const char *appid)
+{
+ struct json_object *appli;
+ struct json_object *runner;
+ char buffer[250];
+
+ /* get the application description */
+ appli = appfwk_get_application(af, appid);
+ if (appli == NULL) {
+ errno = ENOENT;
+ return -1;
+ }
+
+ /* prepare the execution */
+}
+
+int appfwk_stop(struct appfwk *af, const char *runid)
+{
+ struct json_object *runner;
+ runner = appfwk_state(af, runid);
+ if (runner == NULL) {
+ errno = ENOENT;
+ return -1;
+ }
+ json_object_get(runner);
+ json_object_object_del(af->runners, runid);
+
+
+
+
+
+
+..........
+
+
+
+
+
+
+ json_object_put(runner);
+}
+
+int appfwk_suspend(struct appfwk *af, const char *runid)
+{
+}
+
+int appfwk_resume(struct appfwk *af, const char *runid)
+{
+}
+
+struct json_object *appfwk_running_list(struct appfwk *af)
+{
+ return af->runners;
+}
+
+struct json_object *appfwk_state(struct appfwk *af, const char *runid)
+{
+ struct json_object *result;
+ int status = json_object_object_get_ex(af->runners, runid, &result);
+ return status ? result : NULL;
+}
+
+
+
+#endif
--- /dev/null
+/*
+ Copyright 2015 IoT.bzh
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+extern int appfwk_run_start(struct json_object *appli);
+extern int appfwk_run_stop(int runid);
+extern int appfwk_run_suspend(int runid);
+extern int appfwk_run_resume(int runid);
+extern struct json_object *appfwk_run_list();
+extern struct json_object *appfwk_run_state(int runid);
+
int nrroots;
char **roots;
struct afapps applications;
- struct json_object *runners;
};
struct appfwk *appfwk_create()
if (appfwk == NULL)
errno = ENOMEM;
else {
- appfwk->runners = json_object_new_object();
- if (appfwk->runners == NULL) {
- free(appfwk);
- appfwk = NULL;
- errno = ENOMEM;
- } else {
- appfwk->refcount = 1;
- appfwk->nrroots = 0;
- appfwk->roots = NULL;
- appfwk->applications.pubarr = NULL;
- appfwk->applications.direct = NULL;
- appfwk->applications.byapp = NULL;
- }
+ appfwk->refcount = 1;
+ appfwk->nrroots = 0;
+ appfwk->roots = NULL;
+ appfwk->applications.pubarr = NULL;
+ appfwk->applications.direct = NULL;
+ appfwk->applications.byapp = NULL;
}
return appfwk;
}
json_object_put(appfwk->applications.pubarr);
json_object_put(appfwk->applications.direct);
json_object_put(appfwk->applications.byapp);
- json_object_put(appfwk->runners);
while (appfwk->nrroots)
free(appfwk->roots[--appfwk->nrroots]);
free(appfwk->roots);
struct json_object *appfwk_get_application(struct appfwk *af, const char *id)
{
struct json_object *result;
- if (!appfwk_ensure_applications(af) && json_object_object_get_ex(obj, id, &result))
+ if (!appfwk_ensure_applications(af) && json_object_object_get_ex(af->applications.direct, id, &result))
return result;
- }
return NULL;
}
return result && json_object_object_get_ex(result, "public", &result) ? result : NULL;
}
-static struct json_object *mkrunner(const char *appid, const char *runid)
-{
- struct json_object *result = json_object_new_object();
- if (result) {
- if(json_add_str(result, "id", appid)
- || json_add_str(result, "runid", runid)
- || json_add_str(result, "state", NULL)) {
- json_object_put(result);
- result = NULL;
- }
- }
- return result;
-}
-
-const char *appfwk_start(struct appfwk *af, const char *appid)
-{
- struct json_object *appli;
- struct json_object *runner;
- char buffer[250];
-
- /* get the application description */
- appli = appfwk_get_application(af, appid);
- if (appli == NULL) {
- errno = ENOENT;
- return -1;
- }
-
- /* prepare the execution */
- snprintf(buffer, sizeof buffer, "{\"id\":\"%s\",\"runid\":\"%s\"
-}
-
-int appfwk_stop(struct appfwk *af, const char *runid)
-{
- struct json_object *runner;
- runner = appfwk_state(af, runid);
- if (runner == NULL) {
- errno = ENOENT;
- return -1;
- }
- json_object_get(runner);
- json_object_object_del(af->runners, runid);
-
-
-
-
-
-
-..........
-
-
-
-
-
-
- json_object_put(runner);
-}
-
-int appfwk_suspend(struct appfwk *af, const char *runid)
-{
-}
-
-int appfwk_resume(struct appfwk *af, const char *runid)
-{
-}
-
-struct json_object *appfwk_running_list(struct appfwk *af)
-{
- return af->runners;
-}
-
-struct json_object *appfwk_state(struct appfwk *af, const char *runid)
-{
- struct json_object *result;
- int status = json_object_object_get_ex(af->runners, runid, &result);
- return status ? result : NULL;
-}
-
-
-
-
extern struct json_object *appfwk_get_application(struct appfwk *af, const char *id);
extern struct json_object *appfwk_get_application_public(struct appfwk *af, const char *id);
-extern const char *appfwk_start(struct appfwk *af, const char *appid);
-extern int appfwk_stop(struct appfwk *af, const char *runid);
-extern int appfwk_suspend(struct appfwk *af, const char *runid);
-extern int appfwk_resume(struct appfwk *af, const char *runid);
-extern struct json_object *appfwk_running_list(struct appfwk *af);
-extern struct json_object *appfwk_state(struct appfwk *af, const char *runid);