return JNI_ERR;
}""")
+find_class_template = Template("""
+ ${ref_name}Class = (jclass)(*env)->NewGlobalRef(env, (*env)->FindClass(env, "${class_name}"));
+ if ((*env)->ExceptionCheck(env)) {
+ (*env)->ExceptionDescribe(env);
+ return JNI_ERR;
+ }""")
+
class_cache_template = Template("""
$class_references
static int cache_class_references(JNIEnv* env) {
ref_name=ref_name,
class_name=class_name))
+ # add exception class to class cache
+ ref_name = 'callbackException'
+ class_name = 'org/openvpp/jvpp/VppCallbackException'
+ class_references.append(class_reference_template.substitute(
+ ref_name=ref_name))
+ find_class_invocations.append(find_class_template.substitute(
+ ref_name=ref_name,
+ class_name=class_name))
return class_cache_template.substitute(
class_references="".join(class_references), find_class_invocations="".join(find_class_invocations))
mp->context = clib_host_to_net_u32 (my_context_id);
$struct_setters
S;
+ if ((*env)->ExceptionCheck(env)) {
+ return JNI_ERR;
+ }
return my_context_id;
}""")
'u64[]': u64_array_dto_field_setter_template
}
+# code fragment for checking result of the operation before sending request reply
+callback_err_handler_template = Template("""
+ // for negative result don't send callback message but send error callback
+ if (mp->retval<0) {
+ CallOnError("${handler_name}",mp->context,mp->retval);
+ return;
+ }
+ if (mp->retval == VNET_API_ERROR_IN_PROGRESS) {
+ clib_warning("Result in progress");
+ return;
+ }
+""")
+
msg_handler_template = Template("""
/**
* Handler for ${handler_name} vpe.api message.
{
vppjni_main_t * jm = &vppjni_main;
JNIEnv *env = jm->jenv;
+ $err_handler
jmethodID constructor = (*env)->GetMethodID(env, ${class_ref_name}Class, "<init>", "()V");
jmethodID callbackMethod = (*env)->GetMethodID(env, jm->callbackClass, "on${dto_name}", "(Lorg/openvpp/jvpp/dto/${dto_name};)V");
continue
dto_setters = ''
+ err_handler = ''
# dto setters
for t in zip(f['c_types'], f['types'], f['args'], f['lengths']):
c_type = t[0]
c_name = t[2]
field_length = t[3]
+ # for retval don't generate setters and generate retval check
+ if util.is_retval_field(c_name):
+ err_handler = callback_err_handler_template.substitute(
+ handler_name=handler_name
+ )
+ continue
+
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]
field_length=field_length)
handlers.append(msg_handler_template.substitute(
- inputfile=inputfile,
- api_data=util.api_message_to_javadoc(f),
- handler_name=handler_name,
- dto_name=dto_name,
- class_ref_name=ref_name,
- dto_setters=dto_setters))
+ inputfile=inputfile,
+ api_data=util.api_message_to_javadoc(f),
+ handler_name=handler_name,
+ dto_name=dto_name,
+ class_ref_name=ref_name,
+ dto_setters=dto_setters,
+ err_handler=err_handler))
return "\n".join(handlers)
* (python representation of vpe.api generated by vppapigen).
*/
+void CallOnError(const char* call, int context, int retval);
+
// JAVA class reference cache
$class_cache
jvpp_c_file.flush()
jvpp_c_file.close()
-