d7c894db49712bb9af52beec406885830b53e5b1
[contrib/iotivity.git] / android / Base / app / jni / ocrepresentation-jni.cpp
1 //******************************************************************
2 //
3 // Copyright 2014 MediaTek All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //
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
10 //
11 //      http://www.apache.org/licenses/LICENSE-2.0
12 //
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.
18 //
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20
21 #include "ocstack-jni.h"
22
23 static const char* TAG = "OCREPRESENTATION-JNI";
24
25 JNIEXPORT jlong JNICALL OCRepresentationConstructor(JNIEnv *env, jobject jobj)
26 {
27     OC::OCRepresentation *rep = new OC::OCRepresentation();
28     jlong instptr = reinterpret_cast<jlong>(rep);
29     return instptr;
30 }
31
32 JNIEXPORT jstring JNICALL getUri(JNIEnv *env, jobject jobj)
33 {
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());
38 }
39
40 JNIEXPORT jint JNICALL getValueInt(JNIEnv *env, jobject jobj, jstring jstr)
41 {
42     OC::OCRepresentation *rep = getHandle<OC::OCRepresentation>(env, jobj);
43         string str = env->GetStringUTFChars(jstr,0);
44         int val;
45     rep->getValue(str, val);
46     __android_log_print(ANDROID_LOG_INFO, TAG, "getValueInt() : %d", val);
47     return((jint) val);
48 }
49
50
51 JNIEXPORT jboolean JNICALL getValueBool(JNIEnv *env, jobject jobj, jstring jstr)
52 {
53     OC::OCRepresentation *rep = getHandle<OC::OCRepresentation>(env, jobj);
54         string str = env->GetStringUTFChars(jstr,0);
55     bool val;
56     rep->getValue(str, val);
57     __android_log_print(ANDROID_LOG_INFO, TAG, "getValueBool() : %d", val);
58     return((jboolean) val);
59 }
60
61 JNIEXPORT jstring JNICALL getValueString(JNIEnv *env, jobject jobj, jstring jstr)
62 {
63     OC::OCRepresentation *rep = getHandle<OC::OCRepresentation>(env, jobj);
64         string str = env->GetStringUTFChars(jstr,0);
65         string get_val;
66     rep->getValue(str, get_val);
67
68     __android_log_print(ANDROID_LOG_INFO, TAG, "getValueString() : %s", get_val.c_str());
69     return env->NewStringUTF(get_val.c_str());
70 }
71
72 JNIEXPORT void JNICALL setValueInt(JNIEnv *env, jobject jobj, jstring jstr, jint jval)
73 {
74     OC::OCRepresentation *rep = getHandle<OC::OCRepresentation>(env, jobj);
75         string str = env->GetStringUTFChars(jstr,0);
76     rep->setValue(str, jval);
77 }
78
79 JNIEXPORT void JNICALL setValueBool(JNIEnv *env, jobject jobj, jstring jstr, jboolean jval)
80 {
81     OC::OCRepresentation *rep = getHandle<OC::OCRepresentation>(env, jobj);
82         string str = env->GetStringUTFChars(jstr,0);
83     rep->setValue(str, (bool) jval);
84 }
85
86 JNIEXPORT void JNICALL setValueString(JNIEnv *env, jobject jobj, jstring jstr, jstring jval)
87 {
88     OC::OCRepresentation *rep = getHandle<OC::OCRepresentation>(env, jobj);
89         string str = env->GetStringUTFChars(jstr,0);
90         string val = env->GetStringUTFChars(jval,0);
91
92     rep->setValue(str, val);
93 }
94
95 JNIEXPORT jboolean JNICALL hasAttribute(JNIEnv *env, jobject jobj, jstring jstr)
96 {
97     OC::OCRepresentation *rep = getHandle<OC::OCRepresentation>(env, jobj);
98         string str = env->GetStringUTFChars(jstr,0);
99
100     return rep->hasAttribute(str);
101 }