2 * //******************************************************************
\r
4 * // Copyright 2015 Intel Corporation.
\r
6 * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
\r
8 * // Licensed under the Apache License, Version 2.0 (the "License");
\r
9 * // you may not use this file except in compliance with the License.
\r
10 * // You may obtain a copy of the License at
\r
12 * // http://www.apache.org/licenses/LICENSE-2.0
\r
14 * // Unless required by applicable law or agreed to in writing, software
\r
15 * // distributed under the License is distributed on an "AS IS" BASIS,
\r
16 * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
17 * // See the License for the specific language governing permissions and
\r
18 * // limitations under the License.
\r
20 * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
\r
22 #include "JniOcRepresentation.h"
\r
23 #include "JniUtils.h"
\r
27 OCRepresentation* JniOcRepresentation::getOCRepresentationPtr(JNIEnv *env, jobject thiz)
\r
29 OCRepresentation *rep = GetHandle<OCRepresentation>(env, thiz);
\r
30 if (env->ExceptionCheck())
\r
32 LOGE("Failed to get native handle from OcRepresentation");
\r
36 ThrowOcException(JNI_NO_NATIVE_POINTER, "");
\r
42 * Class: org_iotivity_base_OcRepresentation
\r
44 * Signature: (Ljava/lang/String;)Ljava/lang/Object;
\r
46 JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcRepresentation_getValueN
\r
47 (JNIEnv *env, jobject thiz, jstring jKey)
\r
49 LOGD("OcRepresentation_getValue");
\r
52 ThrowOcException(OC_STACK_INVALID_PARAM, "attributeKey cannot be null");
\r
55 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
\r
56 if (!rep) return nullptr;
\r
58 std::string key = env->GetStringUTFChars(jKey, NULL);
\r
60 AttributeValue attrValue;
\r
61 if (!rep->getAttributeValue(key.c_str(), attrValue))
\r
63 ThrowOcException(JNI_NO_SUCH_KEY, " attribute key does not exist");
\r
66 return boost::apply_visitor(JObjectConverter(env), attrValue);
\r
70 * Class: org_iotivity_base_OcRepresentation
\r
71 * Method: setValueInteger
\r
72 * Signature: (Ljava/lang/String;I)V
\r
74 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueInteger
\r
75 (JNIEnv *env, jobject thiz, jstring jKey, jint jValue)
\r
77 LOGD("OcRepresentation_setValueInteger");
\r
80 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
\r
83 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
\r
86 std::string str = env->GetStringUTFChars(jKey, NULL);
\r
87 rep->setValue(str, static_cast<int>(jValue));
\r
91 * Class: org_iotivity_base_OcRepresentation
\r
92 * Method: setValueDouble
\r
93 * Signature: (Ljava/lang/String;D)V
\r
95 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueDouble
\r
96 (JNIEnv *env, jobject thiz, jstring jKey, jdouble jValue)
\r
98 LOGD("OcRepresentation_setValueDouble");
\r
101 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
\r
104 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
\r
107 std::string str = env->GetStringUTFChars(jKey, NULL);
\r
108 rep->setValue(str, static_cast<double>(jValue));
\r
112 * Class: org_iotivity_base_OcRepresentation
\r
113 * Method: setValueBoolean
\r
114 * Signature: (Ljava/lang/String;Z)V
\r
116 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueBoolean
\r
117 (JNIEnv *env, jobject thiz, jstring jKey, jboolean jValue)
\r
119 LOGD("OcRepresentation_setValueBoolean");
\r
122 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
\r
125 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
\r
128 std::string str = env->GetStringUTFChars(jKey, NULL);
\r
129 rep->setValue(str, static_cast<bool>(jValue));
\r
133 * Class: org_iotivity_base_OcRepresentation
\r
134 * Method: setValueStringN
\r
135 * Signature: (Ljava/lang/String;Ljava/lang/String;)V
\r
137 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueStringN
\r
138 (JNIEnv *env, jobject thiz, jstring jKey, jstring jValue)
\r
140 LOGD("OcRepresentation_setValueString");
\r
143 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
\r
146 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
\r
149 std::string key = env->GetStringUTFChars(jKey, NULL);
\r
150 std::string value = env->GetStringUTFChars(jValue, NULL);
\r
152 rep->setValue(key, value);
\r
156 * Class: org_iotivity_base_OcRepresentation
\r
157 * Method: setValueRepresentation
\r
158 * Signature: (Ljava/lang/String;Lorg/iotivity/base/OcRepresentation;)V
\r
160 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueRepresentation
\r
161 (JNIEnv *env, jobject thiz, jstring jKey, jobject jValue)
\r
163 LOGD("OcRepresentation_setValueRepresentation");
\r
166 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
\r
169 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
\r
172 std::string key = env->GetStringUTFChars(jKey, NULL);
\r
173 OCRepresentation *value = JniOcRepresentation::getOCRepresentationPtr(env, jValue);
\r
174 if (!value) return;
\r
176 rep->setValue(key, *value);
\r
180 * Class: org_iotivity_base_OcRepresentation
\r
181 * Method: setValueIntegerArray
\r
182 * Signature: (Ljava/lang/String;[I)V
\r
184 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueIntegerArray
\r
185 (JNIEnv *env, jobject thiz, jstring jKey, jintArray jValue)
\r
187 LOGD("OcRepresentation_setValueIntegerArray");
\r
190 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
\r
194 const jsize len = env->GetArrayLength(jValue);
\r
195 jint* ints = env->GetIntArrayElements(jValue, NULL);
\r
197 std::vector<int> value;
\r
198 for (jsize i = 0; i < len; ++i)
\r
200 value.push_back(static_cast<int>(ints[i]));
\r
202 env->ReleaseIntArrayElements(jValue, ints, JNI_ABORT);
\r
204 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
\r
207 std::string key = env->GetStringUTFChars(jKey, NULL);
\r
208 rep->setValue(key, value);
\r
212 * Class: org_iotivity_base_OcRepresentation
\r
213 * Method: setValueInteger2DArray
\r
214 * Signature: (Ljava/lang/String;[[I)V
\r
216 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueInteger2DArray
\r
217 (JNIEnv *env, jobject thiz, jstring jKey, jobjectArray jValue)
\r
219 LOGD("OcRepresentation__setValueInteger2DArray");
\r
222 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
\r
225 std::vector<std::vector<int>> value;
\r
226 const jsize lenOuter = env->GetArrayLength(jValue);
\r
227 for (jsize j = 0; j < lenOuter; ++j)
\r
229 jintArray jInnerArray = static_cast<jintArray>(env->GetObjectArrayElement(jValue, j));
\r
230 jint* ints = env->GetIntArrayElements(jInnerArray, NULL);
\r
231 std::vector<int> innerVector;
\r
232 const jsize lenInner = env->GetArrayLength(jInnerArray);
\r
233 for (jsize i = 0; i < lenInner; ++i)
\r
235 innerVector.push_back(static_cast<int>(ints[i]));
\r
237 env->ReleaseIntArrayElements(jInnerArray, ints, JNI_ABORT);
\r
238 env->DeleteLocalRef(jInnerArray);
\r
239 value.push_back(innerVector);
\r
242 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
\r
245 std::string key = env->GetStringUTFChars(jKey, NULL);
\r
246 rep->setValue(key, value);
\r
250 * Class: org_iotivity_base_OcRepresentation
\r
251 * Method: setValueInteger3DArray
\r
252 * Signature: (Ljava/lang/String;[[[I)V
\r
254 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueInteger3DArray
\r
255 (JNIEnv *env, jobject thiz, jstring jKey, jobjectArray jValue)
\r
257 LOGD("OcRepresentation_setValueInteger3DArray");
\r
260 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
\r
263 std::vector<std::vector<std::vector<int>>> value;
\r
264 const jsize lenOuter = env->GetArrayLength(jValue);
\r
265 for (jsize k = 0; k < lenOuter; ++k)
\r
267 jobjectArray jMiddleArray = static_cast<jobjectArray>(env->GetObjectArrayElement(jValue, k));
\r
268 const jsize lenMiddle = env->GetArrayLength(jMiddleArray);
\r
269 std::vector<std::vector<int>> middleArray;
\r
270 for (jsize j = 0; j < lenMiddle; ++j)
\r
272 jintArray jInnerArray = static_cast<jintArray>(env->GetObjectArrayElement(jMiddleArray, j));
\r
273 jint* ints = env->GetIntArrayElements(jInnerArray, NULL);
\r
274 std::vector<int> innerVector;
\r
275 const jsize lenInner = env->GetArrayLength(jInnerArray);
\r
276 for (jsize i = 0; i < lenInner; ++i)
\r
278 innerVector.push_back(static_cast<int>(ints[i]));
\r
280 env->ReleaseIntArrayElements(jInnerArray, ints, JNI_ABORT);
\r
281 env->DeleteLocalRef(jInnerArray);
\r
282 middleArray.push_back(innerVector);
\r
284 env->DeleteLocalRef(jMiddleArray);
\r
285 value.push_back(middleArray);
\r
288 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
\r
291 std::string key = env->GetStringUTFChars(jKey, NULL);
\r
292 rep->setValue(key, value);
\r
296 * Class: org_iotivity_base_OcRepresentation
\r
297 * Method: setValueDoubleArray
\r
298 * Signature: (Ljava/lang/String;[D)V
\r
300 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueDoubleArray
\r
301 (JNIEnv *env, jobject thiz, jstring jKey, jdoubleArray jValue)
\r
303 LOGD("OcRepresentation_setValueDoubleArray");
\r
306 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
\r
310 const jsize len = env->GetArrayLength(jValue);
\r
311 jdouble* doubles = env->GetDoubleArrayElements(jValue, NULL);
\r
313 std::vector<double> value;
\r
314 for (jsize i = 0; i < len; ++i)
\r
316 value.push_back(static_cast<double>(doubles[i]));
\r
318 env->ReleaseDoubleArrayElements(jValue, doubles, JNI_ABORT);
\r
320 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
\r
323 std::string key = env->GetStringUTFChars(jKey, NULL);
\r
324 rep->setValue(key, value);
\r
328 * Class: org_iotivity_base_OcRepresentation
\r
329 * Method: setValueDouble2DArray
\r
330 * Signature: (Ljava/lang/String;[[D)V
\r
332 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueDouble2DArray
\r
333 (JNIEnv *env, jobject thiz, jstring jKey, jobjectArray jValue)
\r
335 LOGD("OcRepresentation_setValueDouble2DArray");
\r
338 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
\r
341 std::vector<std::vector<double>> value;
\r
342 const jsize lenOuter = env->GetArrayLength(jValue);
\r
343 for (jsize j = 0; j < lenOuter; ++j)
\r
345 jdoubleArray jInnerArray = static_cast<jdoubleArray>(env->GetObjectArrayElement(jValue, j));
\r
346 jdouble* doubles = env->GetDoubleArrayElements(jInnerArray, NULL);
\r
347 std::vector<double> innerVector;
\r
348 const jsize lenInner = env->GetArrayLength(jInnerArray);
\r
349 for (jsize i = 0; i < lenInner; ++i)
\r
351 innerVector.push_back(static_cast<double>(doubles[i]));
\r
353 env->ReleaseDoubleArrayElements(jInnerArray, doubles, JNI_ABORT);
\r
354 env->DeleteLocalRef(jInnerArray);
\r
355 value.push_back(innerVector);
\r
358 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
\r
361 std::string key = env->GetStringUTFChars(jKey, NULL);
\r
362 rep->setValue(key, value);
\r
366 * Class: org_iotivity_base_OcRepresentation
\r
367 * Method: setValueDouble3DArray
\r
368 * Signature: (Ljava/lang/String;[[[D)V
\r
370 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueDouble3DArray
\r
371 (JNIEnv *env, jobject thiz, jstring jKey, jobjectArray jValue)
\r
373 LOGD("OcRepresentation_setValueDouble3DArray");
\r
376 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
\r
379 std::vector<std::vector<std::vector<double>>> value;
\r
380 const jsize lenOuter = env->GetArrayLength(jValue);
\r
381 for (jsize k = 0; k < lenOuter; ++k)
\r
383 jobjectArray jMiddleArray = static_cast<jobjectArray>(env->GetObjectArrayElement(jValue, k));
\r
384 const jsize lenMiddle = env->GetArrayLength(jMiddleArray);
\r
385 std::vector<std::vector<double>> middleArray;
\r
386 for (jsize j = 0; j < lenMiddle; ++j)
\r
388 jdoubleArray jInnerArray = static_cast<jdoubleArray>(env->GetObjectArrayElement(jMiddleArray, j));
\r
389 jdouble* doubles = env->GetDoubleArrayElements(jInnerArray, NULL);
\r
390 std::vector<double> innerVector;
\r
391 const jsize lenInner = env->GetArrayLength(jInnerArray);
\r
392 for (jsize i = 0; i < lenInner; ++i)
\r
394 innerVector.push_back(static_cast<double>(doubles[i]));
\r
396 env->ReleaseDoubleArrayElements(jInnerArray, doubles, JNI_ABORT);
\r
397 env->DeleteLocalRef(jInnerArray);
\r
398 middleArray.push_back(innerVector);
\r
400 env->DeleteLocalRef(jMiddleArray);
\r
401 value.push_back(middleArray);
\r
404 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
\r
407 std::string key = env->GetStringUTFChars(jKey, NULL);
\r
408 rep->setValue(key, value);
\r
412 * Class: org_iotivity_base_OcRepresentation
\r
413 * Method: setValueBooleanArray
\r
414 * Signature: (Ljava/lang/String;[Z)V
\r
416 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueBooleanArray
\r
417 (JNIEnv *env, jobject thiz, jstring jKey, jbooleanArray jValue)
\r
419 LOGD("OcRepresentation_setValueBooleanArray");
\r
422 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
\r
426 const jsize len = env->GetArrayLength(jValue);
\r
427 jboolean* booleans = env->GetBooleanArrayElements(jValue, NULL);
\r
429 std::vector<bool> value;
\r
430 for (jsize i = 0; i < len; ++i)
\r
432 value.push_back(static_cast<bool>(booleans[i]));
\r
434 env->ReleaseBooleanArrayElements(jValue, booleans, JNI_ABORT);
\r
436 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
\r
439 std::string key = env->GetStringUTFChars(jKey, NULL);
\r
440 rep->setValue(key, value);
\r
444 * Class: org_iotivity_base_OcRepresentation
\r
445 * Method: setValueBoolean2DArray
\r
446 * Signature: (Ljava/lang/String;[[Z)V
\r
448 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueBoolean2DArray
\r
449 (JNIEnv *env, jobject thiz, jstring jKey, jobjectArray jValue)
\r
451 LOGD("OcRepresentation_setValueBoolean2DArray");
\r
454 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
\r
457 std::vector<std::vector<bool>> value;
\r
458 const jsize lenOuter = env->GetArrayLength(jValue);
\r
459 for (jsize j = 0; j < lenOuter; ++j)
\r
461 jbooleanArray jInnerArray = static_cast<jbooleanArray>(env->GetObjectArrayElement(jValue, j));
\r
462 const jsize lenInner = env->GetArrayLength(jInnerArray);
\r
463 jboolean* booleans = env->GetBooleanArrayElements(jInnerArray, NULL);
\r
465 std::vector<bool> innerVector;
\r
466 for (jsize i = 0; i < lenInner; ++i)
\r
468 innerVector.push_back(static_cast<bool>(booleans[i]));
\r
470 env->ReleaseBooleanArrayElements(jInnerArray, booleans, JNI_ABORT);
\r
471 env->DeleteLocalRef(jInnerArray);
\r
472 value.push_back(innerVector);
\r
475 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
\r
478 std::string key = env->GetStringUTFChars(jKey, NULL);
\r
479 rep->setValue(key, value);
\r
483 * Class: org_iotivity_base_OcRepresentation
\r
484 * Method: setValueBoolean3DArray
\r
485 * Signature: (Ljava/lang/String;[[[Z)V
\r
487 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueBoolean3DArray
\r
488 (JNIEnv *env, jobject thiz, jstring jKey, jobjectArray jValue)
\r
490 LOGD("OcRepresentation_setValueBoolean3DArray");
\r
493 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
\r
496 std::vector<std::vector<std::vector<bool>>> value;
\r
497 const jsize lenOuter = env->GetArrayLength(jValue);
\r
498 for (jsize k = 0; k < lenOuter; ++k)
\r
500 jobjectArray jMiddleArray = static_cast<jobjectArray>(env->GetObjectArrayElement(jValue, k));
\r
501 const jsize lenMiddle = env->GetArrayLength(jMiddleArray);
\r
502 std::vector<std::vector<bool>> middleArray;
\r
503 for (jsize j = 0; j < lenMiddle; ++j)
\r
505 jbooleanArray jInnerArray = static_cast<jbooleanArray>(env->GetObjectArrayElement(jMiddleArray, j));
\r
506 const jsize lenInner = env->GetArrayLength(jInnerArray);
\r
507 jboolean* booleans = env->GetBooleanArrayElements(jInnerArray, NULL);
\r
509 std::vector<bool> innerVector;
\r
510 for (jsize i = 0; i < lenInner; ++i)
\r
512 innerVector.push_back(static_cast<bool>(booleans[i]));
\r
514 env->ReleaseBooleanArrayElements(jInnerArray, booleans, JNI_ABORT);
\r
515 env->DeleteLocalRef(jInnerArray);
\r
516 middleArray.push_back(innerVector);
\r
518 env->DeleteLocalRef(jMiddleArray);
\r
519 value.push_back(middleArray);
\r
522 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
\r
525 std::string key = env->GetStringUTFChars(jKey, NULL);
\r
526 rep->setValue(key, value);
\r
530 * Class: org_iotivity_base_OcRepresentation
\r
531 * Method: setValueStringArray
\r
532 * Signature: (Ljava/lang/String;[Ljava/lang/String;)V
\r
534 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueStringArray
\r
535 (JNIEnv *env, jobject thiz, jstring jKey, jobjectArray jValue)
\r
537 LOGD("OcRepresentation_setValueStringArray");
\r
540 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
\r
544 std::vector<std::string> value;
\r
545 JniUtils::convertJavaStrArrToStrVector(env, jValue, value);
\r
547 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
\r
550 std::string key = env->GetStringUTFChars(jKey, NULL);
\r
551 rep->setValue(key, value);
\r
555 * Class: org_iotivity_base_OcRepresentation
\r
556 * Method: setValueString2DArray
\r
557 * Signature: (Ljava/lang/String;[[Ljava/lang/String;)V
\r
559 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueString2DArray
\r
560 (JNIEnv *env, jobject thiz, jstring jKey, jobjectArray jValue)
\r
562 LOGD("OcRepresentation_setValueString2DArray");
\r
565 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
\r
568 std::vector<std::vector<std::string>> value;
\r
569 const jsize lenOuter = env->GetArrayLength(jValue);
\r
570 for (jsize j = 0; j < lenOuter; ++j)
\r
572 jobjectArray jInnerArray = static_cast<jobjectArray>(env->GetObjectArrayElement(jValue, j));
\r
573 std::vector<std::string> innerVector;
\r
574 JniUtils::convertJavaStrArrToStrVector(env, jInnerArray, innerVector);
\r
575 env->DeleteLocalRef(jInnerArray);
\r
576 value.push_back(innerVector);
\r
579 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
\r
582 std::string key = env->GetStringUTFChars(jKey, NULL);
\r
583 rep->setValue(key, value);
\r
587 * Class: org_iotivity_base_OcRepresentation
\r
588 * Method: setValueString3DArray
\r
589 * Signature: (Ljava/lang/String;[[[Ljava/lang/String;)V
\r
591 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueString3DArray
\r
592 (JNIEnv *env, jobject thiz, jstring jKey, jobjectArray jValue)
\r
594 LOGD("OcRepresentation_setValueString3DArray");
\r
597 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
\r
600 std::vector<std::vector<std::vector<std::string>>> value;
\r
601 const jsize lenOuter = env->GetArrayLength(jValue);
\r
602 for (jsize k = 0; k < lenOuter; ++k)
\r
604 jobjectArray jMiddleArray = static_cast<jobjectArray>(env->GetObjectArrayElement(jValue, k));
\r
605 const jsize lenMiddle = env->GetArrayLength(jMiddleArray);
\r
606 std::vector<std::vector<std::string>> middleArray;
\r
607 for (jsize j = 0; j < lenMiddle; ++j)
\r
609 jobjectArray jInnerArray = static_cast<jobjectArray>(env->GetObjectArrayElement(jMiddleArray, j));
\r
610 std::vector<std::string> innerVector;
\r
611 JniUtils::convertJavaStrArrToStrVector(env, jInnerArray, innerVector);
\r
612 env->DeleteLocalRef(jInnerArray);
\r
613 middleArray.push_back(innerVector);
\r
615 env->DeleteLocalRef(jMiddleArray);
\r
616 value.push_back(middleArray);
\r
619 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
\r
622 std::string key = env->GetStringUTFChars(jKey, NULL);
\r
623 rep->setValue(key, value);
\r
627 * Class: org_iotivity_base_OcRepresentation
\r
628 * Method: setValueRepresentationArray
\r
629 * Signature: (Ljava/lang/String;[Lorg/iotivity/base/OcRepresentation;)V
\r
631 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueRepresentationArray
\r
632 (JNIEnv *env, jobject thiz, jstring jKey, jobjectArray jValue)
\r
634 LOGD("OcRepresentation_setValueRepresentationArray");
\r
637 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
\r
641 std::vector<OCRepresentation> value;
\r
642 JniUtils::convertJavaRepresentationArrToVector(env, jValue, value);
\r
644 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
\r
647 std::string key = env->GetStringUTFChars(jKey, NULL);
\r
648 rep->setValue(key, value);
\r
652 * Class: org_iotivity_base_OcRepresentation
\r
653 * Method: setValueRepresentation2DArray
\r
654 * Signature: (Ljava/lang/String;[[Lorg/iotivity/base/OcRepresentation;)V
\r
656 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueRepresentation2DArray
\r
657 (JNIEnv *env, jobject thiz, jstring jKey, jobjectArray jValue)
\r
659 LOGD("OcRepresentation_setValueRepresentation2DArray");
\r
662 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
\r
665 std::vector<std::vector<OCRepresentation>> value;
\r
666 const jsize lenOuter = env->GetArrayLength(jValue);
\r
667 for (jsize j = 0; j < lenOuter; ++j)
\r
669 jobjectArray jInnerArray = static_cast<jobjectArray>(env->GetObjectArrayElement(jValue, j));
\r
670 std::vector<OCRepresentation> innerVector;
\r
671 JniUtils::convertJavaRepresentationArrToVector(env, jInnerArray, innerVector);
\r
672 env->DeleteLocalRef(jInnerArray);
\r
673 value.push_back(innerVector);
\r
676 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
\r
679 std::string key = env->GetStringUTFChars(jKey, NULL);
\r
680 rep->setValue(key, value);
\r
684 * Class: org_iotivity_base_OcRepresentation
\r
685 * Method: setValueRepresentation3DArray
\r
686 * Signature: (Ljava/lang/String;[[[Lorg/iotivity/base/OcRepresentation;)V
\r
688 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueRepresentation3DArray
\r
689 (JNIEnv *env, jobject thiz, jstring jKey, jobjectArray jValue)
\r
691 LOGD("OcRepresentation_setValueRepresentation3DArray");
\r
694 ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
\r
697 std::vector<std::vector<std::vector<OCRepresentation>>> value;
\r
698 const jsize lenOuter = env->GetArrayLength(jValue);
\r
699 for (jsize k = 0; k < lenOuter; ++k)
\r
701 jobjectArray jMiddleArray = static_cast<jobjectArray>(env->GetObjectArrayElement(jValue, k));
\r
702 const jsize lenMiddle = env->GetArrayLength(jMiddleArray);
\r
703 std::vector<std::vector<OCRepresentation>> middleArray;
\r
704 for (jsize j = 0; j < lenMiddle; ++j)
\r
706 jobjectArray jInnerArray = static_cast<jobjectArray>(env->GetObjectArrayElement(jMiddleArray, j));
\r
707 std::vector<OCRepresentation> innerVector;
\r
708 JniUtils::convertJavaRepresentationArrToVector(env, jInnerArray, innerVector);
\r
709 env->DeleteLocalRef(jInnerArray);
\r
710 middleArray.push_back(innerVector);
\r
712 env->DeleteLocalRef(jMiddleArray);
\r
713 value.push_back(middleArray);
\r
716 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
\r
719 std::string key = env->GetStringUTFChars(jKey, NULL);
\r
720 rep->setValue(key, value);
\r
724 * Class: org_iotivity_base_OcRepresentation
\r
725 * Method: getJSONRepresentation
\r
726 * Signature: ()Ljava/lang/String;
\r
728 JNIEXPORT jstring JNICALL Java_org_iotivity_base_OcRepresentation_getJSONRepresentation
\r
729 (JNIEnv *env, jobject thiz)
\r
731 LOGD("OcRepresentation_getJSONRepresentation");
\r
732 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
\r
733 if (!rep) return nullptr;
\r
735 std::string jsonStr = rep->getJSONRepresentation();
\r
736 return env->NewStringUTF(jsonStr.c_str());
\r
740 * Class: org_iotivity_base_OcRepresentation
\r
742 * Signature: (Lorg/iotivity/base/OcRepresentation;)V
\r
744 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_addChild
\r
745 (JNIEnv *env, jobject thiz, jobject jOcRepresentation)
\r
747 LOGD("OcRepresentation_addChild");
\r
748 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
\r
751 OCRepresentation *child = JniOcRepresentation::getOCRepresentationPtr(env, jOcRepresentation);
\r
752 if (!child) return;
\r
754 rep->addChild(*child);
\r
758 * Class: org_iotivity_base_OcRepresentation
\r
759 * Method: clearChildren
\r
762 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_clearChildren
\r
763 (JNIEnv *env, jobject thiz)
\r
765 LOGD("OcRepresentation_clearChildren");
\r
766 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
\r
769 rep->clearChildren();
\r
773 * Class: org_iotivity_base_OcRepresentation
\r
774 * Method: getChildrenArray
\r
775 * Signature: ()[Lorg/iotivity/base/OcRepresentation;
\r
777 JNIEXPORT jobjectArray JNICALL Java_org_iotivity_base_OcRepresentation_getChildrenArray
\r
778 (JNIEnv *env, jobject thiz)
\r
780 LOGD("OcRepresentation_getChildrenArray");
\r
781 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
\r
782 if (!rep) return nullptr;
\r
784 return JniUtils::convertRepresentationVectorToJavaArray(env, rep->getChildren());
\r
788 * Class: org_iotivity_base_OcRepresentation
\r
790 * Signature: ()Ljava/lang/String;
\r
792 JNIEXPORT jstring JNICALL Java_org_iotivity_base_OcRepresentation_getUri
\r
793 (JNIEnv *env, jobject thiz)
\r
795 LOGD("OcRepresentation_getUri");
\r
796 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
\r
797 if (!rep) return nullptr;
\r
799 std::string uri(rep->getUri());
\r
800 return env->NewStringUTF(uri.c_str());
\r
804 * Class: org_iotivity_base_OcRepresentation
\r
806 * Signature: (Ljava/lang/String;)V
\r
808 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setUri
\r
809 (JNIEnv *env, jobject thiz, jstring jUri)
\r
811 LOGD("OcRepresentation_setUri");
\r
814 ThrowOcException(OC_STACK_INVALID_PARAM, "uri cannot be null");
\r
817 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
\r
820 rep->setUri(env->GetStringUTFChars(jUri, NULL));
\r
823 JNIEXPORT jboolean JNICALL Java_org_iotivity_base_OcRepresentation_hasAttribute
\r
824 (JNIEnv *env, jobject thiz, jstring jstr)
\r
826 LOGD("OcRepresentation_hasAttribute");
\r
829 ThrowOcException(OC_STACK_INVALID_PARAM, "attributeKey cannot be null");
\r
832 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
\r
833 if (!rep) return false;
\r
835 std::string str = env->GetStringUTFChars(jstr, NULL);
\r
836 return rep->hasAttribute(str);
\r
840 * Class: org_iotivity_base_OcRepresentation
\r
841 * Method: getResourceTypes
\r
842 * Signature: ()Ljava/util/List;
\r
844 JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcRepresentation_getResourceTypes
\r
845 (JNIEnv *env, jobject thiz)
\r
847 LOGD("OcRepresentation_getResourceTypes");
\r
848 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
\r
849 if (!rep) return nullptr;
\r
851 std::vector<std::string> resourceTypes = rep->getResourceTypes();
\r
852 return JniUtils::convertStrVectorToJavaStrList(env, resourceTypes);
\r
856 * Class: org_iotivity_base_OcRepresentation
\r
857 * Method: setResourceTypeArray
\r
858 * Signature: ([Ljava/lang/String;)V
\r
860 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setResourceTypeArray
\r
861 (JNIEnv *env, jobject thiz, jobjectArray jResourceTypeArray)
\r
863 LOGD("OcRepresentation_setResourceTypeArray");
\r
864 if (!jResourceTypeArray)
\r
866 ThrowOcException(OC_STACK_INVALID_PARAM, "resourceTypeList cannot be null");
\r
869 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
\r
872 std::vector<std::string> resourceTypes;
\r
873 JniUtils::convertJavaStrArrToStrVector(env, jResourceTypeArray, resourceTypes);
\r
874 rep->setResourceTypes(resourceTypes);
\r
877 * Class: org_iotivity_base_OcRepresentation
\r
878 * Method: getResourceInterfaces
\r
879 * Signature: ()Ljava/util/List;
\r
881 JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcRepresentation_getResourceInterfaces
\r
882 (JNIEnv *env, jobject thiz)
\r
884 LOGD("OcRepresentation_getResourceInterfaces");
\r
885 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
\r
886 if (!rep) return nullptr;
\r
888 std::vector<std::string> resourceInterfaces = rep->getResourceInterfaces();
\r
889 return JniUtils::convertStrVectorToJavaStrList(env, resourceInterfaces);
\r
893 * Class: org_iotivity_base_OcRepresentation
\r
894 * Method: setResourceInterfaceArray
\r
895 * Signature: ([Ljava/lang/String;)V
\r
897 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setResourceInterfaceArray
\r
898 (JNIEnv *env, jobject thiz, jobjectArray jResourceInterfaceArray)
\r
900 LOGD("OcRepresentation_setResourceInterfaceArray");
\r
901 if (!jResourceInterfaceArray)
\r
903 ThrowOcException(OC_STACK_INVALID_PARAM, "resourceInterfaceList cannot be null");
\r
906 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
\r
909 std::vector<std::string> resourceInterfaces;
\r
910 JniUtils::convertJavaStrArrToStrVector(env, jResourceInterfaceArray, resourceInterfaces);
\r
911 rep->setResourceInterfaces(resourceInterfaces);
\r
915 * Class: org_iotivity_base_OcRepresentation
\r
919 JNIEXPORT jboolean JNICALL Java_org_iotivity_base_OcRepresentation_isEmpty
\r
920 (JNIEnv *env, jobject thiz)
\r
922 LOGD("OcRepresentation_isEmpty");
\r
923 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
\r
924 if (!rep) return false;
\r
926 return static_cast<jboolean>(rep->empty());
\r
930 * Class: org_iotivity_base_OcRepresentation
\r
934 JNIEXPORT jint JNICALL Java_org_iotivity_base_OcRepresentation_size
\r
935 (JNIEnv *env, jobject thiz)
\r
937 LOGD("OcRepresentation_size");
\r
938 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
\r
939 if (!rep) return -1;
\r
941 return static_cast<jint>(rep->numberOfAttributes());
\r
945 * Class: org_iotivity_base_OcRepresentation
\r
947 * Signature: (Ljava/lang/String;)Z
\r
949 JNIEXPORT jboolean JNICALL Java_org_iotivity_base_OcRepresentation_remove
\r
950 (JNIEnv *env, jobject thiz, jstring jAttributeKey)
\r
952 LOGD("OcRepresentation_remove");
\r
953 if (!jAttributeKey)
\r
955 ThrowOcException(OC_STACK_INVALID_PARAM, "attributeKey cannot be null");
\r
958 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
\r
959 if (!rep) return false;
\r
961 std::string attributeKey = env->GetStringUTFChars(jAttributeKey, NULL);
\r
962 return static_cast<jboolean>(rep->erase(attributeKey));
\r
966 * Class: org_iotivity_base_OcRepresentation
\r
968 * Signature: (Ljava/lang/String;)V
\r
970 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setNull
\r
971 (JNIEnv *env, jobject thiz, jstring jAttributeKey)
\r
973 LOGD("OcRepresentation_setNull");
\r
974 if (!jAttributeKey)
\r
976 ThrowOcException(OC_STACK_INVALID_PARAM, "attributeKey cannot be null");
\r
979 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
\r
982 std::string attributeKey = env->GetStringUTFChars(jAttributeKey, NULL);
\r
983 rep->setNULL(attributeKey);
\r
987 * Class: org_iotivity_base_OcRepresentation
\r
989 * Signature: (Ljava/lang/String;)Z
\r
991 JNIEXPORT jboolean JNICALL Java_org_iotivity_base_OcRepresentation_isNull
\r
992 (JNIEnv *env, jobject thiz, jstring jAttributeKey)
\r
994 LOGD("OcRepresentation_isNull");
\r
995 if (!jAttributeKey)
\r
997 ThrowOcException(OC_STACK_INVALID_PARAM, "attributeKey cannot be null");
\r
1000 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
\r
1001 if (!rep) return false;
\r
1003 std::string attributeKey = env->GetStringUTFChars(jAttributeKey, NULL);
\r
1004 return static_cast<jboolean>(rep->isNULL(attributeKey));
\r
1008 * Class: org_iotivity_base_OcRepresentation
\r
1012 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_create
\r
1013 (JNIEnv *env, jobject thiz)
\r
1015 LOGD("OcRepresentation_create");
\r
1016 OCRepresentation *rep = new OCRepresentation();
\r
1017 SetHandle<OCRepresentation>(env, thiz, rep);
\r
1018 if (env->ExceptionCheck())
\r
1020 LOGE("Failed to set native handle for OcRepresentation");
\r
1026 * Class: org_iotivity_base_OcRepresentation
\r
1030 JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_dispose
\r
1031 (JNIEnv *env, jobject thiz, jboolean jNeedsDelete)
\r
1033 LOGD("OcRepresentation_dispose");
\r
1034 OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
\r