tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

ffjni.h (4931B)


      1 /*
      2 * JNI utility functions
      3 *
      4 * Copyright (c) 2015-2016 Matthieu Bouron <matthieu.bouron stupeflix.com>
      5 *
      6 * This file is part of FFmpeg.
      7 *
      8 * FFmpeg is free software; you can redistribute it and/or
      9 * modify it under the terms of the GNU Lesser General Public
     10 * License as published by the Free Software Foundation; either
     11 * version 2.1 of the License, or (at your option) any later version.
     12 *
     13 * FFmpeg is distributed in the hope that it will be useful,
     14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     16 * Lesser General Public License for more details.
     17 *
     18 * You should have received a copy of the GNU Lesser General Public
     19 * License along with FFmpeg; if not, write to the Free Software
     20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
     21 */
     22 
     23 #ifndef AVCODEC_FFJNI_H
     24 #define AVCODEC_FFJNI_H
     25 
     26 #include "jni.h"
     27 #include <stddef.h>
     28 
     29 /*
     30 * Attach permanently a JNI environment to the current thread and retrieve it.
     31 *
     32 * If successfully attached, the JNI environment will automatically be detached
     33 * at thread destruction.
     34 *
     35 * @param attached pointer to an integer that will be set to 1 if the
     36 * environment has been attached to the current thread or 0 if it is
     37 * already attached.
     38 * @param log_ctx context used for logging, can be NULL
     39 * @return the JNI environment on success, NULL otherwise
     40 */
     41 JNIEnv *ff_jni_get_env(void *log_ctx);
     42 
     43 /*
     44 * Convert a jstring to its utf characters equivalent.
     45 *
     46 * @param env JNI environment
     47 * @param string Java string to convert
     48 * @param log_ctx context used for logging, can be NULL
     49 * @return a pointer to an array of unicode characters on success, NULL
     50 * otherwise
     51 */
     52 char *ff_jni_jstring_to_utf_chars(JNIEnv *env, jstring string, void *log_ctx);
     53 
     54 /*
     55 * Convert utf chars to its jstring equivalent.
     56 *
     57 * @param env JNI environment
     58 * @param utf_chars a pointer to an array of unicode characters
     59 * @param log_ctx context used for logging, can be NULL
     60 * @return a Java string object on success, NULL otherwise
     61 */
     62 jstring ff_jni_utf_chars_to_jstring(JNIEnv *env, const char *utf_chars, void *log_ctx);
     63 
     64 /*
     65 * Extract the error summary from a jthrowable in the form of "className: errorMessage"
     66 *
     67 * @param env JNI environment
     68 * @param exception exception to get the summary from
     69 * @param error address pointing to the error, the value is updated if a
     70 * summary can be extracted
     71 * @param log_ctx context used for logging, can be NULL
     72 * @return 0 on success, < 0 otherwise
     73 */
     74 int ff_jni_exception_get_summary(JNIEnv *env, jthrowable exception, char **error, void *log_ctx);
     75 
     76 /*
     77 * Check if an exception has occurred,log it using av_log and clear it.
     78 *
     79 * @param env JNI environment
     80 * @param log value used to enable logging if an exception has occurred,
     81 * 0 disables logging, != 0 enables logging
     82 * @param log_ctx context used for logging, can be NULL
     83 */
     84 int ff_jni_exception_check(JNIEnv *env, int log, void *log_ctx);
     85 
     86 /*
     87 * Jni field type.
     88 */
     89 enum FFJniFieldType {
     90 
     91    FF_JNI_CLASS,
     92    FF_JNI_FIELD,
     93    FF_JNI_STATIC_FIELD,
     94    FF_JNI_METHOD,
     95    FF_JNI_STATIC_METHOD
     96 
     97 };
     98 
     99 /*
    100 * Jni field describing a class, a field or a method to be retrieved using
    101 * the ff_jni_init_jfields method.
    102 */
    103 struct FFJniField {
    104 
    105    const char *name;
    106    const char *method;
    107    const char *signature;
    108    enum FFJniFieldType type;
    109    size_t offset;
    110    int mandatory;
    111 
    112 };
    113 
    114 /*
    115 * Retrieve class references, field ids and method ids to an arbitrary structure.
    116 *
    117 * @param env JNI environment
    118 * @param jfields a pointer to an arbitrary structure where the different
    119 * fields are declared and where the FFJNIField mapping table offsets are
    120 * pointing to
    121 * @param jfields_mapping null terminated array of FFJNIFields describing
    122 * the class/field/method to be retrieved
    123 * @param global make the classes references global. It is the caller
    124 * responsibility to properly release global references.
    125 * @param log_ctx context used for logging, can be NULL
    126 * @return 0 on success, < 0 otherwise
    127 */
    128 int ff_jni_init_jfields(JNIEnv *env, void *jfields, const struct FFJniField *jfields_mapping, int global, void *log_ctx);
    129 
    130 /*
    131 * Delete class references, field ids and method ids of an arbitrary structure.
    132 *
    133 * @param env JNI environment
    134 * @param jfields a pointer to an arbitrary structure where the different
    135 * fields are declared and where the FFJNIField mapping table offsets are
    136 * pointing to
    137 * @param jfields_mapping null terminated array of FFJNIFields describing
    138 * the class/field/method to be deleted
    139 * @param global threat the classes references as global and delete them
    140 * accordingly
    141 * @param log_ctx context used for logging, can be NULL
    142 * @return 0 on success, < 0 otherwise
    143 */
    144 int ff_jni_reset_jfields(JNIEnv *env, void *jfields, const struct FFJniField *jfields_mapping, int global, void *log_ctx);
    145 
    146 #endif /* AVCODEC_FFJNI_H */