summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2017-05-02 10:34:52 +0200
committerJosé Bollo <jose.bollo@iot.bzh>2017-09-19 15:25:36 +0200
commit6b647feb6483cecbfbf50efde394b5a7d8d0aa56 (patch)
tree13cca6999c0d4530f9445c19afb492021096c4ce /src
parent36b13c48406e977265669f5c99802571b8499cef (diff)
Include json description for callbacks
This tiny modification is mainly for debugging. Change-Id: Ieda90da49d365a7b092a02833227c869bd0397a4 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
Diffstat (limited to 'src')
-rw-r--r--src/tests/test-unit/test-unit.c12
-rw-r--r--src/wgtpkg-unit.c5
-rw-r--r--src/wgtpkg-unit.h1
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;
};