diff options
Diffstat (limited to 'src/vpp-api/java/jvpp/gen')
-rw-r--r-- | src/vpp-api/java/jvpp/gen/jvppgen/callback_gen.py | 5 | ||||
-rw-r--r-- | src/vpp-api/java/jvpp/gen/jvppgen/dto_gen.py | 57 | ||||
-rw-r--r-- | src/vpp-api/java/jvpp/gen/jvppgen/jvpp_c_gen.py | 25 | ||||
-rw-r--r-- | src/vpp-api/java/jvpp/gen/jvppgen/jvpp_callback_facade_gen.py | 28 | ||||
-rw-r--r-- | src/vpp-api/java/jvpp/gen/jvppgen/jvpp_future_facade_gen.py | 153 | ||||
-rw-r--r-- | src/vpp-api/java/jvpp/gen/jvppgen/notification_gen.py | 11 | ||||
-rw-r--r-- | src/vpp-api/java/jvpp/gen/jvppgen/util.py | 37 |
7 files changed, 175 insertions, 141 deletions
diff --git a/src/vpp-api/java/jvpp/gen/jvppgen/callback_gen.py b/src/vpp-api/java/jvpp/gen/jvppgen/callback_gen.py index e1c31dd6661..f0462158b9e 100644 --- a/src/vpp-api/java/jvpp/gen/jvppgen/callback_gen.py +++ b/src/vpp-api/java/jvpp/gen/jvppgen/callback_gen.py @@ -58,14 +58,15 @@ def generate_callbacks(func_list, base_package, plugin_package, plugin_name, cal callbacks = [] for func in func_list: - camel_case_name_with_suffix = util.underscore_to_camelcase_upper(func['name']) if util.is_control_ping(camel_case_name_with_suffix): + # Skip control_ping managed by jvpp registry. continue - if not util.is_reply(camel_case_name_with_suffix) and not util.is_notification(func['name']): + if util.is_dump(func['name']) or util.is_request(func['name'], func_list): continue + # Generate callbacks for all messages except for dumps and requests (handled by vpp, not client). callback_type = "JVppCallback" callbacks.append("{0}.{1}.{2}".format(plugin_package, callback_package, camel_case_name_with_suffix + callback_suffix)) callback_path = os.path.join(callback_package, camel_case_name_with_suffix + callback_suffix + ".java") diff --git a/src/vpp-api/java/jvpp/gen/jvppgen/dto_gen.py b/src/vpp-api/java/jvpp/gen/jvppgen/dto_gen.py index 8126912230b..158e26ef59f 100644 --- a/src/vpp-api/java/jvpp/gen/jvppgen/dto_gen.py +++ b/src/vpp-api/java/jvpp/gen/jvppgen/dto_gen.py @@ -79,41 +79,34 @@ def generate_dtos(func_list, base_package, plugin_package, plugin_name, dto_pack 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_notification(func["name"]): - if util.is_reply(camel_case_dto_name): - description = "reply DTO" - request_dto_name = util.remove_reply_suffix(camel_case_dto_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) + if util.is_reply(camel_case_dto_name): + description = "reply DTO" + request_dto_name = util.remove_reply_suffix(camel_case_dto_name) + if util.is_details(camel_case_dto_name): + 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: - 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) + base_type += "JVppReply<%s.%s.%s>" % (plugin_package, dto_package, request_dto_name) + elif util.is_dump(camel_case_dto_name) or util.is_request(func['name'], func_list): + 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" else: - # for structures that are also used as notifications, generate dedicated notification DTO - description = "notification DTO" + description = "event DTO" 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) + + 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) diff --git a/src/vpp-api/java/jvpp/gen/jvppgen/jvpp_c_gen.py b/src/vpp-api/java/jvpp/gen/jvppgen/jvpp_c_gen.py index a02f04d6ce7..df1312a1308 100644 --- a/src/vpp-api/java/jvpp/gen/jvppgen/jvpp_c_gen.py +++ b/src/vpp-api/java/jvpp/gen/jvppgen/jvpp_c_gen.py @@ -6,7 +6,7 @@ # You may obtain a copy of the License at: # # http://www.apache.org/licenses/LICENSE-2.0 -# l +# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -139,15 +139,19 @@ JNIEXPORT jint JNICALL Java_io_fd_vpp_jvpp_${plugin_name}_JVpp${java_plugin_name return my_context_id; }""") + 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) or util.is_reply(camel_case_function_name) \ - or util.is_notification(f_name): + if is_manually_generated(f_name): + # Skip control ping managed by jvpp registry. + continue + if not (util.is_dump(f_name) or util.is_request(f_name, func_list)): continue + # Generate jni bindings for sending dump and request messages. arguments = '' request_class = '' jni_identifiers = '' @@ -255,11 +259,12 @@ def generate_msg_handlers(func_list, plugin_name, inputfile): ref_name = util.underscore_to_camelcase(handler_name) if is_manually_generated(handler_name): + # Skip control ping managed by jvpp registry. continue - - if not util.is_reply(dto_name) and not util.is_notification(handler_name): + if util.is_dump(handler_name) or util.is_request(handler_name, func_list): continue + # Generate msg handlers for all messages except for dumps and requests (handled by vpp, not client). dto_setters = '' err_handler = '' # dto setters @@ -306,12 +311,15 @@ def generate_handler_registration(func_list): handler_registration = ["#define foreach_api_reply_handler \\\n"] for f in func_list: name = f['name'] - camelcase_name = util.underscore_to_camelcase(f['name']) + camelcase_name = util.underscore_to_camelcase(name) - if (not util.is_reply(camelcase_name) and not util.is_notification(name)) \ - or util.is_control_ping(camelcase_name): + if util.is_control_ping(camelcase_name): + # Skip control ping managed by registry. + continue + if util.is_dump(name) or util.is_request(name, func_list): continue + # Generate msg handler registration for all messages except for dumps and requests. handler_registration.append(handler_registration_template.substitute( name=name, crc=f['crc'])) @@ -357,6 +365,7 @@ $msg_handlers $handler_registration """) + def generate_jvpp(func_list, plugin_name, inputfile, path): """ Generates jvpp C file """ print "Generating jvpp C" diff --git a/src/vpp-api/java/jvpp/gen/jvppgen/jvpp_callback_facade_gen.py b/src/vpp-api/java/jvpp/gen/jvppgen/jvpp_callback_facade_gen.py index f2659871f2f..a365946beea 100644 --- a/src/vpp-api/java/jvpp/gen/jvppgen/jvpp_callback_facade_gen.py +++ b/src/vpp-api/java/jvpp/gen/jvppgen/jvpp_callback_facade_gen.py @@ -109,11 +109,9 @@ def generate_jvpp(func_list, base_package, plugin_package, plugin_name, dto_pack methods = [] methods_impl = [] - for func in func_list: - - if util.is_notification(func['name']): - continue + # Generate methods for sending messages. + for func in func_list: 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) or util.is_control_ping(camel_case_name): @@ -123,8 +121,11 @@ def generate_jvpp(func_list, base_package, plugin_package, plugin_name, dto_pack callback_type = get_request_name(camel_case_name_upper) if util.is_dump(camel_case_name_upper): callback_type += "Details" - elif not util.is_notification(camel_case_name_upper): + elif util.is_request(func['name'], func_list): callback_type += "Reply" + else: + # Skip messages that do not not have replies (e.g events/counters). + continue callback_type += callback_gen.callback_suffix if len(func['args']) == 0: @@ -278,12 +279,15 @@ jvpp_facade_callback_notification_method_template = Template(""" def generate_callback(func_list, base_package, plugin_package, plugin_name, dto_package, callback_package, notification_package, callback_facade_package, inputfile): callbacks = [] for func in func_list: - camel_case_name_with_suffix = util.underscore_to_camelcase_upper(func['name']) if util.is_control_ping(camel_case_name_with_suffix): + # Skip control ping managed by jvpp registry. + continue + if util.is_dump(func['name']) or util.is_request(func['name'], func_list): continue + # Generate callbacks for all messages except for dumps and requests (handled by vpp, not client). if util.is_reply(camel_case_name_with_suffix): request_method = camel_case_name_with_suffix callbacks.append(jvpp_facade_callback_method_template.substitute(plugin_package=plugin_package, @@ -291,13 +295,12 @@ def generate_callback(func_list, base_package, plugin_package, plugin_name, dto_ callback_package=callback_package, callback=camel_case_name_with_suffix + callback_gen.callback_suffix, callback_dto=request_method)) - - if util.is_notification(func["name"]): + else: callbacks.append(jvpp_facade_callback_notification_method_template.substitute(plugin_package=plugin_package, - dto_package=dto_package, - callback_package=callback_package, - callback=camel_case_name_with_suffix + callback_gen.callback_suffix, - callback_dto=camel_case_name_with_suffix)) + dto_package=dto_package, + callback_package=callback_package, + callback=camel_case_name_with_suffix + callback_gen.callback_suffix, + callback_dto=camel_case_name_with_suffix)) jvpp_file = open(os.path.join(callback_facade_package, "CallbackJVpp%sFacadeCallback.java" % plugin_name), 'w') jvpp_file.write(jvpp_facade_callback_template.substitute(inputfile=inputfile, @@ -317,6 +320,7 @@ def generate_callback(func_list, base_package, plugin_package, plugin_name, dto_ def get_request_name(camel_case_dto_name): return remove_suffix(camel_case_dto_name) + def remove_suffix(name): if util.is_reply(name): return util.remove_reply_suffix(name) diff --git a/src/vpp-api/java/jvpp/gen/jvppgen/jvpp_future_facade_gen.py b/src/vpp-api/java/jvpp/gen/jvppgen/jvpp_future_facade_gen.py index e1bb43b9a65..b91eca26142 100644 --- a/src/vpp-api/java/jvpp/gen/jvppgen/jvpp_future_facade_gen.py +++ b/src/vpp-api/java/jvpp/gen/jvppgen/jvpp_future_facade_gen.py @@ -165,82 +165,50 @@ def generate_jvpp(func_list, base_package, plugin_package, plugin_name, dto_pack methods = [] methods_impl = [] - callbacks = [] + + # Generate methods for sending messages. for func in func_list: camel_case_name_with_suffix = util.underscore_to_camelcase_upper(func['name']) if util.is_control_ping(camel_case_name_with_suffix): + # Skip control ping managed by jvpp registry. continue - if not util.is_reply(camel_case_name_with_suffix) and not util.is_notification(func['name']): + # Process replies instead of requests (optimization). + if not util.is_reply(camel_case_name_with_suffix): + # Do not generate send methods for messages that do not have replies. continue - camel_case_method_name = util.underscore_to_camelcase(func['name']) - - if not util.is_notification(func["name"]): - camel_case_request_method_name = util.remove_reply_suffix(util.underscore_to_camelcase(func['name'])) - request_dto = util.remove_reply_suffix(util.underscore_to_camelcase_upper(func['name'])) - if util.is_details(camel_case_name_with_suffix): - camel_case_reply_name = util.underscore_to_camelcase_upper(func['name']) - callbacks.append(jvpp_facade_details_callback_method_template.substitute(base_package=base_package, - plugin_package=plugin_package, - dto_package=dto_package, - callback_dto=camel_case_name_with_suffix, - callback_dto_field=camel_case_method_name, - callback_dto_reply_dump=camel_case_reply_name + dto_gen.dump_dto_suffix, - future_package=future_facade_package)) - - methods.append(future_jvpp_method_template.substitute(plugin_package=plugin_package, - dto_package=dto_package, - method_name=camel_case_request_method_name + - util.underscore_to_camelcase_upper(util.dump_suffix), - reply_name=camel_case_reply_name + dto_gen.dump_dto_suffix, - request_name=util.remove_reply_suffix(camel_case_reply_name) + - util.underscore_to_camelcase_upper(util.dump_suffix))) - methods_impl.append(future_jvpp_dump_method_impl_template.substitute(plugin_package=plugin_package, - dto_package=dto_package, - method_name=camel_case_request_method_name + - util.underscore_to_camelcase_upper(util.dump_suffix), - reply_name=camel_case_reply_name + dto_gen.dump_dto_suffix, - request_name=util.remove_reply_suffix(camel_case_reply_name) + - util.underscore_to_camelcase_upper(util.dump_suffix))) - else: - request_name = util.remove_reply_suffix(camel_case_name_with_suffix) - - methods.append(future_jvpp_method_template.substitute(plugin_package=plugin_package, - dto_package=dto_package, - method_name=camel_case_request_method_name, - reply_name=camel_case_name_with_suffix, - request_name=request_name)) - methods_impl.append(future_jvpp_method_impl_template.substitute(plugin_package=plugin_package, - dto_package=dto_package, - method_name=camel_case_request_method_name, - reply_name=camel_case_name_with_suffix, - request_name=request_name)) - - callbacks.append(jvpp_facade_callback_method_template.substitute(base_package=base_package, - plugin_package=plugin_package, + camel_case_request_method_name = util.remove_reply_suffix(util.underscore_to_camelcase(func['name'])) + if util.is_details(camel_case_name_with_suffix): + camel_case_reply_name = util.underscore_to_camelcase_upper(func['name']) + methods.append(future_jvpp_method_template.substitute(plugin_package=plugin_package, + dto_package=dto_package, + method_name=camel_case_request_method_name + + util.underscore_to_camelcase_upper(util.dump_suffix), + reply_name=camel_case_reply_name + dto_gen.dump_dto_suffix, + request_name=util.remove_reply_suffix(camel_case_reply_name) + + util.underscore_to_camelcase_upper(util.dump_suffix))) + methods_impl.append(future_jvpp_dump_method_impl_template.substitute(plugin_package=plugin_package, dto_package=dto_package, - callback_dto=camel_case_name_with_suffix, - request_dto=request_dto)) - - if util.is_notification(func["name"]): - callbacks.append(jvpp_facade_callback_notification_method_template.substitute(plugin_package=plugin_package, - dto_package=dto_package, - callback_dto=camel_case_name_with_suffix)) - - jvpp_file = open(os.path.join(future_facade_package, "FutureJVpp%sFacadeCallback.java" % plugin_name), 'w') - jvpp_file.write(jvpp_facade_callback_template.substitute(inputfile=inputfile, - base_package=base_package, - plugin_package=plugin_package, - plugin_name=plugin_name, - dto_package=dto_package, - notification_package=notification_package, - callback_package=callback_package, - methods="".join(callbacks), - future_package=future_facade_package)) - jvpp_file.flush() - jvpp_file.close() + method_name=camel_case_request_method_name + + util.underscore_to_camelcase_upper(util.dump_suffix), + reply_name=camel_case_reply_name + dto_gen.dump_dto_suffix, + request_name=util.remove_reply_suffix(camel_case_reply_name) + + util.underscore_to_camelcase_upper(util.dump_suffix))) + else: + request_name = util.remove_reply_suffix(camel_case_name_with_suffix) + + methods.append(future_jvpp_method_template.substitute(plugin_package=plugin_package, + dto_package=dto_package, + method_name=camel_case_request_method_name, + reply_name=camel_case_name_with_suffix, + request_name=request_name)) + methods_impl.append(future_jvpp_method_impl_template.substitute(plugin_package=plugin_package, + dto_package=dto_package, + method_name=camel_case_request_method_name, + reply_name=camel_case_name_with_suffix, + request_name=request_name)) jvpp_file = open(os.path.join(future_facade_package, "FutureJVpp%s.java" % plugin_name), 'w') jvpp_file.write(future_jvpp_template.substitute(inputfile=inputfile, @@ -265,6 +233,8 @@ def generate_jvpp(func_list, base_package, plugin_package, plugin_name, dto_pack jvpp_file.flush() jvpp_file.close() + generate_callback(func_list, base_package, plugin_package, plugin_name, dto_package, callback_package, notification_package, future_facade_package, inputfile) + future_jvpp_template = Template(''' package $plugin_package.$future_package; @@ -337,3 +307,52 @@ future_jvpp_dump_method_impl_template = Template(''' return send(request, new $plugin_package.$dto_package.$reply_name()); } ''') + + +def generate_callback(func_list, base_package, plugin_package, plugin_name, dto_package, callback_package, notification_package, future_facade_package, inputfile): + callbacks = [] + for func in func_list: + camel_case_name_with_suffix = util.underscore_to_camelcase_upper(func['name']) + + if util.is_control_ping(camel_case_name_with_suffix): + # Skip control ping managed by jvpp registry. + continue + if util.is_dump(func['name']) or util.is_request(func['name'], func_list): + continue + + # Generate callbacks for all messages except for dumps and requests (handled by vpp, not client). + if util.is_details(camel_case_name_with_suffix): + # Callbacks for detail messages that append replies to a list. + camel_case_method_name = util.underscore_to_camelcase(func['name']) + camel_case_reply_name = util.underscore_to_camelcase_upper(func['name']) + callbacks.append(jvpp_facade_details_callback_method_template.substitute(base_package=base_package, + plugin_package=plugin_package, + dto_package=dto_package, + callback_dto=camel_case_name_with_suffix, + callback_dto_field=camel_case_method_name, + callback_dto_reply_dump=camel_case_reply_name + dto_gen.dump_dto_suffix, + future_package=future_facade_package)) + elif util.is_reply(camel_case_name_with_suffix): + request_dto = util.remove_reply_suffix(util.underscore_to_camelcase_upper(func['name'])) + callbacks.append(jvpp_facade_callback_method_template.substitute(base_package=base_package, + plugin_package=plugin_package, + dto_package=dto_package, + callback_dto=camel_case_name_with_suffix, + request_dto=request_dto)) + else: + callbacks.append(jvpp_facade_callback_notification_method_template.substitute(plugin_package=plugin_package, + dto_package=dto_package, + callback_dto=camel_case_name_with_suffix)) + + jvpp_file = open(os.path.join(future_facade_package, "FutureJVpp%sFacadeCallback.java" % plugin_name), 'w') + jvpp_file.write(jvpp_facade_callback_template.substitute(inputfile=inputfile, + base_package=base_package, + plugin_package=plugin_package, + plugin_name=plugin_name, + dto_package=dto_package, + notification_package=notification_package, + callback_package=callback_package, + methods="".join(callbacks), + future_package=future_facade_package)) + jvpp_file.flush() + jvpp_file.close() diff --git a/src/vpp-api/java/jvpp/gen/jvppgen/notification_gen.py b/src/vpp-api/java/jvpp/gen/jvppgen/notification_gen.py index 6da58c2e12c..72a32469460 100644 --- a/src/vpp-api/java/jvpp/gen/jvppgen/notification_gen.py +++ b/src/vpp-api/java/jvpp/gen/jvppgen/notification_gen.py @@ -135,13 +135,15 @@ def generate_notification_registry(func_list, base_package, plugin_package, plug register_callback_methods_impl = [] handler_methods = [] for func in func_list: - - if not util.is_reply(func['name']) and not util.is_notification(func['name']): - continue - camel_case_name_with_suffix = util.underscore_to_camelcase_upper(func['name']) + if util.is_control_ping(camel_case_name_with_suffix): + # Skip control ping managed by jvpp registry. continue + if util.is_dump(func['name']) or util.is_request(func['name'], func_list): + continue + + # Generate callbacks for all messages except for dumps and requests (handled by vpp, not client). notification_dto = camel_case_name_with_suffix callback_ifc = camel_case_name_with_suffix + callback_gen.callback_suffix fully_qualified_callback_ifc = "{0}.{1}.{2}".format(plugin_package, callback_package, callback_ifc) @@ -164,7 +166,6 @@ def generate_notification_registry(func_list, base_package, plugin_package, plug notification_reply=camel_case_name_with_suffix, callback=callback_ifc)) - callback_file = open(os.path.join(notification_package, "%sEventRegistry.java" % plugin_name), 'w') callback_file.write(notification_registry_template.substitute(inputfile=inputfile, register_callback_methods="\n ".join(register_callback_methods), diff --git a/src/vpp-api/java/jvpp/gen/jvppgen/util.py b/src/vpp-api/java/jvpp/gen/jvppgen/util.py index ce34f8549d8..70ddc8ea8e7 100644 --- a/src/vpp-api/java/jvpp/gen/jvppgen/util.py +++ b/src/vpp-api/java/jvpp/gen/jvppgen/util.py @@ -35,19 +35,30 @@ def remove_folder(folder): removedirs(folder) -reply_suffixes = ("reply", "details") +_REPLY_SUFFIX = "reply" +_DETAILS_SUFFIX = "details" +_REPLY_SUFFIXES = (_REPLY_SUFFIX, _DETAILS_SUFFIX) def is_reply(name): - return name.lower().endswith(reply_suffixes) + return name.lower().endswith(_REPLY_SUFFIXES) -def is_details(name): - return name.lower().endswith(reply_suffixes[1]) +def is_request(msg_name_underscore, all_messages): + """ + Checks if reply message is present in all_messages. + :param msg_name_underscore name of vpp API message + :param all_messages: sequence of vpp message names + :returns: True if reply for the msg_name_underscore message is defined. + """ + reply_msg = msg_name_underscore + "_" + _REPLY_SUFFIX + return reply_msg in [m['name'] for m in all_messages] + + +def is_details(name): + return name.lower().endswith(_DETAILS_SUFFIX) -def is_retval_field(name): - return name == 'retval' dump_suffix = "dump" @@ -56,8 +67,12 @@ def is_dump(name): return name.lower().endswith(dump_suffix) +def is_retval_field(name): + return name == 'retval' + + def get_reply_suffix(name): - for reply_suffix in reply_suffixes: + for reply_suffix in _REPLY_SUFFIXES: if name.lower().endswith(reply_suffix): return reply_suffix @@ -149,14 +164,6 @@ jni_field_accessors = {'u8': 'ByteField', } -def is_notification(name): - """ Returns true if the structure is a notification """ - # FIXME no convention in the naming of events (notifications) in vpe.api - notifications_message_suffixes = ("event", "counters") - - return name.lower().endswith(notifications_message_suffixes) - - def remove_reply_suffix(camel_case_name_with_suffix): return remove_suffix(camel_case_name_with_suffix, get_reply_suffix(camel_case_name_with_suffix)) |