From 5f53ea07c7ebe72b36abd41a297ffa49e79adbc0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Bollo?= Date: Tue, 15 Dec 2015 16:46:55 +0100 Subject: [PATCH] in progress (compiles) Change-Id: Ia053606daba26ac7e5a59c3137da44d7e80fedcb --- .gitignore | 2 +- src/Makefile.am | 3 +- src/af-usrd.c | 38 +++++++++++-------- src/appfwk-run.c | 110 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- src/appfwk-run.h | 23 ++++++++++++ src/appfwk.c | 104 ++++------------------------------------------------ src/appfwk.h | 6 --- 7 files changed, 162 insertions(+), 124 deletions(-) create mode 100644 src/appfwk-run.h diff --git a/.gitignore b/.gitignore index cee9cf3..3ba4578 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -appfwk +af-usrd wgtpkg-installer wgtpkg-pack wgtpkg-sign diff --git a/src/Makefile.am b/src/Makefile.am index cb4d334..ac4814c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -30,7 +30,8 @@ SECWRP = \ secmgr-wrap.c APPFWK = \ - appfwk.c + appfwk.c \ + appfwk-run.c AM_CFLAGS = -Wall -Wno-pointer-sign diff --git a/src/af-usrd.c b/src/af-usrd.c index f7e039f..6dac577 100644 --- a/src/af-usrd.c +++ b/src/af-usrd.c @@ -19,11 +19,13 @@ #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) @@ -31,14 +33,14 @@ 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); @@ -62,48 +64,54 @@ static void on_detail(struct jreq *jreq, struct json_object *obj) 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) @@ -133,7 +141,7 @@ 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) diff --git a/src/appfwk-run.c b/src/appfwk-run.c index 1c7fcaa..f0bb478 100644 --- a/src/appfwk-run.c +++ b/src/appfwk-run.c @@ -41,7 +41,7 @@ enum appstate { struct apprun { struct apprun *next; - int runid; + int id; enum appstate state; pid_t backend; pid_t frontend; @@ -64,7 +64,7 @@ static struct apprun *getrunner(int id) 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; @@ -101,12 +101,35 @@ static struct apprun *createrunner() 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) { @@ -136,7 +159,7 @@ const char *appfwk_start(struct appfwk *af, const char *appid) } /* 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) @@ -205,3 +228,82 @@ return 0; } #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 diff --git a/src/appfwk-run.h b/src/appfwk-run.h new file mode 100644 index 0000000..ea0f1a5 --- /dev/null +++ b/src/appfwk-run.h @@ -0,0 +1,23 @@ +/* + 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); + diff --git a/src/appfwk.c b/src/appfwk.c index 6a625ca..a8ae6c8 100644 --- a/src/appfwk.c +++ b/src/appfwk.c @@ -38,7 +38,6 @@ struct appfwk { int nrroots; char **roots; struct afapps applications; - struct json_object *runners; }; struct appfwk *appfwk_create() @@ -47,19 +46,12 @@ 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; } @@ -77,7 +69,6 @@ void appfwk_unref(struct appfwk *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); @@ -345,9 +336,8 @@ struct json_object *appfwk_application_list(struct appfwk *af) 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; } @@ -357,86 +347,6 @@ struct json_object *appfwk_get_application_public(struct appfwk *af, const char 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; -} - - - - diff --git a/src/appfwk.h b/src/appfwk.h index 3e0d1b7..7bd4af2 100644 --- a/src/appfwk.h +++ b/src/appfwk.h @@ -28,9 +28,3 @@ extern struct json_object *appfwk_application_list(struct appfwk *af); 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); -- 2.16.6