j4a_base.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * copyright (c) 2015 Zhang Rui <bbcallen@gmail.com>
  3. *
  4. * This file is part of jni4android.
  5. *
  6. * jni4android is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * jni4android is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with jni4android; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #ifndef J4A_BASE_H
  21. #define J4A_BASE_H
  22. #include <string.h>
  23. #include <stdbool.h>
  24. #include <stdint.h>
  25. #include <jni.h>
  26. #include <android/log.h>
  27. #ifndef J4A_UNUSED
  28. #define J4A_UNUSED(x) x __attribute__((unused))
  29. #endif
  30. #define J4A_LOG_TAG "J4A"
  31. #define J4A_VLOGV(...) __android_log_vprint(ANDROID_LOG_VERBOSE, J4A_LOG_TAG, __VA_ARGS__)
  32. #define J4A_VLOGD(...) __android_log_vprint(ANDROID_LOG_DEBUG, J4A_LOG_TAG, __VA_ARGS__)
  33. #define J4A_VLOGI(...) __android_log_vprint(ANDROID_LOG_INFO, J4A_LOG_TAG, __VA_ARGS__)
  34. #define J4A_VLOGW(...) __android_log_vprint(ANDROID_LOG_WARN, J4A_LOG_TAG, __VA_ARGS__)
  35. #define J4A_VLOGE(...) __android_log_vprint(ANDROID_LOG_ERROR, J4A_LOG_TAG, __VA_ARGS__)
  36. #define J4A_ALOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, J4A_LOG_TAG, __VA_ARGS__)
  37. #define J4A_ALOGD(...) __android_log_print(ANDROID_LOG_DEBUG, J4A_LOG_TAG, __VA_ARGS__)
  38. #define J4A_ALOGI(...) __android_log_print(ANDROID_LOG_INFO, J4A_LOG_TAG, __VA_ARGS__)
  39. #define J4A_ALOGW(...) __android_log_print(ANDROID_LOG_WARN, J4A_LOG_TAG, __VA_ARGS__)
  40. #define J4A_ALOGE(...) __android_log_print(ANDROID_LOG_ERROR, J4A_LOG_TAG, __VA_ARGS__)
  41. #define J4A_FUNC_FAIL_TRACE() do {J4A_ALOGE("%s: failed\n", __func__);} while (0)
  42. #define J4A_FUNC_FAIL_TRACE1(x__) do {J4A_ALOGE("%s: failed: %s\n", __func__, x__);} while (0)
  43. #define J4A_FUNC_FAIL_TRACE2(x1__, x2__) do {J4A_ALOGE("%s: failed: %s %s\n", __func__, x1__, x2__);} while (0)
  44. #define J4A_LOAD_CLASS(class__) \
  45. do { \
  46. ret = J4A_loadClass__J4AC_##class__(env); \
  47. if (ret) \
  48. goto fail; \
  49. } while (0)
  50. /********************
  51. * Exception Handle
  52. ********************/
  53. bool J4A_ExceptionCheck__throwAny(JNIEnv *env);
  54. bool J4A_ExceptionCheck__catchAll(JNIEnv *env);
  55. int J4A_ThrowExceptionOfClass(JNIEnv* env, jclass clazz, const char* msg);
  56. int J4A_ThrowException(JNIEnv* env, const char* class_sign, const char* msg);
  57. int J4A_ThrowIllegalStateException(JNIEnv *env, const char* msg);
  58. /********************
  59. * References
  60. ********************/
  61. jclass J4A_NewGlobalRef__catchAll(JNIEnv *env, jobject obj);
  62. void J4A_DeleteLocalRef(JNIEnv *env, jobject obj);
  63. void J4A_DeleteLocalRef__p(JNIEnv *env, jobject *obj);
  64. void J4A_DeleteGlobalRef(JNIEnv *env, jobject obj);
  65. void J4A_DeleteGlobalRef__p(JNIEnv *env, jobject *obj);
  66. void J4A_ReleaseStringUTFChars(JNIEnv *env, jstring str, const char *c_str);
  67. void J4A_ReleaseStringUTFChars__p(JNIEnv *env, jstring str, const char **c_str);
  68. /********************
  69. * Class Load
  70. ********************/
  71. int J4A_LoadAll__catchAll(JNIEnv *env);
  72. jclass J4A_FindClass__catchAll(JNIEnv *env, const char *class_sign);
  73. jclass J4A_FindClass__asGlobalRef__catchAll(JNIEnv *env, const char *class_sign);
  74. jmethodID J4A_GetMethodID__catchAll(JNIEnv *env, jclass clazz, const char *method_name, const char *method_sign);
  75. jmethodID J4A_GetStaticMethodID__catchAll(JNIEnv *env, jclass clazz, const char *method_name, const char *method_sign);
  76. jfieldID J4A_GetFieldID__catchAll(JNIEnv *env, jclass clazz, const char *field_name, const char *method_sign);
  77. jfieldID J4A_GetStaticFieldID__catchAll(JNIEnv *env, jclass clazz, const char *field_name, const char *method_sign);
  78. /********************
  79. * Misc Functions
  80. ********************/
  81. jbyteArray J4A_NewByteArray__catchAll(JNIEnv *env, jsize capacity);
  82. jbyteArray J4A_NewByteArray__asGlobalRef__catchAll(JNIEnv *env, jsize capacity);
  83. int J4A_GetSystemAndroidApiLevel(JNIEnv *env);
  84. #endif//J4A_INTERNAL_H