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 #include <ioam/export/ioam_export_msg_enum.h>
19 #define vl_typedefs /* define message structures */
20 #include <ioam/export/ioam_export_all_api_h.h>
23 #include <vnet/api_errno.h>
24 #include <vlibapi/api.h>
25 #include <vlibmemory/api.h>
28 #define DEBUG_LOG(...) clib_warning(__VA_ARGS__)
30 #define DEBUG_LOG(...)
33 #include <jvpp-common/jvpp_common.h>
35 #include "jvpp-ioamexport/io_fd_vpp_jvpp_ioamexport_JVppIoamexportImpl.h"
36 #include "jvpp_ioam_export.h"
37 #include "jvpp-ioamexport/jvpp_ioamexport_gen.h"
40 * Class: io_fd_vpp_jvpp_ioamexport_JVppIoamexportImpl
44 JNIEXPORT void JNICALL Java_io_fd_vpp_jvpp_ioamexport_JVppIoamexportImpl_init0
45 (JNIEnv *env, jclass clazz, jobject callback, jlong queue_address, jint my_client_index) {
46 ioamexport_main_t * plugin_main = &ioamexport_main;
47 clib_warning ("Java_io_fd_vpp_jvpp_ioamexport_JVppIoamexportImpl_init0");
49 plugin_main->my_client_index = my_client_index;
50 plugin_main->vl_input_queue = uword_to_pointer (queue_address, svm_queue_t *);
52 plugin_main->callbackObject = (*env)->NewGlobalRef(env, callback);
53 plugin_main->callbackClass = (jclass)(*env)->NewGlobalRef(env, (*env)->GetObjectClass(env, callback));
55 // verify API has not changed since jar generation
57 if (get_message_id(env, #N) == 0) return;
58 foreach_supported_api_message;
62 vl_msg_api_set_handlers(get_message_id(env, #N), #n, \
63 vl_api_##n##_t_handler, \
67 sizeof(vl_api_##n##_t), 1);
68 foreach_api_reply_handler;
72 JNIEXPORT void JNICALL Java_io_fd_vpp_jvpp_ioamexport_JVppIoamexportImpl_close0
73 (JNIEnv *env, jclass clazz) {
74 ioamexport_main_t * plugin_main = &ioamexport_main;
77 (*env)->DeleteGlobalRef(env, plugin_main->callbackClass);
78 (*env)->DeleteGlobalRef(env, plugin_main->callbackObject);
80 plugin_main->callbackClass = NULL;
81 plugin_main->callbackObject = NULL;
84 /* Attach thread to JVM and cache class references when initiating JVPP iOAM EXPORT */
85 jint JNI_OnLoad(JavaVM *vm, void *reserved) {
88 if ((*vm)->GetEnv(vm, (void**) &env, JNI_VERSION_1_8) != JNI_OK) {
92 if (cache_class_references(env) != 0) {
93 clib_warning ("Failed to cache class references\n");
97 return JNI_VERSION_1_8;
100 /* Clean up cached references when disposing JVPP iOAM EXPORT */
101 void JNI_OnUnload(JavaVM *vm, void *reserved) {
103 if ((*vm)->GetEnv(vm, (void**) &env, JNI_VERSION_1_8) != JNI_OK) {
106 delete_class_references(env);