source: trunk/lang/java/jRpLibrary.cc @ 1735

Last change on this file since 1735 was 1727, checked in by braffert, 12 years ago

Last fix for building java bindings. Also added license info and more comments.

File size: 2.9 KB
Line 
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 */
23JNIEXPORT 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 */
35JNIEXPORT void JNICALL Java_rappture_Library_jRpDeleteLibrary
36  (JNIEnv *env, jobject obj, jlong libPtr){
37  delete (RpLibrary*) libPtr;
38  return;
39}
40
41// getDouble
42JNIEXPORT 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
51JNIEXPORT 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
60JNIEXPORT 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
69JNIEXPORT 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
80JNIEXPORT void JNICALL Java_rappture_Library_jRpResult
81  (JNIEnv *env, jobject obj, jlong libPtr, jint exitStatus){
82  ((RpLibrary*)libPtr)->result(exitStatus);
83}
84
85
Note: See TracBrowser for help on using the repository browser.