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

Side by Side Diff: jni/JniSubscription.cpp

Issue 6606493159784448: New JNI bindings (Closed)
Patch Set: Cleaned up namespace usage in cpp files. Created March 20, 2014, 3:17 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
(Empty)
1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2014 Eyeo GmbH
4 *
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
7 * published by the Free Software Foundation.
8 *
9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
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/>.
16 */
17
18 #include <AdblockPlus.h>
19 #include "Utils.h"
20 #include "JniJsValue.h"
21
22 static AdblockPlus::Subscription* GetSubscriptionPtr(jlong ptr)
23 {
24 return AdblockPlus::Android::JniLong2TypePtr<AdblockPlus::SubscriptionPtr>(ptr )->get();
25 }
26
27 static jlong JNICALL JniCtor(JNIEnv* env, jclass clazz, jlong jsValue)
28 {
29 TRY
30 {
31 return AdblockPlus::Android::JniPtr2Long(
32 new AdblockPlus::SubscriptionPtr(new AdblockPlus::Subscription(AdblockPl us::Android::JniGetJsValuePtr(jsValue))));
33 }
34 CATCH_THROW_AND_RETURN(env, 0)
35 }
36
37 static jboolean JNICALL JniIsListed(JNIEnv* env, jclass clazz, jlong ptr)
38 {
39 TRY
40 {
41 return GetSubscriptionPtr(ptr)->IsListed() ? JNI_TRUE : JNI_FALSE;
42 }
43 CATCH_THROW_AND_RETURN(env, JNI_FALSE)
44 }
45
46 static void JNICALL JniAddToList(JNIEnv* env, jclass clazz, jlong ptr)
47 {
48 TRY
49 {
50 GetSubscriptionPtr(ptr)->AddToList();
51 }
52 CATCH_AND_THROW(env)
53 }
54
55 static void JNICALL JniRemoveFromList(JNIEnv* env, jclass clazz, jlong ptr)
56 {
57 TRY
58 {
59 GetSubscriptionPtr(ptr)->RemoveFromList();
60 }
61 CATCH_AND_THROW(env)
62 }
63
64 static void JNICALL JniUpdateFilters(JNIEnv* env, jclass clazz, jlong ptr)
65 {
66 TRY
67 {
68 GetSubscriptionPtr(ptr)->UpdateFilters();
69 }
70 CATCH_AND_THROW(env)
71 }
72
73 static jboolean JNICALL JniIsUpdating(JNIEnv* env, jclass clazz, jlong ptr)
74 {
75 TRY
76 {
77 return GetSubscriptionPtr(ptr)->IsUpdating() ? JNI_TRUE : JNI_FALSE;
78 }
79 CATCH_THROW_AND_RETURN(env, JNI_FALSE)
80 }
81
82 static jboolean JNICALL JniOperatorEquals(JNIEnv* env, jclass clazz, jlong ptr, jlong otherPtr)
83 {
84 AdblockPlus::Subscription* me = GetSubscriptionPtr(ptr);
85 AdblockPlus::Subscription* other = GetSubscriptionPtr(otherPtr);
86
87 TRY
88 {
89 return *me == *other ? JNI_TRUE : JNI_FALSE;
90 }
91 CATCH_THROW_AND_RETURN(env, JNI_FALSE)
92 }
93
94 static JNINativeMethod methods[] =
95 {
96 { (char*)"ctor", (char*)"(J)J", (void*)JniCtor },
97 { (char*)"isListed", (char*)"(J)Z", (void*)JniIsListed },
98 { (char*)"addToList", (char*)"(J)V", (void*)JniAddToList },
99 { (char*)"removeFromList", (char*)"(J)V", (void*)JniRemoveFromList },
100 { (char*)"updateFilters", (char*)"(J)V", (void*)JniUpdateFilters },
101 { (char*)"isUpdating", (char*)"(J)Z", (void*)JniIsUpdating },
102 { (char*)"operatorEquals", (char*)"(JJ)Z", (void*)JniOperatorEquals }, };
103
104 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_android_api_Subscription_ registerNatives(JNIEnv *env, jclass clazz)
105 {
106 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0]));
107 }
OLDNEW

Powered by Google App Engine
This is Rietveld