This just defines the namespace, its contexts and related constants and the only
supported one is currently base:allocation. The names of the constants are not
very future-proof, but shorter than LIBNBD_META_NS_CONTEXT_BASE_ALLOCATION or
similar.
Currently the output looks like this:
/* "base" namespace */
/* "base" namespace contexts */
/* "base:allocation" context related constants */
Separated by two empty lines from unrelated parts of the header file above and
below.
Signed-off-by: Martin Kletzander <mkletzan(a)redhat.com>
---
Notes:
Everything is up for a debate:
- the names might need to be different so that they do not clash with other
constants in the scope later on,
- the fact that "base" and "base:allocation" are even defined,
which might be
useless, since listing contexts of a namespace is not exposed,
- whether this should live in a separate (still included in libnbd.h) file,
- and more...
generator/generator | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/generator/generator b/generator/generator
index 684fb44ac918..9d8d257fd2f1 100755
--- a/generator/generator
+++ b/generator/generator
@@ -2066,6 +2066,13 @@ let constants = [
"READ_ERROR", 3;
]
+let metadata_namespaces = [
+ "base", [ "allocation", [
+ "STATE_HOLE", 1 lsl 0;
+ "STATE_ZERO", 1 lsl 1;
+ ] ];
+]
+
(*----------------------------------------------------------------------*)
(* Helper functions. *)
@@ -2908,6 +2915,25 @@ let print_extern_and_define name args ret =
pr "#define LIBNBD_HAVE_NBD_%s 1\n" name_upper;
pr "\n"
+let print_ns_ctxt ns ns_upper ctxt consts =
+ let ctxt_upper = String.uppercase_ascii ctxt in
+ pr "#define LIBNBD_CONTEXT_%s_%s \"%s:%s\"\n"
+ ns_upper ctxt_upper ns ctxt;
+ pr "\n";
+ pr "/* \"%s:%s\" context related constants */\n" ns ctxt;
+ List.iter (fun (n, i) -> pr "#define LIBNBD_%-30s %d\n" n i) consts
+
+let print_ns ns ctxts =
+ let ns_upper = String.uppercase_ascii ns in
+ pr "/* \"%s\" namespace */\n" ns;
+ pr "#define LIBNBD_NAMESPACE_%s \"%s\"\n" ns_upper ns;
+ pr "\n";
+ pr "/* \"%s\" namespace contexts */\n" ns;
+ List.iter (
+ fun (ctxt, consts) -> print_ns_ctxt ns ns_upper ctxt consts
+ ) ctxts;
+ pr "\n"
+
let generate_include_libnbd_h () =
generate_header CStyle;
@@ -2944,6 +2970,10 @@ let generate_include_libnbd_h () =
fun (name, { args; ret }) -> print_extern_and_define name args ret
) handle_calls;
pr "\n";
+ List.iter (
+ fun (ns, ctxts) -> print_ns ns ctxts
+ ) metadata_namespaces;
+ pr "\n";
pr "#endif /* LIBNBD_H */\n"
let generate_lib_unlocked_h () =
--
2.22.0