1 //******************************************************************
3 // Copyright 2014 MediaTek All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 #include "ocstack-jni.h"
23 static const char* TAG = "OCREPRESENTATION-JNI";
25 JNIEXPORT jlong JNICALL OCRepresentationConstructor(JNIEnv *env, jobject jobj)
27 OC::OCRepresentation *rep = new OC::OCRepresentation();
28 jlong instptr = reinterpret_cast<jlong>(rep);
32 JNIEXPORT jstring JNICALL getUri(JNIEnv *env, jobject jobj)
34 OC::OCRepresentation *rep = getHandle<OC::OCRepresentation>(env, jobj);
35 string uri = rep->getUri();
36 __android_log_print(ANDROID_LOG_INFO, TAG, "getUri() URI : %s", uri.c_str());
37 return env->NewStringUTF(uri.c_str());
40 JNIEXPORT jint JNICALL getValueInt(JNIEnv *env, jobject jobj, jstring jstr)
42 OC::OCRepresentation *rep = getHandle<OC::OCRepresentation>(env, jobj);
43 string str = env->GetStringUTFChars(jstr,0);
45 rep->getValue(str, val);
46 __android_log_print(ANDROID_LOG_INFO, TAG, "getValueInt() : %d", val);
51 JNIEXPORT jboolean JNICALL getValueBool(JNIEnv *env, jobject jobj, jstring jstr)
53 OC::OCRepresentation *rep = getHandle<OC::OCRepresentation>(env, jobj);
54 string str = env->GetStringUTFChars(jstr,0);
56 rep->getValue(str, val);
57 __android_log_print(ANDROID_LOG_INFO, TAG, "getValueBool() : %d", val);
58 return((jboolean) val);
61 JNIEXPORT jstring JNICALL getValueString(JNIEnv *env, jobject jobj, jstring jstr)
63 OC::OCRepresentation *rep = getHandle<OC::OCRepresentation>(env, jobj);
64 string str = env->GetStringUTFChars(jstr,0);
66 rep->getValue(str, get_val);
68 __android_log_print(ANDROID_LOG_INFO, TAG, "getValueString() : %s", get_val.c_str());
69 return env->NewStringUTF(get_val.c_str());
72 JNIEXPORT void JNICALL setValueInt(JNIEnv *env, jobject jobj, jstring jstr, jint jval)
74 OC::OCRepresentation *rep = getHandle<OC::OCRepresentation>(env, jobj);
75 string str = env->GetStringUTFChars(jstr,0);
76 rep->setValue(str, jval);
79 JNIEXPORT void JNICALL setValueBool(JNIEnv *env, jobject jobj, jstring jstr, jboolean jval)
81 OC::OCRepresentation *rep = getHandle<OC::OCRepresentation>(env, jobj);
82 string str = env->GetStringUTFChars(jstr,0);
83 rep->setValue(str, (bool) jval);
86 JNIEXPORT void JNICALL setValueString(JNIEnv *env, jobject jobj, jstring jstr, jstring jval)
88 OC::OCRepresentation *rep = getHandle<OC::OCRepresentation>(env, jobj);
89 string str = env->GetStringUTFChars(jstr,0);
90 string val = env->GetStringUTFChars(jval,0);
92 rep->setValue(str, val);
95 JNIEXPORT jboolean JNICALL hasAttribute(JNIEnv *env, jobject jobj, jstring jstr)
97 OC::OCRepresentation *rep = getHandle<OC::OCRepresentation>(env, jobj);
98 string str = env->GetStringUTFChars(jstr,0);
100 return rep->hasAttribute(str);