66ea26b1bc
Splits jvpp into two jars jvpp-registry.jar - base jvpp functionality jvpp-core.jar - Java wrapper for vpe.api Plugins can be generated the same way jvpp-core.jar is. Example (nsh): https://gerrit.fd.io/r/#/c/2118/ Change-Id: I2254f90b2c3e423563bb91bf70877979f1e90a7d Signed-off-by: Marek Gradzki <mgradzki@cisco.com>
106 lines
4.3 KiB
Python
106 lines
4.3 KiB
Python
#!/usr/bin/env python
|
|
#
|
|
# Copyright (c) 2016 Cisco and/or its affiliates.
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at:
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# 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.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
import os
|
|
import util
|
|
from string import Template
|
|
|
|
from util import remove_suffix
|
|
|
|
callback_suffix = "Callback"
|
|
|
|
callback_template = Template("""
|
|
package $plugin_package.$callback_package;
|
|
|
|
/**
|
|
* <p>Represents callback for plugin's api file message.
|
|
* <br>It was generated by callback_gen.py based on $inputfile preparsed data:
|
|
* <pre>
|
|
$docs
|
|
* </pre>
|
|
*/
|
|
public interface $cls_name extends $base_package.$callback_package.$callback_type {
|
|
|
|
$callback_method
|
|
|
|
}
|
|
""")
|
|
|
|
global_callback_template = Template("""
|
|
package $plugin_package.$callback_package;
|
|
|
|
/**
|
|
* <p>Global aggregated callback interface.
|
|
* <br>It was generated by callback_gen.py based on $inputfile
|
|
* <br>(python representation of api file generated by vppapigen).
|
|
*/
|
|
public interface JVpp${plugin_name}GlobalCallback extends $base_package.$callback_package.ControlPingCallback, $callbacks {
|
|
}
|
|
""")
|
|
|
|
|
|
def generate_callbacks(func_list, base_package, plugin_package, plugin_name, callback_package, dto_package, inputfile):
|
|
""" Generates callback interfaces """
|
|
print "Generating Callback interfaces"
|
|
|
|
if not os.path.exists(callback_package):
|
|
raise Exception("%s folder is missing" % callback_package)
|
|
|
|
callbacks = []
|
|
for func in func_list:
|
|
|
|
camel_case_name_with_suffix = util.underscore_to_camelcase_upper(func['name'])
|
|
|
|
if util.is_ignored(func['name']) or util.is_control_ping(camel_case_name_with_suffix):
|
|
continue
|
|
if not util.is_reply(camel_case_name_with_suffix) and not util.is_notification(func['name']):
|
|
continue
|
|
|
|
if util.is_reply(camel_case_name_with_suffix):
|
|
camel_case_name = util.remove_reply_suffix(camel_case_name_with_suffix)
|
|
callback_type = "JVppCallback"
|
|
else:
|
|
camel_case_name_with_suffix = util.add_notification_suffix(camel_case_name_with_suffix)
|
|
camel_case_name = camel_case_name_with_suffix
|
|
callback_type = "JVppNotificationCallback"
|
|
|
|
callbacks.append("{0}.{1}.{2}".format(plugin_package, callback_package, camel_case_name + callback_suffix))
|
|
callback_path = os.path.join(callback_package, camel_case_name + callback_suffix + ".java")
|
|
callback_file = open(callback_path, 'w')
|
|
|
|
reply_type = "%s.%s.%s" % (plugin_package, dto_package, camel_case_name_with_suffix)
|
|
method = "void on{0}({1} reply);".format(camel_case_name_with_suffix, reply_type)
|
|
callback_file.write(
|
|
callback_template.substitute(inputfile=inputfile,
|
|
docs=util.api_message_to_javadoc(func),
|
|
cls_name=camel_case_name + callback_suffix,
|
|
callback_method=method,
|
|
base_package=base_package,
|
|
plugin_package=plugin_package,
|
|
callback_package=callback_package,
|
|
callback_type=callback_type))
|
|
callback_file.flush()
|
|
callback_file.close()
|
|
|
|
callback_file = open(os.path.join(callback_package, "JVpp%sGlobalCallback.java" % plugin_name), 'w')
|
|
callback_file.write(global_callback_template.substitute(inputfile=inputfile,
|
|
callbacks=", ".join(callbacks),
|
|
base_package=base_package,
|
|
plugin_package=plugin_package,
|
|
plugin_name=plugin_name,
|
|
callback_package=callback_package))
|
|
callback_file.flush()
|
|
callback_file.close()
|