LEFT | RIGHT |
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-2017 eyeo GmbH | 3 * Copyright (C) 2006-2017 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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 | 157 |
158 JNIEnvAcquire::~JNIEnvAcquire() | 158 JNIEnvAcquire::~JNIEnvAcquire() |
159 { | 159 { |
160 if (attachmentStatus == JNI_EDETACHED) | 160 if (attachmentStatus == JNI_EDETACHED) |
161 { | 161 { |
162 javaVM->DetachCurrentThread(); | 162 javaVM->DetachCurrentThread(); |
163 } | 163 } |
164 } | 164 } |
165 | 165 |
166 template<typename T> | 166 template<typename T> |
167 static jobject NewJniObject(JNIEnv* env, const T& value, jclass clazz, jmethodID
ctor) | 167 static jobject NewJniObject(JNIEnv* env, T&& value, jclass clazz, jmethodID ctor
) |
168 { | 168 { |
169 return env->NewObject(clazz, ctor, JniPtrToLong(new T(value))); | 169 return env->NewObject(clazz, ctor, JniPtrToLong(new T(std::forward<T>(value)))
); |
170 } | 170 } |
171 | 171 |
172 template<typename T> | 172 jobject NewJniFilter(JNIEnv* env, AdblockPlus::Filter&& filter) |
173 static jobject NewJniObject(JNIEnv* env, const T& value, const char* javaClass) | |
174 { | 173 { |
175 JniLocalReference<jclass> clazz( env, env->FindClass(javaClass)); | 174 return NewJniObject<AdblockPlus::Filter>( |
176 jmethodID ctor = env->GetMethodID(*clazz, "<init>", "(J)V"); | 175 env, std::move(filter), filterClass->Get(), filterCtor); |
177 return NewJniObject(env, value, *clazz, ctor); | |
178 } | 176 } |
179 | 177 |
180 jobject NewJniFilter(JNIEnv* env, AdblockPlus::Filter& filter) | 178 jobject NewJniSubscription(JNIEnv* env, AdblockPlus::Subscription&& subscription
) |
181 { | 179 { |
182 return NewJniObject(env, filter, filterClass->Get(), filterCtor); | 180 return NewJniObject<AdblockPlus::Subscription>( |
| 181 env, std::move(subscription), subscriptionClass->Get(), subscriptionCtor); |
183 } | 182 } |
184 | 183 |
185 jobject NewJniSubscription(JNIEnv* env, AdblockPlus::Subscription& subscription) | 184 jobject NewJniNotification(JNIEnv* env, AdblockPlus::Notification&& notification
) |
186 { | 185 { |
187 return NewJniObject(env, subscription, subscriptionClass->Get(), subscriptionC
tor); | 186 return NewJniObject<AdblockPlus::Notification>( |
| 187 env, std::move(notification), notificationClass->Get(), notificationCtor); |
188 } | 188 } |
189 | |
190 jobject NewJniNotification(JNIEnv* env, AdblockPlus::Notification& notification) | |
191 { | |
192 return NewJniObject(env, notification, notificationClass->Get(), notificationC
tor); | |
193 } | |
LEFT | RIGHT |