def generate_dtos(func_list, base_package, plugin_package, plugin_name, dto_package, inputfile): """ Generates dto objects in a dedicated package """ print "Generating DTOs" if not os.path.exists(dto_package): os.mkdir(dto_package) for func in func_list: camel_case_dto_name = util.underscore_to_camelcase_upper(func['name']) camel_case_method_name = util.underscore_to_camelcase(func['name']) dto_path = os.path.join(dto_package, camel_case_dto_name + ".java") if util.is_ignored(func['name']) or util.is_control_ping(camel_case_dto_name): continue fields = generate_dto_fields(camel_case_dto_name, func) methods = generate_dto_base_methods(camel_case_dto_name, func) base_type = "" # Generate request/reply or dump/dumpReply even if structure can be used as notification if not util.is_just_notification(func["name"]): if util.is_reply(camel_case_dto_name): description = "reply DTO" request_dto_name = get_request_name(camel_case_dto_name, func['name']) if util.is_details(camel_case_dto_name): # FIXME assumption that dump calls end with "Dump" suffix. Not enforced in vpe.api base_type += "JVppReply<%s.%s.%s>" % (plugin_package, dto_package, request_dto_name + "Dump") generate_dump_reply_dto(request_dto_name, base_package, plugin_package, dto_package, camel_case_dto_name, camel_case_method_name, func) else: base_type += "JVppReply<%s.%s.%s>" % (plugin_package, dto_package, request_dto_name) else: args = "" if fields is "" else "this" methods += send_template.substitute(method_name=camel_case_method_name, base_package=base_package, plugin_package=plugin_package, plugin_name=plugin_name, args=args) if util.is_dump(camel_case_dto_name): base_type += "JVppDump" description = "dump request DTO" else: base_type += "JVppRequest" description = "request DTO" write_dto_file(base_package, plugin_package, base_type, camel_case_dto_name, description, dto_package, dto_path, fields, func, inputfile, methods) # for structures that are also used as notifications, generate dedicated notification DTO if util.is_notification(func["name"]): base_type = "JVppNotification" description = "notification DTO" camel_case_dto_name = util.add_notification_suffix(camel_case_dto_name) dto_path = os.path.join(dto_package, camel_case_dto_name + ".java") methods = generate_dto_base_methods(camel_case_dto_name, func) write_dto_file(base_package, plugin_package, base_type, camel_case_dto_name, description, dto_package, dto_path, fields, func, inputfile, methods) flush_dump_reply_dtos(inputfile)
def generate_jvpp(func_list, base_package, dto_package, inputfile): """ Generates JVpp interface and JNI implementation """ print "Generating JVpp" methods = [] methods_impl = [] for func in func_list: # Skip structures that are used only as notifications if util.is_just_notification(func['name']) or util.is_ignored(func['name']): continue camel_case_name = util.underscore_to_camelcase(func['name']) camel_case_name_upper = util.underscore_to_camelcase_upper(func['name']) if util.is_reply(camel_case_name): continue if len(func['args']) == 0: methods.append(no_arg_method_template.substitute(name=camel_case_name, base_package=base_package, dto_package=dto_package)) methods_impl.append( no_arg_method_native_template.substitute(name=camel_case_name, base_package=base_package, dto_package=dto_package)) methods_impl.append(no_arg_method_impl_template.substitute(name=camel_case_name, base_package=base_package, dto_package=dto_package)) else: methods.append(method_template.substitute(name=camel_case_name, request=camel_case_name_upper, base_package=base_package, dto_package=dto_package)) methods_impl.append(method_native_template.substitute(name=camel_case_name, request=camel_case_name_upper, base_package=base_package, dto_package=dto_package)) methods_impl.append(method_impl_template.substitute(name=camel_case_name, request=camel_case_name_upper, base_package=base_package, dto_package=dto_package)) jvpp_file = open("JVpp.java", 'w') jvpp_file.write( jvpp_ifc_template.substitute(inputfile=inputfile, methods="\n".join(methods), base_package=base_package, dto_package=dto_package)) jvpp_file.flush() jvpp_file.close() jvpp_file = open("JVppImpl.java", 'w') jvpp_file.write(jvpp_impl_template.substitute(inputfile=inputfile, methods="\n".join(methods_impl), base_package=base_package, dto_package=dto_package)) jvpp_file.flush() jvpp_file.close()
def generate_jvpp(func_list, base_package, plugin_package, plugin_name_underscore, control_ping_class, dto_package, inputfile): """ Generates JVpp interface and JNI implementation """ print "Generating JVpp" plugin_name = util.underscore_to_camelcase_upper(plugin_name_underscore) methods = [] methods_impl = [] for func in func_list: # Skip structures that are used only as notifications if util.is_just_notification(func['name']) or util.is_ignored(func['name']): continue camel_case_name = util.underscore_to_camelcase(func['name']) camel_case_name_upper = util.underscore_to_camelcase_upper(func['name']) if util.is_reply(camel_case_name): continue if len(func['args']) == 0: methods.append(no_arg_method_template.substitute(name=camel_case_name)) methods_impl.append(no_arg_method_native_template.substitute(name=camel_case_name)) methods_impl.append(no_arg_method_impl_template.substitute(name=camel_case_name)) else: methods.append(method_template.substitute(name=camel_case_name, request=camel_case_name_upper, plugin_package=plugin_package, dto_package=dto_package)) methods_impl.append(method_native_template.substitute(name=camel_case_name, request=camel_case_name_upper, plugin_package=plugin_package, dto_package=dto_package)) methods_impl.append(method_impl_template.substitute(name=camel_case_name, request=camel_case_name_upper, plugin_package=plugin_package, dto_package=dto_package)) jvpp_file = open("JVpp%s.java" % plugin_name, 'w') jvpp_file.write( jvpp_ifc_template.substitute(inputfile=inputfile, methods="\n".join(methods), base_package=base_package, plugin_package=plugin_package, plugin_name=plugin_name, dto_package=dto_package)) jvpp_file.flush() jvpp_file.close() jvpp_file = open("JVpp%sImpl.java" % plugin_name, 'w') jvpp_file.write(jvpp_impl_template.substitute(inputfile=inputfile, methods="\n".join(methods_impl), base_package=base_package, plugin_package=plugin_package, plugin_name=plugin_name, plugin_name_underscore=plugin_name_underscore, dto_package=dto_package, control_ping_class=control_ping_class)) jvpp_file.flush() jvpp_file.close()
def generate_jni_impl(func_list, plugin_name, inputfile): jni_impl = [] for f in func_list: f_name = f['name'] camel_case_function_name = util.underscore_to_camelcase(f_name) if is_manually_generated(f_name, plugin_name) or util.is_reply(camel_case_function_name) \ or util.is_ignored(f_name) or util.is_just_notification(f_name): continue arguments = '' request_class = '' jni_identifiers = '' msg_initialization = '' f_name_uppercase = f_name.upper() msg_size = 'sizeof(*mp)' if f['args']: arguments = ', jobject request' camel_case_function_name_upper = util.underscore_to_camelcase_upper(f_name) request_class = request_class_template.substitute( java_name_upper=camel_case_function_name_upper, plugin_name=plugin_name) for t in zip(f['types'], f['args'], f['lengths'], f['arg_types']): field_name = util.underscore_to_camelcase(t[1]) is_variable_len_array = t[2][1] if is_variable_len_array: msg_size += jni_msg_size_template.substitute(array_length=util.underscore_to_camelcase(t[2][0]), element_type=t[3]) jni_identifiers += jni_gen.jni_request_identifiers_for_type(field_type=t[0], field_reference_name=field_name, field_name=field_name) msg_initialization += jni_gen.jni_request_binding_for_type(field_type=t[0], c_name=t[1], field_reference_name=field_name, field_length=t[2][0], is_variable_len_array=is_variable_len_array) jni_impl.append(jni_impl_template.substitute( inputfile=inputfile, api_data=util.api_message_to_javadoc(f), field_reference_name=camel_case_function_name, field_name=camel_case_function_name, c_name_uppercase=f_name_uppercase, c_name=f_name, crc=f['crc'], plugin_name=plugin_name, java_plugin_name=plugin_name.title(), request_class=request_class, jni_identifiers=jni_identifiers, msg_size=msg_size, msg_initialization=msg_initialization, args=arguments)) return "\n".join(jni_impl)
def generate_jni_impl(func_list, inputfile): jni_impl = [] for f in func_list: f_name = f['name'] camel_case_function_name = util.underscore_to_camelcase(f_name) if is_manually_generated(f_name) or util.is_reply(camel_case_function_name) \ or util.is_ignored(f_name) or util.is_just_notification(f_name): continue arguments = '' request_class = '' field_identifiers = '' struct_setters = '' f_name_uppercase = f_name.upper() if f['args']: arguments = ', jobject request' camel_case_function_name_upper = util.underscore_to_camelcase_upper(f_name) request_class = request_class_template.substitute(java_name_upper=camel_case_function_name_upper) # field identifiers for t in zip(f['types'], f['args']): jni_type = t[0] java_field_name = util.underscore_to_camelcase(t[1]) jni_signature = util.jni_2_signature_mapping[jni_type] jni_getter = util.jni_field_accessors[jni_type] field_identifiers += request_field_identifier_template.substitute( jni_type=jni_type, java_name=java_field_name, jni_signature=jni_signature, jni_getter=jni_getter) # field setters for t in zip(f['c_types'], f['args'], f['lengths']): c_type = t[0] c_name = t[1] field_length = t[2][0] # check if we are processing variable length array: if t[2][1]: field_length = util.underscore_to_camelcase(t[2][0]) java_field_name = util.underscore_to_camelcase(c_name) struct_setter_template = struct_setter_templates[c_type] struct_setters += struct_setter_template.substitute( c_name=c_name, java_name=java_field_name, field_length=field_length) jni_impl.append(jni_impl_template.substitute( inputfile=inputfile, api_data=util.api_message_to_javadoc(f), java_name=camel_case_function_name, c_name_uppercase=f_name_uppercase, c_name=f_name, request_class=request_class, field_identifiers=field_identifiers, struct_setters=struct_setters, args=arguments)) return "\n".join(jni_impl)
def generate_jni_impl(func_list, plugin_name, inputfile): jni_impl = [] for f in func_list: f_name = f['name'] camel_case_function_name = util.underscore_to_camelcase(f_name) if is_manually_generated(f_name, plugin_name) or util.is_reply(camel_case_function_name) \ or util.is_ignored(f_name) or util.is_just_notification(f_name): continue arguments = '' request_class = '' field_identifiers = '' struct_setters = '' f_name_uppercase = f_name.upper() if f['args']: arguments = ', jobject request' camel_case_function_name_upper = util.underscore_to_camelcase_upper( f_name) request_class = request_class_template.substitute( java_name_upper=camel_case_function_name_upper, plugin_name=plugin_name) # field identifiers for t in zip(f['types'], f['args']): jni_type = t[0] java_field_name = util.underscore_to_camelcase(t[1]) jni_signature = util.jni_2_signature_mapping[jni_type] jni_getter = util.jni_field_accessors[jni_type] field_identifiers += request_field_identifier_template.substitute( jni_type=jni_type, java_name=java_field_name, jni_signature=jni_signature, jni_getter=jni_getter) # field setters for t in zip(f['c_types'], f['args'], f['lengths']): c_type = t[0] c_name = t[1] field_length = t[2][0] # check if we are processing variable length array: if t[2][1]: field_length = util.underscore_to_camelcase(t[2][0]) java_field_name = util.underscore_to_camelcase(c_name) struct_setter_template = struct_setter_templates[c_type] struct_setters += struct_setter_template.substitute( c_name=c_name, java_name=java_field_name, field_length=field_length) jni_impl.append( jni_impl_template.substitute( inputfile=inputfile, api_data=util.api_message_to_javadoc(f), java_name=camel_case_function_name, c_name_uppercase=f_name_uppercase, c_name=f_name, plugin_name=plugin_name, java_plugin_name=plugin_name.title(), request_class=request_class, field_identifiers=field_identifiers, struct_setters=struct_setters, args=arguments)) return "\n".join(jni_impl)
def generate_dtos(func_list, base_package, dto_package, inputfile): """ Generates dto objects in a dedicated package """ print "Generating DTOs" if not os.path.exists(dto_package): raise Exception("%s folder is missing" % dto_package) for func in func_list: camel_case_dto_name = util.underscore_to_camelcase_upper(func['name']) camel_case_method_name = util.underscore_to_camelcase(func['name']) dto_path = os.path.join(dto_package, camel_case_dto_name + ".java") if util.is_ignored(func['name']): continue fields = "" for t in zip(func['types'], func['args']): # for retval don't generate dto field in Reply field_name = util.underscore_to_camelcase(t[1]) if util.is_reply(camel_case_dto_name) and util.is_retval_field(field_name): continue fields += field_template.substitute(type=util.jni_2_java_type_mapping[t[0]], name=field_name) methods = "" base_type = "" # Generate request/reply or dump/dumpReply even if structure can be used as notification if not util.is_just_notification(func["name"]): if util.is_reply(camel_case_dto_name): description = "vpe.api reply DTO" request_dto_name = get_request_name(camel_case_dto_name, func['name']) if util.is_details(camel_case_dto_name): # FIXME assumption that dump calls end with "Dump" suffix. Not enforced in vpe.api base_type += "JVppReply<%s.%s.%s>" % (base_package, dto_package, request_dto_name + "Dump") generate_dump_reply_dto(request_dto_name, base_package, dto_package, camel_case_dto_name, camel_case_method_name, func) else: base_type += "JVppReply<%s.%s.%s>" % (base_package, dto_package, request_dto_name) else: args = "" if fields is "" else "this" methods = send_template.substitute(method_name=camel_case_method_name, base_package=base_package, args=args) if util.is_dump(camel_case_dto_name): base_type += "JVppDump" description = "vpe.api dump request DTO" else: base_type += "JVppRequest" description = "vpe.api request DTO" write_dto_file(base_package, base_type, camel_case_dto_name, description, dto_package, dto_path, fields, func, inputfile, methods) # for structures that are also used as notifications, generate dedicated notification DTO if util.is_notification(func["name"]): base_type = "JVppNotification" description = "vpe.api notification DTO" camel_case_dto_name = util.add_notification_suffix(camel_case_dto_name) methods = "" dto_path = os.path.join(dto_package, camel_case_dto_name + ".java") write_dto_file(base_package, base_type, camel_case_dto_name, description, dto_package, dto_path, fields, func, inputfile, methods) flush_dump_reply_dtos(inputfile)