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.
17 #include "vppjni_env.h"
19 // Head of the class registration list.
20 static vppjni_class_t *class_head;
21 // Head of the class registration list.
22 static vppjni_field_t *field_head;
24 void vppjni_init_register_class(vppjni_class_t *ptr)
26 vppjni_class_t **where = &class_head;
27 while (*where != NULL) {
28 where = &((*where)->next);
33 void vppjni_register_field(vppjni_field_t *ptr) {
34 vppjni_field_t **where = &field_head;
35 while (*where != NULL) {
36 where = &((*where)->next);
41 jobject vppjni_init_new_object(JNIEnv *env, const vppjni_class_t *ptr, va_list ap) {
42 jobject obj = (*env)->NewObjectV(env, ptr->jclass, ptr->jinit, ap);
43 if ((*env)->ExceptionCheck(env)) {
44 (*env)->ExceptionDescribe(env);
51 int vppjni_env_init(JNIEnv *env)
56 for (cwlk = class_head; cwlk != NULL; cwlk = cwlk->next) {
60 cls = (*env)->FindClass(env, cwlk->fqcn);
61 if ((*env)->ExceptionCheck(env)) {
62 (*env)->ExceptionDescribe(env);
67 method = (*env)->GetMethodID(env, cls, "<init>", cwlk->init_sig);
68 if ((*env)->ExceptionCheck(env)) {
69 (*env)->ExceptionDescribe(env);
74 cwlk->jclass = (*env)->NewGlobalRef(env, cls);
75 if (cwlk->jclass == NULL) {
82 for (fwlk = field_head; fwlk != NULL; fwlk = fwlk->next) {
83 fwlk->jfield = (*env)->GetFieldID(env, fwlk->clsref->jclass, fwlk->name, fwlk->type);
84 if ((*env)->ExceptionCheck(env)) {
85 (*env)->ExceptionDescribe(env);
94 void vppjni_env_uninit(JNIEnv *env) {
98 for (fwlk = field_head; fwlk != NULL; fwlk = fwlk->next) {
102 for (cwlk = class_head; cwlk != NULL; cwlk = cwlk->next) {
103 if (cwlk->jclass != NULL ) {
104 (*env)->DeleteGlobalRef(env, cwlk->jclass);