jvppgen: update headers
[vpp.git] / extras / japi / java / jvpp / gen / jvppgen / callback_gen.py
1 #!/usr/bin/env python2
2 #
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:
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
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 from string import Template
17
18 from jvpp_model import is_request, is_dump, is_control_ping, is_control_ping_reply
19
20
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
25
26     callbacks = []
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.
31             continue
32         if is_dump(msg) or is_request(msg):
33             continue
34
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,
39             name=name)
40
41         with open("%s/%sCallback.java" % (work_dir, name), "w") as f:
42             f.write(callback)
43
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)
51         ))
52
53 _CALLBACK_TEMPLATE = Template("""package $plugin_package.callback;
54
55 /**
56  * <p>Represents callback for plugin's api message.
57  * <br>It was generated by jvppgen/callback_gen.py based on $json_filename.
58  */
59 public interface ${name}Callback extends io.fd.vpp.jvpp.callback.JVppCallback {
60
61     void on${name}(${plugin_package}.dto.${name} reply);
62 }
63 """)
64
65 _GLOBAL_CALLBACK_TEMPLATE = Template("""package $plugin_package.callback;
66
67 /**
68  * <p>Global aggregated callback interface.
69  * <br>It was generated by jvppgen/callback_gen.py based on $json_filename.
70  */
71 public interface JVpp${plugin_name}GlobalCallback extends io.fd.vpp.jvpp.callback.ControlPingCallback, $callbacks {
72 }
73 """)