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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 std::string JavaToStdString(JNIEnv* jni, const jstring& j_string); | 101 std::string JavaToStdString(JNIEnv* jni, const jstring& j_string); |
102 | 102 |
103 // Return the (singleton) Java Enum object corresponding to |index|; | 103 // Return the (singleton) Java Enum object corresponding to |index|; |
104 jobject JavaEnumFromIndex(JNIEnv* jni, jclass state_class, | 104 jobject JavaEnumFromIndex(JNIEnv* jni, jclass state_class, |
105 const std::string& state_class_name, int index); | 105 const std::string& state_class_name, int index); |
106 | 106 |
107 jobject NewGlobalRef(JNIEnv* jni, jobject o); | 107 jobject NewGlobalRef(JNIEnv* jni, jobject o); |
108 | 108 |
109 void DeleteGlobalRef(JNIEnv* jni, jobject o); | 109 void DeleteGlobalRef(JNIEnv* jni, jobject o); |
110 | 110 |
111 // Given a jweak reference, allocate a (strong) local reference scoped to the | |
112 // lifetime of this object if the weak reference is still valid, or NULL | |
113 // otherwise. | |
114 class WeakRef { | |
115 public: | |
116 WeakRef(JNIEnv* jni, jweak ref); | |
117 ~WeakRef(); | |
118 jobject obj() { return obj_; } | |
119 | |
120 private: | |
121 JNIEnv* const jni_; | |
122 jobject const obj_; | |
123 }; | |
124 | |
125 // Scope Java local references to the lifetime of this object. Use in all C++ | 111 // Scope Java local references to the lifetime of this object. Use in all C++ |
126 // callbacks (i.e. entry points that don't originate in a Java callstack | 112 // callbacks (i.e. entry points that don't originate in a Java callstack |
127 // through a "native" method call). | 113 // through a "native" method call). |
128 class ScopedLocalRefFrame { | 114 class ScopedLocalRefFrame { |
129 public: | 115 public: |
130 explicit ScopedLocalRefFrame(JNIEnv* jni); | 116 explicit ScopedLocalRefFrame(JNIEnv* jni); |
131 ~ScopedLocalRefFrame(); | 117 ~ScopedLocalRefFrame(); |
132 | 118 |
133 private: | 119 private: |
134 JNIEnv* jni_; | 120 JNIEnv* jni_; |
(...skipping 11 matching lines...) Expand all Loading... |
146 T operator*() const { | 132 T operator*() const { |
147 return obj_; | 133 return obj_; |
148 } | 134 } |
149 private: | 135 private: |
150 T obj_; | 136 T obj_; |
151 }; | 137 }; |
152 | 138 |
153 } // namespace webrtc_jni | 139 } // namespace webrtc_jni |
154 | 140 |
155 #endif // TALK_APP_WEBRTC_JAVA_JNI_JNI_HELPERS_H_ | 141 #endif // TALK_APP_WEBRTC_JAVA_JNI_JNI_HELPERS_H_ |
OLD | NEW |