/*
 * 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.
 */

/*
 * Utilities for accessing Java classes/method/fields in an efficient
 * manner.
 */

/*
 * A potentially-uninitialized reference to a Java class
 */
typedef struct vppjni_class {
    // Fully-Qualified Class Name
    const char          *fqcn;
    // Constructor signature
    const char          *init_sig;
    // Global reference to class handle
    jclass              jclass;
    // Constructor method handle
    jmethodID           jinit;
    // Next item in linked list
    struct vppjni_class *next;
} vppjni_class_t;

typedef struct jenv_field {
    // Field name
    const char           *name;
    // Field type
    const char           *type;
    // Defining class reference
    const vppjni_class_t *clsref;
    // Field handle
    jfieldID             jfield;
    // Next item in linked list
    struct jenv_field    *next;
} vppjni_field_t;

#define VPPJNI_CLASS_SYMBOL(name) vppjni_class_##name
#define VPPJNI_CLASS_INIT(name) vppjni_class_##name##_init
#define BIND_JAPI_CLASS(name, sig) \
    static vppjni_class_t VPPJNI_CLASS_SYMBOL(name); \
    static void VPPJNI_CLASS_INIT(name)(void) __attribute__((__constructor__)); \
    static void VPPJNI_CLASS_INIT(name)() \
    { \
        VPPJNI_CLASS_SYMBOL(name).fqcn = "org/openvpp/vppjapi/" #name; \
        VPPJNI_CLASS_SYMBOL(name).init_sig = sig; \
        vppjni_register_class(&VPPJNI_CLASS_SYMBOL(name)); \
    } \
    static __attribute__((unused)) jobject name##Array(JNIEnv *env, jsize length) \
    { \
        return (*env)->NewObjectArray(env, length, VPPJNI_CLASS_SYMBOL(name).jclass, NULL); \
    } \
    static jobject name##Object(JNIEnv *env, ...) \
    { \
        va_list ap; \
        va_start(ap, env); \
        jobject obj = vppjni_new_object(env, &VPPJNI_CLASS_SYMBOL(name), ap); \
        va_end(ap); \
        return obj; \
    }

#define VPPJNI_FIELD_SYMBOL(cls, name) vppjni_field_##cls##_##name
#define VPPJNI_FIELD_INIT(cls, name) vppjni_field_##cls##_##name##_init
#define BIND_JAPI_FIELD(cls, field, sig) \
    static vppjni_field_t VPPJNI_FIELD_SYMBOL(cls, field); \
        static void VPPJNI_FIELD_INIT(cls, field)(void) __attribute__((__constructor__)); \
    static void VPPJNI_FIELD_INIT(cls, field)() \
    { \
        VPPJNI_FIELD_SYMBOL(cls, field).name = #field; \
        VPPJNI_FIELD_SYMBOL(cls, field).type = sig; \
        VPPJNI_FIELD_SYMBOL(cls, field).clsref = &VPPJNI_CLASS_SYMBOL(cls); \
        vppjni_register_field(&VPPJNI_FIELD_SYMBOL(cls, field)); \
    }
#define BIND_JAPI_BOOL_FIELD(cls, field) \
    BIND_JAPI_FIELD(cls, field, "Z"); \
    static void set_##cls##_##field(JNIEnv *env, jobject obj, jboolean value) \
    { \
        (*env)->SetBooleanField(env, obj, VPPJNI_FIELD_SYMBOL(cls, field).jfield, value); \
    }
#define BIND_JAPI_BYTE_FIELD(cls, field) \
    BIND_JAPI_FIELD(cls, field, "B"); \
    static void set_##cls##_##field(JNIEnv *env, jobject obj, jbyte value) \
    { \
        (*env)->SetByteField(env, obj, VPPJNI_FIELD_SYMBOL(cls, field).jfield, value); \
    }
#define BIND_JAPI_INT_FIELD(cls, field) \
    BIND_JAPI_FIELD(cls, field, "I"); \
    static void set_##cls##_##field(JNIEnv *env, jobject obj, jint value) \
    { \
        (*env)->SetIntField(env, obj, VPPJNI_FIELD_SYMBOL(cls, field).jfield, value); \
    }
#define BIND_JAPI_OBJ_FIELD(cls, field, sig) \
    BIND_JAPI_FIELD(cls, field, sig); \
    static void set_##cls##_##field(JNIEnv *env, jobject obj, jobject value) \
    { \
        (*env)->SetObjectField(env, obj, VPPJNI_FIELD_SYMBOL(cls, field).jfield, value); \
    }
#define BIND_JAPI_STRING_FIELD(cls, field) \
    BIND_JAPI_OBJ_FIELD(cls, field, "Ljava/lang/String;")

jobject vppjni_new_object(JNIEnv *env, const vppjni_class_t *ptr, va_list ap);
void vppjni_register_class(vppjni_class_t *ptr);
void vppjni_register_field(vppjni_field_t *ptr);
int vppjni_init(JNIEnv *env);
void vppjni_uninit(JNIEnv *env);

