X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fgenskel%2Fgenskel.c;h=8b179aa31b0639f16a6b5775d96b376734ee589b;hb=170aef20bc3a59d5139c2eff8794d9ba4c83a2e5;hp=58f7a2c499670ed7bf84053edc8da19c2785a4dd;hpb=66451a0d658eabab18f37995659d81d429e0138e;p=src%2Fapp-framework-binder.git diff --git a/src/genskel/genskel.c b/src/genskel/genskel.c index 58f7a2c4..8b179aa3 100644 --- a/src/genskel/genskel.c +++ b/src/genskel/genskel.c @@ -44,6 +44,7 @@ #include #include #include +#include #include @@ -71,8 +72,9 @@ const char *api = NULL; const char *scope = NULL; const char *prefix = NULL; const char *postfix = NULL; +char *capi = NULL; int priv = -1; -int conc = -1; +int noconc = -1; /** * Search for a reference of type "#/a/b/c" int the @@ -167,15 +169,27 @@ struct json_object *expand_$ref(struct path path) return path.object; } +char *cify(const char *str) +{ + char *r = strdup(str); + int i = 0; + while (r && r[i]) { + if (!isalnum(r[i])) + r[i] = '_'; + i++; + } + return r; +} -char *make_desc(struct json_object *o) +char *make_info(const char *text, int split) { const char *a, *b; char *desc, c, buf[3]; size_t len; int i, pos, e; - a = b = json_object_to_json_string_ext(root, 0); + /* estimated length */ + a = b = text; len = 1; while((c = *b++)) { len += 1 + ('"' == c); @@ -186,6 +200,8 @@ char *make_desc(struct json_object *o) oom(desc); len = pos = 0; + if (!split) + desc[len++] = '"'; b = a; while((c = *b++)) { if (c == '"') { @@ -215,18 +231,20 @@ char *make_desc(struct json_object *o) } i = e = 0; while (buf[i]) { - if (pos >= 77 && !e) { - desc[len++] = '"'; - desc[len++] = '\n'; - pos = 0; - } - if (pos == 0) { - desc[len++] = ' '; - desc[len++] = ' '; - desc[len++] = ' '; - desc[len++] = ' '; - desc[len++] = '"'; - pos = 5; + if (split) { + if (pos >= 77 && !e) { + desc[len++] = '"'; + desc[len++] = '\n'; + pos = 0; + } + if (pos == 0) { + desc[len++] = ' '; + desc[len++] = ' '; + desc[len++] = ' '; + desc[len++] = ' '; + desc[len++] = '"'; + pos = 5; + } } c = buf[i++]; desc[len++] = c; @@ -235,11 +253,17 @@ char *make_desc(struct json_object *o) } } desc[len++] = '"'; - desc[len++] = '\n'; + if (split) + desc[len++] = '\n'; desc[len] = 0; return desc; } +char *make_desc(struct json_object *o) +{ + return make_info(json_object_to_json_string_ext(root, 0), 1); +} + struct json_object *permissions_of_verb(struct json_object *obj) { struct json_object *x, *y; @@ -260,7 +284,7 @@ void print_perms() n = a_perms ? json_object_array_length(a_perms) : 0; if (n) { - printf("static const struct afb_auth _afb_auths_v2_%s[] = {\n" , api); + printf("static const struct afb_auth _afb_auths_v2_%s[] = {\n" , capi); i = 0; while (i < n) { printf("\t{ %s }", json_object_get_string(json_object_array_get_idx(a_perms, i))); @@ -283,7 +307,7 @@ struct json_object *new_perm(struct json_object *obj, const char *desc) a_perms = json_object_new_array(); } - asprintf(&b, "&_afb_auths_v2_%s[%d]", api, json_object_array_length(a_perms)); + asprintf(&b, "&_afb_auths_v2_%s[%d]", capi, json_object_array_length(a_perms)); x = json_object_new_string(desc); y = json_object_new_string(b); json_object_array_add(a_perms, x); @@ -483,7 +507,12 @@ void print_declare_verb(const char *name, struct json_object *obj) void print_struct_verb(const char *name, struct json_object *obj) { - struct json_object *p; + struct json_object *p, *i; + const char *info; + + info = NULL; + if (json_object_object_get_ex(obj, "description", &i)) + info = json_object_get_string(i); p = permissions_of_verb(obj); printf( @@ -496,8 +525,10 @@ void print_struct_verb(const char *name, struct json_object *obj) printf( ",\n" " .auth = %s,\n" + " .info = %s,\n" " .session = " - , p ? json_object_get_string(decl_perm(p)) : "NULL" + , p && decl_perm(p) ? json_object_get_string(decl_perm(p)) : "NULL" + , info ? make_info(info, 0) : "NULL" ); print_session(p); printf( @@ -561,6 +592,7 @@ void getvar(const char **var, const char *path, const char *defval) void process(char *filename) { char *desc; + const char *info; /* translate - */ if (!strcmp(filename, "-")) @@ -594,8 +626,11 @@ void process(char *filename) getvar(&prefix, "#/info/x-binding-c-generator/prefix", "afb_verb_"); getvar(&postfix, "#/info/x-binding-c-generator/postfix", "_cb"); getvarbool(&priv, "#/info/x-binding-c-generator/private", 0); - getvarbool(&conc, "#/info/x-binding-c-generator/concurrent", 0); + getvarbool(&noconc, "#/info/x-binding-c-generator/noconcurrency", 0); getvar(&api, "#/info/title", "?"); + info = NULL; + getvar(&info, "#/info/description", NULL); + capi = cify(api); /* get the API name */ printf( @@ -604,7 +639,7 @@ void process(char *filename) "%s" ";\n" "\n" - , api, desc + , capi, desc ); enum_verbs(declare_permissions); print_perms(); @@ -612,11 +647,17 @@ void process(char *filename) printf( "\n" "static const struct afb_verb_v2 _afb_verbs_v2_%s[] = {\n" - , api + , capi ); enum_verbs(print_struct_verb); printf( - " { .verb = NULL }\n" + " {\n" + " .verb = NULL,\n" + " .callback = NULL,\n" + " .auth = NULL,\n" + " .info = NULL,\n" + " .session = 0\n" + " }\n" "};\n" ); printf( @@ -624,23 +665,25 @@ void process(char *filename) "%sconst struct afb_binding_v2 %s%s = {\n" " .api = \"%s\",\n" " .specification = _afb_description_v2_%s,\n" + " .info = %s,\n" " .verbs = _afb_verbs_v2_%s,\n" " .preinit = %s,\n" " .init = %s,\n" " .onevent = %s,\n" - " .concurrent = %d\n" + " .noconcurrency = %d\n" "};\n" "\n" , priv ? "static " : "" , priv ? "_afb_binding_v2_" : "afbBindingV2" - , priv ? api : "" - , api - , api + , priv ? capi : "" , api + , capi + , info ? make_info(info, 0) : "NULL" + , capi , preinit ?: "NULL" , init ?: "NULL" , onevent ?: "NULL" - , !!conc + , !!noconc ); /* clean up */