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

Delta Between Two Patch Sets: jni/JniCallbacks.h

Issue 6606493159784448: New JNI bindings (Closed)
Left Patch Set: Cleaned up namespace usage in cpp files. Created March 20, 2014, 3:17 p.m.
Right Patch Set: Removed TODO from AppInfo. Created April 11, 2014, 1:28 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/Android.mk ('k') | jni/JniCallbacks.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 <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2014 Eyeo GmbH 3 * Copyright (C) 2006-2014 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 JNICALLBACKS_H_ 18 #ifndef JNICALLBACKS_H
Felix Dahlke 2014/03/28 08:29:00 Our convention is: JNI_CALLBACKS_H (no trailing _,
19 #define JNICALLBACKS_H_ 19 #define JNICALLBACKS_H
20 20
21 #include <AdblockPlus.h> 21 #include <AdblockPlus.h>
22 #include "Utils.h" 22 #include "Utils.h"
23 #include "JniJsValue.h" 23 #include "JniJsValue.h"
24 24
25 namespace AdblockPlus
26 {
27 namespace Android
Felix Dahlke 2014/03/28 08:29:00 Namespace bodies are to be indented: https://adblo
28 {
29
30 class JniCallbackBase 25 class JniCallbackBase
31 { 26 {
32 public: 27 public:
33 JniCallbackBase(JNIEnv* env, jobject callbackObject) 28 JniCallbackBase(JNIEnv* env, jobject callbackObject);
29 virtual ~JniCallbackBase();
30 void LogException(JNIEnv* env, jthrowable throwable) const;
31 void CheckAndLogJavaException(JNIEnv* env) const;
32
33 JavaVM* GetJavaVM() const
34 { 34 {
35 env->GetJavaVM(&m_JavaVM); 35 return javaVM;
Felix Dahlke 2014/03/28 08:29:00 IMO, we should move all the function definitions f
36 m_CallbackObject.reset(new JniGlobalReference<jobject>(env, callbackObject)) ;
37 m_ExceptionLoggerClass.reset(new JniGlobalReference<jclass>(env, env->FindCl ass(PKG("JniExceptionHandler"))));
38 } 36 }
39 37
40 virtual ~JniCallbackBase() 38 jobject GetCallbackObject() const
41 { 39 {
42 } 40 return callbackObject->Get();
43
44 inline JavaVM* GetJavaVM() const
Felix Dahlke 2014/03/28 08:29:00 inline is redundant for member functions. Same bel
45 {
46 return m_JavaVM;
47 }
48
49 inline jobject GetCallbackObject() const
50 {
51 return m_CallbackObject->get();
52 }
53
54 void LogException(JNIEnv* env, jthrowable throwable) const
55 {
56 jmethodID logMethod = env->GetStaticMethodID(m_ExceptionLoggerClass->get(), "logException", "(Ljava/lang/Throwable;)V");
57 if (logMethod)
58 {
59 env->CallStaticVoidMethod(m_ExceptionLoggerClass->get(), logMethod, throwa ble);
60 }
61 }
62
63 void CheckAndLogJavaException(JNIEnv* env) const
64 {
65 if (env->ExceptionCheck())
66 {
67 jthrowable throwable = env->ExceptionOccurred();
68 env->ExceptionClear();
69 LogException(env, throwable);
70 }
71 } 41 }
72 42
73 private: 43 private:
74 JavaVM* m_JavaVM; 44 JavaVM* javaVM;
Felix Dahlke 2014/03/28 08:29:00 From https://adblockplus.org/en/coding-style: "No
René Jeschke 2014/03/28 10:59:15 I'll change this, but we should think this over ag
75 JniGlobalReference<jobject>::PTR m_CallbackObject; 45 JniGlobalReference<jobject>::Ptr callbackObject;
76 JniGlobalReference<jclass>::PTR m_ExceptionLoggerClass; 46 JniGlobalReference<jclass>::Ptr exceptionLoggerClass;
77 }; 47 };
78 48
79 class JniEventCallback: public JniCallbackBase 49 class JniEventCallback : public JniCallbackBase
Felix Dahlke 2014/03/28 08:29:00 Space before ":" please :) Likewise below.
80 { 50 {
81 public: 51 public:
82 JniEventCallback(JNIEnv* env, jobject callbackObject); 52 JniEventCallback(JNIEnv* env, jobject callbackObject);
83 virtual ~JniEventCallback();
84 void Callback(AdblockPlus::JsValueList& params); 53 void Callback(AdblockPlus::JsValueList& params);
85 }; 54 };
86 55
87 class JniUpdaterCallback: public JniCallbackBase 56 class JniUpdaterCallback : public JniCallbackBase
88 { 57 {
89 public: 58 public:
90 JniUpdaterCallback(JNIEnv* env, jobject callbackObject); 59 JniUpdaterCallback(JNIEnv* env, jobject callbackObject);
91 virtual ~JniUpdaterCallback();
92 void Callback(const std::string& arg); 60 void Callback(const std::string& arg);
93 }; 61 };
94 62
95 class JniFilterChangeCallback: public JniCallbackBase 63 class JniFilterChangeCallback : public JniCallbackBase
96 { 64 {
97 public: 65 public:
98 JniFilterChangeCallback(JNIEnv* env, jobject callbackObject); 66 JniFilterChangeCallback(JNIEnv* env, jobject callbackObject);
99 virtual ~JniFilterChangeCallback();
100 void Callback(const std::string& arg, const AdblockPlus::JsValuePtr jsValue); 67 void Callback(const std::string& arg, const AdblockPlus::JsValuePtr jsValue);
101 }; 68 };
102 69
103 class JniLogSystemCallback: public JniCallbackBase, public AdblockPlus::LogSyste m 70 class JniLogSystemCallback : public JniCallbackBase, public AdblockPlus::LogSyst em
104 { 71 {
105 public: 72 public:
106 JniLogSystemCallback(JNIEnv* env, jobject callbackObject); 73 JniLogSystemCallback(JNIEnv* env, jobject callbackObject);
107 virtual ~JniLogSystemCallback();
108 void operator()(AdblockPlus::LogSystem::LogLevel logLevel, const std::string& message, const std::string& source); 74 void operator()(AdblockPlus::LogSystem::LogLevel logLevel, const std::string& message, const std::string& source);
75
109 private: 76 private:
Felix Dahlke 2014/03/28 08:29:00 Whitespace before "private"?
110 JniGlobalReference<jclass>::PTR m_LogLevelClass; 77 JniGlobalReference<jclass>::Ptr logLevelClass;
111 }; 78 };
112 79
113 class JniWebRequest: public JniCallbackBase, public AdblockPlus::WebRequest 80 class JniWebRequest : public JniCallbackBase, public AdblockPlus::WebRequest
114 { 81 {
115 public: 82 public:
116 JniWebRequest(JNIEnv* env, jobject callbackObject); 83 JniWebRequest(JNIEnv* env, jobject callbackObject);
117 virtual ~JniWebRequest();
118 AdblockPlus::ServerResponse GET(const std::string& url, const AdblockPlus::Hea derList& requestHeaders) const; 84 AdblockPlus::ServerResponse GET(const std::string& url, const AdblockPlus::Hea derList& requestHeaders) const;
85
119 private: 86 private:
Felix Dahlke 2014/03/28 08:29:00 Whitespace before "private"?
120 jobject NewTuple(JNIEnv* env, const std::string& a, const std::string& b) cons t; 87 jobject NewTuple(JNIEnv* env, const std::string& a, const std::string& b) cons t;
121 88
122 JniGlobalReference<jclass>::PTR m_TupleClass; 89 JniGlobalReference<jclass>::Ptr tupleClass;
123 JniGlobalReference<jclass>::PTR m_ServerResponseClass; 90 JniGlobalReference<jclass>::Ptr serverResponseClass;
124 }; 91 };
125 92
126 } // namespace Android 93 #endif /* JNICALLBACKS_H */
127 } // namespace AdblockPlus
128
129 #endif /* JNICALLBACKS_H_ */
LEFTRIGHT

Powered by Google App Engine
This is Rietveld