Include json description for callbacks
authorJosé Bollo <jose.bollo@iot.bzh>
Tue, 2 May 2017 08:34:52 +0000 (10:34 +0200)
committerJosé Bollo <jose.bollo@iot.bzh>
Tue, 19 Sep 2017 13:25:36 +0000 (15:25 +0200)
This tiny modification is mainly for debugging.

Change-Id: Ieda90da49d365a7b092a02833227c869bd0397a4
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
src/tests/test-unit/test-unit.c
src/wgtpkg-unit.c
src/wgtpkg-unit.h

index 5912dbc..9a205fc 100644 (file)
@@ -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);
index 8607eb4..123a950 100644 (file)
@@ -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);
                }
        }
index 8acc62e..10751a6 100644 (file)
@@ -52,6 +52,7 @@ struct unitconf {
 
 struct generatedesc {
        const struct unitconf *conf;
+       struct json_object *desc;
        const struct unitdesc *units;
        int nunits;
 };