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

Unified Diff: jni/Utils.cpp

Issue 6606493159784448: New JNI bindings (Closed)
Patch Set: Added missing copyright header Created March 14, 2014, 11:37 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « jni/Utils.h ('k') | src/com/github/rjeschke/neetutils/Objects.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: jni/Utils.cpp
===================================================================
--- a/jni/Utils.cpp
+++ b/jni/Utils.cpp
@@ -15,6 +15,8 @@
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <string>
+
#include "Utils.h"
#include "Debug.h"
@@ -36,3 +38,54 @@
return value;
}
+
+namespace AdblockPlus
+{
+namespace Android
+{
+
+std::string JniJava2StdString(JNIEnv* env, jstring str)
+{
+ if (!str)
+ {
+ return std::string();
+ }
+
+ const char* cStr = env->GetStringUTFChars(str, 0);
+ std::string ret(cStr);
+ env->ReleaseStringUTFChars(str, cStr);
+
+ return ret;
+}
+
+jobject NewJniArrayList(JNIEnv* env)
+{
+ jclass clazz = env->FindClass("java/util/ArrayList");
+ jmethodID ctor = env->GetMethodID(clazz, "<init>", "()V");
+ return env->NewObject(clazz, ctor);
+}
+
+void JniAddObjectToList(JNIEnv* env, jobject list, jobject value)
+{
+ jmethodID add = env->GetMethodID(env->GetObjectClass(list), "add", "(Ljava/lang/Object;)Z");
+ env->CallBooleanMethod(list, add, value);
+}
+
+void JniThrowException(JNIEnv* env, const std::string& message)
+{
+ jclass clazz = env->FindClass(PKG("AdblockPlusException"));
+ env->ThrowNew(clazz, message.c_str());
+}
+
+void JniThrowException(JNIEnv* env, const std::exception& e)
+{
+ JniThrowException(env, e.what());
+}
+
+void JniThrowException(JNIEnv* env)
+{
+ JniThrowException(env, "Unknown exception from libAdblockPlus");
+}
+
+} // namespace Android
+} // namespace AdblockPlus
« no previous file with comments | « jni/Utils.h ('k') | src/com/github/rjeschke/neetutils/Objects.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld