aboutsummaryrefslogtreecommitdiffstats
path: root/vpp-api/java/jvpp/gen/jvpp_c_gen.py
diff options
context:
space:
mode:
authorMarek Gradzki <mgradzki@cisco.com>2016-06-15 16:38:33 +0200
committerDave Wallace <dwallacelf@gmail.com>2016-06-24 13:23:16 +0000
commitfa42e25c4e498c57e15ebb0ded56502a61b7dc08 (patch)
treea6a79850ddab1e962c9f639050a09925fe57c9f0 /vpp-api/java/jvpp/gen/jvpp_c_gen.py
parent80ee21386cea217d0e9292d2a8b15ea88bf99d30 (diff)
VPP-118: add support for variable length arrays to jvpp
* extends VPP's message definition language with the following syntax: u32 count: u8 array[count]; which is traslated to: u32 count; u8 array[0]; but now, python API representation generated by vppapigen contains information about where the array length is stored. * modifies existing response messages to use the new syntax Change-Id: I68210bc7a3a755d03d067e9b79a567f40e2d31f3 Signed-off-by: Marek Gradzki <mgradzki@cisco.com>
Diffstat (limited to 'vpp-api/java/jvpp/gen/jvpp_c_gen.py')
-rw-r--r--vpp-api/java/jvpp/gen/jvpp_c_gen.py23
1 files changed, 21 insertions, 2 deletions
diff --git a/vpp-api/java/jvpp/gen/jvpp_c_gen.py b/vpp-api/java/jvpp/gen/jvpp_c_gen.py
index c006c34103b..0b7fc67d41f 100644
--- a/vpp-api/java/jvpp/gen/jvpp_c_gen.py
+++ b/vpp-api/java/jvpp/gen/jvpp_c_gen.py
@@ -210,7 +210,10 @@ def generate_jni_impl(func_list, inputfile):
for t in zip(f['c_types'], f['args'], f['lengths']):
c_type = t[0]
c_name = t[1]
- field_length = t[2]
+ # variable length arrays do not need special handling in requests,
+ # because the length of Java array is known:
+ field_length = t[2][0]
+
java_field_name = util.underscore_to_camelcase(c_name)
struct_setter_template = struct_setter_templates[c_type]
@@ -241,6 +244,9 @@ default_dto_field_setter_template = Template("""
(*env)->Set${jni_setter}(env, dto, ${java_name}FieldId, mp->${c_name});
""")
+variable_length_array_value_template = Template("""mp->${length_var_name}""")
+variable_length_array_template = Template("""clib_net_to_host_${length_field_type}(${value})""")
+
u16_dto_field_setter_template = Template("""
(*env)->Set${jni_setter}(env, dto, ${java_name}FieldId, clib_net_to_host_u16(mp->${c_name}));
""")
@@ -267,6 +273,8 @@ u32_array_dto_field_setter_template = Template("""
for (_i = 0; _i < ${field_length}; _i++) {
${java_name}ArrayElements[_i] = clib_net_to_host_u32(mp->${c_name}[_i]);
}
+
+ (*env)->ReleaseIntArrayElements(env, ${java_name}, ${java_name}ArrayElements, 0);
(*env)->SetObjectField(env, dto, ${java_name}FieldId, ${java_name});
}
""")
@@ -281,6 +289,8 @@ u64_array_dto_field_setter_template = Template("""
for (_i = 0; _i < ${field_length}; _i++) {
${java_name}ArrayElements[_i] = clib_net_to_host_u64(mp->${c_name}[_i]);
}
+
+ (*env)->ReleaseLongArrayElements(env, ${java_name}, ${java_name}ArrayElements, 0);
(*env)->SetObjectField(env, dto, ${java_name}FieldId, ${java_name});
}
""")
@@ -353,7 +363,16 @@ def generate_msg_handlers(func_list, inputfile):
c_type = t[0]
jni_type = t[1]
c_name = t[2]
- field_length = t[3]
+ field_length = t[3][0]
+
+ # check if we are processing variable length array
+ if t[3][1]:
+ length_var_name = t[3][0]
+ length_field_type = f['c_types'][f['args'].index(length_var_name)]
+ field_length = variable_length_array_value_template.substitute(length_var_name=length_var_name)
+ if length_field_type != 'u8': # we need net to host conversion:
+ field_length = variable_length_array_template.substitute(
+ length_field_type=length_field_type, value=field_length)
# for retval don't generate setters and generate retval check
if util.is_retval_field(c_name):