| Index: jni/JniNotification.cpp |
| diff --git a/jni/JniNotification.cpp b/jni/JniNotification.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..1dd5eb09013d0a14ba01e71f59a3c3d706101ec5 |
| --- /dev/null |
| +++ b/jni/JniNotification.cpp |
| @@ -0,0 +1,101 @@ |
| +/* |
| + * This file is part of Adblock Plus <https://adblockplus.org/>, |
| + * Copyright (C) 2006-2015 Eyeo GmbH |
| + * |
| + * Adblock Plus is free software: you can redistribute it and/or modify |
| + * it under the terms of the GNU General Public License version 3 as |
| + * published by the Free Software Foundation. |
| + * |
| + * Adblock Plus is distributed in the hope that it will be useful, |
| + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| + * GNU General Public License for more details. |
| + * |
| + * You should have received a copy of the GNU General Public License |
| + * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| + */ |
| + |
| +#include <AdblockPlus.h> |
| +#include "Utils.h" |
| +#include "JniJsValue.h" |
| + |
| +// TODO (rje) apply local_ref |
|
Felix Dahlke
2015/02/18 12:49:56
Ah, TODO comment! :) Sounds like something that ne
René Jeschke
2015/02/18 13:13:02
Nah, was written during the local_ref review to re
|
| + |
| +static AdblockPlus::Notification* GetNotificationPtr(jlong ptr) |
| +{ |
| + return JniLongToTypePtr<AdblockPlus::NotificationPtr>(ptr)->get(); |
| +} |
| + |
| +static jobject JNICALL JniGetType(JNIEnv* env, jclass clazz, jlong ptr) |
| +{ |
| + AdblockPlus::NotificationType type; |
| + try |
| + { |
| + type = GetNotificationPtr(ptr)->GetType(); |
| + } |
| + CATCH_THROW_AND_RETURN(env, 0) |
| + |
| + const char* enumName = 0; |
| + |
| + switch (type) |
| + { |
| + case AdblockPlus::NotificationType::NOTIFICATION_TYPE_CRITICAL: |
| + enumName = "CRITICAL"; |
| + break; |
| + case AdblockPlus::NotificationType::NOTIFICATION_TYPE_INFORMATION: |
| + enumName = "INFORMATION"; |
| + break; |
| + case AdblockPlus::NotificationType::NOTIFICATION_TYPE_QUESTION: |
| + enumName = "QUESTION"; |
| + break; |
| + default: |
| + enumName = "INVALID"; |
| + break; |
| + } |
| + |
| + jclass enumClass = env->FindClass(PKG("Notification$Type")); |
| + jfieldID enumField = env->GetStaticFieldID(enumClass, enumName, TYP("Notification$Type")); |
| + return env->GetStaticObjectField(enumClass, enumField); |
| +} |
| + |
| +static jstring JniGetTitle(JNIEnv* env, jclass clazz, jlong ptr) |
| +{ |
| + try |
| + { |
| + return env->NewStringUTF(GetNotificationPtr(ptr)->GetTitle().c_str()); |
| + } |
| + CATCH_THROW_AND_RETURN(env, 0) |
| +} |
| + |
| +static jstring JniGetMessageString(JNIEnv* env, jclass clazz, jlong ptr) |
| +{ |
| + try |
| + { |
| + return env->NewStringUTF(GetNotificationPtr(ptr)->GetMessageString().c_str()); |
| + } |
| + CATCH_THROW_AND_RETURN(env, 0) |
| +} |
| + |
| +static void JniMarkAsShown(JNIEnv* env, jclass clazz, jlong ptr) |
| +{ |
| + try |
| + { |
| + GetNotificationPtr(ptr)->MarkAsShown(); |
| + } |
| + CATCH_AND_THROW(env) |
| +} |
| + |
| +static JNINativeMethod methods[] = |
| +{ |
| + { (char*) "markAsShown", (char*) "(J)V", (void*) JniMarkAsShown }, |
| + { (char*) "getMessageString", (char*) "(J)Ljava/lang/String;", (void*) JniGetMessageString }, |
| + { (char*) "getTitle", (char*) "(J)Ljava/lang/String;", (void*) JniGetTitle }, |
| + { (char*) "getType", (char*) "(J)" TYP("Notification$Type"), (void*) JniGetType } |
| +}; |
| + |
| +extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_Notification_registerNatives( |
| + JNIEnv *env, jclass clazz) |
| +{ |
| + env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); |
| +} |
| + |