diff options
author | Ole Troan <ot@cisco.com> | 2018-11-28 11:36:05 +0100 |
---|---|---|
committer | Neale Ranns <nranns@cisco.com> | 2018-12-13 12:11:50 +0000 |
commit | 413f4a5b2123c1625d615315db293a080078482b (patch) | |
tree | 6cfd8376c1d84b93793b062731ec9594487dc95e /extras/japi/java/jvpp/gen | |
parent | 6f666ad99ae1e384aa851af5e0feed3d2a25e709 (diff) |
API: Use string type instead of u8.
The new string type is modelled after string in proto3.
It is always variable length.
Change-Id: I64884067e28a80072c8dac31b7c7c82d6e306051
Signed-off-by: Ole Troan <ot@cisco.com>
Signed-off-by: Michal Cmarada <mcmarada@cisco.com>
Signed-off-by: Ole Troan <ot@cisco.com>
Diffstat (limited to 'extras/japi/java/jvpp/gen')
8 files changed, 39 insertions, 18 deletions
diff --git a/extras/japi/java/jvpp/gen/jvppgen/dto_gen.py b/extras/japi/java/jvpp/gen/jvppgen/dto_gen.py index ca015a30456..cbd969d51fe 100755 --- a/extras/japi/java/jvpp/gen/jvppgen/dto_gen.py +++ b/extras/japi/java/jvpp/gen/jvppgen/dto_gen.py @@ -221,7 +221,7 @@ public final class ${details_class}ReplyDump implements io.fd.vpp.jvpp.dto.JVppR } @Override - public String toString() { + public java.lang.String toString() { return "${details_class}ReplyDump{" + "${details_field}=" + ${details_field} + "}"; } diff --git a/extras/japi/java/jvpp/gen/jvppgen/jni_common_gen.py b/extras/japi/java/jvpp/gen/jvppgen/jni_common_gen.py index 708cc1cba81..b52e5ff2d2c 100755 --- a/extras/japi/java/jvpp/gen/jvppgen/jni_common_gen.py +++ b/extras/japi/java/jvpp/gen/jvppgen/jni_common_gen.py @@ -165,6 +165,7 @@ def _generate_field_length_check(field): else: return "" + # Make sure we do not write more elements that are expected _FIELD_LENGTH_CHECK = Template(""" size_t max_size = ${field_length}; @@ -177,9 +178,13 @@ def _generate_j2c_scalar_swap(field, struct_ref_name, is_alias): host = field.java_name if not is_alias: net = "%s->%s" % (struct_ref_name, field.name) - return " %s;" % field_type.get_host_to_net_function(host, net) + if field_type.name == "string": + net = "%s->%s" % (struct_ref_name, field.name) + return " _host_to_net_%s(env, %s, (vl_api_string_t *) &%s);" % (field_type.name, host, net) + else: + return " %s;" % field_type.get_host_to_net_function(host, net) else: - net = "%s" % (struct_ref_name) + net = "%s" % struct_ref_name return " *%s;" % field_type.get_host_to_net_function(host, net) else: return " %s->%s = %s;" % (struct_ref_name, field.name, field.java_name) @@ -424,7 +429,10 @@ _C2J_ENUM_SWAP_TEMPLATE = Template(""" def _generate_c2j_primitive_type_swap(msg_java_name, field, object_ref_name, struct_ref_name, is_alias): field_type = field.type if not is_alias: - template = _C2J_PRIMITIVE_TYPE_SWAP_TEMPLATE + if field_type.name == "string": + template = _C2J_STRING_TYPE_SWAP_TEMPLATE + else: + template = _C2J_PRIMITIVE_TYPE_SWAP_TEMPLATE else: template = _C2J_ALIAS_PRIMITIVE_TYPE_SWAP_TEMPLATE return template.substitute( @@ -444,6 +452,12 @@ _C2J_PRIMITIVE_TYPE_SWAP_TEMPLATE = Template(""" """) +_C2J_STRING_TYPE_SWAP_TEMPLATE = Template(""" + jfieldID ${java_name}FieldId = (*env)->GetFieldID(env, ${class_ref_name}Class, "${java_name}", "${jni_signature}"); + (*env)->Set${jni_accessor}Field(env, ${object_ref_name}, ${java_name}FieldId, ${net_to_host_function}(env, (const vl_api_string_t *) &${struct_ref_name}->${c_name})); +""") + + _C2J_ALIAS_PRIMITIVE_TYPE_SWAP_TEMPLATE = Template(""" jfieldID ${java_name}FieldId = (*env)->GetFieldID(env, ${class_ref_name}Class, "${java_name}", "${jni_signature}"); (*env)->Set${jni_accessor}Field(env, ${object_ref_name}, ${java_name}FieldId, ${net_to_host_function}(*${struct_ref_name})); diff --git a/extras/japi/java/jvpp/gen/jvppgen/jvpp_callback_facade_gen.py b/extras/japi/java/jvpp/gen/jvppgen/jvpp_callback_facade_gen.py index c5634de2e48..ebc552bfda6 100644 --- a/extras/japi/java/jvpp/gen/jvppgen/jvpp_callback_facade_gen.py +++ b/extras/japi/java/jvpp/gen/jvppgen/jvpp_callback_facade_gen.py @@ -210,7 +210,7 @@ public final class CallbackJVpp${plugin_name}FacadeCallback implements $plugin_p failedCall.onError(reply); } catch(RuntimeException ex) { ex.addSuppressed(reply); - LOG.log(java.util.logging.Level.WARNING, String.format("Callback: %s failed while handling exception: %s", failedCall, reply), ex); + LOG.log(java.util.logging.Level.WARNING, java.lang.String.format("Callback: %s failed while handling exception: %s", failedCall, reply), ex); } } } @@ -265,7 +265,7 @@ _CALLBACK_METHOD_TEMPLATE = Template(""" $plugin_package.callback.$callback callback; final int replyId = reply.context; if (LOG.isLoggable(java.util.logging.Level.FINE)) { - LOG.fine(String.format("Received ${message} event message: %s", reply)); + LOG.fine(java.lang.String.format("Received ${message} event message: %s", reply)); } synchronized(requests) { callback = ($plugin_package.callback.$callback) requests.remove(replyId); @@ -282,7 +282,7 @@ _CALLBACK_EVENT_METHOD_TEMPLATE = Template(""" @SuppressWarnings("unchecked") public void on${message}($plugin_package.dto.${message} notification) { if (LOG.isLoggable(java.util.logging.Level.FINE)) { - LOG.fine(String.format("Received ${message} event message: %s", notification)); + LOG.fine(java.lang.String.format("Received ${message} event message: %s", notification)); } eventCallback.on${message}(notification); } diff --git a/extras/japi/java/jvpp/gen/jvppgen/jvpp_common_gen.py b/extras/japi/java/jvpp/gen/jvppgen/jvpp_common_gen.py index 83226ea78ac..499adbc3f56 100755 --- a/extras/japi/java/jvpp/gen/jvppgen/jvpp_common_gen.py +++ b/extras/japi/java/jvpp/gen/jvppgen/jvpp_common_gen.py @@ -103,7 +103,7 @@ def generate_to_string(class_name, fields): _TO_STRING_TEMPLATE = Template(""" @Override - public String toString() { + public java.lang.String toString() { return "$class_name{" + $to_string_fields }""") diff --git a/extras/japi/java/jvpp/gen/jvppgen/jvpp_future_facade_gen.py b/extras/japi/java/jvpp/gen/jvppgen/jvpp_future_facade_gen.py index 47a9985144d..3da367a4d5f 100644 --- a/extras/japi/java/jvpp/gen/jvppgen/jvpp_future_facade_gen.py +++ b/extras/japi/java/jvpp/gen/jvppgen/jvpp_future_facade_gen.py @@ -280,7 +280,7 @@ _FUTURE_JVPP_FACADE_DETAILS_CALLBACK_TEMPLATE = Template(""" io.fd.vpp.jvpp.future.AbstractFutureJVppInvoker.CompletableDumpFuture<$plugin_package.dto.${callback_dto}ReplyDump> completableFuture; final int replyId = reply.context; if (LOG.isLoggable(java.util.logging.Level.FINE)) { - LOG.fine(String.format("Received $callback_dto event message: %s", reply)); + LOG.fine(java.lang.String.format("Received $callback_dto event message: %s", reply)); } synchronized(requests) { completableFuture = (io.fd.vpp.jvpp.future.AbstractFutureJVppInvoker.CompletableDumpFuture<$plugin_package.dto.${callback_dto}ReplyDump>) requests.get(replyId); @@ -305,7 +305,7 @@ _FUTURE_JVPP_FACADE_REPLY_CALLBACK_TEMPLATE = Template(""" java.util.concurrent.CompletableFuture<io.fd.vpp.jvpp.dto.JVppReply<$plugin_package.dto.$request_dto>> completableFuture; final int replyId = reply.context; if (LOG.isLoggable(java.util.logging.Level.FINE)) { - LOG.fine(String.format("Received $callback_dto event message: %s", reply)); + LOG.fine(java.lang.String.format("Received $callback_dto event message: %s", reply)); } synchronized(requests) { completableFuture = @@ -331,7 +331,7 @@ _FUTURE_JVPP_FACADE_EVENT_CALLBACK_TEMPLATE = Template(""" @Override public void on$callback_dto($plugin_package.dto.$callback_dto notification) { if (LOG.isLoggable(java.util.logging.Level.FINE)) { - LOG.fine(String.format("Received $callback_dto event message: %s", notification)); + LOG.fine(java.lang.String.format("Received $callback_dto event message: %s", notification)); } notificationCallback.on$callback_dto(notification); } diff --git a/extras/japi/java/jvpp/gen/jvppgen/jvpp_impl_gen.py b/extras/japi/java/jvpp/gen/jvppgen/jvpp_impl_gen.py index aff8d7fc99c..376952b620e 100755 --- a/extras/japi/java/jvpp/gen/jvppgen/jvpp_impl_gen.py +++ b/extras/japi/java/jvpp/gen/jvppgen/jvpp_impl_gen.py @@ -74,7 +74,7 @@ import io.fd.vpp.jvpp.JVppRegistry; public final class JVpp${plugin_name}Impl implements $plugin_package.JVpp${plugin_name} { private final static Logger LOG = Logger.getLogger(JVpp${plugin_name}Impl.class.getName()); - private static final String LIBNAME = "libjvpp_${plugin_name_underscore}.so"; + private static final java.lang.String LIBNAME = "libjvpp_${plugin_name_underscore}.so"; // FIXME using NativeLibraryLoader makes load fail could not find (WantInterfaceEventsReply). static { @@ -151,7 +151,7 @@ _JVPP_IMPL_METHOD_TEMPLATE = Template(""" java.util.Objects.requireNonNull(request, "Null request object"); connection.checkActive(); if (LOG.isLoggable(Level.FINE)) { - LOG.fine(String.format("Sending $type event message: %s", request)); + LOG.fine(java.lang.String.format("Sending $type event message: %s", request)); } int result=${name}0(request); if (result<0){ diff --git a/extras/japi/java/jvpp/gen/jvppgen/jvpp_model.py b/extras/japi/java/jvpp/gen/jvppgen/jvpp_model.py index 16099689880..da1e01f5a63 100755 --- a/extras/japi/java/jvpp/gen/jvppgen/jvpp_model.py +++ b/extras/japi/java/jvpp/gen/jvppgen/jvpp_model.py @@ -92,9 +92,11 @@ class SimpleType(Type): # TODO(VPP-1187): add array host to net functions to reduce number of members and simplify JNI generation class Array(Type): - def __init__(self, base_type): + def __init__(self, base_type, name=None): + if name is None: + name = base_type.name + _ARRAY_SUFFIX super(Array, self).__init__( - name=base_type.name + _ARRAY_SUFFIX, + name=name, java_name=base_type.java_name + _ARRAY_SUFFIX, java_name_fqn=base_type.java_name_fqn + _ARRAY_SUFFIX, jni_signature="[%s" % base_type.jni_signature, @@ -341,6 +343,8 @@ class JVppModel(object): self._parse_types(types) def _parse_aliases(self, types): + + # model aliases for alias_name in self._aliases: alias = self._aliases[alias_name] alias_type = {"type": "type"} @@ -442,7 +446,10 @@ class JVppModel(object): 'i64': SimpleType('i64', 'long', 'J', 'jlong', 'Long', host_to_net_function='clib_host_to_net_i64', net_to_host_function='clib_net_to_host_i64'), - 'f64': SimpleType('f64', 'double', 'D', 'jdouble', 'Double') + 'f64': SimpleType('f64', 'double', 'D', 'jdouble', 'Double'), + 'string': SimpleType('string', 'String', 'l', 'jstring', 'Object', + host_to_net_function='_host_to_net_string', + net_to_host_function='_net_to_host_string') }) for n, t in self._types_by_name.items(): diff --git a/extras/japi/java/jvpp/gen/jvppgen/notification_gen.py b/extras/japi/java/jvpp/gen/jvppgen/notification_gen.py index 69e870ed33d..fa86fe4bbf2 100644 --- a/extras/japi/java/jvpp/gen/jvppgen/notification_gen.py +++ b/extras/japi/java/jvpp/gen/jvppgen/notification_gen.py @@ -117,7 +117,7 @@ _HANDLER_IMPL_TEMPLATE = Template(""" public void on$notification( final $plugin_package.dto.$notification notification) { if (LOG.isLoggable(java.util.logging.Level.FINE)) { - LOG.fine(String.format("Received $notification event message: %s", notification)); + LOG.fine(java.lang.String.format("Received $notification event message: %s", notification)); } final io.fd.vpp.jvpp.callback.JVppCallback jVppCallback = registeredCallbacks.get($plugin_package.dto.$notification.class); if (null != jVppCallback) { @@ -153,7 +153,7 @@ public final class ${plugin_name}EventRegistryImpl implements ${plugin_name}Even @Override public void onError(io.fd.vpp.jvpp.VppCallbackException ex) { java.util.logging.Logger LOG = java.util.logging.Logger.getLogger(${plugin_name}EventRegistryImpl.class.getName()); - LOG.log(java.util.logging.Level.WARNING, String.format("Received onError exception: call=%s, context=%d, retval=%d%n", ex.getMethodName(), + LOG.log(java.util.logging.Level.WARNING, java.lang.String.format("Received onError exception: call=%s, context=%d, retval=%d%n", ex.getMethodName(), ex.getCtxId(), ex.getErrorCode()), ex); } } |