summaryrefslogtreecommitdiffstats
path: root/nsh-plugin
diff options
context:
space:
mode:
authorMarek Gradzki <mgradzki@cisco.com>2016-11-03 14:02:20 +0100
committerMarek Gradzki <mgradzki@cisco.com>2016-11-03 14:02:25 +0100
commitad43a56f743f8fe133b06c1d4477078daae984f4 (patch)
treeb6c819009a6783572313e9df68b521d261920212 /nsh-plugin
parente556e7c0272b37a695c38549ead57ba002ff2c01 (diff)
Fail to register Java API for nsh plugin if it was not loaded (VPP-522)
Change-Id: I8746a89b1f7f146d23c40154936aa0ac7f121bae Signed-off-by: Marek Gradzki <mgradzki@cisco.com>
Diffstat (limited to 'nsh-plugin')
-rw-r--r--nsh-plugin/java/jvpp/jvpp_nsh.c39
1 files changed, 22 insertions, 17 deletions
diff --git a/nsh-plugin/java/jvpp/jvpp_nsh.c b/nsh-plugin/java/jvpp/jvpp_nsh.c
index 06f5fb0..cc8bcb7 100644
--- a/nsh-plugin/java/jvpp/jvpp_nsh.c
+++ b/nsh-plugin/java/jvpp/jvpp_nsh.c
@@ -52,28 +52,33 @@
*/
JNIEXPORT void JNICALL Java_io_fd_vpp_jvpp_nsh_JVppNshImpl_init0
(JNIEnv *env, jclass clazz, jobject callback, jlong queue_address, jint my_client_index) {
- nsh_main_t * plugin_main = &nsh_main;
- u8 * name;
- clib_warning ("Java_io_fd_vpp_jvpp_nsh_JVppNshImpl_init0");
+ nsh_main_t * plugin_main = &nsh_main;
+ u8 * name;
+ clib_warning ("Java_io_fd_vpp_jvpp_nsh_JVppNshImpl_init0");
- plugin_main->my_client_index = my_client_index;
- plugin_main->vl_input_queue = (unix_shared_memory_queue_t *)queue_address;
+ plugin_main->my_client_index = my_client_index;
+ plugin_main->vl_input_queue = (unix_shared_memory_queue_t *)queue_address;
name = format (0, "nsh_%08x%c", api_version, 0);
plugin_main->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
- plugin_main->callbackObject = (*env)->NewGlobalRef(env, callback);
- plugin_main->callbackClass = (jclass)(*env)->NewGlobalRef(env, (*env)->GetObjectClass(env, callback));
-
- #define _(N,n) \
- vl_msg_api_set_handlers(VL_API_##N + plugin_main->msg_id_base, #n, \
- vl_api_##n##_t_handler, \
- vl_noop_handler, \
- vl_api_##n##_t_endian, \
- vl_api_##n##_t_print, \
- sizeof(vl_api_##n##_t), 1);
- foreach_api_reply_handler;
- #undef _
+ if (plugin_main->msg_id_base == (u16) ~0) {
+ jclass exClass = (*env)->FindClass(env, "java/lang/IllegalStateException");
+ (*env)->ThrowNew(env, exClass, "nsh plugin is not loaded in VPP");
+ } else {
+ plugin_main->callbackObject = (*env)->NewGlobalRef(env, callback);
+ plugin_main->callbackClass = (jclass)(*env)->NewGlobalRef(env, (*env)->GetObjectClass(env, callback));
+
+ #define _(N,n) \
+ vl_msg_api_set_handlers(VL_API_##N + plugin_main->msg_id_base, #n, \
+ vl_api_##n##_t_handler, \
+ vl_noop_handler, \
+ vl_api_##n##_t_endian, \
+ vl_api_##n##_t_print, \
+ sizeof(vl_api_##n##_t), 1);
+ foreach_api_reply_handler;
+ #undef _
+ }
}
JNIEXPORT void JNICALL Java_io_fd_vpp_jvpp_nsh_JVppNshImpl_close0