modified coding style for parenthesis for Android JNI
authorjihwan.seo <jihwan.seo@samsung.com>
Wed, 29 Jun 2016 02:24:55 +0000 (11:24 +0900)
committerAshok Babu Channa <ashok.channa@samsung.com>
Thu, 30 Jun 2016 10:11:30 +0000 (10:11 +0000)
and some variable is declared with initial value

Change-Id: I44977ced60dfd2f15f162e5beac0461840f72ef6
Signed-off-by: jihwan.seo <jihwan.seo@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/9011
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Ashok Babu Channa <ashok.channa@samsung.com>
33 files changed:
android/android_api/base/jni/JniDisplayPinListener.cpp
android/android_api/base/jni/JniEntityHandler.cpp
android/android_api/base/jni/JniListenerManager.h
android/android_api/base/jni/JniOcDirectPairDevice.cpp
android/android_api/base/jni/JniOcPlatform.cpp
android/android_api/base/jni/JniOcPresenceHandle.cpp
android/android_api/base/jni/JniOcRepresentation.cpp
android/android_api/base/jni/JniOcRepresentation.h
android/android_api/base/jni/JniOcRequestHandle.cpp
android/android_api/base/jni/JniOcResource.cpp
android/android_api/base/jni/JniOcResourceHandle.cpp
android/android_api/base/jni/JniOcResourceIdentifier.cpp
android/android_api/base/jni/JniOcResourceRequest.cpp
android/android_api/base/jni/JniOcResourceResponse.cpp
android/android_api/base/jni/JniOcSecureResource.cpp
android/android_api/base/jni/JniOcStack.cpp
android/android_api/base/jni/JniOcStack.h
android/android_api/base/jni/JniOnDPDevicesFoundListener.cpp
android/android_api/base/jni/JniOnDeleteListener.cpp
android/android_api/base/jni/JniOnDeviceInfoListener.cpp
android/android_api/base/jni/JniOnDirectPairingListener.cpp
android/android_api/base/jni/JniOnGetListener.cpp
android/android_api/base/jni/JniOnObserveListener.cpp
android/android_api/base/jni/JniOnPlatformInfoListener.cpp
android/android_api/base/jni/JniOnPostListener.cpp
android/android_api/base/jni/JniOnPresenceListener.cpp
android/android_api/base/jni/JniOnPutListener.cpp
android/android_api/base/jni/JniOnResourceFoundListener.cpp
android/android_api/base/jni/JniPinCheckListener.cpp
android/android_api/base/jni/JniProvisionResultListner.cpp
android/android_api/base/jni/JniUtils.cpp
android/android_api/base/jni/JniUtils.h
resource/csdk/stack/src/ocstack.c

index 25ee926..1705bdf 100644 (file)
@@ -33,7 +33,7 @@ JniDisplayPinListener::~JniDisplayPinListener()
     LOGI("~JniDisplayPinListener()");
     if (m_jgListener)
     {
-        jint ret;
+        jint ret = JNI_ERR;
         JNIEnv *env = GetJNIEnv(ret);
         if (NULL == env) return;
         env->DeleteGlobalRef(m_jgListener);
@@ -43,9 +43,12 @@ JniDisplayPinListener::~JniDisplayPinListener()
 
 void JniDisplayPinListener::displayPinCallback(char *pinBuf, size_t pinSize)
 {
-    jint ret;
+    jint ret = JNI_ERR;
     JNIEnv *env = GetJNIEnv(ret);
-    if (NULL == env) return;
+    if (NULL == env)
+    {
+        return;
+    }
 
     jclass clsL = env->GetObjectClass(m_jgListener);
 
index 1d641ae..f46dde0 100644 (file)
@@ -33,7 +33,7 @@ JniEntityHandler::~JniEntityHandler()
     LOGD("~JniEntityHandler");
     if (m_jListener)
     {
-        jint ret;
+        jint ret = JNI_ERR;
         JNIEnv *env = GetJNIEnv(ret);
         if (nullptr == env)
         {
@@ -54,7 +54,7 @@ OCEntityHandlerResult JniEntityHandler::handleEntity(
     const std::shared_ptr<OCResourceRequest> request)
 {
     LOGD("JniEntityHandler_handleEntity");
-    jint envRet;
+    jint envRet = JNI_ERR;
     JNIEnv *env = GetJNIEnv(envRet);
     if (nullptr == env)
     {
@@ -133,7 +133,10 @@ OCEntityHandlerResult JniEntityHandler::handleEntity(
     jmethodID getValue_ID = env->GetMethodID(clsResult, "getValue", "()I");
     if (!getValue_ID)
     {
-        if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
+        if (JNI_EDETACHED == envRet)
+        {
+            g_jvm->DetachCurrentThread();
+        }
         return OC_EH_ERROR;
     }
     jint jResult = env->CallIntMethod(entityHandlerResult, getValue_ID);
index b082f7d..989dd3d 100644 (file)
@@ -51,6 +51,7 @@ public:
                 break;
             }
         }
+
         if (!onEventListener)
         {
             onEventListener = new T(env, jListener, owner);
@@ -66,9 +67,11 @@ public:
             {
                 LOGD("OnEventListener: Failed to create global listener ref.");
                 delete onEventListener;
+                return nullptr;
             }
             LOGD("OnEventListener: new listener");
         }
+
         m_mapMutex.unlock();
         return onEventListener;
     }
index 535bebc..ff4e626 100644 (file)
@@ -28,7 +28,8 @@ namespace PH = std::placeholders;
 
 JniOcDirectPairDevice::JniOcDirectPairDevice(std::shared_ptr<OC::OCDirectPairing> directPairingDevice)
     : m_sharedDirectPairDevice(directPairingDevice)
-{}
+{
+}
 
 JniOcDirectPairDevice::~JniOcDirectPairDevice()
 {
@@ -77,7 +78,10 @@ JNIEXPORT jstring JNICALL Java_org_iotivity_base_OcDirectPairDevice_getHost
     LOGD("OcDirectPairing_getHost");
 
     JniOcDirectPairDevice* device = JniOcDirectPairDevice::getJniOcDirectPairDevicePtr(env,thiz);
-    if (!device) return nullptr;
+    if (!device)
+    {
+        return nullptr;
+    }
 
     std::string dev  = device->getHost();
     return env->NewStringUTF(dev.c_str());
@@ -91,7 +95,10 @@ JNIEXPORT jintArray JNICALL Java_org_iotivity_base_OcDirectPairDevice_getPairing
 
     std::vector<jint> pairingMethodList;
     JniOcDirectPairDevice* device = JniOcDirectPairDevice::getJniOcDirectPairDevicePtr(env,thiz);
-    if (!device) return nullptr;
+    if (!device)
+    {
+        return nullptr;
+    }
 
     std::vector<OCPrm_t> pairingMethods = device->getPairingMethods();
     return JniOcDirectPairDevice::JconvertIntVectorToJavaList(env,pairingMethods);
@@ -104,7 +111,10 @@ jintArray JniOcDirectPairDevice::JconvertIntVectorToJavaList(JNIEnv *env, std::v
     jsize len = static_cast<jsize>(vector.size());
 
     jintArray intArray = env->NewIntArray(len);
-    if (!intArray) return nullptr;
+    if (!intArray)
+    {
+        return nullptr;
+    }
 
     env->SetIntArrayRegion(intArray, (jsize)0, len, (const jint*)&vector[0]);
 
@@ -125,7 +135,10 @@ JNIEXPORT jint JNICALL Java_org_iotivity_base_OcDirectPairDevice_getConnectivity
 {
     LOGD("OcDirectPairDevice_getConnectivityType");
     JniOcDirectPairDevice* device = JniOcDirectPairDevice::getJniOcDirectPairDevicePtr(env,thiz);
-    if (!device) return -1;
+    if (!device)
+    {
+        return -1;
+    }
 
     OCConnectivityType connectivityType = device->connectivityType();
     return static_cast<jint>(connectivityType);
index 82f693f..5678341 100644 (file)
@@ -520,7 +520,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_notifyAllObservers0
 
     JniOcResourceHandle* jniOcResourceHandle = JniOcResourceHandle::getJniOcResourceHandlePtr(
         env, jResourceHandle);
-    if (!jniOcResourceHandle) return;
+    if (!jniOcResourceHandle)
+    {
+        return;
+    }
 
     try
     {
@@ -563,7 +566,7 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_notifyAllObservers1
         return;
     }
 
-    try{
+    try {
         OCStackResult result = OCPlatform::notifyAllObservers(
             jniOcResourceHandle->getOCResourceHandle(),
             JniUtils::getQOS(env, static_cast<int>(jQoS)));
@@ -1232,7 +1235,10 @@ JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcPlatform_registerResource0(
         return nullptr;
     }
     JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, jResource);
-    if (!resource) return nullptr;
+    if (!resource)
+    {
+        return nullptr;
+    }
 
     OCResourceHandle resourceHandle;
     try
@@ -1382,12 +1388,17 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_registerDeviceInfo0(
             jstring jStr = (jstring)env->GetObjectArrayElement(jDeviceTypes, i);
             if (!jStr)
             {
+                delete deviceInfo.deviceName;
                 ThrowOcException(OC_STACK_INVALID_PARAM, "device type cannot be null");
                 return;
             }
 
             OCResourcePayloadAddStringLL(&deviceInfo.types, env->GetStringUTFChars(jStr, nullptr));
-            if (env->ExceptionCheck()) return;
+            if (env->ExceptionCheck())
+            {
+                delete deviceInfo.deviceName;
+                return;
+            }
 
             env->DeleteLocalRef(jStr);
         }
@@ -1606,7 +1617,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_bindResource0
     }
     JniOcResourceHandle* jniOcResourceCollectionHandle =
         JniOcResourceHandle::getJniOcResourceHandlePtr(env, jResourceCollectionHandle);
-    if (!jniOcResourceCollectionHandle) return;
+    if (!jniOcResourceCollectionHandle)
+    {
+        return;
+    }
 
     JniOcResourceHandle* jniOcResourceHandle = JniOcResourceHandle::getJniOcResourceHandlePtr(
         env, jResourceHandle);
@@ -1857,7 +1871,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_bindTypeToResource0(
 
     JniOcResourceHandle* jniOcResourceHandle =
         JniOcResourceHandle::getJniOcResourceHandlePtr(env, jResourceHandle);
-    if (!jniOcResourceHandle) return;
+    if (!jniOcResourceHandle)
+    {
+        return;
+    }
 
     try
     {
@@ -2257,7 +2274,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_sendResponse0(
 
     JniOcResourceResponse *jniResponse =
         JniOcResourceResponse::getJniOcResourceResponsePtr(env, jResourceResponse);
-    if (!jniResponse) return;
+    if (!jniResponse)
+    {
+        return;
+    }
 
     try
     {
index 00f81a1..28b7859 100644 (file)
@@ -24,7 +24,8 @@
 
 JniOcPresenceHandle::JniOcPresenceHandle(JniOnPresenceListener* jniListener, OCPresenceHandle presenceHandle)
     : m_jniListener(jniListener), m_presenceHandle(presenceHandle)
-{}
+{
+}
 
 JniOcPresenceHandle::~JniOcPresenceHandle()
 {
@@ -70,4 +71,4 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcPresenceHandle_dispose
     LOGD("OcPresenceHandle_dispose");
     JniOcPresenceHandle *presenceHandle = JniOcPresenceHandle::getJniOcPresenceHandlePtr(env, thiz);
     delete presenceHandle;
-}
\ No newline at end of file
+}
index 1403349..042e2a4 100644 (file)
@@ -51,13 +51,20 @@ JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcRepresentation_getValues
 {
     LOGD("OcRepresentation_getValues");
     OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
-    if (!rep) return nullptr;
+    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;
+    if (!jHashMap)
+    {
+        return nullptr;
+    }
 
-    for (std::map<std::string, AttributeValue>::const_iterator it = values.begin(); it != values.end(); it++) {
+    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);
@@ -80,7 +87,10 @@ JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcRepresentation_getValueN
         return nullptr;
     }
     OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
-    if (!rep) return nullptr;
+    if (!rep)
+    {
+        return nullptr;
+    }
 
     std::string key = env->GetStringUTFChars(jKey, nullptr);
 
@@ -108,7 +118,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueInteger
         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));
@@ -129,7 +142,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueDouble
         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));
@@ -150,7 +166,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueBoolean
         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));
@@ -171,7 +190,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueStringN
         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);
@@ -194,14 +216,20 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueRepresent
         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
@@ -236,7 +264,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueIntegerAr
     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);
@@ -274,7 +305,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueInteger2D
     }
 
     OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
-    if (!rep) return;
+    if (!rep)
+    {
+        return;
+    }
 
     std::string key = env->GetStringUTFChars(jKey, nullptr);
     rep->setValue(key, value);
@@ -320,7 +354,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueInteger3D
     }
 
     OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
-    if (!rep) return;
+    if (!rep)
+    {
+        return;
+    }
 
     std::string key = env->GetStringUTFChars(jKey, nullptr);
     rep->setValue(key, value);
@@ -352,7 +389,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueDoubleArr
     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);
@@ -390,7 +430,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueDouble2DA
     }
 
     OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
-    if (!rep) return;
+    if (!rep)
+    {
+        return;
+    }
 
     std::string key = env->GetStringUTFChars(jKey, nullptr);
     rep->setValue(key, value);
@@ -436,7 +479,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueDouble3DA
     }
 
     OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
-    if (!rep) return;
+    if (!rep)
+    {
+        return;
+    }
 
     std::string key = env->GetStringUTFChars(jKey, nullptr);
     rep->setValue(key, value);
@@ -468,7 +514,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueBooleanAr
     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);
@@ -507,7 +556,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueBoolean2D
     }
 
     OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
-    if (!rep) return;
+    if (!rep)
+    {
+        return;
+    }
 
     std::string key = env->GetStringUTFChars(jKey, nullptr);
     rep->setValue(key, value);
@@ -554,7 +606,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueBoolean3D
     }
 
     OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
-    if (!rep) return;
+    if (!rep)
+    {
+        return;
+    }
 
     std::string key = env->GetStringUTFChars(jKey, nullptr);
     rep->setValue(key, value);
@@ -579,7 +634,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueStringArr
     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);
@@ -611,7 +669,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueString2DA
     }
 
     OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
-    if (!rep) return;
+    if (!rep)
+    {
+        return;
+    }
 
     std::string key = env->GetStringUTFChars(jKey, nullptr);
     rep->setValue(key, value);
@@ -651,8 +712,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueString3DA
     }
 
     OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
-    if (!rep) return;
-
+    if (!rep)
+    {
+        return;
+    }
     std::string key = env->GetStringUTFChars(jKey, nullptr);
     rep->setValue(key, value);
 }
@@ -676,7 +739,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueRepresent
     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);
@@ -708,7 +774,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueRepresent
     }
 
     OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
-    if (!rep) return;
+    if (!rep)
+    {
+        return;
+    }
 
     std::string key = env->GetStringUTFChars(jKey, nullptr);
     rep->setValue(key, value);
@@ -748,7 +817,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueRepresent
     }
 
     OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
-    if (!rep) return;
+    if (!rep)
+    {
+        return;
+    }
 
     std::string key = env->GetStringUTFChars(jKey, nullptr);
     rep->setValue(key, value);
@@ -780,7 +852,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueByteArray
     env->ReleaseByteArrayElements(jValue, bytes, 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);
@@ -796,10 +871,16 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_addChild
 {
     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);
 }
@@ -814,7 +895,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_clearChildren
 {
     LOGD("OcRepresentation_clearChildren");
     OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
-    if (!rep) return;
+    if (!rep)
+    {
+        return;
+    }
 
     rep->clearChildren();
 }
@@ -829,7 +913,10 @@ JNIEXPORT jobjectArray JNICALL Java_org_iotivity_base_OcRepresentation_getChildr
 {
     LOGD("OcRepresentation_getChildrenArray");
     OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
-    if (!rep) return nullptr;
+    if (!rep)
+    {
+        return nullptr;
+    }
 
     return JniUtils::convertRepresentationVectorToJavaArray(env, rep->getChildren());
 }
@@ -844,7 +931,10 @@ JNIEXPORT jstring JNICALL Java_org_iotivity_base_OcRepresentation_getUri
 {
     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());
@@ -860,7 +950,10 @@ JNIEXPORT jstring JNICALL Java_org_iotivity_base_OcRepresentation_getHost
 {
     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());
@@ -881,7 +974,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setUri
         return;
     }
     OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
-    if (!rep) return;
+    if (!rep)
+    {
+        return;
+    }
 
     rep->setUri(env->GetStringUTFChars(jUri, nullptr));
 }
@@ -896,7 +992,10 @@ JNIEXPORT jboolean JNICALL Java_org_iotivity_base_OcRepresentation_hasAttribute
         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);
@@ -912,7 +1011,10 @@ JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcRepresentation_getResourceTyp
 {
     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);
@@ -933,7 +1035,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setResourceTypeAr
         return;
     }
     OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
-    if (!rep) return;
+    if (!rep)
+    {
+        return;
+    }
 
     std::vector<std::string> resourceTypes;
     JniUtils::convertJavaStrArrToStrVector(env, jResourceTypeArray, resourceTypes);
@@ -949,7 +1054,10 @@ JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcRepresentation_getResourceInt
 {
     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);
@@ -970,7 +1078,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setResourceInterf
         return;
     }
     OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
-    if (!rep) return;
+    if (!rep)
+    {
+        return;
+    }
 
     std::vector<std::string> resourceInterfaces;
     JniUtils::convertJavaStrArrToStrVector(env, jResourceInterfaceArray, resourceInterfaces);
@@ -987,7 +1098,10 @@ JNIEXPORT jboolean JNICALL Java_org_iotivity_base_OcRepresentation_isEmpty
 {
     LOGD("OcRepresentation_isEmpty");
     OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
-    if (!rep) return false;
+    if (!rep)
+    {
+        return false;
+    }
 
     return static_cast<jboolean>(rep->empty());
 }
@@ -1002,7 +1116,10 @@ JNIEXPORT jint JNICALL Java_org_iotivity_base_OcRepresentation_size
 {
     LOGD("OcRepresentation_size");
     OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
-    if (!rep) return -1;
+    if (!rep)
+    {
+        return -1;
+    }
 
     return static_cast<jint>(rep->numberOfAttributes());
 }
@@ -1022,7 +1139,10 @@ JNIEXPORT jboolean JNICALL Java_org_iotivity_base_OcRepresentation_remove
         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));
@@ -1043,7 +1163,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setNull
         return;
     }
     OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
-    if (!rep) return;
+    if (!rep)
+    {
+        return;
+    }
 
     std::string attributeKey = env->GetStringUTFChars(jAttributeKey, nullptr);
     rep->setNULL(attributeKey);
@@ -1064,7 +1187,10 @@ JNIEXPORT jboolean JNICALL Java_org_iotivity_base_OcRepresentation_isNull
         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));
index a153dd7..e9acd35 100644 (file)
@@ -35,9 +35,15 @@ public:
 
 struct JObjectConverter : boost::static_visitor < jobject >
 {
-    JObjectConverter(JNIEnv *env) : env(env){}
+    JObjectConverter(JNIEnv *env) : env(env)
+    {
+    }
+
+    jobject operator()(const NullType&) const
+    {
+        return nullptr;
+    }
 
-    jobject operator()(const NullType&) const { return nullptr; }
     jobject operator()(const int& val) const
     {
         jobject jobj = env->NewObject(
@@ -87,7 +93,10 @@ struct JObjectConverter : boost::static_visitor < jobject >
     {
         size_t len = val.size();
         jintArray jIntArray = env->NewIntArray(len);
-        if (!jIntArray) return nullptr;
+        if (!jIntArray)
+        {
+            return nullptr;
+        }
         const int* ints = &val[0];
         env->SetIntArrayRegion(jIntArray, 0, len, reinterpret_cast<const jint*>(ints));
         return jIntArray;
@@ -96,7 +105,10 @@ struct JObjectConverter : boost::static_visitor < jobject >
     {
         size_t len = val.size();
         jdoubleArray jDoubleArray = env->NewDoubleArray(len);
-        if (!jDoubleArray) return nullptr;
+        if (!jDoubleArray)
+        {
+            return nullptr;
+        }
         const double* doubles = &val[0];
         env->SetDoubleArrayRegion(jDoubleArray, 0, len, reinterpret_cast<const jdouble*>(doubles));
         return jDoubleArray;
@@ -105,13 +117,20 @@ struct JObjectConverter : boost::static_visitor < jobject >
     {
         size_t len = val.size();
         jbooleanArray jBooleanArray = env->NewBooleanArray(len);
-        if (!jBooleanArray) return nullptr;
+        if (!jBooleanArray)
+        {
+            return nullptr;
+        }
         jboolean* booleans = new jboolean[len];
-        for (size_t i = 0; i < len; ++i) {
+        for (size_t i = 0; i < len; ++i)
+        {
             booleans[i] = static_cast<jboolean>(val[i]);
         }
         env->SetBooleanArrayRegion(jBooleanArray, 0, len, booleans);
-        if (env->ExceptionCheck()) return nullptr;
+        if (env->ExceptionCheck())
+        {
+            return nullptr;
+        }
         env->ReleaseBooleanArrayElements(jBooleanArray, booleans, 0);
         return jBooleanArray;
     }
@@ -119,12 +138,18 @@ struct JObjectConverter : boost::static_visitor < jobject >
     {
         size_t len = val.size();
         jobjectArray strArr = env->NewObjectArray(len, g_cls_String, nullptr);
-        if (!strArr) return nullptr;
+        if (!strArr)
+        {
+            return nullptr;
+        }
         for (size_t i = 0; i < len; ++i)
         {
             jstring jString = env->NewStringUTF(val[i].c_str());
             env->SetObjectArrayElement(strArr, static_cast<jsize>(i), jString);
-            if (env->ExceptionCheck()) return nullptr;
+            if (env->ExceptionCheck())
+            {
+                return nullptr;
+            }
             env->DeleteLocalRef(jString);
         }
         return strArr;
@@ -133,7 +158,10 @@ struct JObjectConverter : boost::static_visitor < jobject >
     {
         jsize len = static_cast<jsize>(val.size());
         jobjectArray repArr = env->NewObjectArray(len, g_cls_OcRepresentation, nullptr);
-        if (!repArr) return nullptr;
+        if (!repArr)
+        {
+            return nullptr;
+        }
         for (jsize i = 0; i < len; ++i)
         {
             OCRepresentation* rep = new OCRepresentation(val[i]);
@@ -159,7 +187,10 @@ struct JObjectConverter : boost::static_visitor < jobject >
     {
         size_t len = val.size();
         jbyteArray jByteArray = env->NewByteArray(len);
-        if (!jByteArray) return nullptr;
+        if (!jByteArray)
+        {
+            return nullptr;
+        }
         const uint8_t* bytes = &val[0];
         env->SetByteArrayRegion(jByteArray, 0, len, reinterpret_cast<const jbyte*>(bytes));
         return jByteArray;
@@ -178,12 +209,21 @@ struct JObjectConverter : boost::static_visitor < jobject >
         {
             size_t lenInner = val[i].size();
             jintArray jIntArray = env->NewIntArray(lenInner);
-            if (!jIntArray) return nullptr;
+            if (!jIntArray)
+            {
+                return nullptr;
+            }
             const int* ints = &val[i][0];
             env->SetIntArrayRegion(jIntArray, 0, lenInner, reinterpret_cast<const jint*>(ints));
-            if (env->ExceptionCheck()) return nullptr;
+            if (env->ExceptionCheck())
+            {
+                return nullptr;
+            }
             env->SetObjectArrayElement(jOuterArr, i, static_cast<jobject>(jIntArray));
-            if (env->ExceptionCheck()) return nullptr;
+            if (env->ExceptionCheck())
+            {
+                return nullptr;
+            }
             env->DeleteLocalRef(jIntArray);
         }
         return jOuterArr;
@@ -192,26 +232,46 @@ struct JObjectConverter : boost::static_visitor < jobject >
     {
         jsize lenOuter = static_cast<jsize>(val.size());
         jobjectArray jOuterArr = env->NewObjectArray(lenOuter, g_cls_int2DArray, nullptr);
-        if (!jOuterArr) return nullptr;
+        if (!jOuterArr)
+        {
+            return nullptr;
+        }
+
         for (jsize k = 0; k < lenOuter; ++k)
         {
             jsize lenMiddle = static_cast<jsize>(val[k].size());
             jobjectArray jMiddleArr = env->NewObjectArray(lenMiddle, g_cls_int1DArray, nullptr);
-            if (!jMiddleArr) return nullptr;
+            if (!jMiddleArr)
+            {
+                return nullptr;
+            }
+
             for (jsize i = 0; i < lenMiddle; ++i)
             {
                 jsize lenInner = static_cast<jsize>(val[k][i].size());
                 jintArray jIntArray = env->NewIntArray(lenInner);
-                if (!jIntArray) return nullptr;
+                if (!jIntArray)
+                {
+                    return nullptr;
+                }
                 const int* ints = &val[k][i][0];
                 env->SetIntArrayRegion(jIntArray, 0, lenInner, reinterpret_cast<const jint*>(ints));
-                if (env->ExceptionCheck()) return nullptr;
+                if (env->ExceptionCheck())
+                {
+                    return nullptr;
+                }
                 env->SetObjectArrayElement(jMiddleArr, i, jIntArray);
-                if (env->ExceptionCheck()) return nullptr;
+                if (env->ExceptionCheck())
+                {
+                    return nullptr;
+                }
                 env->DeleteLocalRef(jIntArray);
             }
             env->SetObjectArrayElement(jOuterArr, k, jMiddleArr);
-            if (env->ExceptionCheck()) return nullptr;
+            if (env->ExceptionCheck())
+            {
+                return nullptr;
+            }
             env->DeleteLocalRef(jMiddleArr);
         }
         return jOuterArr;
@@ -221,17 +281,31 @@ struct JObjectConverter : boost::static_visitor < jobject >
     {
         jsize lenOuter = static_cast<jsize>(val.size());
         jobjectArray jOuterArr = env->NewObjectArray(lenOuter, g_cls_double1DArray, nullptr);
-        if (!jOuterArr) return nullptr;
+        if (!jOuterArr)
+        {
+            return nullptr;
+        }
+
         for (jsize i = 0; i < lenOuter; ++i)
         {
             size_t lenInner = val[i].size();
             jdoubleArray jDoubleArray = env->NewDoubleArray(lenInner);
-            if (!jDoubleArray) return nullptr;
+            if (!jDoubleArray)
+            {
+                return nullptr;
+            }
+
             const double* doubles = &val[i][0];
             env->SetDoubleArrayRegion(jDoubleArray, 0, lenInner, reinterpret_cast<const jdouble*>(doubles));
-            if (env->ExceptionCheck()) return nullptr;
+            if (env->ExceptionCheck())
+            {
+                return nullptr;
+            }
             env->SetObjectArrayElement(jOuterArr, i, jDoubleArray);
-            if (env->ExceptionCheck()) return nullptr;
+            if (env->ExceptionCheck())
+            {
+                return nullptr;
+            }
             env->DeleteLocalRef(jDoubleArray);
         }
 
@@ -241,26 +315,44 @@ struct JObjectConverter : boost::static_visitor < jobject >
     {
         jsize lenOuter = static_cast<jsize>(val.size());
         jobjectArray jOuterArr = env->NewObjectArray(lenOuter, g_cls_double2DArray, nullptr);
-        if (!jOuterArr) return nullptr;
+        if (!jOuterArr)
+        {
+            return nullptr;
+        }
         for (jsize k = 0; k < lenOuter; ++k)
         {
             jsize lenMiddle = static_cast<jsize>(val[k].size());
             jobjectArray jMiddleArr = env->NewObjectArray(lenMiddle, g_cls_double1DArray, nullptr);
-            if (!jMiddleArr) return nullptr;
+            if (!jMiddleArr)
+            {
+                return nullptr;
+            }
             for (jsize i = 0; i < lenMiddle; ++i)
             {
                 jsize lenInner = static_cast<jsize>(val[k][i].size());
                 jdoubleArray jDoubleArray = env->NewDoubleArray(lenInner);
-                if (!jDoubleArray) return nullptr;
+                if (!jDoubleArray)
+                {
+                    return nullptr;
+                }
                 const double* doubles = &val[k][i][0];
                 env->SetDoubleArrayRegion(jDoubleArray, 0, lenInner, reinterpret_cast<const jdouble*>(doubles));
-                if (env->ExceptionCheck()) return nullptr;
+                if (env->ExceptionCheck())
+                {
+                    return nullptr;
+                }
                 env->SetObjectArrayElement(jMiddleArr, i, jDoubleArray);
-                if (env->ExceptionCheck()) return nullptr;
+                if (env->ExceptionCheck())
+                {
+                    return nullptr;
+                }
                 env->DeleteLocalRef(jDoubleArray);
             }
             env->SetObjectArrayElement(jOuterArr, k, jMiddleArr);
-            if (env->ExceptionCheck()) return nullptr;
+            if (env->ExceptionCheck())
+            {
+                return nullptr;
+            }
             env->DeleteLocalRef(jMiddleArr);
         }
         return jOuterArr;
@@ -270,22 +362,38 @@ struct JObjectConverter : boost::static_visitor < jobject >
     {
         jsize lenOuter = static_cast<jsize>(val.size());
         jobjectArray jOuterArr = env->NewObjectArray(lenOuter, g_cls_boolean1DArray, 0);
-        if (!jOuterArr) return nullptr;
+        if (!jOuterArr)
+        {
+            return nullptr;
+        }
         for (jsize i = 0; i < lenOuter; ++i)
         {
             size_t lenInner = val[i].size();
             jbooleanArray jBooleanArray = env->NewBooleanArray(lenInner);
-            if (!jBooleanArray) return nullptr;
+            if (!jBooleanArray)
+            {
+                return nullptr;
+            }
             jboolean* booleans = new jboolean[lenInner];
-            for (size_t j = 0; j < lenInner; ++j) {
+            for (size_t j = 0; j < lenInner; ++j)
+            {
                 booleans[j] = static_cast<jboolean>(val[i][j]);
             }
             env->SetBooleanArrayRegion(jBooleanArray, 0, lenInner, booleans);
-            if (env->ExceptionCheck()) return nullptr;
+            if (env->ExceptionCheck())
+            {
+                return nullptr;
+            }
             env->SetObjectArrayElement(jOuterArr, i, jBooleanArray);
-            if (env->ExceptionCheck()) return nullptr;
+            if (env->ExceptionCheck())
+            {
+                return nullptr;
+            }
             env->ReleaseBooleanArrayElements(jBooleanArray, booleans, 0);
-            if (env->ExceptionCheck()) return nullptr;
+            if (env->ExceptionCheck())
+            {
+                return nullptr;
+            }
             env->DeleteLocalRef(jBooleanArray);
         }
         return jOuterArr;
@@ -294,31 +402,49 @@ struct JObjectConverter : boost::static_visitor < jobject >
     {
         jsize lenOuter = static_cast<jsize>(val.size());
         jobjectArray jOuterArr = env->NewObjectArray(lenOuter, g_cls_boolean2DArray, nullptr);
-        if (!jOuterArr) return nullptr;
+        if (!jOuterArr)
+        {
+            return nullptr;
+        }
         for (jsize k = 0; k < lenOuter; ++k)
         {
             jsize lenMiddle = static_cast<jsize>(val[k].size());
             jobjectArray jMiddleArr = env->NewObjectArray(lenMiddle, g_cls_boolean1DArray, nullptr);
-            if (!jMiddleArr) return nullptr;
+            if (!jMiddleArr)
+            {
+                return nullptr;
+            }
             for (jsize i = 0; i < lenMiddle; ++i)
             {
                 size_t lenInner = val[k][i].size();
                 jbooleanArray jBooleanArray = env->NewBooleanArray(lenInner);
                 jboolean* booleans = new jboolean[lenInner];
-                for (size_t j = 0; j < lenInner; ++j) {
+                for (size_t j = 0; j < lenInner; ++j)
+                {
                     booleans[j] = val[k][i][j];
                 }
                 env->SetBooleanArrayRegion(jBooleanArray, 0, lenInner, booleans);
-                if (env->ExceptionCheck()) return nullptr;
+                if (env->ExceptionCheck())
+                {
+                    return nullptr;
+                }
                 env->SetObjectArrayElement(jMiddleArr, i, jBooleanArray);
-                if (env->ExceptionCheck()) return nullptr;
+                if (env->ExceptionCheck())
+                {
+                    return nullptr;
+                }
                 env->ReleaseBooleanArrayElements(jBooleanArray, booleans, 0);
-                if (env->ExceptionCheck()) return nullptr;
+                if (env->ExceptionCheck())
+                {
+                    return nullptr;
+                }
                 env->DeleteLocalRef(jBooleanArray);
             }
             env->SetObjectArrayElement(jOuterArr, k, jMiddleArr);
-            if (env->ExceptionCheck()) return nullptr;
-            env->DeleteLocalRef(jMiddleArr);
+            if (env->ExceptionCheck())
+            {
+                return nullptr;
+            }            env->DeleteLocalRef(jMiddleArr);
         }
         return jOuterArr;
     }
@@ -327,21 +453,33 @@ struct JObjectConverter : boost::static_visitor < jobject >
     {
         jsize lenOuter = static_cast<jsize>(val.size());
         jobjectArray jOuterArr = env->NewObjectArray(lenOuter, g_cls_String1DArray, nullptr);
-        if (!jOuterArr) return nullptr;
+        if (!jOuterArr)
+        {
+            return nullptr;
+        }
         for (jsize i = 0; i < lenOuter; ++i)
         {
             jsize lenInner = static_cast<jsize>(val[i].size());
             jobjectArray strArr = env->NewObjectArray(lenInner, g_cls_String, nullptr);
-            if (!strArr) return nullptr;
+            if (!strArr)
+            {
+                return nullptr;
+            }
             for (jsize j = 0; j < lenInner; ++j)
             {
                 jstring jString = env->NewStringUTF(val[i][j].c_str());
                 env->SetObjectArrayElement(strArr, j, jString);
-                if (env->ExceptionCheck()) return nullptr;
+                if (env->ExceptionCheck())
+                {
+                    return nullptr;
+                }
                 env->DeleteLocalRef(jString);
             }
             env->SetObjectArrayElement(jOuterArr, i, strArr);
-            if (env->ExceptionCheck()) return nullptr;
+            if (env->ExceptionCheck())
+            {
+                return nullptr;
+            }
             env->DeleteLocalRef(strArr);
         }
 
@@ -351,30 +489,48 @@ struct JObjectConverter : boost::static_visitor < jobject >
     {
         jsize lenOuter = static_cast<jsize>(val.size());
         jobjectArray jOuterArr = env->NewObjectArray(lenOuter, g_cls_String2DArray, nullptr);
-        if (!jOuterArr) return nullptr;
+        if (!jOuterArr)
+        {
+            return nullptr;
+        }
         for (jsize k = 0; k < lenOuter; ++k)
         {
             jsize lenMiddle = static_cast<jsize>(val[k].size());
             jobjectArray jMiddleArr = env->NewObjectArray(lenMiddle, g_cls_String1DArray, nullptr);
-            if (!jMiddleArr) return nullptr;
+            if (!jMiddleArr)
+            {
+                return nullptr;
+            }
             for (jsize i = 0; i < lenMiddle; ++i)
             {
                 jsize lenInner = static_cast<jsize>(val[k][i].size());
                 jobjectArray strArr = env->NewObjectArray(lenInner, g_cls_String, nullptr);
-                if (!strArr) return nullptr;
+                if (!strArr)
+                {
+                    return nullptr;
+                }
                 for (jsize j = 0; j < lenInner; ++j)
                 {
                     jstring jString = env->NewStringUTF(val[k][i][j].c_str());
                     env->SetObjectArrayElement(strArr, j, jString);
-                    if (env->ExceptionCheck()) return nullptr;
+                    if (env->ExceptionCheck())
+                    {
+                        return nullptr;
+                    }
                     env->DeleteLocalRef(jString);
                 }
                 env->SetObjectArrayElement(jMiddleArr, i, strArr);
-                if (env->ExceptionCheck()) return nullptr;
+                if (env->ExceptionCheck())
+                {
+                    return nullptr;
+                }
                 env->DeleteLocalRef(strArr);
             }
             env->SetObjectArrayElement(jOuterArr, k, jMiddleArr);
-            if (env->ExceptionCheck()) return nullptr;
+            if (env->ExceptionCheck())
+            {
+                return nullptr;
+            }
             env->DeleteLocalRef(jMiddleArr);
         }
         return jOuterArr;
@@ -384,12 +540,18 @@ struct JObjectConverter : boost::static_visitor < jobject >
     {
         jsize lenOuter = static_cast<jsize>(val.size());
         jobjectArray jOuterArr = env->NewObjectArray(lenOuter, g_cls_OcRepresentation1DArray, nullptr);
-        if (!jOuterArr) return nullptr;
+        if (!jOuterArr)
+        {
+            return nullptr;
+        }
         for (jsize i = 0; i < lenOuter; ++i)
         {
             jsize lenInner = static_cast<jsize>(val[i].size());
             jobjectArray repArr = env->NewObjectArray(lenInner, g_cls_OcRepresentation, nullptr);
-            if (!repArr) return nullptr;
+            if (!repArr)
+            {
+                return nullptr;
+            }
             for (jsize j = 0; j < lenInner; ++j)
             {
                 OCRepresentation* rep = new OCRepresentation(val[i][j]);
@@ -402,11 +564,17 @@ struct JObjectConverter : boost::static_visitor < jobject >
                     return nullptr;
                 }
                 env->SetObjectArrayElement(repArr, j, jRepresentation);
-                if (env->ExceptionCheck()) return nullptr;
+                if (env->ExceptionCheck())
+                {
+                    return nullptr;
+                }
                 env->DeleteLocalRef(jRepresentation);
             }
             env->SetObjectArrayElement(jOuterArr, i, repArr);
-            if (env->ExceptionCheck()) return nullptr;
+            if (env->ExceptionCheck())
+            {
+                return nullptr;
+            }
             env->DeleteLocalRef(repArr);
         }
         return jOuterArr;
@@ -415,17 +583,26 @@ struct JObjectConverter : boost::static_visitor < jobject >
     {
         jsize lenOuter = static_cast<jsize>(val.size());
         jobjectArray jOuterArr = env->NewObjectArray(lenOuter, g_cls_OcRepresentation2DArray, nullptr);
-        if (!jOuterArr) return nullptr;
+        if (!jOuterArr)
+        {
+            return nullptr;
+        }
         for (jsize k = 0; k < lenOuter; ++k)
         {
             jsize lenMiddle = static_cast<jsize>(val[k].size());
             jobjectArray jMiddleArr = env->NewObjectArray(lenMiddle, g_cls_OcRepresentation1DArray, nullptr);
-            if (!jMiddleArr) return nullptr;
+            if (!jMiddleArr)
+            {
+                return nullptr;
+            }
             for (jsize i = 0; i < lenMiddle; ++i)
             {
                 jsize lenInner = static_cast<jsize>(val[k][i].size());
                 jobjectArray repArr = env->NewObjectArray(lenInner, g_cls_OcRepresentation, nullptr);
-                if (!repArr) return nullptr;
+                if (!repArr)
+                {
+                    return nullptr;
+                }
                 for (jsize j = 0; j < lenInner; ++j)
                 {
                     OCRepresentation* rep = new OCRepresentation(val[k][i][j]);
@@ -438,15 +615,24 @@ struct JObjectConverter : boost::static_visitor < jobject >
                         return nullptr;
                     }
                     env->SetObjectArrayElement(repArr, j, jRepresentation);
-                    if (env->ExceptionCheck()) return nullptr;
+                    if (env->ExceptionCheck())
+                    {
+                        return nullptr;
+                    }
                     env->DeleteLocalRef(jRepresentation);
                 }
                 env->SetObjectArrayElement(jMiddleArr, i, repArr);
-                if (env->ExceptionCheck()) return nullptr;
+                if (env->ExceptionCheck())
+                {
+                    return nullptr;
+                }
                 env->DeleteLocalRef(repArr);
             }
             env->SetObjectArrayElement(jOuterArr, k, jMiddleArr);
-            if (env->ExceptionCheck()) return nullptr;
+            if (env->ExceptionCheck())
+            {
+                return nullptr;
+            }
             env->DeleteLocalRef(jMiddleArr);
         }
         return jOuterArr;
index b916490..9585c55 100644 (file)
@@ -22,7 +22,8 @@
 #include "JniOcRequestHandle.h"
 
 JniOcRequestHandle::JniOcRequestHandle(OCRequestHandle requestHandle) : m_requestHandle(requestHandle)
-{}
+{
+}
 
 JniOcRequestHandle::~JniOcRequestHandle()
 {
@@ -60,4 +61,4 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcRequestHandle_dispose
     LOGD("OcRequestHandle_dispose");
     JniOcRequestHandle *handle = JniOcRequestHandle::getJniOcRequestHandlePtr(env, thiz);
     delete handle;
-}
\ No newline at end of file
+}
index 9e6925a..743c1bc 100644 (file)
@@ -26,7 +26,8 @@
 
 JniOcResource::JniOcResource(std::shared_ptr<OCResource> resource)
     : m_sharedResource(resource)
-{}
+{
+}
 
 JniOcResource::~JniOcResource()
 {
@@ -34,9 +35,12 @@ JniOcResource::~JniOcResource()
 
     m_sharedResource = nullptr;
 
-    jint envRet;
+    jint envRet = JNI_ERR;
     JNIEnv *env = GetJNIEnv(envRet);
-    if (nullptr == env) return;
+    if (nullptr == env)
+    {
+        return;
+    }
 
     m_onGetManager.removeAllListeners(env);
     m_onPutManager.removeAllListeners(env);
@@ -44,7 +48,10 @@ JniOcResource::~JniOcResource()
     m_onDeleteManager.removeAllListeners(env);
     m_onObserveManager.removeAllListeners(env);
 
-    if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
+    if (JNI_EDETACHED == envRet)
+    {
+        g_jvm->DetachCurrentThread();
+    }
 }
 
 OCStackResult JniOcResource::get(JNIEnv* env, const QueryParamsMap &queryParametersMap, jobject jListener)
@@ -432,7 +439,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_get
         return;
     }
     JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
-    if (!resource) return;
+    if (!resource)
+    {
+        return;
+    }
 
     QueryParamsMap qpm;
     JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
@@ -476,7 +486,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_get1
         return;
     }
     JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
-    if (!resource) return;
+    if (!resource)
+    {
+        return;
+    }
 
     QueryParamsMap qpm;
     JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
@@ -533,7 +546,10 @@ jobject jQueryParamsMap, jobject jListener)
         return;
     }
     JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
-    if (!resource) return;
+    if (!resource)
+    {
+        return;
+    }
 
     QueryParamsMap qpm;
     JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
@@ -590,7 +606,10 @@ jobject jQueryParamsMap, jobject jListener, jint jQoS)
         resourceInterface = env->GetStringUTFChars(jResourceInterface, nullptr);
     }
     JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
-    if (!resource) return;
+    if (!resource)
+    {
+        return;
+    }
 
     QueryParamsMap qpm;
     JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
@@ -643,10 +662,16 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_put
         return;
     }
     JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
-    if (!resource) return;
+    if (!resource)
+    {
+        return;
+    }
 
     OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env, jRepresentation);
-    if (!representation) return;
+    if (!representation)
+    {
+        return;
+    }
 
     QueryParamsMap qpm;
     JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
@@ -698,10 +723,16 @@ jobject jListener, jint jQoS)
         return;
     }
     JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
-    if (!resource) return;
+    if (!resource)
+    {
+        return;
+    }
 
     OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env, jRepresentation);
-    if (!representation) return;
+    if (!representation)
+    {
+        return;
+    }
 
     QueryParamsMap qpm;
     JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
@@ -764,10 +795,16 @@ jobject jRepresentation, jobject jQueryParamsMap, jobject jListener)
         return;
     }
     JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
-    if (!resource) return;
+    if (!resource)
+    {
+        return;
+    }
 
     OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env, jRepresentation);
-    if (!representation) return;
+    if (!representation)
+    {
+        return;
+    }
 
     QueryParamsMap qpm;
     JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
@@ -832,10 +869,16 @@ jobject jQueryParamsMap, jobject jListener, jint jQoS)
     }
 
     JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
-    if (!resource) return;
+    if (!resource)
+    {
+        return;
+    }
 
     OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env, jRepresentation);
-    if (!representation) return;
+    if (!representation)
+    {
+        return;
+    }
 
     QueryParamsMap qpm;
     JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
@@ -888,10 +931,16 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_post
         return;
     }
     JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
-    if (!resource) return;
+    if (!resource)
+    {
+        return;
+    }
 
     OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env, jRepresentation);
-    if (!representation) return;
+    if (!representation)
+    {
+        return;
+    }
 
     QueryParamsMap qpm;
     JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
@@ -941,10 +990,16 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_post1
         return;
     }
     JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
-    if (!resource) return;
+    if (!resource)
+    {
+        return;
+    }
 
     OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env, jRepresentation);
-    if (!representation) return;
+    if (!representation)
+    {
+        return;
+    }
 
     QueryParamsMap qpm;
     JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
@@ -1008,10 +1063,16 @@ jobject jRepresentation, jobject jQueryParamsMap, jobject jListener)
     }
 
     JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
-    if (!resource) return;
+    if (!resource)
+    {
+        return;
+    }
 
     OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env, jRepresentation);
-    if (!representation) return;
+    if (!representation)
+    {
+        return;
+    }
 
     QueryParamsMap qpm;
     JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
@@ -1076,10 +1137,16 @@ jobject jRepresentation, jobject jQueryParamsMap, jobject jListener, jint jQoS)
     }
 
     JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
-    if (!resource) return;
+    if (!resource)
+    {
+        return;
+    }
 
     OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env, jRepresentation);
-    if (!representation) return;
+    if (!representation)
+    {
+        return;
+    }
 
     QueryParamsMap qpm;
     JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
@@ -1122,7 +1189,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_deleteResource
         return;
     }
     JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
-    if (!resource) return;
+    if (!resource)
+    {
+        return;
+    }
 
     try
     {
@@ -1157,7 +1227,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_deleteResource1
         return;
     }
     JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
-    if (!resource) return;
+    if (!resource)
+    {
+        return;
+    }
 
     try
     {
@@ -1199,7 +1272,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_observe
         return;
     }
     JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
-    if (!resource) return;
+    if (!resource)
+    {
+        return;
+    }
 
     QueryParamsMap qpm;
     JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
@@ -1246,7 +1322,10 @@ jobject jListener, jint jQoS)
         return;
     }
     JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
-    if (!resource) return;
+    if (!resource)
+    {
+        return;
+    }
 
     QueryParamsMap qpm;
     JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
@@ -1282,7 +1361,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_cancelObserve1
 {
     LOGD("OcResource_cancelObserve1");
     JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
-    if (!resource) return;
+    if (!resource)
+    {
+        return;
+    }
 
     try
     {
@@ -1317,7 +1399,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_setHeaderOptions
         return;
     }
     JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
-    if (!resource) return;
+    if (!resource)
+    {
+        return;
+    }
 
     HeaderOptions headerOptions;
     JniUtils::convertJavaHeaderOptionsArrToVector(env, jheaderOptionArr, headerOptions);
@@ -1335,7 +1420,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_unsetHeaderOptions
 {
     LOGD("OcResource_unsetHeaderOptions");
     JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
-    if (!resource) return;
+    if (!resource)
+    {
+        return;
+    }
 
     resource->unsetHeaderOptions();
 }
@@ -1350,7 +1438,10 @@ JNIEXPORT jstring JNICALL Java_org_iotivity_base_OcResource_getHost
 {
     LOGD("OcResource_getHost");
     JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
-    if (!resource) return nullptr;
+    if (!resource)
+    {
+        return nullptr;
+    }
 
     return env->NewStringUTF(resource->host().c_str());
 }
@@ -1365,7 +1456,10 @@ JNIEXPORT jstring JNICALL Java_org_iotivity_base_OcResource_getUri
 {
     LOGD("OcResource_getUri");
     JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
-    if (!resource) return nullptr;
+    if (!resource)
+    {
+        return nullptr;
+    }
 
     return env->NewStringUTF(resource->uri().c_str());
 }
@@ -1380,7 +1474,10 @@ JNIEXPORT jint JNICALL Java_org_iotivity_base_OcResource_getConnectivityTypeN
 {
     LOGD("OcResource_getConnectivityType");
     JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
-    if (!resource) return -1;
+    if (!resource)
+    {
+        return -1;
+    }
 
     OCConnectivityType connectivityType = resource->connectivityType();
     return static_cast<jint>(connectivityType);
@@ -1396,6 +1493,11 @@ JNIEXPORT jboolean JNICALL Java_org_iotivity_base_OcResource_isObservable
 {
     LOGD("OcResource_isObservable");
     JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
+    if (!resource)
+    {
+        return false;
+    }
+
     return (jboolean)resource->isObservable();
 }
 
@@ -1409,7 +1511,10 @@ JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcResource_getResourceTypes
 {
     LOGD("OcResource_getResourceTypes");
     JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
-    if (!resource) return nullptr;
+    if (!resource)
+    {
+        return nullptr;
+    }
 
     std::vector<std::string> resourceTypes = resource->getResourceTypes();
 
@@ -1426,7 +1531,10 @@ JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcResource_getResourceInterface
 {
     LOGD("OcResource_getResourceInterfaces");
     JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
-    if (!resource) return nullptr;
+    if (!resource)
+    {
+        return nullptr;
+    }
 
     std::vector<std::string> resourceInterfaces = resource->getResourceInterfaces();
 
@@ -1443,11 +1551,17 @@ JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcResource_getUniqueIdentifier
 {
     LOGD("OcResource_getUniqueIdentifier");
     JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
-    if (!resource) return nullptr;
+    if (!resource)
+    {
+        return nullptr;
+    }
 
     JniOcResourceIdentifier *jniResourceIdentifier =
         new JniOcResourceIdentifier(resource->uniqueIdentifier());
-    if (!jniResourceIdentifier) return nullptr;
+    if (!jniResourceIdentifier)
+    {
+        return nullptr;
+    }
 
     jlong handle = reinterpret_cast<jlong>(jniResourceIdentifier);
     jobject jResourceIdentifier = env->NewObject(g_cls_OcResourceIdentifier,
@@ -1469,7 +1583,10 @@ JNIEXPORT jstring JNICALL Java_org_iotivity_base_OcResource_getServerId
 {
     LOGD("OcResource_getServerId");
     JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
-    if (!resource) return nullptr;
+    if (!resource)
+    {
+        return nullptr;
+    }
 
     return env->NewStringUTF(resource->sid().c_str());
 }
@@ -1485,4 +1602,4 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_dispose
     LOGD("OcResource_dispose");
     JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
     delete resource;
-}
\ No newline at end of file
+}
index 2d438f2..92371f4 100644 (file)
@@ -25,7 +25,8 @@ using namespace OC;
 
 JniOcResourceHandle::JniOcResourceHandle(OCResourceHandle resourceHandle)
     : m_resourceHandle(resourceHandle)
-{}
+{
+}
 
 JniOcResourceHandle::~JniOcResourceHandle()
 {
@@ -63,4 +64,4 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcResourceHandle_dispose
     LOGD("OcResourceHandle_dispose");
     JniOcResourceHandle *resourceHandle = JniOcResourceHandle::getJniOcResourceHandlePtr(env, thiz);
     delete resourceHandle;
-}
\ No newline at end of file
+}
index b0b7d65..beeb724 100644 (file)
@@ -24,7 +24,8 @@
 
 JniOcResourceIdentifier::JniOcResourceIdentifier(OC::OCResourceIdentifier resourceIdentifier)
     : m_resourceIdentifier(resourceIdentifier)
-{}
+{
+}
 
 JniOcResourceIdentifier::~JniOcResourceIdentifier()
 {
@@ -60,10 +61,16 @@ JNIEXPORT jboolean JNICALL Java_org_iotivity_base_OcResourceIdentifier_equalsN
 (JNIEnv *env, jobject jThiz, jobject jOther)
 {
     JniOcResourceIdentifier *thiz = JniOcResourceIdentifier::getJniOcResourceIdentifierPtr(env, jThiz);
-    if (!thiz) return false;
+    if (!thiz)
+    {
+        return false;
+    }
 
     JniOcResourceIdentifier *other = JniOcResourceIdentifier::getJniOcResourceIdentifierPtr(env, jOther);
-    if (!other) return false;
+    if (!other)
+    {
+        return false;
+    }
 
     if (thiz->getOCResourceIdentifier() == other->getOCResourceIdentifier())
     {
@@ -86,4 +93,4 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcResourceIdentifier_dispose
     LOGD("JniOcResourceIdentifier_dispose");
     JniOcResourceIdentifier *identifier = JniOcResourceIdentifier::getJniOcResourceIdentifierPtr(env, thiz);
     delete identifier;
-}
\ No newline at end of file
+}
index c943f70..c977bac 100644 (file)
@@ -29,10 +29,12 @@ using namespace OC;
 
 JniOcResourceRequest::JniOcResourceRequest(const std::shared_ptr<OCResourceRequest> request)
     : m_request(request)
-{}
+{
+}
 
 JniOcResourceRequest::~JniOcResourceRequest()
-{}
+{
+}
 
 std::string
 JniOcResourceRequest::getRequestType()
@@ -119,8 +121,10 @@ JNIEXPORT jstring JNICALL Java_org_iotivity_base_OcResourceRequest_getRequestTyp
 {
     LOGD("OcResourceRequest_getRequestTypeNative");
     JniOcResourceRequest *request = JniOcResourceRequest::getJniOcResourceRequestPtr(env, thiz);
-    if (!request) return nullptr;
-
+    if (!request)
+    {
+        return nullptr;
+    }
     std::string requestType = request->getRequestType();
     return env->NewStringUTF(requestType.c_str());
 }
@@ -135,7 +139,10 @@ JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcResourceRequest_getQueryParam
 {
     LOGD("OcResourceRequest_getQueryParameters");
     JniOcResourceRequest *request = JniOcResourceRequest::getJniOcResourceRequestPtr(env, thiz);
-    if (!request) return nullptr;
+    if (!request)
+    {
+        return nullptr;
+    }
 
     return JniUtils::convertQueryParamsMapToJavaMap(env, request->getQueryParameters());
 }
@@ -150,7 +157,10 @@ JNIEXPORT jint JNICALL Java_org_iotivity_base_OcResourceRequest_getRequestHandle
 {
     LOGD("OcResourceRequest_getRequestHandlerFlagNative");
     JniOcResourceRequest *request = JniOcResourceRequest::getJniOcResourceRequestPtr(env, thiz);
-    if (!request) return -1;
+    if (!request)
+    {
+        return -1;
+    }
 
     return static_cast<jint>(request->getRequestHandlerFlag());
 }
@@ -165,10 +175,16 @@ JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcResourceRequest_getResourceRe
 {
     LOGD("OcResourceRequest_getResourceRepresentation");
     JniOcResourceRequest *request = JniOcResourceRequest::getJniOcResourceRequestPtr(env, thiz);
-    if (!request) return nullptr;
+    if (!request)
+    {
+        return nullptr;
+    }
 
     OCRepresentation *ocRepresentation = new OCRepresentation(request->getResourceRepresentation());
-    if (!ocRepresentation) return nullptr;
+    if (!ocRepresentation)
+    {
+        return nullptr;
+    }
 
     jlong handle = reinterpret_cast<jlong>(ocRepresentation);
     jobject jRepresentation = env->NewObject(g_cls_OcRepresentation, g_mid_OcRepresentation_N_ctor_bool,
@@ -192,8 +208,10 @@ JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcResourceRequest_getObservatio
 {
     LOGD("OcResourceRequest_getObservationInfo");
     JniOcResourceRequest *request = JniOcResourceRequest::getJniOcResourceRequestPtr(env, thiz);
-    if (!request) return nullptr;
-
+    if (!request)
+    {
+        return nullptr;
+    }
     ObservationInfo oInfo = request->getObservationInfo();
 
     jobject jObservationInfo = env->NewObject(g_cls_ObservationInfo, g_mid_ObservationInfo_N_ctor,
@@ -222,8 +240,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcResourceRequest_setResourceUri
         return;
     }
     JniOcResourceRequest *request = JniOcResourceRequest::getJniOcResourceRequestPtr(env, thiz);
-    if (!request) return;
-
+    if (!request)
+    {
+        return;
+    }
     request->setResourceUri(env->GetStringUTFChars(jUri, 0));
 }
 
@@ -237,8 +257,10 @@ JNIEXPORT jstring JNICALL Java_org_iotivity_base_OcResourceRequest_getResourceUr
 {
     LOGD("OcResourceRequest_getResourceUri");
     JniOcResourceRequest *request = JniOcResourceRequest::getJniOcResourceRequestPtr(env, thiz);
-    if (!request) return nullptr;
-
+    if (!request)
+    {
+        return nullptr;
+    }
     std::string requestUri = request->getResourceUri();
     return env->NewStringUTF(requestUri.c_str());
 }
@@ -253,8 +275,10 @@ JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcResourceRequest_getHeaderOpti
 {
     LOGD("OcResourceRequest_getHeaderOptions");
     JniOcResourceRequest *request = JniOcResourceRequest::getJniOcResourceRequestPtr(env, thiz);
-    if (!request) return nullptr;
-
+    if (!request)
+    {
+        return nullptr;
+    }
     return JniUtils::convertHeaderOptionsVectorToJavaList(env, request->getHeaderOptions());
 }
 
@@ -268,7 +292,10 @@ JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcResourceRequest_getRequestHan
 {
     LOGD("OcResourceRequest_getRequestHandle");
     JniOcResourceRequest *request = JniOcResourceRequest::getJniOcResourceRequestPtr(env, thiz);
-    if (!request) return nullptr;
+    if (!request)
+    {
+        return nullptr;
+    }
 
     JniOcRequestHandle* jniHandle = new JniOcRequestHandle(request->getRequestHandle());
     jlong handle = reinterpret_cast<jlong>(jniHandle);
@@ -292,7 +319,10 @@ JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcResourceRequest_getResourceHa
 {
     LOGD("OcResourceRequest_getResourceHandle");
     JniOcResourceRequest *request = JniOcResourceRequest::getJniOcResourceRequestPtr(env, thiz);
-    if (!request) return nullptr;
+    if (!request)
+    {
+        return nullptr;
+    }
 
     JniOcResourceHandle* jniHandle = new JniOcResourceHandle(
         request->getResourceHandle());
@@ -318,4 +348,4 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcResourceRequest_dispose
     LOGD("OcResourceRequest_dispose");
     JniOcResourceRequest *request = JniOcResourceRequest::getJniOcResourceRequestPtr(env, thiz);
     delete request;
-}
\ No newline at end of file
+}
index 0781d9f..8189073 100644 (file)
@@ -30,10 +30,13 @@ using namespace OC;
 
 JniOcResourceResponse::JniOcResourceResponse
 (std::shared_ptr<OCResourceResponse> resourceResponse)
-: m_response(resourceResponse){}
+: m_response(resourceResponse)
+{
+}
 
 JniOcResourceResponse::~JniOcResourceResponse()
-{}
+{
+}
 
 void JniOcResourceResponse::setErrorCode(const int eCode)
 {
@@ -111,8 +114,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcResourceResponse_setErrorCode
 {
     LOGD("OcResourceResponse_setErrorCode");
     JniOcResourceResponse *response = JniOcResourceResponse::getJniOcResourceResponsePtr(env, thiz);
-    if (!response) return;
-
+    if (!response)
+    {
+        return;
+    }
     response->setErrorCode(static_cast<int>(eCode));
 }
 
@@ -126,8 +131,10 @@ JNIEXPORT jstring JNICALL Java_org_iotivity_base_OcResourceResponse_getNewResour
 {
     LOGD("OcResourceResponse_getNewResourceUri");
     JniOcResourceResponse *response = JniOcResourceResponse::getJniOcResourceResponsePtr(env, thiz);
-    if (!response) return nullptr;
-
+    if (!response)
+    {
+        return nullptr;
+    }
     return env->NewStringUTF(response->getNewResourceUri().c_str());
 }
 
@@ -141,8 +148,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcResourceResponse_setNewResourceU
 {
     LOGD("OcResourceResponse_setNewResourceUri");
     JniOcResourceResponse *response = JniOcResourceResponse::getJniOcResourceResponsePtr(env, thiz);
-    if (!response) return;
-
+    if (!response)
+    {
+        return;
+    }
     response->setNewResourceUri(env->GetStringUTFChars(jstr, 0));
 }
 
@@ -161,8 +170,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcResourceResponse_setHeaderOption
         return;
     }
     JniOcResourceResponse *jniResponse = JniOcResourceResponse::getJniOcResourceResponsePtr(env, thiz);
-    if (!jniResponse) return;
-
+    if (!jniResponse)
+    {
+        return;
+    }
     HeaderOptions headerOptions;
     JniUtils::convertJavaHeaderOptionsArrToVector(env, jHeaderOptions, headerOptions);
 
@@ -184,11 +195,15 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcResourceResponse_setRequestHandl
         return;
     }
     JniOcResourceResponse *jniResponse = JniOcResourceResponse::getJniOcResourceResponsePtr(env, thiz);
-    if (!jniResponse) return;
-
+    if (!jniResponse)
+    {
+        return;
+    }
     JniOcRequestHandle* jniOcRequestHandle = JniOcRequestHandle::getJniOcRequestHandlePtr(env, jRequestHandle);
-    if (!jniOcRequestHandle) return;
-
+    if (!jniOcRequestHandle)
+    {
+        return;
+    }
     jniResponse->setRequestHandle(jniOcRequestHandle->getOCRequestHandle());
 }
 
@@ -207,11 +222,15 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcResourceResponse_setResourceHand
         return;
     }
     JniOcResourceResponse *jniResponse = JniOcResourceResponse::getJniOcResourceResponsePtr(env, thiz);
-    if (!jniResponse) return;
-
+    if (!jniResponse)
+    {
+        return;
+    }
     JniOcResourceHandle* jniOcResourceHandle = JniOcResourceHandle::getJniOcResourceHandlePtr(env, jResourceHandle);
-    if (!jniOcResourceHandle) return;
-
+    if (!jniOcResourceHandle)
+    {
+        return;
+    }
     jniResponse->setResourceHandle(jniOcResourceHandle->getOCResourceHandle());
 }
 
@@ -225,8 +244,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcResourceResponse_setResponseResu
 {
     LOGD("OcResourceResponse_setResponseResult");
     JniOcResourceResponse *response = JniOcResourceResponse::getJniOcResourceResponsePtr(env, thiz);
-    if (!response) return;
-
+    if (!response)
+    {
+        return;
+    }
     response->setResponseResult(JniUtils::getOCEntityHandlerResult(env, static_cast<int>(responseResult)));
 }
 
@@ -252,12 +273,16 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcResourceResponse_setResourceRepr
 
     JniOcResourceResponse *response = JniOcResourceResponse::getJniOcResourceResponsePtr(env,
         thiz);
-    if (!response) return;
-
+    if (!response)
+    {
+        return;
+    }
     OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env,
         jRepresentation);
-    if (!representation) return;
-
+    if (!representation)
+    {
+        return;
+    }
     response->setResourceRepresentation(*representation, env->GetStringUTFChars(jstr, 0));
 }
 
@@ -276,8 +301,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcResourceResponse_setResourceRepr
         return;
     }
     JniOcResourceResponse *response = JniOcResourceResponse::getJniOcResourceResponsePtr(env, thiz);
-    if (!response) return;
-
+    if (!response)
+    {
+        return;
+    }
     OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env,
         jRepresentation);
 
@@ -317,4 +344,4 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcResourceResponse_dispose
     LOGD("OcResourceResponse_dispose");
     JniOcResourceResponse *resp = JniOcResourceResponse::getJniOcResourceResponsePtr(env, thiz);
     delete resp;
-}
\ No newline at end of file
+}
index f1cd7f9..7585b7b 100644 (file)
@@ -27,7 +27,8 @@ namespace PH = std::placeholders;
 
 JniOcSecureResource::JniOcSecureResource(std::shared_ptr<OCSecureResource> device)
     : m_sharedSecureResource(device)
-{}
+{
+}
 
 JniOcSecureResource::~JniOcSecureResource()
 {
index 86e00bb..e2c6175 100644 (file)
 #include "OCRepresentation.h"
 #include "JniUtils.h"
 
+/**
+ * Macro to verify the validity of input argument.
+ *
+ * @param  arg  log level
+ */
+#define VERIFY_VARIABLE_NULL(arg) \
+    if (nullptr == (arg)) \
+    { \
+        LOGE("invalid input"); \
+        return JNI_ERR; \
+    } \
+
 JavaVM* g_jvm = nullptr;
 
 jclass g_cls_Integer = nullptr;
@@ -151,7 +163,7 @@ void throwOcException(JNIEnv* env, jobject ex)
 JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved)
 {
     LOGI("JNI_OnLoad");
-    JNIEnv* env;
+    JNIEnv* env = nullptr;
     g_jvm = vm;
 
     if (g_jvm->GetEnv((void **)&env, JNI_CURRENT_VERSION) != JNI_OK)
@@ -159,352 +171,353 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved)
         LOGE("Failed to get the environment using GetEnv()");
         return JNI_ERR;
     }
+    VERIFY_VARIABLE_NULL(env);
 
     jclass clazz = nullptr;
 
     //Integer
     clazz = env->FindClass("java/lang/Integer");
-    if (!clazz) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(clazz);
+
     g_cls_Integer = (jclass)env->NewGlobalRef(clazz);
     env->DeleteLocalRef(clazz);
 
     g_mid_Integer_ctor = env->GetMethodID(g_cls_Integer, "<init>", "(I)V");
-    if (!g_mid_Integer_ctor) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(g_mid_Integer_ctor);
 
     clazz = env->FindClass("[I");
-    if (!clazz) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(clazz);
     g_cls_int1DArray = (jclass)env->NewGlobalRef(clazz);
     env->DeleteLocalRef(clazz);
 
     clazz = env->FindClass("[[I");
-    if (!clazz) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(clazz);
     g_cls_int2DArray = (jclass)env->NewGlobalRef(clazz);
     env->DeleteLocalRef(clazz);
 
     //Double
     clazz = env->FindClass("java/lang/Double");
-    if (!clazz) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(clazz);
     g_cls_Double = (jclass)env->NewGlobalRef(clazz);
     env->DeleteLocalRef(clazz);
 
     g_mid_Double_ctor = env->GetMethodID(g_cls_Double, "<init>", "(D)V");
-    if (!g_mid_Double_ctor) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(g_mid_Double_ctor);
 
     clazz = env->FindClass("[D");
-    if (!clazz) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(clazz);
     g_cls_double1DArray = (jclass)env->NewGlobalRef(clazz);
     env->DeleteLocalRef(clazz);
 
     clazz = env->FindClass("[[D");
-    if (!clazz) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(clazz);
     g_cls_double2DArray = (jclass)env->NewGlobalRef(clazz);
     env->DeleteLocalRef(clazz);
 
     //Boolean
     clazz = env->FindClass("java/lang/Boolean");
-    if (!clazz) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(clazz);
     g_cls_Boolean = (jclass)env->NewGlobalRef(clazz);
     env->DeleteLocalRef(clazz);
 
     g_mid_Boolean_ctor = env->GetMethodID(g_cls_Boolean, "<init>", "(Z)V");
-    if (!g_mid_Boolean_ctor) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(g_mid_Boolean_ctor);
 
     clazz = env->FindClass("[Z");
-    if (!clazz) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(clazz);
     g_cls_boolean1DArray = (jclass)env->NewGlobalRef(clazz);
     env->DeleteLocalRef(clazz);
 
     clazz = env->FindClass("[[Z");
-    if (!clazz) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(clazz);
     g_cls_boolean2DArray = (jclass)env->NewGlobalRef(clazz);
     env->DeleteLocalRef(clazz);
 
     //String
     clazz = env->FindClass("java/lang/String");
-    if (!clazz) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(clazz);
     g_cls_String = (jclass)env->NewGlobalRef(clazz);
     env->DeleteLocalRef(clazz);
 
     clazz = env->FindClass("[Ljava/lang/String;");
-    if (!clazz) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(clazz);
     g_cls_String1DArray = (jclass)env->NewGlobalRef(clazz);
     env->DeleteLocalRef(clazz);
 
     clazz = env->FindClass("[[Ljava/lang/String;");
-    if (!clazz) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(clazz);
     g_cls_String2DArray = (jclass)env->NewGlobalRef(clazz);
     env->DeleteLocalRef(clazz);
 
     //LinkedList
     clazz = env->FindClass("java/util/LinkedList");
-    if (!clazz) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(clazz);
     g_cls_LinkedList = (jclass)env->NewGlobalRef(clazz);
     env->DeleteLocalRef(clazz);
 
     g_mid_LinkedList_ctor = env->GetMethodID(g_cls_LinkedList, "<init>", "()V");
-    if (!g_mid_LinkedList_ctor) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(g_mid_LinkedList_ctor);
 
     g_mid_LinkedList_add_object = env->GetMethodID(g_cls_LinkedList, "add", "(Ljava/lang/Object;)Z");
-    if (!g_mid_LinkedList_add_object) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(g_mid_LinkedList_add_object);
 
     //Map
     clazz = env->FindClass("java/util/Map");
-    if (!clazz) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(clazz);
     g_cls_Map = (jclass)env->NewGlobalRef(clazz);
     env->DeleteLocalRef(clazz);
 
     g_mid_Map_entrySet = env->GetMethodID(g_cls_Map, "entrySet", "()Ljava/util/Set;");
-    if (!g_mid_Map_entrySet) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(g_mid_Map_entrySet);
 
     //MapEntry
     clazz = env->FindClass("java/util/Map$Entry");
-    if (!clazz) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(clazz);
     g_cls_MapEntry = (jclass)env->NewGlobalRef(clazz);
     env->DeleteLocalRef(clazz);
 
     g_mid_MapEntry_getKey = env->GetMethodID(g_cls_MapEntry, "getKey", "()Ljava/lang/Object;");
-    if (!g_mid_MapEntry_getKey) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(g_mid_MapEntry_getKey);
     g_mid_MapEntry_getValue = env->GetMethodID(g_cls_MapEntry, "getValue", "()Ljava/lang/Object;");
-    if (!g_mid_MapEntry_getValue) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(g_mid_MapEntry_getValue);
 
     //Set
     clazz = env->FindClass("java/util/Set");
-    if (!clazz) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(clazz);
     g_cls_Set = (jclass)env->NewGlobalRef(clazz);
     env->DeleteLocalRef(clazz);
 
     g_mid_Set_iterator = env->GetMethodID(g_cls_Set, "iterator", "()Ljava/util/Iterator;");
-    if (!g_mid_Set_iterator) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(g_mid_Set_iterator);
 
     //Iterator
     clazz = env->FindClass("java/util/Iterator");
-    if (!clazz) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(clazz);
     g_cls_Iterator = (jclass)env->NewGlobalRef(clazz);
     env->DeleteLocalRef(clazz);
 
     g_mid_Iterator_hasNext = env->GetMethodID(g_cls_Iterator, "hasNext", "()Z");
-    if (!g_mid_Iterator_hasNext) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(g_mid_Iterator_hasNext);
 
     g_mid_Iterator_next = env->GetMethodID(g_cls_Iterator, "next", "()Ljava/lang/Object;");
-    if (!g_mid_Iterator_next) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(g_mid_Iterator_next);
 
     //HashMap
     clazz = env->FindClass("java/util/HashMap");
-    if (!clazz) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(clazz);
     g_cls_HashMap = (jclass)env->NewGlobalRef(clazz);
     env->DeleteLocalRef(clazz);
 
     g_mid_HashMap_ctor = env->GetMethodID(g_cls_HashMap, "<init>", "()V");
-    if (!g_mid_HashMap_ctor) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(g_mid_HashMap_ctor);
 
     g_mid_HashMap_put = env->GetMethodID(g_cls_HashMap, "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
-    if (!g_mid_HashMap_put) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(g_mid_HashMap_put);
 
     //OcException
     clazz = env->FindClass("org/iotivity/base/OcException");
-    if (!clazz) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(clazz);
     g_cls_OcException = (jclass)env->NewGlobalRef(clazz);
     env->DeleteLocalRef(clazz);
 
     g_mid_OcException_ctor = env->GetMethodID(g_cls_OcException, "<init>", "(Ljava/lang/String;Ljava/lang/String;)V");
-    if (!g_mid_OcException_ctor) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(g_mid_OcException_ctor);
 
     g_mid_OcException_setNativeExceptionLocation = env->GetMethodID(g_cls_OcException, "setNativeExceptionLocation",
         "(Ljava/lang/String;""Ljava/lang/String;""I)V");
-    if (!g_mid_OcException_setNativeExceptionLocation) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(g_mid_OcException_setNativeExceptionLocation);
 
     //OcResource
     clazz = env->FindClass("org/iotivity/base/OcResource");
-    if (!clazz) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(clazz);
     g_cls_OcResource = (jclass)env->NewGlobalRef(clazz);
     env->DeleteLocalRef(clazz);
 
     g_mid_OcResource_ctor = env->GetMethodID(g_cls_OcResource, "<init>", "(J)V");
-    if (!g_mid_OcResource_ctor) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(g_mid_OcResource_ctor);
 
     //OcRepresentation
     clazz = env->FindClass("org/iotivity/base/OcRepresentation");
-    if (!clazz) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(clazz);
     g_cls_OcRepresentation = (jclass)env->NewGlobalRef(clazz);
     env->DeleteLocalRef(clazz);
 
     g_mid_OcRepresentation_N_ctor = env->GetMethodID(g_cls_OcRepresentation, "<init>", "(J)V");
-    if (!g_mid_OcRepresentation_N_ctor) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(g_mid_OcRepresentation_N_ctor);
 
     g_mid_OcRepresentation_N_ctor_bool = env->GetMethodID(g_cls_OcRepresentation, "<init>", "(JZ)V");
-    if (!g_mid_OcRepresentation_N_ctor_bool) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(g_mid_OcRepresentation_N_ctor_bool);
 
     clazz = env->FindClass("[Lorg/iotivity/base/OcRepresentation;");
-    if (!clazz) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(clazz);
     g_cls_OcRepresentation1DArray = (jclass)env->NewGlobalRef(clazz);
     env->DeleteLocalRef(clazz);
 
     clazz = env->FindClass("[[Lorg/iotivity/base/OcRepresentation;");
-    if (!clazz) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(clazz);
     g_cls_OcRepresentation2DArray = (jclass)env->NewGlobalRef(clazz);
     env->DeleteLocalRef(clazz);
 
     //HeaderOptions
     clazz = env->FindClass("org/iotivity/base/OcHeaderOption");
-    if (!clazz) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(clazz);
     g_cls_OcHeaderOption = (jclass)env->NewGlobalRef(clazz);
     env->DeleteLocalRef(clazz);
     g_mid_OcHeaderOption_ctor = env->GetMethodID(g_cls_OcHeaderOption, "<init>", "(ILjava/lang/String;)V");
-    if (!g_mid_OcHeaderOption_ctor) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(g_mid_OcHeaderOption_ctor);
 
     g_mid_OcHeaderOption_get_id = env->GetMethodID(g_cls_OcHeaderOption, "getOptionId", "()I");
-    if (!g_mid_OcHeaderOption_get_id) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(g_mid_OcHeaderOption_get_id);
 
     g_mid_OcHeaderOption_get_data = env->GetMethodID(g_cls_OcHeaderOption, "getOptionData", "()Ljava/lang/String;");
-    if (!g_mid_OcHeaderOption_get_data) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(g_mid_OcHeaderOption_get_data);
 
     //OcResourceRequest
     clazz = env->FindClass("org/iotivity/base/OcResourceRequest");
-    if (!clazz) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(clazz);
     g_cls_OcResourceRequest = (jclass)env->NewGlobalRef(clazz);
     env->DeleteLocalRef(clazz);
 
     g_mid_OcResourceRequest_N_ctor = env->GetMethodID(g_cls_OcResourceRequest, "<init>", "(J)V");
-    if (!g_mid_OcResourceRequest_N_ctor) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(g_mid_OcResourceRequest_N_ctor);
 
     //OcResourceResponse
     clazz = env->FindClass("org/iotivity/base/OcResourceResponse");
-    if (!clazz) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(clazz);
     g_cls_OcResourceResponse = (jclass)env->NewGlobalRef(clazz);
     env->DeleteLocalRef(clazz);
 
     g_mid_OcResourceResponse_N_ctor = env->GetMethodID(g_cls_OcResourceResponse, "<init>", "(J)V");
-    if (!g_mid_OcResourceResponse_N_ctor) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(g_mid_OcResourceResponse_N_ctor);
 
     //OcResourceHandle
     clazz = env->FindClass("org/iotivity/base/OcResourceHandle");
-    if (!clazz) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(clazz);
     g_cls_OcResourceHandle = (jclass)env->NewGlobalRef(clazz);
     env->DeleteLocalRef(clazz);
     g_mid_OcResourceHandle_N_ctor = env->GetMethodID(g_cls_OcResourceHandle, "<init>", "(J)V");
-    if (!g_mid_OcResourceHandle_N_ctor) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(g_mid_OcResourceHandle_N_ctor);
 
     //OcPresenceHandle
     clazz = env->FindClass("org/iotivity/base/OcPresenceHandle");
-    if (!clazz) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(clazz);
     g_cls_OcPresenceHandle = (jclass)env->NewGlobalRef(clazz);
     env->DeleteLocalRef(clazz);
     g_mid_OcPresenceHandle_N_ctor = env->GetMethodID(g_cls_OcPresenceHandle, "<init>", "(J)V");
-    if (!g_mid_OcPresenceHandle_N_ctor) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(g_mid_OcPresenceHandle_N_ctor);
 
     //OcRequestHandle
     clazz = env->FindClass("org/iotivity/base/OcRequestHandle");
-    if (!clazz) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(clazz);
     g_cls_OcRequestHandle = (jclass)env->NewGlobalRef(clazz);
     env->DeleteLocalRef(clazz);
     g_mid_OcRequestHandle_N_ctor = env->GetMethodID(g_cls_OcRequestHandle, "<init>", "(J)V");
-    if (!g_mid_OcRequestHandle_N_ctor) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(g_mid_OcRequestHandle_N_ctor);
 
     //OcPresenceStatus
     clazz = env->FindClass("org/iotivity/base/OcPresenceStatus");
-    if (!clazz) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(clazz);
     g_cls_OcPresenceStatus = (jclass)env->NewGlobalRef(clazz);
     env->DeleteLocalRef(clazz);
     g_mid_OcPresenceStatus_get = env->GetStaticMethodID(g_cls_OcPresenceStatus, "get",
         "(Ljava/lang/String;)Lorg/iotivity/base/OcPresenceStatus;");
-    if (!g_mid_OcPresenceStatus_get) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(g_mid_OcPresenceStatus_get);
 
     //ObservationInfo
     clazz = env->FindClass("org/iotivity/base/ObservationInfo");
-    if (!clazz) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(clazz);
     g_cls_ObservationInfo = (jclass)env->NewGlobalRef(clazz);
     env->DeleteLocalRef(clazz);
     g_mid_ObservationInfo_N_ctor = env->GetMethodID(g_cls_ObservationInfo, "<init>", "(IB)V");
-    if (!g_mid_ObservationInfo_N_ctor) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(g_mid_ObservationInfo_N_ctor);
 
     clazz = env->FindClass("org/iotivity/base/OcResourceIdentifier");
-    if (!clazz) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(clazz);
     g_cls_OcResourceIdentifier = (jclass)env->NewGlobalRef(clazz);
     env->DeleteLocalRef(clazz);
     g_mid_OcResourceIdentifier_N_ctor = env->GetMethodID(g_cls_OcResourceIdentifier, "<init>", "(J)V");
-    if (!g_mid_OcResourceIdentifier_N_ctor) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(g_mid_OcResourceIdentifier_N_ctor);
 
     //OcSecureResource
     clazz = env->FindClass("org/iotivity/base/OcSecureResource");
-    if (!clazz) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(clazz);
     g_cls_OcSecureResource =  (jclass)env->NewGlobalRef(clazz);
     env->DeleteLocalRef(clazz);
     g_mid_OcSecureResource_ctor = env->GetMethodID(g_cls_OcSecureResource, "<init>", "(J)V");
-    if (!g_mid_OcSecureResource_ctor) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(g_mid_OcSecureResource_ctor);
 
     //ProvisionResult
     clazz = env->FindClass("org/iotivity/base/ProvisionResult");
-    if (!clazz) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(clazz);
     g_cls_OcProvisionResult =  (jclass)env->NewGlobalRef(clazz);
     env->DeleteLocalRef(clazz);
     g_mid_OcProvisionResult_ctor = env->GetMethodID(g_cls_OcProvisionResult, "<init>", "(Ljava/lang/String;I)V");
-    if (!g_mid_OcProvisionResult_ctor) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(g_mid_OcProvisionResult_ctor);
 
     //OcDirectPairDevice
     clazz = env->FindClass("org/iotivity/base/OcDirectPairDevice");
-    if (!clazz) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(clazz);
     g_cls_OcDirectPairDevice =  (jclass)env->NewGlobalRef(clazz);
-    //env->DeleteLocalRef(clazz);
     g_mid_OcDirectPairDevice_ctor = env->GetMethodID(g_cls_OcDirectPairDevice, "<init>", "(J)V");
-    if (!g_mid_OcDirectPairDevice_ctor) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(g_mid_OcDirectPairDevice_ctor);
 
     g_mid_OcDirectPairDevice_dev_ctor = env->GetMethodID(g_cls_OcDirectPairDevice, "<init>", "(Ljava/lang/String;)V");
-    if (!g_mid_OcDirectPairDevice_dev_ctor) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(g_mid_OcDirectPairDevice_dev_ctor);
     env->DeleteLocalRef(clazz);
 
     //OicSecAcl
     clazz = env->FindClass("org/iotivity/base/OicSecAcl");
-    if (!clazz) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(clazz);
     g_cls_OcOicSecAcl =  (jclass)env->NewGlobalRef(clazz);
     env->DeleteLocalRef(clazz);
 
     g_mid_OcOicSecAcl_get_subject = env->GetMethodID(g_cls_OcOicSecAcl, "getSubject", "()Ljava/lang/String;");
-    if (!g_mid_OcOicSecAcl_get_subject) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(g_mid_OcOicSecAcl_get_subject);
 
     g_mid_OcOicSecAcl_get_resources_cnt = env->GetMethodID(g_cls_OcOicSecAcl, "getResourcesCount", "()I");
-    if (!g_mid_OcOicSecAcl_get_resources_cnt) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(g_mid_OcOicSecAcl_get_resources_cnt);
 
     g_mid_OcOicSecAcl_get_resources = env->GetMethodID(g_cls_OcOicSecAcl, "getResources", "(I)Ljava/lang/String;");
-    if (!g_mid_OcOicSecAcl_get_resources) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(g_mid_OcOicSecAcl_get_resources);
 
     g_mid_OcOicSecAcl_get_permission = env->GetMethodID(g_cls_OcOicSecAcl, "getPermission", "()I");
-    if (!g_mid_OcOicSecAcl_get_permission) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(g_mid_OcOicSecAcl_get_permission);
 
     g_mid_OcOicSecAcl_get_periods_cnt = env->GetMethodID(g_cls_OcOicSecAcl, "getPeriodsCount", "()I");
-    if (!g_mid_OcOicSecAcl_get_periods_cnt) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(g_mid_OcOicSecAcl_get_periods_cnt);
 
     g_mid_OcOicSecAcl_get_periods = env->GetMethodID(g_cls_OcOicSecAcl, "getPeriods", "(I)Ljava/lang/String;");
-    if (!g_mid_OcOicSecAcl_get_periods) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(g_mid_OcOicSecAcl_get_periods);
 
     g_mid_OcOicSecAcl_get_recurrences = env->GetMethodID(g_cls_OcOicSecAcl, "getRecurrences", "(I)Ljava/lang/String;");
-    if (!g_mid_OcOicSecAcl_get_recurrences) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(g_mid_OcOicSecAcl_get_recurrences);
 
     g_mid_OcOicSecAcl_get_rownerID = env->GetMethodID(g_cls_OcOicSecAcl, "getRownerID", "()Ljava/lang/String;");
-    if (!g_mid_OcOicSecAcl_get_rownerID) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(g_mid_OcOicSecAcl_get_rownerID);
 
     //OicSecPdAcl
     clazz = env->FindClass("org/iotivity/base/OicSecPdAcl");
-    if (!clazz) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(clazz);
     g_cls_OcOicSecPdAcl =  (jclass)env->NewGlobalRef(clazz);
     env->DeleteLocalRef(clazz);
 
     g_mid_OcOicSecPdAcl_get_resources_cnt = env->GetMethodID(g_cls_OcOicSecPdAcl, "getResourcesCount", "()I");
-    if (!g_mid_OcOicSecPdAcl_get_resources_cnt) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(g_mid_OcOicSecPdAcl_get_resources_cnt);
 
     g_mid_OcOicSecPdAcl_get_resources = env->GetMethodID(g_cls_OcOicSecPdAcl, "getResources", "(I)Ljava/lang/String;");
-    if (!g_mid_OcOicSecPdAcl_get_resources) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(g_mid_OcOicSecPdAcl_get_resources);
 
     g_mid_OcOicSecPdAcl_get_permission = env->GetMethodID(g_cls_OcOicSecPdAcl, "getPermission", "()I");
-    if (!g_mid_OcOicSecPdAcl_get_permission) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(g_mid_OcOicSecPdAcl_get_permission);
 
     g_mid_OcOicSecPdAcl_get_periods_cnt = env->GetMethodID(g_cls_OcOicSecPdAcl, "getPeriodsCount", "()I");
-    if (!g_mid_OcOicSecPdAcl_get_periods_cnt) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(g_mid_OcOicSecPdAcl_get_periods_cnt);
 
     g_mid_OcOicSecPdAcl_get_periods = env->GetMethodID(g_cls_OcOicSecPdAcl, "getPeriods", "(I)Ljava/lang/String;");
-    if (!g_mid_OcOicSecPdAcl_get_periods) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(g_mid_OcOicSecPdAcl_get_periods);
 
     g_mid_OcOicSecPdAcl_get_recurrences = env->GetMethodID(g_cls_OcOicSecPdAcl, "getRecurrences", "(I)Ljava/lang/String;");
-    if (!g_mid_OcOicSecPdAcl_get_recurrences) return JNI_ERR;
+    VERIFY_VARIABLE_NULL(g_mid_OcOicSecPdAcl_get_recurrences);
 
     return JNI_CURRENT_VERSION;
 }
@@ -520,6 +533,7 @@ JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved)
         return;
     }
 
+
     env->DeleteGlobalRef(g_cls_Integer);
     env->DeleteGlobalRef(g_cls_int1DArray);
     env->DeleteGlobalRef(g_cls_int2DArray);
index bb2de3d..7f7e851 100644 (file)
@@ -161,26 +161,29 @@ static JNIEnv* GetJNIEnv(jint& ret)
     JNIEnv *env = nullptr;
 
     ret = g_jvm->GetEnv((void **)&env, JNI_CURRENT_VERSION);
-    switch (ret) {
-    case JNI_OK:
-        return env;
-    case JNI_EDETACHED:
-        if (g_jvm->AttachCurrentThread(&env, nullptr) < 0)
-        {
+    switch (ret)
+    {
+        case JNI_OK:
+            return env;
+        case JNI_EDETACHED:
+            if (g_jvm->AttachCurrentThread(&env, nullptr) < 0)
+            {
+                LOGE("Failed to get the environment");
+                return nullptr;
+            }
+            else
+            {
+                return env;
+            }
+
+        case JNI_EVERSION:
+            LOGE("JNI version not supported");
+            break;
+        default:
             LOGE("Failed to get the environment");
             return nullptr;
-        }
-        else
-        {
-            return env;
-        }
-
-    case JNI_EVERSION:
-        LOGE("JNI version not supported");
-    default:
-        LOGE("Failed to get the environment");
-        return nullptr;
     }
+    return nullptr;
 }
 
 static void DuplicateString(char ** targetString, std::string sourceString)
@@ -189,4 +192,4 @@ static void DuplicateString(char ** targetString, std::string sourceString)
     strncpy(*targetString, sourceString.c_str(), (sourceString.length() + 1));
 }
 
-#endif // _Included_org_iotivity_base_ocstack
\ No newline at end of file
+#endif // _Included_org_iotivity_base_ocstack
index 5c5d900..13db923 100644 (file)
@@ -77,12 +77,18 @@ JniOnDPDevicesFoundListener::~JniOnDPDevicesFoundListener()
     LOGI("~JniOnDPDevicesFoundListener()");
     if (m_jwListener)
     {
-        jint ret;
+        jint ret = JNI_ERR;
         JNIEnv *env = GetJNIEnv(ret);
-        if (nullptr == env) return;
+        if (nullptr == env)
+        {
+            return;
+        }
         env->DeleteWeakGlobalRef(m_jwListener);
         m_jwListener = nullptr;
-        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+        if (JNI_EDETACHED == ret)
+        {
+            g_jvm->DetachCurrentThread();
+        }
     }
 }
 
@@ -90,13 +96,19 @@ void JniOnDPDevicesFoundListener::directPairingDevicesCallback(PairedDevices par
 {
     jint ret;
     JNIEnv *env = GetJNIEnv(ret);
-    if (nullptr == env) return;
+    if (nullptr == env)
+    {
+        return;
+    }
 
     jobject jListener = env->NewLocalRef(m_jwListener);
     if (!jListener)
     {
         checkExAndRemoveListener(env);
-        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+        if (JNI_EDETACHED == ret)
+        {
+            g_jvm->DetachCurrentThread();
+        }
         return;
     }
 
@@ -105,7 +117,10 @@ void JniOnDPDevicesFoundListener::directPairingDevicesCallback(PairedDevices par
     if (!clsL)
     {
         checkExAndRemoveListener(env);
-        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+        if (JNI_EDETACHED == ret)
+        {
+            g_jvm->DetachCurrentThread();
+        }
         return;
     }
 
@@ -122,10 +137,14 @@ void JniOnDPDevicesFoundListener::directPairingDevicesCallback(PairedDevices par
             {
                 calledFunc = "onGetDirectPairedListener";
             }
+            break;
         default:
             {
                 checkExAndRemoveListener(env);
-                if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+                if (JNI_EDETACHED == ret)
+                {
+                    g_jvm->DetachCurrentThread();
+                }
             }
             return;
     }
@@ -135,7 +154,10 @@ void JniOnDPDevicesFoundListener::directPairingDevicesCallback(PairedDevices par
     if (!midL)
     {
         checkExAndRemoveListener(env);
-        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+        if (JNI_EDETACHED == ret)
+        {
+            g_jvm->DetachCurrentThread();
+        }
         return;
     }
 
@@ -146,7 +168,10 @@ void JniOnDPDevicesFoundListener::directPairingDevicesCallback(PairedDevices par
     }
 
     checkExAndRemoveListener(env);
-    if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+    if (JNI_EDETACHED == ret)
+    {
+        g_jvm->DetachCurrentThread();
+    }
 }
 
 void JniOnDPDevicesFoundListener::checkExAndRemoveListener(JNIEnv* env)
index 87ebd71..4f95a4c 100644 (file)
@@ -34,35 +34,49 @@ JniOnDeleteListener::~JniOnDeleteListener()
 {
     if (m_jwListener)
     {
-        jint ret;
+        jint ret = JNI_ERR;
         JNIEnv *env = GetJNIEnv(ret);
-        if (nullptr == env) return;
-
+        if (nullptr == env)
+        {
+            return;
+        }
         env->DeleteWeakGlobalRef(m_jwListener);
         m_jwListener = nullptr;
 
-        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+        if (JNI_EDETACHED == ret)
+        {
+            g_jvm->DetachCurrentThread();
+        }
     }
 }
 
 void JniOnDeleteListener::onDeleteCallback(const HeaderOptions& headerOptions, const int eCode)
 {
-    jint envRet;
+    jint envRet = JNI_ERR;
     JNIEnv *env = GetJNIEnv(envRet);
-    if (nullptr == env) return;
+    if (nullptr == env)
+    {
+        return;
+    }
 
     jobject jListener = env->NewLocalRef(m_jwListener);
     if (!jListener)
     {
         checkExAndRemoveListener(env);
-        if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
+        if (JNI_EDETACHED == envRet)
+        {
+            g_jvm->DetachCurrentThread();
+        }
         return;
     }
     jclass clsL = env->GetObjectClass(jListener);
     if (!clsL)
     {
         checkExAndRemoveListener(env);
-        if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
+        if (JNI_EDETACHED == envRet)
+        {
+            g_jvm->DetachCurrentThread();
+        }
         return;
     }
 
@@ -72,14 +86,20 @@ void JniOnDeleteListener::onDeleteCallback(const HeaderOptions& headerOptions, c
         if (!ex)
         {
             checkExAndRemoveListener(env);
-            if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
+            if (JNI_EDETACHED == envRet)
+            {
+                g_jvm->DetachCurrentThread();
+            }
             return;
         }
         jmethodID midL = env->GetMethodID(clsL, "onDeleteFailed", "(Ljava/lang/Throwable;)V");
         if (!midL)
         {
             checkExAndRemoveListener(env);
-            if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
+            if (JNI_EDETACHED == envRet)
+            {
+                g_jvm->DetachCurrentThread();
+            }
             return;
         }
         env->CallVoidMethod(jListener, midL, ex);
@@ -90,7 +110,10 @@ void JniOnDeleteListener::onDeleteCallback(const HeaderOptions& headerOptions, c
         if (!jHeaderOptionList)
         {
             checkExAndRemoveListener(env);
-            if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
+            if (JNI_EDETACHED == envRet)
+            {
+                g_jvm->DetachCurrentThread();
+            }
             return;
         }
 
@@ -98,14 +121,20 @@ void JniOnDeleteListener::onDeleteCallback(const HeaderOptions& headerOptions, c
         if (!midL)
         {
             checkExAndRemoveListener(env);
-            if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
+            if (JNI_EDETACHED == envRet)
+            {
+                g_jvm->DetachCurrentThread();
+            }
             return;
         }
         env->CallVoidMethod(jListener, midL, jHeaderOptionList);
     }
 
     checkExAndRemoveListener(env);
-    if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
+    if (JNI_EDETACHED == envRet)
+    {
+        g_jvm->DetachCurrentThread();
+    }
 }
 
 void JniOnDeleteListener::checkExAndRemoveListener(JNIEnv* env)
@@ -121,4 +150,4 @@ void JniOnDeleteListener::checkExAndRemoveListener(JNIEnv* env)
     {
         m_ownerResource->removeOnDeleteListener(env, m_jwListener);
     }
-}
\ No newline at end of file
+}
index 28d8e44..520cdfd 100644 (file)
@@ -34,29 +34,41 @@ JniOnDeviceInfoListener::~JniOnDeviceInfoListener()
     LOGI("~JniOnDeviceInfoListener");
     if (m_jwListener)
     {
-        jint ret;
+        jint ret = JNI_ERR;
         JNIEnv *env = GetJNIEnv(ret);
-        if (nullptr == env) return;
+        if (nullptr == env)
+        {
+            return;
+        }
 
         env->DeleteWeakGlobalRef(m_jwListener);
         m_jwListener = nullptr;
 
-        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+        if (JNI_EDETACHED == ret)
+        {
+            g_jvm->DetachCurrentThread();
+        }
     }
 }
 
 void JniOnDeviceInfoListener::foundDeviceCallback(const OC::OCRepresentation& ocRepresentation)
 {
-    jint ret;
+    jint ret = JNI_ERR;
     JNIEnv *env = GetJNIEnv(ret);
-    if (nullptr == env) return;
+    if (nullptr == env)
+    {
+        return;
+    }
 
     jobject jListener = env->NewLocalRef(m_jwListener);
     if (!jListener)
     {
         LOGI("Java onDeviceInfoListener object is already destroyed, quiting");
         checkExAndRemoveListener(env);
-        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+        if (JNI_EDETACHED == ret)
+        {
+            g_jvm->DetachCurrentThread();
+        }
         return;
     }
 
@@ -68,7 +80,10 @@ void JniOnDeviceInfoListener::foundDeviceCallback(const OC::OCRepresentation& oc
     {
         delete rep;
         checkExAndRemoveListener(env);
-        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+        if (JNI_EDETACHED == ret)
+        {
+            g_jvm->DetachCurrentThread();
+        }
         return;
     }
 
@@ -77,7 +92,10 @@ void JniOnDeviceInfoListener::foundDeviceCallback(const OC::OCRepresentation& oc
     {
         delete rep;
         checkExAndRemoveListener(env);
-        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+        if (JNI_EDETACHED == ret)
+        {
+            g_jvm->DetachCurrentThread();
+        }
         return;
     }
     jmethodID midL = env->GetMethodID(clsL, "onDeviceFound", "(Lorg/iotivity/base/OcRepresentation;)V");
@@ -85,7 +103,10 @@ void JniOnDeviceInfoListener::foundDeviceCallback(const OC::OCRepresentation& oc
     {
         delete rep;
         checkExAndRemoveListener(env);
-        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+        if (JNI_EDETACHED == ret)
+        {
+            g_jvm->DetachCurrentThread();
+        }
         return;
     }
 
@@ -97,7 +118,10 @@ void JniOnDeviceInfoListener::foundDeviceCallback(const OC::OCRepresentation& oc
         checkExAndRemoveListener(env);
     }
 
-    if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+    if (JNI_EDETACHED == ret)
+    {
+        g_jvm->DetachCurrentThread();
+    }
 }
 
 void JniOnDeviceInfoListener::checkExAndRemoveListener(JNIEnv* env)
@@ -113,4 +137,4 @@ void JniOnDeviceInfoListener::checkExAndRemoveListener(JNIEnv* env)
     {
         m_removeListenerCallback(env, m_jwListener);
     }
-}
\ No newline at end of file
+}
index f580079..085c2b9 100644 (file)
@@ -38,56 +38,79 @@ JniOnDirectPairingListener::~JniOnDirectPairingListener()
     LOGI("~JniOnDirectPairingListener()");
     if (m_jwListener)
     {
-        jint ret;
+        jint ret = JNI_ERR;
         JNIEnv *env = GetJNIEnv(ret);
-        if (nullptr == env) return;
+        if (nullptr == env)
+        {
+            return;
+        }
         env->DeleteWeakGlobalRef(m_jwListener);
         m_jwListener = nullptr;
-        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+        if (JNI_EDETACHED == ret)
+        {
+            g_jvm->DetachCurrentThread();
+        }
     }
 }
 
 void JniOnDirectPairingListener::doDirectPairingCB(std::shared_ptr<OC::OCDirectPairing> dpDev,
                                                                     OCStackResult result)
 {
-    jint ret;
+    jint ret = JNI_ERR;
     JNIEnv *env = GetJNIEnv(ret);
-    if (nullptr == env) return;
+    if (nullptr == env)
+    {
+        return;
+    }
 
     jobject jListener = env->NewLocalRef(m_jwListener);
     if (!jListener)
     {
         checkExAndRemoveListener(env);
-        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+        if (JNI_EDETACHED == ret)
+        {
+            g_jvm->DetachCurrentThread();
+        }
         return;
     }
 
     jclass clsL = env->GetObjectClass(jListener);
-
     if (!clsL)
     {
         checkExAndRemoveListener(env);
-        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+        if (JNI_EDETACHED == ret)
+        {
+            g_jvm->DetachCurrentThread();
+        }
         return;
     }
 
     JniOcDirectPairDevice *device = new JniOcDirectPairDevice(dpDev);
-    if (!device) return;
+    if (!device)
+    {
+        return;
+    }
 
     jstring jStr = env->NewStringUTF((dpDev->getDeviceID()).c_str());
     if (!jStr)
     {
         checkExAndRemoveListener(env);
-        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
-        return ;
+        if (JNI_EDETACHED == ret)
+        {
+            g_jvm->DetachCurrentThread();
+        }
+        return;
     }
 
     jobject jresult = env->NewObject(g_cls_OcDirectPairDevice, g_mid_OcDirectPairDevice_ctor);
     if (!jresult)
     {
         checkExAndRemoveListener(env);
-        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
-        return ;
+        if (JNI_EDETACHED == ret)
+        {
+            g_jvm->DetachCurrentThread();
+        }
+        return;
     }
 
     SetHandle<JniOcDirectPairDevice>(env, jresult, device);
@@ -99,7 +122,10 @@ void JniOnDirectPairingListener::doDirectPairingCB(std::shared_ptr<OC::OCDirectP
     if (!midL)
     {
         checkExAndRemoveListener(env);
-        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+        if (JNI_EDETACHED == ret)
+        {
+            g_jvm->DetachCurrentThread();
+        }
         return;
     }
 
@@ -110,7 +136,11 @@ void JniOnDirectPairingListener::doDirectPairingCB(std::shared_ptr<OC::OCDirectP
     }
 
     checkExAndRemoveListener(env);
-    if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+
+    if (JNI_EDETACHED == ret)
+    {
+        g_jvm->DetachCurrentThread();
+    }
 }
 
 void JniOnDirectPairingListener::checkExAndRemoveListener(JNIEnv* env)
index 2bc8624..1a46903 100644 (file)
@@ -35,29 +35,41 @@ JniOnGetListener::~JniOnGetListener()
     LOGD("~JniOnGetListener");
     if (m_jwListener)
     {
-        jint ret;
+        jint ret = JNI_ERR;
         JNIEnv *env = GetJNIEnv(ret);
-        if (nullptr == env) return;
+        if (nullptr == env)
+        {
+            return;
+        }
 
         env->DeleteWeakGlobalRef(m_jwListener);
         m_jwListener = nullptr;
 
-        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+        if (JNI_EDETACHED == ret)
+        {
+            g_jvm->DetachCurrentThread();
+        }
     }
 }
 
 void JniOnGetListener::onGetCallback(const HeaderOptions& headerOptions,
     const OCRepresentation& ocRepresentation, const int eCode)
 {
-    jint envRet;
+    jint envRet = JNI_ERR;
     JNIEnv *env = GetJNIEnv(envRet);
-    if (nullptr == env) return;
+    if (nullptr == env)
+    {
+        return;
+    }
 
     jobject jListener = env->NewLocalRef(m_jwListener);
     if (!jListener)
     {
         checkExAndRemoveListener(env);
-        if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
+        if (JNI_EDETACHED == envRet)
+        {
+            g_jvm->DetachCurrentThread();
+        }
         return;
     }
     jclass clsL = env->GetObjectClass(jListener);
@@ -65,7 +77,10 @@ void JniOnGetListener::onGetCallback(const HeaderOptions& headerOptions,
     if (!clsL)
     {
         checkExAndRemoveListener(env);
-        if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
+        if (JNI_EDETACHED == envRet)
+        {
+            g_jvm->DetachCurrentThread();
+        }
         return;
     }
 
@@ -75,14 +90,20 @@ void JniOnGetListener::onGetCallback(const HeaderOptions& headerOptions,
         if (!ex)
         {
             checkExAndRemoveListener(env);
-            if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
+            if (JNI_EDETACHED == envRet)
+            {
+                g_jvm->DetachCurrentThread();
+            }
             return;
         }
         jmethodID midL = env->GetMethodID(clsL, "onGetFailed", "(Ljava/lang/Throwable;)V");
         if (!midL)
         {
             checkExAndRemoveListener(env);
-            if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
+            if (JNI_EDETACHED == envRet)
+            {
+                g_jvm->DetachCurrentThread();
+            }
             return;
         }
         env->CallVoidMethod(jListener, midL, ex);
@@ -93,7 +114,10 @@ void JniOnGetListener::onGetCallback(const HeaderOptions& headerOptions,
         if (!jHeaderOptionList)
         {
             checkExAndRemoveListener(env);
-            if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
+            if (JNI_EDETACHED == envRet)
+            {
+                g_jvm->DetachCurrentThread();
+            }
             return;
         }
 
@@ -105,7 +129,10 @@ void JniOnGetListener::onGetCallback(const HeaderOptions& headerOptions,
         {
             delete rep;
             checkExAndRemoveListener(env);
-            if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
+            if (JNI_EDETACHED == envRet)
+            {
+                g_jvm->DetachCurrentThread();
+            }
             return;
         }
 
@@ -115,7 +142,10 @@ void JniOnGetListener::onGetCallback(const HeaderOptions& headerOptions,
         {
             delete rep;
             checkExAndRemoveListener(env);
-            if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
+            if (JNI_EDETACHED == envRet)
+            {
+                g_jvm->DetachCurrentThread();
+            }
             return;
         }
         env->CallVoidMethod(jListener, midL, jHeaderOptionList, jRepresentation);
@@ -127,7 +157,10 @@ void JniOnGetListener::onGetCallback(const HeaderOptions& headerOptions,
     }
 
     checkExAndRemoveListener(env);
-    if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
+    if (JNI_EDETACHED == envRet)
+    {
+        g_jvm->DetachCurrentThread();
+    }
 }
 
 void JniOnGetListener::checkExAndRemoveListener(JNIEnv* env)
@@ -143,4 +176,4 @@ void JniOnGetListener::checkExAndRemoveListener(JNIEnv* env)
     {
         m_ownerResource->removeOnGetListener(env, m_jwListener);
     }
-}
\ No newline at end of file
+}
index 3ad1d11..03d92f0 100644 (file)
@@ -34,36 +34,51 @@ JniOnObserveListener::~JniOnObserveListener()
 {
     if (m_jwListener)
     {
-        jint ret;
+        jint ret = JNI_ERR;
         JNIEnv *env = GetJNIEnv(ret);
-        if (nullptr == env) return;
+        if (nullptr == env)
+        {
+            return;
+        }
 
         env->DeleteWeakGlobalRef(m_jwListener);
         m_jwListener = nullptr;
 
-        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+        if (JNI_EDETACHED == ret)
+        {
+            g_jvm->DetachCurrentThread();
+        }
     }
 }
 
 void JniOnObserveListener::onObserveCallback(const HeaderOptions headerOptions,
     const OCRepresentation& ocRepresentation, const int& eCode, const int& sequenceNumber)
 {
-    jint envRet;
+    jint envRet = JNI_ERR;
     JNIEnv *env = GetJNIEnv(envRet);
-    if (nullptr == env) return;
+    if (nullptr == env)
+    {
+        return;
+    }
 
     jobject jListener = env->NewLocalRef(m_jwListener);
     if (!jListener)
     {
         checkExAndRemoveListener(env);
-        if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
+        if (JNI_EDETACHED == envRet)
+        {
+            g_jvm->DetachCurrentThread();
+        }
         return;
     }
     jclass clsL = env->GetObjectClass(jListener);
     if (!clsL)
     {
         checkExAndRemoveListener(env);
-        if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
+        if (JNI_EDETACHED == envRet)
+        {
+            g_jvm->DetachCurrentThread();
+        }
         return;
     }
 
@@ -73,14 +88,20 @@ void JniOnObserveListener::onObserveCallback(const HeaderOptions headerOptions,
         if (!ex)
         {
             checkExAndRemoveListener(env);
-            if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
+            if (JNI_EDETACHED == envRet)
+            {
+                g_jvm->DetachCurrentThread();
+            }
             return;
         }
         jmethodID midL = env->GetMethodID(clsL, "onObserveFailed", "(Ljava/lang/Throwable;)V");
         if (!midL)
         {
             checkExAndRemoveListener(env);
-            if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
+            if (JNI_EDETACHED == envRet)
+            {
+                g_jvm->DetachCurrentThread();
+            }
             return;
         }
         env->CallVoidMethod(jListener, midL, ex);
@@ -91,7 +112,10 @@ void JniOnObserveListener::onObserveCallback(const HeaderOptions headerOptions,
         if (!jHeaderOptionList)
         {
             checkExAndRemoveListener(env);
-            if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
+            if (JNI_EDETACHED == envRet)
+            {
+                g_jvm->DetachCurrentThread();
+            }
             return;
         }
 
@@ -103,7 +127,10 @@ void JniOnObserveListener::onObserveCallback(const HeaderOptions headerOptions,
         {
             delete rep;
             checkExAndRemoveListener(env);
-            if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
+            if (JNI_EDETACHED == envRet)
+            {
+                g_jvm->DetachCurrentThread();
+            }
             return;
         }
 
@@ -112,7 +139,10 @@ void JniOnObserveListener::onObserveCallback(const HeaderOptions headerOptions,
         if (!midL)
         {
             checkExAndRemoveListener(env);
-            if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
+            if (JNI_EDETACHED == envRet)
+            {
+                g_jvm->DetachCurrentThread();
+            }
             return;
         }
 
@@ -134,7 +164,10 @@ void JniOnObserveListener::onObserveCallback(const HeaderOptions headerOptions,
         }
     }
 
-    if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
+    if (JNI_EDETACHED == envRet)
+    {
+        g_jvm->DetachCurrentThread();
+    }
 }
 
 void JniOnObserveListener::checkExAndRemoveListener(JNIEnv* env)
@@ -150,4 +183,4 @@ void JniOnObserveListener::checkExAndRemoveListener(JNIEnv* env)
     {
         m_ownerResource->removeOnObserveListener(env, m_jwListener);
     }
-}
\ No newline at end of file
+}
index 03e2ed8..7a220bf 100644 (file)
@@ -34,29 +34,41 @@ JniOnPlatformInfoListener::~JniOnPlatformInfoListener()
     LOGI("~JniOnPlatformInfoListener");
     if (m_jwListener)
     {
-        jint ret;
+        jint ret = JNI_ERR;
         JNIEnv *env = GetJNIEnv(ret);
-        if (nullptr == env) return;
+        if (nullptr == env)
+        {
+            return;
+        }
 
         env->DeleteWeakGlobalRef(m_jwListener);
         m_jwListener = nullptr;
 
-        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+        if (JNI_EDETACHED == ret)
+        {
+            g_jvm->DetachCurrentThread();
+        }
     }
 }
 
 void JniOnPlatformInfoListener::foundPlatformCallback(const OC::OCRepresentation& ocRepresentation)
 {
-    jint ret;
+    jint ret = JNI_ERR;
     JNIEnv *env = GetJNIEnv(ret);
-    if (nullptr == env) return;
+    if (nullptr == env)
+    {
+        return;
+    }
 
     jobject jListener = env->NewLocalRef(m_jwListener);
     if (!jListener)
     {
         LOGI("Java onPlatformInfoListener object is already destroyed, quiting");
         checkExAndRemoveListener(env);
-        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+        if (JNI_EDETACHED == ret)
+        {
+            g_jvm->DetachCurrentThread();
+        }
         return;
     }
 
@@ -68,7 +80,10 @@ void JniOnPlatformInfoListener::foundPlatformCallback(const OC::OCRepresentation
     {
         delete rep;
         checkExAndRemoveListener(env);
-        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+        if (JNI_EDETACHED == ret)
+        {
+            g_jvm->DetachCurrentThread();
+        }
         return;
     }
 
@@ -77,7 +92,10 @@ void JniOnPlatformInfoListener::foundPlatformCallback(const OC::OCRepresentation
     {
         delete rep;
         checkExAndRemoveListener(env);
-        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+        if (JNI_EDETACHED == ret)
+        {
+            g_jvm->DetachCurrentThread();
+        }
         return;
     }
     jmethodID midL = env->GetMethodID(clsL, "onPlatformFound", "(Lorg/iotivity/base/OcRepresentation;)V");
@@ -85,7 +103,10 @@ void JniOnPlatformInfoListener::foundPlatformCallback(const OC::OCRepresentation
     {
         delete rep;
         checkExAndRemoveListener(env);
-        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+        if (JNI_EDETACHED == ret)
+        {
+            g_jvm->DetachCurrentThread();
+        }
         return;
     }
 
@@ -97,7 +118,10 @@ void JniOnPlatformInfoListener::foundPlatformCallback(const OC::OCRepresentation
         checkExAndRemoveListener(env);
     }
 
-    if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+    if (JNI_EDETACHED == ret)
+    {
+        g_jvm->DetachCurrentThread();
+    }
 }
 
 void JniOnPlatformInfoListener::checkExAndRemoveListener(JNIEnv* env)
index 575748e..6a9bb06 100644 (file)
@@ -34,36 +34,51 @@ JniOnPostListener::~JniOnPostListener()
 {
     if (m_jwListener)
     {
-        jint ret;
+        jint ret = JNI_ERR;
         JNIEnv *env = GetJNIEnv(ret);
-        if (nullptr == env) return;
+        if (nullptr == env)
+        {
+            return;
+        }
 
         env->DeleteWeakGlobalRef(m_jwListener);
         m_jwListener = nullptr;
 
-        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+        if (JNI_EDETACHED == ret)
+        {
+            g_jvm->DetachCurrentThread();
+        }
     }
 }
 
 void JniOnPostListener::onPostCallback(const HeaderOptions& headerOptions,
     const OCRepresentation& ocRepresentation, const int eCode)
 {
-    jint envRet;
+    jint envRet = JNI_ERR;
     JNIEnv *env = GetJNIEnv(envRet);
-    if (nullptr == env) return;
+    if (nullptr == env)
+    {
+        return;
+    }
 
     jobject jListener = env->NewLocalRef(m_jwListener);
     if (!jListener)
     {
         checkExAndRemoveListener(env);
-        if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
+        if (JNI_EDETACHED == envRet)
+        {
+            g_jvm->DetachCurrentThread();
+        }
         return;
     }
     jclass clsL = env->GetObjectClass(jListener);
     if (!clsL)
     {
         checkExAndRemoveListener(env);
-        if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
+        if (JNI_EDETACHED == envRet)
+        {
+            g_jvm->DetachCurrentThread();
+        }
         return;
     }
 
@@ -73,14 +88,20 @@ void JniOnPostListener::onPostCallback(const HeaderOptions& headerOptions,
         if (!ex)
         {
             checkExAndRemoveListener(env);
-            if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
+            if (JNI_EDETACHED == envRet)
+            {
+                g_jvm->DetachCurrentThread();
+            }
             return;
         }
         jmethodID midL = env->GetMethodID(clsL, "onPostFailed", "(Ljava/lang/Throwable;)V");
         if (!midL)
         {
             checkExAndRemoveListener(env);
-            if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
+            if (JNI_EDETACHED == envRet)
+            {
+                g_jvm->DetachCurrentThread();
+            }
             return;
         }
         env->CallVoidMethod(jListener, midL, ex);
@@ -91,7 +112,10 @@ void JniOnPostListener::onPostCallback(const HeaderOptions& headerOptions,
         if (!jHeaderOptionList)
         {
             checkExAndRemoveListener(env);
-            if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
+            if (JNI_EDETACHED == envRet)
+            {
+                g_jvm->DetachCurrentThread();
+            }
             return;
         }
 
@@ -103,7 +127,10 @@ void JniOnPostListener::onPostCallback(const HeaderOptions& headerOptions,
         {
             delete rep;
             checkExAndRemoveListener(env);
-            if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
+            if (JNI_EDETACHED == envRet)
+            {
+                g_jvm->DetachCurrentThread();
+            }
             return;
         }
 
@@ -112,7 +139,10 @@ void JniOnPostListener::onPostCallback(const HeaderOptions& headerOptions,
         if (!midL)
         {
             checkExAndRemoveListener(env);
-            if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
+            if (JNI_EDETACHED == envRet)
+            {
+                g_jvm->DetachCurrentThread();
+            }
             return;
         }
 
@@ -125,7 +155,10 @@ void JniOnPostListener::onPostCallback(const HeaderOptions& headerOptions,
     }
 
     checkExAndRemoveListener(env);
-    if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
+    if (JNI_EDETACHED == envRet)
+    {
+        g_jvm->DetachCurrentThread();
+    }
 }
 
 void JniOnPostListener::checkExAndRemoveListener(JNIEnv* env)
@@ -141,4 +174,4 @@ void JniOnPostListener::checkExAndRemoveListener(JNIEnv* env)
     {
         m_ownerResource->removeOnPostListener(env, m_jwListener);
     }
-}
\ No newline at end of file
+}
index 023c61d..9223250 100644 (file)
@@ -34,14 +34,20 @@ JniOnPresenceListener::~JniOnPresenceListener()
     LOGD("~JniOnPresenceListener");
     if (m_jwListener)
     {
-        jint ret;
+        jint ret = JNI_ERR;
         JNIEnv *env = GetJNIEnv(ret);
-        if (nullptr == env) return;
+        if (nullptr == env)
+        {
+            return;
+        }
 
         env->DeleteWeakGlobalRef(m_jwListener);
         m_jwListener = nullptr;
 
-        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+        if (JNI_EDETACHED == ret)
+        {
+            g_jvm->DetachCurrentThread();
+        }
     }
 }
 
@@ -49,17 +55,26 @@ void JniOnPresenceListener::onPresenceCallback(OCStackResult result, const unsig
     const std::string& hostAddress)
 {
     LOGI("JniOnPresenceListener::onPresenceCallback");
-    if (!m_jwListener) return;
+    if (!m_jwListener)
+    {
+        return;
+    }
 
-    jint ret;
+    jint ret = JNI_ERR;
     JNIEnv *env = GetJNIEnv(ret);
-    if (nullptr == env) return;
+    if (nullptr == env)
+    {
+        return;
+    }
 
     if (OC_STACK_OK != result && OC_STACK_PRESENCE_STOPPED != result &&
         OC_STACK_PRESENCE_TIMEOUT != result &&  OC_STACK_PRESENCE_DO_NOT_HANDLE != result)
     {
         ThrowOcException(result, "onPresenceCallback: stack failure");
-        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+        if (JNI_EDETACHED == ret)
+        {
+            g_jvm->DetachCurrentThread();
+        }
         return;
     }
 
@@ -67,7 +82,10 @@ void JniOnPresenceListener::onPresenceCallback(OCStackResult result, const unsig
     if (enumField.empty())
     {
         ThrowOcException(JNI_INVALID_VALUE, "Unexpected OCStackResult value");
-        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+        if (JNI_EDETACHED == ret)
+        {
+            g_jvm->DetachCurrentThread();
+        }
         return;
     }
 
@@ -76,7 +94,10 @@ void JniOnPresenceListener::onPresenceCallback(OCStackResult result, const unsig
     if (!jPresenceStatus)
     {
         checkExAndRemoveListener(env);
-        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+        if (JNI_EDETACHED == ret)
+        {
+            g_jvm->DetachCurrentThread();
+        }
         return;
     }
 
@@ -84,7 +105,10 @@ void JniOnPresenceListener::onPresenceCallback(OCStackResult result, const unsig
     if (!jListener)
     {
         checkExAndRemoveListener(env);
-        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+        if (JNI_EDETACHED == ret)
+        {
+            g_jvm->DetachCurrentThread();
+        }
         return;
     }
 
@@ -92,7 +116,10 @@ void JniOnPresenceListener::onPresenceCallback(OCStackResult result, const unsig
     if (!clsL)
     {
         checkExAndRemoveListener(env);
-        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+        if (JNI_EDETACHED == ret)
+        {
+            g_jvm->DetachCurrentThread();
+        }
         return;
     }
     jmethodID midL = env->GetMethodID(clsL, "onPresence",
@@ -100,7 +127,10 @@ void JniOnPresenceListener::onPresenceCallback(OCStackResult result, const unsig
     if (!midL)
     {
         checkExAndRemoveListener(env);
-        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+        if (JNI_EDETACHED == ret)
+        {
+            g_jvm->DetachCurrentThread();
+        }
         return;
     }
 
@@ -111,7 +141,11 @@ void JniOnPresenceListener::onPresenceCallback(OCStackResult result, const unsig
         LOGE("Java exception is thrown");
         checkExAndRemoveListener(env);
     }
-    if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+
+    if (JNI_EDETACHED == ret)
+    {
+        g_jvm->DetachCurrentThread();
+    }
 }
 
 void JniOnPresenceListener::checkExAndRemoveListener(JNIEnv* env)
@@ -132,4 +166,4 @@ void JniOnPresenceListener::checkExAndRemoveListener(JNIEnv* env)
 jweak JniOnPresenceListener::getJWListener()
 {
     return this->m_jwListener;
-}
\ No newline at end of file
+}
index 7f375b9..961280a 100644 (file)
@@ -34,36 +34,51 @@ JniOnPutListener::~JniOnPutListener()
 {
     if (m_jwListener)
     {
-        jint ret;
+        jint ret = JNI_ERR;
         JNIEnv *env = GetJNIEnv(ret);
-        if (nullptr == env) return;
+        if (nullptr == env)
+        {
+            return;
+        }
 
         env->DeleteWeakGlobalRef(m_jwListener);
         m_jwListener = nullptr;
 
-        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+        if (JNI_EDETACHED == ret)
+        {
+            g_jvm->DetachCurrentThread();
+        }
     }
 }
 
 void JniOnPutListener::onPutCallback(const HeaderOptions& headerOptions,
     const OCRepresentation& ocRepresentation, const int eCode)
 {
-    jint envRet;
+    jint envRet = JNI_ERR;
     JNIEnv *env = GetJNIEnv(envRet);
-    if (nullptr == env) return;
+    if (nullptr == env)
+    {
+        return;
+    }
 
     jobject jListener = env->NewLocalRef(m_jwListener);
     if (!jListener)
     {
         checkExAndRemoveListener(env);
-        if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
+        if (JNI_EDETACHED == envRet)
+        {
+            g_jvm->DetachCurrentThread();
+        }
         return;
     }
     jclass clsL = env->GetObjectClass(jListener);
     if (!clsL)
     {
         checkExAndRemoveListener(env);
-        if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
+        if (JNI_EDETACHED == envRet)
+        {
+            g_jvm->DetachCurrentThread();
+        }
         return;
     }
 
@@ -73,14 +88,20 @@ void JniOnPutListener::onPutCallback(const HeaderOptions& headerOptions,
         if (!ex)
         {
             checkExAndRemoveListener(env);
-            if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
+            if (JNI_EDETACHED == envRet)
+            {
+                g_jvm->DetachCurrentThread();
+            }
             return;
         }
         jmethodID midL = env->GetMethodID(clsL, "onPutFailed", "(Ljava/lang/Throwable;)V");
         if (!midL)
         {
             checkExAndRemoveListener(env);
-            if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
+            if (JNI_EDETACHED == envRet)
+            {
+                g_jvm->DetachCurrentThread();
+            }
             return;
         }
         env->CallVoidMethod(jListener, midL, ex);
@@ -91,7 +112,10 @@ void JniOnPutListener::onPutCallback(const HeaderOptions& headerOptions,
         if (!jHeaderOptionList)
         {
             checkExAndRemoveListener(env);
-            if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
+            if (JNI_EDETACHED == envRet)
+            {
+                g_jvm->DetachCurrentThread();
+            }
             return;
         }
 
@@ -103,7 +127,10 @@ void JniOnPutListener::onPutCallback(const HeaderOptions& headerOptions,
         {
             delete rep;
             checkExAndRemoveListener(env);
-            if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
+            if (JNI_EDETACHED == envRet)
+            {
+                g_jvm->DetachCurrentThread();
+            }
             return;
         }
 
@@ -113,7 +140,10 @@ void JniOnPutListener::onPutCallback(const HeaderOptions& headerOptions,
         if (!midL)
         {
             checkExAndRemoveListener(env);
-            if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
+            if (JNI_EDETACHED == envRet)
+            {
+                g_jvm->DetachCurrentThread();
+            }
             return;
         }
 
@@ -126,7 +156,10 @@ void JniOnPutListener::onPutCallback(const HeaderOptions& headerOptions,
     }
 
     checkExAndRemoveListener(env);
-    if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
+    if (JNI_EDETACHED == envRet)
+    {
+        g_jvm->DetachCurrentThread();
+    }
 }
 
 void JniOnPutListener::checkExAndRemoveListener(JNIEnv* env)
@@ -142,4 +175,4 @@ void JniOnPutListener::checkExAndRemoveListener(JNIEnv* env)
     {
         m_ownerResource->removeOnPutListener(env, m_jwListener);
     }
-}
\ No newline at end of file
+}
index cdc68d3..270b3f8 100644 (file)
@@ -34,35 +34,48 @@ JniOnResourceFoundListener::~JniOnResourceFoundListener()
     LOGI("~JniOnResourceFoundListener()");
     if (m_jwListener)
     {
-        jint ret;
+        jint ret = JNI_ERR;
         JNIEnv *env = GetJNIEnv(ret);
-        if (nullptr == env) return;
+        if (nullptr == env)
+        {
+            return;
+        }
         env->DeleteWeakGlobalRef(m_jwListener);
         m_jwListener = nullptr;
-        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+        if (JNI_EDETACHED == ret)
+        {
+            g_jvm->DetachCurrentThread();
+        }
     }
 }
 
 void JniOnResourceFoundListener::foundResourceCallback(std::shared_ptr<OC::OCResource> resource)
 {
-    jint ret;
+    jint ret = JNI_ERR;
     JNIEnv *env = GetJNIEnv(ret);
-    if (nullptr == env) return;
+    if (nullptr == env)
+    {
+        return;
+    }
 
     jobject jListener = env->NewLocalRef(m_jwListener);
     if (!jListener)
     {
         checkExAndRemoveListener(env);
-        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
-        return;
+        if (JNI_EDETACHED == ret)
+        {
+            g_jvm->DetachCurrentThread();
+        }
     }
 
     jobject jResource = env->NewObject(g_cls_OcResource, g_mid_OcResource_ctor);
     if (!jResource)
     {
         checkExAndRemoveListener(env);
-        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
-        return;
+        if (JNI_EDETACHED == ret)
+        {
+            g_jvm->DetachCurrentThread();
+        }
     }
 
     JniOcResource *jniOcResource = new JniOcResource(resource);
@@ -71,24 +84,30 @@ void JniOnResourceFoundListener::foundResourceCallback(std::shared_ptr<OC::OCRes
     {
         delete jniOcResource;
         checkExAndRemoveListener(env);
-        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
-        return;
+        if (JNI_EDETACHED == ret)
+        {
+            g_jvm->DetachCurrentThread();
+        }
     }
     jclass clsL = env->GetObjectClass(jListener);
     if (!clsL)
     {
         delete jniOcResource;
         checkExAndRemoveListener(env);
-        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
-        return;
+        if (JNI_EDETACHED == ret)
+        {
+            g_jvm->DetachCurrentThread();
+        }
     }
     jmethodID midL = env->GetMethodID(clsL, "onResourceFound", "(Lorg/iotivity/base/OcResource;)V");
     if (!midL)
     {
         delete jniOcResource;
         checkExAndRemoveListener(env);
-        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
-        return;
+        if (JNI_EDETACHED == ret)
+        {
+            g_jvm->DetachCurrentThread();
+        }
     }
     env->CallVoidMethod(jListener, midL, jResource);
     if (env->ExceptionCheck())
@@ -96,11 +115,16 @@ void JniOnResourceFoundListener::foundResourceCallback(std::shared_ptr<OC::OCRes
         LOGE("Java exception is thrown");
         delete jniOcResource;
         checkExAndRemoveListener(env);
-        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
-        return;
+        if (JNI_EDETACHED == ret)
+        {
+            g_jvm->DetachCurrentThread();
+        }
     }
 
-    if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+    if (JNI_EDETACHED == ret)
+    {
+        g_jvm->DetachCurrentThread();
+    }
 }
 
 void JniOnResourceFoundListener::checkExAndRemoveListener(JNIEnv* env)
@@ -116,4 +140,4 @@ void JniOnResourceFoundListener::checkExAndRemoveListener(JNIEnv* env)
     {
         m_removeListenerCallback(env, m_jwListener);
     }
-}
\ No newline at end of file
+}
index 55cdfba..12377d1 100644 (file)
@@ -32,40 +32,57 @@ JniPinCheckListener::~JniPinCheckListener()
     LOGI("~JniPinCheckListener()");
     if (m_jListener)
     {
-        jint ret;
+        jint ret = JNI_ERR;
         JNIEnv *env = GetJNIEnv(ret);
-        if (NULL == env) return;
+        if (nullptr == env)
+        {
+            return;
+        }
         env->DeleteGlobalRef(m_jListener);
-        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+        if (JNI_EDETACHED == ret)
+        {
+            g_jvm->DetachCurrentThread();
+        }
     }
 }
 
 void JniPinCheckListener::PinCallback(char *pinBuf, size_t bufSize)
 {
-    jint ret;
-
+    jint ret = JNI_ERR;
     JNIEnv *env = GetJNIEnv(ret);
-    if (NULL == env) return;
+    if (nullptr == env)
+    {
+        return;
+    }
 
     jclass clsL = env->GetObjectClass(m_jListener);
 
     if (!clsL)
     {
-        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+        if (JNI_EDETACHED == ret)
+        {
+            g_jvm->DetachCurrentThread();
+        }
         return;
     }
 
     jmethodID midL = env->GetMethodID(clsL, "pinCallbackListener", "()Ljava/lang/String;");
     if (!midL)
     {
-        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+        if (JNI_EDETACHED == ret)
+        {
+            g_jvm->DetachCurrentThread();
+        }
         return;
     }
     jstring jpin = (jstring)env->CallObjectMethod(m_jListener, midL);
     if (env->ExceptionCheck())
     {
         LOGE("Java exception is thrown");
-        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+        if (JNI_EDETACHED == ret)
+        {
+            g_jvm->DetachCurrentThread();
+        }
         return;
     }
 
@@ -73,5 +90,8 @@ void JniPinCheckListener::PinCallback(char *pinBuf, size_t bufSize)
     OICStrcpy(pinBuf, bufSize, str);
     env->ReleaseStringUTFChars(jpin, str);
 
-    if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+    if (JNI_EDETACHED == ret)
+    {
+        g_jvm->DetachCurrentThread();
+    }
 }
index a600e64..066a677 100644 (file)
@@ -35,26 +35,38 @@ JniProvisionResultListner::~JniProvisionResultListner()
     LOGI("~JniProvisionResultListner()");
     if (m_jwListener)
     {
-        jint ret;
+        jint ret = JNI_ERR;
         JNIEnv *env = GetJNIEnv(ret);
-        if (NULL == env) return;
+        if (nullptr == env)
+        {
+            return;
+        }
         env->DeleteWeakGlobalRef(m_jwListener);
-        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+        if (JNI_EDETACHED == ret)
+        {
+            g_jvm->DetachCurrentThread();
+        }
     }
 }
 
 void JniProvisionResultListner::ProvisionResultCallback(PMResultList_t *result, int hasError,
       ListenerFunc func)
 {
-    jint ret;
+    jint ret = JNI_ERR;
     JNIEnv *env = GetJNIEnv(ret);
-    if (NULL == env) return;
+    if (nullptr == env)
+    {
+        return;
+    }
 
     jobject jListener = env->NewLocalRef(m_jwListener);
     if (!jListener)
     {
         checkExAndRemoveListener(env);
-        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+        if (JNI_EDETACHED == ret)
+        {
+            g_jvm->DetachCurrentThread();
+        }
         return;
     }
 
@@ -63,7 +75,10 @@ void JniProvisionResultListner::ProvisionResultCallback(PMResultList_t *result,
     if (!clsL)
     {
         checkExAndRemoveListener(env);
-        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+        if (JNI_EDETACHED == ret)
+        {
+            g_jvm->DetachCurrentThread();
+        }
         return;
     }
 
@@ -72,7 +87,10 @@ void JniProvisionResultListner::ProvisionResultCallback(PMResultList_t *result,
     if (!jResultList)
     {
         checkExAndRemoveListener(env);
-        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+        if (JNI_EDETACHED == ret)
+        {
+            g_jvm->DetachCurrentThread();
+        }
         return;
     }
 
@@ -117,7 +135,11 @@ void JniProvisionResultListner::ProvisionResultCallback(PMResultList_t *result,
         default:
         {
             checkExAndRemoveListener(env);
-            if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+            if (JNI_EDETACHED == ret)
+            {
+                g_jvm->DetachCurrentThread();
+            }
+            return;
         }
         return;
     }
@@ -126,7 +148,10 @@ void JniProvisionResultListner::ProvisionResultCallback(PMResultList_t *result,
     if (!midL)
     {
         checkExAndRemoveListener(env);
-        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+        if (JNI_EDETACHED == ret)
+        {
+            g_jvm->DetachCurrentThread();
+        }
         return;
     }
     env->CallVoidMethod(jListener, midL, jResultList, (jint)hasError);
@@ -136,7 +161,10 @@ void JniProvisionResultListner::ProvisionResultCallback(PMResultList_t *result,
     }
 
     checkExAndRemoveListener(env);
-    if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+    if (JNI_EDETACHED == ret)
+    {
+        g_jvm->DetachCurrentThread();
+    }
 }
 
 void JniProvisionResultListner::checkExAndRemoveListener(JNIEnv* env)
index 4e3f276..3ee3ada 100644 (file)
 jobject JniUtils::convertStrVectorToJavaStrList(JNIEnv *env, std::vector<std::string> &vector)
 {
     jobject jList = env->NewObject(g_cls_LinkedList, g_mid_LinkedList_ctor);
-    if (!jList) return nullptr;
+    if (!jList)
+    {
+        return nullptr;
+    }
     for (size_t i = 0; i < vector.size(); ++i)
     {
         jstring jStr = env->NewStringUTF(vector[i].c_str());
-        if (!jStr) return nullptr;
+        if (!jStr)
+        {
+            return nullptr;
+        }
         env->CallBooleanMethod(jList, g_mid_LinkedList_add_object, jStr);
-        if (env->ExceptionCheck()) return nullptr;
+        if (env->ExceptionCheck())
+        {
+            return nullptr;
+        }
         env->DeleteLocalRef(jStr);
     }
     return jList;
@@ -40,15 +49,24 @@ jobject JniUtils::convertStrVectorToJavaStrList(JNIEnv *env, std::vector<std::st
 
 void JniUtils::convertJavaStrArrToStrVector(JNIEnv *env, jobjectArray jStrArr, std::vector<std::string> &vector)
 {
-    if (!jStrArr) return;
+    if (!jStrArr)
+    {
+        return;
+    }
 
     jsize len = env->GetArrayLength(jStrArr);
     for (jsize i = 0; i < len; ++i)
     {
         jstring jStr = (jstring)env->GetObjectArrayElement(jStrArr, i);
-        if (!jStr) return;
+        if (!jStr)
+        {
+            return;
+        }
         vector.push_back(env->GetStringUTFChars(jStr, nullptr));
-        if (env->ExceptionCheck()) return;
+        if (env->ExceptionCheck())
+        {
+            return;
+        }
         env->DeleteLocalRef(jStr);
     }
 }
@@ -56,12 +74,19 @@ void JniUtils::convertJavaStrArrToStrVector(JNIEnv *env, jobjectArray jStrArr, s
 void JniUtils::convertJavaHeaderOptionsArrToVector(JNIEnv *env, jobjectArray jHeaderOptions,
     OC::HeaderOptions &headerOptions)
 {
-    if (!jHeaderOptions) return;
+    if (!jHeaderOptions)
+    {
+        return;
+    }
+
     jsize len = env->GetArrayLength(jHeaderOptions);
     for (jsize i = 0; i < len; ++i)
     {
         jobject header = env->GetObjectArrayElement(jHeaderOptions, i);
-        if (!header) return;
+        if (!header)
+        {
+            return;
+        }
         jint jId = env->CallIntMethod(header, g_mid_OcHeaderOption_get_id);
         jstring jData = (jstring)env->CallObjectMethod(header, g_mid_OcHeaderOption_get_data);
         OC::HeaderOption::OCHeaderOption hopt(
@@ -70,7 +95,10 @@ void JniUtils::convertJavaHeaderOptionsArrToVector(JNIEnv *env, jobjectArray jHe
 
         headerOptions.push_back(hopt);
 
-        if (env->ExceptionCheck()) return;
+        if (env->ExceptionCheck())
+        {
+            return;
+        }
         env->DeleteLocalRef(header);
         env->DeleteLocalRef(jData);
     }
@@ -79,7 +107,10 @@ void JniUtils::convertJavaHeaderOptionsArrToVector(JNIEnv *env, jobjectArray jHe
 jobject JniUtils::convertHeaderOptionsVectorToJavaList(JNIEnv *env, const OC::HeaderOptions& headerOptions)
 {
     jobject jHeaderOptionList = env->NewObject(g_cls_LinkedList, g_mid_LinkedList_ctor);
-    if (!jHeaderOptionList) return nullptr;
+    if (!jHeaderOptionList)
+    {
+        return nullptr;
+    }
 
     for (size_t i = 0; i < headerOptions.size(); ++i)
     {
@@ -89,10 +120,16 @@ jobject JniUtils::convertHeaderOptionsVectorToJavaList(JNIEnv *env, const OC::He
             static_cast<jint>(headerOptions[i].getOptionID()),
             env->NewStringUTF(headerOptions[i].getOptionData().c_str())
             );
-        if (!jHeaderOption) return nullptr;
+        if (!jHeaderOption)
+        {
+            return nullptr;
+        }
 
         env->CallBooleanMethod(jHeaderOptionList, g_mid_LinkedList_add_object, jHeaderOption);
-        if (env->ExceptionCheck()) return nullptr;
+        if (env->ExceptionCheck())
+        {
+            return nullptr;
+        }
         env->DeleteLocalRef(jHeaderOption);
     }
 
@@ -101,25 +138,43 @@ jobject JniUtils::convertHeaderOptionsVectorToJavaList(JNIEnv *env, const OC::He
 
 void JniUtils::convertJavaMapToQueryParamsMap(JNIEnv *env, jobject hashMap, OC::QueryParamsMap &map)
 {
-    if (!hashMap) return;
+    if (!hashMap)
+    {
+        return;
+    }
 
     jobject jEntrySet = env->CallObjectMethod(hashMap, g_mid_Map_entrySet);
     jobject jIterator = env->CallObjectMethod(jEntrySet, g_mid_Set_iterator);
-    if (!jEntrySet || !jIterator || env->ExceptionCheck()) return;
+    if (!jEntrySet || !jIterator || env->ExceptionCheck())
+    {
+        return;
+    }
 
     while (env->CallBooleanMethod(jIterator, g_mid_Iterator_hasNext))
     {
         jobject jEntry = env->CallObjectMethod(jIterator, g_mid_Iterator_next);
-        if (!jEntry) return;
+        if (!jEntry)
+        {
+            return;
+        }
         jstring jKey = (jstring)env->CallObjectMethod(jEntry, g_mid_MapEntry_getKey);
-        if (!jKey) return;
+        if (!jKey)
+        {
+            return;
+        }
         jstring jValue = (jstring)env->CallObjectMethod(jEntry, g_mid_MapEntry_getValue);
-        if (!jValue) return;
+        if (!jValue)
+        {
+            return;
+        }
 
         map.insert(std::make_pair(env->GetStringUTFChars(jKey, nullptr),
             env->GetStringUTFChars(jValue, nullptr)));
 
-        if (env->ExceptionCheck()) return;
+        if (env->ExceptionCheck())
+        {
+            return;
+        }
         env->DeleteLocalRef(jEntry);
         env->DeleteLocalRef(jKey);
         env->DeleteLocalRef(jValue);
@@ -129,7 +184,10 @@ void JniUtils::convertJavaMapToQueryParamsMap(JNIEnv *env, jobject hashMap, OC::
 jobject JniUtils::convertQueryParamsMapToJavaMap(JNIEnv *env, const OC::QueryParamsMap &map)
 {
     jobject hashMap = env->NewObject(g_cls_HashMap, g_mid_HashMap_ctor);
-    if (!hashMap) return nullptr;
+    if (!hashMap)
+    {
+        return nullptr;
+    }
 
     for (auto it = map.begin(); it != map.end(); ++it)
     {
@@ -140,7 +198,10 @@ jobject JniUtils::convertQueryParamsMapToJavaMap(JNIEnv *env, const OC::QueryPar
             g_mid_HashMap_put,
             env->NewStringUTF(key.c_str()),
             env->NewStringUTF(value.c_str()));
-        if (env->ExceptionCheck()) return nullptr;
+        if (env->ExceptionCheck())
+        {
+            return nullptr;
+        }
     }
 
     return hashMap;
@@ -150,16 +211,25 @@ void JniUtils::convertJavaRepresentationArrToVector(JNIEnv *env,
     jobjectArray jRepresentationArray,
     std::vector<OC::OCRepresentation>& representationVector)
 {
-    if (!jRepresentationArray) return;
+    if (!jRepresentationArray)
+    {
+        return;
+    }
     jsize len = env->GetArrayLength(jRepresentationArray);
 
     for (jsize i = 0; i < len; ++i)
     {
         jobject jRep = env->GetObjectArrayElement(jRepresentationArray, i);
-        if (!jRep) return;
+        if (!jRep)
+        {
+            return;
+        }
         OC::OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, jRep);
         representationVector.push_back(*rep);
-        if (env->ExceptionCheck()) return;
+        if (env->ExceptionCheck())
+        {
+            return;
+        }
         env->DeleteLocalRef(jRep);
     }
 }
@@ -169,7 +239,10 @@ jobjectArray JniUtils::convertRepresentationVectorToJavaArray(JNIEnv *env,
 {
     jsize len = static_cast<jsize>(representationVector.size());
     jobjectArray repArr = env->NewObjectArray(len, g_cls_OcRepresentation, nullptr);
-    if (!repArr) return nullptr;
+    if (!repArr)
+    {
+        return nullptr;
+    }
     for (jsize i = 0; i < len; ++i)
     {
         OCRepresentation* rep = new OCRepresentation(representationVector[i]);
@@ -182,9 +255,12 @@ jobjectArray JniUtils::convertRepresentationVectorToJavaArray(JNIEnv *env,
             return nullptr;
         }
         env->SetObjectArrayElement(repArr, i, jRepresentation);
-        if (env->ExceptionCheck()) return nullptr;
+        if (env->ExceptionCheck())
+        {
+            return nullptr;
+        }
         env->DeleteLocalRef(jRepresentation);
     }
 
     return repArr;
-}
\ No newline at end of file
+}
index fcfa2a1..a7a259a 100644 (file)
@@ -47,84 +47,89 @@ public:
 
     static OC::ServiceType getServiceType(JNIEnv *env, int type)
     {
-        switch (type) {
-        case 0:
-            return OC::ServiceType::InProc;
-        case 1:
-            return OC::ServiceType::OutOfProc;
-        default:
-            ThrowOcException(OC_STACK_INVALID_PARAM, "Unexpected service type");
-            return OC::ServiceType::OutOfProc;
+        switch (type)
+        {
+            case 0:
+                return OC::ServiceType::InProc;
+            case 1:
+                return OC::ServiceType::OutOfProc;
+            default:
+                ThrowOcException(OC_STACK_INVALID_PARAM, "Unexpected service type");
+                return OC::ServiceType::OutOfProc;
         };
     }
 
     static OC::ModeType getModeType(JNIEnv *env, int type)
     {
-        switch (type) {
-        case 0:
-            return OC::ModeType::Server;
-        case 1:
-            return OC::ModeType::Client;
-        case 2:
-            return OC::ModeType::Both;
-        case 3:
-            return OC::ModeType::Gateway;
-        default:
-            ThrowOcException(OC_STACK_INVALID_PARAM, "Unexpected mode type");
-            return OC::ModeType::Both;
+        switch (type)
+        {
+            case 0:
+                return OC::ModeType::Server;
+            case 1:
+                return OC::ModeType::Client;
+            case 2:
+                return OC::ModeType::Both;
+            case 3:
+                return OC::ModeType::Gateway;
+            default:
+                ThrowOcException(OC_STACK_INVALID_PARAM, "Unexpected mode type");
+                return OC::ModeType::Both;
         };
     }
 
     static OC::QualityOfService getQOS(JNIEnv *env, int type)
     {
-        switch (type) {
-        case 0:
-            return OC::QualityOfService::LowQos;
-        case 1:
-            return OC::QualityOfService::MidQos;
-        case 2:
-            return OC::QualityOfService::HighQos;
-        case 3:
-            return OC::QualityOfService::NaQos;
-        default:
-            ThrowOcException(OC_STACK_INVALID_PARAM, "Unexpected quality of service");
-            return OC::QualityOfService::NaQos;
+        switch (type)
+        {
+            case 0:
+                return OC::QualityOfService::LowQos;
+            case 1:
+                return OC::QualityOfService::MidQos;
+            case 2:
+                return OC::QualityOfService::HighQos;
+            case 3:
+                return OC::QualityOfService::NaQos;
+            default:
+                ThrowOcException(OC_STACK_INVALID_PARAM, "Unexpected quality of service");
+                return OC::QualityOfService::NaQos;
         };
     }
 
     static OC::ObserveType getObserveType(JNIEnv *env, int type)
     {
-        switch (type) {
-        case 0:
-            return OC::ObserveType::Observe;
-        case 1:
-            return OC::ObserveType::ObserveAll;
-        default:
-            ThrowOcException(OC_STACK_INVALID_PARAM, "Unexpected observe type");
-            return OC::ObserveType::ObserveAll;
+        switch (type)
+        {
+            case 0:
+                return OC::ObserveType::Observe;
+            case 1:
+                return OC::ObserveType::ObserveAll;
+            default:
+                ThrowOcException(OC_STACK_INVALID_PARAM, "Unexpected observe type");
+                return OC::ObserveType::ObserveAll;
         };
     }
 
     static OCEntityHandlerResult getOCEntityHandlerResult(JNIEnv *env, int type)
     {
-        switch (type) {
-        case 0:
-            return OCEntityHandlerResult::OC_EH_OK;
-        case 1:
-            return OCEntityHandlerResult::OC_EH_ERROR;
-        case 2:
-            return OCEntityHandlerResult::OC_EH_RESOURCE_CREATED;
-        case 3:
-            return OCEntityHandlerResult::OC_EH_RESOURCE_DELETED;
-        case 4:
-            return OCEntityHandlerResult::OC_EH_SLOW;
-        case 5:
-            return OCEntityHandlerResult::OC_EH_FORBIDDEN;
-        case 6:
-            return OCEntityHandlerResult::OC_EH_RESOURCE_NOT_FOUND;
-        default:
-            ThrowOcException(OC_STACK_INVALID_PARAM, "Unexpected OCEntityHandlerResult");
-            return OCEntityHandlerResult::OC_EH_ERROR;
+        switch (type)
+        {
+            case 0:
+                return OCEntityHandlerResult::OC_EH_OK;
+            case 1:
+                return OCEntityHandlerResult::OC_EH_ERROR;
+            case 2:
+                return OCEntityHandlerResult::OC_EH_RESOURCE_CREATED;
+            case 3:
+                return OCEntityHandlerResult::OC_EH_RESOURCE_DELETED;
+            case 4:
+                return OCEntityHandlerResult::OC_EH_SLOW;
+            case 5:
+                return OCEntityHandlerResult::OC_EH_FORBIDDEN;
+            case 6:
+                return OCEntityHandlerResult::OC_EH_RESOURCE_NOT_FOUND;
+            default:
+                ThrowOcException(OC_STACK_INVALID_PARAM, "Unexpected OCEntityHandlerResult");
+                return OCEntityHandlerResult::OC_EH_ERROR;
         };
     }
 
@@ -132,106 +137,106 @@ public:
     {
         switch (result)
         {
-        /** Success status code - START HERE.*/
-        case OC_STACK_OK:
-            return "OK";
-        case OC_STACK_RESOURCE_CREATED:
-            return "RESOURCE_CREATED";
-        case OC_STACK_RESOURCE_DELETED:
-            return "RESOURCE_DELETED";
-        case OC_STACK_CONTINUE:
-            return "CONTINUE";
-        /* Error status code - START HERE */
-        case OC_STACK_INVALID_URI:
-            return "INVALID_URI";
-        case OC_STACK_INVALID_QUERY:
-            return "INVALID_QUERY";
-        case OC_STACK_INVALID_IP:
-            return "INVALID_IP";
-        case OC_STACK_INVALID_PORT:
-            return "INVALID_PORT";
-        case OC_STACK_INVALID_CALLBACK:
-            return "INVALID_CALLBACK";
-        case OC_STACK_INVALID_METHOD:
-            return "INVALID_METHOD";
-        /** Invalid parameter.*/
-        case OC_STACK_INVALID_PARAM:
-            return "INVALID_PARAM";
-        case OC_STACK_INVALID_OBSERVE_PARAM:
-            return "INVALID_OBSERVE_PARAM";
-        case OC_STACK_NO_MEMORY:
-            return "NO_MEMORY";
-        case OC_STACK_COMM_ERROR:
-            return "COMM_ERROR";
-        case OC_STACK_TIMEOUT:
-            return "TIMEOUT";
-        case OC_STACK_ADAPTER_NOT_ENABLED:
-            return "ADAPTER_NOT_ENABLED";
-        case OC_STACK_NOTIMPL:
-            return "NOTIMPL";
-        /** Resource not found.*/
-        case OC_STACK_NO_RESOURCE:
-            return "NO_RESOURCE";
-        /** e.g: not supported method or interface.*/
-        case  OC_STACK_RESOURCE_ERROR:
-            return "RESOURCE_ERROR";
-        case OC_STACK_SLOW_RESOURCE:
-            return "SLOW_RESOURCE";
-        case OC_STACK_DUPLICATE_REQUEST:
-            return "DUPLICATE_REQUEST";
-        /** Resource has no registered observers.*/
-        case OC_STACK_NO_OBSERVERS:
-            return "NO_OBSERVERS";
-        case OC_STACK_OBSERVER_NOT_FOUND:
-            return "OBSERVER_NOT_FOUND";
-        case OC_STACK_VIRTUAL_DO_NOT_HANDLE:
-            return "VIRTUAL_DO_NOT_HANDLE";
-        case OC_STACK_INVALID_OPTION:
-            return "INVALID_OPTION";
-        /** The remote reply contained malformed data.*/
-        case OC_STACK_MALFORMED_RESPONSE:
-            return "MALFORMED_RESPONSE";
-        case OC_STACK_PERSISTENT_BUFFER_REQUIRED:
-            return "PERSISTENT_BUFFER_REQUIRED";
-        case OC_STACK_INVALID_REQUEST_HANDLE:
-            return "INVALID_REQUEST_HANDLE";
-        case OC_STACK_INVALID_DEVICE_INFO:
-            return "INVALID_DEVICE_INFO";
-        case OC_STACK_INVALID_JSON:
-            return "INVALID_JSON";
-        /** Request is not authorized by Resource Server. */
-        case OC_STACK_UNAUTHORIZED_REQ:
-            return "UNAUTHORIZED_REQ";
-        /** Error code from PDM */
-        case OC_STACK_PDM_IS_NOT_INITIALIZED:
-            return "PDM_IS_NOT_INITIALIZED";
-        case OC_STACK_DUPLICATE_UUID:
-            return "DUPLICATE_UUID";
-        case OC_STACK_INCONSISTENT_DB:
-            return "INCONSISTENT_DB";
-        /** Error code from OTM */
-        case OC_STACK_AUTHENTICATION_FAILURE:
-            return "AUTHENTICATION_FAILURE";
-        /** Insert all new error codes here!.*/
+            /** Success status code - START HERE.*/
+            case OC_STACK_OK:
+                return "OK";
+            case OC_STACK_RESOURCE_CREATED:
+                return "RESOURCE_CREATED";
+            case OC_STACK_RESOURCE_DELETED:
+                return "RESOURCE_DELETED";
+            case OC_STACK_CONTINUE:
+                return "CONTINUE";
+            /* Error status code - START HERE */
+            case OC_STACK_INVALID_URI:
+                return "INVALID_URI";
+            case OC_STACK_INVALID_QUERY:
+                return "INVALID_QUERY";
+            case OC_STACK_INVALID_IP:
+                return "INVALID_IP";
+            case OC_STACK_INVALID_PORT:
+                return "INVALID_PORT";
+            case OC_STACK_INVALID_CALLBACK:
+                return "INVALID_CALLBACK";
+            case OC_STACK_INVALID_METHOD:
+                return "INVALID_METHOD";
+            /** Invalid parameter.*/
+            case OC_STACK_INVALID_PARAM:
+                return "INVALID_PARAM";
+            case OC_STACK_INVALID_OBSERVE_PARAM:
+                return "INVALID_OBSERVE_PARAM";
+            case OC_STACK_NO_MEMORY:
+                return "NO_MEMORY";
+            case OC_STACK_COMM_ERROR:
+                return "COMM_ERROR";
+            case OC_STACK_TIMEOUT:
+                return "TIMEOUT";
+            case OC_STACK_ADAPTER_NOT_ENABLED:
+                return "ADAPTER_NOT_ENABLED";
+            case OC_STACK_NOTIMPL:
+                return "NOTIMPL";
+            /** Resource not found.*/
+            case OC_STACK_NO_RESOURCE:
+                return "NO_RESOURCE";
+            /** e.g: not supported method or interface.*/
+            case  OC_STACK_RESOURCE_ERROR:
+                return "RESOURCE_ERROR";
+            case OC_STACK_SLOW_RESOURCE:
+                return "SLOW_RESOURCE";
+            case OC_STACK_DUPLICATE_REQUEST:
+                return "DUPLICATE_REQUEST";
+            /** Resource has no registered observers.*/
+            case OC_STACK_NO_OBSERVERS:
+                return "NO_OBSERVERS";
+            case OC_STACK_OBSERVER_NOT_FOUND:
+                return "OBSERVER_NOT_FOUND";
+            case OC_STACK_VIRTUAL_DO_NOT_HANDLE:
+                return "VIRTUAL_DO_NOT_HANDLE";
+            case OC_STACK_INVALID_OPTION:
+                return "INVALID_OPTION";
+            /** The remote reply contained malformed data.*/
+            case OC_STACK_MALFORMED_RESPONSE:
+                return "MALFORMED_RESPONSE";
+            case OC_STACK_PERSISTENT_BUFFER_REQUIRED:
+                return "PERSISTENT_BUFFER_REQUIRED";
+            case OC_STACK_INVALID_REQUEST_HANDLE:
+                return "INVALID_REQUEST_HANDLE";
+            case OC_STACK_INVALID_DEVICE_INFO:
+                return "INVALID_DEVICE_INFO";
+            case OC_STACK_INVALID_JSON:
+                return "INVALID_JSON";
+            /** Request is not authorized by Resource Server. */
+            case OC_STACK_UNAUTHORIZED_REQ:
+                return "UNAUTHORIZED_REQ";
+            /** Error code from PDM */
+            case OC_STACK_PDM_IS_NOT_INITIALIZED:
+                return "PDM_IS_NOT_INITIALIZED";
+            case OC_STACK_DUPLICATE_UUID:
+                return "DUPLICATE_UUID";
+            case OC_STACK_INCONSISTENT_DB:
+                return "INCONSISTENT_DB";
+            /** Error code from OTM */
+            case OC_STACK_AUTHENTICATION_FAILURE:
+                return "AUTHENTICATION_FAILURE";
+            /** Insert all new error codes here!.*/
 #ifdef WITH_PRESENCE
-        case OC_STACK_PRESENCE_STOPPED:
-            return "PRESENCE_STOPPED";
-        case OC_STACK_PRESENCE_TIMEOUT:
-            return "PRESENCE_TIMEOUT";
-        case OC_STACK_PRESENCE_DO_NOT_HANDLE:
-            return "PRESENCE_DO_NOT_HANDLE";
+            case OC_STACK_PRESENCE_STOPPED:
+                return "PRESENCE_STOPPED";
+            case OC_STACK_PRESENCE_TIMEOUT:
+                return "PRESENCE_TIMEOUT";
+            case OC_STACK_PRESENCE_DO_NOT_HANDLE:
+                return "PRESENCE_DO_NOT_HANDLE";
 #endif
-        case OC_STACK_ERROR:
-            return "ERROR";
+            case OC_STACK_ERROR:
+                return "ERROR";
 
-        case JNI_EXCEPTION:
-            return "JNI_EXCEPTION";
-        case JNI_NO_NATIVE_POINTER:
-            return "JNI_NO_NATIVE_POINTER";
-        case JNI_INVALID_VALUE:
-            return "JNI_INVALID_VALUE";
-        default:
-            return "";
+            case JNI_EXCEPTION:
+                return "JNI_EXCEPTION";
+            case JNI_NO_NATIVE_POINTER:
+                return "JNI_NO_NATIVE_POINTER";
+            case JNI_INVALID_VALUE:
+                return "JNI_INVALID_VALUE";
+            default:
+                return "";
         }
     }
 };
index 398cad3..a63026b 100644 (file)
@@ -2642,12 +2642,6 @@ OCStackResult OCDoResource(OCDoHandle *handle,
         requestInfo.info.payloadFormat = CA_FORMAT_UNDEFINED;
     }
 
-    if (result != OC_STACK_OK)
-    {
-        OIC_LOG(ERROR, TAG, "CACreateEndpoint error");
-        goto exit;
-    }
-
     // prepare for response
 #ifdef WITH_PRESENCE
     if (method == OC_REST_PRESENCE)
@@ -4405,7 +4399,11 @@ void insertResourceInterface(OCResource *resource, OCResourceInterface *newInter
             previous = pointer;
             pointer = pointer->next;
         }
-        previous->next = newInterface;
+
+        if (previous)
+        {
+            previous->next = newInterface;
+        }
     }
 }