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-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 18 matching lines...) Expand all Loading... |
29 static void JNICALL JniDtor(JNIEnv* env, jclass clazz, jlong ptr) | 29 static void JNICALL JniDtor(JNIEnv* env, jclass clazz, jlong ptr) |
30 { | 30 { |
31 delete JniLongToTypePtr<JniLogSystemCallback>(ptr); | 31 delete JniLongToTypePtr<JniLogSystemCallback>(ptr); |
32 } | 32 } |
33 | 33 |
34 JniLogSystemCallback::JniLogSystemCallback(JNIEnv* env, jobject callbackObject) | 34 JniLogSystemCallback::JniLogSystemCallback(JNIEnv* env, jobject callbackObject) |
35 : JniCallbackBase(env, callbackObject), AdblockPlus::LogSystem(), logLevelClas
s(new JniGlobalReference<jclass>(env, env->FindClass(PKG("LogSystem$LogLevel")))
) | 35 : JniCallbackBase(env, callbackObject), AdblockPlus::LogSystem(), logLevelClas
s(new JniGlobalReference<jclass>(env, env->FindClass(PKG("LogSystem$LogLevel")))
) |
36 { | 36 { |
37 } | 37 } |
38 | 38 |
39 void JniLogSystemCallback::operator()(AdblockPlus::LogSystem::LogLevel logLevel,
const std::string& message, const std::string& source) | 39 void JniLogSystemCallback::operator()(AdblockPlus::LogSystem::LogLevel logLevel, |
| 40 const std::string& message, const std::string& source) |
40 { | 41 { |
41 JNIEnvAcquire env(GetJavaVM()); | 42 JNIEnvAcquire env(GetJavaVM()); |
42 | 43 |
43 jmethodID method = env->GetMethodID( | 44 jmethodID method = env->GetMethodID( |
44 *JniLocalReference<jclass>(*env, env->GetObjectClass(GetCallbackObject()))
, | 45 *JniLocalReference<jclass>(*env, |
45 "logCallback", "(" TYP("LogSystem$LogLevel") "Ljava/lang/String;Ljava/lang
/String;)V"); | 46 env->GetObjectClass(GetCallbackObject())), |
| 47 "logCallback", |
| 48 "(" TYP("LogSystem$LogLevel") "Ljava/lang/String;Ljava/lang/String;)V"); |
46 | 49 |
47 // TODO: Set log level from Java and handle it here (to reduce C++->Java calls
) | 50 // TODO: Set log level from Java and handle it here (to reduce C++->Java calls
) |
48 | 51 |
49 if (method) | 52 if (method) |
50 { | 53 { |
51 const char* enumName = 0; | 54 const char* enumName = 0; |
52 | 55 |
53 switch (logLevel) | 56 switch (logLevel) |
54 { | 57 { |
55 default: | 58 default: |
(...skipping 10 matching lines...) Expand all Loading... |
66 enumName = "WARN"; | 69 enumName = "WARN"; |
67 break; | 70 break; |
68 case AdblockPlus::LogSystem::LOG_LEVEL_ERROR: | 71 case AdblockPlus::LogSystem::LOG_LEVEL_ERROR: |
69 enumName = "ERROR"; | 72 enumName = "ERROR"; |
70 break; | 73 break; |
71 } | 74 } |
72 | 75 |
73 jclass enumClass = logLevelClass->Get(); | 76 jclass enumClass = logLevelClass->Get(); |
74 if (enumClass) | 77 if (enumClass) |
75 { | 78 { |
76 jfieldID enumField = env->GetStaticFieldID(enumClass, enumName, TYP("LogSy
stem$LogLevel")); | 79 jfieldID enumField = env->GetStaticFieldID(enumClass, enumName, |
77 JniLocalReference<jobject> jLogLevel(*env, env->GetStaticObjectField(enumC
lass, enumField)); | 80 TYP("LogSystem$LogLevel")); |
| 81 JniLocalReference<jobject> jLogLevel(*env, |
| 82 env->GetStaticObjectField(enumClass, enumField)); |
78 | 83 |
79 JniLocalReference<jstring> jMessage(*env, env->NewStringUTF(message.c_str(
))); | 84 JniLocalReference<jstring> jMessage(*env, |
80 JniLocalReference<jstring> jSource(*env, env->NewStringUTF(source.c_str())
); | 85 env->NewStringUTF(message.c_str())); |
| 86 JniLocalReference<jstring> jSource(*env, |
| 87 env->NewStringUTF(source.c_str())); |
81 | 88 |
82 env->CallVoidMethod(GetCallbackObject(), method, *jLogLevel, *jMessage, *j
Source); | 89 env->CallVoidMethod(GetCallbackObject(), method, *jLogLevel, *jMessage, |
| 90 *jSource); |
83 } | 91 } |
84 | 92 |
85 CheckAndLogJavaException(*env); | 93 CheckAndLogJavaException(*env); |
86 } | 94 } |
87 } | 95 } |
88 | 96 |
89 static JNINativeMethod methods[] = | 97 static JNINativeMethod methods[] = |
90 { | 98 { |
91 { (char*)"ctor", (char*)"(Ljava/lang/Object;)J", (void*)JniCtor }, | 99 { (char*)"ctor", (char*)"(Ljava/lang/Object;)J", (void*)JniCtor }, |
92 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor } | 100 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor } |
93 }; | 101 }; |
94 | 102 |
95 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_LogSystem_
registerNatives(JNIEnv *env, jclass clazz) | 103 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_LogSystem_
registerNatives(JNIEnv *env, jclass clazz) |
96 { | 104 { |
97 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); | 105 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); |
98 } | 106 } |
LEFT | RIGHT |