From 1362f7d4fe3738c69cdddcd56b009be307019ba8 Mon Sep 17 00:00:00 2001 From: Cheng Zhong Date: Mon, 25 Jan 2016 16:37:53 +0800 Subject: [PATCH] Remove unused header files Removed header files only used in Java-JNI bridge code. --- android/jni/include/jni_utility.h | 313 ------------------------------ android/jni/include/log.h | 37 ---- 2 files changed, 350 deletions(-) delete mode 100644 android/jni/include/jni_utility.h delete mode 100644 android/jni/include/log.h diff --git a/android/jni/include/jni_utility.h b/android/jni/include/jni_utility.h deleted file mode 100644 index 960ebe8..0000000 --- a/android/jni/include/jni_utility.h +++ /dev/null @@ -1,313 +0,0 @@ -/* - * Copyright (C) 2003, 2004, 2005, 2008, 2009, 2010 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef JNIUtility_h -#define JNIUtility_h - -#include -#include -#include -#include -#include - -#include - -#include "log.h" - -#define FIND_CLASS_RETURN_GLOBAL_REF 0x1 -#define FIND_CLASS_USE_CLASS_LOADER 0x2 - -/** - * Helper method for checking java exceptions - * @return true if an exception occurred. - */ -bool checkException(JNIEnv* env); -std::string jstringToStdString(JNIEnv* env, jstring jstr); -jstring stdStringToJstring(JNIEnv* env, const std::string& str); -std::list jstringArrayToStdStringList(jobjectArray jstringArray); -bool jbooleanTobool(jboolean jBoolean); - -JNIEnv* getJNIEnv(); -JavaVM* getJavaVM(); -void setJavaVM(JavaVM*); -jclass findClass(const char* name, int flags = FIND_CLASS_USE_CLASS_LOADER); - -inline std::string jstringToStdString(jstring jstr) -{ - return jstringToStdString(getJNIEnv(), jstr); -} -inline jstring stdStringToJstring(const std::string& str) -{ - return stdStringToJstring(getJNIEnv(), str); -} - -jobjectArray createStringArray(JNIEnv* env, int size); - -template struct JNICaller; - -template<> struct JNICaller { - static void callV(jobject obj, jmethodID mid, va_list args) - { - getJNIEnv()->CallVoidMethodV(obj, mid, args); - } - static void callStaticV(jclass cls, jmethodID mid, va_list args) - { - return getJNIEnv()->CallStaticVoidMethodV(cls, mid, args); - } - static void returnEmpty() - { - } -}; - -#define DEFINE_CALLER_TYPE(_jtype, _jname, _default) \ - template<> struct JNICaller<_jtype> { \ - static _jtype callV(jobject obj, jmethodID mid, va_list args) \ - { \ - return getJNIEnv()->Call##_jname##MethodV(obj, mid, args); \ - } \ - static _jtype get(jobject obj, jfieldID fid) \ - { \ - return getJNIEnv()->Get##_jname##Field(obj, fid); \ - } \ - static void set(jobject obj, jfieldID fid, _jtype value) \ - { \ - getJNIEnv()->Set##_jname##Field(obj, fid, value); \ - } \ - static _jtype callStaticV(jclass cls, jmethodID mid, va_list args) \ - { \ - return getJNIEnv()->CallStatic##_jname##MethodV(cls, mid, args); \ - } \ - static _jtype returnEmpty() \ - { \ - return _default; \ - } \ - }; - - DEFINE_CALLER_TYPE(jobject, Object, 0) - DEFINE_CALLER_TYPE(jboolean, Boolean, false) - DEFINE_CALLER_TYPE(jbyte, Byte, 0) - DEFINE_CALLER_TYPE(jchar, Char, 0) - DEFINE_CALLER_TYPE(jshort, Short, 0) - DEFINE_CALLER_TYPE(jint, Int, 0) - DEFINE_CALLER_TYPE(jlong, Long, 0) - DEFINE_CALLER_TYPE(jfloat, Float, 0) - DEFINE_CALLER_TYPE(jdouble, Double, 0) - - -template<> struct JNICaller { - static std::string callA(jobject obj, jmethodID mid, jvalue* args) - { - jobject jstr = getJNIEnv()->CallObjectMethodA(obj, mid, args); - std::string ret = jstringToStdString(getJNIEnv(), (jstring)jstr); - getJNIEnv()->DeleteLocalRef(jstr); - return ret; - } - static std::string callV(jobject obj, jmethodID mid, va_list args) - { - jobject jstr = getJNIEnv()->CallObjectMethodV(obj, mid, args); - std::string ret = jstringToStdString(getJNIEnv(), (jstring)jstr); - getJNIEnv()->DeleteLocalRef(jstr); - return ret; - } - static std::string get(jobject obj, jfieldID fid) - { - jobject jstr = getJNIEnv()->GetObjectField(obj, fid); - std::string ret = jstringToStdString(getJNIEnv(), (jstring)jstr); - getJNIEnv()->DeleteLocalRef(jstr); - return ret; - } - static void set(jobject obj, jfieldID fid, std::string value) - { - jobject jstr = stdStringToJstring(getJNIEnv(), value); - getJNIEnv()->SetObjectField(obj, fid, jstr); - getJNIEnv()->DeleteLocalRef(jstr); - } - static std::string callStaticV(jclass cls, jmethodID mid, va_list args) - { - jobject jstr = getJNIEnv()->CallStaticObjectMethodV(cls, mid, args); - std::string ret = jstringToStdString(getJNIEnv(), (jstring)jstr); - getJNIEnv()->DeleteLocalRef(jstr); - return ret; - } - static std::string returnEmpty() - { - return std::string(); - } -}; - -template T callJNIMethodIDV(jobject obj, jmethodID mid, va_list args) -{ - return JNICaller::callV(obj, mid, args); -} - -template -static T callJNIMethodV(jobject obj, const char* name, const char* sig, va_list args) -{ - JavaVM* jvm = getJavaVM(); - JNIEnv* env = getJNIEnv(); - - if (obj && jvm && env) { - ScopedLocalRef cls(env, env->GetObjectClass(obj)); - if (cls.get()) { - jmethodID mid = env->GetMethodID(cls.get(), name, sig); - if (mid) { - // Avoids references to cls without popping the local frame. - return JNICaller::callV(obj, mid, args); - } else { - LOGE("Could not find method %s for %p", name, cls.get()); - } - env->ExceptionDescribe(); - } else { - env->ExceptionDescribe(); - LOGE("Could not find class for %p", obj); - } - } - - return JNICaller::returnEmpty(); -} - -template -T callJNIMethod(jobject obj, const char* methodName, const char* methodSignature, ...) -{ - va_list args; - va_start(args, methodSignature); - - T result = callJNIMethodV(obj, methodName, methodSignature, args); - - va_end(args); - - return result; -} - -template -T callJNIMethodID(jobject obj, jmethodID mid, ...) -{ - va_list args; - va_start(args, mid); - - T result = callJNIMethodIDV(obj, mid, args); - - va_end(args); - - return result; -} - -template -T callJNIStaticMethod(jclass cls, jmethodID mid, ...) -{ - va_list args; - va_start(args, mid); - - T result = JNICaller::callStaticV(cls, mid, args); - - va_end(args); - - return result; -} - -template -T callJNIStaticMethod(jclass cls, const char* methodName, const char* methodSignature, ...) -{ - JavaVM* jvm = getJavaVM(); - JNIEnv* env = getJNIEnv(); - va_list args; - - va_start(args, methodSignature); - - if (cls && jvm && env) { - jmethodID mid = env->GetStaticMethodID(cls, methodName, methodSignature); - if (mid) - return JNICaller::callStaticV(cls, mid, args); - else { - env->ExceptionDescribe(); - LOGE("Could not find method: %s for %p", methodName, cls); - } - } - - va_end(args); - - return JNICaller::returnEmpty(); -} - -void callJNIVoidMethod(jobject obj, const char* methodName, const char* methodSignature, ...); -void callJNIVoidMethodID(jobject obj, jmethodID mid, ...); - -void callJNIStaticVoidMethod(const char* className, const char* methodName, const char* methodSignature, ...); - -template -static void setFieldValue(jobject obj, const char* name, const char* sig, T value) -{ - JavaVM* jvm = getJavaVM(); - JNIEnv* env = getJNIEnv(); - - if (obj && jvm && env) { - ScopedLocalRef cls(env, env->GetObjectClass(obj)); - if (cls.get()) { - jfieldID fid = env->GetFieldID(cls.get(), name, sig); - if (fid) { - // Avoids references to cls without popping the local frame. - return JNICaller::set(obj, fid, value); - } else { - LOGE("Could not find field %s for %p", name, cls.get()); - } - env->ExceptionDescribe(); - } else { - env->ExceptionDescribe(); - LOGE("Could not find class for %p", name, obj); - } - } -} - -template -static T getFieldValue(jobject obj, const char* name, const char* sig) -{ - JavaVM* jvm = getJavaVM(); - JNIEnv* env = getJNIEnv(); - - if (obj && jvm && env) { - ScopedLocalRef cls(env, env->GetObjectClass(obj)); - if (cls.get()) { - jfieldID fid = env->GetFieldID(cls.get(), name, sig); - if (fid) { - // Avoids references to cls without popping the local frame. - return JNICaller::get(obj, fid); - } else { - LOGE("Could not find field %s", name); - } - env->ExceptionDescribe(); - } else { - env->ExceptionDescribe(); - LOGE("Could not find class for %p", name, obj); - } - } - return JNICaller::returnEmpty(); -} - -jobject toJavaBoolean(bool value); -jobject toJavaLong(jlong value); -jobject toJavaInt(jint value); -jobject newJavaObject(const char* className); - -#endif // JNIUtility_h diff --git a/android/jni/include/log.h b/android/jni/include/log.h deleted file mode 100644 index fb28d49..0000000 --- a/android/jni/include/log.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef __LOG_H_ -#define __LOG_H_ - -#include - -#define LOG_TAG "serial" - -#if NDK_DEBUG - -#define LOGA(cond,fmt,...) ((cond) ? ((void)0) : __android_log_assert(0, LOG_TAG, fmt, ##__VA_ARGS__)) -#define LOGV(fmt,...) __android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, fmt, ##__VA_ARGS__) -#define LOGD(fmt,...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, fmt, ##__VA_ARGS__) - -#define LOG_ASSERT(cond,fmt,...) ((cond) ? ((void)0) : __android_log_assert(0, tag, fmt, ##__VA_ARGS__)) -#define LOG_VERBOSE(tag,fmt,...) __android_log_print(ANDROID_LOG_VERBOSE, tag, fmt, ##__VA_ARGS__) -#define LOG_DEBUG(tag,fmt,...) __android_log_print(ANDROID_LOG_VERBOSE, tag, fmt, ##__VA_ARGS__) - -#else - -#define LOGA(...) -#define LOGV(...) -#define LOGD(...) - -#define LOG_VERBOSE(...) -#define LOG_DEBUG(...) - -#endif - -#define LOGI(fmt,...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, fmt, ##__VA_ARGS__) -#define LOGW(fmt,...) __android_log_print(ANDROID_LOG_WARN, LOG_TAG, fmt, ##__VA_ARGS__) -#define LOGE(fmt,...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, fmt, ##__VA_ARGS__) - -#define LOG_INFO(tag,fmt,...) __android_log_print(ANDROID_LOG_INFO, tag, fmt, ##__VA_ARGS__) -#define LOG_WARN(tag,fmt,...) __android_log_print(ANDROID_LOG_WARN, tag, fmt, ##__VA_ARGS__) -#define LOG_ERROR(tag,fmt,...) __android_log_print(ANDROID_LOG_ERROR, tag, fmt, ##__VA_ARGS__) - -#endif