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

Side by Side Diff: libadblockplus-android/jni/JniLogSystem.cpp

Issue 29524596: Issue 5556 - make C++ implementation of LogSystem manageable only by JsEngine (Closed) Base URL: github.com:abby-sergz/libadblockplus-android.git
Patch Set: Created Aug. 23, 2017, 12:10 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-present eyeo GmbH 3 * Copyright (C) 2006-present 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 17 matching lines...) Expand all
28 28
29 void JniLogSystem_OnUnload(JavaVM* vm, JNIEnv* env, void* reserved) 29 void JniLogSystem_OnUnload(JavaVM* vm, JNIEnv* env, void* reserved)
30 { 30 {
31 if (logLevelClass) 31 if (logLevelClass)
32 { 32 {
33 delete logLevelClass; 33 delete logLevelClass;
34 logLevelClass = NULL; 34 logLevelClass = NULL;
35 } 35 }
36 } 36 }
37 37
38 static jlong JNICALL JniCtor(JNIEnv* env, jclass clazz, jobject callbackObject)
39 {
40 try
41 {
42 return JniPtrToLong(new AdblockPlus::LogSystemPtr(new JniLogSystemCallback(e nv, callbackObject)));
43 }
44 CATCH_THROW_AND_RETURN(env, 0)
45 }
46
47 static void JNICALL JniDtor(JNIEnv* env, jclass clazz, jlong ptr)
48 {
49 delete JniLongToTypePtr<AdblockPlus::LogSystemPtr>(ptr);
50 }
51
52 JniLogSystemCallback::JniLogSystemCallback(JNIEnv* env, jobject callbackObject) 38 JniLogSystemCallback::JniLogSystemCallback(JNIEnv* env, jobject callbackObject)
53 : JniCallbackBase(env, callbackObject), AdblockPlus::LogSystem() 39 : JniCallbackBase(env, callbackObject), AdblockPlus::LogSystem()
54 { 40 {
55 } 41 }
56 42
57 void JniLogSystemCallback::operator()(AdblockPlus::LogSystem::LogLevel logLevel, 43 void JniLogSystemCallback::operator()(AdblockPlus::LogSystem::LogLevel logLevel,
58 const std::string& message, const std::string& source) 44 const std::string& message, const std::string& source)
59 { 45 {
60 JNIEnvAcquire env(GetJavaVM()); 46 JNIEnvAcquire env(GetJavaVM());
61 47
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 JniLocalReference<jstring> jSource(*env, 90 JniLocalReference<jstring> jSource(*env,
105 env->NewStringUTF(source.c_str())); 91 env->NewStringUTF(source.c_str()));
106 92
107 env->CallVoidMethod(GetCallbackObject(), method, *jLogLevel, *jMessage, 93 env->CallVoidMethod(GetCallbackObject(), method, *jLogLevel, *jMessage,
108 *jSource); 94 *jSource);
109 } 95 }
110 96
111 CheckAndLogJavaException(*env); 97 CheckAndLogJavaException(*env);
112 } 98 }
113 } 99 }
114
115 static JNINativeMethod methods[] =
116 {
117 { (char*)"ctor", (char*)"(Ljava/lang/Object;)J", (void*)JniCtor },
118 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor }
119 };
120
121 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_LogSystem_ registerNatives(JNIEnv *env, jclass clazz)
122 {
123 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0]));
124 }
OLDNEW

Powered by Google App Engine
This is Rietveld