From 6b647feb6483cecbfbf50efde394b5a7d8d0aa56 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Bollo?= Date: Tue, 2 May 2017 10:34:52 +0200 Subject: [PATCH] Include json description for callbacks MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This tiny modification is mainly for debugging. Change-Id: Ieda90da49d365a7b092a02833227c869bd0397a4 Signed-off-by: José Bollo --- src/tests/test-unit/test-unit.c | 12 ++++++++++-- src/wgtpkg-unit.c | 5 +++-- src/wgtpkg-unit.h | 1 + 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/tests/test-unit/test-unit.c b/src/tests/test-unit/test-unit.c index 5912dbc..9a205fc 100644 --- a/src/tests/test-unit/test-unit.c +++ b/src/tests/test-unit/test-unit.c @@ -46,7 +46,8 @@ static int processunit(const struct unitdesc *desc) const char *content = desc->content; printf("\n##########################################################"); -printf("\n### usr=%d sys=%d soc=%d srv=%d name %s%s", isuser, issystem, issock, isserv, name?:"?", issock?".socket":isserv?".service":""); +printf("\n### usr=%d sys=%d soc=%d srv=%d name %s%s", isuser, issystem, issock, + isserv, name?:"?", issock?".socket":isserv?".service":""); printf("\n##########################################################"); printf("\n%s\n\n",content); return 0; @@ -55,6 +56,10 @@ printf("\n%s\n\n",content); static int process(void *closure, const struct generatedesc *desc) { int i; +printf("\n##########################################################"); +printf("\n###### J S O N D E S C AFTER #######"); +printf("\n##########################################################"); +puts(json_object_to_json_string_ext(desc->desc, JSON_C_TO_STRING_PRETTY)); for (i = 0 ; i < desc->nunits ; i++) processunit(&desc->units[i]); return 0; @@ -77,7 +82,10 @@ int main(int ac, char **av) if (!obj) error("can't read widget config at %s: %m",*av); - puts(json_object_to_json_string_ext(obj, JSON_C_TO_STRING_PRETTY)); +printf("\n##########################################################"); +printf("\n###### J S O N D E S C BEFORE #######"); +printf("\n##########################################################"); +puts(json_object_to_json_string_ext(obj, JSON_C_TO_STRING_PRETTY)); rc = unit_generator_process(obj, &conf, process, NULL); if (rc) error("can't apply generate units, error %d",rc); diff --git a/src/wgtpkg-unit.c b/src/wgtpkg-unit.c index 8607eb4..123a950 100644 --- a/src/wgtpkg-unit.c +++ b/src/wgtpkg-unit.c @@ -249,7 +249,7 @@ static int process_one_unit(char *spec, struct unitdesc *desc) * with its given 'closure' and the array descripbing the units. * Return 0 in case of success or a negative value in case of error. */ -static int process_all_units(char *corpus, const struct unitconf *conf, int (*process)(void *closure, const struct generatedesc *desc), void *closure) +static int process_all_units(char *corpus, const struct unitconf *conf, int (*process)(void *closure, const struct generatedesc *desc), void *closure, struct json_object *jdesc) { int rc, rc2; char *beg, *end, *befbeg, *aftend; @@ -257,6 +257,7 @@ static int process_all_units(char *corpus, const struct unitconf *conf, int (*pr struct generatedesc gdesc; gdesc.conf = conf; + gdesc.desc = jdesc; gdesc.units = NULL; gdesc.nunits = 0; rc = rc2 = 0; @@ -408,7 +409,7 @@ int unit_generator_process(struct json_object *jdesc, const struct unitconf *con instance = NULL; rc = apply_mustach(template, jdesc, &instance, &size); if (!rc) - rc = process_all_units(instance, conf, process, closure); + rc = process_all_units(instance, conf, process, closure, jdesc); free(instance); } } diff --git a/src/wgtpkg-unit.h b/src/wgtpkg-unit.h index 8acc62e..10751a6 100644 --- a/src/wgtpkg-unit.h +++ b/src/wgtpkg-unit.h @@ -52,6 +52,7 @@ struct unitconf { struct generatedesc { const struct unitconf *conf; + struct json_object *desc; const struct unitdesc *units; int nunits; }; -- 2.16.6