* //
* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
*/
+
+#include <map>
+
#include "JniOcRepresentation.h"
#include "JniUtils.h"
/*
* Class: org_iotivity_base_OcRepresentation
+* Method: getValues
+* Signature: ()Ljava/util/Map;
+*/
+JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcRepresentation_getValues
+(JNIEnv *env, jobject thiz)
+{
+ LOGD("OcRepresentation_getValues");
+ OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
+ if (!rep)
+ {
+ return nullptr;
+ }
+
+ std::map<std::string, AttributeValue> values = rep->getValues();
+ jobject jHashMap = env->NewObject(g_cls_HashMap, g_mid_HashMap_ctor);
+ if (!jHashMap)
+ {
+ return nullptr;
+ }
+
+ for (std::map<std::string, AttributeValue>::const_iterator it = values.begin(); it != values.end(); it++)
+ {
+ jobject key = static_cast<jobject>(env->NewStringUTF(it->first.c_str()));
+ jobject val = boost::apply_visitor(JObjectConverter(env), it->second);
+ env->CallObjectMethod(jHashMap, g_mid_HashMap_put, key, val);
+ }
+ return jHashMap;
+}
+
+/*
+* Class: org_iotivity_base_OcRepresentation
* Method: getValueN
* Signature: (Ljava/lang/String;)Ljava/lang/Object;
*/
return nullptr;
}
OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
- if (!rep) return nullptr;
+ if (!rep)
+ {
+ return nullptr;
+ }
std::string key = env->GetStringUTFChars(jKey, nullptr);
return;
}
OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
- if (!rep) return;
+ if (!rep)
+ {
+ return;
+ }
std::string str = env->GetStringUTFChars(jKey, nullptr);
rep->setValue(str, static_cast<int>(jValue));
return;
}
OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
- if (!rep) return;
+ if (!rep)
+ {
+ return;
+ }
std::string str = env->GetStringUTFChars(jKey, nullptr);
rep->setValue(str, static_cast<double>(jValue));
return;
}
OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
- if (!rep) return;
+ if (!rep)
+ {
+ return;
+ }
std::string str = env->GetStringUTFChars(jKey, nullptr);
rep->setValue(str, static_cast<bool>(jValue));
return;
}
OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
- if (!rep) return;
+ if (!rep)
+ {
+ return;
+ }
std::string key = env->GetStringUTFChars(jKey, nullptr);
std::string value = env->GetStringUTFChars(jValue, nullptr);
return;
}
OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
- if (!rep) return;
+ if (!rep)
+ {
+ return;
+ }
std::string key = env->GetStringUTFChars(jKey, nullptr);
if (jValue)
{
OCRepresentation *value = JniOcRepresentation::getOCRepresentationPtr(env, jValue);
- if (!value) return;
+ if (!value)
+ {
+ return;
+ }
rep->setValue(key, *value);
}
else
env->ReleaseIntArrayElements(jValue, ints, JNI_ABORT);
OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
- if (!rep) return;
+ if (!rep)
+ {
+ return;
+ }
std::string key = env->GetStringUTFChars(jKey, nullptr);
rep->setValue(key, value);
}
OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
- if (!rep) return;
+ if (!rep)
+ {
+ return;
+ }
std::string key = env->GetStringUTFChars(jKey, nullptr);
rep->setValue(key, value);
}
OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
- if (!rep) return;
+ if (!rep)
+ {
+ return;
+ }
std::string key = env->GetStringUTFChars(jKey, nullptr);
rep->setValue(key, value);
env->ReleaseDoubleArrayElements(jValue, doubles, JNI_ABORT);
OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
- if (!rep) return;
+ if (!rep)
+ {
+ return;
+ }
std::string key = env->GetStringUTFChars(jKey, nullptr);
rep->setValue(key, value);
}
OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
- if (!rep) return;
+ if (!rep)
+ {
+ return;
+ }
std::string key = env->GetStringUTFChars(jKey, nullptr);
rep->setValue(key, value);
}
OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
- if (!rep) return;
+ if (!rep)
+ {
+ return;
+ }
std::string key = env->GetStringUTFChars(jKey, nullptr);
rep->setValue(key, value);
env->ReleaseBooleanArrayElements(jValue, booleans, JNI_ABORT);
OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
- if (!rep) return;
+ if (!rep)
+ {
+ return;
+ }
std::string key = env->GetStringUTFChars(jKey, nullptr);
rep->setValue(key, value);
}
OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
- if (!rep) return;
+ if (!rep)
+ {
+ return;
+ }
std::string key = env->GetStringUTFChars(jKey, nullptr);
rep->setValue(key, value);
}
OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
- if (!rep) return;
+ if (!rep)
+ {
+ return;
+ }
std::string key = env->GetStringUTFChars(jKey, nullptr);
rep->setValue(key, value);
JniUtils::convertJavaStrArrToStrVector(env, jValue, value);
OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
- if (!rep) return;
+ if (!rep)
+ {
+ return;
+ }
std::string key = env->GetStringUTFChars(jKey, nullptr);
rep->setValue(key, value);
}
OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
- if (!rep) return;
+ if (!rep)
+ {
+ return;
+ }
std::string key = env->GetStringUTFChars(jKey, nullptr);
rep->setValue(key, value);
}
OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
- if (!rep) return;
-
+ if (!rep)
+ {
+ return;
+ }
std::string key = env->GetStringUTFChars(jKey, nullptr);
rep->setValue(key, value);
}
JniUtils::convertJavaRepresentationArrToVector(env, jValue, value);
OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
- if (!rep) return;
+ if (!rep)
+ {
+ return;
+ }
std::string key = env->GetStringUTFChars(jKey, nullptr);
rep->setValue(key, value);
}
OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
- if (!rep) return;
+ if (!rep)
+ {
+ return;
+ }
std::string key = env->GetStringUTFChars(jKey, nullptr);
rep->setValue(key, value);
}
OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
- if (!rep) return;
+ if (!rep)
+ {
+ return;
+ }
+
+ std::string key = env->GetStringUTFChars(jKey, nullptr);
+ rep->setValue(key, value);
+}
+
+/*
+* Class: org_iotivity_base_OcRepresentation
+* Method: setValueByteArray
+* Signature: (Ljava/lang/String;[B)V
+*/
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueByteArray
+(JNIEnv *env, jobject thiz, jstring jKey, jbyteArray jValue)
+{
+ LOGD("OcRepresentation_setValueByteArray");
+ if (!jKey)
+ {
+ ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
+ return;
+ }
+
+ const jsize len = env->GetArrayLength(jValue);
+ jbyte* bytes = env->GetByteArrayElements(jValue, nullptr);
+
+ std::vector<uint8_t> value;
+ for (jsize i = 0; i < len; ++i)
+ {
+ value.push_back(static_cast<uint8_t>(bytes[i]));
+ }
+ env->ReleaseByteArrayElements(jValue, bytes, JNI_ABORT);
+
+ OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
+ if (!rep)
+ {
+ return;
+ }
std::string key = env->GetStringUTFChars(jKey, nullptr);
rep->setValue(key, value);
{
LOGD("OcRepresentation_addChild");
OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
- if (!rep) return;
+ if (!rep)
+ {
+ return;
+ }
OCRepresentation *child = JniOcRepresentation::getOCRepresentationPtr(env, jOcRepresentation);
- if (!child) return;
+ if (!child)
+ {
+ return;
+ }
rep->addChild(*child);
}
{
LOGD("OcRepresentation_clearChildren");
OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
- if (!rep) return;
+ if (!rep)
+ {
+ return;
+ }
rep->clearChildren();
}
{
LOGD("OcRepresentation_getChildrenArray");
OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
- if (!rep) return nullptr;
+ if (!rep)
+ {
+ return nullptr;
+ }
return JniUtils::convertRepresentationVectorToJavaArray(env, rep->getChildren());
}
{
LOGD("OcRepresentation_getUri");
OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
- if (!rep) return nullptr;
+ if (!rep)
+ {
+ return nullptr;
+ }
std::string uri(rep->getUri());
return env->NewStringUTF(uri.c_str());
{
LOGD("OcRepresentation_getHost");
OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
- if (!rep) return nullptr;
+ if (!rep)
+ {
+ return nullptr;
+ }
std::string uri(rep->getHost());
return env->NewStringUTF(uri.c_str());
return;
}
OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
- if (!rep) return;
+ if (!rep)
+ {
+ return;
+ }
rep->setUri(env->GetStringUTFChars(jUri, nullptr));
}
return false;
}
OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
- if (!rep) return false;
+ if (!rep)
+ {
+ return false;
+ }
std::string str = env->GetStringUTFChars(jstr, nullptr);
return rep->hasAttribute(str);
{
LOGD("OcRepresentation_getResourceTypes");
OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
- if (!rep) return nullptr;
+ if (!rep)
+ {
+ return nullptr;
+ }
std::vector<std::string> resourceTypes = rep->getResourceTypes();
return JniUtils::convertStrVectorToJavaStrList(env, resourceTypes);
return;
}
OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
- if (!rep) return;
+ if (!rep)
+ {
+ return;
+ }
std::vector<std::string> resourceTypes;
JniUtils::convertJavaStrArrToStrVector(env, jResourceTypeArray, resourceTypes);
{
LOGD("OcRepresentation_getResourceInterfaces");
OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
- if (!rep) return nullptr;
+ if (!rep)
+ {
+ return nullptr;
+ }
std::vector<std::string> resourceInterfaces = rep->getResourceInterfaces();
return JniUtils::convertStrVectorToJavaStrList(env, resourceInterfaces);
return;
}
OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
- if (!rep) return;
+ if (!rep)
+ {
+ return;
+ }
std::vector<std::string> resourceInterfaces;
JniUtils::convertJavaStrArrToStrVector(env, jResourceInterfaceArray, resourceInterfaces);
{
LOGD("OcRepresentation_isEmpty");
OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
- if (!rep) return false;
+ if (!rep)
+ {
+ return false;
+ }
return static_cast<jboolean>(rep->empty());
}
{
LOGD("OcRepresentation_size");
OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
- if (!rep) return -1;
+ if (!rep)
+ {
+ return -1;
+ }
return static_cast<jint>(rep->numberOfAttributes());
}
return false;
}
OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
- if (!rep) return false;
+ if (!rep)
+ {
+ return false;
+ }
std::string attributeKey = env->GetStringUTFChars(jAttributeKey, nullptr);
return static_cast<jboolean>(rep->erase(attributeKey));
return;
}
OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
- if (!rep) return;
+ if (!rep)
+ {
+ return;
+ }
std::string attributeKey = env->GetStringUTFChars(jAttributeKey, nullptr);
rep->setNULL(attributeKey);
return false;
}
OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
- if (!rep) return false;
+ if (!rep)
+ {
+ return false;
+ }
std::string attributeKey = env->GetStringUTFChars(jAttributeKey, nullptr);
return static_cast<jboolean>(rep->isNULL(attributeKey));