summaryrefslogtreecommitdiffstats
path: root/vpp-japi/japi/vppjni_env.c
diff options
context:
space:
mode:
authorOle Troan <ot@cisco.com>2016-04-09 03:16:30 +0200
committerDave Wallace <dwallacelf@gmail.com>2016-04-20 16:50:29 +0000
commit6855f6cdfee8c479f1e0ae440ce87a91ff41a708 (patch)
treee438e21c8107a675dc3a3141c6af6ba0ab458992 /vpp-japi/japi/vppjni_env.c
parent633951c3d8dc1640813b4778f3e35463d08f3795 (diff)
Python-API: Inital commit of Python bindings for the VPP API.
See: https://wiki.fd.io/view/VPP/Python_API Change-Id: If135fc32208c7031787e1935b399d930e0e1ea1f Signed-off-by: Ole Troan <ot@cisco.com>
Diffstat (limited to 'vpp-japi/japi/vppjni_env.c')
-rw-r--r--vpp-japi/japi/vppjni_env.c111
1 files changed, 0 insertions, 111 deletions
diff --git a/vpp-japi/japi/vppjni_env.c b/vpp-japi/japi/vppjni_env.c
deleted file mode 100644
index 1c4ea6ebe18..00000000000
--- a/vpp-japi/japi/vppjni_env.c
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Copyright (c) 2016 Cisco and/or its affiliates.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#include <jni.h>
-
-#include "vppjni_env.h"
-
-// Head of the class registration list.
-static vppjni_class_t *class_head;
-// Head of the class registration list.
-static vppjni_field_t *field_head;
-
-void vppjni_register_class(vppjni_class_t *ptr)
-{
- vppjni_class_t **where = &class_head;
- while (*where != NULL) {
- where = &((*where)->next);
- }
- *where = ptr;
-}
-
-void vppjni_register_field(vppjni_field_t *ptr) {
- vppjni_field_t **where = &field_head;
- while (*where != NULL) {
- where = &((*where)->next);
- }
- *where = ptr;
-}
-
-jobject vppjni_new_object(JNIEnv *env, const vppjni_class_t *ptr, va_list ap) {
- jobject obj = (*env)->NewObjectV(env, ptr->jclass, ptr->jinit, ap);
- if ((*env)->ExceptionCheck(env)) {
- (*env)->ExceptionDescribe(env);
- return NULL;
- }
-
- return obj;
-}
-
-int vppjni_init(JNIEnv *env)
-{
- vppjni_class_t *cwlk;
- vppjni_field_t *fwlk;
-
- for (cwlk = class_head; cwlk != NULL; cwlk = cwlk->next) {
- jclass cls;
- jmethodID method;
-
- cls = (*env)->FindClass(env, cwlk->fqcn);
- if ((*env)->ExceptionCheck(env)) {
- (*env)->ExceptionDescribe(env);
- vppjni_uninit(env);
- return JNI_ERR;
- }
-
- method = (*env)->GetMethodID(env, cls, "<init>", cwlk->init_sig);
- if ((*env)->ExceptionCheck(env)) {
- (*env)->ExceptionDescribe(env);
- vppjni_uninit(env);
- return JNI_ERR;
- }
-
- cwlk->jclass = (*env)->NewGlobalRef(env, cls);
- if (cwlk->jclass == NULL) {
- vppjni_uninit(env);
- return JNI_ERR;
- }
- cwlk->jinit = method;
- }
-
- for (fwlk = field_head; fwlk != NULL; fwlk = fwlk->next) {
- fwlk->jfield = (*env)->GetFieldID(env, fwlk->clsref->jclass, fwlk->name, fwlk->type);
- if ((*env)->ExceptionCheck(env)) {
- (*env)->ExceptionDescribe(env);
- vppjni_uninit(env);
- return JNI_ERR;
- }
- }
-
- return 0;
-}
-
-void vppjni_uninit(JNIEnv *env) {
- vppjni_class_t *cwlk;
- vppjni_field_t *fwlk;
-
- for (fwlk = field_head; fwlk != NULL; fwlk = fwlk->next) {
- fwlk->jfield = NULL;
- }
-
- for (cwlk = class_head; cwlk != NULL; cwlk = cwlk->next) {
- if (cwlk->jclass != NULL ) {
- (*env)->DeleteGlobalRef(env, cwlk->jclass);
- }
-
- cwlk->jclass = NULL;
- cwlk->jinit = NULL;
- }
-}
-