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

Side by Side Diff: jni/Utils.h

Issue 5327480814567424: Issue 1108 - Support notifications (Closed)
Patch Set: Removed markAsShown() Created Feb. 18, 2015, 2:46 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
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
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 // TODO: It's feeling a bit dirty casting to shared_ptr<T: JsValue> directly, so maybe 140 // TODO: It's feeling a bit dirty casting to shared_ptr<T: JsValue> directly, so maybe
141 // implement a special cast functions that first reinterpret_casts to shared_ptr <JsValue> and then 141 // implement a special cast functions that first reinterpret_casts to shared_ptr <JsValue> and then
142 // dynamic_casts to shared_ptr<T: JsValue> ... also as the same inheritance is m irrored on the Java 142 // dynamic_casts to shared_ptr<T: JsValue> ... also as the same inheritance is m irrored on the Java
143 // side (and Java will throw a class cast exception on error) this shouldn't be an issue (TM) 143 // side (and Java will throw a class cast exception on error) this shouldn't be an issue (TM)
144 template<typename T> 144 template<typename T>
145 inline T* JniLongToTypePtr(jlong value) 145 inline T* JniLongToTypePtr(jlong value)
146 { 146 {
147 return reinterpret_cast<T*>((size_t)value); 147 return reinterpret_cast<T*>((size_t)value);
148 } 148 }
149 149
150 jobject NewJniArrayList(JNIEnv* env);
151
152 std::string JniJavaToStdString(JNIEnv* env, jstring str); 150 std::string JniJavaToStdString(JNIEnv* env, jstring str);
153 151
154 void JniAddObjectToList(JNIEnv* env, jobject list, jobject value); 152 void JniAddObjectToList(JNIEnv* env, jobject list, jobject value);
155 153
156 inline std::string JniGetStringField(JNIEnv* env, jclass clazz, jobject jObj, co nst char* name) 154 inline std::string JniGetStringField(JNIEnv* env, jclass clazz, jobject jObj, co nst char* name)
157 { 155 {
158 return JniJavaToStdString(env, reinterpret_cast<jstring>(env->GetObjectField(j Obj, env->GetFieldID(clazz, name, "Ljava/lang/String;")))); 156 return JniJavaToStdString(env, reinterpret_cast<jstring>(env->GetObjectField(j Obj, env->GetFieldID(clazz, name, "Ljava/lang/String;"))));
159 } 157 }
160 158
161 inline bool JniGetBooleanField(JNIEnv* env, jclass clazz, jobject jObj, const ch ar* name) 159 inline bool JniGetBooleanField(JNIEnv* env, jclass clazz, jobject jObj, const ch ar* name)
162 { 160 {
163 return env->GetBooleanField(jObj, env->GetFieldID(clazz, name, "Z")) == JNI_TR UE; 161 return env->GetBooleanField(jObj, env->GetFieldID(clazz, name, "Z")) == JNI_TR UE;
164 } 162 }
165 163
166 inline int32_t JniGetIntField(JNIEnv* env, jclass clazz, jobject jObj, const cha r* name) 164 inline int32_t JniGetIntField(JNIEnv* env, jclass clazz, jobject jObj, const cha r* name)
167 { 165 {
168 return (int32_t)env->GetIntField(jObj, env->GetFieldID(clazz, name, "I")); 166 return (int32_t)env->GetIntField(jObj, env->GetFieldID(clazz, name, "I"));
169 } 167 }
170 168
171 inline int64_t JniGetLongField(JNIEnv* env, jclass clazz, jobject jObj, const ch ar* name) 169 inline int64_t JniGetLongField(JNIEnv* env, jclass clazz, jobject jObj, const ch ar* name)
172 { 170 {
173 return (int64_t)env->GetLongField(jObj, env->GetFieldID(clazz, name, "J")); 171 return (int64_t)env->GetLongField(jObj, env->GetFieldID(clazz, name, "J"));
174 } 172 }
175 173
176 inline jobject NewJniFilter(JNIEnv* env, const AdblockPlus::FilterPtr& filter) 174 jobject NewJniArrayList(JNIEnv* env);
177 {
178 if (!filter.get())
179 {
180 return 0;
181 }
182 175
183 JniLocalReference<jclass> clazz(env, env->FindClass(PKG("Filter"))); 176 jobject NewJniFilter(JNIEnv* env, const AdblockPlus::FilterPtr& filter);
184 jmethodID method = env->GetMethodID(*clazz, "<init>", "(J)V");
185 return env->NewObject(*clazz, method,
186 JniPtrToLong(new AdblockPlus::FilterPtr(filter)));
187 }
188 177
189 inline jobject NewJniSubscription(JNIEnv* env, 178 jobject NewJniSubscription(JNIEnv* env,
190 const AdblockPlus::SubscriptionPtr& subscription) 179 const AdblockPlus::SubscriptionPtr& subscription);
191 {
192 if (!subscription.get())
193 {
194 return 0;
195 }
196 180
197 JniLocalReference<jclass> clazz(env, env->FindClass(PKG("Subscription"))); 181 jobject NewJniNotification(JNIEnv* env,
198 jmethodID method = env->GetMethodID(*clazz, "<init>", "(J)V"); 182 const AdblockPlus::NotificationPtr& notification);
199 return env->NewObject(*clazz, method,
200 JniPtrToLong(new AdblockPlus::SubscriptionPtr(subscription)));
201 }
202 183
203 #define CATCH_AND_THROW(jEnv) \ 184 #define CATCH_AND_THROW(jEnv) \
204 catch (const std::exception& except) \ 185 catch (const std::exception& except) \
205 { \ 186 { \
206 JniThrowException(jEnv, except); \ 187 JniThrowException(jEnv, except); \
207 } \ 188 } \
208 catch (...) \ 189 catch (...) \
209 { \ 190 { \
210 JniThrowException(jEnv); \ 191 JniThrowException(jEnv); \
211 } 192 }
212 193
213 #define CATCH_THROW_AND_RETURN(jEnv, retVal) \ 194 #define CATCH_THROW_AND_RETURN(jEnv, retVal) \
214 catch (const std::exception& except) \ 195 catch (const std::exception& except) \
215 { \ 196 { \
216 JniThrowException(jEnv, except); \ 197 JniThrowException(jEnv, except); \
217 return retVal; \ 198 return retVal; \
218 } \ 199 } \
219 catch (...) \ 200 catch (...) \
220 { \ 201 { \
221 JniThrowException(jEnv); \ 202 JniThrowException(jEnv); \
222 return retVal; \ 203 return retVal; \
223 } 204 }
224 205
225 #endif 206 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld