From f50d4fef49904927358e2502b9ef46e4301375d0 Mon Sep 17 00:00:00 2001 From: Markus Jung Date: Thu, 14 Jan 2016 10:40:38 +0900 Subject: [PATCH] Check for error messages and code formatting for resource container Android extension Signed-off-by: Markus Jung Change-Id: I7209209155b85b39d0c87b01da284c56d4d0c47d Signed-off-by: Markus Jung Reviewed-on: https://gerrit.iotivity.org/gerrit/4801 Tested-by: jenkins-iotivity Reviewed-by: Uze Choi --- .../src/main/jni/JniRcsResourceContainer.cpp | 78 ++++++++++++++++++++-- .../src/main/jni/JniRcsResourceContainer.h | 2 +- 2 files changed, 73 insertions(+), 7 deletions(-) diff --git a/service/resource-container/android/resource-container/src/main/jni/JniRcsResourceContainer.cpp b/service/resource-container/android/resource-container/src/main/jni/JniRcsResourceContainer.cpp index cf84553..09ef002 100644 --- a/service/resource-container/android/resource-container/src/main/jni/JniRcsResourceContainer.cpp +++ b/service/resource-container/android/resource-container/src/main/jni/JniRcsResourceContainer.cpp @@ -25,6 +25,7 @@ #include "JNIEnvWrapper.h" #include "Log.h" #include "Verify.h" +#include #include "ResourceContainerBundleAPI.h" #include "JniBundleResource.h" @@ -116,6 +117,15 @@ Java_org_iotivity_service_resourcecontainer_RcsResourceContainer_nativeStartCont { LOGD("nativeStartContainer"); + // A strange error message happens if the container is used as native library on Android + // and further native libraries are loaded at runtime. + const char *error; + if ((error = dlerror()) != NULL) + { + __android_log_print(ANDROID_LOG_DEBUG, "JNI-RCSResourceContainer", + "dlerror: %s.", error); + } + EXPECT(configFileObj, "ConfigFile is null."); auto configFile = toStdString(env, configFileObj); @@ -126,11 +136,19 @@ Java_org_iotivity_service_resourcecontainer_RcsResourceContainer_nativeStartCont } JNIEXPORT void JNICALL -Java_org_iotivity_service_resourcecontainer_RcsResourceContainer_nativeStopContainer -(JNIEnv *env, jobject) +Java_org_iotivity_service_resourcecontainer_RcsResourceContainer_nativeStopContainer(JNIEnv *env, jobject) { LOGD("nativeStopContainers"); + // A strange error message happens if the container is used as native library on Android + // and further native libraries are loaded at runtime. + const char *error; + if ((error = dlerror()) != NULL) + { + __android_log_print(ANDROID_LOG_DEBUG, "JNI-RCSResourceContainer", + "dlerror: %s.", error); + } + RCSResourceContainer::getInstance()->stopContainer(); } @@ -141,6 +159,15 @@ Java_org_iotivity_service_resourcecontainer_RcsResourceContainer_nativeAddBundle { LOGD("nativeAddBundle"); + // A strange error message happens if the container is used as native library on Android + // and further native libraries are loaded at runtime. + const char *error; + if ((error = dlerror()) != NULL) + { + __android_log_print(ANDROID_LOG_DEBUG, "JNI-RCSResourceContainer", + "dlerror: %s.", error); + } + EXPECT(idObj, "BundleId is null."); EXPECT(pathObj, "BundlePath is null."); EXPECT(activatorObj, "Activator is null."); @@ -169,6 +196,15 @@ Java_org_iotivity_service_resourcecontainer_RcsResourceContainer_nativeRemoveBun { LOGD("nativeRemoveBundle"); + // A strange error message happens if the container is used as native library on Android + // and further native libraries are loaded at runtime. + const char *error; + if ((error = dlerror()) != NULL) + { + __android_log_print(ANDROID_LOG_DEBUG, "JNI-RCSResourceContainer", + "dlerror: %s.", error); + } + EXPECT(idObj, "BundleId is null."); auto id = toStdString(env, idObj); @@ -184,6 +220,15 @@ Java_org_iotivity_service_resourcecontainer_RcsResourceContainer_nativeListBundl { LOGD("nativeListBundles"); + // A strange error message happens if the container is used as native library on Android + // and further native libraries are loaded at runtime. + const char *error; + if ((error = dlerror()) != NULL) + { + __android_log_print(ANDROID_LOG_DEBUG, "JNI-RCSResourceContainer", + "dlerror: %s.", error); + } + JNIEnvWrapper envWrapper(env); try @@ -208,7 +253,16 @@ JNIEXPORT void JNICALL Java_org_iotivity_service_resourcecontainer_RcsResourceContainer_nativeStartBundle (JNIEnv *env, jobject, jstring idObj) { - LOGD("nativeStartBundle2"); + LOGD("nativeStartBundle"); + + // A strange error message happens if the container is used as native library on Android + // and further native libraries are loaded at runtime. + const char *error; + if ((error = dlerror()) != NULL) + { + __android_log_print(ANDROID_LOG_DEBUG, "JNI-RCSResourceContainer", + "dlerror: %s.", error); + } EXPECT(idObj, "BundleId is null."); @@ -224,6 +278,15 @@ Java_org_iotivity_service_resourcecontainer_RcsResourceContainer_nativeStopBundl { LOGD("nativeStopBundle"); + // A strange error message happens if the container is used as native library on Android + // and further native libraries are loaded at runtime. + const char *error; + if ((error = dlerror()) != NULL) + { + __android_log_print(ANDROID_LOG_DEBUG, "JNI-RCSResourceContainer", + "dlerror: %s.", error); + } + EXPECT(idObj, "BundleId is null."); auto id = env->GetStringUTFChars(idObj, NULL); @@ -314,11 +377,14 @@ Java_org_iotivity_service_resourcecontainer_RcsResourceContainer_nativeRegisterB JNIEnvWrapper envWrapper(env); LOGD("nativeRegisterJniBundleResource"); auto str_bundle_id = toStdString(&envWrapper, bundleId); - __android_log_print(ANDROID_LOG_DEBUG, "JNI-RCSResourceContainer", "retrieved bundle id: %s.", str_bundle_id.c_str()); + __android_log_print(ANDROID_LOG_DEBUG, "JNI-RCSResourceContainer", "retrieved bundle id: %s.", + str_bundle_id.c_str()); auto str_uri = toStdString(&envWrapper, uri); - __android_log_print(ANDROID_LOG_DEBUG, "JNI-RCSResourceContainer", "retrieved uri: %s.", str_uri.c_str()); + __android_log_print(ANDROID_LOG_DEBUG, "JNI-RCSResourceContainer", "retrieved uri: %s.", + str_uri.c_str()); auto str_resourceType = toStdString(&envWrapper, resourceType); - __android_log_print(ANDROID_LOG_DEBUG, "JNI-RCSResourceContainer", "retrieved resource type: %s.", str_resourceType.c_str()); + __android_log_print(ANDROID_LOG_DEBUG, "JNI-RCSResourceContainer", "retrieved resource type: %s.", + str_resourceType.c_str()); auto str_res_name = toStdString(&envWrapper, res_name); LOGD("retrieved res name."); JniBundleResource res; diff --git a/service/resource-container/android/resource-container/src/main/jni/JniRcsResourceContainer.h b/service/resource-container/android/resource-container/src/main/jni/JniRcsResourceContainer.h index 825d276..db2fc07 100644 --- a/service/resource-container/android/resource-container/src/main/jni/JniRcsResourceContainer.h +++ b/service/resource-container/android/resource-container/src/main/jni/JniRcsResourceContainer.h @@ -40,7 +40,7 @@ extern "C" { JNIEXPORT void JNICALL Java_org_iotivity_service_resourcecontainer_RcsResourceContainer_nativeStartContainer -(JNIEnv *, jobject, jstring configFile); +(JNIEnv *, jobject, jstring); JNIEXPORT void JNICALL Java_org_iotivity_service_resourcecontainer_RcsResourceContainer_nativeStopContainer -- 2.7.4