diff options
author | José Bollo <jose.bollo@iot.bzh> | 2015-12-16 14:26:53 +0100 |
---|---|---|
committer | José Bollo <jose.bollo@iot.bzh> | 2015-12-16 14:26:53 +0100 |
commit | d98ed87299e26531f5a71ad053cbe412f8252799 (patch) | |
tree | 754593d77624e681850ceaa3e4c49cb1f794557c /src | |
parent | a3a2a5da508f810005f587ab60e85f989fd219bd (diff) |
refactoring names
Change-Id: I46cb0843457cb2e65dc3e65069e5c86981b4838c
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 6 | ||||
-rw-r--r-- | src/af-db.c (renamed from src/appfwk.c) | 109 | ||||
-rw-r--r-- | src/af-db.h | 30 | ||||
-rw-r--r-- | src/af-run.c (renamed from src/appfwk-run.c) | 103 | ||||
-rw-r--r-- | src/af-run.h (renamed from src/appfwk-run.h) | 13 | ||||
-rw-r--r-- | src/af-usrd.c | 47 | ||||
-rw-r--r-- | src/appfwk.h | 30 |
7 files changed, 203 insertions, 135 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 3259434..b1c95bc 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -30,8 +30,8 @@ SECWRP = \ secmgr-wrap.c APPFWK = \ - appfwk.c \ - appfwk-run.c + af-db.c \ + af-run.c AM_CFLAGS = -Wall -Wno-pointer-sign @@ -45,6 +45,7 @@ fwk_icondir = $(fwk_datadir)/icons fwk_prefix = urn:agl: fwk_prefix_permission = $(fwk_prefix)perm: fwk_prefix_plugin = $(fwk_prefix)plugin: +fwk_user_appdir = app-data wgtpkg_trusted_cert_dir = $(fwk_confdir)/certs AM_CFLAGS += -DFWK_CONFIG_DIR=\"$(fwk_confdir)\" @@ -52,6 +53,7 @@ AM_CFLAGS += -DFWK_PREFIX_PERMISSION=\"$(fwk_prefix_permission)\" AM_CFLAGS += -DFWK_PREFIX_PLUGIN=\"$(fwk_prefix_plugin)\" AM_CFLAGS += -DFWK_ICON_DIR=\"$(fwk_icondir)\" AM_CFLAGS += -DFWK_APP_DIR=\"$(fwk_appdir)\" +AM_CFLAGS += -DFWK_USER_APP_DIR=\"$(fwk_user_appdir)\" AM_CFLAGS += -DWGTPKG_TRUSTED_CERT_DIR=\"$(wgtpkg_trusted_cert_dir)\" diff --git a/src/appfwk.c b/src/af-db.c index a8ae6c8..1663b35 100644 --- a/src/appfwk.c +++ b/src/af-db.c @@ -25,7 +25,8 @@ #include <json.h> -#include <wgt-info.h> +#include "wgt-info.h" +#include "af-db.h" struct afapps { struct json_object *pubarr; @@ -33,55 +34,55 @@ struct afapps { struct json_object *byapp; }; -struct appfwk { +struct af_db { int refcount; int nrroots; char **roots; struct afapps applications; }; -struct appfwk *appfwk_create() +struct af_db *af_db_create() { - struct appfwk *appfwk = malloc(sizeof * appfwk); - if (appfwk == NULL) + struct af_db *afdb = malloc(sizeof * afdb); + if (afdb == 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; + afdb->refcount = 1; + afdb->nrroots = 0; + afdb->roots = NULL; + afdb->applications.pubarr = NULL; + afdb->applications.direct = NULL; + afdb->applications.byapp = NULL; } - return appfwk; + return afdb; } -void appfwk_addref(struct appfwk *appfwk) +void af_db_addref(struct af_db *afdb) { - assert(appfwk); - appfwk->refcount++; + assert(afdb); + afdb->refcount++; } -void appfwk_unref(struct appfwk *appfwk) +void af_db_unref(struct af_db *afdb) { - assert(appfwk); - if (!--appfwk->refcount) { - json_object_put(appfwk->applications.pubarr); - json_object_put(appfwk->applications.direct); - json_object_put(appfwk->applications.byapp); - while (appfwk->nrroots) - free(appfwk->roots[--appfwk->nrroots]); - free(appfwk->roots); - free(appfwk); + assert(afdb); + if (!--afdb->refcount) { + json_object_put(afdb->applications.pubarr); + json_object_put(afdb->applications.direct); + json_object_put(afdb->applications.byapp); + while (afdb->nrroots) + free(afdb->roots[--afdb->nrroots]); + free(afdb->roots); + free(afdb); } } -int appfwk_add_root(struct appfwk *appfwk, const char *path) +int af_db_add_root(struct af_db *afdb, const char *path) { int i, n; char *r, **roots; - assert(appfwk); + assert(afdb); /* don't depend on the cwd and unique name */ r = realpath(path, NULL); @@ -89,8 +90,8 @@ int appfwk_add_root(struct appfwk *appfwk, const char *path) return -1; /* avoiding duplications */ - n = appfwk->nrroots; - roots = appfwk->roots; + n = afdb->nrroots; + roots = afdb->roots; for (i = 0 ; i < n ; i++) { if (!strcmp(r, roots[i])) { free(r); @@ -106,8 +107,8 @@ int appfwk_add_root(struct appfwk *appfwk, const char *path) return -1; } roots[n++] = r; - appfwk->roots = roots; - appfwk->nrroots = n; + afdb->roots = roots; + afdb->nrroots = n; return 0; } @@ -172,10 +173,12 @@ static int addapp(struct afapps *apps, const char *path) goto error2; } - if(json_add_str(pub, "id", appid) - || json_add_str(priv, "id", desc->id) - || json_add_str(pub, "version", desc->version) + if(json_add_str(priv, "id", desc->id) || json_add_str(priv, "path", path) + || json_add_str(priv, "content", desc->content_src) + || json_add_str(priv, "type", desc->content_type) + || json_add_str(pub, "id", appid) + || json_add_str(pub, "version", desc->version) || json_add_int(pub, "width", desc->width) || json_add_int(pub, "height", desc->height) || json_add_str(pub, "name", desc->name) @@ -285,7 +288,7 @@ static int enumvers(struct enumdata *data) } /* regenerate the list of applications */ -int appfwk_update_applications(struct appfwk *af) +int af_db_update_applications(struct af_db *afdb) { int rc, iroot; struct enumdata edata; @@ -300,8 +303,8 @@ int appfwk_update_applications(struct appfwk *af) goto error; } /* for each root */ - for (iroot = 0 ; iroot < af->nrroots ; iroot++) { - edata.length = stpcpy(edata.path, af->roots[iroot]) - edata.path; + for (iroot = 0 ; iroot < afdb->nrroots ; iroot++) { + edata.length = stpcpy(edata.path, afdb->roots[iroot]) - edata.path; assert(edata.length < sizeof edata.path); /* enumerate the applications */ rc = enumentries(&edata, enumvers); @@ -309,8 +312,8 @@ int appfwk_update_applications(struct appfwk *af) goto error; } /* commit the result */ - oldapps = af->applications; - af->applications = edata.apps; + oldapps = afdb->applications; + afdb->applications = edata.apps; json_object_put(oldapps.pubarr); json_object_put(oldapps.direct); json_object_put(oldapps.byapp); @@ -323,27 +326,27 @@ error: return -1; } -int appfwk_ensure_applications(struct appfwk *af) +int af_db_ensure_applications(struct af_db *afdb) { - return af->applications.pubarr ? 0 : appfwk_update_applications(af); + return afdb->applications.pubarr ? 0 : af_db_update_applications(afdb); } -struct json_object *appfwk_application_list(struct appfwk *af) +struct json_object *af_db_application_list(struct af_db *afdb) { - return appfwk_ensure_applications(af) ? NULL : af->applications.pubarr; + return af_db_ensure_applications(afdb) ? NULL : afdb->applications.pubarr; } -struct json_object *appfwk_get_application(struct appfwk *af, const char *id) +struct json_object *af_db_get_application(struct af_db *afdb, const char *id) { struct json_object *result; - if (!appfwk_ensure_applications(af) && json_object_object_get_ex(af->applications.direct, id, &result)) + if (!af_db_ensure_applications(afdb) && json_object_object_get_ex(afdb->applications.direct, id, &result)) return result; return NULL; } -struct json_object *appfwk_get_application_public(struct appfwk *af, const char *id) +struct json_object *af_db_get_application_public(struct af_db *afdb, const char *id) { - struct json_object *result = appfwk_get_application(af, id); + struct json_object *result = af_db_get_application(afdb, id); return result && json_object_object_get_ex(result, "public", &result) ? result : NULL; } @@ -354,12 +357,12 @@ struct json_object *appfwk_get_application_public(struct appfwk *af, const char #include <stdio.h> int main() { -struct appfwk *af = appfwk_create(); -appfwk_add_root(af,FWK_APP_DIR); -appfwk_update_applications(af); -printf("array = %s\n", json_object_to_json_string_ext(af->applications.pubarr, 3)); -printf("direct = %s\n", json_object_to_json_string_ext(af->applications.direct, 3)); -printf("byapp = %s\n", json_object_to_json_string_ext(af->applications.byapp, 3)); +struct af_db *afdb = af_db_create(); +af_db_add_root(afdb,FWK_APP_DIR); +af_db_update_applications(afdb); +printf("array = %s\n", json_object_to_json_string_ext(afdb->applications.pubarr, 3)); +printf("direct = %s\n", json_object_to_json_string_ext(afdb->applications.direct, 3)); +printf("byapp = %s\n", json_object_to_json_string_ext(afdb->applications.byapp, 3)); return 0; } #endif diff --git a/src/af-db.h b/src/af-db.h new file mode 100644 index 0000000..f54d807 --- /dev/null +++ b/src/af-db.h @@ -0,0 +1,30 @@ +/* + 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. +*/ + +struct af_db; + +extern struct af_db *af_db_create(); +extern void af_db_addref(struct af_db *afdb); +extern void af_db_unref(struct af_db *afdb); + +extern int af_db_add_root(struct af_db *afdb, const char *path); +extern int af_db_update_applications(struct af_db *afdb); +extern int af_db_ensure_applications(struct af_db *afdb); + +extern struct json_object *af_db_application_list(struct af_db *afdb); +extern struct json_object *af_db_get_application(struct af_db *afdb, const char *id); +extern struct json_object *af_db_get_application_public(struct af_db *afdb, const char *id); + diff --git a/src/appfwk-run.c b/src/af-run.c index 87b02b0..0fd533c 100644 --- a/src/appfwk-run.c +++ b/src/af-run.c @@ -14,23 +14,22 @@ limitations under the License. */ +#include <fcntl.h> #include <unistd.h> #include <signal.h> - - - -#include <stdlib.h> +#include <pwd.h> +#include <sys/types.h> +#include <errno.h> #include <assert.h> +#include <stdio.h> +#include <limits.h> #include <string.h> -#include <errno.h> -#include <dirent.h> -#include <fcntl.h> -#include <sys/types.h> #include <json.h> -#include <wgt-info.h> - +#include "verbose.h" +#include "utils-dir.h" +#include "wgt-info.h" enum appstate { as_starting, @@ -44,8 +43,7 @@ struct apprun { struct apprun *next_by_runid; struct apprun *next_by_pgid; int runid; - pid_t backend; - pid_t frontend; + pid_t pgid; enum appstate state; json_object *appli; }; @@ -58,13 +56,16 @@ static struct apprun *runners_by_pgid[ROOT_RUNNERS_COUNT]; static int runnercount = 0; static int runnerid = 0; +static const char fwk_user_app_dir[] = FWK_USER_APP_DIR; +static char *homeappdir; + /****************** manages pgids **********************/ /* get a runner by its pgid */ static struct apprun *runner_of_pgid(pid_t pgid) { struct apprun *result = runners_by_pgid[(int)(pgid & (ROOT_RUNNERS_COUNT - 1))]; - while (result && result->backend != pgid) + while (result && result->pgid != pgid) result = result->next_by_pgid; return result; } @@ -72,7 +73,7 @@ static struct apprun *runner_of_pgid(pid_t pgid) /* insert a runner for its pgid */ static void pgid_insert(struct apprun *runner) { - struct apprun **prev = &runners_by_runid[(int)(runner->backend & (ROOT_RUNNERS_COUNT - 1))]; + struct apprun **prev = &runners_by_runid[(int)(runner->pgid & (ROOT_RUNNERS_COUNT - 1))]; runner->next_by_pgid = *prev; *prev = runner; } @@ -80,7 +81,7 @@ static void pgid_insert(struct apprun *runner) /* remove a runner for its pgid */ static void pgid_remove(struct apprun *runner) { - struct apprun **prev = &runners_by_runid[(int)(runner->backend & (ROOT_RUNNERS_COUNT - 1))]; + struct apprun **prev = &runners_by_runid[(int)(runner->pgid & (ROOT_RUNNERS_COUNT - 1))]; runner->next_by_pgid = *prev; *prev = runner; } @@ -142,8 +143,7 @@ static struct apprun *createrunner(json_object *appli) result->next_by_runid = *prev; result->next_by_pgid = NULL; result->runid = runnerid; - result->backend = 0; - result->frontend = 0; + result->pgid = 0; result->state = as_starting; result->appli = json_object_get(appli); *prev = result; @@ -192,31 +192,46 @@ static int killrunner(int runid, int sig, enum appstate tostate) rc = 0; } else { - rc = killpg(runner->backend, sig); + rc = killpg(runner->pgid, sig); if (!rc) runner->state = tostate; } return rc; } +/**************** summarizing the application *********************/ + +struct applisum { + const char *path; + const char *tag; + const char *appid; + const char *content; + const char *type; + const char *name; + int width; + int height; +}; + /**************** API handling ************************/ -int appfwk_run_start(struct json_object *appli) +int af_run_start(struct json_object *appli) { + const char *path; + const char *id; return -1; } -int appfwk_run_terminate(int runid) +int af_run_terminate(int runid) { return killrunner(runid, SIGTERM, as_terminating); } -int appfwk_run_stop(int runid) +int af_run_stop(int runid) { return killrunner(runid, SIGSTOP, as_stopped); } -int appfwk_run_continue(int runid) +int af_run_continue(int runid) { return killrunner(runid, SIGCONT, as_running); } @@ -276,7 +291,7 @@ error: return NULL; } -struct json_object *appfwk_run_list() +struct json_object *af_run_list() { struct json_object *result, *obj; struct apprun *runner; @@ -306,7 +321,7 @@ struct json_object *appfwk_run_list() return result; } -struct json_object *appfwk_run_state(int runid) +struct json_object *af_run_state(int runid) { struct apprun *runner = getrunner(runid); if (runner == NULL || runner->state == as_terminating || runner->state == as_terminated) { @@ -316,3 +331,43 @@ struct json_object *appfwk_run_state(int runid) return mkstate(runner, NULL); } +/**************** INITIALISATION **********************/ + +int af_run_init() +{ + char buf[2048]; + char dir[PATH_MAX]; + int rc; + uid_t me; + struct passwd passwd, *pw; + + /* computes the 'homeappdir' */ + me = geteuid(); + rc = getpwuid_r(me, &passwd, buf, sizeof buf, &pw); + if (rc || pw == NULL) { + errno = rc ? errno : ENOENT; + ERROR("getpwuid_r failed for uid=%d: %m",(int)me); + return -1; + } + rc = snprintf(dir, sizeof dir, "%s/%s", passwd.pw_dir, fwk_user_app_dir); + if (rc >= sizeof dir) { + ERROR("buffer overflow in user_app_dir for uid=%d",(int)me); + return -1; + } + rc = create_directory(dir, 0755, 1); + if (rc && errno != EEXIST) { + ERROR("creation of directory %s failed in user_app_dir: %m", dir); + return -1; + } + homeappdir = strdup(dir); + if (homeappdir == NULL) { + errno = ENOMEM; + ERROR("out of memory in user_app_dir for %s : %m", dir); + return -1; + } + + /* install signal handlers */ + + return 0; +} + diff --git a/src/appfwk-run.h b/src/af-run.h index 8d3526b..e3cd14f 100644 --- a/src/appfwk-run.h +++ b/src/af-run.h @@ -14,10 +14,11 @@ limitations under the License. */ -extern int appfwk_run_start(struct json_object *appli); -extern int appfwk_run_terminate(int runid); -extern int appfwk_run_stop(int runid); -extern int appfwk_run_continue(int runid); -extern struct json_object *appfwk_run_list(); -extern struct json_object *appfwk_run_state(int runid); +extern int af_run_start(struct json_object *appli); +extern int af_run_terminate(int runid); +extern int af_run_stop(int runid); +extern int af_run_continue(int runid); +extern struct json_object *af_run_list(); +extern struct json_object *af_run_state(int runid); +extern int af_run_init(); diff --git a/src/af-usrd.c b/src/af-usrd.c index 1563e44..89e1c57 100644 --- a/src/af-usrd.c +++ b/src/af-usrd.c @@ -14,17 +14,18 @@ limitations under the License. */ +#include <unistd.h> #include <stdio.h> #include <json.h> #include "verbose.h" #include "utils-jbus.h" -#include "appfwk.h" -#include "appfwk-run.h" +#include "af-db.h" +#include "af-run.h" static struct jbus *jbus; -static struct appfwk *appfwk; +static struct af_db *afdb; const char error_nothing[] = "[]"; const char error_bad_request[] = "{\"status\":\"error: bad request\"}"; @@ -51,7 +52,7 @@ static void reply(struct jreq *jreq, struct json_object *resp, const char *errst static void on_runnables(struct jreq *jreq, struct json_object *obj) { - struct json_object *resp = appfwk_application_list(appfwk); + struct json_object *resp = af_db_application_list(afdb); jbus_reply(jreq, resp); json_object_put(obj); } @@ -59,7 +60,7 @@ static void on_runnables(struct jreq *jreq, struct json_object *obj) static void on_detail(struct jreq *jreq, struct json_object *obj) { const char *appid = getappid(obj); - struct json_object *resp = appfwk_get_application_public(appfwk, appid); + struct json_object *resp = af_db_get_application_public(afdb, appid); reply(jreq, resp, error_not_found); json_object_put(obj); } @@ -75,11 +76,11 @@ static void on_start(struct jreq *jreq, struct json_object *obj) if (appid == NULL) jbus_replyj(jreq, error_bad_request); else { - appli = appfwk_get_application(appfwk, appid); + appli = af_db_get_application(afdb, appid); if (appli == NULL) jbus_replyj(jreq, error_not_found); else { - runid = appfwk_run_start(appli); + runid = af_run_start(appli); if (runid <= 0) jbus_replyj(jreq, error_cant_start); else { @@ -95,7 +96,7 @@ static void on_start(struct jreq *jreq, struct json_object *obj) static void on_stop(struct jreq *jreq, struct json_object *obj) { int runid = getrunid(obj); - int status = appfwk_run_stop(runid); + int status = af_run_stop(runid); jbus_replyj(jreq, status ? error_not_found : "true"); json_object_put(obj); } @@ -103,7 +104,7 @@ static void on_stop(struct jreq *jreq, struct json_object *obj) static void on_continue(struct jreq *jreq, struct json_object *obj) { int runid = getrunid(obj); - int status = appfwk_run_continue(runid); + int status = af_run_continue(runid); jbus_replyj(jreq, status ? error_not_found : "true"); json_object_put(obj); } @@ -111,14 +112,14 @@ static void on_continue(struct jreq *jreq, struct json_object *obj) static void on_terminate(struct jreq *jreq, struct json_object *obj) { int runid = getrunid(obj); - int status = appfwk_run_terminate(runid); + int status = af_run_terminate(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_run_list(); + struct json_object *resp = af_run_list(); jbus_reply(jreq, resp); json_object_put(resp); json_object_put(obj); @@ -127,7 +128,7 @@ static void on_runners(struct jreq *jreq, struct json_object *obj) static void on_state(struct jreq *jreq, struct json_object *obj) { int runid = getrunid(obj); - struct json_object *resp = appfwk_run_state(runid); + struct json_object *resp = af_run_state(runid); reply(jreq, resp, error_not_found); json_object_put(resp); json_object_put(obj); @@ -145,25 +146,31 @@ static int daemonize() int main(int ac, char **av) { - LOGAUTH("af-usrd"); + LOGAUTH("afdb-usrd"); + + /* init runners */ + if (af_run_init()) { + ERROR("af_run_init failed"); + return 1; + } /* init framework */ - appfwk = appfwk_create(); - if (!appfwk) { - ERROR("appfwk_create failed"); + afdb = af_db_create(); + if (!afdb) { + ERROR("af_create failed"); return 1; } - if (appfwk_add_root(appfwk, FWK_APP_DIR)) { + if (af_db_add_root(afdb, FWK_APP_DIR)) { ERROR("can't add root %s", FWK_APP_DIR); return 1; } - if (appfwk_update_applications(appfwk)) { - ERROR("appfwk_update_applications failed"); + if (af_db_update_applications(afdb)) { + ERROR("af_update_applications failed"); return 1; } /* init service */ - jbus = create_jbus(1, "/org/automotive/linux/framework"); + jbus = create_jbus(1, "/org/AGL/framework"); if (!jbus) { ERROR("create_jbus failed"); return 1; diff --git a/src/appfwk.h b/src/appfwk.h deleted file mode 100644 index 7bd4af2..0000000 --- a/src/appfwk.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - 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. -*/ - -struct appfwk; - -extern struct appfwk *appfwk_create(); -extern void appfwk_addref(struct appfwk *appfwk); -extern void appfwk_unref(struct appfwk *appfwk); - -extern int appfwk_add_root(struct appfwk *appfwk, const char *path); -extern int appfwk_update_applications(struct appfwk *af); -extern int appfwk_ensure_applications(struct appfwk *af); - -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); - |