3 # Copyright (c) 2016,2018 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:
8 # http://www.apache.org/licenses/LICENSE-2.0
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.
16 from string import Template
18 from jvpp_model import is_request, is_dump, is_control_ping, is_control_ping_reply
21 def generate_callbacks(work_dir, model, logger):
22 json_api_files = model.json_api_files
23 logger.debug("Generating Callback interfaces for %s" % json_api_files)
24 plugin_package = model.plugin_package
27 for msg in model.messages:
28 name = msg.java_name_upper
29 if is_control_ping(msg) or is_control_ping_reply(msg):
30 # Skip control_ping managed by jvpp registry.
32 if is_dump(msg) or is_request(msg):
35 callbacks.append("%s.callback.%sCallback" % (plugin_package, name))
36 callback = _CALLBACK_TEMPLATE.substitute(
37 plugin_package=plugin_package,
38 json_filename=json_api_files,
41 with open("%s/%sCallback.java" % (work_dir, name), "w") as f:
44 plugin_name = model.plugin_java_name
45 with open("%s/JVpp%sGlobalCallback.java" % (work_dir, plugin_name), "w") as f:
46 f.write(_GLOBAL_CALLBACK_TEMPLATE.substitute(
47 plugin_package=plugin_package,
48 json_filename=json_api_files,
49 plugin_name=plugin_name,
50 callbacks=", ".join(callbacks)
53 _CALLBACK_TEMPLATE = Template("""package $plugin_package.callback;
56 * <p>Represents callback for plugin's api message.
57 * <br>It was generated by jvppgen/callback_gen.py based on $json_filename.
59 public interface ${name}Callback extends io.fd.vpp.jvpp.callback.JVppCallback {
61 void on${name}(${plugin_package}.dto.${name} reply);
65 _GLOBAL_CALLBACK_TEMPLATE = Template("""package $plugin_package.callback;
68 * <p>Global aggregated callback interface.
69 * <br>It was generated by jvppgen/callback_gen.py based on $json_filename.
71 public interface JVpp${plugin_name}GlobalCallback extends io.fd.vpp.jvpp.callback.ControlPingCallback, $callbacks {