source: branches/1.6/lang/java/jRpLibrary.cc @ 6221

Last change on this file since 6221 was 5679, checked in by ldelgass, 9 years ago

Full merge 1.3 branch to uq branch to sync. Fixed partial subdirectory merge
by removing mergeinfo from lang/python/Rappture directory.

  • Property svn:eol-style set to native
File size: 5.3 KB
Line 
1/* * ======================================================================
2 *  AUTHOR:  Ben Rafferty, Purdue University
3 *  Copyright (c) 2004-2012  HUBzero Foundation, LLC
4 *
5 *  See the file "license.terms" for information on usage and
6 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
7 * ======================================================================
8 */
9
10/*
11 * This file defines the native functions which are called by the java Library
12 * class methods, and in turn call the corresponding rappture RpLibrary methods.
13 */
14
15#include "jRpLibrary.h"
16#include "rappture.h"
17
18/*
19 * Constructor.  Creates a C++ RpLibrary object and returns its address to
20 * java as a long int.
21 */
22JNIEXPORT jlong JNICALL Java_rappture_Library_jRpLibrary
23  (JNIEnv *env, jobject obj, jstring javaPath){
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
45  return (jlong)lib;
46}
47
48/*
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.
52 */
53JNIEXPORT void JNICALL Java_rappture_Library_jRpDeleteLibrary
54  (JNIEnv *env, jobject obj, jlong libPtr){
55  delete (RpLibrary*) libPtr;
56  return;
57}
58
59// getData
60JNIEXPORT jbyteArray JNICALL Java_rappture_Library_jRpGetData
61  (JNIEnv *env, jobject obj, jlong libPtr, jstring javaPath){
62  const char* nativePath = env->GetStringUTFChars(javaPath, 0);
63  Rappture::Buffer buf = ((RpLibrary*)libPtr)->getData(nativePath);
64  size_t size = buf.size();
65  _jbyteArray* jbuf = env->NewByteArray(size);
66  env->SetByteArrayRegion(jbuf, 0, size, (const jbyte*)buf.bytes());
67  env->ReleaseStringUTFChars(javaPath, nativePath);
68  return jbuf;
69}
70
71// getDouble
72JNIEXPORT jdouble JNICALL Java_rappture_Library_jRpGetDouble
73  (JNIEnv *env, jobject obj, jlong libPtr, jstring javaPath){
74  const char* nativePath = env->GetStringUTFChars(javaPath, 0);
75  double retDVal = ((RpLibrary*)libPtr)->getDouble(nativePath);
76  env->ReleaseStringUTFChars(javaPath, nativePath);
77  return (jdouble)retDVal;
78}
79
80// getInt
81JNIEXPORT 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;
87}
88
89// getString
90JNIEXPORT jstring JNICALL Java_rappture_Library_jRpGetString
91  (JNIEnv *env, jobject obj, jlong libPtr, jstring javaPath){
92  const char* nativePath = env->GetStringUTFChars(javaPath, 0);
93  std::string retStr = ((RpLibrary*)libPtr)->getString(nativePath);
94  env->ReleaseStringUTFChars(javaPath, nativePath);
95  return(env->NewStringUTF(retStr.c_str()));
96}
97
98// putDouble
99JNIEXPORT void JNICALL Java_rappture_Library_jRpPutDouble
100  (JNIEnv *env, jobject obj, jlong libPtr, jstring javaPath,
101   jdouble value, jboolean append){
102  const char* nativePath = env->GetStringUTFChars(javaPath, 0);
103  ((RpLibrary*)libPtr)->put(nativePath, value, "", (int)append);
104  env->ReleaseStringUTFChars(javaPath, nativePath);
105}
106
107// put
108JNIEXPORT void JNICALL Java_rappture_Library_jRpPut
109  (JNIEnv *env, jobject obj, jlong libPtr, jstring javaPath, jstring javaValue, jboolean append){
110  const char* nativePath = env->GetStringUTFChars(javaPath, 0);
111  const char* nativeValue = env->GetStringUTFChars(javaValue, 0);
112  ((RpLibrary*)libPtr)->put(nativePath, nativeValue, "", (int)append);
113  env->ReleaseStringUTFChars(javaPath, nativePath);
114  env->ReleaseStringUTFChars(javaValue, nativeValue);
115}
116
117// putData
118JNIEXPORT void JNICALL Java_rappture_Library_jRpPutData
119  (JNIEnv *env, jobject obj, jlong libPtr, jstring javaPath,
120    jbyteArray jb, jint nbytes, jboolean append){
121  const char* nativePath = env->GetStringUTFChars(javaPath, 0);
122  jbyte* b = env->GetByteArrayElements(jb, NULL);
123  ((RpLibrary*)libPtr)->putData(nativePath, (const char*)b,
124                                nbytes, (int)append);
125  env->ReleaseByteArrayElements(jb, b, 0);
126  env->ReleaseStringUTFChars(javaPath, nativePath);
127}
128
129// putFile
130JNIEXPORT void JNICALL Java_rappture_Library_jRpPutFile
131  (JNIEnv *env, jobject obj, jlong libPtr, jstring javaPath,
132   jstring javaFileName, jboolean compress, jboolean append){
133  const char* nativePath = env->GetStringUTFChars(javaPath, 0);
134  const char* nativeFileName = env->GetStringUTFChars(javaFileName, 0);
135  ((RpLibrary*)libPtr)->putFile(nativePath, nativeFileName,
136                                (int)compress, (int)append);
137  env->ReleaseStringUTFChars(javaPath, nativePath);
138  env->ReleaseStringUTFChars(javaFileName, nativeFileName);
139}
140
141// result
142JNIEXPORT void JNICALL Java_rappture_Library_jRpResult
143  (JNIEnv *env, jobject obj, jlong libPtr, jint exitStatus){
144  ((RpLibrary*)libPtr)->result(exitStatus);
145}
146
147// xml
148JNIEXPORT jstring JNICALL Java_rappture_Library_jRpXml
149  (JNIEnv *env, jobject obj, jlong libPtr) {
150  std::string retStr = ((RpLibrary*)libPtr)->xml();
151  return(env->NewStringUTF(retStr.c_str()));
152}
153
Note: See TracBrowser for help on using the repository browser.