Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: jni/Utils.h

Issue 4761138508070912: Issue 1848 - Clean up local reference handling (Closed)
Left Patch Set: Some formatting issues Created Jan. 23, 2015, 12:30 p.m.
Right Patch Set: Stupid auto-formatter^^ Created Feb. 4, 2015, 12:04 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « jni/JniWebRequest.cpp ('k') | jni/Utils.cpp » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 #ifndef UTILS_H 18 #ifndef UTILS_H
19 #define UTILS_H 19 #define UTILS_H
20 20
21 #include <string> 21 #include <string>
22 #include <algorithm> 22 #include <algorithm>
23 #include <jni.h> 23 #include <jni.h>
24 #include <stdexcept> 24 #include <stdexcept>
25 25
26 #include <AdblockPlus.h> 26 #include <AdblockPlus.h>
27 #include <AdblockPlus/tr1_memory.h> 27 #include <AdblockPlus/tr1_memory.h>
28 28
29 #include "v8/v8stdint.h"
30
31 #define PKG(x) "org/adblockplus/libadblockplus/" x 29 #define PKG(x) "org/adblockplus/libadblockplus/" x
32 #define TYP(x) "L" PKG(x) ";" 30 #define TYP(x) "L" PKG(x) ";"
33 31
34 #define ABP_JNI_VERSION JNI_VERSION_1_6 32 #define ABP_JNI_VERSION JNI_VERSION_1_6
35 33
36 void JniThrowException(JNIEnv* env, const std::string& message); 34 void JniThrowException(JNIEnv* env, const std::string& message);
37 35
38 void JniThrowException(JNIEnv* env, const std::exception& e); 36 void JniThrowException(JNIEnv* env, const std::exception& e);
39 37
40 void JniThrowException(JNIEnv* env); 38 void JniThrowException(JNIEnv* env);
41 39
42 class JNIEnvAcquire; 40 class JNIEnvAcquire;
43 41
44 /** 42 /**
45 * This class is _NOT_ thread safe! 43 * This class is _NOT_ thread safe!
46 */ 44 */
47 template<typename T> 45 template<typename T>
48 class JniLocalReference 46 class JniLocalReference
49 { 47 {
50 public: 48 public:
51 explicit JniLocalReference(JNIEnv* jniEnv, T object) 49 JniLocalReference(JNIEnv* jniEnv, T object)
52 : m_JNIEnv(jniEnv), m_Object(object) 50 : jniEnv(jniEnv), object(object)
53 { 51 {
54 52
55 } 53 }
56 54
57 JniLocalReference(const JniLocalReference<T>& other); 55 JniLocalReference(const JniLocalReference<T>& other);
58 56
59 ~JniLocalReference() 57 ~JniLocalReference()
60 { 58 {
61 m_JNIEnv->DeleteLocalRef(m_Object); 59 jniEnv->DeleteLocalRef(object);
62 } 60 }
63 61
64 T operator*() 62 T operator*()
65 { 63 {
66 return m_Object; 64 return object;
67 } 65 }
68 66
69 T Get() 67 T Get()
70 { 68 {
71 return m_Object; 69 return object;
72 } 70 }
73 71
74 private: 72 private:
75 JNIEnv* m_JNIEnv; 73 JNIEnv* jniEnv;
76 T m_Object; 74 T object;
77 }; 75 };
78 76
79 class JNIEnvAcquire 77 class JNIEnvAcquire
80 { 78 {
81 public: 79 public:
82 JNIEnvAcquire(JavaVM* javaVM); 80 JNIEnvAcquire(JavaVM* javaVM);
83 ~JNIEnvAcquire(); 81 ~JNIEnvAcquire();
84 82
85 JNIEnv* operator*() 83 JNIEnv* operator*()
86 { 84 {
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 JniThrowException(jEnv, except); \ 216 JniThrowException(jEnv, except); \
219 return retVal; \ 217 return retVal; \
220 } \ 218 } \
221 catch (...) \ 219 catch (...) \
222 { \ 220 { \
223 JniThrowException(jEnv); \ 221 JniThrowException(jEnv); \
224 return retVal; \ 222 return retVal; \
225 } 223 }
226 224
227 #endif 225 #endif
LEFTRIGHT

Powered by Google App Engine
This is Rietveld