p≡p for Java
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

130 lines
4.1 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. #pragma once
  2. #include <unordered_map>
  3. #include <thread>
  4. #include <mutex>
  5. #include <jni.h>
  6. #include <pEp/stringpair.h>
  7. #include <pEp/identity_list.h>
  8. #include <pEp/bloblist.h>
  9. #include <pEp/message.h>
  10. #include <pEp/sync_api.h>
  11. #include <pEp/passphrase_cache.hh>
  12. #if 0 // Enable if log needed
  13. #include <android/log.h>
  14. #define LOG_TAG "pEpJNIAdapter"
  15. #define LOGD(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)
  16. #else
  17. #define LOGD(...) do{}while(0)
  18. #endif
  19. namespace pEp {
  20. namespace JNIAdapter {
  21. // Global mutex needs to be locked in all constructors which insert their own mutex object
  22. // into the unordered_map (which is thread safe for read, but not for write)
  23. extern std::mutex global_mutex;
  24. // Stores mutex per java object
  25. extern std::unordered_map<long, std::mutex*> engine_objid_mutex;
  26. // needs to be called after create_engine_java_object_mutex()
  27. // and before release_engine_java_object_mutex()
  28. // Thread safe
  29. std::mutex* get_engine_java_object_mutex(
  30. JNIEnv *env,
  31. jobject me
  32. );
  33. // Needs to be called exactly once per obj, in the constructor of the obj
  34. // You need to lock a global mutex before calling this function (write to unordered_map)
  35. void create_engine_java_object_mutex(
  36. JNIEnv *env,
  37. jobject me
  38. );
  39. // Needs to be called exactly once per obj, in the destructor of this obj
  40. // You need to lock a global mutex before calling this function (write to unordered_map)
  41. void release_engine_java_object_mutex(
  42. JNIEnv *env,
  43. jobject me
  44. );
  45. jclass findClass(JNIEnv *env, const char *classname);
  46. jfieldID getFieldID(
  47. JNIEnv *env,
  48. const char *classname,
  49. const char *fieldname,
  50. const char *signature
  51. );
  52. jfieldID getFieldID(
  53. JNIEnv *env,
  54. const char *classname,
  55. const char *fieldname,
  56. const char *signature,
  57. const jclass clazz
  58. );
  59. jint callIntMethod(
  60. JNIEnv *env,
  61. jobject obj,
  62. const char *methodname
  63. );
  64. jlong callLongMethod(
  65. JNIEnv *env,
  66. jobject obj,
  67. const char *methodname
  68. );
  69. jobject callObjectMethod(
  70. JNIEnv *env,
  71. jobject obj,
  72. const char *methodname,
  73. jint index
  74. );
  75. jboolean callBooleanMethod(
  76. JNIEnv *env,
  77. jobject obj,
  78. const char *methodname,
  79. jobject o
  80. );
  81. jint outOfMemory(JNIEnv *env);
  82. jobject from_Integer(JNIEnv *env, int val);
  83. int to_Integer(JNIEnv *env, jobject obj);
  84. jbyteArray from_string(JNIEnv *env, const char *str);
  85. char *to_string(JNIEnv *env, jbyteArray str);
  86. jobject from_stringlist(JNIEnv *env, stringlist_t *sl);
  87. stringlist_t *to_stringlist(JNIEnv *env, jobject obj);
  88. jobject from_stringpairlist(JNIEnv *env, stringpair_list_t *sl);
  89. stringpair_list_t *to_stringpairlist(JNIEnv *env, jobject obj);
  90. jobject from_timestamp(JNIEnv *env, timestamp *ts);
  91. timestamp *to_timestamp(JNIEnv *env, jobject date);
  92. jobject from_identity(JNIEnv *env, pEp_identity *ident);
  93. jobject from_identity(JNIEnv *env, pEp_identity *ident, jclass identityClass);
  94. pEp_identity *to_identity(JNIEnv *env, jobject obj);
  95. jobject from_identitylist(JNIEnv *env, identity_list *il);
  96. identity_list *to_identitylist(JNIEnv *env, jobject obj);
  97. jobject from_bloblist(JNIEnv *env, bloblist_t *bl);
  98. bloblist_t *to_blob(JNIEnv *env, jobject obj);
  99. bloblist_t *to_bloblist(JNIEnv *env, jobject obj);
  100. PEP_enc_format to_EncFormat(JNIEnv *env, jobject obj);
  101. PEP_CIPHER_SUITE to_CipherSuite(JNIEnv *env, jobject obj);
  102. sync_handshake_result to_SyncHandshakeResult(JNIEnv *env, jobject obj);
  103. };
  104. };