8 from vapi_json_parser import (
23 return "vapi_type_%s" % self.name
26 if self.type.get_c_name() == "string":
28 return "u8 %s[%d];" % (self.name, self.len)
30 return "vl_api_string_t %s;" % (self.name)
32 if self.len is not None and type(self.len) != dict:
33 return "%s %s[%d];" % (self.type.get_c_name(), self.name, self.len)
35 return "%s %s;" % (self.type.get_c_name(), self.name)
37 def get_swap_to_be_code(self, struct, var):
38 if self.len is not None and type(self.len) != dict:
41 "do { unsigned i; for (i = 0; i < %d; ++i) { %s } }"
43 % (self.len, self.type.get_swap_to_be_code(struct, "%s[i]" % var))
46 if self.nelem_field.needs_byte_swap():
47 nelem_field = "%s(%s%s)" % (
48 self.nelem_field.type.get_swap_to_host_func_name(),
50 self.nelem_field.name,
53 nelem_field = "%s%s" % (struct, self.nelem_field.name)
55 "do { unsigned i; for (i = 0; i < %s; ++i) { %s } }"
59 self.type.get_swap_to_be_code(struct, "%s[i]" % var),
62 return self.type.get_swap_to_be_code(struct, "%s" % var)
64 def get_swap_to_host_code(self, struct, var):
65 if self.len is not None and type(self.len) != dict:
68 "do { unsigned i; for (i = 0; i < %d; ++i) { %s } }"
70 % (self.len, self.type.get_swap_to_host_code(struct, "%s[i]" % var))
73 # nelem_field already swapped to host here...
75 "do { unsigned i; for (i = 0; i < %s%s; ++i) { %s } }"
79 self.nelem_field.name,
80 self.type.get_swap_to_host_code(struct, "%s[i]" % var),
83 return self.type.get_swap_to_host_code(struct, "%s" % var)
85 def needs_byte_swap(self):
86 return self.type.needs_byte_swap()
88 def get_vla_parameter_name(self, path):
89 return "%s_%s_array_size" % ("_".join(path), self.name)
91 def get_vla_field_name(self, path):
92 return ".".join(path + [self.nelem_field.name])
94 def get_alloc_vla_param_names(self, path):
96 result = [self.get_vla_parameter_name(path)]
99 if self.type.has_vla():
100 t = self.type.get_alloc_vla_param_names(path + [self.name])
104 def get_vla_calc_size_code(self, prefix, path, is_alloc):
107 "sizeof(%s.%s[0]) * %s"
109 ".".join([prefix] + path),
111 self.get_vla_parameter_name(path)
113 else "%s.%s" % (prefix, self.get_vla_field_name(path)),
118 if self.type.has_vla():
119 t = self.type.get_vla_calc_size_code(prefix, path + [self.name], is_alloc)
123 def get_vla_assign_code(self, prefix, path):
129 ".".join([prefix] + path),
130 self.nelem_field.name,
131 self.get_vla_parameter_name(path),
134 if self.type.has_vla():
135 t = self.type.get_vla_assign_code(prefix, path + [self.name])
140 class CAlias(CField):
141 def get_c_name(self):
142 return "vapi_type_%s" % self.name
145 if self.len is not None:
146 return "typedef %s vapi_type_%s[%d];" % (
147 self.type.get_c_name(),
152 return "typedef %s vapi_type_%s;" % (self.type.get_c_name(), self.name)
155 class CStruct(Struct):
159 "typedef struct __attribute__((__packed__)) {\n%s"
160 % ("\n".join([" %s" % x.get_c_def() for x in self.fields])),
161 "} %s;" % self.get_c_name(),
165 def get_vla_assign_code(self, prefix, path):
170 for x in f.get_vla_assign_code(prefix, path)
173 def get_alloc_vla_param_names(self, path):
178 for x in f.get_alloc_vla_param_names(path)
181 def get_vla_calc_size_code(self, prefix, path, is_alloc):
186 for x in f.get_vla_calc_size_code(prefix, path, is_alloc)
190 class CSimpleType(SimpleType):
200 swap_to_host_dict = {
209 __packed = "__attribute__((packed))"
217 def get_c_name(self):
220 def get_swap_to_be_func_name(self):
221 return self.swap_to_be_dict[self.name]
223 def get_swap_to_host_func_name(self):
224 return self.swap_to_host_dict[self.name]
226 def get_packed_string(self):
227 return self.pack_dict[self.name]
229 def get_swap_to_be_code(self, struct, var, cast=None):
230 x = "%s%s" % (struct, var)
231 return "%s = %s%s(%s);" % (
233 "(%s)" % cast if cast else "",
234 self.get_swap_to_be_func_name(),
238 def get_swap_to_host_code(self, struct, var, cast=None):
239 x = "%s%s" % (struct, var)
240 return "%s = %s%s(%s);" % (
242 "(%s)" % cast if cast else "",
243 self.get_swap_to_host_func_name(),
247 def needs_byte_swap(self):
249 self.get_swap_to_host_func_name()
255 def get_packed(self):
256 return self.pack_dict.get(self.name, "")
260 def get_c_name(self):
261 return "vapi_enum_%s" % self.name
264 return "typedef enum {\n%s\n} %s %s;" % (
265 "\n".join([" %s = %s," % (i, j) for i, j in self.value_pairs]),
266 self.type.get_packed(),
270 def needs_byte_swap(self):
271 return self.type.needs_byte_swap()
273 def get_swap_to_be_code(self, struct, var):
274 return self.type.get_swap_to_be_code(struct, var, self.get_c_name())
276 def get_swap_to_host_code(self, struct, var):
277 return self.type.get_swap_to_host_code(struct, var, self.get_c_name())
281 def get_c_name(self):
282 return "vapi_union_%s" % self.name
285 return "typedef union {\n%s\n} %s;" % (
286 "\n".join([" %s %s;" % (i.get_c_name(), j) for i, j in self.type_pairs]),
290 def needs_byte_swap(self):
294 class CStructType(StructType, CStruct):
295 def get_c_name(self):
296 if self.name == "vl_api_string_t":
297 return "vl_api_string_t"
298 return "vapi_type_%s" % self.name
300 def get_swap_to_be_func_name(self):
301 return "%s_hton" % self.get_c_name()
303 def get_swap_to_host_func_name(self):
304 return "%s_ntoh" % self.get_c_name()
306 def get_swap_to_be_func_decl(self):
307 return "void %s(%s *msg)" % (self.get_swap_to_be_func_name(), self.get_c_name())
309 def get_swap_to_be_func_def(self):
310 return "%s\n{\n%s\n}" % (
311 self.get_swap_to_be_func_decl(),
314 " %s" % p.get_swap_to_be_code("msg->", "%s" % p.name)
316 if p.needs_byte_swap()
321 def get_swap_to_host_func_decl(self):
322 return "void %s(%s *msg)" % (
323 self.get_swap_to_host_func_name(),
327 def get_swap_to_host_func_def(self):
328 return "%s\n{\n%s\n}" % (
329 self.get_swap_to_host_func_decl(),
332 " %s" % p.get_swap_to_host_code("msg->", "%s" % p.name)
334 if p.needs_byte_swap()
339 def get_swap_to_be_code(self, struct, var):
340 return "%s(&%s%s);" % (self.get_swap_to_be_func_name(), struct, var)
342 def get_swap_to_host_code(self, struct, var):
343 return "%s(&%s%s);" % (self.get_swap_to_host_func_name(), struct, var)
345 def needs_byte_swap(self):
346 for f in self.fields:
347 if f.needs_byte_swap():
352 class CMessage(Message):
353 def __init__(self, logger, definition, json_parser):
354 super(CMessage, self).__init__(logger, definition, json_parser)
355 self.payload_members = [
356 " %s" % p.get_c_def() for p in self.fields if p.type != self.header
359 def has_payload(self):
360 return len(self.payload_members) > 0
362 def get_msg_id_name(self):
363 return "vapi_msg_id_%s" % self.name
365 def get_c_name(self):
366 return "vapi_msg_%s" % self.name
368 def get_payload_struct_name(self):
369 return "vapi_payload_%s" % self.name
371 def get_alloc_func_name(self):
372 return "vapi_alloc_%s" % self.name
374 def get_alloc_vla_param_names(self):
379 for x in f.get_alloc_vla_param_names([])
382 def get_alloc_func_decl(self):
383 return "%s* %s(struct vapi_ctx_s *ctx%s)" % (
385 self.get_alloc_func_name(),
386 "".join([", size_t %s" % n for n in self.get_alloc_vla_param_names()]),
389 def get_alloc_func_def(self):
391 if self.header.has_field("client_index"):
392 extra.append(" msg->header.client_index = vapi_get_client_index(ctx);")
393 if self.header.has_field("context"):
394 extra.append(" msg->header.context = 0;")
397 "%s" % self.get_alloc_func_decl(),
399 " %s *msg = NULL;" % self.get_c_name(),
400 " const size_t size = sizeof(%s)%s;"
408 for x in f.get_vla_calc_size_code(
409 "msg->payload", [], is_alloc=True
414 " /* cast here required to play nicely with C++ world ... */",
415 " msg = (%s*)vapi_msg_alloc(ctx, size);" % self.get_c_name(),
422 " msg->header._vl_msg_id = vapi_lookup_vl_msg_id(ctx, %s);"
423 % self.get_msg_id_name(),
429 for line in f.get_vla_assign_code("msg->payload", [])
437 def get_calc_msg_size_func_name(self):
438 return "vapi_calc_%s_msg_size" % self.name
440 def get_calc_msg_size_func_decl(self):
441 return "uword %s(%s *msg)" % (
442 self.get_calc_msg_size_func_name(),
446 def get_calc_msg_size_func_def(self):
449 "%s" % self.get_calc_msg_size_func_decl(),
451 " return sizeof(*msg)%s;"
457 for x in f.get_vla_calc_size_code(
458 "msg->payload", [], is_alloc=False
466 def get_verify_msg_size_func_name(self):
467 return f"vapi_verify_{self.name}_msg_size"
469 def get_verify_msg_size_func_decl(self):
470 return "int %s(%s *msg, uword buf_size)" % (
471 self.get_verify_msg_size_func_name(),
475 def get_verify_msg_size_func_def(self):
476 return inspect.cleandoc(
478 {self.get_verify_msg_size_func_decl()}
480 if (sizeof({self.get_c_name()}) > buf_size)
482 VAPI_ERR("Truncated '{self.name}' msg received, received %lu"
483 "bytes, expected %lu bytes.", buf_size,
484 sizeof({self.get_c_name()}));
487 if ({self.get_calc_msg_size_func_name()}(msg) > buf_size)
489 VAPI_ERR("Truncated '{self.name}' msg received, received %lu"
490 "bytes, expected %lu bytes.", buf_size,
491 {self.get_calc_msg_size_func_name()}(msg));
500 if self.has_payload():
503 "typedef struct __attribute__ ((__packed__)) {",
504 "%s " % "\n".join(self.payload_members),
505 "} %s;" % self.get_payload_struct_name(),
507 "typedef struct __attribute__ ((__packed__)) {",
509 " %s %s;" % (self.header.get_c_name(), self.fields[0].name)
510 if self.header is not None
513 " %s payload;" % self.get_payload_struct_name(),
514 "} %s;" % self.get_c_name(),
520 "typedef struct __attribute__ ((__packed__)) {",
522 " %s %s;" % (self.header.get_c_name(), self.fields[0].name)
523 if self.header is not None
526 "} %s;" % self.get_c_name(),
530 def get_swap_payload_to_host_func_name(self):
531 return "%s_payload_ntoh" % self.get_c_name()
533 def get_swap_payload_to_be_func_name(self):
534 return "%s_payload_hton" % self.get_c_name()
536 def get_swap_payload_to_host_func_decl(self):
537 return "void %s(%s *payload)" % (
538 self.get_swap_payload_to_host_func_name(),
539 self.get_payload_struct_name(),
542 def get_swap_payload_to_be_func_decl(self):
543 return "void %s(%s *payload)" % (
544 self.get_swap_payload_to_be_func_name(),
545 self.get_payload_struct_name(),
548 def get_swap_payload_to_be_func_def(self):
549 return "%s\n{\n%s\n}" % (
550 self.get_swap_payload_to_be_func_decl(),
553 " %s" % p.get_swap_to_be_code("payload->", "%s" % p.name)
555 if p.needs_byte_swap() and p.type != self.header
560 def get_swap_payload_to_host_func_def(self):
561 return "%s\n{\n%s\n}" % (
562 self.get_swap_payload_to_host_func_decl(),
565 " %s" % p.get_swap_to_host_code("payload->", "%s" % p.name)
567 if p.needs_byte_swap() and p.type != self.header
572 def get_swap_to_host_func_name(self):
573 return "%s_ntoh" % self.get_c_name()
575 def get_swap_to_be_func_name(self):
576 return "%s_hton" % self.get_c_name()
578 def get_swap_to_host_func_decl(self):
579 return "void %s(%s *msg)" % (
580 self.get_swap_to_host_func_name(),
584 def get_swap_to_be_func_decl(self):
585 return "void %s(%s *msg)" % (self.get_swap_to_be_func_name(), self.get_c_name())
587 def get_swap_to_be_func_def(self):
590 "%s" % self.get_swap_to_be_func_decl(),
593 ' VAPI_DBG("Swapping `%s\'@%%p to big endian", msg);'
596 " %s(&msg->header);" % self.header.get_swap_to_be_func_name()
597 if self.header is not None
599 " %s(&msg->payload);" % self.get_swap_payload_to_be_func_name()
600 if self.has_payload()
606 def get_swap_to_host_func_def(self):
609 "%s" % self.get_swap_to_host_func_decl(),
612 ' VAPI_DBG("Swapping `%s\'@%%p to host byte order", msg);'
615 " %s(&msg->header);" % self.header.get_swap_to_host_func_name()
616 if self.header is not None
618 " %s(&msg->payload);" % self.get_swap_payload_to_host_func_name()
619 if self.has_payload()
625 def get_op_func_name(self):
626 return "vapi_%s" % self.name
628 def get_op_func_decl(self):
629 stream_param_lines = []
630 if self.has_stream_msg:
631 stream_param_lines = [
632 "vapi_error_e (*details_callback)(struct vapi_ctx_s *ctx",
633 " void *callback_ctx",
637 % self.stream_msg.get_payload_struct_name(),
638 "void *details_callback_ctx",
641 return "vapi_error_e %s(%s)" % (
642 self.get_op_func_name(),
645 "struct vapi_ctx_s *ctx",
646 "%s *msg" % self.get_c_name(),
647 "vapi_error_e (*reply_callback)(struct vapi_ctx_s *ctx",
648 " void *callback_ctx",
652 % self.reply.get_payload_struct_name(),
655 "void *reply_callback_ctx",
661 def get_op_func_def(self):
662 param_check_lines = [" if (!msg || !reply_callback) {"]
663 store_request_lines = [
664 " vapi_store_request(ctx, req_context, %s, %s, "
666 self.reply.get_msg_id_name(),
667 "VAPI_REQUEST_DUMP" if self.reply_is_stream else "VAPI_REQUEST_REG",
669 " (vapi_cb_t)reply_callback, reply_callback_ctx);",
671 if self.has_stream_msg:
672 param_check_lines = [
673 " if (!msg || !reply_callback || !details_callback) {"
675 store_request_lines = [
676 f" vapi_store_request(ctx, req_context, {self.stream_msg.get_msg_id_name()}, VAPI_REQUEST_STREAM, ",
677 " (vapi_cb_t)details_callback, details_callback_ctx);",
678 f" vapi_store_request(ctx, req_context, {self.reply.get_msg_id_name()}, VAPI_REQUEST_REG, ",
679 " (vapi_cb_t)reply_callback, reply_callback_ctx);",
684 "%s" % self.get_op_func_decl(),
689 " return VAPI_EINVAL;",
691 " if (vapi_is_nonblocking(ctx) && vapi_requests_full(ctx)) {",
692 " return VAPI_EAGAIN;",
695 " if (VAPI_OK != (rv = vapi_producer_lock (ctx))) {",
698 " u32 req_context = vapi_gen_req_context(ctx);",
699 " msg->header.context = req_context;",
700 " %s(msg);" % self.get_swap_to_be_func_name(),
702 " if (VAPI_OK == (rv = vapi_send_with_control_ping "
703 "(ctx, msg, req_context))) {"
704 if (self.reply_is_stream and not self.has_stream_msg)
705 else " if (VAPI_OK == (rv = vapi_send (ctx, msg))) {"
708 + store_request_lines
710 " if (VAPI_OK != vapi_producer_unlock (ctx)) {",
711 " abort (); /* this really shouldn't happen */",
713 " if (vapi_is_nonblocking(ctx)) {",
716 " rv = vapi_dispatch(ctx);",
719 " %s(msg);" % self.get_swap_to_host_func_name(),
720 " if (VAPI_OK != vapi_producer_unlock (ctx)) {",
721 " abort (); /* this really shouldn't happen */",
730 def get_event_cb_func_decl(self):
731 if not self.is_reply and not self.is_event:
732 raise Exception("Cannot register event callback for non-reply message")
733 if self.has_payload():
736 "void vapi_set_%s_event_cb (" % self.get_c_name(),
737 " struct vapi_ctx_s *ctx, ",
739 " vapi_error_e (*callback)(struct vapi_ctx_s *ctx, "
740 "void *callback_ctx, %s *payload),"
741 % self.get_payload_struct_name()
743 " void *callback_ctx)",
749 "void vapi_set_%s_event_cb (" % self.get_c_name(),
750 " struct vapi_ctx_s *ctx, ",
751 " vapi_error_e (*callback)(struct vapi_ctx_s *ctx, "
752 "void *callback_ctx),",
753 " void *callback_ctx)",
757 def get_event_cb_func_def(self):
758 if not self.is_reply and not self.is_event:
759 raise Exception("Cannot register event callback for non-reply function")
762 "%s" % self.get_event_cb_func_decl(),
765 " vapi_set_event_cb(ctx, %s, (vapi_event_cb)callback, "
766 "callback_ctx);" % self.get_msg_id_name()
772 def get_c_metadata_struct_name(self):
773 return "__vapi_metadata_%s" % self.name
775 def get_c_constructor(self):
777 if self.header is not None:
778 has_context = self.header.has_field("context")
781 "static void __attribute__((constructor)) __vapi_constructor_%s()"
784 ' static const char name[] = "%s";' % self.name,
785 ' static const char name_with_crc[] = "%s_%s";'
786 % (self.name, self.crc[2:]),
787 " static vapi_message_desc_t %s = {"
788 % self.get_c_metadata_struct_name(),
790 " sizeof(name) - 1,",
792 " sizeof(name_with_crc) - 1,",
793 " true," if has_context else " false,",
794 " offsetof(%s, context)," % self.header.get_c_name()
797 (" offsetof(%s, payload)," % self.get_c_name())
798 if self.has_payload()
799 else " VAPI_INVALID_MSG_ID,",
800 " (verify_msg_size_fn_t)%s," % self.get_verify_msg_size_func_name(),
801 " (generic_swap_fn_t)%s," % self.get_swap_to_be_func_name(),
802 " (generic_swap_fn_t)%s," % self.get_swap_to_host_func_name(),
803 " VAPI_INVALID_MSG_ID,",
806 " %s = vapi_register_msg(&%s);"
807 % (self.get_msg_id_name(), self.get_c_metadata_struct_name()),
808 ' VAPI_DBG("Assigned msg id %%d to %s", %s);'
809 % (self.name, self.get_msg_id_name()),
815 def emit_definition(parser, json_file, emitted, o):
818 if o.name in ("msg_header1_t", "msg_header2_t"):
820 if hasattr(o, "depends"):
822 emit_definition(parser, json_file, emitted, x)
823 if hasattr(o, "reply"):
824 emit_definition(parser, json_file, emitted, o.reply)
825 if hasattr(o, "stream_msg"):
826 emit_definition(parser, json_file, emitted, o.stream_msg)
827 if hasattr(o, "get_c_def"):
829 o not in parser.enums_by_json[json_file]
830 and o not in parser.types_by_json[json_file]
831 and o not in parser.unions_by_json[json_file]
832 and o.name not in parser.messages_by_json[json_file]
833 and o not in parser.aliases_by_json[json_file]
836 guard = "defined_%s" % o.get_c_name()
837 print("#ifndef %s" % guard)
838 print("#define %s" % guard)
839 print("%s" % o.get_c_def())
841 function_attrs = "static inline "
842 if o.name in parser.messages_by_json[json_file]:
844 print("%s%s" % (function_attrs, o.get_swap_payload_to_be_func_def()))
846 print("%s%s" % (function_attrs, o.get_swap_payload_to_host_func_def()))
848 print("%s%s" % (function_attrs, o.get_swap_to_be_func_def()))
850 print("%s%s" % (function_attrs, o.get_swap_to_host_func_def()))
852 print("%s%s" % (function_attrs, o.get_calc_msg_size_func_def()))
854 print("%s%s" % (function_attrs, o.get_verify_msg_size_func_def()))
855 if not o.is_reply and not o.is_event and not o.is_stream:
857 print("%s%s" % (function_attrs, o.get_alloc_func_def()))
859 print("%s%s" % (function_attrs, o.get_op_func_def()))
861 print("%s" % o.get_c_constructor())
862 if (o.is_reply or o.is_event) and not o.is_stream:
864 print("%s%s;" % (function_attrs, o.get_event_cb_func_def()))
865 elif hasattr(o, "get_swap_to_be_func_def"):
866 print("%s%s" % (function_attrs, o.get_swap_to_be_func_def()))
868 print("%s%s" % (function_attrs, o.get_swap_to_host_func_def()))
874 def gen_json_unified_header(parser, logger, j, io, name):
875 d, f = os.path.split(j)
876 logger.info("Generating header `%s'" % name)
877 orig_stdout = sys.stdout
879 include_guard = "__included_%s" % (
886 print("#ifndef %s" % include_guard)
887 print("#define %s" % include_guard)
889 print("#include <stdlib.h>")
890 print("#include <stddef.h>")
891 print("#include <arpa/inet.h>")
892 print("#include <vapi/vapi_internal.h>")
893 print("#include <vapi/vapi.h>")
894 print("#include <vapi/vapi_dbg.h>")
896 print("#ifdef __cplusplus")
897 print('extern "C" {')
900 print("#ifndef __vl_api_string_swap_fns_defined__")
901 print("#define __vl_api_string_swap_fns_defined__")
903 print("#include <vlibapi/api_types.h>")
905 function_attrs = "static inline "
906 o = parser.types["vl_api_string_t"]
907 print("%s%s" % (function_attrs, o.get_swap_to_be_func_def()))
909 print("%s%s" % (function_attrs, o.get_swap_to_host_func_def()))
911 print("#endif //__vl_api_string_swap_fns_defined__")
913 if name == "memclnt.api.vapi.h":
916 "static inline vapi_error_e vapi_send_with_control_ping "
917 "(vapi_ctx_t ctx, void * msg, u32 context);"
919 elif name == "vlib.api.vapi.h":
920 print("#include <vapi/memclnt.api.vapi.h>")
922 print("#include <vapi/vlib.api.vapi.h>")
924 for m in parser.messages_by_json[j].values():
925 print("extern vapi_msg_id_t %s;" % m.get_msg_id_name())
928 "#define DEFINE_VAPI_MSG_IDS_%s\\"
929 % f.replace(".", "_").replace("/", "_").replace("-", "_").upper()
934 " vapi_msg_id_t %s;" % m.get_msg_id_name()
935 for m in parser.messages_by_json[j].values()
942 for e in parser.enums_by_json[j]:
943 emit_definition(parser, j, emitted, e)
944 for u in parser.unions_by_json[j]:
945 emit_definition(parser, j, emitted, u)
946 for t in parser.types_by_json[j]:
947 emit_definition(parser, j, emitted, t)
948 for a in parser.aliases_by_json[j]:
949 emit_definition(parser, j, emitted, a)
950 for m in parser.messages_by_json[j].values():
951 emit_definition(parser, j, emitted, m)
955 if name == "vlib.api.vapi.h":
956 vapi_send_with_control_ping_function = """
957 static inline vapi_error_e
958 vapi_send_with_control_ping (vapi_ctx_t ctx, void *msg, u32 context)
960 vapi_msg_control_ping *ping = vapi_alloc_control_ping (ctx);
965 ping->header.context = context;
966 vapi_msg_control_ping_hton (ping);
967 return vapi_send2 (ctx, msg, ping);
970 print("%s" % vapi_send_with_control_ping_function)
973 print("#ifdef __cplusplus")
978 sys.stdout = orig_stdout
981 def json_to_c_header_name(json_name):
982 if json_name.endswith(".json"):
983 return "%s.vapi.h" % os.path.splitext(json_name)[0]
984 raise Exception("Unexpected json name `%s'!" % json_name)
987 def gen_c_unified_headers(parser, logger, prefix, remove_path):
988 if prefix == "" or prefix is None:
991 prefix = "%s/" % prefix
992 for j in parser.json_files:
994 d, f = os.path.split(j)
997 with open("%s%s" % (prefix, json_to_c_header_name(f)), "w") as io:
998 gen_json_unified_header(parser, logger, j, io, json_to_c_header_name(f))
1001 if __name__ == "__main__":
1003 verbose = int(os.getenv("V", 0))
1014 logging.basicConfig(stream=sys.stdout, level=log_level)
1015 logger = logging.getLogger("VAPI C GEN")
1016 logger.setLevel(log_level)
1018 argparser = argparse.ArgumentParser(description="VPP C API generator")
1019 argparser.add_argument(
1024 help="json api file" "(may be specified multiple times)",
1026 argparser.add_argument("--prefix", action="store", default=None, help="path prefix")
1027 argparser.add_argument(
1028 "--remove-path", action="store_true", help="remove path from filename"
1030 args = argparser.parse_args()
1032 jsonparser = JsonParser(
1035 simple_type_class=CSimpleType,
1038 struct_type_class=CStructType,
1040 message_class=CMessage,
1044 # not using the model of having separate generated header and code files
1045 # with generated symbols present in shared library (per discussion with
1046 # Damjan), to avoid symbol version issues in .so
1047 # gen_c_headers_and_code(jsonparser, logger, args.prefix)
1049 gen_c_unified_headers(jsonparser, logger, args.prefix, args.remove_path)
1051 for e in jsonparser.exceptions: