| LEFT | RIGHT |
| 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 #include "JniCallbacks.h" | 18 #include "JniCallbacks.h" |
| 19 |
| 20 static jlong JNICALL JniCtor(JNIEnv* env, jclass clazz, jobject callbackObject) |
| 21 { |
| 22 try |
| 23 { |
| 24 return JniPtrToLong(new JniLogSystemCallback(env, callbackObject)); |
| 25 } |
| 26 CATCH_THROW_AND_RETURN(env, 0) |
| 27 } |
| 28 |
| 29 static void JNICALL JniDtor(JNIEnv* env, jclass clazz, jlong ptr) |
| 30 { |
| 31 delete JniLongToTypePtr<JniLogSystemCallback>(ptr); |
| 32 } |
| 19 | 33 |
| 20 JniLogSystemCallback::JniLogSystemCallback(JNIEnv* env, jobject callbackObject) | 34 JniLogSystemCallback::JniLogSystemCallback(JNIEnv* env, jobject callbackObject) |
| 21 : JniCallbackBase(env, callbackObject), AdblockPlus::LogSystem() | 35 : JniCallbackBase(env, callbackObject), AdblockPlus::LogSystem() |
| 22 { | 36 { |
| 23 logLevelClass.reset(new JniGlobalReference<jclass>(env, env->FindClass(PKG("Lo
gSystem$LogLevel")))); | 37 logLevelClass.reset(new JniGlobalReference<jclass>(env, env->FindClass(PKG("Lo
gSystem$LogLevel")))); |
| 24 } | 38 } |
| 25 | 39 |
| 26 void JniLogSystemCallback::operator()(AdblockPlus::LogSystem::LogLevel logLevel,
const std::string& message, const std::string& source) | 40 void JniLogSystemCallback::operator()(AdblockPlus::LogSystem::LogLevel logLevel,
const std::string& message, const std::string& source) |
| 27 { | 41 { |
| 28 JNIEnvAcquire env(GetJavaVM()); | 42 JNIEnvAcquire env(GetJavaVM()); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 jstring jMessage = env->NewStringUTF(message.c_str()); | 79 jstring jMessage = env->NewStringUTF(message.c_str()); |
| 66 jstring jSource = env->NewStringUTF(source.c_str()); | 80 jstring jSource = env->NewStringUTF(source.c_str()); |
| 67 | 81 |
| 68 env->CallVoidMethod(GetCallbackObject(), method, jLogLevel, jMessage, jSou
rce); | 82 env->CallVoidMethod(GetCallbackObject(), method, jLogLevel, jMessage, jSou
rce); |
| 69 } | 83 } |
| 70 | 84 |
| 71 CheckAndLogJavaException(*env); | 85 CheckAndLogJavaException(*env); |
| 72 } | 86 } |
| 73 } | 87 } |
| 74 | 88 |
| 75 static jlong JNICALL JniCtor(JNIEnv* env, jclass clazz, jobject callbackObject) | |
| 76 { | |
| 77 TRY | |
| 78 { | |
| 79 return JniPtrToLong(new JniLogSystemCallback(env, callbackObject)); | |
| 80 } | |
| 81 CATCH_THROW_AND_RETURN(env, 0) | |
| 82 } | |
| 83 | |
| 84 static void JNICALL JniDtor(JNIEnv* env, jclass clazz, jlong ptr) | |
| 85 { | |
| 86 delete JniLongToTypePtr<JniLogSystemCallback>(ptr); | |
| 87 } | |
| 88 | |
| 89 static JNINativeMethod methods[] = | 89 static JNINativeMethod methods[] = |
| 90 { | 90 { |
| 91 { (char*)"ctor", (char*)"(Ljava/lang/Object;)J", (void*)JniCtor }, | 91 { (char*)"ctor", (char*)"(Ljava/lang/Object;)J", (void*)JniCtor }, |
| 92 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor } | 92 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor } |
| 93 }; | 93 }; |
| 94 | 94 |
| 95 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_LogSystem_
registerNatives(JNIEnv *env, jclass clazz) | 95 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_LogSystem_
registerNatives(JNIEnv *env, jclass clazz) |
| 96 { | 96 { |
| 97 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); | 97 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); |
| 98 } | 98 } |
| LEFT | RIGHT |