From 2c566e2dc9df934fb3884f9d4a9ad7ffc73a4aab Mon Sep 17 00:00:00 2001 From: José Bollo Date: Fri, 17 Mar 2017 23:43:41 +0100 Subject: Provide unit in config.xml and documentation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit remove urn:AGL:widget:provided-application in favour of urn:AGL:widget:provided-unit. In the same time, the feature urn:AGL:widget:provided-api must be attached to a unit. This will enable to export more than one API for a unit if needed. Change-Id: I17ade3651db2cd61402875333d063ee05cf57a10 Signed-off-by: José Bollo --- src/tests/test-unit/config.xml | 13 +++++++-- src/wgt-json.c | 63 +++++++++++++++++------------------------- src/wgt-strings.c | 2 +- src/wgt-strings.h | 2 +- 4 files changed, 38 insertions(+), 42 deletions(-) (limited to 'src') diff --git a/src/tests/test-unit/config.xml b/src/tests/test-unit/config.xml index 48a7e3c..65fa43e 100644 --- a/src/tests/test-unit/config.xml +++ b/src/tests/test-unit/config.xml @@ -23,21 +23,30 @@ + - + - + + + + + + + + + diff --git a/src/wgt-json.c b/src/wgt-json.c index 258f151..e0ff08b 100644 --- a/src/wgt-json.c +++ b/src/wgt-json.c @@ -35,26 +35,6 @@ #include "wgt-strings.h" #include "verbose.h" -/* -{ - permissions: { - dict: { - ID: { name: ID, level: LEVEL, index: INDEX }, - ... - }, - list: [ - { name: ID, level: LEVEL, index: 0 }, - ... - } - }, - targets: [ - { name: ID, level: LEVEL, index: 0 }, - ... - ] - } -} -*/ - struct paramaction { const char *name; @@ -258,12 +238,13 @@ static int add_param_simple(struct json_object *obj, const struct wgt_desc_param static int add_param_array(struct json_object *obj, const struct wgt_desc_param *param, void *closure) { + const char *array_name = closure; struct json_object *array, *value; - if (!closure) + if (!array_name) array = obj; - else if (!json_object_object_get_ex(obj, closure, &array)) { - array = j_add_new_array(obj, closure); + else if (!json_object_object_get_ex(obj, array_name, &array)) { + array = j_add_new_array(obj, array_name); if (!array) return -ENOMEM; } @@ -305,7 +286,7 @@ static int add_targeted_params(struct json_object *targets, const struct wgt_des return rc < 0 ? rc : apply_params(obj, feat->params, actions); } -static int add_provided(struct json_object *targets, const struct wgt_desc_feature *feat) +static int add_provided_unit(struct json_object *targets, const struct wgt_desc_feature *feat) { static struct paramaction actions[] = { { .name = string_sharp_target, .action = NULL, .closure = NULL }, @@ -314,6 +295,15 @@ static int add_provided(struct json_object *targets, const struct wgt_desc_featu return add_targeted_params(targets, feat, actions); } +static int add_provided_api(struct json_object *targets, const struct wgt_desc_feature *feat) +{ + static struct paramaction actions[] = { + { .name = string_sharp_target, .action = NULL, .closure = NULL }, + { .name = NULL, .action = add_param_array, .closure = (void*)string_provided_api } + }; + return add_targeted_params(targets, feat, actions); +} + static int add_required_api(struct json_object *targets, const struct wgt_desc_feature *feat) { static struct paramaction actions[] = { @@ -323,7 +313,6 @@ static int add_required_api(struct json_object *targets, const struct wgt_desc_f return add_targeted_params(targets, feat, actions); } - static int add_required_permission(struct json_object *targets, const struct wgt_desc_feature *feat) { static struct paramaction actions[] = { @@ -370,8 +359,7 @@ static struct json_object *to_json(const struct wgt_desc *desc) rc = -EINVAL; } featname += prefixlen; - if (!strcmp(featname, string_provided_api) - || !strcmp(featname, string_provided_application)) { + if (!strcmp(featname, string_provided_unit)) { rc2 = make_target(targets, feat); if (rc2 < 0 && !rc) rc = rc2; @@ -386,25 +374,24 @@ static struct json_object *to_json(const struct wgt_desc *desc) featname += prefixlen; if (!strcmp(featname, string_defined_permission)) { rc2 = add_defined_permission(permissions, feat); - if (rc2 < 0 && !rc) - rc = rc2; } - else if (!strcmp(featname, string_provided_application) - || !strcmp(featname, string_provided_api)) { - rc2 = add_provided(targets, feat); - if (rc2 < 0 && !rc) - rc = rc2; + else if (!strcmp(featname, string_provided_unit)) { + rc2 = add_provided_unit(targets, feat); + } + else if (!strcmp(featname, string_provided_api)) { + rc2 = add_provided_api(targets, feat); } else if (!strcmp(featname, string_required_api)) { rc2 = add_required_api(targets, feat); - if (rc2 < 0 && !rc) - rc = rc2; } else if (!strcmp(featname, string_required_permission)) { rc2 = add_required_permission(targets, feat); - if (rc2 < 0 && !rc) - rc = rc2; + } else { + /* gently ignore other features */ + rc2 = 0; } + if (rc2 < 0 && !rc) + rc = rc2; } } diff --git a/src/wgt-strings.c b/src/wgt-strings.c index f9fe01e..12e5ba5 100644 --- a/src/wgt-strings.c +++ b/src/wgt-strings.c @@ -56,8 +56,8 @@ const char string_level[] = "level"; const char string_list[] = "list"; const char string_main[] = "main"; const char string_optional[] = "optional"; -const char string_provided_application[] = "provided-application"; const char string_provided_api[] = "provided-api"; +const char string_provided_unit[] = "provided-unit"; const char string_required_api[] = "required-api"; const char string_required_permission[] = "required-permission"; const char string_targets[] = "targets"; diff --git a/src/wgt-strings.h b/src/wgt-strings.h index 504bd16..25bfa02 100644 --- a/src/wgt-strings.h +++ b/src/wgt-strings.h @@ -54,8 +54,8 @@ extern const char string_level[]; extern const char string_list[]; extern const char string_main[]; extern const char string_optional[]; -extern const char string_provided_application[]; extern const char string_provided_api[]; +extern const char string_provided_unit[]; extern const char string_required_api[]; extern const char string_required_permission[]; extern const char string_sharp_target[]; -- cgit 1.2.3-korg