aboutsummaryrefslogtreecommitdiffstats
path: root/vpp-api/java/jvpp/gen
diff options
context:
space:
mode:
Diffstat (limited to 'vpp-api/java/jvpp/gen')
-rw-r--r--vpp-api/java/jvpp/gen/callback_gen.py20
-rw-r--r--vpp-api/java/jvpp/gen/dto_gen.py27
-rw-r--r--vpp-api/java/jvpp/gen/jvpp_c_gen.py330
-rw-r--r--vpp-api/java/jvpp/gen/jvpp_callback_facade_gen.py29
-rw-r--r--vpp-api/java/jvpp/gen/jvpp_future_facade_gen.py9
-rwxr-xr-xvpp-api/java/jvpp/gen/jvpp_gen.py131
-rw-r--r--vpp-api/java/jvpp/gen/jvpp_impl_gen.py19
-rw-r--r--vpp-api/java/jvpp/gen/util.py7
8 files changed, 542 insertions, 30 deletions
diff --git a/vpp-api/java/jvpp/gen/callback_gen.py b/vpp-api/java/jvpp/gen/callback_gen.py
index 218ac62298b..8a0d20124ae 100644
--- a/vpp-api/java/jvpp/gen/callback_gen.py
+++ b/vpp-api/java/jvpp/gen/callback_gen.py
@@ -25,7 +25,11 @@ callback_template = Template("""
package $base_package.$callback_package;
/**
- * $docs
+ * <p>Represents callback for vpe.api 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.JVppCallback {
@@ -38,16 +42,16 @@ global_callback_template = Template("""
package $base_package.$callback_package;
/**
- *
- *
- * Global aggregated callback interface
+ * <p>Global aggregated callback interface.
+ * <br>It was generated by callback_gen.py based on $inputfile
+ * <br>(python representation of vpe.api generated by vppapigen).
*/
public interface JVppGlobalCallback extends $callbacks {
}
""")
-def generate_callbacks(func_list, base_package, callback_package, dto_package):
+def generate_callbacks(func_list, base_package, callback_package, dto_package, inputfile):
""" Generates callback interfaces """
print "Generating Callback interfaces"
@@ -73,7 +77,8 @@ def generate_callbacks(func_list, base_package, callback_package, dto_package):
reply_type = "%s.%s.%s" % (base_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(docs='Generated from ' + str(func),
+ 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,
@@ -82,7 +87,8 @@ def generate_callbacks(func_list, base_package, callback_package, dto_package):
callback_file.close()
callback_file = open(os.path.join(callback_package, "JVppGlobalCallback.java"), 'w')
- callback_file.write(global_callback_template.substitute(callbacks=", ".join(callbacks),
+ callback_file.write(global_callback_template.substitute(inputfile=inputfile,
+ callbacks=", ".join(callbacks),
base_package=base_package,
callback_package=callback_package))
callback_file.flush()
diff --git a/vpp-api/java/jvpp/gen/dto_gen.py b/vpp-api/java/jvpp/gen/dto_gen.py
index 17fde68a26d..378d279c6d0 100644
--- a/vpp-api/java/jvpp/gen/dto_gen.py
+++ b/vpp-api/java/jvpp/gen/dto_gen.py
@@ -20,7 +20,11 @@ dto_template = Template("""
package $base_package.$dto_package;
/**
- * $docs
+ * <p>This class represents $description.
+ * <br>It was generated by dto_gen.py based on $inputfile preparsed data:
+ * <pre>
+$docs
+ * </pre>
*/
public final class $cls_name implements $base_package.$dto_package.$base_type {
@@ -36,8 +40,7 @@ send_template = Template(""" @Override
return jvpp.$method_name($args);
}\n""")
-
-def generate_dtos(func_list, base_package, dto_package):
+def generate_dtos(func_list, base_package, dto_package, inputfile):
""" Generates dto objects in a dedicated package """
print "Generating DTOs"
@@ -60,6 +63,7 @@ def generate_dtos(func_list, base_package, dto_package):
methods = ""
base_type = ""
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
@@ -75,11 +79,15 @@ def generate_dtos(func_list, base_package, dto_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"
dto_file = open(dto_path, 'w')
- dto_file.write(dto_template.substitute(docs='Generated from ' + str(func),
+ dto_file.write(dto_template.substitute(inputfile=inputfile,
+ description=description,
+ docs=util.api_message_to_javadoc(func),
cls_name=camel_case_dto_name,
fields=fields,
methods=methods,
@@ -89,13 +97,12 @@ def generate_dtos(func_list, base_package, dto_package):
dto_file.flush()
dto_file.close()
- flush_dump_reply_dtos()
+ flush_dump_reply_dtos(inputfile)
dump_dto_suffix = "ReplyDump"
dump_reply_artificial_dtos = {}
-
# Returns request name or special one from unconventional_naming_rep_req map
def get_request_name(camel_case_dto_name, func_name):
return util.underscore_to_camelcase_upper(
@@ -103,12 +110,14 @@ def get_request_name(camel_case_dto_name, func_name):
else util.remove_reply_suffix(camel_case_dto_name)
-def flush_dump_reply_dtos():
+def flush_dump_reply_dtos(inputfile):
for dump_reply_artificial_dto in dump_reply_artificial_dtos.values():
dto_path = os.path.join(dump_reply_artificial_dto['dto_package'],
dump_reply_artificial_dto['cls_name'] + ".java")
dto_file = open(dto_path, 'w')
- dto_file.write(dto_template.substitute(docs=dump_reply_artificial_dto['docs'],
+ dto_file.write(dto_template.substitute(inputfile=inputfile,
+ description="vpe.api dump reply wrapper",
+ docs=dump_reply_artificial_dto['docs'],
cls_name=dump_reply_artificial_dto['cls_name'],
fields=dump_reply_artificial_dto['fields'],
methods=dump_reply_artificial_dto['methods'],
@@ -133,7 +142,7 @@ def generate_dump_reply_dto(request_dto_name, base_package, dto_package, camel_c
dump_reply_artificial_dtos[request_dto_name]['fields'] = \
dump_reply_artificial_dtos[request_dto_name]['fields'] + '\n' + fields
else:
- dump_reply_artificial_dtos[request_dto_name] = ({'docs': 'Dump reply wrapper generated from ' + str(func),
+ dump_reply_artificial_dtos[request_dto_name] = ({'docs': util.api_message_to_javadoc(func),
'cls_name': cls_name,
'fields': fields,
'methods': "",
diff --git a/vpp-api/java/jvpp/gen/jvpp_c_gen.py b/vpp-api/java/jvpp/gen/jvpp_c_gen.py
new file mode 100644
index 00000000000..c0efed81d30
--- /dev/null
+++ b/vpp-api/java/jvpp/gen/jvpp_c_gen.py
@@ -0,0 +1,330 @@
+#!/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
+# 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.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+import os, util
+from string import Template
+
+def is_manually_generated(f_name):
+ return f_name in {'control_ping_reply'}
+
+# TODO: cache class/method/field identifiers to achieve better performance
+# https://jira.fd.io/browse/HONEYCOMB-42
+request_class_template = Template("""
+ jclass requestClass = (*env)->FindClass(env, "org/openvpp/jvpp/dto/${java_name_upper}");""")
+
+request_field_identifier_template = Template("""
+ jfieldID ${java_name}FieldId = (*env)->GetFieldID(env, requestClass, "${java_name}", "${jni_signature}");
+ ${jni_type} ${java_name} = (*env)->Get${jni_getter}(env, request, ${java_name}FieldId);
+ """)
+
+u8_struct_setter_template = Template("""
+ mp->${c_name} = ${java_name};""")
+
+u16_struct_setter_template = Template("""
+ mp->${c_name} = clib_host_to_net_u16(${java_name});""")
+
+u32_struct_setter_template = Template("""
+ mp->${c_name} = clib_host_to_net_u32(${java_name});""")
+
+i32_struct_setter_template = Template("""
+ mp->${c_name} = clib_host_to_net_i32(${java_name});!""")
+
+u64_struct_setter_template = Template("""
+ mp->${c_name} = clib_host_to_net_u64(${java_name});""")
+
+u8_array_struct_setter_template = Template("""
+ {
+ jsize cnt = (*env)->GetArrayLength (env, ${java_name});
+ if (cnt > sizeof(mp->${c_name})) cnt = sizeof(mp->${c_name});
+ (*env)->GetByteArrayRegion(env, ${java_name}, 0, cnt, (jbyte *)mp->${c_name});
+ }
+""")
+
+u32_array_struct_setter_template = Template("""
+ jint * ${java_name}ArrayElements = (*env)->GetIntArrayElements(env, ${java_name}, NULL);
+ {
+ int _i;
+ for (_i = 0; _i < 0; _i++) {
+ mp->${c_name}[_i] = clib_host_to_net_u32(${java_name}ArrayElements[_i]);
+ }
+ }
+ (*env)->ReleaseIntArrayElements (env, ${java_name}, ${java_name}ArrayElements, 0);
+ """)
+
+vl_api_ip4_fib_counter_t_array_struct_setter_template = Template("""
+ // vl_api_ip4_fib_counter_t_array_field_setter_template FIXME""")
+
+vl_api_ip6_fib_counter_t_array_struct_setter_template = Template("""
+ // vl_api_ip6_fib_counter_t_array_field_setter_template FIXME""")
+
+struct_setter_templates = {'u8': u8_struct_setter_template,
+ 'u16': u32_struct_setter_template,
+ 'u32': u32_struct_setter_template,
+ 'i32': u32_struct_setter_template,
+ 'u64': u64_struct_setter_template,
+ 'u8[]': u8_array_struct_setter_template,
+ 'u32[]': u32_array_struct_setter_template,
+ 'vl_api_ip4_fib_counter_t[]': vl_api_ip4_fib_counter_t_array_struct_setter_template,
+ 'vl_api_ip6_fib_counter_t[]': vl_api_ip6_fib_counter_t_array_struct_setter_template
+ }
+
+jni_impl_template = Template("""
+/**
+ * JNI binding for sending ${c_name} vpe.api message.
+ * Generated based on $inputfile preparsed data:
+$api_data
+ */
+JNIEXPORT jint JNICALL Java_org_openvpp_jvpp_JVppImpl_${java_name}0
+(JNIEnv * env, jclass clazz$args) {
+ vppjni_main_t *jm = &vppjni_main;
+ vl_api_${c_name}_t * mp;
+ u32 my_context_id;
+ int rv;
+ rv = vppjni_sanity_check (jm);
+ if (rv) return rv;
+ my_context_id = vppjni_get_context_id (jm);
+ $request_class
+ $field_identifiers
+ M(${c_name_uppercase}, ${c_name});
+ mp->context = clib_host_to_net_u32 (my_context_id);
+ $struct_setters
+ S;
+ return my_context_id;
+}""")
+
+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_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']):
+ c_type = t[0]
+ c_name = t[1]
+ 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)
+
+ 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)
+
+
+dto_field_id_template = Template("""
+ jfieldID ${java_name}FieldId = (*env)->GetFieldID(env, dtoClass, "${java_name}", "${jni_signature}");""")
+
+default_dto_field_setter_template = Template("""
+ (*env)->Set${jni_setter}(env, dto, ${java_name}FieldId, mp->${c_name});
+""")
+
+u32_dto_field_setter_template = Template("""
+ (*env)->Set${jni_setter}(env, dto, ${java_name}FieldId, clib_net_to_host_u32(mp->${c_name}));
+""")
+
+u64_dto_field_setter_template = Template("""
+ (*env)->Set${jni_setter}(env, dto, ${java_name}FieldId, clib_net_to_host_u64(mp->${c_name}));
+""")
+
+u8_array_dto_field_setter_template = Template("""
+ jbyteArray ${java_name} = (*env)->NewByteArray(env, sizeof(mp->${c_name}));
+ (*env)->SetByteArrayRegion(env, ${java_name}, 0, sizeof(mp->${c_name}), (const jbyte*)mp->${c_name});
+ (*env)->SetObjectField(env, dto, ${java_name}FieldId, ${java_name});
+""")
+
+# For each u64 array we get its elements. Then we convert values to host byte order.
+# All changes to jint* buffer are written to jlongArray (isCopy is set to NULL)
+u64_array_dto_field_setter_template = Template("""
+ jlongArray ${java_name} = (*env)->NewLongArray(env, sizeof(mp->${c_name}));
+ {
+ jlong * ${java_name}ArrayElements = (*env)->GetLongArrayElements(env, ${java_name}, NULL);
+ int _i;
+ for (_i = 0; _i < 0; _i++) {
+ ${java_name}ArrayElements[_i] = clib_net_to_host_u64(mp->${c_name}[_i]);
+ }
+ }
+ (*env)->SetObjectField(env, dto, ${java_name}FieldId, ${java_name});
+""")
+
+dto_field_setter_templates = {'u8': default_dto_field_setter_template,
+ 'u16': u32_dto_field_setter_template,
+ 'u32': u32_dto_field_setter_template,
+ 'i32': u32_dto_field_setter_template,
+ 'u64': u64_dto_field_setter_template,
+ 'f64': default_dto_field_setter_template,
+ 'u64[]': u64_array_dto_field_setter_template,
+ 'u8[]': u8_array_dto_field_setter_template
+ }
+
+msg_handler_template = Template("""
+/**
+ * Handler for ${handler_name} vpe.api message.
+ * Generated based on $inputfile preparsed data:
+$api_data
+ */
+static void vl_api_${handler_name}_t_handler (vl_api_${handler_name}_t * mp)
+{
+ vppjni_main_t * jm = &vppjni_main;
+ JNIEnv *env = jm->jenv;
+
+ jclass dtoClass = (*env)->FindClass(env, "org/openvpp/jvpp/dto/${dto_name}");
+
+ jmethodID constructor = (*env)->GetMethodID(env, dtoClass, "<init>", "()V");
+ jmethodID callbackMethod = (*env)->GetMethodID(env, jm->callbackClass, "on${dto_name}", "(Lorg/openvpp/jvpp/dto/${dto_name};)V");
+
+ jobject dto = (*env)->NewObject(env, dtoClass, constructor);
+ $dto_setters
+ (*env)->CallVoidMethod(env, jm->callback, callbackMethod, dto);
+}""")
+
+def generate_msg_handlers(func_list, inputfile):
+ handlers = []
+ for f in func_list:
+ handler_name = f['name']
+ dto_name = util.underscore_to_camelcase_upper(handler_name)
+
+ if is_manually_generated(handler_name) or not util.is_reply(dto_name) or util.is_ignored(handler_name) or util.is_notification(handler_name):
+ # TODO handle notifications
+ continue
+
+ dto_setters = ''
+ # dto setters
+ for t in zip(f['c_types'], f['types'], f['args']):
+ c_type = t[0]
+ jni_type = t[1]
+ c_name = t[2]
+
+ java_field_name = util.underscore_to_camelcase(c_name)
+ jni_signature = util.jni_2_signature_mapping[jni_type]
+ jni_setter = util.jni_field_accessors[jni_type]
+
+ dto_setters += dto_field_id_template.substitute(
+ java_name=java_field_name,
+ jni_signature=jni_signature)
+
+ dto_setter_template = dto_field_setter_templates[c_type]
+
+ dto_setters += dto_setter_template.substitute(
+ java_name=java_field_name,
+ jni_signature=jni_signature,
+ c_name=c_name,
+ jni_setter=jni_setter)
+
+ handlers.append(msg_handler_template.substitute(
+ inputfile=inputfile,
+ api_data=util.api_message_to_javadoc(f),
+ handler_name=handler_name,
+ dto_name=dto_name,
+ dto_setters=dto_setters))
+
+ return "\n".join(handlers)
+
+
+handler_registration_template = Template("""_(${upercase_name}, ${name}) \\
+""")
+
+
+def generate_handler_registration(func_list):
+ handler_registration = ["#define foreach_vpe_api_msg \\\n"]
+ for f in func_list:
+ name = f['name']
+ camelcase_name = util.underscore_to_camelcase(f['name'])
+
+ if not util.is_reply(camelcase_name) or util.is_ignored(name) or util.is_notification(name):
+ # TODO handle notifications
+ continue
+
+ handler_registration.append(handler_registration_template.substitute(
+ name=name,
+ upercase_name=name.upper()))
+
+ return "".join(handler_registration)
+
+jvpp_c_template = Template("""
+/**
+ * This file contains JNI bindings for jvpp Java API.
+ * It was generated by jvpp_c_gen.py based on $inputfile
+ * (python representation of vpe.api generated by vppapigen).
+ */
+
+// JNI bindings
+$jni_implementations
+
+// Message handlers
+$msg_handlers
+
+// Registration of message handlers in vlib
+$handler_registration
+""")
+
+def generate_jvpp(func_list, inputfile):
+ """ Generates jvpp C file """
+ print "Generating jvpp C"
+
+ jni_impl = generate_jni_impl(func_list, inputfile)
+ msg_handlers = generate_msg_handlers(func_list, inputfile)
+ handler_registration = generate_handler_registration(func_list)
+
+ jvpp_c_file = open("jvpp_gen.h", 'w')
+ jvpp_c_file.write(jvpp_c_template.substitute(
+ inputfile=inputfile,
+ jni_implementations=jni_impl,
+ msg_handlers=msg_handlers,
+ handler_registration=handler_registration))
+ jvpp_c_file.flush()
+ jvpp_c_file.close()
+
+
diff --git a/vpp-api/java/jvpp/gen/jvpp_callback_facade_gen.py b/vpp-api/java/jvpp/gen/jvpp_callback_facade_gen.py
index 731bd894cee..7b8723bf87c 100644
--- a/vpp-api/java/jvpp/gen/jvpp_callback_facade_gen.py
+++ b/vpp-api/java/jvpp/gen/jvpp_callback_facade_gen.py
@@ -22,6 +22,11 @@ import dto_gen
jvpp_ifc_template = Template("""
package $base_package.$callback_facade_package;
+/**
+ * <p>Callback Java API representation of vpe.api.
+ * <br>It was generated by jvpp_callback_facade_gen.py based on $inputfile
+ * <br>(python representation of vpe.api generated by vppapigen).
+ */
public interface CallbackJVpp extends java.lang.AutoCloseable {
@Override
@@ -36,6 +41,11 @@ $methods
jvpp_impl_template = Template("""
package $base_package.$callback_facade_package;
+/**
+ * <p>Default implementation of CallbackJVpp interface.
+ * <br>It was generated by jvpp_callback_facade_gen.py based on $inputfile
+ * <br>(python representation of vpe.api generated by vppapigen).
+ */
public final class CallbackJVppFacade implements $base_package.$callback_facade_package.CallbackJVpp {
private final $base_package.JVpp jvpp;
@@ -78,7 +88,7 @@ no_arg_method_impl_template = Template(""" public final void $name($base_pack
""")
-def generate_jvpp(func_list, base_package, dto_package, callback_package, callback_facade_package):
+def generate_jvpp(func_list, base_package, dto_package, callback_package, callback_facade_package, inputfile):
""" Generates callback facade """
print "Generating JVpp callback facade"
@@ -131,7 +141,8 @@ def generate_jvpp(func_list, base_package, dto_package, callback_package, callba
join = os.path.join(callback_facade_package, "CallbackJVpp.java")
jvpp_file = open(join, 'w')
jvpp_file.write(
- jvpp_ifc_template.substitute(methods="\n".join(methods),
+ jvpp_ifc_template.substitute(inputfile=inputfile,
+ methods="\n".join(methods),
base_package=base_package,
dto_package=dto_package,
callback_facade_package=callback_facade_package))
@@ -139,7 +150,8 @@ def generate_jvpp(func_list, base_package, dto_package, callback_package, callba
jvpp_file.close()
jvpp_file = open(os.path.join(callback_facade_package, "CallbackJVppFacade.java"), 'w')
- jvpp_file.write(jvpp_impl_template.substitute(methods="\n".join(methods_impl),
+ jvpp_file.write(jvpp_impl_template.substitute(inputfile=inputfile,
+ methods="\n".join(methods_impl),
base_package=base_package,
dto_package=dto_package,
callback_package=callback_package,
@@ -147,14 +159,16 @@ def generate_jvpp(func_list, base_package, dto_package, callback_package, callba
jvpp_file.flush()
jvpp_file.close()
- generate_callback(func_list, base_package, dto_package, callback_package, callback_facade_package)
+ generate_callback(func_list, base_package, dto_package, callback_package, callback_facade_package, inputfile)
jvpp_facade_callback_template = Template("""
package $base_package.$callback_facade_package;
/**
- * Async facade callback setting values to future objects
+ * <p>JVppGlobalCallback implementation for Java Callback API.
+ * <br>It was generated by jvpp_callback_facade_gen.py based on $inputfile
+ * <br>(python representation of vpe.api generated by vppapigen).
*/
public final class CallbackJVppFacadeCallback implements $base_package.$callback_package.JVppGlobalCallback {
@@ -185,7 +199,7 @@ jvpp_facade_callback_method_template = Template("""
""")
-def generate_callback(func_list, base_package, dto_package, callback_package, callback_facade_package):
+def generate_callback(func_list, base_package, dto_package, callback_package, callback_facade_package, inputfile):
callbacks = []
for func in func_list:
@@ -204,7 +218,8 @@ def generate_callback(func_list, base_package, dto_package, callback_package, ca
callback_dto=camel_case_name_with_suffix))
jvpp_file = open(os.path.join(callback_facade_package, "CallbackJVppFacadeCallback.java"), 'w')
- jvpp_file.write(jvpp_facade_callback_template.substitute(base_package=base_package,
+ jvpp_file.write(jvpp_facade_callback_template.substitute(inputfile=inputfile,
+ base_package=base_package,
dto_package=dto_package,
callback_package=callback_package,
methods="".join(callbacks),
diff --git a/vpp-api/java/jvpp/gen/jvpp_future_facade_gen.py b/vpp-api/java/jvpp/gen/jvpp_future_facade_gen.py
index 2aae5b8018a..60010b1070d 100644
--- a/vpp-api/java/jvpp/gen/jvpp_future_facade_gen.py
+++ b/vpp-api/java/jvpp/gen/jvpp_future_facade_gen.py
@@ -22,7 +22,9 @@ jvpp_facade_callback_template = Template("""
package $base_package.$future_package;
/**
- * Async facade callback setting values to future objects
+ * <p>Async facade callback setting values to future objects
+ * <br>It was generated by jvpp_future_facade_gen.py based on $inputfile
+ * <br>(python representation of vpe.api generated by vppapigen).
*/
public final class FutureJVppFacadeCallback implements $base_package.$callback_package.JVppGlobalCallback {
@@ -119,7 +121,7 @@ jvpp_facade_details_callback_method_template = Template("""
""")
-def generate_jvpp(func_list, base_package, dto_package, callback_package, future_facade_package):
+def generate_jvpp(func_list, base_package, dto_package, callback_package, future_facade_package, inputfile):
""" Generates JVpp interface and JNI implementation """
print "Generating JVpp future facade"
@@ -159,7 +161,8 @@ def generate_jvpp(func_list, base_package, dto_package, callback_package, future
callback_dto=camel_case_name_with_suffix))
jvpp_file = open(os.path.join(future_facade_package, "FutureJVppFacadeCallback.java"), 'w')
- jvpp_file.write(jvpp_facade_callback_template.substitute(base_package=base_package,
+ jvpp_file.write(jvpp_facade_callback_template.substitute(inputfile=inputfile,
+ base_package=base_package,
dto_package=dto_package,
callback_package=callback_package,
methods="".join(callbacks),
diff --git a/vpp-api/java/jvpp/gen/jvpp_gen.py b/vpp-api/java/jvpp/gen/jvpp_gen.py
new file mode 100755
index 00000000000..931141e884a
--- /dev/null
+++ b/vpp-api/java/jvpp/gen/jvpp_gen.py
@@ -0,0 +1,131 @@
+#!/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
+# 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.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+import argparse
+import importlib
+import sys
+
+import callback_gen
+import dto_gen
+import jvpp_callback_facade_gen
+import jvpp_future_facade_gen
+import jvpp_impl_gen
+import jvpp_c_gen
+import util
+
+# Invocation:
+# ~/Projects/vpp/vpp-api/jvpp/gen$ mkdir -p java/org/openvpp/jvpp && cd java/org/openvpp/jvpp
+# ~/Projects/vpp/vpp-api/jvpp/gen/java/org/openvpp/jvpp$ ../../../../jvpp_gen.py -idefs_api_vpp_papi.py
+#
+# Compilation:
+# ~/Projects/vpp/vpp-api/jvpp/gen/java/org/openvpp/jvpp$ javac *.java dto/*.java callback/*.java
+#
+# where
+# defs_api_vpp_papi.py - vpe.api in python format (generated by vppapigen)
+from util import vpp_2_jni_type_mapping
+
+parser = argparse.ArgumentParser(description='VPP Java API generator')
+parser.add_argument('-i', action="store", dest="inputfile")
+args = parser.parse_args()
+
+sys.path.append(".")
+
+inputfile = args.inputfile.replace('.py', '')
+cfg = importlib.import_module(inputfile, package=None)
+
+
+# FIXME: functions unsupported due to problems with vpe.api
+def is_supported(f_name):
+ return f_name not in {'vnet_ip4_fib_counters', 'vnet_ip6_fib_counters'}
+
+
+def is_request_field(field_name):
+ return field_name not in {'_vl_msg_id', 'client_index', 'context'}
+
+
+def is_response_field(field_name):
+ return field_name not in {'_vl_msg_id'}
+
+
+def get_args(t, filter):
+ arg_list = []
+ for i in t:
+ if not filter(i[1]):
+ continue
+ arg_list.append(i[1])
+ return arg_list
+
+
+def get_types(t, filter):
+ types_list = []
+ c_types_list = []
+ for i in t:
+ if not filter(i[1]):
+ continue
+ if len(i) is 3: # array type
+ types_list.append(vpp_2_jni_type_mapping[i[0]] + 'Array')
+ c_types_list.append(i[0] + '[]')
+ else: # primitive type
+ types_list.append(vpp_2_jni_type_mapping[i[0]])
+ c_types_list.append(i[0])
+ return types_list, c_types_list
+
+
+def get_definitions():
+ # Pass 1
+ func_list = []
+ func_name = {}
+ for a in cfg.vppapidef:
+ if not is_supported(a[0]):
+ continue
+
+ java_name = util.underscore_to_camelcase(a[0])
+
+ # For replies include all the arguments except message_id
+ if util.is_reply(java_name):
+ types, c_types = get_types(a[1:], is_response_field)
+ func_name[a[0]] = dict(
+ [('name', a[0]), ('java_name', java_name),
+ ('args', get_args(a[1:], is_response_field)), ('full_args', get_args(a[1:], lambda x: True)),
+ ('types', types), ('c_types', c_types)])
+ # For requests skip message_id, client_id and context
+ else:
+ types, c_types = get_types(a[1:], is_request_field)
+ func_name[a[0]] = dict(
+ [('name', a[0]), ('java_name', java_name),
+ ('args', get_args(a[1:], is_request_field)), ('full_args', get_args(a[1:], lambda x: True)),
+ ('types', types), ('c_types', c_types)])
+
+ # Indexed by name
+ func_list.append(func_name[a[0]])
+ return func_list, func_name
+
+
+func_list, func_name = get_definitions()
+
+base_package = 'org.openvpp.jvpp'
+dto_package = 'dto'
+callback_package = 'callback'
+future_package = 'future'
+# TODO find better package name
+callback_facade_package = 'callfacade'
+
+dto_gen.generate_dtos(func_list, base_package, dto_package, args.inputfile)
+jvpp_impl_gen.generate_jvpp(func_list, base_package, dto_package, args.inputfile)
+callback_gen.generate_callbacks(func_list, base_package, callback_package, dto_package, args.inputfile)
+jvpp_c_gen.generate_jvpp(func_list, args.inputfile)
+jvpp_future_facade_gen.generate_jvpp(func_list, base_package, dto_package, callback_package, future_package, args.inputfile)
+jvpp_callback_facade_gen.generate_jvpp(func_list, base_package, dto_package, callback_package, callback_facade_package, args.inputfile)
diff --git a/vpp-api/java/jvpp/gen/jvpp_impl_gen.py b/vpp-api/java/jvpp/gen/jvpp_impl_gen.py
index 5446a694c1b..08ebddfcf97 100644
--- a/vpp-api/java/jvpp/gen/jvpp_impl_gen.py
+++ b/vpp-api/java/jvpp/gen/jvpp_impl_gen.py
@@ -19,6 +19,12 @@ from string import Template
jvpp_ifc_template = Template("""
package $base_package;
+
+/**
+ * <p>Java representation of vpe.api.
+ * <br>It was generated by jvpp_impl_gen.py based on $inputfile
+ * <br>(python representation of vpe.api generated by vppapigen).
+ */
public interface JVpp extends java.lang.AutoCloseable {
/**
@@ -36,6 +42,11 @@ $methods
jvpp_impl_template = Template("""
package $base_package;
+/**
+ * <p>Default implementation of JVpp interface.
+ * <br>It was generated by jvpp_impl_gen.py based on $inputfile
+ * <br>(python representation of vpe.api generated by vppapigen).
+ */
public final class JVppImpl implements $base_package.JVpp {
private final $base_package.VppConnection connection;
@@ -82,7 +93,7 @@ no_arg_method_impl_template = Template(""" public final int $name() {
""")
-def generate_jvpp(func_list, base_package, dto_package):
+def generate_jvpp(func_list, base_package, dto_package, inputfile):
""" Generates JVpp interface and JNI implementation """
print "Generating JVpp"
@@ -126,14 +137,16 @@ def generate_jvpp(func_list, base_package, dto_package):
jvpp_file = open("JVpp.java", 'w')
jvpp_file.write(
- jvpp_ifc_template.substitute(methods="\n".join(methods),
+ 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(methods="\n".join(methods_impl),
+ 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()
diff --git a/vpp-api/java/jvpp/gen/util.py b/vpp-api/java/jvpp/gen/util.py
index 17dc2ed90a9..f951bf828d1 100644
--- a/vpp-api/java/jvpp/gen/util.py
+++ b/vpp-api/java/jvpp/gen/util.py
@@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-import os
+import os, pprint
from os import removedirs
@@ -171,3 +171,8 @@ def remove_suffix(camel_case_name_with_suffix, suffix):
def is_control_ping(camel_case_name_with_suffix):
return "controlping" in camel_case_name_with_suffix.lower()
+
+def api_message_to_javadoc(api_message):
+ """ Converts vpe.api message description to javadoc """
+ str = pprint.pformat(api_message, indent=4, width=120, depth=None)
+ return " * " + str.replace("\n", "\n * ") \ No newline at end of file