API: Use string type instead of u8.
[vpp.git] / src / tools / vppapigen / vppapigen_c.py
index b56e072..e189b02 100644 (file)
@@ -3,7 +3,8 @@ import datetime
 import os
 import time
 
-datestring = datetime.datetime.utcfromtimestamp(int(os.environ.get('SOURCE_DATE_EPOCH', time.time())))
+datestring = datetime.datetime.utcfromtimestamp(
+    int(os.environ.get('SOURCE_DATE_EPOCH', time.time())))
 input_filename = 'inputfil'
 top_boilerplate = '''\
 /*
@@ -85,8 +86,8 @@ def msg_name_crc_list(s, suffix):
 
 
 def duplicate_wrapper_head(name):
-    s = "#ifndef defined_%s\n" % name
-    s += "#define defined_%s\n" % name
+    s = "#ifndef _vl_api_defined_%s\n" % name
+    s += "#define _vl_api_defined_%s\n" % name
     return s
 
 
@@ -94,7 +95,14 @@ def duplicate_wrapper_tail():
     return '#endif\n\n'
 
 
-def typedefs(objs, filename):
+def api2c(fieldtype):
+    mappingtable = {'string': 'vl_api_string_t', }
+    if fieldtype in mappingtable:
+        return mappingtable[fieldtype]
+    return fieldtype
+
+
+def typedefs(objs, aliases, filename):
     name = filename.replace('.', '_')
     output = '''\
 
@@ -106,6 +114,15 @@ def typedefs(objs, filename):
 #define included_{module}
 '''
     output = output.format(module=name)
+
+    for k, v in aliases.items():
+        output += duplicate_wrapper_head(k)
+        if 'length' in v:
+            output +=  'typedef %s vl_api_%s_t[%s];\n' % (v['type'], k, v['length'])
+        else:
+            output += 'typedef %s vl_api_%s_t;\n' % (v['type'], k)
+        output += duplicate_wrapper_tail()
+
     for o in objs:
         tname = o.__class__.__name__
         output += duplicate_wrapper_head(o.name)
@@ -121,12 +138,12 @@ def typedefs(objs, filename):
                 output += "typedef VL_API_PACKED(struct _vl_api_%s {\n" % o.name
             for b in o.block:
                 if b.type == 'Field':
-                    output += "    %s %s;\n" % (b.fieldtype, b.fieldname)
+                    output += "    %s %s;\n" % (api2c(b.fieldtype), b.fieldname)
                 elif b.type == 'Array':
                     if b.lengthfield:
-                        output += "    %s %s[0];\n" % (b.fieldtype, b.fieldname)
+                        output += "    %s %s[0];\n" % (api2c(b.fieldtype), b.fieldname)
                     else:
-                        output += "    %s %s[%s];\n" % (b.fieldtype, b.fieldname,
+                        output += "    %s %s[%s];\n" % (api2c(b.fieldtype), b.fieldname,
                                                         b.length)
                 else:
                     raise ValueError("Error in processing array type %s" % b)
@@ -276,7 +293,7 @@ def run(input_filename, s, file_crc):
     output += msg_ids(s)
     output += msg_names(s)
     output += msg_name_crc_list(s, filename)
-    output += typedefs(s['types'] + s['Define'], filename + file_extension)
+    output += typedefs(s['types'] + s['Define'], s['Alias'], filename + file_extension)
     output += printfun(s['types'] + s['Define'])
     output += endianfun(s['types'] + s['Define'])
     output += version_tuple(s, basename)