Marek Gradzki | d85036f | 2016-04-26 12:09:05 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # |
| 3 | # Copyright (c) 2016 Cisco and/or its affiliates. |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at: |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # l |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | # |
| 16 | |
| 17 | import os, util |
| 18 | from string import Template |
| 19 | |
| 20 | def is_manually_generated(f_name): |
| 21 | return f_name in {'control_ping_reply'} |
| 22 | |
Marek Gradzki | 0aaf92f | 2016-05-03 17:05:27 +0200 | [diff] [blame] | 23 | |
| 24 | class_reference_template = Template("""jclass ${ref_name}Class; |
| 25 | """) |
| 26 | |
| 27 | find_class_invocation_template = Template(""" |
| 28 | ${ref_name}Class = (jclass)(*env)->NewGlobalRef(env, (*env)->FindClass(env, "org/openvpp/jvpp/dto/${class_name}")); |
| 29 | if ((*env)->ExceptionCheck(env)) { |
| 30 | (*env)->ExceptionDescribe(env); |
| 31 | return JNI_ERR; |
| 32 | }""") |
| 33 | |
| 34 | class_cache_template = Template(""" |
| 35 | $class_references |
| 36 | static int cache_class_references(JNIEnv* env) { |
| 37 | $find_class_invocations |
| 38 | return 0; |
| 39 | }""") |
| 40 | |
| 41 | def generate_class_cache(func_list): |
| 42 | class_references = [] |
| 43 | find_class_invocations = [] |
| 44 | for f in func_list: |
| 45 | c_name = f['name'] |
| 46 | class_name = util.underscore_to_camelcase_upper(c_name) |
| 47 | ref_name = util.underscore_to_camelcase(c_name) |
| 48 | |
| 49 | if not util.is_reply(class_name) or util.is_ignored(c_name) or util.is_notification(c_name): |
| 50 | # TODO handle notifications |
| 51 | continue |
| 52 | |
| 53 | class_references.append(class_reference_template.substitute( |
| 54 | ref_name=ref_name)) |
| 55 | |
| 56 | find_class_invocations.append(find_class_invocation_template.substitute( |
| 57 | ref_name=ref_name, |
| 58 | class_name=class_name)) |
| 59 | |
| 60 | return class_cache_template.substitute( |
| 61 | class_references="".join(class_references), find_class_invocations="".join(find_class_invocations)) |
| 62 | |
| 63 | |
| 64 | # TODO: cache method and field identifiers to achieve better performance |
Marek Gradzki | d85036f | 2016-04-26 12:09:05 +0200 | [diff] [blame] | 65 | # https://jira.fd.io/browse/HONEYCOMB-42 |
| 66 | request_class_template = Template(""" |
| 67 | jclass requestClass = (*env)->FindClass(env, "org/openvpp/jvpp/dto/${java_name_upper}");""") |
| 68 | |
| 69 | request_field_identifier_template = Template(""" |
| 70 | jfieldID ${java_name}FieldId = (*env)->GetFieldID(env, requestClass, "${java_name}", "${jni_signature}"); |
| 71 | ${jni_type} ${java_name} = (*env)->Get${jni_getter}(env, request, ${java_name}FieldId); |
| 72 | """) |
| 73 | |
| 74 | u8_struct_setter_template = Template(""" |
| 75 | mp->${c_name} = ${java_name};""") |
| 76 | |
| 77 | u16_struct_setter_template = Template(""" |
| 78 | mp->${c_name} = clib_host_to_net_u16(${java_name});""") |
| 79 | |
| 80 | u32_struct_setter_template = Template(""" |
| 81 | mp->${c_name} = clib_host_to_net_u32(${java_name});""") |
| 82 | |
| 83 | i32_struct_setter_template = Template(""" |
| 84 | mp->${c_name} = clib_host_to_net_i32(${java_name});!""") |
| 85 | |
| 86 | u64_struct_setter_template = Template(""" |
| 87 | mp->${c_name} = clib_host_to_net_u64(${java_name});""") |
| 88 | |
| 89 | u8_array_struct_setter_template = Template(""" |
| 90 | { |
| 91 | jsize cnt = (*env)->GetArrayLength (env, ${java_name}); |
Marek Gradzki | c4cb44c | 2016-05-24 13:32:26 +0200 | [diff] [blame] | 92 | size_t max_size = ${field_length}; |
| 93 | if (max_size != 0 && cnt > max_size) cnt = max_size; |
Marek Gradzki | d85036f | 2016-04-26 12:09:05 +0200 | [diff] [blame] | 94 | (*env)->GetByteArrayRegion(env, ${java_name}, 0, cnt, (jbyte *)mp->${c_name}); |
| 95 | } |
| 96 | """) |
| 97 | |
| 98 | u32_array_struct_setter_template = Template(""" |
| 99 | jint * ${java_name}ArrayElements = (*env)->GetIntArrayElements(env, ${java_name}, NULL); |
| 100 | { |
Marek Gradzki | c4cb44c | 2016-05-24 13:32:26 +0200 | [diff] [blame] | 101 | size_t _i; |
| 102 | jsize cnt = (*env)->GetArrayLength (env, ${java_name}); |
| 103 | size_t max_size = ${field_length}; |
| 104 | if (max_size != 0 && cnt > max_size) cnt = max_size; |
| 105 | for (_i = 0; _i < cnt; _i++) { |
Marek Gradzki | d85036f | 2016-04-26 12:09:05 +0200 | [diff] [blame] | 106 | mp->${c_name}[_i] = clib_host_to_net_u32(${java_name}ArrayElements[_i]); |
| 107 | } |
| 108 | } |
| 109 | (*env)->ReleaseIntArrayElements (env, ${java_name}, ${java_name}ArrayElements, 0); |
| 110 | """) |
| 111 | |
| 112 | vl_api_ip4_fib_counter_t_array_struct_setter_template = Template(""" |
| 113 | // vl_api_ip4_fib_counter_t_array_field_setter_template FIXME""") |
| 114 | |
| 115 | vl_api_ip6_fib_counter_t_array_struct_setter_template = Template(""" |
| 116 | // vl_api_ip6_fib_counter_t_array_field_setter_template FIXME""") |
| 117 | |
| 118 | struct_setter_templates = {'u8': u8_struct_setter_template, |
Marek Gradzki | 34e7772 | 2016-05-30 21:52:37 +0200 | [diff] [blame] | 119 | 'u16': u16_struct_setter_template, |
Marek Gradzki | d85036f | 2016-04-26 12:09:05 +0200 | [diff] [blame] | 120 | 'u32': u32_struct_setter_template, |
| 121 | 'i32': u32_struct_setter_template, |
| 122 | 'u64': u64_struct_setter_template, |
| 123 | 'u8[]': u8_array_struct_setter_template, |
| 124 | 'u32[]': u32_array_struct_setter_template, |
| 125 | 'vl_api_ip4_fib_counter_t[]': vl_api_ip4_fib_counter_t_array_struct_setter_template, |
| 126 | 'vl_api_ip6_fib_counter_t[]': vl_api_ip6_fib_counter_t_array_struct_setter_template |
| 127 | } |
| 128 | |
| 129 | jni_impl_template = Template(""" |
| 130 | /** |
| 131 | * JNI binding for sending ${c_name} vpe.api message. |
| 132 | * Generated based on $inputfile preparsed data: |
| 133 | $api_data |
| 134 | */ |
| 135 | JNIEXPORT jint JNICALL Java_org_openvpp_jvpp_JVppImpl_${java_name}0 |
| 136 | (JNIEnv * env, jclass clazz$args) { |
| 137 | vppjni_main_t *jm = &vppjni_main; |
| 138 | vl_api_${c_name}_t * mp; |
| 139 | u32 my_context_id; |
| 140 | int rv; |
| 141 | rv = vppjni_sanity_check (jm); |
| 142 | if (rv) return rv; |
| 143 | my_context_id = vppjni_get_context_id (jm); |
| 144 | $request_class |
| 145 | $field_identifiers |
| 146 | M(${c_name_uppercase}, ${c_name}); |
| 147 | mp->context = clib_host_to_net_u32 (my_context_id); |
| 148 | $struct_setters |
| 149 | S; |
| 150 | return my_context_id; |
| 151 | }""") |
| 152 | |
| 153 | def generate_jni_impl(func_list, inputfile): |
| 154 | jni_impl = [] |
| 155 | for f in func_list: |
| 156 | f_name = f['name'] |
| 157 | camel_case_function_name = util.underscore_to_camelcase(f_name) |
| 158 | if is_manually_generated(f_name) or util.is_reply(camel_case_function_name) \ |
| 159 | or util.is_ignored(f_name) or util.is_notification(f_name): |
| 160 | continue |
| 161 | |
| 162 | arguments = '' |
| 163 | request_class = '' |
| 164 | field_identifiers = '' |
| 165 | struct_setters = '' |
| 166 | f_name_uppercase = f_name.upper() |
| 167 | |
| 168 | if f['args']: |
| 169 | arguments = ', jobject request' |
| 170 | camel_case_function_name_upper = util.underscore_to_camelcase_upper(f_name) |
| 171 | |
| 172 | request_class = request_class_template.substitute(java_name_upper=camel_case_function_name_upper) |
| 173 | |
| 174 | # field identifiers |
| 175 | for t in zip(f['types'], f['args']): |
| 176 | jni_type = t[0] |
| 177 | java_field_name = util.underscore_to_camelcase(t[1]) |
| 178 | jni_signature = util.jni_2_signature_mapping[jni_type] |
| 179 | jni_getter = util.jni_field_accessors[jni_type] |
| 180 | field_identifiers += request_field_identifier_template.substitute( |
| 181 | jni_type=jni_type, |
| 182 | java_name=java_field_name, |
| 183 | jni_signature=jni_signature, |
| 184 | jni_getter=jni_getter) |
| 185 | |
| 186 | # field setters |
Marek Gradzki | c4cb44c | 2016-05-24 13:32:26 +0200 | [diff] [blame] | 187 | for t in zip(f['c_types'], f['args'], f['lengths']): |
Marek Gradzki | d85036f | 2016-04-26 12:09:05 +0200 | [diff] [blame] | 188 | c_type = t[0] |
| 189 | c_name = t[1] |
Marek Gradzki | c4cb44c | 2016-05-24 13:32:26 +0200 | [diff] [blame] | 190 | field_length = t[2] |
Marek Gradzki | d85036f | 2016-04-26 12:09:05 +0200 | [diff] [blame] | 191 | java_field_name = util.underscore_to_camelcase(c_name) |
| 192 | |
| 193 | struct_setter_template = struct_setter_templates[c_type] |
| 194 | |
| 195 | struct_setters += struct_setter_template.substitute( |
| 196 | c_name=c_name, |
Marek Gradzki | c4cb44c | 2016-05-24 13:32:26 +0200 | [diff] [blame] | 197 | java_name=java_field_name, |
| 198 | field_length=field_length) |
Marek Gradzki | d85036f | 2016-04-26 12:09:05 +0200 | [diff] [blame] | 199 | |
| 200 | jni_impl.append(jni_impl_template.substitute( |
| 201 | inputfile=inputfile, |
| 202 | api_data=util.api_message_to_javadoc(f), |
| 203 | java_name=camel_case_function_name, |
| 204 | c_name_uppercase=f_name_uppercase, |
| 205 | c_name=f_name, |
| 206 | request_class=request_class, |
| 207 | field_identifiers=field_identifiers, |
| 208 | struct_setters=struct_setters, |
| 209 | args=arguments)) |
| 210 | |
| 211 | return "\n".join(jni_impl) |
| 212 | |
| 213 | |
| 214 | dto_field_id_template = Template(""" |
Marek Gradzki | 0aaf92f | 2016-05-03 17:05:27 +0200 | [diff] [blame] | 215 | jfieldID ${java_name}FieldId = (*env)->GetFieldID(env, ${class_ref_name}Class, "${java_name}", "${jni_signature}");""") |
Marek Gradzki | d85036f | 2016-04-26 12:09:05 +0200 | [diff] [blame] | 216 | |
| 217 | default_dto_field_setter_template = Template(""" |
| 218 | (*env)->Set${jni_setter}(env, dto, ${java_name}FieldId, mp->${c_name}); |
| 219 | """) |
| 220 | |
Marek Gradzki | 34e7772 | 2016-05-30 21:52:37 +0200 | [diff] [blame] | 221 | u16_dto_field_setter_template = Template(""" |
| 222 | (*env)->Set${jni_setter}(env, dto, ${java_name}FieldId, clib_net_to_host_u16(mp->${c_name})); |
| 223 | """) |
| 224 | |
Marek Gradzki | d85036f | 2016-04-26 12:09:05 +0200 | [diff] [blame] | 225 | u32_dto_field_setter_template = Template(""" |
| 226 | (*env)->Set${jni_setter}(env, dto, ${java_name}FieldId, clib_net_to_host_u32(mp->${c_name})); |
| 227 | """) |
| 228 | |
| 229 | u64_dto_field_setter_template = Template(""" |
| 230 | (*env)->Set${jni_setter}(env, dto, ${java_name}FieldId, clib_net_to_host_u64(mp->${c_name})); |
| 231 | """) |
| 232 | |
| 233 | u8_array_dto_field_setter_template = Template(""" |
Marek Gradzki | c4cb44c | 2016-05-24 13:32:26 +0200 | [diff] [blame] | 234 | jbyteArray ${java_name} = (*env)->NewByteArray(env, ${field_length}); |
| 235 | (*env)->SetByteArrayRegion(env, ${java_name}, 0, ${field_length}, (const jbyte*)mp->${c_name}); |
Marek Gradzki | d85036f | 2016-04-26 12:09:05 +0200 | [diff] [blame] | 236 | (*env)->SetObjectField(env, dto, ${java_name}FieldId, ${java_name}); |
| 237 | """) |
| 238 | |
Marek Gradzki | 97d9951 | 2016-06-06 12:36:09 +0200 | [diff] [blame^] | 239 | u32_array_dto_field_setter_template = Template(""" |
| 240 | { |
| 241 | jintArray ${java_name} = (*env)->NewIntArray(env, ${field_length}); |
| 242 | jint * ${java_name}ArrayElements = (*env)->GetIntArrayElements(env, ${java_name}, NULL); |
| 243 | unsigned int _i; |
| 244 | for (_i = 0; _i < ${field_length}; _i++) { |
| 245 | ${java_name}ArrayElements[_i] = clib_net_to_host_u32(mp->${c_name}[_i]); |
| 246 | } |
| 247 | (*env)->SetObjectField(env, dto, ${java_name}FieldId, ${java_name}); |
| 248 | } |
| 249 | """) |
| 250 | |
Marek Gradzki | d85036f | 2016-04-26 12:09:05 +0200 | [diff] [blame] | 251 | # For each u64 array we get its elements. Then we convert values to host byte order. |
Marek Gradzki | 97d9951 | 2016-06-06 12:36:09 +0200 | [diff] [blame^] | 252 | # All changes to jlong* buffer are written to jlongArray (isCopy is set to NULL) |
Marek Gradzki | d85036f | 2016-04-26 12:09:05 +0200 | [diff] [blame] | 253 | u64_array_dto_field_setter_template = Template(""" |
Marek Gradzki | d85036f | 2016-04-26 12:09:05 +0200 | [diff] [blame] | 254 | { |
Marek Gradzki | c4cb44c | 2016-05-24 13:32:26 +0200 | [diff] [blame] | 255 | jlongArray ${java_name} = (*env)->NewLongArray(env, ${field_length}); |
Marek Gradzki | d85036f | 2016-04-26 12:09:05 +0200 | [diff] [blame] | 256 | jlong * ${java_name}ArrayElements = (*env)->GetLongArrayElements(env, ${java_name}, NULL); |
Marek Gradzki | c4cb44c | 2016-05-24 13:32:26 +0200 | [diff] [blame] | 257 | unsigned int _i; |
| 258 | for (_i = 0; _i < ${field_length}; _i++) { |
Marek Gradzki | d85036f | 2016-04-26 12:09:05 +0200 | [diff] [blame] | 259 | ${java_name}ArrayElements[_i] = clib_net_to_host_u64(mp->${c_name}[_i]); |
| 260 | } |
Marek Gradzki | c4cb44c | 2016-05-24 13:32:26 +0200 | [diff] [blame] | 261 | (*env)->SetObjectField(env, dto, ${java_name}FieldId, ${java_name}); |
Marek Gradzki | d85036f | 2016-04-26 12:09:05 +0200 | [diff] [blame] | 262 | } |
Marek Gradzki | d85036f | 2016-04-26 12:09:05 +0200 | [diff] [blame] | 263 | """) |
| 264 | |
| 265 | dto_field_setter_templates = {'u8': default_dto_field_setter_template, |
Marek Gradzki | 34e7772 | 2016-05-30 21:52:37 +0200 | [diff] [blame] | 266 | 'u16': u16_dto_field_setter_template, |
Marek Gradzki | d85036f | 2016-04-26 12:09:05 +0200 | [diff] [blame] | 267 | 'u32': u32_dto_field_setter_template, |
| 268 | 'i32': u32_dto_field_setter_template, |
| 269 | 'u64': u64_dto_field_setter_template, |
Marek Gradzki | 34e7772 | 2016-05-30 21:52:37 +0200 | [diff] [blame] | 270 | 'f64': default_dto_field_setter_template, #fixme |
Marek Gradzki | 97d9951 | 2016-06-06 12:36:09 +0200 | [diff] [blame^] | 271 | 'u8[]': u8_array_dto_field_setter_template, |
| 272 | 'u32[]': u32_array_dto_field_setter_template, |
| 273 | 'u64[]': u64_array_dto_field_setter_template |
Marek Gradzki | d85036f | 2016-04-26 12:09:05 +0200 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | msg_handler_template = Template(""" |
| 277 | /** |
| 278 | * Handler for ${handler_name} vpe.api message. |
| 279 | * Generated based on $inputfile preparsed data: |
| 280 | $api_data |
| 281 | */ |
| 282 | static void vl_api_${handler_name}_t_handler (vl_api_${handler_name}_t * mp) |
| 283 | { |
| 284 | vppjni_main_t * jm = &vppjni_main; |
| 285 | JNIEnv *env = jm->jenv; |
| 286 | |
Marek Gradzki | 0aaf92f | 2016-05-03 17:05:27 +0200 | [diff] [blame] | 287 | jmethodID constructor = (*env)->GetMethodID(env, ${class_ref_name}Class, "<init>", "()V"); |
Marek Gradzki | d85036f | 2016-04-26 12:09:05 +0200 | [diff] [blame] | 288 | jmethodID callbackMethod = (*env)->GetMethodID(env, jm->callbackClass, "on${dto_name}", "(Lorg/openvpp/jvpp/dto/${dto_name};)V"); |
| 289 | |
Marek Gradzki | 0aaf92f | 2016-05-03 17:05:27 +0200 | [diff] [blame] | 290 | jobject dto = (*env)->NewObject(env, ${class_ref_name}Class, constructor); |
Marek Gradzki | d85036f | 2016-04-26 12:09:05 +0200 | [diff] [blame] | 291 | $dto_setters |
| 292 | (*env)->CallVoidMethod(env, jm->callback, callbackMethod, dto); |
| 293 | }""") |
| 294 | |
| 295 | def generate_msg_handlers(func_list, inputfile): |
| 296 | handlers = [] |
| 297 | for f in func_list: |
| 298 | handler_name = f['name'] |
| 299 | dto_name = util.underscore_to_camelcase_upper(handler_name) |
Marek Gradzki | 0aaf92f | 2016-05-03 17:05:27 +0200 | [diff] [blame] | 300 | ref_name = util.underscore_to_camelcase(handler_name) |
Marek Gradzki | d85036f | 2016-04-26 12:09:05 +0200 | [diff] [blame] | 301 | |
| 302 | if is_manually_generated(handler_name) or not util.is_reply(dto_name) or util.is_ignored(handler_name) or util.is_notification(handler_name): |
| 303 | # TODO handle notifications |
| 304 | continue |
| 305 | |
| 306 | dto_setters = '' |
| 307 | # dto setters |
Marek Gradzki | c4cb44c | 2016-05-24 13:32:26 +0200 | [diff] [blame] | 308 | for t in zip(f['c_types'], f['types'], f['args'], f['lengths']): |
Marek Gradzki | d85036f | 2016-04-26 12:09:05 +0200 | [diff] [blame] | 309 | c_type = t[0] |
| 310 | jni_type = t[1] |
| 311 | c_name = t[2] |
Marek Gradzki | c4cb44c | 2016-05-24 13:32:26 +0200 | [diff] [blame] | 312 | field_length = t[3] |
Marek Gradzki | d85036f | 2016-04-26 12:09:05 +0200 | [diff] [blame] | 313 | |
| 314 | java_field_name = util.underscore_to_camelcase(c_name) |
| 315 | jni_signature = util.jni_2_signature_mapping[jni_type] |
| 316 | jni_setter = util.jni_field_accessors[jni_type] |
| 317 | |
| 318 | dto_setters += dto_field_id_template.substitute( |
| 319 | java_name=java_field_name, |
Marek Gradzki | 0aaf92f | 2016-05-03 17:05:27 +0200 | [diff] [blame] | 320 | class_ref_name=ref_name, |
Marek Gradzki | d85036f | 2016-04-26 12:09:05 +0200 | [diff] [blame] | 321 | jni_signature=jni_signature) |
| 322 | |
| 323 | dto_setter_template = dto_field_setter_templates[c_type] |
| 324 | |
| 325 | dto_setters += dto_setter_template.substitute( |
| 326 | java_name=java_field_name, |
| 327 | jni_signature=jni_signature, |
| 328 | c_name=c_name, |
Marek Gradzki | c4cb44c | 2016-05-24 13:32:26 +0200 | [diff] [blame] | 329 | jni_setter=jni_setter, |
| 330 | field_length=field_length) |
Marek Gradzki | d85036f | 2016-04-26 12:09:05 +0200 | [diff] [blame] | 331 | |
| 332 | handlers.append(msg_handler_template.substitute( |
| 333 | inputfile=inputfile, |
| 334 | api_data=util.api_message_to_javadoc(f), |
| 335 | handler_name=handler_name, |
| 336 | dto_name=dto_name, |
Marek Gradzki | 0aaf92f | 2016-05-03 17:05:27 +0200 | [diff] [blame] | 337 | class_ref_name=ref_name, |
Marek Gradzki | d85036f | 2016-04-26 12:09:05 +0200 | [diff] [blame] | 338 | dto_setters=dto_setters)) |
| 339 | |
| 340 | return "\n".join(handlers) |
| 341 | |
| 342 | |
| 343 | handler_registration_template = Template("""_(${upercase_name}, ${name}) \\ |
| 344 | """) |
| 345 | |
| 346 | |
| 347 | def generate_handler_registration(func_list): |
| 348 | handler_registration = ["#define foreach_vpe_api_msg \\\n"] |
| 349 | for f in func_list: |
| 350 | name = f['name'] |
| 351 | camelcase_name = util.underscore_to_camelcase(f['name']) |
| 352 | |
| 353 | if not util.is_reply(camelcase_name) or util.is_ignored(name) or util.is_notification(name): |
| 354 | # TODO handle notifications |
| 355 | continue |
| 356 | |
| 357 | handler_registration.append(handler_registration_template.substitute( |
| 358 | name=name, |
| 359 | upercase_name=name.upper())) |
| 360 | |
| 361 | return "".join(handler_registration) |
| 362 | |
Marek Gradzki | 0aaf92f | 2016-05-03 17:05:27 +0200 | [diff] [blame] | 363 | |
| 364 | jvpp_c_template = Template("""/** |
Marek Gradzki | d85036f | 2016-04-26 12:09:05 +0200 | [diff] [blame] | 365 | * This file contains JNI bindings for jvpp Java API. |
| 366 | * It was generated by jvpp_c_gen.py based on $inputfile |
| 367 | * (python representation of vpe.api generated by vppapigen). |
| 368 | */ |
| 369 | |
Marek Gradzki | 0aaf92f | 2016-05-03 17:05:27 +0200 | [diff] [blame] | 370 | // JAVA class reference cache |
| 371 | $class_cache |
| 372 | |
Marek Gradzki | d85036f | 2016-04-26 12:09:05 +0200 | [diff] [blame] | 373 | // JNI bindings |
| 374 | $jni_implementations |
| 375 | |
| 376 | // Message handlers |
| 377 | $msg_handlers |
| 378 | |
| 379 | // Registration of message handlers in vlib |
| 380 | $handler_registration |
| 381 | """) |
| 382 | |
| 383 | def generate_jvpp(func_list, inputfile): |
| 384 | """ Generates jvpp C file """ |
| 385 | print "Generating jvpp C" |
| 386 | |
Marek Gradzki | 0aaf92f | 2016-05-03 17:05:27 +0200 | [diff] [blame] | 387 | class_cache = generate_class_cache(func_list) |
Marek Gradzki | d85036f | 2016-04-26 12:09:05 +0200 | [diff] [blame] | 388 | jni_impl = generate_jni_impl(func_list, inputfile) |
| 389 | msg_handlers = generate_msg_handlers(func_list, inputfile) |
| 390 | handler_registration = generate_handler_registration(func_list) |
| 391 | |
| 392 | jvpp_c_file = open("jvpp_gen.h", 'w') |
| 393 | jvpp_c_file.write(jvpp_c_template.substitute( |
| 394 | inputfile=inputfile, |
Marek Gradzki | 0aaf92f | 2016-05-03 17:05:27 +0200 | [diff] [blame] | 395 | class_cache=class_cache, |
Marek Gradzki | d85036f | 2016-04-26 12:09:05 +0200 | [diff] [blame] | 396 | jni_implementations=jni_impl, |
| 397 | msg_handlers=msg_handlers, |
| 398 | handler_registration=handler_registration)) |
| 399 | jvpp_c_file.flush() |
| 400 | jvpp_c_file.close() |
| 401 | |
| 402 | |