clogan_protocol.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Copyright (c) 2018-present, 美团点评
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to deal
  6. * in the Software without restriction, including without limitation the rights
  7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. * copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. * THE SOFTWARE.
  21. */
  22. #include "clogan_protocol.h"
  23. JNIEXPORT jint JNICALL
  24. Java_com_dianping_logan_CLoganProtocol_clogan_1write(JNIEnv *env, jobject instance, jint flag,
  25. jstring log_, jlong local_time,
  26. jstring thread_name_, jlong thread_id,
  27. jint is_main) {
  28. const char *log = (*env)->GetStringUTFChars(env, log_, 0);
  29. const char *thread_name = (*env)->GetStringUTFChars(env, thread_name_, 0);
  30. jint code = (jint) clogan_write(flag, log, local_time, thread_name, thread_id, is_main);
  31. (*env)->ReleaseStringUTFChars(env, log_, log);
  32. (*env)->ReleaseStringUTFChars(env, thread_name_, thread_name);
  33. return code;
  34. }
  35. JNIEXPORT jint JNICALL
  36. Java_com_dianping_logan_CLoganProtocol_clogan_1init(JNIEnv *env, jobject instance,
  37. jstring cache_path_,
  38. jstring dir_path_, jint max_file,
  39. jstring encrypt_key16_, jstring encrypt_iv16_) {
  40. const char *dir_path = (*env)->GetStringUTFChars(env, dir_path_, 0);
  41. const char *cache_path = (*env)->GetStringUTFChars(env, cache_path_, 0);
  42. const char *encrypt_key16 = (*env)->GetStringUTFChars(env, encrypt_key16_, 0);
  43. const char *encrypt_iv16 = (*env)->GetStringUTFChars(env, encrypt_iv16_, 0);
  44. jint code = (jint) clogan_init(cache_path, dir_path, max_file, encrypt_key16, encrypt_iv16);
  45. (*env)->ReleaseStringUTFChars(env, dir_path_, dir_path);
  46. (*env)->ReleaseStringUTFChars(env, cache_path_, cache_path);
  47. (*env)->ReleaseStringUTFChars(env, encrypt_key16_, encrypt_key16);
  48. (*env)->ReleaseStringUTFChars(env, encrypt_iv16_, encrypt_iv16);
  49. return code;
  50. }
  51. JNIEXPORT jint JNICALL
  52. Java_com_dianping_logan_CLoganProtocol_clogan_1open(JNIEnv *env, jobject instance,
  53. jstring file_name_) {
  54. const char *file_name = (*env)->GetStringUTFChars(env, file_name_, 0);
  55. jint code = (jint) clogan_open(file_name);
  56. (*env)->ReleaseStringUTFChars(env, file_name_, file_name);
  57. return code;
  58. }
  59. JNIEXPORT void JNICALL
  60. Java_com_dianping_logan_CLoganProtocol_clogan_1flush(JNIEnv *env, jobject instance) {
  61. clogan_flush();
  62. }
  63. JNIEXPORT void JNICALL
  64. Java_com_dianping_logan_CLoganProtocol_clogan_1debug(JNIEnv *env, jobject instance,
  65. jboolean is_debug) {
  66. int i = 1;
  67. if (!is_debug) {
  68. i = 0;
  69. }
  70. clogan_debug(i);
  71. }