- Timestamp:
- Jun 9, 2010, 11:05:15 AM (14 years ago)
- Location:
- trunk/lang/java
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lang/java/Library.java
r1749 r1753 27 27 } 28 28 29 public Library(){ 30 libPtr = jRpLibrary(null); 31 } 32 29 33 // Pseudo-Destructor. Called when the object is garbage collected.---------- 30 34 protected void finalize() throws Throwable { … … 48 52 public String getString(String path){ 49 53 return jRpGetString(libPtr, path); 54 } 55 56 public int getInt(String path){ 57 return jRpGetInt(libPtr, path); 50 58 } 51 59 … … 99 107 private native byte[] jRpGetData(long libPtr, String path); 100 108 private native double jRpGetDouble(long libPtr, String path); 109 private native int jRpGetInt(long libPtr, String path); 101 110 private native String jRpGetString(long libPtr, String path); 102 111 -
trunk/lang/java/Units.java
r1732 r1753 27 27 } 28 28 29 public static String convert(String fromVal, String to){ 30 return jRpUnitsConvert(fromVal, to, true); 31 } 32 29 33 private static native String jRpUnitsConvert(String fromVal, String to, boolean units); 30 34 } -
trunk/lang/java/jRpLibrary.cc
r1749 r1753 1 /* 2 * ====================================================================== 1 /* * ====================================================================== 3 2 * AUTHOR: Ben Rafferty, Purdue University 4 3 * Copyright (c) 2010 Purdue Research Foundation … … 18 17 19 18 /* 20 * Constructor. Returns the address of the newly created RpLibrary object to19 * Constructor. Creates a C++ RpLibrary object and returns its address to 21 20 * java as a long int. 22 21 */ 23 22 JNIEXPORT jlong JNICALL Java_rappture_Library_jRpLibrary 24 23 (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); 24 RpLibrary* lib = NULL; 25 const char* nativePath; 26 jclass ex; 27 28 if (javaPath == NULL){ 29 lib = new RpLibrary(); 30 } 31 else{ 32 nativePath = env->GetStringUTFChars(javaPath, 0); 33 lib = new RpLibrary(nativePath); 34 env->ReleaseStringUTFChars(javaPath, nativePath); 35 } 36 37 if (lib == NULL){ 38 ex = env->FindClass("java/lang/NullPointerException"); 39 if (ex){ 40 env->ThrowNew(ex, "Could not create rappture library."); 41 } 42 env->DeleteLocalRef(ex); 43 } 44 28 45 return (jlong)lib; 29 46 } 30 47 31 48 /* 32 * Pseudo-destructor. This function is called by the java Library class's 33 * finalizer. 49 * Destructor. This function is called by the java Library class's 50 * finalizer. Deletes the C++ RpLibrary object when the java Library 51 * is garbage collected. 34 52 */ 35 53 JNIEXPORT void JNICALL Java_rappture_Library_jRpDeleteLibrary … … 51 69 } 52 70 53 54 71 // getDouble 55 72 JNIEXPORT jdouble JNICALL Java_rappture_Library_jRpGetDouble … … 59 76 env->ReleaseStringUTFChars(javaPath, nativePath); 60 77 return (jdouble)retDVal; 78 } 79 80 // getInt 81 JNIEXPORT jint JNICALL Java_rappture_Library_jRpGetInt 82 (JNIEnv *env, jobject obj, jlong libPtr, jstring javaPath){ 83 const char* nativePath = env->GetStringUTFChars(javaPath, 0); 84 int retIVal = ((RpLibrary*)libPtr)->getInt(nativePath); 85 env->ReleaseStringUTFChars(javaPath, nativePath); 86 return (jint)retIVal; 61 87 } 62 88 … … 119 145 } 120 146 121 -
trunk/lang/java/jRpUnits.cc
r1727 r1753 22 22 const char* nativeFromVal = env->GetStringUTFChars(javaFromVal, 0); 23 23 const char* nativeTo = env->GetStringUTFChars(javaTo, 0); 24 std::string retStr = RpUnits::convert(nativeFromVal, nativeTo, (int)units); 24 int err; 25 jclass ex; 26 std::string errorMsg; 27 28 // perform conversion 29 std::string retStr = RpUnits::convert(nativeFromVal, nativeTo, 30 (int)units, &err); 31 32 // raise a runtime exception on error 33 if (err){ 34 ex = env->FindClass("java/lang/RuntimeException"); 35 if (ex){ 36 errorMsg = "Connot convert "; 37 errorMsg += nativeFromVal; 38 errorMsg += " to "; 39 errorMsg += nativeTo; 40 env->ThrowNew(ex, errorMsg.c_str()); 41 } 42 env->DeleteLocalRef(ex); 43 } 44 25 45 env->ReleaseStringUTFChars(javaFromVal, nativeFromVal); 26 46 env->ReleaseStringUTFChars(javaTo, nativeTo); 47 48 // create new java string and return 27 49 return (env->NewStringUTF(retStr.c_str())); 28 50 } -
trunk/lang/java/jRpUtils.cc
r1727 r1753 20 20 JNIEXPORT void JNICALL Java_rappture_Utils_jRpUtilsProgress 21 21 (JNIEnv *env, jclass cls, jint percent, jstring javaText){ 22 const char* nativeText = env->GetStringUTFChars(javaText, 0); 23 Rappture::Utils::progress(percent, nativeText); 22 const char* nativeText = env->GetStringUTFChars(javaText, 0); 23 int err = Rappture::Utils::progress(percent, nativeText); 24 jclass ex; 25 if (err){ 26 ex = env->FindClass("java/lang/RuntimeException"); 27 if (ex){ 28 env->ThrowNew(ex, "rappture.Utils.progress failed."); 29 } 30 env->DeleteLocalRef(ex); 31 } 24 32 env->ReleaseStringUTFChars(javaText, nativeText); 25 33 return;
Note: See TracChangeset
for help on using the changeset viewer.