1 | /* |
---|
2 | * ====================================================================== |
---|
3 | * AUTHOR: Ben Rafferty, Purdue University |
---|
4 | * Copyright (c) 2010 Purdue Research Foundation |
---|
5 | * |
---|
6 | * See the file "license.terms" for information on usage and |
---|
7 | * redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
8 | * ====================================================================== |
---|
9 | */ |
---|
10 | |
---|
11 | /* |
---|
12 | * This file defines the native functions which are called by the java Library |
---|
13 | * class methods, and in turn call the corresponding rappture RpLibrary methods. |
---|
14 | */ |
---|
15 | |
---|
16 | #include "jRpLibrary.h" |
---|
17 | #include "rappture.h" |
---|
18 | |
---|
19 | /* |
---|
20 | * Constructor. Returns the address of the newly created RpLibrary object to |
---|
21 | * java as a long int. |
---|
22 | */ |
---|
23 | JNIEXPORT jlong JNICALL Java_rappture_Library_jRpLibrary |
---|
24 | (JNIEnv *env, jobject obj, jstring javaPath){ |
---|
25 | const char* nativePath = env->GetStringUTFChars(javaPath, 0); |
---|
26 | RpLibrary* lib = new RpLibrary(nativePath); |
---|
27 | env->ReleaseStringUTFChars(javaPath, nativePath); |
---|
28 | return (jlong)lib; |
---|
29 | } |
---|
30 | |
---|
31 | /* |
---|
32 | * Pseudo-destructor. This function is called by the java Library class's |
---|
33 | * finalizer. |
---|
34 | */ |
---|
35 | JNIEXPORT void JNICALL Java_rappture_Library_jRpDeleteLibrary |
---|
36 | (JNIEnv *env, jobject obj, jlong libPtr){ |
---|
37 | delete (RpLibrary*) libPtr; |
---|
38 | return; |
---|
39 | } |
---|
40 | |
---|
41 | // getDouble |
---|
42 | JNIEXPORT jdouble JNICALL Java_rappture_Library_jRpGetDouble |
---|
43 | (JNIEnv *env, jobject obj, jlong libPtr, jstring javaPath){ |
---|
44 | const char* nativePath = env->GetStringUTFChars(javaPath, 0); |
---|
45 | double retDVal = ((RpLibrary*)libPtr)->getDouble(nativePath); |
---|
46 | env->ReleaseStringUTFChars(javaPath, nativePath); |
---|
47 | return (jdouble)retDVal; |
---|
48 | } |
---|
49 | |
---|
50 | // getString |
---|
51 | JNIEXPORT jstring JNICALL Java_rappture_Library_jRpGetString |
---|
52 | (JNIEnv *env, jobject obj, jlong libPtr, jstring javaPath){ |
---|
53 | const char* nativePath = env->GetStringUTFChars(javaPath, 0); |
---|
54 | std::string retStr = ((RpLibrary*)libPtr)->getString(nativePath); |
---|
55 | env->ReleaseStringUTFChars(javaPath, nativePath); |
---|
56 | return(env->NewStringUTF(retStr.c_str())); |
---|
57 | } |
---|
58 | |
---|
59 | // putDouble |
---|
60 | JNIEXPORT void JNICALL Java_rappture_Library_jRpPutDouble |
---|
61 | (JNIEnv *env, jobject obj, jlong libPtr, jstring javaPath, |
---|
62 | jdouble value, jboolean append){ |
---|
63 | const char* nativePath = env->GetStringUTFChars(javaPath, 0); |
---|
64 | ((RpLibrary*)libPtr)->put(nativePath, value, "", (int)append); |
---|
65 | env->ReleaseStringUTFChars(javaPath, nativePath); |
---|
66 | } |
---|
67 | |
---|
68 | // put |
---|
69 | JNIEXPORT void JNICALL Java_rappture_Library_jRpPut |
---|
70 | (JNIEnv *env, jobject obj, jlong libPtr, jstring javaPath, jstring javaValue, jboolean append){ |
---|
71 | const char* nativePath = env->GetStringUTFChars(javaPath, 0); |
---|
72 | const char* nativeValue = env->GetStringUTFChars(javaValue, 0); |
---|
73 | ((RpLibrary*)libPtr)->put(nativePath, nativeValue, "", (int)append); |
---|
74 | env->ReleaseStringUTFChars(javaPath, nativePath); |
---|
75 | env->ReleaseStringUTFChars(javaValue, nativeValue); |
---|
76 | } |
---|
77 | |
---|
78 | |
---|
79 | // result |
---|
80 | JNIEXPORT void JNICALL Java_rappture_Library_jRpResult |
---|
81 | (JNIEnv *env, jobject obj, jlong libPtr, jint exitStatus){ |
---|
82 | ((RpLibrary*)libPtr)->result(exitStatus); |
---|
83 | } |
---|
84 | |
---|
85 | |
---|