2 * Copyright (c) 2016 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
16 #include <vnet/vnet.h>
18 #define vl_typedefs /* define message structures */
19 #include <nsh/nsh.api.h>
22 #include <vnet/api_errno.h>
23 #include <vlibapi/api.h>
24 #include <vlibmemory/api.h>
27 #define DEBUG_LOG(...) clib_warning(__VA_ARGS__)
29 #define DEBUG_LOG(...)
32 #include <jvpp-common/jvpp_common.h>
34 #include "jvpp-nsh/io_fd_vpp_jvpp_nsh_JVppNshImpl.h"
36 #include "jvpp-nsh/jvpp_nsh_gen.h"
39 * Class: io_fd_vpp_jvpp_nsh_JVppnshImpl
43 JNIEXPORT void JNICALL Java_io_fd_vpp_jvpp_nsh_JVppNshImpl_init0
44 (JNIEnv *env, jclass clazz, jobject callback, jlong queue_address, jint my_client_index) {
45 nsh_main_t * plugin_main = &nsh_main;
46 clib_warning ("Java_io_fd_vpp_jvpp_nsh_JVppNshImpl_init0");
48 plugin_main->my_client_index = my_client_index;
49 plugin_main->vl_input_queue = (svm_queue_t *)queue_address;
51 plugin_main->callbackObject = (*env)->NewGlobalRef(env, callback);
52 plugin_main->callbackClass = (jclass)(*env)->NewGlobalRef(env, (*env)->GetObjectClass(env, callback));
54 // verify API has not changed since jar generation
56 if (get_message_id(env, #N) == 0) return;
57 foreach_supported_api_message;
61 vl_msg_api_set_handlers(get_message_id(env, #N), #n, \
62 vl_api_##n##_t_handler, \
66 sizeof(vl_api_##n##_t), 1);
67 foreach_api_reply_handler;
71 JNIEXPORT void JNICALL Java_io_fd_vpp_jvpp_nsh_JVppNshImpl_close0
72 (JNIEnv *env, jclass clazz) {
73 nsh_main_t * plugin_main = &nsh_main;
76 (*env)->DeleteGlobalRef(env, plugin_main->callbackClass);
77 (*env)->DeleteGlobalRef(env, plugin_main->callbackObject);
79 plugin_main->callbackClass = NULL;
80 plugin_main->callbackObject = NULL;
83 /* Attach thread to JVM and cache class references when initiating JVPP ACL */
84 jint JNI_OnLoad(JavaVM *vm, void *reserved) {
87 if ((*vm)->GetEnv(vm, (void**) &env, JNI_VERSION_1_8) != JNI_OK) {
91 if (cache_class_references(env) != 0) {
92 clib_warning ("Failed to cache class references\n");
96 return JNI_VERSION_1_8;
99 /* Clean up cached references when disposing JVPP ACL */
100 void JNI_OnUnload(JavaVM *vm, void *reserved) {
102 if ((*vm)->GetEnv(vm, (void**) &env, JNI_VERSION_1_8) != JNI_OK) {
105 delete_class_references(env);