OLD | NEW |
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2015 Google Inc. | 3 * Copyright 2015 Google Inc. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
(...skipping 23 matching lines...) Expand all Loading... |
34 | 34 |
35 #include <jni.h> | 35 #include <jni.h> |
36 #include <string> | 36 #include <string> |
37 | 37 |
38 #include "webrtc/base/checks.h" | 38 #include "webrtc/base/checks.h" |
39 | 39 |
40 // Abort the process if |jni| has a Java exception pending. | 40 // Abort the process if |jni| has a Java exception pending. |
41 // This macros uses the comma operator to execute ExceptionDescribe | 41 // This macros uses the comma operator to execute ExceptionDescribe |
42 // and ExceptionClear ignoring their return values and sending "" | 42 // and ExceptionClear ignoring their return values and sending "" |
43 // to the error stream. | 43 // to the error stream. |
44 #define CHECK_EXCEPTION(jni) \ | 44 #define CHECK_EXCEPTION(jni) \ |
45 CHECK(!jni->ExceptionCheck()) \ | 45 RTC_CHECK(!jni->ExceptionCheck()) \ |
46 << (jni->ExceptionDescribe(), jni->ExceptionClear(), "") | 46 << (jni->ExceptionDescribe(), jni->ExceptionClear(), "") |
47 | 47 |
48 // Helper that calls ptr->Release() and aborts the process with a useful | 48 // Helper that calls ptr->Release() and aborts the process with a useful |
49 // message if that didn't actually delete *ptr because of extra refcounts. | 49 // message if that didn't actually delete *ptr because of extra refcounts. |
50 #define CHECK_RELEASE(ptr) \ | 50 #define CHECK_RELEASE(ptr) \ |
51 CHECK_EQ(0, (ptr)->Release()) << "Unexpected refcount." | 51 RTC_CHECK_EQ(0, (ptr)->Release()) << "Unexpected refcount." |
52 | 52 |
53 namespace webrtc_jni { | 53 namespace webrtc_jni { |
54 | 54 |
55 jint InitGlobalJniVariables(JavaVM *jvm); | 55 jint InitGlobalJniVariables(JavaVM *jvm); |
56 | 56 |
57 // Return a |JNIEnv*| usable on this thread or NULL if this thread is detached. | 57 // Return a |JNIEnv*| usable on this thread or NULL if this thread is detached. |
58 JNIEnv* GetEnv(); | 58 JNIEnv* GetEnv(); |
59 | 59 |
60 JavaVM *GetJVM(); | 60 JavaVM *GetJVM(); |
61 | 61 |
62 // Return a |JNIEnv*| usable on this thread. Attaches to |g_jvm| if necessary. | 62 // Return a |JNIEnv*| usable on this thread. Attaches to |g_jvm| if necessary. |
63 JNIEnv* AttachCurrentThreadIfNeeded(); | 63 JNIEnv* AttachCurrentThreadIfNeeded(); |
64 | 64 |
65 // Return a |jlong| that will correctly convert back to |ptr|. This is needed | 65 // Return a |jlong| that will correctly convert back to |ptr|. This is needed |
66 // because the alternative (of silently passing a 32-bit pointer to a vararg | 66 // because the alternative (of silently passing a 32-bit pointer to a vararg |
67 // function expecting a 64-bit param) picks up garbage in the high 32 bits. | 67 // function expecting a 64-bit param) picks up garbage in the high 32 bits. |
68 jlong jlongFromPointer(void* ptr); | 68 jlong jlongFromPointer(void* ptr); |
69 | 69 |
70 // JNIEnv-helper methods that CHECK success: no Java exception thrown and found | 70 // JNIEnv-helper methods that RTC_CHECK success: no Java exception thrown and |
71 // object/class/method/field is non-null. | 71 // found object/class/method/field is non-null. |
72 jmethodID GetMethodID( | 72 jmethodID GetMethodID( |
73 JNIEnv* jni, jclass c, const std::string& name, const char* signature); | 73 JNIEnv* jni, jclass c, const std::string& name, const char* signature); |
74 | 74 |
75 jmethodID GetStaticMethodID( | 75 jmethodID GetStaticMethodID( |
76 JNIEnv* jni, jclass c, const char* name, const char* signature); | 76 JNIEnv* jni, jclass c, const char* name, const char* signature); |
77 | 77 |
78 jfieldID GetFieldID(JNIEnv* jni, jclass c, const char* name, | 78 jfieldID GetFieldID(JNIEnv* jni, jclass c, const char* name, |
79 const char* signature); | 79 const char* signature); |
80 | 80 |
81 jclass GetObjectClass(JNIEnv* jni, jobject object); | 81 jclass GetObjectClass(JNIEnv* jni, jobject object); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 T operator*() const { | 132 T operator*() const { |
133 return obj_; | 133 return obj_; |
134 } | 134 } |
135 private: | 135 private: |
136 T obj_; | 136 T obj_; |
137 }; | 137 }; |
138 | 138 |
139 } // namespace webrtc_jni | 139 } // namespace webrtc_jni |
140 | 140 |
141 #endif // TALK_APP_WEBRTC_JAVA_JNI_JNI_HELPERS_H_ | 141 #endif // TALK_APP_WEBRTC_JAVA_JNI_JNI_HELPERS_H_ |
OLD | NEW |