vppapigen: enable codegen for stream message types
[vpp.git] / src / tools / vppapigen / vppapigen_c.py
old mode 100644 (file)
new mode 100755 (executable)
index b9f9e07..26a348f
@@ -1250,6 +1250,11 @@ static inline void vl_api_{name}_t_endian (vl_api_{name}_t *a)
 
         output += signature.format(name=t.name)
 
+        # make Array type appear before the others:
+        # some arrays have dynamic length, and we want to iterate over
+        # them before changing endiann for the length field
+        t.block.sort(key=lambda x: x.type)
+
         for o in t.block:
             output += endianfun_obj(o)
         output += "}\n\n"
@@ -1576,6 +1581,31 @@ def generate_c_boilerplate(services, defines, counters, file_crc, module, stream
         except KeyError:
             pass
 
+        try:
+            if s.stream:
+                d = define_hash[s.stream_message]
+                write(
+                    "   c = (vl_msg_api_msg_config_t) "
+                    "{{.id = VL_API_{ID} + msg_id_base,\n"
+                    '  .name = "{n}",\n'
+                    "  .handler = 0,\n"
+                    "  .endian = vl_api_{n}_t_endian,\n"
+                    "  .format_fn = vl_api_{n}_t_format,\n"
+                    "  .traced = 1,\n"
+                    "  .replay = 1,\n"
+                    "  .tojson = vl_api_{n}_t_tojson,\n"
+                    "  .fromjson = vl_api_{n}_t_fromjson,\n"
+                    "  .calc_size = vl_api_{n}_t_calc_size,\n"
+                    "  .is_autoendian = {auto}}};\n".format(
+                        n=s.stream_message,
+                        ID=s.stream_message.upper(),
+                        auto=d.autoendian,
+                    )
+                )
+                write("   vl_msg_api_config (&c);\n")
+        except KeyError:
+            pass
+
     write("   return msg_id_base;\n")
     write("}\n")
 
@@ -1669,17 +1699,18 @@ def generate_c_test_boilerplate(services, defines, file_crc, module, plugin, str
     write("setup_message_id_table (vat_main_t * vam, u16 msg_id_base) {\n")
     for s in services:
         write(
-            "   vl_msg_api_set_handlers(VL_API_{ID} + msg_id_base, "
-            '                           "{n}",\n'
-            "                           vl_api_{n}_t_handler, "
-            "                           vl_api_{n}_t_endian, "
-            "                           vl_api_{n}_t_format,\n"
-            "                           sizeof(vl_api_{n}_t), 1,\n"
-            "                           vl_api_{n}_t_tojson,\n"
-            "                           vl_api_{n}_t_fromjson,\n"
-            "                           vl_api_{n}_t_calc_size);\n".format(
-                n=s.reply, ID=s.reply.upper()
-            )
+            "   vl_msg_api_config (&(vl_msg_api_msg_config_t){{\n"
+            "    .id = VL_API_{ID} + msg_id_base,\n"
+            '    .name = "{n}",\n'
+            "    .handler = vl_api_{n}_t_handler,\n"
+            "    .endian = vl_api_{n}_t_endian,\n"
+            "    .format_fn = vl_api_{n}_t_format,\n"
+            "    .size = sizeof(vl_api_{n}_t),\n"
+            "    .traced = 1,\n"
+            "    .tojson = vl_api_{n}_t_tojson,\n"
+            "    .fromjson = vl_api_{n}_t_fromjson,\n"
+            "    .calc_size = vl_api_{n}_t_calc_size,\n"
+            "   }});".format(n=s.reply, ID=s.reply.upper())
         )
         write(
             '   hash_set_mem (vam->function_by_name, "{n}", api_{n});\n'.format(
@@ -1698,17 +1729,18 @@ def generate_c_test_boilerplate(services, defines, file_crc, module, plugin, str
         # Events
         for e in s.events:
             write(
-                "   vl_msg_api_set_handlers(VL_API_{ID} + msg_id_base, "
-                '                          "{n}",\n'
-                "                           vl_api_{n}_t_handler, "
-                "                           vl_api_{n}_t_endian, "
-                "                           vl_api_{n}_t_format,\n"
-                "                           sizeof(vl_api_{n}_t), 1,\n"
-                "                           vl_api_{n}_t_tojson,\n"
-                "                           vl_api_{n}_t_fromjson,\n"
-                "                           vl_api_{n}_t_calc_size);\n".format(
-                    n=e, ID=e.upper()
-                )
+                "   vl_msg_api_config (&(vl_msg_api_msg_config_t){{\n"
+                "    .id = VL_API_{ID} + msg_id_base,\n"
+                '    .name = "{n}",\n'
+                "    .handler = vl_api_{n}_t_handler,\n"
+                "    .endian = vl_api_{n}_t_endian,\n"
+                "    .format_fn = vl_api_{n}_t_format,\n"
+                "    .size = sizeof(vl_api_{n}_t),\n"
+                "    .traced = 1,\n"
+                "    .tojson = vl_api_{n}_t_tojson,\n"
+                "    .fromjson = vl_api_{n}_t_fromjson,\n"
+                "    .calc_size = vl_api_{n}_t_calc_size,\n"
+                "   }});".format(n=e, ID=e.upper())
             )
 
     write("}\n")