From: Youngjae Shin Date: Tue, 1 Nov 2016 07:39:53 +0000 (+0900) Subject: Imported Upstream version 1.2.0 X-Git-Tag: upstream/1.2.0^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fheads%2Fupstream;p=platform%2Fupstream%2Fiotivity.git Imported Upstream version 1.2.0 --- diff --git a/.gbs.conf b/.gbs.conf new file mode 100644 index 000000000..4cdf5c548 --- /dev/null +++ b/.gbs.conf @@ -0,0 +1,4 @@ +[general] +upstream_branch = upstream +upstream_tag = ${upstreamversion} +packaging_dir = tools/tizen diff --git a/.gitignore b/.gitignore index f13274854..88c8a40c5 100644 --- a/.gitignore +++ b/.gitignore @@ -37,6 +37,9 @@ resource/csdk/stack/samples/linux/SimpleClientServer/release/ resource/csdk/connectivity/build/out/ +# Ignore autogenerated files +resource/c_common/iotivity_config.h + resource/oc_logger/bin/ resource/oc_logger/lib/ resource/oc_logger/samples/linux/release/ @@ -49,6 +52,11 @@ service/things-manager/build/linux/release service/things-manager/build/linux/debug service/things-manager/sdk/build/linux/ +service/notification/android/.gradle/ +service/notification/android/build/ +service/notification/android/notification-service/build/ +service/notification/android/notification-service/src/main/obj/ + # Ignore any object files *.o *.os @@ -84,8 +92,11 @@ config.log os out/ platform +iotivity.pc +tmp/ # Ignore downloaded dependencies +extlibs/libcoap/libcoap extlibs/gtest/gtest-* extlibs/hippomocks-master/ extlibs/master.zip @@ -97,7 +108,7 @@ extlibs/android/sdk/android-sdk_r24.2 extlibs/android/sdk/android-sdk-linux extlibs/android/sdk/android-sdk-macosx extlibs/android/sdk/android-sdk-windows -extlibs/boost/boost_1_58_0 +extlibs/boost/* extlibs/tinycbor/tinycbor *.tgz *.zip @@ -106,14 +117,28 @@ build_common/arduino/extlibs/arduino/arduino-1.5.8 extlibs/tinydtls/dtls-client extlibs/tinydtls/dtls-server extlibs/bluez/bluez +extlibs/mbedtls/mbedtls # Ignore editor (e.g. Emacs) backup and autosave files *~ *#*# *.orig +.cproject +.gradle/ +.project # Ignore byte-compiled Python scripts *.pyc # Ignore Valgrind generated files. *.memcheck + +# Ignore generated files +*.dat + +# Ignore debian generated files +debian/files +debian/*.debhelper.log +debian/*.substvars +debian/iotivity*/* +debian/tmp/* diff --git a/Readme.scons.txt b/Readme.scons.txt index 56f5f026f..1c2d0dd8b 100644 --- a/Readme.scons.txt +++ b/Readme.scons.txt @@ -265,6 +265,8 @@ IOS: * WITH_RA=true or false (Build with Remote Access module) * WITH_RD=1 or 0 (Build including Resource Directory) * SIMULATOR=true or false (Build with simulator module) + * Possible values for are: PUB,SUB,BROKER (Build including Message Queue) + -> PUB : publisher, SUB : subscriber, BROKER : MQ broker(not supported yet) Note1: Currently most IoTivity project doesn't support Windows, so you can't set TARGET_OS to 'windows' except the project support Windows. diff --git a/SConstruct b/SConstruct index 35ff720c6..ac76f3975 100644 --- a/SConstruct +++ b/SConstruct @@ -56,7 +56,7 @@ build_dir = env.get('BUILD_DIR') # Build 'resource' sub-project SConscript(build_dir + 'resource/SConscript') -if target_os not in ['arduino','darwin','ios', 'android']: +if target_os not in ['arduino','darwin','ios', 'android', 'msys_nt', 'windows']: SConscript(build_dir + 'examples/OICMiddle/SConscript') # Build 'service' sub-project @@ -76,6 +76,6 @@ env.PrintTargets() if target_os == 'arduino': env.UploadHelp() -# to install the generated pc file into custome prefix location +# to install the generated pc file into custom prefix location env.UserInstallTargetPCFile('iotivity.pc', 'iotivity.pc') diff --git a/android/android_api/SConscript b/android/android_api/SConscript index 32ffb222e..895ebb631 100644 --- a/android/android_api/SConscript +++ b/android/android_api/SConscript @@ -11,6 +11,46 @@ else: ANDROID_RELEASE="debug" ANDROID_SECURED = env.get('SECURED') +if env.get('WITH_CLOUD'): + ANDROID_CLOUD=1 +else: + ANDROID_CLOUD=0 + +if env.get('WITH_TCP'): + ANDROID_TCP=1 +else: + ANDROID_TCP=0 + +ANDROID_MQ = env.get('WITH_MQ') +ANDROID_MQ_SUB = 0 +ANDROID_MQ_PUB = 0 +ANDROID_MQ_BROKER = 0 +ANDROID_RD_MODE = env.get('RD_MODE') +ANDROID_TRANSPORT = env.get('TARGET_TRANSPORT') +ANDROID_TRANSPORT_EDR = 0 +ANDROID_TRANSPORT_BLE = 0 +ANDROID_TRANSPORT_NFC = 0 + +if 'SUB' in ANDROID_MQ: + ANDROID_MQ_SUB = 1 +if 'PUB' in ANDROID_MQ: + ANDROID_MQ_PUB = 1 +if 'BROKER' in ANDROID_MQ: + ANDROID_MQ_BROKER = 1 + +if 'ALL' in ANDROID_TRANSPORT: + ANDROID_TRANSPORT_EDR = 1 + ANDROID_TRANSPORT_BLE = 1 + ANDROID_TRANSPORT_NFC = 1 + print "Android Transport is ALL" +else: + if 'BT' in ANDROID_TRANSPORT: + ANDROID_TRANSPORT_EDR = 1 + if 'BLE' in ANDROID_TRANSPORT: + ANDROID_TRANSPORT_BLE = 1 + if 'NFC' in ANDROID_TRANSPORT: + ANDROID_TRANSPORT_NFC = 1 + os.environ['ANDROID_HOME'] = env.get('ANDROID_HOME') os.environ['ANDROID_NDK_HOME'] = env.get('ANDROID_NDK') @@ -48,13 +88,14 @@ def ensure_libs(target, source, env): # build android_api jdk_env = Environment(ENV=os.environ) -jdk_env['BUILDERS']['Gradle'] = Builder(action = env.get('ANDROID_GRADLE') + ' build -b' + os.getcwd()+'/build.gradle -PTARGET_ARCH=%s -PRELEASE=%s -PSECURED=%s -DSECURE=%s --stacktrace' %(ANDROID_TARGET_ARCH, ANDROID_RELEASE, ANDROID_SECURED, ANDROID_SECURED), emitter = ensure_libs) +jdk_env['BUILDERS']['Gradle'] = Builder(action = env.get('ANDROID_GRADLE') + ' build -b' + os.getcwd()+'/build.gradle -PWITH_TRANSPORT_EDR=%s -PWITH_TRANSPORT_BLE=%s -PWITH_TRANSPORT_NFC=%s -PTARGET_ARCH=%s -PRELEASE=%s -PSECURED=%s -DSECURE=%s -PWITH_CLOUD=%s -PRD_MODE=%s -PWITH_MQ_PUB=%s -PWITH_MQ_SUB=%s -PWITH_MQ_BROKER=%s -PWITH_TCP=%s --stacktrace' %(ANDROID_TRANSPORT_EDR, ANDROID_TRANSPORT_BLE, ANDROID_TRANSPORT_NFC, ANDROID_TARGET_ARCH, ANDROID_RELEASE, ANDROID_SECURED, ANDROID_SECURED, ANDROID_CLOUD, ANDROID_RD_MODE, ANDROID_MQ_PUB, ANDROID_MQ_SUB, ANDROID_MQ_BROKER, ANDROID_TCP), emitter = ensure_libs) jdk_env['BUILD_DIR'] = env.get('BUILD_DIR') cmdBuildApi=jdk_env.Gradle(target="base/objs", source="base/src/main/java/org/iotivity/base/OcResource.java") -jdk_env['BUILDERS']['Gradle'] = Builder(action = env.get('ANDROID_GRADLE') + ' build -b' + 'android/examples/build.gradle -PTARGET_ARCH=%s -PRELEASE=%s -PSECURED=%s -DSECURE=%s --stacktrace' %(ANDROID_TARGET_ARCH, ANDROID_RELEASE, ANDROID_SECURED, ANDROID_SECURED)) +jdk_env['BUILDERS']['Gradle'] = Builder(action = env.get('ANDROID_GRADLE') + ' build -b' + 'android/examples/build.gradle -DWITH_TRANSPORT_EDR=%s -DWITH_TRANSPORT_BLE=%s -DWITH_TRANSPORT_NFC=%s -PTARGET_ARCH=%s -PRELEASE=%s -PSECURED=%s -DSECURE=%s -PWITH_CLOUD=%s -PRD_MODE=%s -PWITH_MQ_PUB=%s -PWITH_MQ_SUB=%s -PWITH_MQ_BROKER=%s -PWITH_TCP=%s --stacktrace' %(ANDROID_TRANSPORT_EDR, ANDROID_TRANSPORT_BLE, ANDROID_TRANSPORT_NFC, ANDROID_TARGET_ARCH, ANDROID_RELEASE, ANDROID_SECURED, ANDROID_SECURED, ANDROID_CLOUD, ANDROID_RD_MODE, ANDROID_MQ_PUB, ANDROID_MQ_SUB, ANDROID_MQ_BROKER, ANDROID_TCP)) cmdBuildExamples=jdk_env.Gradle(target="../examples/devicediscoveryclient/apk", source="../examples/devicediscoveryclient/src/main/java/org/iotivity/base/examples/DeviceDiscoveryClient.java") # android examples require android api to be built before being invoked Depends(cmdBuildExamples, cmdBuildApi) +env.AppendUnique(baseAAR = cmdBuildApi) diff --git a/android/android_api/base/build.gradle b/android/android_api/base/build.gradle index a0b52ae6a..855418d52 100755 --- a/android/android_api/base/build.gradle +++ b/android/android_api/base/build.gradle @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Intel Corporation. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ apply plugin: 'com.android.library' @@ -41,8 +41,17 @@ android { minSdkVersion 21 targetSdkVersion 21 versionCode 1 - versionName "1.1.1" + versionName "1.2.0" buildConfigField 'int', 'SECURED', SECURED + buildConfigField 'int', 'WITH_TCP', WITH_TCP + buildConfigField 'int', 'WITH_CLOUD', WITH_CLOUD + buildConfigField "int", 'WITH_MQ_PUB', WITH_MQ_PUB + buildConfigField "int", 'WITH_MQ_SUB', WITH_MQ_SUB + buildConfigField "int", 'WITH_MQ_BROKER', WITH_MQ_BROKER + buildConfigField "String", 'RD_MODE', "\"RD_MODE\"" + buildConfigField "int", 'WITH_TRANSPORT_EDR', WITH_TRANSPORT_EDR + buildConfigField "int", 'WITH_TRANSPORT_BLE', WITH_TRANSPORT_BLE + buildConfigField "int", 'WITH_TRANSPORT_NFC', WITH_TRANSPORT_NFC } buildTypes { release { @@ -59,6 +68,22 @@ android { manifest.srcFile 'src/main/AndroidManifest.xml' jniLibs.srcDir 'libs' jni.srcDirs = [] //disable automatic ndk-build call + java{ + if (WITH_TRANSPORT_EDR == "0") { + exclude "**/ca/CaBtPairingInterface.java" + exclude "**/ca/CaEdrInterface.java" + println 'excluded EDR interface' + } + if (WITH_TRANSPORT_BLE == "0") { + exclude "**/ca/CaLeClientInterface.java" + exclude "**/ca/CaLeServerInterface.java" + println 'excluded BLE interface' + } + if (WITH_TRANSPORT_NFC == "0") { + exclude "**/ca/CaNfcInterface.java" + println 'excluded NFC interface' + } + } } } } @@ -94,8 +119,8 @@ task buildNative(type: Exec) { if (System.env.ANDROID_NDK_HOME != null) { //for windows use 'ndk-build.cmd' //def ndkBuild = new File(System.env.ANDROID_NDK_HOME, 'ndk-build.cmd') - def ndkBuild = new File(System.env.ANDROID_NDK_HOME, 'ndk-build') - commandLine ndkBuild, "APP_ABI=$TARGET_ARCH", "APP_OPTIM=$RELEASE", "SECURE=$SECURED" + def ndkBuild = new File(System.env.ANDROID_NDK_HOME, 'ndk-build') + commandLine ndkBuild, "APP_ABI=$TARGET_ARCH", "APP_OPTIM=$RELEASE", "SECURE=$SECURED", "WITH_CLOUD=$WITH_CLOUD", "RD_MODE=$RD_MODE", "WITH_MQ_PUB=$WITH_MQ_PUB", "WITH_MQ_SUB=$WITH_MQ_SUB", "WITH_MQ_BROKER=$WITH_MQ_BROKER", "WITH_TCP=$WITH_TCP" } else { println '##################' println 'Skipping NDK build' diff --git a/android/android_api/base/jni/Android.mk b/android/android_api/base/jni/Android.mk index 51d9dcd49..aabb512f5 100644 --- a/android/android_api/base/jni/Android.mk +++ b/android/android_api/base/jni/Android.mk @@ -1,6 +1,12 @@ LOCAL_PATH := $(call my-dir) TARGET_ARCH_ABI := $(APP_ABI) SECURED := $(SECURE) +WITH_CLOUD := $(WITH_CLOUD) +WITH_TCP := $(WITH_TCP) +WITH_MQ_PUB := $(WITH_MQ_PUB) +WITH_MQ_SUB := $(WITH_MQ_SUB) +WITH_MQ_BROKER := $(WITH_MQ_BROKER) +RD_MODE := $(RD_MODE) include $(CLEAR_VARS) OIC_LIB_PATH := ../../../../out/android/$(APP_ABI)/$(APP_OPTIM) @@ -47,12 +53,36 @@ LOCAL_SRC_FILES := JniCaInterface.c LOCAL_STATIC_LIBRARIES := libandroid-ca LOCAL_LDLIBS := -llog LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/csdk/connectivity/api +LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/c_common include $(BUILD_SHARED_LIBRARY) include $(CLEAR_VARS) OIC_SRC_PATH := ../../../resource OIC_OUT_PATH := ../../../out LOCAL_MODULE := ocstack-jni + +ifeq ($(WITH_CLOUD), 1) + LOCAL_CPPFLAGS += -DWITH_CLOUD +endif + +ifeq ($(WITH_TCP), 1) + LOCAL_CPPFLAGS += -D__WITH_TLS__ +endif + +MQ_FLAG = 0 +ifeq ($(WITH_MQ_PUB), 1) +LOCAL_CFLAGS += -DWITH_MQ -DMQ_PUBLISHER +MQ_FLAG = 1 +endif +ifeq ($(WITH_MQ_SUB), 1) +LOCAL_CFLAGS += -DWITH_MQ -DMQ_SUBSCRIBER +MQ_FLAG = 1 +endif +ifeq ($(WITH_MQ_BROKER), 1) +LOCAL_CFLAGS += -DWITH_MQ -DMQ_BROKER +MQ_FLAG = 1 +endif + LOCAL_SRC_FILES := JniOcStack.cpp \ JniUtils.cpp \ JniEntityHandler.cpp \ @@ -77,7 +107,15 @@ LOCAL_SRC_FILES := JniOcStack.cpp \ JniOcSecurity.cpp \ JniOnDPDevicesFoundListener.cpp \ JniOnDirectPairingListener.cpp \ - JniOcDirectPairDevice.cpp + JniOcDirectPairDevice.cpp \ + JniOnPublishResourceListener.cpp \ + JniOnDeleteResourceListener.cpp + +ifeq ($(MQ_FLAG), 1) + LOCAL_SRC_FILES += JniOnMQTopicFoundListener.cpp \ + JniOnMQSubscribeListener.cpp +endif + ifeq ($(SECURED), 1) LOCAL_SRC_FILES += JniOcSecureResource.cpp \ JniOcProvisioning.cpp \ @@ -85,7 +123,19 @@ ifeq ($(SECURED), 1) JniProvisionResultListner.cpp \ JniPinCheckListener.cpp \ JniDisplayPinListener.cpp - endif +endif + +ifeq ($(WITH_CLOUD), 1) + LOCAL_SRC_FILES += JniOcAccountManager.cpp +endif + +ifeq ($(WITH_TCP), 1) +ifeq ($(SECURED), 1) + LOCAL_SRC_FILES += JniOcCloudProvisioning.cpp \ + JniOcCloudResultListener.cpp \ + JniGetAclIdByDeviceListener.cpp +endif +endif LOCAL_LDLIBS := -llog LOCAL_STATIC_LIBRARIES := android-oc @@ -99,6 +149,9 @@ LOCAL_STATIC_LIBRARIES += android-ocprovision LOCAL_STATIC_LIBRARIES += android-ocpmapi endif +ifeq "$(RD_MODE)" "CLIENT" +LOCAL_CPPFLAGS += -DRD_CLIENT +endif LOCAL_CPPFLAGS += -std=c++0x LOCAL_CPP_FEATURES := rtti exceptions LOCAL_C_INCLUDES := $(OIC_SRC_PATH)/include @@ -110,12 +163,15 @@ LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/csdk/ocsocket/include LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/oc_logger/include LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/../extlibs/boost/boost_1_58_0 LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/../extlibs/cjson +LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/../extlibs/tinycbor/tinycbor/src LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/../build_common/android/compatibility LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/csdk/security/provisioning/include LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/csdk/security/provisioning/include/oxm/ LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/csdk/security/provisioning/include/internal +LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/csdk/security/provisioning/include/cloud/ LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/csdk/security/include LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/csdk/security/include/internal LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/csdk/connectivity/api -LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/csdk/connectivity/lib/libcoap-4.1.1 +LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/csdk/connectivity/inc/pkix +LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/csdk/connectivity/lib/libcoap-4.1.1/include include $(BUILD_SHARED_LIBRARY) diff --git a/android/android_api/base/jni/JniCaInterface.c b/android/android_api/base/jni/JniCaInterface.c index d641f3dd6..9499b5596 100644 --- a/android/android_api/base/jni/JniCaInterface.c +++ b/android/android_api/base/jni/JniCaInterface.c @@ -35,6 +35,8 @@ static jobject g_foundDeviceListenerObject = NULL; static jobject g_listenerObject = NULL; static JavaVM *g_jvm = NULL; +static jclass g_jni_cls_enum = NULL; +static jmethodID g_jni_mid_enum = NULL; JNIEXPORT jint JNI_OnLoad(JavaVM *jvm, void *reserved) { @@ -60,12 +62,14 @@ Java_org_iotivity_ca_CaInterface_initialize CANativeJNISetContext(env, context); } -void CAManagerConnectionStateChangedCB(CATransportAdapter_t adapter, - const char *remote_address, +void CAManagerConnectionStateChangedCB(const CAEndpoint_t *info, bool connected) { - LOGI("Callback - CAManagerConnectionStateChangedCB : type(%d), address(%s), connected(%d)", - adapter, remote_address, connected); + if (!info) + { + LOGE("info is NULL"); + return; + } if (!g_listenerObject) { @@ -73,8 +77,11 @@ void CAManagerConnectionStateChangedCB(CATransportAdapter_t adapter, return; } + LOGI("Callback - CAManagerConnectionStateChangedCB : type(%d), address(%s), connected(%d)", + info->adapter, info->addr, connected); + bool isAttached = false; - JNIEnv* env; + JNIEnv* env = NULL; jint res = (*g_jvm)->GetEnv(g_jvm, (void**) &env, JNI_VERSION_1_6); if (JNI_OK != res) { @@ -106,34 +113,22 @@ void CAManagerConnectionStateChangedCB(CATransportAdapter_t adapter, goto exit_error; } - jstring jni_address = (*env)->NewStringUTF(env, remote_address); + jstring jni_address = (*env)->NewStringUTF(env, info->addr); if (!jni_address) { LOGE("jni_address is null"); goto exit_error; } - jclass jni_cls_enum = (*env)->FindClass(env, "org/iotivity/base/OcConnectivityType"); - if (!jni_cls_enum) + if (g_jni_cls_enum && g_jni_mid_enum) { - LOGE("could not get jni_cls_enum"); - goto exit_error; - } - - jmethodID jni_mid_enum = (*env)->GetStaticMethodID(env, jni_cls_enum, "getInstance", - "(I)Lorg/iotivity/base/OcConnectivityType;"); - if (!jni_mid_enum) - { - LOGE("could not get Method ID (getInstance)"); - goto exit_error; + jobject jni_adaptertype = (*env)->CallStaticObjectMethod(env, g_jni_cls_enum, + g_jni_mid_enum, info->adapter); + (*env)->CallVoidMethod(env, g_listenerObject, jni_mid_listener, + jni_adaptertype, jni_address, + (jboolean)connected); } - jobject jni_adaptertype = (*env)->CallStaticObjectMethod(env, jni_cls_enum, - jni_mid_enum, adapter); - (*env)->CallVoidMethod(env, g_listenerObject, jni_mid_listener, - jni_adaptertype, jni_address, - (jboolean)connected); - exit_error: if (isAttached) { @@ -155,7 +150,7 @@ void CAManagerAdapterStateChangedCB(CATransportAdapter_t adapter, bool enabled) } bool isAttached = false; - JNIEnv* env; + JNIEnv* env = NULL; jint res = (*g_jvm)->GetEnv(g_jvm, (void**) &env, JNI_VERSION_1_6); if (JNI_OK != res) { @@ -186,27 +181,15 @@ void CAManagerAdapterStateChangedCB(CATransportAdapter_t adapter, bool enabled) goto exit_error; } - jclass jni_cls_enum = (*env)->FindClass(env, "org/iotivity/base/OcConnectivityType"); - if (!jni_cls_enum) + if (g_jni_cls_enum && g_jni_mid_enum) { - LOGE("could not get jni_cls_enum"); - goto exit_error; - } + jobject jni_adaptertype = (*env)->CallStaticObjectMethod(env, g_jni_cls_enum, + g_jni_mid_enum, adapter); - jmethodID jni_mid_enum = (*env)->GetStaticMethodID(env, jni_cls_enum, "getInstance", - "(I)Lorg/iotivity/base/OcConnectivityType;"); - if (!jni_mid_enum) - { - LOGE("could not get Method ID (getInstance)"); - goto exit_error; + (*env)->CallVoidMethod(env, g_listenerObject, jni_mid_listener, + jni_adaptertype, (jboolean)enabled); } - jobject jni_adaptertype = (*env)->CallStaticObjectMethod(env, jni_cls_enum, - jni_mid_enum, adapter); - - (*env)->CallVoidMethod(env, g_listenerObject, jni_mid_listener, - jni_adaptertype, (jboolean)enabled); - exit_error: if (isAttached) { @@ -223,8 +206,25 @@ Java_org_iotivity_ca_CaInterface_caManagerInitialize(JNIEnv *env, jclass clazz, CAUtilClientInitialize(env, g_jvm, context); - g_listenerObject = (*env)->NewGlobalRef(env, listener); + if (listener) + { + g_listenerObject = (*env)->NewGlobalRef(env, listener); + } + if (g_listenerObject) + { + jclass cls = (*env)->FindClass(env, "org/iotivity/base/OcConnectivityType"); + if (cls) + { + g_jni_cls_enum = (jclass)(*env)->NewGlobalRef(env, cls); + } + + if (g_jni_cls_enum) + { + g_jni_mid_enum = (*env)->GetStaticMethodID(env, g_jni_cls_enum, "getInstance", + "(I)Lorg/iotivity/base/OcConnectivityType;"); + } + } CARegisterNetworkMonitorHandler(CAManagerAdapterStateChangedCB, CAManagerConnectionStateChangedCB); } @@ -241,6 +241,12 @@ Java_org_iotivity_ca_CaInterface_caManagerTerminate(JNIEnv *env, jclass clazz) (*env)->DeleteGlobalRef(env, g_listenerObject); g_listenerObject = NULL; } + + if (g_jni_cls_enum) + { + (*env)->DeleteGlobalRef(env, g_jni_cls_enum); + g_jni_cls_enum = NULL; + } } JNIEXPORT void JNICALL @@ -249,6 +255,11 @@ Java_org_iotivity_ca_CaInterface_caManagerSetAutoConnectionDeviceInfo(JNIEnv *en jstring jaddress) { LOGI("CaManager_setAutoConnectionDeviceInfo"); + if (!jaddress) + { + LOGE("jaddress is null"); + return; + } const char* address = (*env)->GetStringUTFChars(env, jaddress, NULL); if (!address) @@ -268,6 +279,11 @@ Java_org_iotivity_ca_CaInterface_caManagerUnsetAutoConnectionDeviceInfo(JNIEnv * jstring jaddress) { LOGI("CaManager_unsetAutoConnectionDeviceInfo"); + if (!jaddress) + { + LOGE("jaddress is null"); + return; + } const char* address = (*env)->GetStringUTFChars(env, jaddress, NULL); if (!address) @@ -329,3 +345,29 @@ Java_org_iotivity_ca_CaInterface_caBtPairingCreateBond(JNIEnv *env, jclass clazz (void)clazz; CAUtilCreateBond(env, device); } + +JNIEXPORT void JNICALL +Java_org_iotivity_ca_CaInterface_setLeScanIntervalTimeImpl(JNIEnv *env, jclass clazz, + jint intervalTime, jint workignCount) +{ + LOGI("setLeScanIntervalTimeImpl"); + (void)env; + (void)clazz; + CAUtilSetLEScanInterval(intervalTime, workignCount); +} + +JNIEXPORT jint JNICALL Java_org_iotivity_ca_CaInterface_setCipherSuiteImpl + (JNIEnv *env, jclass clazz, jint cipherSuite, jint adapter) +{ + LOGI("setCipherSuiteImpl"); +#if defined(__WITH_DTLS__) || defined(__WITH_TLS__) + (void)env; + (void)clazz; + CAResult_t ret = CASelectCipherSuite(cipherSuite, (CATransportAdapter_t) adapter); + return ret; +#else + LOGE("Method not supported"); + return -1; +#endif // __WITH_DTLS__ || __WITH_TLS__ +} + diff --git a/android/android_api/base/jni/JniCaInterface.h b/android/android_api/base/jni/JniCaInterface.h index 20dc9958b..663aef33e 100644 --- a/android/android_api/base/jni/JniCaInterface.h +++ b/android/android_api/base/jni/JniCaInterface.h @@ -31,8 +31,7 @@ extern "C" { #endif - void CAManagerConnectionStateChangedCB(CATransportAdapter_t adapter, - const char *remote_address, bool connected); + void CAManagerConnectionStateChangedCB(const CAEndpoint_t *info, bool connected); void CAManagerAdapterStateChangedCB(CATransportAdapter_t adapter, bool enabled); @@ -121,6 +120,22 @@ extern "C" { JNIEXPORT void JNICALL Java_org_iotivity_ca_CaInterface_initialize (JNIEnv *, jclass, jobject, jobject); + /* + * Class: Java_org_iotivity_ca_CaInterface_setLeScanIntervalTimeImpl + * Method: setLeScanIntervalTimeImpl + * Signature: (II)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_ca_CaInterface_setLeScanIntervalTimeImpl + (JNIEnv *, jclass, jint, jint); + + /* + * Class: org_iotivity_ca_CaInterface + * Method: setCipherSuiteImpl + * Signature: (Lorg/iotivity/ca/OicCipher;Lorg/iotivity/ca/CATransportAdapter;)I + */ + JNIEXPORT jint JNICALL Java_org_iotivity_ca_CaInterface_setCipherSuiteImpl + (JNIEnv *, jclass, jint, jint); + #ifdef __cplusplus } #endif diff --git a/android/android_api/base/jni/JniDisplayPinListener.cpp b/android/android_api/base/jni/JniDisplayPinListener.cpp index 25ee92689..1705bdfe6 100644 --- a/android/android_api/base/jni/JniDisplayPinListener.cpp +++ b/android/android_api/base/jni/JniDisplayPinListener.cpp @@ -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); diff --git a/android/android_api/base/jni/JniEntityHandler.cpp b/android/android_api/base/jni/JniEntityHandler.cpp index 1d641ae06..f46dde08b 100644 --- a/android/android_api/base/jni/JniEntityHandler.cpp +++ b/android/android_api/base/jni/JniEntityHandler.cpp @@ -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 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); diff --git a/android/android_api/base/jni/JniGetAclIdByDeviceListener.cpp b/android/android_api/base/jni/JniGetAclIdByDeviceListener.cpp new file mode 100644 index 000000000..c13682fb6 --- /dev/null +++ b/android/android_api/base/jni/JniGetAclIdByDeviceListener.cpp @@ -0,0 +1,128 @@ +/* +* //****************************************************************** +* // +* // Copyright 2016 Samsung Electronics All Rights Reserved. +* // +* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +* // +* // Licensed under the Apache License, Version 2.0 (the "License"); +* // you may not use this file except in compliance with the License. +* // You may obtain a copy of the License at +* // +* // http://www.apache.org/licenses/LICENSE-2.0 +* // +* // Unless required by applicable law or agreed to in writing, software +* // distributed under the License is distributed on an "AS IS" BASIS, +* // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* // See the License for the specific language governing permissions and +* // limitations under the License. +* // +* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +*/ +#include "JniGetAclIdByDeviceListener.h" + +JniGetAclIdByDeviceListener::JniGetAclIdByDeviceListener(JNIEnv *env, jobject jListener, + RemoveCallback removeListener) +{ + m_jwListener = env->NewWeakGlobalRef(jListener); + m_removeGetAclbyIDListener = removeListener; +} + +JniGetAclIdByDeviceListener::~JniGetAclIdByDeviceListener() +{ + LOGI("~JniGetAclIdByDeviceListener()"); + if (m_jwListener) + { + jint ret = JNI_ERR; + JNIEnv *env = GetJNIEnv(ret); + if (nullptr == env) + { + return; + } + env->DeleteWeakGlobalRef(m_jwListener); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } + } +} + +void JniGetAclIdByDeviceListener::GetAclIdByDeviceListenerCB(int result, std::string aclID) +{ + jint ret = JNI_ERR; + JNIEnv *env = GetJNIEnv(ret); + if (nullptr == env) + { + return; + } + + jobject jListener = env->NewLocalRef(m_jwListener); + if (!jListener) + { + checkExAndRemoveListener(env); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } + return; + } + + jclass clsL = env->GetObjectClass(jListener); + + if (!clsL) + { + checkExAndRemoveListener(env); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } + return; + } + + jmethodID midL = env->GetMethodID(clsL, "getAclIdByDeviceListener", "(ZLjava/lang/String;)V"); + if (!midL) + { + checkExAndRemoveListener(env); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } + return; + } + jstring jStr = env-> NewStringUTF(aclID.c_str()); + if (!jStr) + { + checkExAndRemoveListener(env); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } + return; + + } + env->CallVoidMethod(jListener, midL, (jboolean)result, jStr); + if (env->ExceptionCheck()) + { + LOGE("Java exception is thrown"); + } + checkExAndRemoveListener(env); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } +} + +void JniGetAclIdByDeviceListener::checkExAndRemoveListener(JNIEnv* env) +{ + if (env->ExceptionCheck()) + { + jthrowable ex = env->ExceptionOccurred(); + env->ExceptionClear(); + m_removeGetAclbyIDListener(env, m_jwListener); + env->Throw((jthrowable)ex); + } + else + { + m_removeGetAclbyIDListener(env, m_jwListener); + } +} diff --git a/android/android_api/base/jni/JniGetAclIdByDeviceListener.h b/android/android_api/base/jni/JniGetAclIdByDeviceListener.h new file mode 100644 index 000000000..8ad5b1110 --- /dev/null +++ b/android/android_api/base/jni/JniGetAclIdByDeviceListener.h @@ -0,0 +1,46 @@ +/* +* //****************************************************************** +* // +* // Copyright 2016 Samsung Electronics All Rights Reserved. +* // +* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +* // +* // Licensed under the Apache License, Version 2.0 (the "License"); +* // you may not use this file except in compliance with the License. +* // You may obtain a copy of the License at +* // +* // http://www.apache.org/licenses/LICENSE-2.0 +* // +* // Unless required by applicable law or agreed to in writing, software +* // distributed under the License is distributed on an "AS IS" BASIS, +* // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* // See the License for the specific language governing permissions and +* // limitations under the License. +* // +* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +*/ + +#include +#include "JniOcStack.h" + +/* Header for class org_iotivity_base_OcCloudProvisioning_GetAclIdByDeviceListener */ +#ifndef _Included_org_iotivity_base_OcCloudProvisioning_JniGetAclIdByDeviceListener +#define _Included_org_iotivity_base_OcCloudProvisioning_JniGetAclIdByDeviceListener + +typedef std::function RemoveCallback; + +class JniGetAclIdByDeviceListener +{ + public: + JniGetAclIdByDeviceListener(JNIEnv *env, jobject jListener, + RemoveCallback removeListener); + ~JniGetAclIdByDeviceListener(); + + void GetAclIdByDeviceListenerCB(int result, std::string aclID); + + private: + RemoveCallback m_removeGetAclbyIDListener; + jweak m_jwListener; + void checkExAndRemoveListener(JNIEnv* env); +}; +#endif diff --git a/android/android_api/base/jni/JniListenerManager.h b/android/android_api/base/jni/JniListenerManager.h index b082f7d73..8965e859e 100644 --- a/android/android_api/base/jni/JniListenerManager.h +++ b/android/android_api/base/jni/JniListenerManager.h @@ -27,6 +27,9 @@ #define _JniListenerManager class JniOcResource; +#ifdef WITH_CLOUD +class JniOcAccountManager; +#endif template class JniListenerManager @@ -51,6 +54,7 @@ public: break; } } + if (!onEventListener) { onEventListener = new T(env, jListener, owner); @@ -66,13 +70,63 @@ public: { LOGD("OnEventListener: Failed to create global listener ref."); delete onEventListener; + m_mapMutex.unlock(); + return nullptr; } LOGD("OnEventListener: new listener"); } + m_mapMutex.unlock(); return onEventListener; } +#ifdef WITH_CLOUD + T* addListener(JNIEnv* env, jobject jListener, JniOcAccountManager* owner) + { + T *onEventListener = nullptr; + + m_mapMutex.lock(); + + for (auto it = m_listenerMap.begin(); it != m_listenerMap.end(); ++it) + { + if (env->IsSameObject(jListener, it->first)) + { + auto refPair = it->second; + onEventListener = refPair.first; + refPair.second++; + it->second = refPair; + m_listenerMap.insert(*it); + LOGD("OnEventListener: ref. count is incremented"); + break; + } + } + + if (!onEventListener) + { + onEventListener = new T(env, jListener, owner); + jobject jgListener = env->NewGlobalRef(jListener); + + if (jgListener) + { + m_listenerMap.insert( + std::pair>(jgListener, std::pair(onEventListener, 1))); + } + else + { + LOGD("OnEventListener: Failed to create global listener ref."); + delete onEventListener; + m_mapMutex.unlock(); + return nullptr; + } + LOGD("OnEventListener: new listener"); + } + + m_mapMutex.unlock(); + return onEventListener; + } +#endif + void removeListener(JNIEnv* env, jobject jListener) { m_mapMutex.lock(); @@ -94,7 +148,6 @@ public: T* listener = refPair.first; delete listener; m_listenerMap.erase(it); - LOGI("OnEventListener is removed"); } break; @@ -106,6 +159,7 @@ public: void removeAllListeners(JNIEnv* env) { m_mapMutex.lock(); + LOGI("All listeners are removed"); for (auto& pair : m_listenerMap) { diff --git a/android/android_api/base/jni/JniOcAccountManager.cpp b/android/android_api/base/jni/JniOcAccountManager.cpp new file mode 100644 index 000000000..9556111a9 --- /dev/null +++ b/android/android_api/base/jni/JniOcAccountManager.cpp @@ -0,0 +1,1540 @@ +/* + ******************************************************************* + * + * Copyright 2016 Samsung Electronics All Rights Reserved. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + */ + +#include "JniOcAccountManager.h" +#include "JniOcRepresentation.h" +#include "JniUtils.h" + +JniOcAccountManager::JniOcAccountManager(std::shared_ptr accountManager) + : m_sharedAccountManager(accountManager) +{ +} + +JniOcAccountManager::~JniOcAccountManager() +{ + LOGD("~JniOcAccountManager()"); + + m_sharedAccountManager = nullptr; + + jint envRet = JNI_ERR; + JNIEnv *env = GetJNIEnv(envRet); + if (nullptr == env) + { + return; + } + + m_onGetManager.removeAllListeners(env); + m_onPostManager.removeAllListeners(env); + m_onDeleteManager.removeAllListeners(env); + m_onObserveManager.removeAllListeners(env); + + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } +} + +std::string JniOcAccountManager::host() +{ + return m_sharedAccountManager->host(); +} + +OCConnectivityType JniOcAccountManager::connectivityType() const +{ + return m_sharedAccountManager->connectivityType(); +} + +JniOcAccountManager* JniOcAccountManager::getJniOcAccountManagerPtr(JNIEnv *env, jobject thiz) +{ + JniOcAccountManager *accountManager = GetHandle(env, thiz); + if (env->ExceptionCheck()) + { + LOGE("Failed to get native handle from OcAccountManager"); + } + if (!accountManager) + { + ThrowOcException(JNI_NO_NATIVE_POINTER, ""); + } + return accountManager; +} + +JniOnGetListener* JniOcAccountManager::addOnGetListener(JNIEnv* env, jobject jListener) +{ + return this->m_onGetManager.addListener(env, jListener, this); +} + +JniOnPostListener* JniOcAccountManager::addOnPostListener(JNIEnv* env, jobject jListener) +{ + return this->m_onPostManager.addListener(env, jListener, this); +} + +JniOnDeleteListener* JniOcAccountManager::addOnDeleteListener(JNIEnv* env, jobject jListener) +{ + return this->m_onDeleteManager.addListener(env, jListener, this); +} + +JniOnObserveListener* JniOcAccountManager::addOnObserveListener(JNIEnv* env, jobject jListener) +{ + return this->m_onObserveManager.addListener(env, jListener, this); +} + +void JniOcAccountManager::removeOnGetListener(JNIEnv* env, jobject jListener) +{ + this->m_onGetManager.removeListener(env, jListener); +} + +void JniOcAccountManager::removeOnPostListener(JNIEnv* env, jobject jListener) +{ + this->m_onPostManager.removeListener(env, jListener); +} + +void JniOcAccountManager::removeOnDeleteListener(JNIEnv* env, jobject jListener) +{ + this->m_onDeleteManager.removeListener(env, jListener); +} + +void JniOcAccountManager::removeOnObserveListener(JNIEnv* env, jobject jListener) +{ + this->m_onObserveManager.removeListener(env, jListener); +} + +OCStackResult JniOcAccountManager::signUp(JNIEnv* env, const std::string& authProvider, + const std::string& authCode, jobject jListener) +{ + JniOnPostListener *onPostListener = addOnPostListener(env, jListener); + + PostCallback postCallback = [onPostListener](const HeaderOptions& opts, + const OCRepresentation& rep, const int eCode) + { + onPostListener->onPostCallback(opts, rep, eCode); + }; + + return m_sharedAccountManager->signUp(authProvider, authCode, postCallback); +} + +OCStackResult JniOcAccountManager::signUp(JNIEnv* env, const std::string& authProvider, + const std::string& authCode, + const QueryParamsMap& options, jobject jListener) +{ + JniOnPostListener *onPostListener = addOnPostListener(env, jListener); + + PostCallback postCallback = [onPostListener](const HeaderOptions& opts, + const OCRepresentation& rep, const int eCode) + { + onPostListener->onPostCallback(opts, rep, eCode); + }; + + return m_sharedAccountManager->signUp(authProvider, authCode, options, postCallback); +} + +OCStackResult JniOcAccountManager::signIn(JNIEnv* env, const std::string& userUuid, + const std::string& accessToken, jobject jListener) +{ + JniOnPostListener *onPostListener = addOnPostListener(env, jListener); + + PostCallback postCallback = [onPostListener](const HeaderOptions& opts, + const OCRepresentation& rep, const int eCode) + { + onPostListener->onPostCallback(opts, rep, eCode); + }; + + return m_sharedAccountManager->signIn(userUuid, accessToken, postCallback); +} + +OCStackResult JniOcAccountManager::signOut(JNIEnv* env, jobject jListener) +{ + JniOnPostListener *onPostListener = addOnPostListener(env, jListener); + + PostCallback postCallback = [onPostListener](const HeaderOptions& opts, + const OCRepresentation& rep, const int eCode) + { + onPostListener->onPostCallback(opts, rep, eCode); + }; + + return m_sharedAccountManager->signOut(postCallback); +} + +OCStackResult JniOcAccountManager::refreshAccessToken(JNIEnv* env, const std::string& userUuid, + const std::string& refreshToken, + jobject jListener) +{ + JniOnPostListener *onPostListener = addOnPostListener(env, jListener); + + PostCallback postCallback = [onPostListener](const HeaderOptions& opts, + const OCRepresentation& rep, const int eCode) + { + onPostListener->onPostCallback(opts, rep, eCode); + }; + + return m_sharedAccountManager->refreshAccessToken(userUuid, refreshToken, postCallback); +} + +OCStackResult JniOcAccountManager::searchUser(JNIEnv* env, const std::string& userUuid, + jobject jListener) +{ + JniOnGetListener *onGetListener = addOnGetListener(env, jListener); + + GetCallback getCallback = [onGetListener](const HeaderOptions& opts, + const OCRepresentation& rep, const int eCode) + { + onGetListener->onGetCallback(opts, rep, eCode); + }; + + return m_sharedAccountManager->searchUser(userUuid, getCallback); +} + +OCStackResult JniOcAccountManager::searchUser(JNIEnv* env, const QueryParamsMap& queryMap, + jobject jListener) +{ + JniOnGetListener *onGetListener = addOnGetListener(env, jListener); + + GetCallback getCallback = [onGetListener](const HeaderOptions& opts, + const OCRepresentation& rep, const int eCode) + { + onGetListener->onGetCallback(opts, rep, eCode); + }; + + return m_sharedAccountManager->searchUser(queryMap, getCallback); +} + +OCStackResult JniOcAccountManager::deleteDevice(JNIEnv* env, const std::string& deviceId, + jobject jListener) +{ + JniOnDeleteListener *onDeleteListener = addOnDeleteListener(env, jListener); + + DeleteCallback deleteCallback = [onDeleteListener](const HeaderOptions& opts, + const int eCode) + { + onDeleteListener->onDeleteCallback(opts, eCode); + }; + + return m_sharedAccountManager->deleteDevice(deviceId, deleteCallback); +} + +OCStackResult JniOcAccountManager::createGroup(JNIEnv* env, AclGroupType groupType, + jobject jListener) +{ + JniOnPostListener *onPostListener = addOnPostListener(env, jListener); + + PostCallback postCallback = [onPostListener](const HeaderOptions& opts, + const OCRepresentation& rep, const int eCode) + { + onPostListener->onPostCallback(opts, rep, eCode); + }; + + return m_sharedAccountManager->createGroup(groupType, postCallback); +} + +OCStackResult JniOcAccountManager::getGroupList(JNIEnv* env, jobject jListener) +{ + JniOnGetListener *onGetListener = addOnGetListener(env, jListener); + + GetCallback getCallback = [onGetListener](const HeaderOptions& opts, + const OCRepresentation& rep, const int eCode) + { + onGetListener->onGetCallback(opts, rep, eCode); + }; + + return m_sharedAccountManager->getGroupList(getCallback); +} + +OCStackResult JniOcAccountManager::deleteGroup(JNIEnv* env, const std::string& groupId, + jobject jListener) +{ + JniOnDeleteListener *onDeleteListener = addOnDeleteListener(env, jListener); + + DeleteCallback deleteCallback = [onDeleteListener](const HeaderOptions& opts, + const int eCode) + { + onDeleteListener->onDeleteCallback(opts, eCode); + }; + + return m_sharedAccountManager->deleteGroup(groupId, deleteCallback); +} + +OCStackResult JniOcAccountManager::joinGroup(JNIEnv* env, const std::string& groupId, + jobject jListener) +{ + JniOnPostListener *onPostListener = addOnPostListener(env, jListener); + + PostCallback postCallback = [onPostListener](const HeaderOptions& opts, + const OCRepresentation& rep, const int eCode) + { + onPostListener->onPostCallback(opts, rep, eCode); + }; + + return m_sharedAccountManager->joinGroup(groupId, postCallback); +} + +OCStackResult JniOcAccountManager::addDeviceToGroup(JNIEnv* env, const std::string& groupId, + const std::vector& deviceId, + jobject jListener) +{ + JniOnPostListener *onPostListener = addOnPostListener(env, jListener); + + PostCallback postCallback = [onPostListener](const HeaderOptions& opts, + const OCRepresentation& rep, const int eCode) + { + onPostListener->onPostCallback(opts, rep, eCode); + }; + + return m_sharedAccountManager->addDeviceToGroup(groupId, deviceId, postCallback); +} + +OCStackResult JniOcAccountManager::getGroupInfo(JNIEnv* env, const std::string& groupId, + jobject jListener) +{ + JniOnGetListener *onGetListener = addOnGetListener(env, jListener); + + GetCallback getCallback = [onGetListener](const HeaderOptions& opts, + const OCRepresentation& rep, const int eCode) + { + onGetListener->onGetCallback(opts, rep, eCode); + }; + + return m_sharedAccountManager->getGroupInfo(groupId, getCallback); +} + +OCStackResult JniOcAccountManager::leaveGroup(JNIEnv* env, const std::string& groupId, + jobject jListener) +{ + JniOnDeleteListener *onDeleteListener = addOnDeleteListener(env, jListener); + + DeleteCallback deleteCallback = [onDeleteListener](const HeaderOptions& opts, + const int eCode) + { + onDeleteListener->onDeleteCallback(opts, eCode); + }; + + return m_sharedAccountManager->leaveGroup(groupId, deleteCallback); +} + +OCStackResult JniOcAccountManager::deleteDeviceFromGroup(JNIEnv* env, const std::string& groupId, + const std::vector& deviceId, + jobject jListener) +{ + JniOnDeleteListener *onDeleteListener = addOnDeleteListener(env, jListener); + + DeleteCallback deleteCallback = [onDeleteListener](const HeaderOptions& opts, + const int eCode) + { + onDeleteListener->onDeleteCallback(opts, eCode); + }; + + return m_sharedAccountManager->deleteDeviceFromGroup(groupId, deviceId, deleteCallback); +} + +OCStackResult JniOcAccountManager::observeGroup(JNIEnv* env, const std::string& groupId, + jobject jListener) +{ + JniOnObserveListener *onObserveListener = addOnObserveListener(env, jListener); + + ObserveCallback observeCallback = [onObserveListener](const HeaderOptions& opts, + const OCRepresentation& rep, const int& eCode, const int& sequenceNumber) + { + onObserveListener->onObserveCallback(opts, rep, eCode, sequenceNumber); + }; + + return m_sharedAccountManager->observeGroup(groupId, observeCallback); +} + +OCStackResult JniOcAccountManager::cancelObserveGroup(const std::string& groupId) +{ + return m_sharedAccountManager->cancelObserveGroup(groupId); +} + +OCStackResult JniOcAccountManager::observeInvitation(JNIEnv* env, jobject jListener) +{ + JniOnObserveListener *onObserveListener = addOnObserveListener(env, jListener); + + ObserveCallback observeCallback = [onObserveListener](const HeaderOptions& opts, + const OCRepresentation& rep, const int& eCode, const int& sequenceNumber) + { + onObserveListener->onObserveCallback(opts, rep, eCode, sequenceNumber); + }; + + return m_sharedAccountManager->observeInvitation(observeCallback); +} + +OCStackResult JniOcAccountManager::cancelObserveInvitation() +{ + return m_sharedAccountManager->cancelObserveInvitation(); +} + +OCStackResult JniOcAccountManager::sendInvitation(JNIEnv* env, const std::string& groupId, + const std::string& userUuid, jobject jListener) +{ + JniOnPostListener *onPostListener = addOnPostListener(env, jListener); + + PostCallback postCallback = [onPostListener](const HeaderOptions& opts, + const OCRepresentation& rep, const int eCode) + { + onPostListener->onPostCallback(opts, rep, eCode); + }; + + return m_sharedAccountManager->sendInvitation(groupId, userUuid, postCallback); +} + +OCStackResult JniOcAccountManager::cancelInvitation(JNIEnv* env, const std::string& groupId, + const std::string& userUuid, jobject jListener) +{ + JniOnDeleteListener *onDeleteListener = addOnDeleteListener(env, jListener); + + DeleteCallback deleteCallback = [onDeleteListener](const HeaderOptions& opts, + const int eCode) + { + onDeleteListener->onDeleteCallback(opts, eCode); + }; + + return m_sharedAccountManager->cancelInvitation(groupId, userUuid, deleteCallback); +} + +OCStackResult JniOcAccountManager::deleteInvitation(JNIEnv* env, const std::string& groupId, + jobject jListener) +{ + JniOnDeleteListener *onDeleteListener = addOnDeleteListener(env, jListener); + + DeleteCallback deleteCallback = [onDeleteListener](const HeaderOptions& opts, + const int eCode) + { + onDeleteListener->onDeleteCallback(opts, eCode); + }; + + return m_sharedAccountManager->deleteInvitation(groupId, deleteCallback); +} + + +/* +* Class: org_iotivity_base_OcAccountManager +* Method: getHost +* Signature: ()Ljava/lang/String; +*/ +JNIEXPORT jstring JNICALL Java_org_iotivity_base_OcAccountManager_getHost + (JNIEnv *env, jobject thiz) +{ + LOGD("OcAccountManager_getHost"); + JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, + thiz); + if (!accountManager) + { + return nullptr; + } + + return env->NewStringUTF(accountManager->host().c_str()); +} + +/* +* Class: org_iotivity_base_OcAccountManager +* Method: getConnectivityTypeN +* Signature: ()I +*/ +JNIEXPORT jint JNICALL Java_org_iotivity_base_OcAccountManager_getConnectivityTypeN + (JNIEnv *env, jobject thiz) +{ + LOGD("OcAccountManager_getConnectivityType"); + JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, + thiz); + if (!accountManager) + { + return -1; + } + + OCConnectivityType connectivityType = accountManager->connectivityType(); + return static_cast(connectivityType); +} + +/* +* Class: org_iotivity_base_OcAccountManager +* Method: signUp0 +* Signature: (Ljava/lang/String;Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/OnPostListener;)V +*/ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_signUp0 + (JNIEnv *env, jobject thiz, jstring jAuthProvider, jstring jAuthCode, jobject jListener) +{ + LOGD("OcAccountManager_signUp"); + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "onPostListener cannot be null"); + return; + } + + JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, + thiz); + if (!accountManager) + { + return; + } + + std::string authProvider; + std::string authCode; + if (jAuthProvider) + { + authProvider = env->GetStringUTFChars(jAuthProvider, nullptr); + } + if (jAuthCode) + { + authCode = env->GetStringUTFChars(jAuthCode, nullptr); + } + + try + { + OCStackResult result = accountManager->signUp(env, + authProvider, + authCode, + jListener); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcAccountManager_signUp"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +} + +/* +* Class: org_iotivity_base_OcAccountManager +* Method: signUp1 +* Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/util/Map;Lorg/iotivity/base/OcAccountManager/OnPostListener;)V +*/ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_signUp1 + (JNIEnv *env, jobject thiz, jstring jAuthProvider, jstring jAuthCode, jobject jOptionsMap, + jobject jListener) +{ + LOGD("OcAccountManager_signUp"); + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "onPostListener cannot be null"); + return; + } + if (!jOptionsMap) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "options cannot be null"); + return; + } + + JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, + thiz); + if (!accountManager) + { + return; + } + + std::string authProvider; + std::string authCode; + if (jAuthProvider) + { + authProvider = env->GetStringUTFChars(jAuthProvider, nullptr); + } + if (jAuthCode) + { + authCode = env->GetStringUTFChars(jAuthCode, nullptr); + } + + QueryParamsMap optionsMap; + JniUtils::convertJavaMapToQueryParamsMap(env, jOptionsMap, optionsMap); + + try + { + OCStackResult result = accountManager->signUp(env, + authProvider, + authCode, + optionsMap, + jListener); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcAccountManager_signUp"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +} + +/* +* Class: org_iotivity_base_OcAccountManager +* Method: signIn0 +* Signature: (Ljava/lang/String;Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/OnPostListener;)V +*/ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_signIn0 + (JNIEnv *env, jobject thiz, jstring jUserUuid, jstring jAccessToken, jobject jListener) +{ + LOGD("OcAccountManager_signIn"); + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "onPostListener cannot be null"); + return; + } + + JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, + thiz); + if (!accountManager) + { + return; + } + + std::string userUuid; + std::string accessToken; + if (jUserUuid) + { + userUuid = env->GetStringUTFChars(jUserUuid, nullptr); + } + if (jAccessToken) + { + accessToken = env->GetStringUTFChars(jAccessToken, nullptr); + } + + try + { + OCStackResult result = accountManager->signIn(env, + userUuid, + accessToken, + jListener); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcAccountManager_signIn"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +} + +/* +* Class: org_iotivity_base_OcAccountManager +* Method: signOut0 +* Signature: (Lorg/iotivity/base/OcAccountManager/OnPostListener;)V +*/ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_signOut0 + (JNIEnv *env, jobject thiz, jobject jListener) +{ + LOGD("OcAccountManager_signOut"); + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "onPostListener cannot be null"); + return; + } + + JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, + thiz); + if (!accountManager) + { + return; + } + + try + { + OCStackResult result = accountManager->signOut(env, + jListener); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcAccountManager_signOut"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +} + +/* +* Class: org_iotivity_base_OcAccountManager +* Method: refreshAccessToken0 +* Signature: (Ljava/lang/String;Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/OnPostListener;)V +*/ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_refreshAccessToken0 + (JNIEnv *env, jobject thiz, jstring jUserUuid, jstring jRefreshAccessToken, jobject jListener) +{ + LOGD("OcAccountManager_refreshAccessToken"); + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "onPostListener cannot be null"); + return; + } + + JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, + thiz); + if (!accountManager) + { + return; + } + + std::string userUuid; + std::string refreshAccessToken; + if (jUserUuid) + { + userUuid = env->GetStringUTFChars(jUserUuid, nullptr); + } + if (jRefreshAccessToken) + { + refreshAccessToken = env->GetStringUTFChars(jRefreshAccessToken, nullptr); + } + + try + { + OCStackResult result = accountManager->refreshAccessToken(env, + userUuid, + refreshAccessToken, + jListener); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcAccountManager_refreshAccessToken"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +} + +/* +* Class: org_iotivity_base_OcAccountManager +* Method: searchUser0 +* Signature: (Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/OnGetListener;)V +*/ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_searchUser0 + (JNIEnv *env, jobject thiz, jstring jUserUuid, jobject jListener) +{ + LOGD("OcAccountManager_searchUser"); + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "onGetListener cannot be null"); + return; + } + + JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, + thiz); + if (!accountManager) + { + return; + } + + std::string userUuid; + if (jUserUuid) + { + userUuid = env->GetStringUTFChars(jUserUuid, nullptr); + } + + try + { + OCStackResult result = accountManager->searchUser(env, + userUuid, + jListener); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcAccountManager_searchUser"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +} + +/* +* Class: org_iotivity_base_OcAccountManager +* Method: searchUser1 +* Signature: (Ljava/util/Map;Lorg/iotivity/base/OcAccountManager/OnGetListener;)V +*/ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_searchUser1 + (JNIEnv *env, jobject thiz, jobject jQueryMap, jobject jListener) +{ + LOGD("OcAccountManager_searchUser"); + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "onGetListener cannot be null"); + return; + } + if (!jQueryMap) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "queryMap cannot be null"); + return; + } + + JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, + thiz); + if (!accountManager) + { + return; + } + + QueryParamsMap queryMap; + JniUtils::convertJavaMapToQueryParamsMap(env, jQueryMap, queryMap); + + try + { + OCStackResult result = accountManager->searchUser(env, + queryMap, + jListener); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcAccountManager_searchUser"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +} + +/* +* Class: org_iotivity_base_OcAccountManager +* Method: deleteDevice0 +* Signature: (Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/onDeleteListener;)V +*/ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_deleteDevice0 + (JNIEnv *env, jobject thiz, jstring jDeviceId, jobject jListener) +{ + LOGD("OcAccountManager_deleteDevice"); + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "onDeleteListener cannot be null"); + return; + } + + JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, + thiz); + if (!accountManager) + { + return; + } + + std::string deviceId; + if (jDeviceId) + { + deviceId = env->GetStringUTFChars(jDeviceId, nullptr); + } + + try + { + OCStackResult result = accountManager->deleteDevice(env, + deviceId, + jListener); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcAccountManager_deleteDevice"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +} + +/* +* Class: org_iotivity_base_OcAccountManager +* Method: createGroup0 +* Signature: (Lorg/iotivity/base/AclGroupType;Lorg/iotivity/base/OcAccountManager/OnPostListener;)V +*/ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_createGroup0 + (JNIEnv *env, jobject thiz, jint groupType, jobject jListener) +{ + LOGD("OcAccountManager_createGroup"); + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "onPostListener cannot be null"); + return; + } + + JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, + thiz); + if (!accountManager) + { + return; + } + + try + { + OCStackResult result = accountManager->createGroup(env, + JniUtils::getAclGroupType(env, static_cast(groupType)), + jListener); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcAccountManager_createGroup"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +} + +/* +* Class: org_iotivity_base_OcAccountManager +* Method: getGroupList0 +* Signature: (Lorg/iotivity/base/OcAccountManager/OnGetListener;)V +*/ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_getGroupList0 + (JNIEnv *env, jobject thiz, jobject jListener) +{ + LOGD("OcAccountManager_getGroupList"); + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "onGetListener cannot be null"); + return; + } + + JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, + thiz); + if (!accountManager) + { + return; + } + + try + { + OCStackResult result = accountManager->getGroupList(env, + jListener); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcAccountManager_getGroupList"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +} + +/* +* Class: org_iotivity_base_OcAccountManager +* Method: deleteGroup0 +* Signature: (Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/onDeleteListener;)V +*/ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_deleteGroup0 + (JNIEnv *env, jobject thiz, jstring jGroupId, jobject jListener) +{ + LOGD("OcAccountManager_deleteGroup"); + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "onDeleteListener cannot be null"); + return; + } + + JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, + thiz); + if (!accountManager) + { + return; + } + + std::string groupId; + if (jGroupId) + { + groupId = env->GetStringUTFChars(jGroupId, nullptr); + } + + try + { + OCStackResult result = accountManager->deleteGroup(env, + groupId, + jListener); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcAccountManager_deleteGroup"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +} + +/* +* Class: org_iotivity_base_OcAccountManager +* Method: joinGroup0 +* Signature: (Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/OnPostListener;)V +*/ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_joinGroup0 + (JNIEnv *env, jobject thiz, jstring jGroupId, jobject jListener) +{ + LOGD("OcAccountManager_joinGroup"); + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "onPostListener cannot be null"); + return; + } + + JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, + thiz); + if (!accountManager) + { + return; + } + + std::string groupId; + if (jGroupId) + { + groupId = env->GetStringUTFChars(jGroupId, nullptr); + } + + try + { + OCStackResult result = accountManager->joinGroup(env, + groupId, + jListener); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcAccountManager_joinGroup"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +} + +/* +* Class: org_iotivity_base_OcAccountManager +* Method: addDeviceToGroup0 +* Signature: (Ljava/lang/String;[Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/OnPostListener;)V +*/ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_addDeviceToGroup0 + (JNIEnv *env, jobject thiz, jstring jGroupId, jobjectArray jDeviceIdArray, jobject jListener) +{ + LOGD("OcAccountManager_addDeviceToGroup"); + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "onPostListener cannot be null"); + return; + } + if (!jDeviceIdArray) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "deviceId cannot be null"); + return; + } + + JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, + thiz); + if (!accountManager) + { + return; + } + + std::string groupId; + if (jGroupId) + { + groupId = env->GetStringUTFChars(jGroupId, nullptr); + } + + std::vector deviceIds; + JniUtils::convertJavaStrArrToStrVector(env, jDeviceIdArray, deviceIds); + + try + { + OCStackResult result = accountManager->addDeviceToGroup(env, + groupId, + deviceIds, + jListener); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcAccountManager_addDeviceToGroup"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +} + +/* +* Class: org_iotivity_base_OcAccountManager +* Method: getGroupInfo0 +* Signature: (Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/OnGetListener;)V +*/ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_getGroupInfo0 + (JNIEnv *env, jobject thiz, jstring jGroupId, jobject jListener) +{ + LOGD("OcAccountManager_getGroupInfo"); + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "onGetListener cannot be null"); + return; + } + + JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, + thiz); + if (!accountManager) + { + return; + } + + std::string groupId; + if (jGroupId) + { + groupId = env->GetStringUTFChars(jGroupId, nullptr); + } + + try + { + OCStackResult result = accountManager->getGroupInfo(env, + groupId, + jListener); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcAccountManager_getGroupInfo"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +} + +/* +* Class: org_iotivity_base_OcAccountManager +* Method: leaveGroup0 +* Signature: (Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/onDeleteListener;)V +*/ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_leaveGroup0 + (JNIEnv *env, jobject thiz, jstring jGroupId, jobject jListener) +{ + LOGD("OcAccountManager_leaveGroup"); + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "onDeleteListener cannot be null"); + return; + } + + JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, + thiz); + if (!accountManager) + { + return; + } + + std::string groupId; + if (jGroupId) + { + groupId = env->GetStringUTFChars(jGroupId, nullptr); + } + + try + { + OCStackResult result = accountManager->leaveGroup(env, + groupId, + jListener); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcAccountManager_leaveGroup"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +} + +/* +* Class: org_iotivity_base_OcAccountManager +* Method: deleteDeviceFromGroup0 +* Signature: (Ljava/lang/String;[Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/onDeleteListener;)V +*/ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_deleteDeviceFromGroup0 + (JNIEnv *env, jobject thiz, jstring jGroupId, jobjectArray jDeviceIdArray, jobject jListener) +{ + LOGD("OcAccountManager_deleteDeviceFromGroup"); + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "onDeleteListener cannot be null"); + return; + } + if (!jDeviceIdArray) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "deviceId cannot be null"); + return; + } + + JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, + thiz); + if (!accountManager) + { + return; + } + + std::string groupId; + if (jGroupId) + { + groupId = env->GetStringUTFChars(jGroupId, nullptr); + } + + std::vector deviceIds; + JniUtils::convertJavaStrArrToStrVector(env, jDeviceIdArray, deviceIds); + + try + { + OCStackResult result = accountManager->deleteDeviceFromGroup(env, + groupId, + deviceIds, + jListener); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcAccountManager_deleteDeviceFromGroup"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +} + +/* +* Class: org_iotivity_base_OcAccountManager +* Method: observeGroup0 +* Signature: (Ljava/lang/String;Lorg/iotivity/base/OcResource/OnObserveListener;)V +*/ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_observeGroup0 + (JNIEnv *env, jobject thiz, jstring jGroupId, jobject jListener) +{ + LOGD("OcAccountManager_observeGroup"); + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "onObserveListener cannot be null"); + return; + } + + JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, + thiz); + if (!accountManager) + { + return; + } + + std::string groupId; + if (jGroupId) + { + groupId = env->GetStringUTFChars(jGroupId, nullptr); + } + + try + { + OCStackResult result = accountManager->observeGroup(env, + groupId, + jListener); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcAccountManager_observeGroup"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +} + +/* +* Class: org_iotivity_base_OcAccountManager +* Method: cancelObserveGroup0 +* Signature: (Ljava/lang/String;)V +*/ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_cancelObserveGroup0 + (JNIEnv *env, jobject thiz, jstring jGroupId) +{ + LOGD("OcAccountManager_cancelObserveGroup"); + + JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, + thiz); + if (!accountManager) + { + return; + } + + std::string groupId; + if (jGroupId) + { + groupId = env->GetStringUTFChars(jGroupId, nullptr); + } + + try + { + OCStackResult result = accountManager->cancelObserveGroup(groupId); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcAccountManager_cancelObserveGroup"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +} + +/* +* Class: org_iotivity_base_OcAccountManager +* Method: observeInvitation0 +* Signature: (Lorg/iotivity/base/OcResource/OnObserveListener;)V +*/ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_observeInvitation0 + (JNIEnv *env, jobject thiz, jobject jListener) +{ + LOGD("OcAccountManager_observeInvitation"); + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "onObserveListener cannot be null"); + return; + } + + JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, + thiz); + if (!accountManager) + { + return; + } + + try + { + OCStackResult result = accountManager->observeInvitation(env, + jListener); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcAccountManager_observeInvitation"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +} + +/* +* Class: org_iotivity_base_OcAccountManager +* Method: cancelObserveInvitation0 +* Signature: ()V +*/ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_cancelObserveInvitation0 + (JNIEnv *env, jobject thiz) +{ + LOGD("OcAccountManager_cancelObserveInvitation"); + + JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, + thiz); + if (!accountManager) + { + return; + } + + try + { + OCStackResult result = accountManager->cancelObserveInvitation(); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcAccountManager_cancelObserveInvitation"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +} + +/* +* Class: org_iotivity_base_OcAccountManager +* Method: sendInvitation0 +* Signature: (Ljava/lang/String;Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/OnPostListener;)V +*/ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_sendInvitation0 + (JNIEnv *env, jobject thiz, jstring jGroupId, jstring jUserUuid, jobject jListener) +{ + LOGD("OcAccountManager_sendInvitation"); + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "onPostListener cannot be null"); + return; + } + + JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, + thiz); + if (!accountManager) + { + return; + } + + std::string groupId, userUuid; + if (jGroupId) + { + groupId = env->GetStringUTFChars(jGroupId, nullptr); + } + if (jUserUuid) + { + userUuid = env->GetStringUTFChars(jUserUuid, nullptr); + } + + try + { + OCStackResult result = accountManager->sendInvitation(env, + groupId, + userUuid, + jListener); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcAccountManager_sendInvitation"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +} + +/* +* Class: org_iotivity_base_OcAccountManager +* Method: cancelInvitation0 +* Signature: (Ljava/lang/String;Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/onDeleteListener;)V +*/ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_cancelInvitation0 + (JNIEnv *env, jobject thiz, jstring jGroupId, jstring jUserUuid, jobject jListener) +{ + LOGD("OcAccountManager_cancelInvitation"); + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "onDeleteListener cannot be null"); + return; + } + + JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, + thiz); + if (!accountManager) + { + return; + } + + std::string groupId, userUuid; + if (jGroupId) + { + groupId = env->GetStringUTFChars(jGroupId, nullptr); + } + if (jUserUuid) + { + userUuid = env->GetStringUTFChars(jUserUuid, nullptr); + } + + try + { + OCStackResult result = accountManager->cancelInvitation(env, + groupId, + userUuid, + jListener); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcAccountManager_cancelInvitation"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +} + +/* +* Class: org_iotivity_base_OcAccountManager +* Method: deleteInvitation0 +* Signature: (Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/onDeleteListener;)V +*/ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_deleteInvitation0 + (JNIEnv *env, jobject thiz, jstring jGroupId, jobject jListener) +{ + LOGD("OcAccountManager_deleteInvitation"); + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "onDeleteListener cannot be null"); + return; + } + + JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, + thiz); + if (!accountManager) + { + return; + } + + std::string groupId; + if (jGroupId) + { + groupId = env->GetStringUTFChars(jGroupId, nullptr); + } + + try + { + OCStackResult result = accountManager->deleteInvitation(env, + groupId, + jListener); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcAccountManager_deleteInvitation"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +} + + diff --git a/android/android_api/base/jni/JniOcAccountManager.h b/android/android_api/base/jni/JniOcAccountManager.h new file mode 100644 index 000000000..7ff841e6d --- /dev/null +++ b/android/android_api/base/jni/JniOcAccountManager.h @@ -0,0 +1,308 @@ +/* + ******************************************************************* + * + * Copyright 2016 Samsung Electronics All Rights Reserved. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + */ + +#ifndef _Included_org_iotivity_base_OcAccountManager +#define _Included_org_iotivity_base_OcAccountManager + +#include "JniOcStack.h" +#include "OCAccountManager.h" +#include "JniListenerManager.h" +#include "JniOnGetListener.h" +#include "JniOnPostListener.h" +#include "JniOnDeleteListener.h" +#include "JniOnObserveListener.h" + +using namespace OC; + +class JniOcAccountManager +{ +public: + JniOcAccountManager(std::shared_ptr accountManager); + ~JniOcAccountManager(); + + std::string host(); + OCConnectivityType connectivityType() const; + + static JniOcAccountManager* getJniOcAccountManagerPtr(JNIEnv *env, jobject thiz); + + OCStackResult signUp(JNIEnv* env, const std::string& authProvider, const std::string& authCode, + jobject jListener); + OCStackResult signUp(JNIEnv* env, const std::string& authProvider, const std::string& authCode, + const QueryParamsMap& options, jobject jListener); + OCStackResult signIn(JNIEnv* env, const std::string& userUuid, const std::string& accessToken, + jobject jListener); + OCStackResult signOut(JNIEnv* env, jobject jListener); + OCStackResult refreshAccessToken(JNIEnv* env, const std::string& userUuid, + const std::string& refreshToken, jobject jListener); + OCStackResult searchUser(JNIEnv* env, const std::string& userUuid, jobject jListener); + OCStackResult searchUser(JNIEnv* env, const QueryParamsMap& queryMap, jobject jListener); + OCStackResult deleteDevice(JNIEnv* env, const std::string& deviceId, jobject jListener); + OCStackResult createGroup(JNIEnv* env, AclGroupType groupType, jobject jListener); + OCStackResult getGroupList(JNIEnv* env, jobject jListener); + OCStackResult deleteGroup(JNIEnv* env, const std::string& groupId, jobject jListener); + OCStackResult joinGroup(JNIEnv* env, const std::string& groupId, jobject jListener); + OCStackResult addDeviceToGroup(JNIEnv* env, const std::string& groupId, + const std::vector& deviceId, jobject jListener); + OCStackResult getGroupInfo(JNIEnv* env, const std::string& groupId, jobject jListener); + OCStackResult leaveGroup(JNIEnv* env, const std::string& groupId, jobject jListener); + OCStackResult deleteDeviceFromGroup(JNIEnv* env, const std::string& groupId, + const std::vector& deviceId, + jobject jListener); + OCStackResult observeGroup(JNIEnv* env, const std::string& groupId, jobject jListener); + OCStackResult cancelObserveGroup(const std::string& groupId); + OCStackResult observeInvitation(JNIEnv* env, jobject jListener); + OCStackResult cancelObserveInvitation(); + OCStackResult sendInvitation(JNIEnv* env, const std::string& groupId, + const std::string& userUuid, jobject jListener); + OCStackResult cancelInvitation(JNIEnv* env, const std::string& groupId, + const std::string& userUuid, jobject jListener); + OCStackResult deleteInvitation(JNIEnv* env, const std::string& groupId, jobject jListener); + + JniOnGetListener* addOnGetListener(JNIEnv* env, jobject jListener); + JniOnPostListener* addOnPostListener(JNIEnv* env, jobject jListener); + JniOnDeleteListener* addOnDeleteListener(JNIEnv* env, jobject jListener); + JniOnObserveListener* addOnObserveListener(JNIEnv* env, jobject jListener); + + void removeOnGetListener(JNIEnv* env, jobject jListener); + void removeOnPostListener(JNIEnv* env, jobject jListener); + void removeOnDeleteListener(JNIEnv* env, jobject jListener); + void removeOnObserveListener(JNIEnv* env, jobject jListener); + +private: + JniListenerManager m_onGetManager; + JniListenerManager m_onPostManager; + JniListenerManager m_onDeleteManager; + JniListenerManager m_onObserveManager; + + std::shared_ptr m_sharedAccountManager; +}; + +/* DO NOT EDIT THIS FILE BEYOND THIS LINE - it is machine generated */ + +#ifdef __cplusplus +extern "C" { +#endif + + /* + * Class: org_iotivity_base_OcAccountManager + * Method: getHost + * Signature: ()Ljava/lang/String; + */ + JNIEXPORT jstring JNICALL Java_org_iotivity_base_OcAccountManager_getHost + (JNIEnv *, jobject); + + /* + * Class: org_iotivity_base_OcAccountManager + * Method: getConnectivityTypeN + * Signature: ()I + */ + JNIEXPORT jint JNICALL Java_org_iotivity_base_OcAccountManager_getConnectivityTypeN + (JNIEnv *, jobject); + + /* + * Class: org_iotivity_base_OcAccountManager + * Method: signUp0 + * Signature: (Ljava/lang/String;Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/OnPostListener;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_signUp0 + (JNIEnv *, jobject, jstring, jstring, jobject); + + /* + * Class: org_iotivity_base_OcAccountManager + * Method: signUp1 + * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/util/Map;Lorg/iotivity/base/OcAccountManager/OnPostListener;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_signUp1 + (JNIEnv *, jobject, jstring, jstring, jobject, jobject); + + /* + * Class: org_iotivity_base_OcAccountManager + * Method: signIn0 + * Signature: (Ljava/lang/String;Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/OnPostListener;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_signIn0 + (JNIEnv *, jobject, jstring, jstring, jobject); + + /* + * Class: org_iotivity_base_OcAccountManager + * Method: signOut0 + * Signature: (Lorg/iotivity/base/OcAccountManager/OnPostListener;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_signOut0 + (JNIEnv *, jobject, jobject); + + /* + * Class: org_iotivity_base_OcAccountManager + * Method: refreshAccessToken0 + * Signature: (Ljava/lang/String;Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/OnPostListener;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_refreshAccessToken0 + (JNIEnv *, jobject, jstring, jstring, jobject); + + /* + * Class: org_iotivity_base_OcAccountManager + * Method: searchUser0 + * Signature: (Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/OnGetListener;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_searchUser0 + (JNIEnv *env, jobject thiz, jstring juserUuid, jobject jListener); + + /* + * Class: org_iotivity_base_OcAccountManager + * Method: searchUser1 + * Signature: (Ljava/util/Map;Lorg/iotivity/base/OcAccountManager/OnGetListener;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_searchUser1 + (JNIEnv *env, jobject thiz, jobject jQueryMap, jobject jListener); + + /* + * Class: org_iotivity_base_OcAccountManager + * Method: deleteDevice0 + * Signature: (Ljava/lang/String;Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/onDeleteListener;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_deleteDevice0 + (JNIEnv *env, jobject thiz, jstring jDeviceId, jobject jListener); + + /* + * Class: org_iotivity_base_OcAccountManager + * Method: createGroup0 + * Signature: (Lorg/iotivity/base/AclGroupType;Lorg/iotivity/base/OcAccountManager/OnPostListener;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_createGroup0 + (JNIEnv *env, jobject thiz, jint groupType, jobject jListener); + + /* + * Class: org_iotivity_base_OcAccountManager + * Method: getGroupList0 + * Signature: (Lorg/iotivity/base/OcAccountManager/OnGetListener;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_getGroupList0 + (JNIEnv *env, jobject thiz, jobject jListener); + + /* + * Class: org_iotivity_base_OcAccountManager + * Method: deleteGroup0 + * Signature: (Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/onDeleteListener;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_deleteGroup0 + (JNIEnv *env, jobject thiz, jstring jGroupId, jobject jListener); + + /* + * Class: org_iotivity_base_OcAccountManager + * Method: joinGroup0 + * Signature: (Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/OnPostListener;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_joinGroup0 + (JNIEnv *env, jobject thiz, jstring jGroupId, jobject jListener); + + /* + * Class: org_iotivity_base_OcAccountManager + * Method: addDeviceToGroup0 + * Signature: (Ljava/lang/String;[Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/OnPostListener;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_addDeviceToGroup0 + (JNIEnv *env, jobject thiz, jstring jGroupId, jobjectArray jDeviceIdArray, jobject jListener); + + /* + * Class: org_iotivity_base_OcAccountManager + * Method: getGroupInfo0 + * Signature: (Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/OnGetListener;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_getGroupInfo0 + (JNIEnv *env, jobject thiz, jstring jGroupId, jobject jListener); + + /* + * Class: org_iotivity_base_OcAccountManager + * Method: leaveGroup0 + * Signature: (Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/onDeleteListener;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_leaveGroup0 + (JNIEnv *env, jobject thiz, jstring jGroupId, jobject jListener); + + /* + * Class: org_iotivity_base_OcAccountManager + * Method: deleteDeviceFromGroup0 + * Signature: (Ljava/lang/String;[Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/onDeleteListener;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_deleteDeviceFromGroup0 + (JNIEnv *env, jobject thiz, jstring jGroupId, jobjectArray jDeviceIdArray, jobject jListener); + + /* + * Class: org_iotivity_base_OcAccountManager + * Method: observeGroup0 + * Signature: (Ljava/lang/String;Lorg/iotivity/base/OcResource/OnObserveListener;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_observeGroup0 + (JNIEnv *env, jobject thiz, jstring jGroupId, jobject jListener); + + /* + * Class: org_iotivity_base_OcAccountManager + * Method: cancelObserveGroup0 + * Signature: (Ljava/lang/String;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_cancelObserveGroup0 + (JNIEnv *env, jobject thiz, jstring jGroupId); + + /* + * Class: org_iotivity_base_OcAccountManager + * Method: observeInvitation0 + * Signature: (Lorg/iotivity/base/OcResource/OnObserveListener;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_observeInvitation0 + (JNIEnv *env, jobject thiz, jobject jListener); + + /* + * Class: org_iotivity_base_OcAccountManager + * Method: cancelObserveInvitation0 + * Signature: ()V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_cancelObserveInvitation0 + (JNIEnv *env, jobject thiz); + + /* + * Class: org_iotivity_base_OcAccountManager + * Method: sendInvitation0 + * Signature: (Ljava/lang/String;Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/OnPostListener;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_sendInvitation0 + (JNIEnv *env, jobject thiz, jstring jGroupId, jstring jUserUuid, jobject jListener); + + /* + * Class: org_iotivity_base_OcAccountManager + * Method: cancelInvitation0 + * Signature: (Ljava/lang/String;Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/onDeleteListener;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_cancelInvitation0 + (JNIEnv *env, jobject thiz, jstring jGroupId, jstring jUserUuid, jobject jListener); + + /* + * Class: org_iotivity_base_OcAccountManager + * Method: deleteInvitation0 + * Signature: (Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/onDeleteListener;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_deleteInvitation0 + (JNIEnv *env, jobject thiz, jstring jGroupId, jobject jListener); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/android/android_api/base/jni/JniOcCloudProvisioning.cpp b/android/android_api/base/jni/JniOcCloudProvisioning.cpp new file mode 100644 index 000000000..c1bac6a22 --- /dev/null +++ b/android/android_api/base/jni/JniOcCloudProvisioning.cpp @@ -0,0 +1,576 @@ +/* +* //****************************************************************** +* // +* // Copyright 2016 Samsung Electronics All Rights Reserved. +* // +* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +* // +* // Licensed under the Apache License, Version 2.0 (the "License"); +* // you may not use this file except in compliance with the License. +* // You may obtain a copy of the License at +* // +* // http://www.apache.org/licenses/LICENSE-2.0 +* // +* // Unless required by applicable law or agreed to in writing, software +* // distributed under the License is distributed on an "AS IS" BASIS, +* // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* // See the License for the specific language governing permissions and +* // limitations under the License. +* // +* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +*/ + +#include "JniOcCloudProvisioning.h" +#include "oic_malloc.h" + +namespace PH = std::placeholders; + +JniOcCloudProvisioning::JniOcCloudProvisioning(std::shared_ptr p) + : m_sharedCloudObject(p) +{} + +JniOcCloudProvisioning::~JniOcCloudProvisioning() +{ + LOGD("~JniOcCloudProvisioning"); + m_sharedCloudObject = nullptr; +} + +JniOcCloudResultListener* JniOcCloudProvisioning::AddCloudResultListener(JNIEnv* env, + jobject jListener) +{ + JniOcCloudResultListener *resultListener = NULL; + resultMapLock.lock(); + + for (auto it = resultMap.begin(); it != resultMap.end(); ++it) + { + if (env->IsSameObject(jListener, it->first)) + { + auto refPair = it->second; + resultListener = refPair.first; + refPair.second++; + it->second = refPair; + resultMap.insert(*it); + LOGD("Cloud Provision resultListener: ref. count incremented"); + break; + } + } + if (!resultListener) + { + resultListener = new JniOcCloudResultListener(env, jListener, + RemoveCallback(std::bind(&JniOcCloudProvisioning::RemoveCloudResultListener, + this, PH::_1, PH::_2))); + jobject jgListener = env->NewGlobalRef(jListener); + + resultMap.insert(std::pair < jobject, std::pair < JniOcCloudResultListener*, + int >> (jgListener, std::pair(resultListener, 1))); + LOGD("Cloud Provision resultListener: new listener"); + } + resultMapLock.unlock(); + return resultListener; +} + +void JniOcCloudProvisioning::RemoveCloudResultListener(JNIEnv* env, jobject jListener) +{ + resultMapLock.lock(); + + for (auto it = resultMap.begin(); it != resultMap.end(); ++it) + { + if (env->IsSameObject(jListener, it->first)) + { + auto refPair = it->second; + if (refPair.second > 1) + { + refPair.second--; + it->second = refPair; + resultMap.insert(*it); + LOGI("Cloud Provision resultListener: ref. count decremented"); + } + else + { + env->DeleteGlobalRef(it->first); + JniOcCloudResultListener* listener = refPair.first; + delete listener; + resultMap.erase(it); + LOGI("Cloud Provision resultListener removed"); + } + break; + } + } + resultMapLock.unlock(); +} + +JniGetAclIdByDeviceListener* JniOcCloudProvisioning::AddGetAclByDeviceListener(JNIEnv* env, + jobject jListener) +{ + JniGetAclIdByDeviceListener *resultListener = NULL; + aclresultMapLock.lock(); + + for (auto it = aclresultMap.begin(); it != aclresultMap.end(); ++it) + { + if (env->IsSameObject(jListener, it->first)) + { + auto refPair = it->second; + resultListener = refPair.first; + refPair.second++; + it->second = refPair; + aclresultMap.insert(*it); + LOGD("GetACLByDeviceID Listener: ref. count incremented"); + break; + } + } + if (!resultListener) + { + resultListener = new JniGetAclIdByDeviceListener(env, jListener, + RemoveCallback(std::bind(&JniOcCloudProvisioning::RemoveGetAclByDeviceIdListener, + this, PH::_1, PH::_2))); + jobject jgListener = env->NewGlobalRef(jListener); + + aclresultMap.insert(std::pair < jobject, std::pair < JniGetAclIdByDeviceListener*, + int >> (jgListener, std::pair(resultListener, 1))); + LOGD("GetACLByDeviceID Listener: new listener"); + } + aclresultMapLock.unlock(); + return resultListener; +} + +void JniOcCloudProvisioning::RemoveGetAclByDeviceIdListener(JNIEnv* env, jobject jListener) +{ + aclresultMapLock.lock(); + + for (auto it = aclresultMap.begin(); it != aclresultMap.end(); ++it) + { + if (env->IsSameObject(jListener, it->first)) + { + auto refPair = it->second; + if (refPair.second > 1) + { + refPair.second--; + it->second = refPair; + aclresultMap.insert(*it); + LOGI("GetACLByDeviceID Listener: ref. count decremented"); + } + else + { + env->DeleteGlobalRef(it->first); + JniGetAclIdByDeviceListener* listener = refPair.first; + delete listener; + aclresultMap.erase(it); + LOGI("GetACLByDeviceID Listener removed"); + } + break; + } + } + aclresultMapLock.unlock(); +} +JniOcCloudProvisioning * Create_native_object(JNIEnv *env, jobject thiz) +{ + jstring jip = (jstring)env->CallObjectMethod(thiz, g_mid_OcCloudProvisioning_getIP); + if (!jip || env->ExceptionCheck()) + { + return nullptr; + } + const char *str = env->GetStringUTFChars(jip, NULL); + std::string ipaddress(str); + env->ReleaseStringUTFChars(jip, str); + + jint port = env->CallIntMethod(thiz, g_mid_OcCloudProvisioning_getPort); + if (env->ExceptionCheck()) + { + return nullptr; + } + JniOcCloudProvisioning *cloud = new JniOcCloudProvisioning( + std::shared_ptr(new OCCloudProvisioning(ipaddress, (uint16_t)port))); + SetHandle(env, thiz, cloud); + return cloud; +} + +JniOcCloudProvisioning* JniOcCloudProvisioning::getJniOcCloudProvisioningPtr(JNIEnv *env, jobject thiz) +{ + JniOcCloudProvisioning *cloud = GetHandle(env, thiz); + + if (env->ExceptionCheck()) + { + LOGE("Failed to get native handle from OcCloudProvisioning class"); + } + + return cloud; +} + +OCStackResult JniOcCloudProvisioning::requestCertificate(JNIEnv* env, jobject jListener) +{ + JniOcCloudResultListener *resultListener = AddCloudResultListener(env, jListener); + + ResponseCallBack responseCallBack = [resultListener](OCStackResult result, void *data) + { + resultListener->CloudResultListenerCB(result, data, ListenerFunc::REQUEST_CERTIFICATE); + }; + + return m_sharedCloudObject->requestCertificate(responseCallBack); +} + +OCStackResult JniOcCloudProvisioning::getIndividualAclInfo(JNIEnv* env, jobject jListener, std::string &aclID) +{ + JniOcCloudResultListener *resultListener = AddCloudResultListener(env, jListener); + + ResponseCallBack responseCallBack = [resultListener](OCStackResult result, void *data) + { + resultListener->CloudResultListenerCB(result, data, ListenerFunc::GET_ACLINFO); + }; + + return m_sharedCloudObject->getIndividualAclInfo(aclID, responseCallBack); +} + +OCStackResult JniOcCloudProvisioning::getCRL(JNIEnv* env, jobject jListener) +{ + JniOcCloudResultListener *resultListener = AddCloudResultListener(env, jListener); + + ResponseCallBack responseCallBack = [resultListener](OCStackResult result, void *data) + { + resultListener->CloudResultListenerCB(result, data, ListenerFunc::GET_CRL); + }; + + return m_sharedCloudObject->getCRL(responseCallBack); +} + +OCStackResult JniOcCloudProvisioning::postCRL(JNIEnv* env, const std::string& thisUpdate, + const std::string& nextUpdate, const OCByteString *crl, + const stringArray_t *serialNumbers, jobject jListener) +{ + JniOcCloudResultListener *resultListener = AddCloudResultListener(env, jListener); + + ResponseCallBack responseCallBack = [resultListener](OCStackResult result, void *data) + { + resultListener->CloudResultListenerCB(result, data, ListenerFunc::POST_CRL); + }; + + return m_sharedCloudObject->postCRL(thisUpdate, nextUpdate, crl, serialNumbers, + responseCallBack); +} + +OCStackResult JniOcCloudProvisioning::getAclIdByDevice(JNIEnv* env, std::string deviceId, + jobject jListener) +{ + JniGetAclIdByDeviceListener *resultListener = AddGetAclByDeviceListener(env, jListener); + + AclIdResponseCallBack aclIdResponseCallBack = [resultListener](OCStackResult result, + std::string aclId) + { + resultListener->GetAclIdByDeviceListenerCB(result, aclId); + }; + + return m_sharedCloudObject->getAclIdByDevice(deviceId, aclIdResponseCallBack); +} +/* + * Class: org_iotivity_base_OcCloudProvisioning + * Method: requestCertificate + * Signature: (Lorg/iotivity/base/OcCloudProvisioning/RequestCertificateListener;)V + */ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcCloudProvisioning_requestCertificate + (JNIEnv* env, jobject thiz, jobject jListener) +{ + LOGD("OcCloudProvisioning_requestCertificate"); + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_CALLBACK, "Listener cannot be null"); + return; + } + + JniOcCloudProvisioning *cloud = JniOcCloudProvisioning::getJniOcCloudProvisioningPtr(env, thiz); + if (!cloud) + { + LOGD("OcCloudProvisioning_requestCertificate, No native object, creating now"); + cloud = Create_native_object(env, thiz); + if (!cloud) + { + ThrowOcException(OC_STACK_ERROR, "OcCloudProvisioning_requestCertificate," + "Can not Create Native object"); + return; + } + } + + try + { + OCStackResult result = cloud->requestCertificate(env, jListener); + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcCloudProvisioning_requestCertificate"); + return; + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } + return; +} + +/* + * Class: org_iotivity_base_OcCloudProvisioning + * Method: getAclIdByDevice + * Signature: (Ljava/lang/String;Lorg/iotivity/base/OcCloudProvisioning/GetAclIdByDeviceListener;)V + */ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcCloudProvisioning_getAclIdByDevice + (JNIEnv *env, jobject thiz, jstring jdeviceId, jobject jListener) +{ + LOGD("OcCloudProvisioning_getAclIdByDevice"); + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_CALLBACK, "Listener cannot be null"); + return; + } + + if (!jdeviceId) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "deviceID can not be null"); + return; + } + JniOcCloudProvisioning *cloud = JniOcCloudProvisioning::getJniOcCloudProvisioningPtr(env, thiz); + if (!cloud) + { + LOGD("OcCloudProvisioning_getAclIdByDevice, No native object, creating now"); + cloud = Create_native_object(env, thiz); + if (!cloud) + { + ThrowOcException(OC_STACK_ERROR, "OcCloudProvisioning_getAclIdByDevice," + "Can not Create Native object"); + return; + } + } + + const char *str = env->GetStringUTFChars(jdeviceId, NULL); + if (!str || env->ExceptionCheck()) + { + ThrowOcException(OC_STACK_ERROR,"OcCloudProvisioning_getAclIdByDevice"); + return; + } + std::string deviceId(str); + env->ReleaseStringUTFChars(jdeviceId, str); + + try + { + OCStackResult result = cloud->getAclIdByDevice(env, deviceId, jListener); + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcCloudProvisioning_getAclIdByDevice"); + return; + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } + return; +} + +/* + * Class: org_iotivity_base_OcCloudProvisioning + * Method: getIndividualAclInfo + * Signature: (Ljava/lang/String;Lorg/iotivity/base/OcCloudProvisioning/GetIndividualAclInfoListener;)V + */ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcCloudProvisioning_getIndividualAclInfo + (JNIEnv *env, jobject thiz, jstring jaclID, jobject jListener) +{ + LOGD("OcCloudProvisioning_getIndividualAclInfo"); + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_CALLBACK, "Listener cannot be null"); + return; + } + if (!jaclID) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "aclID cannot be null"); + return; + } + + JniOcCloudProvisioning *cloud = JniOcCloudProvisioning::getJniOcCloudProvisioningPtr(env, thiz); + if (!cloud) + { + LOGD("OcCloudProvisioning_getIndividualAclInfo, No native object, creating now"); + cloud = Create_native_object(env, thiz); + if (!cloud) + { + ThrowOcException(OC_STACK_ERROR, "OcCloudProvisioning_getIndividualAclInfo," + "Can not Create Native object"); + return; + } + } + + const char *str = env->GetStringUTFChars(jaclID, NULL); + std::string aclID(str); + env->ReleaseStringUTFChars(jaclID, str); + + try + { + OCStackResult result = cloud->getIndividualAclInfo(env, jListener, aclID); + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcCloudProvisioning_getIndividualAclInf"); + return; + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } + return; +} + +/* + * Class: org_iotivity_base_OcCloudProvisioning + * Method: getCRL + * Signature: (Lorg/iotivity/base/OcCloudProvisioning/GetCRLListener;)V + */ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcCloudProvisioning_getCRL + (JNIEnv *env, jobject thiz, jobject jListener) +{ + LOGD("OcCloudProvisioning_getCRL"); + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_CALLBACK, "Listener cannot be null"); + return; + } + + JniOcCloudProvisioning *cloud = JniOcCloudProvisioning::getJniOcCloudProvisioningPtr(env, thiz); + if (!cloud) + { + LOGD("OcCloudProvisioning_getCRL, No native object, creating now"); + cloud = Create_native_object(env, thiz); + if (!cloud) + { + ThrowOcException(OC_STACK_ERROR, "OcCloudProvisioning_getCRL," + "Can not Create Native object"); + return; + } + } + + try + { + OCStackResult result = cloud->getCRL(env, jListener); + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcCloudProvisioning_requestCertificate"); + return; + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } + return; +} + +/* + * Class: org_iotivity_base_OcCloudProvisioning + * Method: postCRL0 + * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/ArrayList;Lorg/iotivity/base/OcCloudProvisioning/PostCRLListener;)V + */ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcCloudProvisioning_postCRL0 + (JNIEnv *env , jobject thiz, jstring jthisUpdate, jstring jnextUpdate, jstring jcrl, + jobjectArray jserialnumArray, jobject jListener) +{ + LOGD("OcCloudProvisioning_postCRL0"); + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_CALLBACK,"Listener can not be null"); + return; + } + if (!jthisUpdate || !jnextUpdate || !jserialnumArray) + { + ThrowOcException(OC_STACK_INVALID_PARAM, " Invalid parameter (NULL param)"); + return; + } + + JniOcCloudProvisioning *cloud = JniOcCloudProvisioning::getJniOcCloudProvisioningPtr(env, thiz); + if (!cloud) + { + LOGD("OcCloudProvisioning_getCRL, No native object, creating now"); + cloud = Create_native_object(env, thiz); + if (!cloud) + { + ThrowOcException(OC_STACK_ERROR, "OcCloudProvisioning_PostCRL0," + "Can not Create Native object"); + return; + } + } + + const char *str = env->GetStringUTFChars(jthisUpdate, NULL); + if (!str || env->ExceptionCheck()) + { + ThrowOcException(OC_STACK_ERROR,"OcCloudProvisioning_PostCRL0"); + return; + } + std::string thisUpdate(str); + env->ReleaseStringUTFChars(jthisUpdate, str); + + str = env->GetStringUTFChars(jnextUpdate, NULL); + if (!str || env->ExceptionCheck()) + { + ThrowOcException(OC_STACK_ERROR,"OcCloudProvisioning_PostCRL0"); + return; + } + std::string nextUpdate(str); + env->ReleaseStringUTFChars(jnextUpdate, str); + + OCByteString *crl = NULL; + if (jcrl) + { + str = env->GetStringUTFChars(jcrl, NULL); + if (!str || env->ExceptionCheck()) + { + ThrowOcException(OC_STACK_ERROR,"OcCloudProvisioning_PostCRL0"); + return; + } + crl = (OCByteString*)OICCalloc(1, sizeof(OCByteString)); + crl->len = (size_t)(strlen(str)); + crl->bytes = (uint8_t*)OICCalloc(crl->len, sizeof(uint8_t)); + + for (size_t i = 0 ; i < crl->len; i++) + { + crl->bytes[i] = (uint8_t)str[i]; + } + } + + jsize len = env->GetArrayLength(jserialnumArray); + + stringArray_t *serialNumArray = (stringArray_t*)OICCalloc(1, sizeof(stringArray_t)); + serialNumArray->array = (char**)OICCalloc(len, sizeof(char*)); + serialNumArray->length = len; + + for (jsize i = 0; i < len; ++i) + { + jstring jStr = (jstring)env->GetObjectArrayElement(jserialnumArray, i); + if (!jStr) + { + ThrowOcException(OC_STACK_ERROR,"OcCloudProvisioning_PostCRL0"); + return; + } + serialNumArray->array[i] = (char*)env->GetStringUTFChars(jStr, nullptr); + if (env->ExceptionCheck()) + { + ThrowOcException(OC_STACK_ERROR,"OcCloudProvisioning_PostCRL0"); + return; + } + env->DeleteLocalRef(jStr); + } + + try + { + OCStackResult result = cloud->postCRL(env, thisUpdate, nextUpdate, crl, + serialNumArray, jListener); + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcCloudProvisioning_PostCRL0"); + return; + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } + return; +} diff --git a/android/android_api/base/jni/JniOcCloudProvisioning.h b/android/android_api/base/jni/JniOcCloudProvisioning.h new file mode 100644 index 000000000..58693c73d --- /dev/null +++ b/android/android_api/base/jni/JniOcCloudProvisioning.h @@ -0,0 +1,110 @@ +/* +* //****************************************************************** +* // +* // Copyright 2016 Samsung Electronics All Rights Reserved. +* // +* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +* // +* // Licensed under the Apache License, Version 2.0 (the "License"); +* // you may not use this file except in compliance with the License. +* // You may obtain a copy of the License at +* // +* // http://www.apache.org/licenses/LICENSE-2.0 +* // +* // Unless required by applicable law or agreed to in writing, software +* // distributed under the License is distributed on an "AS IS" BASIS, +* // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* // See the License for the specific language governing permissions and +* // limitations under the License. +* // +* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +*/ + +#include "JniOcStack.h" +#include "OCCloudProvisioning.h" +#include "JniOcCloudResultListener.h" +#include "JniGetAclIdByDeviceListener.h" +#include + + +using namespace OC; + +#ifndef _Included_org_iotivity_base_OcCloudProvisioning +#define _Included_org_iotivity_base_OcCloudProvisioning +class JniOcCloudProvisioning +{ + public: + JniOcCloudProvisioning(std::shared_ptr cloudObject); + ~JniOcCloudProvisioning(); + + static JniOcCloudProvisioning* getJniOcCloudProvisioningPtr(JNIEnv *env, jobject thiz); + JniOcCloudResultListener* AddCloudResultListener(JNIEnv* env, jobject jListener); + JniGetAclIdByDeviceListener* AddGetAclByDeviceListener(JNIEnv* env, jobject jListener); + void RemoveCloudResultListener(JNIEnv* env, jobject jListener); + void RemoveGetAclByDeviceIdListener(JNIEnv*, jobject); + + OCStackResult requestCertificate(JNIEnv* env, jobject jListener); + OCStackResult getAclIdByDevice(JNIEnv*, std::string, jobject); + OCStackResult getIndividualAclInfo(JNIEnv*, jobject, std::string &); + OCStackResult getCRL(JNIEnv* env, jobject jListener); + OCStackResult postCRL(JNIEnv* env, const std::string& thisUpdate, + const std::string& nextUpdate, const OCByteString *crl, + const stringArray_t *serialNumbers, jobject jListener); + + private: + std::map> resultMap; + std::map> aclresultMap; + std::mutex resultMapLock; + std::mutex aclresultMapLock; + std::shared_ptrm_sharedCloudObject; +}; + + +/* DO NOT EDIT THIS FILE - it is machine generated */ +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: org_iotivity_base_OcCloudProvisioning + * Method: requestCertificate + * Signature: (Lorg/iotivity/base/OcCloudProvisioning/RequestCertificateListener;)V + */ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcCloudProvisioning_requestCertificate + (JNIEnv *, jobject, jobject); + +/* + * Class: org_iotivity_base_OcCloudProvisioning + * Method: getAclIdByDevice + * Signature: (Ljava/lang/String;Lorg/iotivity/base/OcCloudProvisioning/GetAclIdByDeviceListener;)V + */ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcCloudProvisioning_getAclIdByDevice + (JNIEnv *, jobject, jstring, jobject); + +/* + * Class: org_iotivity_base_OcCloudProvisioning + * Method: getIndividualAclInfo + * Signature: (Ljava/lang/String;Lorg/iotivity/base/OcCloudProvisioning/GetIndividualAclInfoListener;)V + */ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcCloudProvisioning_getIndividualAclInfo + (JNIEnv *, jobject, jstring, jobject); + +/* + * Class: org_iotivity_base_OcCloudProvisioning + * Method: getCRL + * Signature: (Lorg/iotivity/base/OcCloudProvisioning/GetCRLListener;)V + */ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcCloudProvisioning_getCRL + (JNIEnv *, jobject, jobject); + +/* + * Class: org_iotivity_base_OcCloudProvisioning + * Method: postCRL0 + * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/ArrayList;Lorg/iotivity/base/OcCloudProvisioning/PostCRLListener;)V + */ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcCloudProvisioning_postCRL0 + (JNIEnv *, jobject, jstring, jstring, jstring, jobjectArray, jobject); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/android/android_api/base/jni/JniOcCloudResultListener.cpp b/android/android_api/base/jni/JniOcCloudResultListener.cpp new file mode 100644 index 000000000..9894fa2c3 --- /dev/null +++ b/android/android_api/base/jni/JniOcCloudResultListener.cpp @@ -0,0 +1,155 @@ +/* +* //****************************************************************** +* // +* // Copyright 2016 Samsung Electronics All Rights Reserved. +* // +* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +* // +* // Licensed under the Apache License, Version 2.0 (the "License"); +* // you may not use this file except in compliance with the License. +* // You may obtain a copy of the License at +* // +* // http://www.apache.org/licenses/LICENSE-2.0 +* // +* // Unless required by applicable law or agreed to in writing, software +* // distributed under the License is distributed on an "AS IS" BASIS, +* // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* // See the License for the specific language governing permissions and +* // limitations under the License. +* // +* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +*/ +#include "JniOcCloudResultListener.h" + +JniOcCloudResultListener::JniOcCloudResultListener(JNIEnv *env, jobject jListener, + RemoveCallback removeCloudResultListener) +{ + m_jwListener = env->NewWeakGlobalRef(jListener); + m_removeCloudResultListener = removeCloudResultListener; +} + +JniOcCloudResultListener::~JniOcCloudResultListener() +{ + LOGI("~JniOcCloudResultListener()"); + if (m_jwListener) + { + jint ret = JNI_ERR; + JNIEnv *env = GetJNIEnv(ret); + if (nullptr == env) + { + return; + } + env->DeleteWeakGlobalRef(m_jwListener); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } + } +} + +void JniOcCloudResultListener::CloudResultListenerCB(int result, void *data, + ListenerFunc func) +{ + jint ret = JNI_ERR; + JNIEnv *env = GetJNIEnv(ret); + if (nullptr == env) + { + return; + } + + jobject jListener = env->NewLocalRef(m_jwListener); + if (!jListener) + { + checkExAndRemoveListener(env); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } + return; + } + + jclass clsL = env->GetObjectClass(jListener); + + if (!clsL) + { + checkExAndRemoveListener(env); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } + return; + } + + std::string calledFunc; + switch (func) + { + case ListenerFunc::REQUEST_CERTIFICATE: + { + calledFunc = "requestCertificateListener"; + } + break; + case ListenerFunc::GET_ACLINFO: + { + calledFunc = "getIndividualAclInfoListener"; + } + break; + case ListenerFunc::GET_CRL: + { + calledFunc = "getCRLListener"; + } + break; + case ListenerFunc::POST_CRL: + { + calledFunc = "postCRLListener"; + } + break; + default: + { + checkExAndRemoveListener(env); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } + return; + } + return; + } + + jmethodID midL = env->GetMethodID(clsL, calledFunc.c_str(), "(Z)V"); + if (!midL) + { + checkExAndRemoveListener(env); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } + return; + } + + env->CallVoidMethod(jListener, midL, (jboolean)result); + if (env->ExceptionCheck()) + { + LOGE("Java exception is thrown"); + } + + checkExAndRemoveListener(env); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } +} + +void JniOcCloudResultListener::checkExAndRemoveListener(JNIEnv* env) +{ + if (env->ExceptionCheck()) + { + jthrowable ex = env->ExceptionOccurred(); + env->ExceptionClear(); + m_removeCloudResultListener(env, m_jwListener); + env->Throw((jthrowable)ex); + } + else + { + m_removeCloudResultListener(env, m_jwListener); + } +} diff --git a/android/android_api/base/jni/JniOcCloudResultListener.h b/android/android_api/base/jni/JniOcCloudResultListener.h new file mode 100644 index 000000000..3cb826a20 --- /dev/null +++ b/android/android_api/base/jni/JniOcCloudResultListener.h @@ -0,0 +1,52 @@ +/* +* //****************************************************************** +* // +* // Copyright 2015 Samsung Electronics All Rights Reserved. +* // +* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +* // +* // Licensed under the Apache License, Version 2.0 (the "License"); +* // you may not use this file except in compliance with the License. +* // You may obtain a copy of the License at +* // +* // http://www.apache.org/licenses/LICENSE-2.0 +* // +* // Unless required by applicable law or agreed to in writing, software +* // distributed under the License is distributed on an "AS IS" BASIS, +* // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* // See the License for the specific language governing permissions and +* // limitations under the License. +* // +* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +*/ +#include +#include "JniOcStack.h" + +#ifndef _Included_org_iotivity_base_OcCloudProvisioning_JniOcCloudResultListener +#define _Included_org_iotivity_base_OcCloudProvisioning_JniOcCloudResultListener + +typedef std::function RemoveCallback; + +enum class ListenerFunc +{ + REQUEST_CERTIFICATE = 1, + GET_ACLINFO, + GET_CRL, + POST_CRL +}; + +class JniOcCloudResultListener +{ + public: + JniOcCloudResultListener(JNIEnv *env, jobject jListener, + RemoveCallback removeCloudResultListener); + ~JniOcCloudResultListener(); + + void CloudResultListenerCB(int result, void *data, ListenerFunc func); + + private: + RemoveCallback m_removeCloudResultListener; + jweak m_jwListener; + void checkExAndRemoveListener(JNIEnv* env); +}; +#endif diff --git a/android/android_api/base/jni/JniOcDirectPairDevice.cpp b/android/android_api/base/jni/JniOcDirectPairDevice.cpp index 535bebc58..ff4e62665 100644 --- a/android/android_api/base/jni/JniOcDirectPairDevice.cpp +++ b/android/android_api/base/jni/JniOcDirectPairDevice.cpp @@ -28,7 +28,8 @@ namespace PH = std::placeholders; JniOcDirectPairDevice::JniOcDirectPairDevice(std::shared_ptr 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 pairingMethodList; JniOcDirectPairDevice* device = JniOcDirectPairDevice::getJniOcDirectPairDevicePtr(env,thiz); - if (!device) return nullptr; + if (!device) + { + return nullptr; + } std::vector pairingMethods = device->getPairingMethods(); return JniOcDirectPairDevice::JconvertIntVectorToJavaList(env,pairingMethods); @@ -104,7 +111,10 @@ jintArray JniOcDirectPairDevice::JconvertIntVectorToJavaList(JNIEnv *env, std::v jsize len = static_cast(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(connectivityType); diff --git a/android/android_api/base/jni/JniOcPlatform.cpp b/android/android_api/base/jni/JniOcPlatform.cpp index 82f693f22..a746cfedc 100644 --- a/android/android_api/base/jni/JniOcPlatform.cpp +++ b/android/android_api/base/jni/JniOcPlatform.cpp @@ -29,6 +29,10 @@ #include "JniUtils.h" #include "ocpayload.h" +#ifdef WITH_CLOUD +#include "JniOcAccountManager.h" +#endif + using namespace OC; JniOnResourceFoundListener* AddOnResourceFoundListener(JNIEnv* env, jobject jListener) @@ -322,6 +326,74 @@ void RemoveOnPresenceListener(JNIEnv* env, jobject jListener) presenceMapLock.unlock(); } +JniOnObserveListener* AddOnObserveListener(JNIEnv* env, jobject jListener) +{ + JniOnObserveListener *onObserveListener = nullptr; + + observeMapLock.lock(); + + for (auto it = onObserveListenerMap.begin(); it != onObserveListenerMap.end(); ++it) + { + if (env->IsSameObject(jListener, it->first)) + { + auto refPair = it->second; + onObserveListener = refPair.first; + refPair.second++; + it->second = refPair; + onObserveListenerMap.insert(*it); + LOGD("OnObserveListener: ref. count incremented"); + break; + } + } + if (!onObserveListener) + { + onObserveListener = new JniOnObserveListener(env, jListener, (JniOcResource*)nullptr); + jobject jgListener = env->NewGlobalRef(jListener); + onObserveListenerMap.insert( + std::pair>( + jgListener, + std::pair(onObserveListener, 1))); + LOGI("OnObserveListener: new listener"); + } + observeMapLock.unlock(); + return onObserveListener; +} + +void RemoveOnObserveListener(JNIEnv* env, jobject jListener) +{ + observeMapLock.lock(); + bool isFound = false; + for (auto it = onObserveListenerMap.begin(); it != onObserveListenerMap.end(); ++it) + { + if (env->IsSameObject(jListener, it->first)) + { + auto refPair = it->second; + if (refPair.second > 1) + { + refPair.second--; + it->second = refPair; + onObserveListenerMap.insert(*it); + LOGI("OnObserveListener: ref. count decremented"); + } + else + { + env->DeleteGlobalRef(it->first); + JniOnObserveListener* listener = refPair.first; + delete listener; + onObserveListenerMap.erase(it); + LOGI("OnObserveListener is removed"); + } + isFound = true; + break; + } + } + if (!isFound) + { + ThrowOcException(JNI_EXCEPTION, "OnObserveListener not found"); + } + observeMapLock.unlock(); +} + JniOnDPDevicesFoundListener* AddOnDPDevicesFoundListener(JNIEnv* env, jobject jListener) { JniOnDPDevicesFoundListener *onDPDeviceListener = nullptr; @@ -464,6 +536,172 @@ void RemoveOnDirectPairingListener(JNIEnv* env, jobject jListener) directPairingListenerMapLock.unlock(); } +JniOnPublishResourceListener* AddOnPublishResourceListener(JNIEnv* env, jobject jListener) +{ + if (!env) + { + LOGD("env is null"); + return nullptr; + } + + JniOnPublishResourceListener *onPublishResourceListener = nullptr; + + publishResourceListenerMapLock.lock(); + + for (auto it = onPublishResourceListenerMap.begin(); it != + onPublishResourceListenerMap.end(); ++it) + { + if (env->IsSameObject(jListener, it->first)) + { + auto refPair = it->second; + onPublishResourceListener = refPair.first; + refPair.second++; + it->second = refPair; + onPublishResourceListenerMap.insert(*it); + LOGD("onPublishResourceListener: ref. count incremented"); + break; + } + } + if (!onPublishResourceListener) + { + onPublishResourceListener = new JniOnPublishResourceListener(env, jListener, + RemoveOnPublishResourceListener); + jobject jgListener = env->NewGlobalRef(jListener); + onPublishResourceListenerMap.insert( + std::pair>( + jgListener, + std::pair(onPublishResourceListener, 1))); + LOGI("onPublishResourceListener: new listener"); + } + publishResourceListenerMapLock.unlock(); + return onPublishResourceListener; +} + +void RemoveOnPublishResourceListener(JNIEnv* env, jobject jListener) +{ + if (!env) + { + LOGE("env is null"); + return; + } + + publishResourceListenerMapLock.lock(); + bool isFound = false; + for (auto it = onPublishResourceListenerMap.begin(); it != + onPublishResourceListenerMap.end(); ++it) + { + if (env->IsSameObject(jListener, it->first)) + { + auto refPair = it->second; + if (refPair.second > 1) + { + refPair.second--; + it->second = refPair; + onPublishResourceListenerMap.insert(*it); + LOGI("onPublishResourceListener: ref. count decremented"); + } + else + { + env->DeleteGlobalRef(it->first); + JniOnPublishResourceListener* listener = refPair.first; + delete listener; + onPublishResourceListenerMap.erase(it); + LOGI("onPublishResourceListener is removed"); + } + isFound = true; + break; + } + } + if (!isFound) + { + ThrowOcException(JNI_EXCEPTION, "onPublishResourceListener not found"); + } + publishResourceListenerMapLock.unlock(); +} + +JniOnDeleteResourceListener* AddOnDeleteResourceListener(JNIEnv* env, jobject jListener) +{ + if (!env) + { + LOGD("env is null"); + return nullptr; + } + + JniOnDeleteResourceListener *onDeleteResourceListener = nullptr; + + deleteResourceListenerMapLock.lock(); + + for (auto it = onDeleteResourceListenerMap.begin(); it != + onDeleteResourceListenerMap.end(); ++it) + { + if (env->IsSameObject(jListener, it->first)) + { + auto refPair = it->second; + onDeleteResourceListener = refPair.first; + refPair.second++; + it->second = refPair; + onDeleteResourceListenerMap.insert(*it); + LOGD("onDeleteResourceListener: ref. count incremented"); + break; + } + } + if (!onDeleteResourceListener) + { + onDeleteResourceListener = new JniOnDeleteResourceListener(env, jListener, + RemoveOnDeleteResourceListener); + jobject jgListener = env->NewGlobalRef(jListener); + onDeleteResourceListenerMap.insert( + std::pair>( + jgListener, + std::pair(onDeleteResourceListener, 1))); + LOGI("onDeleteResourceListener: new listener"); + } + deleteResourceListenerMapLock.unlock(); + return onDeleteResourceListener; +} + +void RemoveOnDeleteResourceListener(JNIEnv* env, jobject jListener) +{ + if (!env) + { + LOGE("env is null"); + return; + } + + deleteResourceListenerMapLock.lock(); + bool isFound = false; + for (auto it = onDeleteResourceListenerMap.begin(); it != + onDeleteResourceListenerMap.end(); ++it) + { + if (env->IsSameObject(jListener, it->first)) + { + auto refPair = it->second; + if (refPair.second > 1) + { + refPair.second--; + it->second = refPair; + onDeleteResourceListenerMap.insert(*it); + LOGI("onDeleteResourceListener: ref. count decremented"); + } + else + { + env->DeleteGlobalRef(it->first); + JniOnDeleteResourceListener* listener = refPair.first; + delete listener; + onDeleteResourceListenerMap.erase(it); + LOGI("onDeleteResourceListener is removed"); + } + isFound = true; + break; + } + } + if (!isFound) + { + ThrowOcException(JNI_EXCEPTION, "onDeleteResourceListener not found"); + } + deleteResourceListenerMapLock.unlock(); +} + /* * Class: org_iotivity_base_OcPlatform * Method: configure @@ -520,7 +758,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 +804,7 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_notifyAllObservers1 return; } - try{ + try { OCStackResult result = OCPlatform::notifyAllObservers( jniOcResourceHandle->getOCResourceHandle(), JniUtils::getQOS(env, static_cast(jQoS))); @@ -766,13 +1007,19 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_findResource0( onResFoundListener->foundResourceCallback(resource); }; + FindErrorCallback findErrorCallback = [onResFoundListener](const std::string& uri, const int eCode) + { + onResFoundListener->findResourceErrorCallback(uri, eCode); + }; + try { OCStackResult result = OCPlatform::findResource( host, resourceUri, static_cast(jConnectivityType), - findCallback); + findCallback, + findErrorCallback); if (OC_STACK_OK != result) { @@ -824,6 +1071,11 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_findResource1( onResFoundListener->foundResourceCallback(resource); }; + FindErrorCallback findErrorCallback = [onResFoundListener](const std::string& uri, const int eCode) + { + onResFoundListener->findResourceErrorCallback(uri, eCode); + }; + try { OCStackResult result = OCPlatform::findResource( @@ -831,6 +1083,7 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_findResource1( resourceUri, static_cast(jConnectivityType), findCallback, + findErrorCallback, JniUtils::getQOS(env, static_cast(jQoS))); if (OC_STACK_OK != result) @@ -1188,12 +1441,12 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_getPlatformInfo1( ThrowOcException(OC_STACK_INVALID_PARAM, "onPlatformFoundListener cannot be null"); return; } - JniOnDeviceInfoListener *onDeviceInfoListener = AddOnDeviceInfoListener(env, jListener); + JniOnPlatformInfoListener *onPlatformInfoListener = AddOnPlatformInfoListener(env, jListener); - FindDeviceCallback findDeviceCallback = - [onDeviceInfoListener](const OCRepresentation& ocRepresentation) + FindPlatformCallback findPlatformCallback = + [onPlatformInfoListener](const OCRepresentation& ocRepresentation) { - onDeviceInfoListener->foundDeviceCallback(ocRepresentation); + onPlatformInfoListener->foundPlatformCallback(ocRepresentation); }; try @@ -1202,7 +1455,7 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_getPlatformInfo1( host, resourceUri, static_cast(jConnectivityType), - findDeviceCallback, + findPlatformCallback, JniUtils::getQOS(env, static_cast(jQoS))); if (OC_STACK_OK != result) @@ -1232,7 +1485,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 @@ -1371,10 +1627,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_registerDeviceInfo0( } OCDeviceInfo deviceInfo; + memset(&deviceInfo, 0, sizeof(deviceInfo)); try { DuplicateString(&deviceInfo.deviceName, env->GetStringUTFChars(jDeviceName, nullptr)); - deviceInfo.types = NULL; jsize len = env->GetArrayLength(jDeviceTypes); for (jsize i = 0; i < len; ++i) @@ -1382,12 +1638,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 +1867,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 +2121,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_bindTypeToResource0( JniOcResourceHandle* jniOcResourceHandle = JniOcResourceHandle::getJniOcResourceHandlePtr(env, jResourceHandle); - if (!jniOcResourceHandle) return; + if (!jniOcResourceHandle) + { + return; + } try { @@ -2150,18 +2417,106 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_unsubscribePresence0( ThrowOcException(result, "unsubscribe presence has failed"); return; } - jweak jwOnPresenceListener = - jniPresenceHandle->getJniOnPresenceListener()->getJWListener(); - if (jwOnPresenceListener) + + JniOnPresenceListener* jniPresenceListener = jniPresenceHandle->getJniOnPresenceListener(); + if (jniPresenceListener) + { + jweak jwOnPresenceListener = jniPresenceListener->getJWListener(); + if (jwOnPresenceListener) + { + RemoveOnPresenceListener(env, jwOnPresenceListener); + } + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +} + +/* +* Class: org_iotivity_base_OcPlatform +* Method: subscribeDevicePresence0 +* Signature: (Ljava/lang/String;[Ljava/lang/String;I +Lorg/iotivity/base/OcResource/OnObserveListener;)Lorg/iotivity/base/OcPresenceHandle; +*/ +JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcPlatform_subscribeDevicePresence0( + JNIEnv *env, + jclass clazz, + jstring jHost, + jobjectArray jDiArray, + jint jConnectivityType, + jobject jListener) +{ + LOGD("OcPlatform_subscribeDevicePresence0"); +#ifdef WITH_CLOUD + std::string host; + if (jHost) + { + host = env->GetStringUTFChars(jHost, nullptr); + } + + if (!jDiArray) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "device id List cannot be null"); + return nullptr; + } + + std::vector di; + JniUtils::convertJavaStrArrToStrVector(env, jDiArray, di); + + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "onObserveListener cannot be null"); + return nullptr; + } + + JniOnObserveListener *onObserveListener = AddOnObserveListener(env, jListener); + + ObserveCallback observeCallback = [onObserveListener](const HeaderOptions& opts, + const OCRepresentation& rep, const int& eCode, const int& sequenceNumber) + { + onObserveListener->onObserveCallback(opts, rep, eCode, sequenceNumber); + }; + + OCPlatform::OCPresenceHandle presenceHandle; + try + { + OCStackResult result = OCPlatform::subscribeDevicePresence( + presenceHandle, + host, + di, + static_cast(jConnectivityType), + observeCallback); + + if (OC_STACK_OK != result) { - RemoveOnPresenceListener(env, jwOnPresenceListener); + ThrowOcException(result, "subscribe device presence has failed"); } } catch (OCException& e) { LOGE("%s", e.reason().c_str()); ThrowOcException(e.code(), e.reason().c_str()); + return nullptr; + } + + JniOcPresenceHandle* jniPresenceHandle = + new JniOcPresenceHandle(onObserveListener, presenceHandle); + jlong jhandle = reinterpret_cast(jniPresenceHandle); + jobject jPresenceHandle = + env->NewObject(g_cls_OcPresenceHandle, g_mid_OcPresenceHandle_N_ctor, jhandle); + if (!jPresenceHandle) + { + LOGE("Failed to create OcPresenceHandle"); + delete jniPresenceHandle; } + return jPresenceHandle; +#else + ThrowOcException(JNI_NO_SUPPORT, "Not supported"); + return nullptr; +#endif } /* @@ -2223,7 +2578,6 @@ JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcPlatform_constructResourceObj } JniOcResource *jniOcResource = new JniOcResource(resource); - jlong handle = reinterpret_cast(jniOcResource); jobject jResource = env->NewObject(g_cls_OcResource, g_mid_OcResource_ctor); if (!jResource) @@ -2257,7 +2611,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_sendResponse0( JniOcResourceResponse *jniResponse = JniOcResourceResponse::getJniOcResourceResponsePtr(env, jResourceResponse); - if (!jniResponse) return; + if (!jniResponse) + { + return; + } try { @@ -2275,3 +2632,444 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_sendResponse0( ThrowOcException(e.code(), e.reason().c_str()); } } + +/* + * Class: org_iotivity_base_OcPlatform + * Method: publishResourceToRD0 + * Signature: (Ljava/lang/String;ILorg/iotivity/base/OcPlatform/OnPublishResourceListener;I)V + */ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_publishResourceToRD0( + JNIEnv *env, + jclass clazz, + jstring jHost, + jint jConnectivityType, + jobject jListener, + jint jQoS) +{ + LOGD("OcPlatform_publishResourceToRD"); +#ifdef RD_CLIENT + std::string host; + if (jHost) + { + host = env->GetStringUTFChars(jHost, nullptr); + } + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "onPublishResourceListener cannot be null"); + return; + } + JniOnPublishResourceListener *onPubResListener = AddOnPublishResourceListener(env, jListener); + + PublishResourceCallback pubResCallback = [onPubResListener]( + const OCRepresentation& ocRepresentation, + const int eCode) + { + onPubResListener->onPublishResourceCallback(ocRepresentation, eCode); + }; + + try + { + OCStackResult result = OCPlatform::publishResourceToRD( + host, + static_cast(jConnectivityType), + pubResCallback, + JniUtils::getQOS(env, static_cast(jQoS))); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "Publish resource has failed"); + return; + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +#else + ThrowOcException(JNI_NO_SUPPORT, "Not supported"); + return; +#endif +} + +/* + * Class: org_iotivity_base_OcPlatform + * Method: publishResourceToRD1 + * Signature: (Ljava/lang/String;I[Lorg/iotivity/base/OcResourceHandle;Lorg/iotivity/base/OcPlatform/OnPublishResourceListener;I)V + */ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_publishResourceToRD1( + JNIEnv *env, + jclass clazz, + jstring jHost, + jint jConnectivityType, + jobjectArray jResourceHandleArray, + jobject jListener, + jint jQoS) +{ + LOGD("OcPlatform_publishResourceToRD"); +#ifdef RD_CLIENT + if (!env) + { + LOGE("env is null"); + return; + } + std::string host; + if (jHost) + { + host = env->GetStringUTFChars(jHost, nullptr); + } + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "onPublishResourceListener cannot be null"); + return; + } + if (!jResourceHandleArray) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "resourceHandleList cannot be null"); + return; + } + JniOnPublishResourceListener *onPubResListener = AddOnPublishResourceListener(env, jListener); + + PublishResourceCallback pubResCallback = [onPubResListener]( + const OCRepresentation& ocRepresentation, + const int eCode) + { + onPubResListener->onPublishResourceCallback(ocRepresentation, eCode); + }; + + std::vector resourceHandleList; + size_t len = env->GetArrayLength(jResourceHandleArray); + for (size_t i = 0; i < len; ++i) + { + jobject jResourceHandle = env->GetObjectArrayElement(jResourceHandleArray, i); + if (!jResourceHandle) + { + ThrowOcException(JNI_EXCEPTION, "resource handle cannot be null"); + return; + } + + JniOcResourceHandle* jniOcResourceHandle = + JniOcResourceHandle::getJniOcResourceHandlePtr(env, jResourceHandle); + if (!jniOcResourceHandle) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "resource handle is invalid"); + return; + } + + resourceHandleList.push_back(jniOcResourceHandle->getOCResourceHandle()); + } + + try + { + OCStackResult result = OCPlatform::publishResourceToRD( + host, + static_cast(jConnectivityType), + resourceHandleList, + pubResCallback, + JniUtils::getQOS(env, static_cast(jQoS))); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "Publish resource has failed"); + return; + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +#else + ThrowOcException(JNI_NO_SUPPORT, "Not supported"); + return; +#endif +} + +/* + * Class: org_iotivity_base_OcPlatform + * Method: deleteResourceFromRD0 + * Signature: (Ljava/lang/String;ILorg/iotivity/base/OcPlatform/OnDeleteResourceListener;I)V + */ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_deleteResourceFromRD0( + JNIEnv *env, + jclass clazz, + jstring jHost, + jint jConnectivityType, + jobject jListener, + jint jQoS) +{ + LOGD("OcPlatform_deleteResourceFromRD"); +#ifdef RD_CLIENT + std::string host; + if (jHost) + { + host = env->GetStringUTFChars(jHost, nullptr); + } + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "onDeleteResourceListener cannot be null"); + return; + } + JniOnDeleteResourceListener *onDelResListener = AddOnDeleteResourceListener(env, jListener); + + DeleteResourceCallback delResCallback = [onDelResListener](const int eCode) + { + onDelResListener->onDeleteResourceCallback(eCode); + }; + + try + { + OCStackResult result = OCPlatform::deleteResourceFromRD( + host, + static_cast(jConnectivityType), + delResCallback, + JniUtils::getQOS(env, static_cast(jQoS))); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "Delete resource has failed"); + return; + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +#else + ThrowOcException(JNI_NO_SUPPORT, "Not supported"); + return; +#endif +} + +/* + * Class: org_iotivity_base_OcPlatform + * Method: deleteResourceFromRD1 + * Signature: (Ljava/lang/String;I[Lorg/iotivity/base/OcResourceHandle;Lorg/iotivity/base/OcPlatform/OnDeleteResourceListener;I)V + */ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_deleteResourceFromRD1( + JNIEnv *env, + jclass clazz, + jstring jHost, + jint jConnectivityType, + jobjectArray jResourceHandleArray, + jobject jListener, + jint jQoS) +{ + LOGD("OcPlatform_deleteResourceFromRD"); +#ifdef RD_CLIENT + if (!env) + { + LOGE("env is null"); + return; + } + std::string host; + if (jHost) + { + host = env->GetStringUTFChars(jHost, nullptr); + } + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "onDeleteResourceListener cannot be null"); + return; + } + if (!jResourceHandleArray) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "resourceHandleList cannot be null"); + return; + } + JniOnDeleteResourceListener *onDelResListener = AddOnDeleteResourceListener(env, jListener); + + DeleteResourceCallback delResCallback = [onDelResListener](const int eCode) + { + onDelResListener->onDeleteResourceCallback(eCode); + }; + + std::vector resourceHandleList; + size_t len = env->GetArrayLength(jResourceHandleArray); + for (size_t i = 0; i < len; ++i) + { + jobject jResourceHandle = env->GetObjectArrayElement(jResourceHandleArray, i); + if (!jResourceHandle) + { + ThrowOcException(JNI_EXCEPTION, "resource handle cannot be null"); + return; + } + + JniOcResourceHandle* jniOcResourceHandle = + JniOcResourceHandle::getJniOcResourceHandlePtr(env, jResourceHandle); + if (!jniOcResourceHandle) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "resource handle is invalid"); + return; + } + + resourceHandleList.push_back(jniOcResourceHandle->getOCResourceHandle()); + } + + try + { + OCStackResult result = OCPlatform::deleteResourceFromRD( + host, + static_cast(jConnectivityType), + resourceHandleList, + delResCallback, + JniUtils::getQOS(env, static_cast(jQoS))); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "Delete resource has failed"); + return; + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +#else + ThrowOcException(JNI_NO_SUPPORT, "Not supported"); + return; +#endif +} + +/* +* Class: org_iotivity_base_OcPlatform +* Method: constructAccountManagerObject0 +* Signature: (Ljava/lang/String;I)Lorg/iotivity/base/OcAccountManager; +*/ +JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcPlatform_constructAccountManagerObject0( + JNIEnv *env, + jclass clazz, + jstring jHost, + jint jConnectivityType) +{ +#ifndef WITH_CLOUD + ThrowOcException(OC_STACK_ERROR, + "OCAccountManager is not supported. (Please build with WITH_CLOUD=1 option)"); + return nullptr; +#else + LOGD("OcPlatform_constructAccountManagerObject"); + if (!jHost) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "host cannot be null"); + return nullptr; + } + + const char* charHost = env->GetStringUTFChars(jHost, nullptr); + if (!charHost) + { + ThrowOcException(JNI_EXCEPTION, "charHost is null"); + return nullptr; + } + std::string host(charHost); + env->ReleaseStringUTFChars(jHost, charHost); + + std::shared_ptr accountManager = OCPlatform::constructAccountManagerObject( + host, + static_cast(jConnectivityType)); + + if (!accountManager) + { + ThrowOcException(OC_STACK_ERROR, "Failed to create OCAccountManager"); + return nullptr; + } + + JniOcAccountManager *jniOcAccountManager = new JniOcAccountManager(accountManager); + + jobject jAccountManager = env->NewObject(g_cls_OcAccountManager, g_mid_OcAccountManager_ctor); + if (!jAccountManager) + { + delete jniOcAccountManager; + return nullptr; + } + SetHandle(env, jAccountManager, jniOcAccountManager); + if (env->ExceptionCheck()) + { + delete jniOcAccountManager; + return nullptr; + } + return jAccountManager; +#endif +} + +/* +* Class: org_iotivity_base_OcPlatform +* Method: getDeviceId +* Signature: (I)V +*/ +JNIEXPORT jbyteArray JNICALL Java_org_iotivity_base_OcPlatform_getDeviceId +(JNIEnv *env, jobject thiz) +{ + LOGD("OcPlatform_getDeviceId"); + OCUUIdentity deviceId; + + jbyteArray ret = env->NewByteArray(UUID_IDENTITY_SIZE); + jbyte uuid[UUID_IDENTITY_SIZE]; + try + { + + OCStackResult result = OCPlatform::getDeviceId(&deviceId); + LOGD("OcPlatform_getDeviceId return from CPP"); + if (OC_STACK_OK != result) + { + ThrowOcException(result, "Error while getting my device Id"); + } + else + { + for(int i=0;i < UUID_IDENTITY_SIZE; i++) + { + uuid[i] =(jbyte) deviceId.id[i]; + } + } + + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } + + env->SetByteArrayRegion(ret, 0, UUID_IDENTITY_SIZE, uuid); + + return ret; +} + +/* +* Class: org_iotivity_base_OcPlatform +* Method: setDeviceId +* Signature: (Ljava/lang/byte;)V +*/ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_setDeviceId( + JNIEnv *env, jobject thiz, jbyteArray data) +{ + LOGI("OcPlatform_setDeviceId"); + OCUUIdentity deviceId; + try + { + OCStackResult result; + jbyte* uuid = env->GetByteArrayElements(data, 0); + jsize arrayLength = env->GetArrayLength(data); + if(arrayLength!=UUID_IDENTITY_SIZE) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "Byte length not equal to UUID_IDENTITY_SIZE"); + } + else + { + for(int i=0;i < UUID_IDENTITY_SIZE; i++) + { + deviceId.id[i]=(jchar)uuid[i]; + } + result = OCPlatform::setDeviceId(&deviceId); + if (OC_STACK_OK != result) + { + ThrowOcException(result, "Failed to set DeviceId"); + } + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +} diff --git a/android/android_api/base/jni/JniOcPlatform.h b/android/android_api/base/jni/JniOcPlatform.h index a45f05912..cf6e20fc1 100644 --- a/android/android_api/base/jni/JniOcPlatform.h +++ b/android/android_api/base/jni/JniOcPlatform.h @@ -26,6 +26,9 @@ #include "JniOnDPDevicesFoundListener.h" #include "JniOnDirectPairingListener.h" #include "JniOnPresenceListener.h" +#include "JniOnObserveListener.h" +#include "JniOnPublishResourceListener.h" +#include "JniOnDeleteResourceListener.h" #include #ifndef _Included_org_iotivity_base_OcPlatform @@ -45,26 +48,40 @@ void RemoveOnPlatformInfoListener(JNIEnv* env, jobject jListener); JniOnPresenceListener* AddOnPresenceListener(JNIEnv* env, jobject jListener); void RemoveOnPresenceListener(JNIEnv* env, jobject jListener); +JniOnObserveListener* AddOnObserveListener(JNIEnv* env, jobject jListener); +void RemoveOnObserveListener(JNIEnv* env, jobject jListener); + JniOnDPDevicesFoundListener* AddOnDPDevicesFoundListener(JNIEnv* env, jobject jListener); void RemoveOnDPDevicesFoundListener(JNIEnv* env, jobject jListener); JniOnDirectPairingListener* AddOnDirectPairingListener(JNIEnv* env, jobject jListener); void RemoveOnDirectPairingListener(JNIEnv* env, jobject jListener); +JniOnPublishResourceListener* AddOnPublishResourceListener(JNIEnv* env, jobject jListener); +void RemoveOnPublishResourceListener(JNIEnv* env, jobject jListener); + +JniOnDeleteResourceListener* AddOnDeleteResourceListener(JNIEnv* env, jobject jListener); +void RemoveOnDeleteResourceListener(JNIEnv* env, jobject jListener); std::map> onResourceFoundListenerMap; std::map> onDeviceInfoListenerMap; std::map> onPlatformInfoListenerMap; std::map> onPresenceListenerMap; +std::map> onObserveListenerMap; std::map> onDPDevicesFoundListenerMap; std::map> directPairingListenerMap; +std::map> onPublishResourceListenerMap; +std::map> onDeleteResourceListenerMap; std::mutex resourceFoundMapLock; std::mutex deviceInfoMapLock; std::mutex platformInfoMapLock; std::mutex presenceMapLock; +std::mutex observeMapLock; std::mutex dpDevicesFoundListenerMapLock; std::mutex directPairingListenerMapLock; +std::mutex publishResourceListenerMapLock; +std::mutex deleteResourceListenerMapLock; #ifdef __cplusplus extern "C" { @@ -285,6 +302,15 @@ extern "C" { JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_unsubscribePresence0 (JNIEnv *, jclass, jobject); + /* + * Class: org_iotivity_base_OcPlatform + * Method: subscribeDevicePresence0 + * Signature: (Ljava/lang/String;[Ljava/lang/String;I + * Lorg/iotivity/base/OcResource/OnObserveListener;)Lorg/iotivity/base/OcPresenceHandle; + */ + JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcPlatform_subscribeDevicePresence0 + (JNIEnv *, jclass, jstring, jobjectArray, jint, jobject); + /* * Class: org_iotivity_base_OcPlatform * Method: constructResourceObject0 @@ -325,6 +351,64 @@ extern "C" { */ JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_doDirectPairing0 (JNIEnv *, jclass, jobject, jint, jstring, jobject); + + /* + * Class: org_iotivity_base_OcPlatform + * Method: publishResourceToRD0 + * Signature: (Ljava/lang/String;ILorg/iotivity/base/OcPlatform/OnPublishResourceListener;I)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_publishResourceToRD0 + (JNIEnv *, jclass, jstring, jint, jobject, jint); + + /* + * Class: org_iotivity_base_OcPlatform + * Method: publishResourceToRD1 + * Signature: (Ljava/lang/String;I[Lorg/iotivity/base/OcResourceHandle + * ;Lorg/iotivity/base/OcPlatform/OnPublishResourceListener;I)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_publishResourceToRD1 + (JNIEnv *, jclass, jstring, jint, jobjectArray, jobject, jint); + + /* + * Class: org_iotivity_base_OcPlatform + * Method: deleteResourceFromRD0 + * Signature: (Ljava/lang/String;ILorg/iotivity/base/OcPlatform/OnDeleteResourceListener;I)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_deleteResourceFromRD0 + (JNIEnv *, jclass, jstring, jint, jobject, jint); + + /* + * Class: org_iotivity_base_OcPlatform + * Method: deleteResourceFromRD1 + * Signature: (Ljava/lang/String;I[Lorg/iotivity/base/OcResourceHandle;Lorg/iotivity/base/OcPlatform/OnDeleteResourceListener;I)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_deleteResourceFromRD1 + (JNIEnv *, jclass, jstring, jint, jobjectArray, jobject, jint); + + /* + * Class: org_iotivity_base_OcPlatform + * Method: constructAccountManagerObject0 + * Signature: (Ljava/lang/String;I)Lorg/iotivity/base/OcAccountManager; + */ + JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcPlatform_constructAccountManagerObject0 + (JNIEnv *, jclass, jstring, jint); + + /* + * Class: org_iotivity_base_OcPlatform + * Method: getDeviceId + * Signature: (I)V + */ + JNIEXPORT jbyteArray JNICALL Java_org_iotivity_base_OcPlatform_getDeviceId + (JNIEnv *, jobject); + + /* + * Class: org_iotivity_base_OcPlatform + * Method: setDeviceId + * Signature: (Ljava/lang/byte;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_setDeviceId( + JNIEnv *, jobject, jbyteArray); + #ifdef __cplusplus } #endif diff --git a/android/android_api/base/jni/JniOcPresenceHandle.cpp b/android/android_api/base/jni/JniOcPresenceHandle.cpp index 00f81a1a7..9d74e2305 100644 --- a/android/android_api/base/jni/JniOcPresenceHandle.cpp +++ b/android/android_api/base/jni/JniOcPresenceHandle.cpp @@ -23,8 +23,14 @@ #include "OCPlatform.h" JniOcPresenceHandle::JniOcPresenceHandle(JniOnPresenceListener* jniListener, OCPresenceHandle presenceHandle) - : m_jniListener(jniListener), m_presenceHandle(presenceHandle) -{} + : m_jniListener(jniListener), m_presenceHandle(presenceHandle), m_jniObserveListener(nullptr) +{ +} + +JniOcPresenceHandle::JniOcPresenceHandle(JniOnObserveListener* jniListener, OCPresenceHandle presenceHandle) + : m_jniObserveListener(jniListener), m_presenceHandle(presenceHandle), m_jniListener(nullptr) +{ +} JniOcPresenceHandle::~JniOcPresenceHandle() { @@ -59,6 +65,11 @@ JniOnPresenceListener* JniOcPresenceHandle::getJniOnPresenceListener() return this->m_jniListener; } +JniOnObserveListener* JniOcPresenceHandle::getJniOnObserveListener() +{ + return this->m_jniObserveListener; +} + /* * Class: org_iotivity_base_OcPresenceHandle * Method: dispose @@ -70,4 +81,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 +} diff --git a/android/android_api/base/jni/JniOcPresenceHandle.h b/android/android_api/base/jni/JniOcPresenceHandle.h index 4052cec59..9c543e690 100644 --- a/android/android_api/base/jni/JniOcPresenceHandle.h +++ b/android/android_api/base/jni/JniOcPresenceHandle.h @@ -20,6 +20,7 @@ * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ #include "JniOcStack.h" +#include "JniOnObserveListener.h" #include "JniOnPresenceListener.h" #include "OCPlatform.h" @@ -33,6 +34,7 @@ class JniOcPresenceHandle public: JniOcPresenceHandle(JniOnPresenceListener* jniListener, OCPresenceHandle presenceHandle); + JniOcPresenceHandle(JniOnObserveListener* jniListener, OCPresenceHandle presenceHandle); ~JniOcPresenceHandle(); JniOcPresenceHandle(const JniOcPresenceHandle &) = delete; void operator=(const JniOcPresenceHandle &) = delete; @@ -41,9 +43,11 @@ public: OCPresenceHandle getOCPresenceHandle(); JniOnPresenceListener* getJniOnPresenceListener(); + JniOnObserveListener* getJniOnObserveListener(); private: JniOnPresenceListener* m_jniListener; + JniOnObserveListener* m_jniObserveListener; OCPresenceHandle m_presenceHandle; }; diff --git a/android/android_api/base/jni/JniOcProvisioning.cpp b/android/android_api/base/jni/JniOcProvisioning.cpp index 52d5bc9cd..5fe0b9066 100644 --- a/android/android_api/base/jni/JniOcProvisioning.cpp +++ b/android/android_api/base/jni/JniOcProvisioning.cpp @@ -93,7 +93,7 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcProvisioning_ownershipTransferCB } else { - result = OC_STACK_ERROR; + result = OC_STACK_INVALID_CALLBACK; } } @@ -267,7 +267,7 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcProvisioning_setDisplayPinListen if (!jListener) { - ThrowOcException(OC_STACK_INVALID_PARAM, "displayPinListener can't be null"); + ThrowOcException(OC_STACK_INVALID_CALLBACK, "displayPinListener can't be null"); return; } delete jniDisplayPinListener; @@ -288,3 +288,39 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcProvisioning_setDisplayPinListen ThrowOcException(OC_STACK_ERROR, e.reason().c_str()); } } +/* + * Class: org_iotivity_base_OcProvisioning + * Method: saveTrustCertChain1 + * Signature: (Lorg/iotivity/base/OcProvisioning/provisionTrustCertChain1;)V + */ + JNIEXPORT jint JNICALL Java_org_iotivity_base_OcProvisioning_saveTrustCertChain1 +(JNIEnv *env, jobject thiz, jbyteArray trustCertChain, jint encodingType) +{ + LOGD("OcProvisioning_saveTrustCertChain1"); +#if defined(__WITH_DTLS__) || defined(__WITH_TLS__) + jbyte* trustCertChainBytes = env->GetByteArrayElements(trustCertChain, 0); + jsize arrayLength = env->GetArrayLength(trustCertChain); + uint16_t credId; + unsigned char* trustedCertChar = new unsigned char[arrayLength]; + try + { + env->GetByteArrayRegion (trustCertChain, 0, arrayLength, reinterpret_cast(trustedCertChar)); + OCStackResult result = OCSecure::saveTrustCertChain((uint8_t*)trustedCertChar, arrayLength, + (OicEncodingType_t)encodingType, &credId); + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcProvisioning_saveTrustCertChain1"); + return -1; + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } + return (jint)credId; +#else + ThrowOcException(OC_STACK_INVALID_PARAM, "WITH_TLS not enabled"); + return -1; +#endif // __WITH_DTLS__ || __WITH_TLS__ +} diff --git a/android/android_api/base/jni/JniOcProvisioning.h b/android/android_api/base/jni/JniOcProvisioning.h index 05d3bf6c4..290744ec5 100644 --- a/android/android_api/base/jni/JniOcProvisioning.h +++ b/android/android_api/base/jni/JniOcProvisioning.h @@ -85,7 +85,13 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcProvisioning_setDisplayPinListen */ JNIEXPORT jobjectArray JNICALL Java_org_iotivity_base_OcProvisioning_getDeviceStatusList1 (JNIEnv *, jclass, jint); - +/* + * Class: org_iotivity_base_OcProvisioning + * Method: saveTrustCertChain1 + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_org_iotivity_base_OcProvisioning_saveTrustCertChain1 + (JNIEnv *, jobject, jbyteArray, jint); #ifdef __cplusplus } #endif diff --git a/android/android_api/base/jni/JniOcRepresentation.cpp b/android/android_api/base/jni/JniOcRepresentation.cpp index c3c37adca..042e2a4dd 100644 --- a/android/android_api/base/jni/JniOcRepresentation.cpp +++ b/android/android_api/base/jni/JniOcRepresentation.cpp @@ -19,6 +19,9 @@ * // * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ + +#include + #include "JniOcRepresentation.h" #include "JniUtils.h" @@ -38,6 +41,37 @@ OCRepresentation* JniOcRepresentation::getOCRepresentationPtr(JNIEnv *env, jobje return rep; } +/* +* Class: org_iotivity_base_OcRepresentation +* Method: getValues +* Signature: ()Ljava/util/Map; +*/ +JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcRepresentation_getValues +(JNIEnv *env, jobject thiz) +{ + LOGD("OcRepresentation_getValues"); + OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz); + if (!rep) + { + return nullptr; + } + + std::map values = rep->getValues(); + jobject jHashMap = env->NewObject(g_cls_HashMap, g_mid_HashMap_ctor); + if (!jHashMap) + { + return nullptr; + } + + for (std::map::const_iterator it = values.begin(); it != values.end(); it++) + { + jobject key = static_cast(env->NewStringUTF(it->first.c_str())); + jobject val = boost::apply_visitor(JObjectConverter(env), it->second); + env->CallObjectMethod(jHashMap, g_mid_HashMap_put, key, val); + } + return jHashMap; +} + /* * Class: org_iotivity_base_OcRepresentation * Method: getValueN @@ -53,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); @@ -81,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(jValue)); @@ -102,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(jValue)); @@ -123,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(jValue)); @@ -144,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); @@ -167,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 @@ -209,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); @@ -247,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); @@ -293,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); @@ -325,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); @@ -363,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); @@ -409,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); @@ -441,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); @@ -480,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); @@ -527,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); @@ -552,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); @@ -584,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); @@ -624,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); } @@ -649,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); @@ -681,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); @@ -721,7 +817,45 @@ 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); +} + +/* +* Class: org_iotivity_base_OcRepresentation +* Method: setValueByteArray +* Signature: (Ljava/lang/String;[B)V +*/ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueByteArray +(JNIEnv *env, jobject thiz, jstring jKey, jbyteArray jValue) +{ + LOGD("OcRepresentation_setValueByteArray"); + if (!jKey) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null"); + return; + } + + const jsize len = env->GetArrayLength(jValue); + jbyte* bytes = env->GetByteArrayElements(jValue, nullptr); + + std::vector value; + for (jsize i = 0; i < len; ++i) + { + value.push_back(static_cast(bytes[i])); + } + env->ReleaseByteArrayElements(jValue, bytes, JNI_ABORT); + + OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz); + if (!rep) + { + return; + } std::string key = env->GetStringUTFChars(jKey, nullptr); rep->setValue(key, value); @@ -737,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); } @@ -755,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(); } @@ -770,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()); } @@ -785,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()); @@ -801,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()); @@ -822,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)); } @@ -837,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); @@ -853,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 resourceTypes = rep->getResourceTypes(); return JniUtils::convertStrVectorToJavaStrList(env, resourceTypes); @@ -874,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 resourceTypes; JniUtils::convertJavaStrArrToStrVector(env, jResourceTypeArray, resourceTypes); @@ -890,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 resourceInterfaces = rep->getResourceInterfaces(); return JniUtils::convertStrVectorToJavaStrList(env, resourceInterfaces); @@ -911,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 resourceInterfaces; JniUtils::convertJavaStrArrToStrVector(env, jResourceInterfaceArray, resourceInterfaces); @@ -928,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(rep->empty()); } @@ -943,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(rep->numberOfAttributes()); } @@ -963,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(rep->erase(attributeKey)); @@ -984,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); @@ -1005,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(rep->isNULL(attributeKey)); diff --git a/android/android_api/base/jni/JniOcRepresentation.h b/android/android_api/base/jni/JniOcRepresentation.h index ee8f2227b..dc85747e3 100644 --- a/android/android_api/base/jni/JniOcRepresentation.h +++ b/android/android_api/base/jni/JniOcRepresentation.h @@ -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(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(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(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,21 +138,127 @@ 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(i), jString); - if (env->ExceptionCheck()) return nullptr; + if (env->ExceptionCheck()) + { + return nullptr; + } env->DeleteLocalRef(jString); } return strArr; } + // OCByteString and arrays: + jobject operator()(const OCByteString &val) const + { + jbyteArray jByteArray = env->NewByteArray(val.len); + if (!jByteArray) + { + return nullptr; + } + env->SetByteArrayRegion(jByteArray, 0, val.len, reinterpret_cast(val.bytes)); + if (env->ExceptionCheck()) + { + env->DeleteLocalRef(jByteArray); + return nullptr; + } + return jByteArray; + } + jobject operator()(const std::vector &val) const + { + jsize lenOuter = static_cast(val.size()); + jobjectArray jOuterArr = env->NewObjectArray(lenOuter, g_cls_byte1DArray, nullptr); + if (!jOuterArr) + { + return nullptr; + } + for (jsize i = 0; i < lenOuter; ++i) + { + jbyteArray jByteArray = (jbyteArray) operator()(val[i]); + if (!jByteArray) + { + env->DeleteLocalRef(jOuterArr); + return nullptr; + } + env->SetObjectArrayElement(jOuterArr, i, static_cast(jByteArray)); + if (env->ExceptionCheck()) + { + env->DeleteLocalRef(jByteArray); + env->DeleteLocalRef(jOuterArr); + return nullptr; + } + env->DeleteLocalRef(jByteArray); + } + return jOuterArr; + } + jobject operator()(const std::vector> &val) const + { + jsize lenOuter = static_cast(val.size()); + jobjectArray jOuterArr = env->NewObjectArray(lenOuter, g_cls_byte2DArray, nullptr); + if (!jOuterArr) + { + return nullptr; + } + for (jsize i = 0; i < lenOuter; ++i) + { + jobjectArray jMiddleArr = (jobjectArray) operator()(val[i]); + if (!jMiddleArr) + { + env->DeleteLocalRef(jOuterArr); + return nullptr; + } + env->SetObjectArrayElement(jOuterArr, i, jMiddleArr); + if (env->ExceptionCheck()) + { + env->DeleteLocalRef(jMiddleArr); + env->DeleteLocalRef(jOuterArr); + return nullptr; + } + env->DeleteLocalRef(jMiddleArr); + } + return jOuterArr; + } + jobject operator()(const std::vector>> &val) const + { + jsize lenOuter = static_cast(val.size()); + jobjectArray jOuterArr = env->NewObjectArray(lenOuter, g_cls_byte3DArray, nullptr); + if (!jOuterArr) + { + return nullptr; + } + for (jsize i = 0; i < lenOuter; ++i) + { + jobjectArray jMiddleArr = (jobjectArray) operator()(val[i]); + if (!jMiddleArr) + { + env->DeleteLocalRef(jOuterArr); + return nullptr; + } + env->SetObjectArrayElement(jOuterArr, i, jMiddleArr); + if (env->ExceptionCheck()) + { + env->DeleteLocalRef(jMiddleArr); + env->DeleteLocalRef(jOuterArr); + return nullptr; + } + env->DeleteLocalRef(jMiddleArr); + } + return jOuterArr; + } jobject operator()(const std::vector& val) const { jsize len = static_cast(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]); @@ -155,6 +280,18 @@ struct JObjectConverter : boost::static_visitor < jobject > } return repArr; } + jobject operator()(const std::vector& val) const + { + size_t len = val.size(); + jbyteArray jByteArray = env->NewByteArray(len); + if (!jByteArray) + { + return nullptr; + } + const uint8_t* bytes = &val[0]; + env->SetByteArrayRegion(jByteArray, 0, len, reinterpret_cast(bytes)); + return jByteArray; + } // Nested sequences: jobject operator()(const std::vector>& val) const @@ -169,12 +306,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(ints)); - if (env->ExceptionCheck()) return nullptr; + if (env->ExceptionCheck()) + { + return nullptr; + } env->SetObjectArrayElement(jOuterArr, i, static_cast(jIntArray)); - if (env->ExceptionCheck()) return nullptr; + if (env->ExceptionCheck()) + { + return nullptr; + } env->DeleteLocalRef(jIntArray); } return jOuterArr; @@ -183,26 +329,46 @@ struct JObjectConverter : boost::static_visitor < jobject > { jsize lenOuter = static_cast(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(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(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(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; @@ -212,17 +378,31 @@ struct JObjectConverter : boost::static_visitor < jobject > { jsize lenOuter = static_cast(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(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); } @@ -232,26 +412,44 @@ struct JObjectConverter : boost::static_visitor < jobject > { jsize lenOuter = static_cast(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(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(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(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; @@ -261,22 +459,38 @@ struct JObjectConverter : boost::static_visitor < jobject > { jsize lenOuter = static_cast(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(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; @@ -285,31 +499,49 @@ struct JObjectConverter : boost::static_visitor < jobject > { jsize lenOuter = static_cast(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(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; } @@ -318,21 +550,33 @@ struct JObjectConverter : boost::static_visitor < jobject > { jsize lenOuter = static_cast(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(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); } @@ -342,30 +586,48 @@ struct JObjectConverter : boost::static_visitor < jobject > { jsize lenOuter = static_cast(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(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(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; @@ -375,12 +637,18 @@ struct JObjectConverter : boost::static_visitor < jobject > { jsize lenOuter = static_cast(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(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]); @@ -393,11 +661,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; @@ -406,17 +680,26 @@ struct JObjectConverter : boost::static_visitor < jobject > { jsize lenOuter = static_cast(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(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(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]); @@ -429,15 +712,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; @@ -451,6 +743,14 @@ private: extern "C" { #endif + /* + * Class: org_iotivity_base_OcRepresentation + * Method: getValues + * Signature: ()Ljava/util/Map; + */ + JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcRepresentation_getValues + (JNIEnv *, jobject); + /* * Class: org_iotivity_base_OcRepresentation * Method: getValueN @@ -619,6 +919,14 @@ extern "C" { JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueRepresentation3DArray (JNIEnv *, jobject, jstring, jobjectArray); + /* + * Class: org_iotivity_base_OcRepresentation + * Method: setValueByteArray + * Signature: (Ljava/lang/String;[B)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueByteArray + (JNIEnv *, jobject, jstring, jbyteArray); + /* * Class: org_iotivity_base_OcRepresentation * Method: addChild diff --git a/android/android_api/base/jni/JniOcRequestHandle.cpp b/android/android_api/base/jni/JniOcRequestHandle.cpp index b916490d8..9585c55b2 100644 --- a/android/android_api/base/jni/JniOcRequestHandle.cpp +++ b/android/android_api/base/jni/JniOcRequestHandle.cpp @@ -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 +} diff --git a/android/android_api/base/jni/JniOcResource.cpp b/android/android_api/base/jni/JniOcResource.cpp index 9e6925a37..44f1eb3c5 100644 --- a/android/android_api/base/jni/JniOcResource.cpp +++ b/android/android_api/base/jni/JniOcResource.cpp @@ -26,7 +26,8 @@ JniOcResource::JniOcResource(std::shared_ptr resource) : m_sharedResource(resource) -{} +{ +} JniOcResource::~JniOcResource() { @@ -34,17 +35,27 @@ 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); m_onPostManager.removeAllListeners(env); m_onDeleteManager.removeAllListeners(env); m_onObserveManager.removeAllListeners(env); +#ifdef WITH_MQ + m_onFoundTopicResourceManager.removeAllListeners(env); + m_onSubcribeTopicManager.removeAllListeners(env); +#endif - if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } } OCStackResult JniOcResource::get(JNIEnv* env, const QueryParamsMap &queryParametersMap, jobject jListener) @@ -286,7 +297,9 @@ OCStackResult JniOcResource::observe(JNIEnv* env, ObserveType observeType, OCStackResult JniOcResource::cancelObserve(JNIEnv* env, QualityOfService qos) { - if (QualityOfService::HighQos != qos) + // In Low case, after delete the callback and send empty message when client receive the notify. + // But TCP does not support EMPTY message. + if ((CT_ADAPTER_IP & connectivityType()) && QualityOfService::HighQos != qos) { this->m_onObserveManager.removeAllListeners(env); } @@ -393,6 +406,28 @@ void JniOcResource::removeOnObserveListener(JNIEnv* env, jobject jListener) this->m_onObserveManager.removeListener(env, jListener); } +#ifdef WITH_MQ +JniOnMQTopicFoundListener* JniOcResource::addOnTopicFoundListener(JNIEnv* env, jobject jListener) +{ + return this->m_onFoundTopicResourceManager.addListener(env, jListener, this); +} + +void JniOcResource::removeOnTopicFoundListener(JNIEnv* env, jobject jListener) +{ + this->m_onFoundTopicResourceManager.removeListener(env, jListener); +} + +JniOnMQSubscribeListener* JniOcResource::addOnMQTopicSubscribeListener(JNIEnv* env, jobject jListener) +{ + return this->m_onSubcribeTopicManager.addListener(env, jListener, this); +} + +void JniOcResource::removeOnMQTopicSubscribeListener(JNIEnv* env, jobject jListener) +{ + this->m_onSubcribeTopicManager.removeListener(env, jListener); +} +#endif + std::shared_ptr JniOcResource::getOCResource() { return this->m_sharedResource; @@ -412,6 +447,90 @@ JniOcResource* JniOcResource::getJniOcResourcePtr(JNIEnv *env, jobject thiz) return resource; } +#ifdef WITH_MQ +OCStackResult JniOcResource::discoveryMQTopics(JNIEnv* env, + const QueryParamsMap &queryParametersMap, jobject jListener, QualityOfService QoS) +{ + JniOnMQTopicFoundListener *onTopicFoundListener = addOnTopicFoundListener(env, jListener); + + MQTopicCallback findCallback = [onTopicFoundListener](const int& eCode, + const std::string& uri, std::shared_ptr resource) + { + onTopicFoundListener->foundTopicCallback(eCode, uri, resource); + }; + + return m_sharedResource->discoveryMQTopics(queryParametersMap, findCallback, QoS); +} + +OCStackResult JniOcResource::createMQTopic(JNIEnv* env, + const OCRepresentation &representation, const std::string &targetUri, + const QueryParamsMap &queryParametersMap, jobject jListener, QualityOfService QoS) +{ + JniOnMQTopicFoundListener *onTopicCreatedListener = addOnTopicFoundListener(env, jListener); + + MQTopicCallback createCallback = [onTopicCreatedListener](const int& eCode, + const std::string& uri, std::shared_ptr resource) + { + onTopicCreatedListener->createdTopicCallback(eCode, uri, resource); + }; + + return m_sharedResource->createMQTopic(representation, targetUri, + queryParametersMap, + createCallback, QoS); +} +#endif +#ifdef MQ_SUBSCRIBER +OCStackResult JniOcResource::subscribeMQTopic(JNIEnv* env, + const QueryParamsMap &queryParametersMap, jobject jListener, QualityOfService QoS) +{ + JniOnMQSubscribeListener *onSubscribeListener = addOnMQTopicSubscribeListener(env, jListener); + + ObserveCallback subscribeCallback = [onSubscribeListener](const HeaderOptions& opts, + const OCRepresentation& rep, const int& eCode, const int& sequenceNumber) + { + onSubscribeListener->onSubscribeCallback(opts, rep, eCode, sequenceNumber); + }; + + return m_sharedResource->subscribeMQTopic(ObserveType::Observe, queryParametersMap, + subscribeCallback, QoS); +} + +OCStackResult JniOcResource::unsubscribeMQTopic(QualityOfService QoS) +{ + return m_sharedResource->unsubscribeMQTopic(QoS); +} + +OCStackResult JniOcResource::requestMQPublish(JNIEnv* env, + const QueryParamsMap &queryParametersMap, jobject jListener, QualityOfService QoS) +{ + JniOnPostListener *onPostListener = addOnPostListener(env, jListener); + + PostCallback postCallback = [onPostListener](const HeaderOptions& opts, + const OCRepresentation& rep, const int eCode) + { + onPostListener->onPostCallback(opts, rep, eCode); + }; + + return m_sharedResource->requestMQPublish(queryParametersMap, postCallback, QoS); +} +#endif +#ifdef MQ_PUBLISHER +OCStackResult JniOcResource::publishMQTopic(JNIEnv* env, const OCRepresentation &representation, + const QueryParamsMap &queryParametersMap, jobject jListener, QualityOfService QoS) +{ + JniOnPostListener *onPostListener = addOnPostListener(env, jListener); + + PostCallback postCallback = [onPostListener](const HeaderOptions& opts, + const OCRepresentation& rep, const int eCode) + { + onPostListener->onPostCallback(opts, rep, eCode); + }; + + return m_sharedResource->publishMQTopic(representation, queryParametersMap, + postCallback, QoS); +} +#endif + /* * Class: org_iotivity_base_OcResource * Method: get @@ -432,7 +551,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 +598,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 +658,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 +718,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 +774,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 +835,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 +907,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 +981,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 +1043,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 +1102,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 +1175,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 +1249,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 +1301,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 +1339,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 +1384,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 +1434,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 +1473,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 +1511,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 +1532,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 +1550,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 +1568,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 +1586,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(connectivityType); @@ -1396,6 +1605,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 +1623,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 resourceTypes = resource->getResourceTypes(); @@ -1426,7 +1643,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 resourceInterfaces = resource->getResourceInterfaces(); @@ -1443,11 +1663,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(jniResourceIdentifier); jobject jResourceIdentifier = env->NewObject(g_cls_OcResourceIdentifier, @@ -1469,7 +1695,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 +1714,347 @@ 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 +} + +/* +* Class: org_iotivity_base_OcResource +* Method: discoveryMQTopicsImpl +* Signature: (Ljava/util/Map;Lorg/iotivity/base/OcPlatform/OnResourceFoundListener;I)V +*/ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_discoveryMQTopicsImpl +(JNIEnv *env, jobject thiz, jobject jQueryParamsMap, jobject jListener, jint jQoS) +{ + LOGD("OcResource_discoveryMQTopicsImpl"); + +#ifdef WITH_MQ + if (!jQueryParamsMap) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null"); + return; + } + + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "listener cannot be null"); + return; + } + + JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz); + if (!resource) + { + return; + } + + QueryParamsMap qpm; + JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm); + + try + { + OCStackResult result = resource->discoveryMQTopics( + env, + qpm, + jListener, + JniUtils::getQOS(env, static_cast(jQoS))); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcResource_discoveryMQTopicsImpl"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +#else + ThrowOcException(JNI_NO_SUPPORT, "not support"); +#endif +} + +/* +* Class: org_iotivity_base_OcResource +* Method: createMQTopicImpl +* Signature: (Lorg/iotivity/base/OcRepresentation;Ljava/util/String;Ljava/util/Map +* ;Lorg/iotivity/base/OcPlatform/OnMQTopicCreatedListener;I)V +*/ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_createMQTopicImpl +(JNIEnv *env, jobject thiz, jobject jRepresentation, jstring jUri, + jobject jQueryParamsMap, jobject jListener, jint jQoS) +{ + LOGD("OcResource_createMQTopicImpl"); + +#ifdef WITH_MQ + if (!jQueryParamsMap) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null"); + return; + } + + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "listener cannot be null"); + return; + } + + if (!jRepresentation) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "representation null"); + return; + } + + JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz); + if (!resource) + { + return; + } + + std::string targetUri; + if (jUri) + { + targetUri = env->GetStringUTFChars(jUri, nullptr); + } + + OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env, + jRepresentation); + if (!representation) + { + return; + } + + QueryParamsMap qpm; + JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm); + + try + { + OCStackResult result = resource->createMQTopic( + env, + *representation, + targetUri, + qpm, + jListener, + JniUtils::getQOS(env, static_cast(jQoS))); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcResource_createMQTopicImpl"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +#else + ThrowOcException(JNI_NO_SUPPORT, "not support"); +#endif +} + +/* +* Class: org_iotivity_base_OcResource +* Method: subscribeMQTopic +* Signature: (Ljava/util/Map;Lorg/iotivity/base/OcResource/OnObserveListener;I)V +*/ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_subscribeMQTopicImpl +(JNIEnv *env, jobject thiz, jobject jQueryParamsMap, jobject jListener, jint jQoS) +{ + LOGD("OcResource_subscribeMQTopicImpl"); +#ifdef MQ_SUBSCRIBER + if (!jQueryParamsMap) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null"); + return; + } + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "onObserveListener cannot be null"); + return; + } + JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz); + if (!resource) + { + return; + } + + QueryParamsMap qpm; + JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm); + + try + { + OCStackResult result = resource->subscribeMQTopic( + env, + qpm, + jListener, + JniUtils::getQOS(env, static_cast(jQoS))); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcResource_subscribeMQTopicImpl"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +#else + ThrowOcException(JNI_NO_SUPPORT, "not support"); +#endif +} + +/* +* Class: org_iotivity_base_OcResource +* Method: unsubscribeMQTopicImpl +* Signature: (I)V +*/ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_unsubscribeMQTopicImpl +(JNIEnv *env, jobject thiz, jint jQoS) +{ + LOGD("OcResource_unsubscribeMQTopicImpl"); +#ifdef MQ_SUBSCRIBER + JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz); + if (!resource) + { + return; + } + + try + { + OCStackResult result = resource->unsubscribeMQTopic( + JniUtils::getQOS(env, static_cast(jQoS))); + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcResource_unsubscribeMQTopicImpl"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +#else + ThrowOcException(JNI_NO_SUPPORT, "not support"); +#endif +} + +/* +* Class: org_iotivity_base_OcResource +* Method: requestMQPublishImpl +* Signature: (Ljava/util/Map;Lorg/iotivity/base/OcResource/OnPostListener;I)V +*/ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_requestMQPublishImpl +(JNIEnv *env, jobject thiz, jobject jQueryParamsMap, jobject jListener, jint jQoS) +{ + LOGD("OcResource_requestMQPublishImpl"); +#ifdef MQ_SUBSCRIBER + if (!jQueryParamsMap) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null"); + return; + } + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "onPostListener cannot be null"); + return; + } + + JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz); + if (!resource) + { + return; + } + + QueryParamsMap qpm; + JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm); + + try + { + OCStackResult result = resource->requestMQPublish( + env, + qpm, + jListener, + JniUtils::getQOS(env, static_cast(jQoS))); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcResource_requestMQPublishImpl"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +#else + ThrowOcException(JNI_NO_SUPPORT, "not support"); +#endif +} + +/* +* Class: org_iotivity_base_OcResource +* Method: publishMQTopicImpl +* Signature: (Lorg/iotivity/base/OcRepresentation;Ljava/util/Map; +* Lorg/iotivity/base/OcResource/OnPostListener;I)V +*/ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_publishMQTopicImpl +(JNIEnv *env, jobject thiz, jobject jRepresentation, jobject jQueryParamsMap, + jobject jListener, jint jQoS) +{ + LOGD("OcResource_publishMQTopicImpl"); +#ifdef MQ_PUBLISHER + if (!jRepresentation) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "representation cannot be null"); + return; + } + + if (!jQueryParamsMap) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null"); + return; + } + + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "onPostListener cannot be null"); + return; + } + + JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz); + if (!resource) + { + return; + } + + OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env, + jRepresentation); + if (!representation) + { + return; + } + + QueryParamsMap qpm; + JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm); + + try + { + OCStackResult result = resource->publishMQTopic( + env, + *representation, + qpm, + jListener, + JniUtils::getQOS(env, static_cast(jQoS))); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcResource_publishMQTopicImpl"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +#else + ThrowOcException(JNI_NO_SUPPORT, "not support"); +#endif +} diff --git a/android/android_api/base/jni/JniOcResource.h b/android/android_api/base/jni/JniOcResource.h index a0383123e..7dfacd327 100644 --- a/android/android_api/base/jni/JniOcResource.h +++ b/android/android_api/base/jni/JniOcResource.h @@ -29,6 +29,10 @@ #include "JniOnDeleteListener.h" #include "JniOnObserveListener.h" #include "JniOcResourceIdentifier.h" +#ifdef WITH_MQ +#include "JniOnMQTopicFoundListener.h" +#include "JniOnMQSubscribeListener.h" +#endif #ifndef _Included_org_iotivity_base_OcResource #define _Included_org_iotivity_base_OcResource @@ -84,8 +88,8 @@ public: std::string uri(); OCConnectivityType connectivityType() const; bool isObservable(); - std::vector< std::string > getResourceTypes() const; - std::vector< std::string > getResourceInterfaces(void) const; + std::vector< std::string > getResourceTypes() const; + std::vector< std::string > getResourceInterfaces(void) const; OCResourceIdentifier uniqueIdentifier() const; std::string sid() const; @@ -105,12 +109,43 @@ public: static JniOcResource* getJniOcResourcePtr(JNIEnv *env, jobject thiz); +#ifdef WITH_MQ + JniOnMQTopicFoundListener* addOnTopicFoundListener(JNIEnv* env, jobject jListener); + void removeOnTopicFoundListener(JNIEnv* env, jobject jListener); + + JniOnMQSubscribeListener* addOnMQTopicSubscribeListener(JNIEnv* env, jobject jListener); + void removeOnMQTopicSubscribeListener(JNIEnv* env, jobject jListener); + + OCStackResult discoveryMQTopics(JNIEnv* env, const QueryParamsMap &queryParametersMap, + jobject jListener, QualityOfService QoS); + OCStackResult createMQTopic(JNIEnv* env, const OCRepresentation &representation, + const std::string &targetUri, + const QueryParamsMap &queryParametersMap, + jobject jListener, QualityOfService QoS); +#endif +#ifdef MQ_SUBSCRIBER + OCStackResult subscribeMQTopic(JNIEnv* env, const QueryParamsMap &queryParametersMap, + jobject jListener, QualityOfService QoS); + OCStackResult unsubscribeMQTopic(QualityOfService QoS); + OCStackResult requestMQPublish(JNIEnv* env, const QueryParamsMap &queryParametersMap, + jobject jListener, QualityOfService QoS); +#endif +#ifdef MQ_PUBLISHER + OCStackResult publishMQTopic(JNIEnv* env, const OCRepresentation &representation, + const QueryParamsMap &queryParametersMap, + jobject jListener, QualityOfService QoS); +#endif + private: JniListenerManager m_onGetManager; JniListenerManager m_onPutManager; JniListenerManager m_onPostManager; JniListenerManager m_onDeleteManager; JniListenerManager m_onObserveManager; +#ifdef WITH_MQ + JniListenerManager m_onFoundTopicResourceManager; + JniListenerManager m_onSubcribeTopicManager; +#endif std::shared_ptr m_sharedResource; }; @@ -345,7 +380,57 @@ extern "C" { JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_dispose (JNIEnv *, jobject); + /* + * Class: org_iotivity_base_OcResource + * Method: subscribeMQTopicImpl + * Signature: (Ljava/util/Map;Lorg/iotivity/base/OcResource/OnObserveListener;I)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_subscribeMQTopicImpl + (JNIEnv *, jobject, jobject, jobject, jint); + + /* + * Class: org_iotivity_base_OcResource + * Method: unsubscribeMQTopicImpl + * Signature: (I)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_unsubscribeMQTopicImpl + (JNIEnv *, jobject, jint); + + /* + * Class: org_iotivity_base_OcResource + * Method: requestMQPublishImpl + * Signature: (Ljava/util/Map;Lorg/iotivity/base/OcResource/OnPostListener;I)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_requestMQPublishImpl + (JNIEnv *, jobject, jobject, jobject, jint); + + /* + * Class: org_iotivity_base_OcResource + * Method: publishMQTopicImpl + * Signature: (Lorg/iotivity/base/OcRepresentation;Ljava/util/Map + * ;Lorg/iotivity/base/OcResource/OnPostListener;I)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_publishMQTopicImpl + (JNIEnv *, jobject, jobject, jobject, jobject, jint); + + /* + * Class: org_iotivity_base_OcResource + * Method: discoveryMQTopicsImpl + * Signature: (Ljava/util/Map;Lorg/iotivity/base/OcResource/OnMQTopicFoundListener;I)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_discoveryMQTopicsImpl + (JNIEnv *, jobject, jobject, jobject, jint); + + /* + * Class: org_iotivity_base_OcResource + * Method: createMQTopicImpl + * Signature: (Lorg/iotivity/base/OcRepresentation;Ljava/util/String;Ljava/util/Map + * ;Lorg/iotivity/base/OcPlatform/OnMQTopicCreatedListener;I)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_createMQTopicImpl + (JNIEnv *, jobject, jobject, jstring, jobject, jobject, jint); + #ifdef __cplusplus } #endif -#endif \ No newline at end of file +#endif diff --git a/android/android_api/base/jni/JniOcResourceHandle.cpp b/android/android_api/base/jni/JniOcResourceHandle.cpp index 2d438f27c..92371f435 100644 --- a/android/android_api/base/jni/JniOcResourceHandle.cpp +++ b/android/android_api/base/jni/JniOcResourceHandle.cpp @@ -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 +} diff --git a/android/android_api/base/jni/JniOcResourceIdentifier.cpp b/android/android_api/base/jni/JniOcResourceIdentifier.cpp index b0b7d657f..beeb724f4 100644 --- a/android/android_api/base/jni/JniOcResourceIdentifier.cpp +++ b/android/android_api/base/jni/JniOcResourceIdentifier.cpp @@ -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 +} diff --git a/android/android_api/base/jni/JniOcResourceRequest.cpp b/android/android_api/base/jni/JniOcResourceRequest.cpp index c943f70a0..c977bace6 100644 --- a/android/android_api/base/jni/JniOcResourceRequest.cpp +++ b/android/android_api/base/jni/JniOcResourceRequest.cpp @@ -29,10 +29,12 @@ using namespace OC; JniOcResourceRequest::JniOcResourceRequest(const std::shared_ptr 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(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(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(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 +} diff --git a/android/android_api/base/jni/JniOcResourceResponse.cpp b/android/android_api/base/jni/JniOcResourceResponse.cpp index 0781d9f82..818907371 100644 --- a/android/android_api/base/jni/JniOcResourceResponse.cpp +++ b/android/android_api/base/jni/JniOcResourceResponse.cpp @@ -30,10 +30,13 @@ using namespace OC; JniOcResourceResponse::JniOcResourceResponse (std::shared_ptr 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(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(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 +} diff --git a/android/android_api/base/jni/JniOcSecureResource.cpp b/android/android_api/base/jni/JniOcSecureResource.cpp index 4b12e525e..2c6274bba 100644 --- a/android/android_api/base/jni/JniOcSecureResource.cpp +++ b/android/android_api/base/jni/JniOcSecureResource.cpp @@ -209,6 +209,22 @@ OCStackResult JniOcSecureResource::provisionCredentials(JNIEnv* env, jint type, resultCallback); } +#if defined(__WITH_TLS__) +OCStackResult JniOcSecureResource::provisionTrustCertChain(JNIEnv* env, jint type, jint credId, + jobject jListener) +{ + JniProvisionResultListner *resultListener = AddProvisionResultListener(env, jListener); + + ResultCallBack resultCallback = [resultListener](PMResultList_t *result, int hasError) + { + resultListener->ProvisionResultCallback(result, hasError, ListenerFunc::PROVISIONTRUSTCERTCHAIN); + }; + + return m_sharedSecureResource->provisionTrustCertChain((OicSecCredType_t)type, credId, + resultCallback); +} +#endif + OCStackResult JniOcSecureResource::provisionACL(JNIEnv* env, jobject _acl, jobject jListener) { OCStackResult ret; @@ -222,20 +238,20 @@ OCStackResult JniOcSecureResource::provisionACL(JNIEnv* env, jobject _acl, jobje if (OC_STACK_OK != JniSecureUtils::convertJavaACLToOCAcl(env, _acl, acl)) { - JniSecureUtils::FreeACLList(acl); + DeleteACLList(acl); return OC_STACK_ERROR; } ResultCallBack resultCallback = [acl, resultListener](PMResultList_t *result, int hasError) { - JniSecureUtils::FreeACLList(acl); + DeleteACLList(acl); resultListener->ProvisionResultCallback(result, hasError, ListenerFunc::PROVISIONACL); }; ret = m_sharedSecureResource->provisionACL(acl, resultCallback); if (ret != OC_STACK_OK) { - JniSecureUtils::FreeACLList(acl); + DeleteACLList(acl); } return ret; } @@ -327,7 +343,10 @@ OCStackResult JniOcSecureResource::provisionPairwiseDevices(JNIEnv* env, jint ty jobject _acl1, jobject _device2, jobject _acl2, jobject jListener) { OCStackResult ret; - + if(!jListener) + { + return OC_STACK_INVALID_CALLBACK; + } JniProvisionResultListner *resultListener = AddProvisionResultListener(env, jListener); JniOcSecureResource *device2 = JniOcSecureResource::getJniOcSecureResourcePtr(env, _device2); if (!device2) @@ -350,7 +369,7 @@ OCStackResult JniOcSecureResource::provisionPairwiseDevices(JNIEnv* env, jint ty if (OC_STACK_OK != JniSecureUtils::convertJavaACLToOCAcl(env, _acl1, acl1)) { - JniSecureUtils::FreeACLList(acl1); + DeleteACLList(acl1); return OC_STACK_ERROR; } } @@ -360,14 +379,13 @@ OCStackResult JniOcSecureResource::provisionPairwiseDevices(JNIEnv* env, jint ty acl2 = (OicSecAcl_t*)OICCalloc(1, sizeof(OicSecAcl_t)); if (!acl2) { - JniSecureUtils::FreeACLList(acl1); + DeleteACLList(acl1); return OC_STACK_NO_MEMORY; } if (OC_STACK_OK != JniSecureUtils::convertJavaACLToOCAcl(env, _acl2, acl2)) { - JniSecureUtils::FreeACLList(acl1); - JniSecureUtils::FreeACLList(acl2); + DeleteACLList(acl2); return OC_STACK_ERROR; } } @@ -375,18 +393,19 @@ OCStackResult JniOcSecureResource::provisionPairwiseDevices(JNIEnv* env, jint ty ResultCallBack resultCallback = [acl1, acl2, resultListener](PMResultList_t *result, int hasError) { - JniSecureUtils::FreeACLList(acl1); - JniSecureUtils::FreeACLList(acl2); + DeleteACLList(acl1); + DeleteACLList(acl2); resultListener->ProvisionResultCallback(result, hasError, ListenerFunc::PROVISIONPAIRWISEDEVICES); }; + ret = m_sharedSecureResource->provisionPairwiseDevices(cred, acl1, *device2->getDevicePtr(), acl2, resultCallback); if (ret != OC_STACK_OK) { - JniSecureUtils::FreeACLList(acl1); - JniSecureUtils::FreeACLList(acl2); + DeleteACLList(acl1); + DeleteACLList(acl2); } return ret; } @@ -402,13 +421,14 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_doOwnershipTransf LOGD("OcSecureResource_doOwnershipTransfer"); if (!jListener) { - ThrowOcException(OC_STACK_INVALID_PARAM, "provisionResultListener cannot be null"); + ThrowOcException(OC_STACK_INVALID_CALLBACK, "provisionResultListener cannot be null"); return; } JniOcSecureResource *secureResource = JniOcSecureResource::getJniOcSecureResourcePtr(env, thiz); if (!secureResource) { + ThrowOcException(OC_STACK_ERROR, "getJniOcSecureResourcePtr failed"); return; } @@ -445,13 +465,14 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_removeDevice if (!jListener) { - ThrowOcException(OC_STACK_INVALID_PARAM, "provisionResultListener cannot be null"); + ThrowOcException(OC_STACK_INVALID_CALLBACK, "provisionResultListener cannot be null"); return; } JniOcSecureResource *secureResource = JniOcSecureResource::getJniOcSecureResourcePtr(env, thiz); if (!secureResource) { + ThrowOcException(OC_STACK_ERROR, "getJniOcSecureResourcePtr failed"); return; } @@ -480,15 +501,21 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_unlinkDevices (JNIEnv *env, jobject thiz, jobject device2, jobject jListener) { LOGD("OcSecureResource_unlinkDevices"); - if (!jListener || !device2) + if (!jListener) { - ThrowOcException(OC_STACK_INVALID_PARAM, "provisionResultListener or device2 cannot be null"); + ThrowOcException(OC_STACK_INVALID_CALLBACK, "provisionResultListener cannot be null"); + return; + } + if (!device2) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "device2 cannot be null"); return; } JniOcSecureResource *secureResource = JniOcSecureResource::getJniOcSecureResourcePtr(env, thiz); if (!secureResource) { + ThrowOcException(OC_STACK_ERROR, "getJniOcSecureResourcePtr failed"); return; } @@ -513,19 +540,25 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_unlinkDevices * Method: provisionCredentials1 * Signature: (Lorg/iotivity/base/OcSecureResource/provisionCredentials;)V */ -JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_provisionCredentials1 + JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_provisionCredentials1 (JNIEnv *env, jobject thiz, jint type, jint keySize, jobject device2, jobject jListener) { LOGD("OcSecureResource_provisionCredentials"); - if (!jListener || !device2) + if (!jListener) { - ThrowOcException(OC_STACK_INVALID_PARAM, "provisionResultListener or device2 cannot be null"); + ThrowOcException(OC_STACK_INVALID_CALLBACK, "provisionResultListener cannot be null"); + return; + } + if (!device2) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "device2 cannot be null"); return; } JniOcSecureResource *secureResource = JniOcSecureResource::getJniOcSecureResourcePtr(env, thiz); if (!secureResource) { + ThrowOcException(OC_STACK_ERROR, "getJniOcSecureResourcePtr failed"); return; } @@ -546,6 +579,49 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_provisionCredenti } } +/* + * Class: org_iotivity_base_OcSecureResource + * Method: provisionTrustCertChain1 + * Signature: (Lorg/iotivity/base/OcSecureResource/provisionTrustCertChain1;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_provisionTrustCertChain1 +(JNIEnv *env, jobject thiz, jint type, jint credId, jobject jListener) +{ + LOGD("OcSecureResource_provisionTrustCertChain1"); +#if defined(__WITH_DTLS__) || defined(__WITH_TLS__) + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_CALLBACK, "provisionTrustCertChainListener cannot be null"); + return; + } + + JniOcSecureResource *secureResource = JniOcSecureResource::getJniOcSecureResourcePtr(env, thiz); + if (!secureResource) + { + return; + } + + try + { + OCStackResult result = secureResource->provisionTrustCertChain(env, type, credId, + jListener); + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcSecureResource_provisionTrustCertChain1"); + return; + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +#else + ThrowOcException(OC_STACK_INVALID_PARAM, "WITH_TLS not enabled"); + return; +#endif // __WITH_DTLS__ || __WITH_TLS__ +} + /* * Class: org_iotivity_base_OcSecureResource * Method: provisionACL @@ -555,15 +631,21 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_provisionACL (JNIEnv *env, jobject thiz, jobject acl, jobject jListener) { LOGD("OcSecureResource_provisionACL"); - if (!jListener || !acl) + if (!jListener) { - ThrowOcException(OC_STACK_INVALID_PARAM, "provisionResultListener or acl cannot be null"); + ThrowOcException(OC_STACK_INVALID_CALLBACK, "provisionResultListener cannot be null"); + return; + } + if (!acl) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "acl cannot be null"); return; } JniOcSecureResource *secureResource = JniOcSecureResource::getJniOcSecureResourcePtr(env, thiz); if (!secureResource) { + ThrowOcException(OC_STACK_ERROR, "getJniOcSecureResourcePtr failed"); return; } @@ -593,15 +675,21 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_provisionPairwise jobject acl2, jobject jListener) { LOGD("OcSecureResource_provisionPairwiseDevices"); - if (!jListener || !device2) + if (!jListener) { - ThrowOcException(OC_STACK_INVALID_PARAM, "Invalid Parameters"); + ThrowOcException(OC_STACK_INVALID_CALLBACK, "Invalid Callback"); + return; + } + if (!device2) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "device2 cannot be null"); return; } JniOcSecureResource *secureResource = JniOcSecureResource::getJniOcSecureResourcePtr(env, thiz); if (!secureResource) { + ThrowOcException(OC_STACK_ERROR, "getJniOcSecureResourcePtr failed"); return; } @@ -632,7 +720,12 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_provisionDirectPa jint jedp, jobject jListener) { LOGD("OcSecureResource_provisionDirectPairing"); - if (!jListener || !pdacls || !jpin || ! jprmType) + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_CALLBACK, "Invalid Callback"); + return; + } + if (!pdacls || !jpin || ! jprmType) { ThrowOcException(OC_STACK_INVALID_PARAM, "Invalid Parameters"); return; @@ -642,6 +735,7 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_provisionDirectPa JniOcSecureResource *secureResource = JniOcSecureResource::getJniOcSecureResourcePtr(env, thiz); if (!secureResource) { + ThrowOcException(OC_STACK_ERROR, "getJniOcSecureResourcePtr failed"); return; } @@ -685,6 +779,7 @@ JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcSecureResource_getLinkedDevic JniOcSecureResource *secureResource = JniOcSecureResource::getJniOcSecureResourcePtr(env, thiz); if (!secureResource) { + ThrowOcException(OC_STACK_ERROR, "getJniOcSecureResourcePtr failed"); return nullptr; } @@ -718,6 +813,7 @@ JNIEXPORT jstring JNICALL Java_org_iotivity_base_OcSecureResource_getIpAddr JniOcSecureResource *secureResource = JniOcSecureResource::getJniOcSecureResourcePtr(env, thiz); if (!secureResource) { + LOGD("getJniOcSecureResourcePtr failed"); return nullptr; } @@ -736,6 +832,7 @@ JNIEXPORT jstring JNICALL Java_org_iotivity_base_OcSecureResource_getDeviceID JniOcSecureResource *secureResource = JniOcSecureResource::getJniOcSecureResourcePtr(env, thiz); if (!secureResource) { + LOGD("getJniOcSecureResourcePtr failed"); return nullptr; } @@ -754,6 +851,7 @@ JNIEXPORT jint JNICALL Java_org_iotivity_base_OcSecureResource_deviceStatus JniOcSecureResource *secureResource = JniOcSecureResource::getJniOcSecureResourcePtr(env, thiz); if (!secureResource) { + LOGD("getJniOcSecureResourcePtr failed"); return -1; } @@ -772,6 +870,7 @@ JNIEXPORT jint JNICALL Java_org_iotivity_base_OcSecureResource_ownedStatus JniOcSecureResource *secureResource = JniOcSecureResource::getJniOcSecureResourcePtr(env, thiz); if (!secureResource) { + LOGD("getJniOcSecureResourcePtr failed"); return -1; } diff --git a/android/android_api/base/jni/JniOcSecureResource.h b/android/android_api/base/jni/JniOcSecureResource.h index d071e968d..213f20db2 100644 --- a/android/android_api/base/jni/JniOcSecureResource.h +++ b/android/android_api/base/jni/JniOcSecureResource.h @@ -53,6 +53,8 @@ class JniOcSecureResource jobject acl1, jobject device2, jobject acl2, jobject jListener); OCStackResult provisionCredentials(JNIEnv* env, jint type, jint keySize, jobject device2, jobject jListener); + OCStackResult provisionTrustCertChain(JNIEnv* env, jint type, jint credId, + jobject jListener); OCStackResult unlinkDevices(JNIEnv* env, jobject device2, jobject jListener); OCStackResult removeDevice(JNIEnv* env, jint timeout, jobject jListener); OCStackResult provisionDirectPairing(JNIEnv* env, jobjectArray jpdacls,jobject jListener, @@ -99,7 +101,15 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_unlinkDevices * Signature: (IILjava/lang/Object;Lorg/iotivity/base/OcSecureResource/ProvisionCredentialsListener;)V */ JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_provisionCredentials1 - (JNIEnv *, jobject, jint, jint, jobject, jobject); + (JNIEnv *, jobject, jint, jint, jobject, jobject); + +/* + * Class: org_iotivity_base_OcSecureResource + * Method: provisionTrustCertChain1 + * Signature: (Lorg/iotivity/base/OcSecureResource/ProvisionTrustCertChainListener;)V + */ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_provisionTrustCertChain1 + (JNIEnv *, jobject, jint, jint, jobject); /* * Class: org_iotivity_base_OcSecureResource @@ -107,7 +117,7 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_provisionCredenti * Signature: (Ljava/lang/Object;Lorg/iotivity/base/OcSecureResource/ProvisionAclListener;)V */ JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_provisionACL - (JNIEnv *, jobject, jobject, jobject); + (JNIEnv *, jobject, jobject, jobject); /* * Class: org_iotivity_base_OcSecureResource diff --git a/android/android_api/base/jni/JniOcStack.cpp b/android/android_api/base/jni/JniOcStack.cpp index 18d01603a..03cb4adae 100644 --- a/android/android_api/base/jni/JniOcStack.cpp +++ b/android/android_api/base/jni/JniOcStack.cpp @@ -39,6 +39,9 @@ JavaVM* g_jvm = nullptr; +jclass g_cls_byte1DArray = nullptr; +jclass g_cls_byte2DArray = nullptr; +jclass g_cls_byte3DArray = nullptr; jclass g_cls_Integer = nullptr; jclass g_cls_int1DArray = nullptr; jclass g_cls_int2DArray = nullptr; @@ -79,6 +82,12 @@ jclass g_cls_OcOicSecAcl_resr = nullptr; jclass g_cls_OcOicSecAcl_validity = nullptr; jclass g_cls_OcOicSecPdAcl = nullptr; jclass g_cls_OcDirectPairDevice = nullptr; +#ifdef __WITH_TLS__ +jclass g_cls_OcCloudProvisioning = nullptr; +#endif +#ifdef WITH_CLOUD +jclass g_cls_OcAccountManager = nullptr; +#endif jmethodID g_mid_Integer_ctor = nullptr; jmethodID g_mid_Double_ctor = nullptr; @@ -102,6 +111,7 @@ jmethodID g_mid_OcResourceRequest_N_ctor = nullptr; jmethodID g_mid_OcResourceResponse_N_ctor = nullptr; jmethodID g_mid_OcResourceHandle_N_ctor = nullptr; jmethodID g_mid_OcPresenceHandle_N_ctor = nullptr; + jmethodID g_mid_OcRequestHandle_N_ctor = nullptr; jmethodID g_mid_OcHeaderOption_ctor = nullptr; jmethodID g_mid_OcHeaderOption_get_id = nullptr; @@ -113,6 +123,9 @@ jmethodID g_mid_OcProvisionResult_ctor = nullptr; jmethodID g_mid_OcSecureResource_ctor = nullptr; jmethodID g_mid_OcDirectPairDevice_ctor = nullptr; jmethodID g_mid_OcDirectPairDevice_dev_ctor = nullptr; +#ifdef WITH_CLOUD +jmethodID g_mid_OcAccountManager_ctor = nullptr; +#endif jmethodID g_mid_OcOicSecPdAcl_get_resources_cnt = nullptr; jmethodID g_mid_OcOicSecPdAcl_get_resources = nullptr; @@ -137,6 +150,11 @@ jmethodID g_mid_OcOicSecAcl_validity_get_recurrenceLen = nullptr; jmethodID g_mid_OcOicSecAcl_resr_get_interfaceLen = nullptr; jmethodID g_mid_OcOicSecAcl_get_rownerID = nullptr; +#ifdef __WITH_TLS__ +jmethodID g_mid_OcCloudProvisioning_getIP = nullptr; +jmethodID g_mid_OcCloudProvisioning_getPort = nullptr; +#endif + jobject getOcException(JNIEnv* env, const char* file, const char* functionName, const int line, const int code, const char* message) { @@ -186,6 +204,22 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved) jclass clazz = nullptr; + //byte + clazz = env->FindClass("[B"); + VERIFY_VARIABLE_NULL(clazz); + g_cls_byte1DArray = (jclass)env->NewGlobalRef(clazz); + env->DeleteLocalRef(clazz); + + clazz = env->FindClass("[[B"); + VERIFY_VARIABLE_NULL(clazz); + g_cls_byte2DArray = (jclass)env->NewGlobalRef(clazz); + env->DeleteLocalRef(clazz); + + clazz = env->FindClass("[[[B"); + VERIFY_VARIABLE_NULL(clazz); + g_cls_byte3DArray = (jclass)env->NewGlobalRef(clazz); + env->DeleteLocalRef(clazz); + //Integer clazz = env->FindClass("java/lang/Integer"); VERIFY_VARIABLE_NULL(clazz); @@ -476,6 +510,17 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved) VERIFY_VARIABLE_NULL(g_mid_OcDirectPairDevice_dev_ctor); env->DeleteLocalRef(clazz); +#ifdef WITH_CLOUD + //OcAccountManager + clazz = env->FindClass("org/iotivity/base/OcAccountManager"); + VERIFY_VARIABLE_NULL(clazz); + g_cls_OcAccountManager = (jclass)env->NewGlobalRef(clazz); + env->DeleteLocalRef(clazz); + + g_mid_OcAccountManager_ctor = env->GetMethodID(g_cls_OcAccountManager, "", "(J)V"); + VERIFY_VARIABLE_NULL(g_mid_OcAccountManager_ctor); +#endif + //OicSecAcl clazz = env->FindClass("org/iotivity/base/OicSecAcl"); VERIFY_VARIABLE_NULL(clazz); @@ -568,14 +613,26 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved) g_mid_OcOicSecPdAcl_get_recurrences = env->GetMethodID(g_cls_OcOicSecPdAcl, "getRecurrences", "(I)Ljava/lang/String;"); VERIFY_VARIABLE_NULL(g_mid_OcOicSecPdAcl_get_recurrences); +#ifdef __WITH_TLS__ + //OcCloudProvisioning + clazz = env->FindClass("org/iotivity/base/OcCloudProvisioning"); + VERIFY_VARIABLE_NULL(clazz); + g_cls_OcCloudProvisioning = (jclass)env->NewGlobalRef(clazz); + env->DeleteLocalRef(clazz); + + g_mid_OcCloudProvisioning_getIP = env->GetMethodID(g_cls_OcCloudProvisioning, "getIP", "()Ljava/lang/String;"); + VERIFY_VARIABLE_NULL(g_mid_OcCloudProvisioning_getIP); + g_mid_OcCloudProvisioning_getPort = env->GetMethodID(g_cls_OcCloudProvisioning, "getPort", "()I"); + VERIFY_VARIABLE_NULL(g_mid_OcCloudProvisioning_getPort); +#endif return JNI_CURRENT_VERSION; } JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved) { LOGI("JNI_OnUnload"); - JNIEnv* env; + JNIEnv* env = nullptr; if (vm->GetEnv((void **)&env, JNI_CURRENT_VERSION) != JNI_OK) { @@ -583,42 +640,55 @@ 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); - env->DeleteGlobalRef(g_cls_Double); - env->DeleteGlobalRef(g_cls_double1DArray); - env->DeleteGlobalRef(g_cls_double2DArray); - env->DeleteGlobalRef(g_cls_Boolean); - env->DeleteGlobalRef(g_cls_boolean1DArray); - env->DeleteGlobalRef(g_cls_boolean2DArray); - env->DeleteGlobalRef(g_cls_String); - env->DeleteGlobalRef(g_cls_String1DArray); - env->DeleteGlobalRef(g_cls_String2DArray); - env->DeleteGlobalRef(g_cls_LinkedList); - env->DeleteGlobalRef(g_cls_Map); - env->DeleteGlobalRef(g_cls_MapEntry); - env->DeleteGlobalRef(g_cls_Set); - env->DeleteGlobalRef(g_cls_Iterator); - env->DeleteGlobalRef(g_cls_HashMap); - env->DeleteGlobalRef(g_cls_OcResource); - env->DeleteGlobalRef(g_cls_OcException); - env->DeleteGlobalRef(g_cls_OcRepresentation); - env->DeleteGlobalRef(g_cls_OcRepresentation1DArray); - env->DeleteGlobalRef(g_cls_OcRepresentation2DArray); - env->DeleteGlobalRef(g_cls_OcResourceRequest); - env->DeleteGlobalRef(g_cls_OcResourceResponse); - env->DeleteGlobalRef(g_cls_OcResourceHandle); - env->DeleteGlobalRef(g_cls_OcPresenceHandle); - env->DeleteGlobalRef(g_cls_OcRequestHandle); - env->DeleteGlobalRef(g_cls_OcPresenceStatus); - env->DeleteGlobalRef(g_cls_OcHeaderOption); - env->DeleteGlobalRef(g_cls_ObservationInfo); - env->DeleteGlobalRef(g_cls_OcResourceIdentifier); - env->DeleteGlobalRef(g_cls_OcSecureResource); - env->DeleteGlobalRef(g_cls_OcProvisionResult); - env->DeleteGlobalRef(g_cls_OcOicSecAcl); - env->DeleteGlobalRef(g_cls_OcOicSecAcl_ace); - env->DeleteGlobalRef(g_cls_OcOicSecAcl_resr); - env->DeleteGlobalRef(g_cls_OcOicSecAcl_validity); + if (env) + { + env->DeleteGlobalRef(g_cls_Integer); + env->DeleteGlobalRef(g_cls_int1DArray); + env->DeleteGlobalRef(g_cls_int2DArray); + env->DeleteGlobalRef(g_cls_Double); + env->DeleteGlobalRef(g_cls_double1DArray); + env->DeleteGlobalRef(g_cls_double2DArray); + env->DeleteGlobalRef(g_cls_Boolean); + env->DeleteGlobalRef(g_cls_boolean1DArray); + env->DeleteGlobalRef(g_cls_boolean2DArray); + env->DeleteGlobalRef(g_cls_String); + env->DeleteGlobalRef(g_cls_String1DArray); + env->DeleteGlobalRef(g_cls_String2DArray); + env->DeleteGlobalRef(g_cls_LinkedList); + env->DeleteGlobalRef(g_cls_Map); + env->DeleteGlobalRef(g_cls_MapEntry); + env->DeleteGlobalRef(g_cls_Set); + env->DeleteGlobalRef(g_cls_Iterator); + env->DeleteGlobalRef(g_cls_HashMap); + env->DeleteGlobalRef(g_cls_OcResource); + env->DeleteGlobalRef(g_cls_OcException); + env->DeleteGlobalRef(g_cls_OcRepresentation); + env->DeleteGlobalRef(g_cls_OcRepresentation1DArray); + env->DeleteGlobalRef(g_cls_OcRepresentation2DArray); + env->DeleteGlobalRef(g_cls_OcResourceRequest); + env->DeleteGlobalRef(g_cls_OcResourceResponse); + env->DeleteGlobalRef(g_cls_OcResourceHandle); + env->DeleteGlobalRef(g_cls_OcPresenceHandle); + env->DeleteGlobalRef(g_cls_OcRequestHandle); + env->DeleteGlobalRef(g_cls_OcPresenceStatus); + env->DeleteGlobalRef(g_cls_OcHeaderOption); + env->DeleteGlobalRef(g_cls_ObservationInfo); + env->DeleteGlobalRef(g_cls_OcResourceIdentifier); + env->DeleteGlobalRef(g_cls_OcSecureResource); + env->DeleteGlobalRef(g_cls_OcProvisionResult); + env->DeleteGlobalRef(g_cls_OcDirectPairDevice); + env->DeleteGlobalRef(g_cls_byte1DArray); + env->DeleteGlobalRef(g_cls_byte2DArray); + env->DeleteGlobalRef(g_cls_byte3DArray); +#ifdef WITH_CLOUD + env->DeleteGlobalRef(g_cls_OcAccountManager); +#endif +#ifdef __WITH_TLS__ + env->DeleteGlobalRef(g_cls_OcCloudProvisioning); +#endif + env->DeleteGlobalRef(g_cls_OcOicSecAcl); + env->DeleteGlobalRef(g_cls_OcOicSecAcl_ace); + env->DeleteGlobalRef(g_cls_OcOicSecAcl_resr); + env->DeleteGlobalRef(g_cls_OcOicSecAcl_validity); + } } diff --git a/android/android_api/base/jni/JniOcStack.h b/android/android_api/base/jni/JniOcStack.h index 243ce4cd0..db5ea1e2b 100644 --- a/android/android_api/base/jni/JniOcStack.h +++ b/android/android_api/base/jni/JniOcStack.h @@ -38,6 +38,7 @@ #define JNI_NO_NATIVE_POINTER 1001 #define JNI_INVALID_VALUE 1002 #define JNI_NO_SUCH_KEY 1003 +#define JNI_NO_SUPPORT 1004 jobject getOcException(JNIEnv* env, const char* file, const char* functionName, const int line, const int code, const char* message); @@ -47,6 +48,9 @@ void throwOcException(JNIEnv* env, jobject ex); extern JavaVM* g_jvm; +extern jclass g_cls_byte1DArray; +extern jclass g_cls_byte2DArray; +extern jclass g_cls_byte3DArray; extern jclass g_cls_Integer; extern jclass g_cls_int1DArray; extern jclass g_cls_int2DArray; @@ -84,6 +88,12 @@ extern jclass g_cls_OcSecureResource; extern jclass g_cls_OcOicSecAcl; extern jclass g_cls_OcOicSecPdAcl; extern jclass g_cls_OcDirectPairDevice; +#ifdef WITH_CLOUD +extern jclass g_cls_OcAccountManager; +#endif +#ifdef __WITH_TLS__ +extern jclass g_cls_OcCloudProvisioning; +#endif extern jclass g_cls_OcOicSecAcl_ace; extern jclass g_cls_OcOicSecAcl_resr; @@ -122,6 +132,13 @@ extern jmethodID g_mid_OcProvisionResult_ctor; extern jmethodID g_mid_OcSecureResource_ctor; extern jmethodID g_mid_OcDirectPairDevice_ctor; extern jmethodID g_mid_OcDirectPairDevice_dev_ctor; +#ifdef WITH_CLOUD +extern jmethodID g_mid_OcAccountManager_ctor; +#endif +#ifdef __WITH_TLS__ +extern jmethodID g_mid_OcCloudProvisioning_getIP; +extern jmethodID g_mid_OcCloudProvisioning_getPort; +#endif extern jmethodID g_mid_OcOicSecAcl_get_rownerID; extern jmethodID g_mid_OcOicSecAcl_get_aces; @@ -145,6 +162,7 @@ extern jmethodID g_mid_OcOicSecPdAcl_get_periods_cnt; extern jmethodID g_mid_OcOicSecPdAcl_get_periods; extern jmethodID g_mid_OcOicSecPdAcl_get_recurrences; + typedef void(*RemoveListenerCallback)(JNIEnv* env, jobject jListener); static jfieldID GetHandleField(JNIEnv *env, jobject jobj) diff --git a/android/android_api/base/jni/JniOnDPDevicesFoundListener.cpp b/android/android_api/base/jni/JniOnDPDevicesFoundListener.cpp index 5c5d900ac..a0ffd05c4 100644 --- a/android/android_api/base/jni/JniOnDPDevicesFoundListener.cpp +++ b/android/android_api/base/jni/JniOnDPDevicesFoundListener.cpp @@ -77,26 +77,38 @@ 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(); + } } } void JniOnDPDevicesFoundListener::directPairingDevicesCallback(PairedDevices paringDevicesList, DPFunc func) { - 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; } @@ -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) diff --git a/android/android_api/base/jni/JniOnDeleteListener.cpp b/android/android_api/base/jni/JniOnDeleteListener.cpp index 87ebd716d..bb0f5dbc4 100644 --- a/android/android_api/base/jni/JniOnDeleteListener.cpp +++ b/android/android_api/base/jni/JniOnDeleteListener.cpp @@ -23,46 +23,75 @@ #include "JniOnDeleteListener.h" #include "JniOcResource.h" #include "JniUtils.h" +#ifdef WITH_CLOUD +#include "JniOcAccountManager.h" +#endif JniOnDeleteListener::JniOnDeleteListener(JNIEnv *env, jobject jListener, JniOcResource* owner) : m_ownerResource(owner) { m_jwListener = env->NewWeakGlobalRef(jListener); +#ifdef WITH_CLOUD + m_ownerAccountManager = nullptr; +#endif } +#ifdef WITH_CLOUD +JniOnDeleteListener::JniOnDeleteListener(JNIEnv *env, jobject jListener, JniOcAccountManager* owner) + : m_ownerAccountManager(owner) +{ + m_jwListener = env->NewWeakGlobalRef(jListener); + m_ownerResource = nullptr; +} +#endif + 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 +101,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 +125,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 +136,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) @@ -114,11 +158,33 @@ void JniOnDeleteListener::checkExAndRemoveListener(JNIEnv* env) { jthrowable ex = env->ExceptionOccurred(); env->ExceptionClear(); +#ifndef WITH_CLOUD m_ownerResource->removeOnDeleteListener(env, m_jwListener); +#else + if (nullptr != m_ownerResource) + { + m_ownerResource->removeOnDeleteListener(env, m_jwListener); + } + if (nullptr != m_ownerAccountManager) + { + m_ownerAccountManager->removeOnDeleteListener(env, m_jwListener); + } +#endif env->Throw((jthrowable)ex); } else { +#ifndef WITH_CLOUD m_ownerResource->removeOnDeleteListener(env, m_jwListener); +#else + if (nullptr != m_ownerResource) + { + m_ownerResource->removeOnDeleteListener(env, m_jwListener); + } + if (nullptr != m_ownerAccountManager) + { + m_ownerAccountManager->removeOnDeleteListener(env, m_jwListener); + } +#endif } -} \ No newline at end of file +} diff --git a/android/android_api/base/jni/JniOnDeleteListener.h b/android/android_api/base/jni/JniOnDeleteListener.h index 20de33f5e..9354232c7 100644 --- a/android/android_api/base/jni/JniOnDeleteListener.h +++ b/android/android_api/base/jni/JniOnDeleteListener.h @@ -27,11 +27,17 @@ using namespace OC; class JniOcResource; +#ifdef WITH_CLOUD +class JniOcAccountManager; +#endif class JniOnDeleteListener { public: JniOnDeleteListener(JNIEnv *env, jobject jListener, JniOcResource* owner); +#ifdef WITH_CLOUD + JniOnDeleteListener(JNIEnv *env, jobject jListener, JniOcAccountManager* owner); +#endif ~JniOnDeleteListener(); void onDeleteCallback(const HeaderOptions&, const int eCode); @@ -39,7 +45,10 @@ public: private: jweak m_jwListener; JniOcResource* m_ownerResource; +#ifdef WITH_CLOUD + JniOcAccountManager* m_ownerAccountManager; +#endif void checkExAndRemoveListener(JNIEnv *env); }; -#endif \ No newline at end of file +#endif diff --git a/android/android_api/base/jni/JniOnDeleteResourceListener.cpp b/android/android_api/base/jni/JniOnDeleteResourceListener.cpp new file mode 100644 index 000000000..3520c077b --- /dev/null +++ b/android/android_api/base/jni/JniOnDeleteResourceListener.cpp @@ -0,0 +1,112 @@ +/* **************************************************************** + * + * Copyright 2016 Samsung Electronics All Rights Reserved. + * + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************/ +#include "JniOnDeleteResourceListener.h" + +JniOnDeleteResourceListener::JniOnDeleteResourceListener(JNIEnv *env, jobject jListener, + RemoveListenerCallback removeListenerCallback) +{ + m_jwListener = env->NewWeakGlobalRef(jListener); + m_removeListenerCallback = removeListenerCallback; +} + +JniOnDeleteResourceListener::~JniOnDeleteResourceListener() +{ + LOGI("~JniOnDeleteResourceListener()"); + if (m_jwListener) + { + jint ret = JNI_ERR; + JNIEnv *env = GetJNIEnv(ret); + if (nullptr == env) + { + return; + } + env->DeleteWeakGlobalRef(m_jwListener); + m_jwListener = nullptr; + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } + } +} + +void JniOnDeleteResourceListener::onDeleteResourceCallback(const int eCode) +{ + jint envRet = JNI_ERR; + JNIEnv *env = GetJNIEnv(envRet); + if (nullptr == env) + { + return; + } + + jobject jListener = env->NewLocalRef(m_jwListener); + if (!jListener) + { + checkExAndRemoveListener(env); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } + return; + } + jclass clsL = env->GetObjectClass(jListener); + if (!clsL) + { + checkExAndRemoveListener(env); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } + return; + } + + jint jres = static_cast(eCode); + jmethodID midL = env->GetMethodID(clsL, "onDeleteResourceCompleted", "(I)V"); + if (!midL) + { + checkExAndRemoveListener(env); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } + return; + } + env->CallVoidMethod(jListener, midL, jres); + + checkExAndRemoveListener(env); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } +} + +void JniOnDeleteResourceListener::checkExAndRemoveListener(JNIEnv* env) +{ + if (env->ExceptionCheck()) + { + jthrowable ex = env->ExceptionOccurred(); + env->ExceptionClear(); + m_removeListenerCallback(env, m_jwListener); + env->Throw((jthrowable)ex); + } + else + { + m_removeListenerCallback(env, m_jwListener); + } +} diff --git a/android/android_api/base/jni/JniOnDeleteResourceListener.h b/android/android_api/base/jni/JniOnDeleteResourceListener.h new file mode 100644 index 000000000..267646fd1 --- /dev/null +++ b/android/android_api/base/jni/JniOnDeleteResourceListener.h @@ -0,0 +1,40 @@ +/* **************************************************************** + * + * Copyright 2016 Samsung Electronics All Rights Reserved. + * + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************/ +#include "JniOcStack.h" + +#ifndef _Included_org_iotivity_base_OcPlatform_OnDeleteResourceListener +#define _Included_org_iotivity_base_OcPlatform_OnDeleteResourceListener + +using namespace OC; + +class JniOnDeleteResourceListener +{ +public: + JniOnDeleteResourceListener(JNIEnv *env, jobject listener, + RemoveListenerCallback removeListenerCallback); + ~JniOnDeleteResourceListener(); + void onDeleteResourceCallback(const int eCode); +private: + RemoveListenerCallback m_removeListenerCallback; + jweak m_jwListener; + void checkExAndRemoveListener(JNIEnv* env); +}; + +#endif diff --git a/android/android_api/base/jni/JniOnDeviceInfoListener.cpp b/android/android_api/base/jni/JniOnDeviceInfoListener.cpp index 28d8e4403..520cdfdee 100644 --- a/android/android_api/base/jni/JniOnDeviceInfoListener.cpp +++ b/android/android_api/base/jni/JniOnDeviceInfoListener.cpp @@ -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 +} diff --git a/android/android_api/base/jni/JniOnDirectPairingListener.cpp b/android/android_api/base/jni/JniOnDirectPairingListener.cpp index f580079a4..085c2b972 100644 --- a/android/android_api/base/jni/JniOnDirectPairingListener.cpp +++ b/android/android_api/base/jni/JniOnDirectPairingListener.cpp @@ -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 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(env, jresult, device); @@ -99,7 +122,10 @@ void JniOnDirectPairingListener::doDirectPairingCB(std::shared_ptrDetachCurrentThread(); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } return; } @@ -110,7 +136,11 @@ void JniOnDirectPairingListener::doDirectPairingCB(std::shared_ptrDetachCurrentThread(); + + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } } void JniOnDirectPairingListener::checkExAndRemoveListener(JNIEnv* env) diff --git a/android/android_api/base/jni/JniOnGetListener.cpp b/android/android_api/base/jni/JniOnGetListener.cpp index 2bc8624bc..9a801f16f 100644 --- a/android/android_api/base/jni/JniOnGetListener.cpp +++ b/android/android_api/base/jni/JniOnGetListener.cpp @@ -23,41 +23,68 @@ #include "JniOcResource.h" #include "JniOcRepresentation.h" #include "JniUtils.h" +#ifdef WITH_CLOUD +#include "JniOcAccountManager.h" +#endif JniOnGetListener::JniOnGetListener(JNIEnv *env, jobject jListener, JniOcResource* owner) : m_ownerResource(owner) { m_jwListener = env->NewWeakGlobalRef(jListener); +#ifdef WITH_CLOUD + m_ownerAccountManager = nullptr; +#endif } +#ifdef WITH_CLOUD +JniOnGetListener::JniOnGetListener(JNIEnv *env, jobject jListener, JniOcAccountManager* owner) + : m_ownerAccountManager(owner) +{ + m_jwListener = env->NewWeakGlobalRef(jListener); + m_ownerResource = nullptr; +} +#endif + 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 +92,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 +105,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 +129,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 +144,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 +157,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 +172,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) @@ -136,11 +184,33 @@ void JniOnGetListener::checkExAndRemoveListener(JNIEnv* env) { jthrowable ex = env->ExceptionOccurred(); env->ExceptionClear(); +#ifndef WITH_CLOUD m_ownerResource->removeOnGetListener(env, m_jwListener); +#else + if (nullptr != m_ownerResource) + { + m_ownerResource->removeOnGetListener(env, m_jwListener); + } + if (nullptr != m_ownerAccountManager) + { + m_ownerAccountManager->removeOnGetListener(env, m_jwListener); + } +#endif env->Throw((jthrowable)ex); } else { +#ifndef WITH_CLOUD m_ownerResource->removeOnGetListener(env, m_jwListener); +#else + if (nullptr != m_ownerResource) + { + m_ownerResource->removeOnGetListener(env, m_jwListener); + } + if (nullptr != m_ownerAccountManager) + { + m_ownerAccountManager->removeOnGetListener(env, m_jwListener); + } +#endif } -} \ No newline at end of file +} diff --git a/android/android_api/base/jni/JniOnGetListener.h b/android/android_api/base/jni/JniOnGetListener.h index a37b4238a..abffaa01e 100644 --- a/android/android_api/base/jni/JniOnGetListener.h +++ b/android/android_api/base/jni/JniOnGetListener.h @@ -27,17 +27,27 @@ using namespace OC; class JniOcResource; +#ifdef WITH_CLOUD +class JniOcAccountManager; +#endif class JniOnGetListener { public: JniOnGetListener(JNIEnv *env, jobject listener, JniOcResource* resource); +#ifdef WITH_CLOUD + JniOnGetListener(JNIEnv *env, jobject listener, JniOcAccountManager* resource); +#endif ~JniOnGetListener(); void onGetCallback(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode); + private: jweak m_jwListener; JniOcResource* m_ownerResource; +#ifdef WITH_CLOUD + JniOcAccountManager* m_ownerAccountManager; +#endif void checkExAndRemoveListener(JNIEnv *env); }; -#endif \ No newline at end of file +#endif diff --git a/android/android_api/base/jni/JniOnMQSubscribeListener.cpp b/android/android_api/base/jni/JniOnMQSubscribeListener.cpp new file mode 100644 index 000000000..705f644ce --- /dev/null +++ b/android/android_api/base/jni/JniOnMQSubscribeListener.cpp @@ -0,0 +1,208 @@ +/* **************************************************************** + * + * Copyright 2016 Samsung Electronics All Rights Reserved. + * + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************/ + +#include "JniOnMQSubscribeListener.h" +#include "JniOcResource.h" +#include "JniOcRepresentation.h" +#include "JniUtils.h" + +JniOnMQSubscribeListener::JniOnMQSubscribeListener(JNIEnv *env, + jobject jListener, + JniOcResource* owner) + : m_ownerResource(owner) +{ + m_jwListener = env->NewWeakGlobalRef(jListener); +} + +JniOnMQSubscribeListener::~JniOnMQSubscribeListener() +{ + if (m_jwListener) + { + jint ret = JNI_ERR; + JNIEnv *env = GetJNIEnv(ret); + if (nullptr == env) + { + return; + } + + env->DeleteWeakGlobalRef(m_jwListener); + m_jwListener = nullptr; + + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } + } +} + +void JniOnMQSubscribeListener::onSubscribeCallback(const HeaderOptions headerOptions, + const OCRepresentation& ocRepresentation, const int& eCode, const int& sequenceNumber) +{ + jint envRet = JNI_ERR; + JNIEnv *env = GetJNIEnv(envRet); + if (nullptr == env) + { + return; + } + + jobject jListener = env->NewLocalRef(m_jwListener); + if (!jListener) + { + checkExAndRemoveListener(env); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } + return; + } + jclass clsL = env->GetObjectClass(jListener); + if (!clsL) + { + env->DeleteLocalRef(jListener); + checkExAndRemoveListener(env); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } + return; + } + + if (OC_STACK_OK != eCode && OC_STACK_RESOURCE_CREATED != eCode && + OC_STACK_RESOURCE_DELETED != eCode && OC_STACK_RESOURCE_CHANGED != eCode) + { + jobject ex = GetOcException(eCode, "stack error in onSubScribeCallback"); + if (!ex) + { + goto JNI_EXIT; + } + jmethodID midL = env->GetMethodID(clsL, "onSubScribeFailed", "(Ljava/lang/Throwable;)V"); + if (!midL) + { + goto JNI_EXIT; + } + + env->CallVoidMethod(jListener, midL, ex); + } + else + { + OCRepresentation * rep = new OCRepresentation(ocRepresentation); + jlong handle = reinterpret_cast(rep); + jobject jRepresentation = env->NewObject(g_cls_OcRepresentation, + g_mid_OcRepresentation_N_ctor_bool, handle, true); + if (!jRepresentation) + { + delete rep; + goto JNI_EXIT; + } + + if (sequenceNumber != 1 + MAX_SEQUENCE_NUMBER) + { + jmethodID midL = env->GetMethodID(clsL, "onSubScribeCompleted", + "(Ljava/util/List;Lorg/iotivity/base/OcRepresentation;I)V"); + if (!midL) + { + delete rep; + env->DeleteLocalRef(jRepresentation); + goto JNI_EXIT; + } + + jobject jHeaderOptionList = JniUtils::convertHeaderOptionsVectorToJavaList(env, + headerOptions); + if (!jHeaderOptionList) + { + delete rep; + env->DeleteLocalRef(jRepresentation); + goto JNI_EXIT; + } + + env->CallVoidMethod(jListener, midL, jHeaderOptionList, jRepresentation, + static_cast(sequenceNumber)); + if (env->ExceptionCheck()) + { + LOGE("Java exception is thrown"); + delete rep; + env->DeleteLocalRef(jRepresentation); + env->DeleteLocalRef(jHeaderOptionList); + jthrowable ex = env->ExceptionOccurred(); + env->ExceptionClear(); + m_ownerResource->removeOnMQTopicSubscribeListener(env, m_jwListener); + env->Throw((jthrowable)ex); + } + } + else + { + jmethodID midL = env->GetMethodID(clsL, "onUnsubScribeCompleted", + "(Lorg/iotivity/base/OcRepresentation;I)V"); + if (!midL) + { + delete rep; + env->DeleteLocalRef(jRepresentation); + goto JNI_EXIT; + } + + env->CallVoidMethod(jListener, midL, jRepresentation, + static_cast(sequenceNumber)); + if (env->ExceptionCheck()) + { + LOGE("Java exception is thrown"); + delete rep; + env->DeleteLocalRef(jRepresentation); + jthrowable ex = env->ExceptionOccurred(); + env->ExceptionClear(); + m_ownerResource->removeOnMQTopicSubscribeListener(env, m_jwListener); + env->Throw((jthrowable)ex); + } + + checkExAndRemoveListener(env); + } + } + + env->DeleteLocalRef(clsL); + env->DeleteLocalRef(jListener); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } + return; + +JNI_EXIT: + env->DeleteLocalRef(clsL); + env->DeleteLocalRef(jListener); + checkExAndRemoveListener(env); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } +} + +void JniOnMQSubscribeListener::checkExAndRemoveListener(JNIEnv* env) +{ + if (env->ExceptionCheck()) + { + jthrowable ex = env->ExceptionOccurred(); + env->ExceptionClear(); + m_ownerResource->removeOnMQTopicSubscribeListener(env, m_jwListener); + env->Throw((jthrowable)ex); + } + else + { + m_ownerResource->removeOnMQTopicSubscribeListener(env, m_jwListener); + } +} diff --git a/android/android_api/base/jni/JniOnMQSubscribeListener.h b/android/android_api/base/jni/JniOnMQSubscribeListener.h new file mode 100644 index 000000000..6b7c05947 --- /dev/null +++ b/android/android_api/base/jni/JniOnMQSubscribeListener.h @@ -0,0 +1,45 @@ +/* **************************************************************** + * + * Copyright 2016 Samsung Electronics All Rights Reserved. + * + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************/ + +#include "JniOcStack.h" + +#ifndef _Included_org_iotivity_base_OcResource_OnMQSubscribeListener +#define _Included_org_iotivity_base_OcResource_OnMQSubscribeListener + +#define MAX_SEQUENCE_NUMBER 0xFFFFFF + +using namespace OC; + +class JniOcResource; + +class JniOnMQSubscribeListener +{ +public: + JniOnMQSubscribeListener(JNIEnv *env, jobject jListener, JniOcResource* owner); + ~JniOnMQSubscribeListener(); + void onSubscribeCallback(const HeaderOptions headerOptions, const OCRepresentation& rep, + const int& eCode, const int& sequenceNumber); +private: + jweak m_jwListener; + JniOcResource* m_ownerResource; + void checkExAndRemoveListener(JNIEnv *env); +}; + +#endif diff --git a/android/android_api/base/jni/JniOnMQTopicFoundListener.cpp b/android/android_api/base/jni/JniOnMQTopicFoundListener.cpp new file mode 100644 index 000000000..6fb1845a6 --- /dev/null +++ b/android/android_api/base/jni/JniOnMQTopicFoundListener.cpp @@ -0,0 +1,265 @@ +/* **************************************************************** + * + * Copyright 2016 Samsung Electronics All Rights Reserved. + * + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************/ + +#include "JniOnMQTopicFoundListener.h" +#include "JniOcResource.h" +#include "JniOcRepresentation.h" +#include "JniUtils.h" + +JniOnMQTopicFoundListener::JniOnMQTopicFoundListener(JNIEnv *env, jobject jListener, + JniOcResource* owner) + : m_ownerResource(owner) +{ + m_jwListener = env->NewWeakGlobalRef(jListener); +} + +JniOnMQTopicFoundListener::~JniOnMQTopicFoundListener() +{ + if (m_jwListener) + { + jint ret = JNI_ERR; + JNIEnv *env = GetJNIEnv(ret); + if (nullptr == env) + { + return; + } + + env->DeleteWeakGlobalRef(m_jwListener); + m_jwListener = nullptr; + + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } + } +} + +void JniOnMQTopicFoundListener::foundTopicCallback(const int eCode, const std::string& uri, + std::shared_ptr resource) +{ + jint ret = JNI_ERR; + JNIEnv *env = GetJNIEnv(ret); + if (nullptr == env) + { + return; + } + + jobject jListener = env->NewLocalRef(m_jwListener); + if (!jListener) + { + checkExAndRemoveListener(env); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } + return; + } + + jclass clsL = env->GetObjectClass(jListener); + if (!clsL) + { + env->DeleteLocalRef(jListener); + checkExAndRemoveListener(env); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } + return; + } + + if (OC_STACK_OK != eCode) + { + jobject ex = GetOcException(eCode, "stack error"); + if (!ex) + { + goto JNI_EXIT; + } + jmethodID midL = env->GetMethodID(clsL, "onDiscoveryTopicFailed", + "(Ljava/lang/Throwable;Ljava/lang/String;)V"); + if (!midL) + { + goto JNI_EXIT; + } + + env->CallVoidMethod(jListener, midL, ex, env->NewStringUTF(uri.c_str())); + } + else + { + + jobject jResource = env->NewObject(g_cls_OcResource, g_mid_OcResource_ctor); + if (!jResource) + { + goto JNI_EXIT; + } + + JniOcResource *jniOcResource = new JniOcResource(resource); + SetHandle(env, jResource, jniOcResource); + if (env->ExceptionCheck()) + { + delete jniOcResource; + env->DeleteLocalRef(jResource); + goto JNI_EXIT; + } + + jmethodID midL = env->GetMethodID(clsL, "onTopicDiscoveried", "(Lorg/iotivity/base/OcResource;)V"); + if (!midL) + { + delete jniOcResource; + env->DeleteLocalRef(jResource); + goto JNI_EXIT; + } + env->CallVoidMethod(jListener, midL, jResource); + if (env->ExceptionCheck()) + { + LOGE("Java exception is thrown"); + delete jniOcResource; + env->DeleteLocalRef(jResource); + goto JNI_EXIT; + } + } + + env->DeleteLocalRef(clsL); + env->DeleteLocalRef(jListener); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } + return; + +JNI_EXIT: + env->DeleteLocalRef(clsL); + env->DeleteLocalRef(jListener); + checkExAndRemoveListener(env); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } +} + +void JniOnMQTopicFoundListener::createdTopicCallback(const int eCode, const std::string& uri, + std::shared_ptr resource) +{ + jint envRet = JNI_ERR; + JNIEnv *env = GetJNIEnv(envRet); + if (nullptr == env) + { + return; + } + + jobject jListener = env->NewLocalRef(m_jwListener); + if (!jListener) + { + checkExAndRemoveListener(env); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } + return; + } + + jclass clsL = env->GetObjectClass(jListener); + if (!clsL) + { + env->DeleteLocalRef(jListener); + checkExAndRemoveListener(env); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } + return; + } + + if (OC_STACK_OK != eCode && OC_STACK_RESOURCE_CREATED != eCode && + OC_STACK_RESOURCE_CHANGED != eCode) + { + jobject ex = GetOcException(eCode, "stack error"); + if (!ex) + { + goto JNI_EXIT; + } + jmethodID midL = env->GetMethodID(clsL, "onCreateTopicFailed", + "(Ljava/lang/Throwable;Ljava/lang/String;)V"); + if (!midL) + { + goto JNI_EXIT; + } + + env->CallVoidMethod(jListener, midL, ex, env->NewStringUTF(uri.c_str())); + } + else + { + // create Resource object + jobject jResource = env->NewObject(g_cls_OcResource, g_mid_OcResource_ctor); + if (!jResource) + { + goto JNI_EXIT; + } + + JniOcResource *jniOcResource = new JniOcResource(resource); + SetHandle(env, jResource, jniOcResource); + if (env->ExceptionCheck()) + { + delete jniOcResource; + env->DeleteLocalRef(jResource); + goto JNI_EXIT; + } + + jmethodID midL = env->GetMethodID(clsL, "onTopicResourceCreated", + "(Lorg/iotivity/base/OcResource;)V"); + if (!midL) + { + delete jniOcResource; + env->DeleteLocalRef(jResource); + goto JNI_EXIT; + } + + env->CallVoidMethod(jListener, midL, jResource); + if (env->ExceptionCheck()) + { + LOGE("Java exception is thrown"); + env->DeleteLocalRef(jResource); + delete jniOcResource; + } + } + +JNI_EXIT: + env->DeleteLocalRef(clsL); + env->DeleteLocalRef(jListener); + checkExAndRemoveListener(env); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } +} + +void JniOnMQTopicFoundListener::checkExAndRemoveListener(JNIEnv* env) +{ + if (env->ExceptionCheck()) + { + jthrowable ex = env->ExceptionOccurred(); + env->ExceptionClear(); + m_ownerResource->removeOnTopicFoundListener(env, m_jwListener); + env->Throw((jthrowable)ex); + } + else + { + m_ownerResource->removeOnTopicFoundListener(env, m_jwListener); + } +} diff --git a/android/android_api/base/jni/JniOnMQTopicFoundListener.h b/android/android_api/base/jni/JniOnMQTopicFoundListener.h new file mode 100644 index 000000000..45b73a01f --- /dev/null +++ b/android/android_api/base/jni/JniOnMQTopicFoundListener.h @@ -0,0 +1,46 @@ +/* **************************************************************** + * + * Copyright 2016 Samsung Electronics All Rights Reserved. + * + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************/ +#include "JniOcStack.h" + +#ifndef _Included_org_iotivity_base_OcResource_JniOnMQTopicFoundListener +#define _Included_org_iotivity_base_OcResource_JniOnMQTopicFoundListener + +using namespace OC; + +class JniOcResource; + +class JniOnMQTopicFoundListener +{ +public: + JniOnMQTopicFoundListener(JNIEnv *env, jobject jListener, JniOcResource* owner); + ~JniOnMQTopicFoundListener(); + + void foundTopicCallback(const int eCode, const std::string& uri, + std::shared_ptr resource); + void createdTopicCallback(const int eCode, const std::string& uri, + std::shared_ptr resource); + +private: + jweak m_jwListener; + JniOcResource* m_ownerResource; + void checkExAndRemoveListener(JNIEnv* env); +}; + +#endif diff --git a/android/android_api/base/jni/JniOnObserveListener.cpp b/android/android_api/base/jni/JniOnObserveListener.cpp index 3ad1d11b4..060b19e2b 100644 --- a/android/android_api/base/jni/JniOnObserveListener.cpp +++ b/android/android_api/base/jni/JniOnObserveListener.cpp @@ -23,65 +23,108 @@ #include "JniOcResource.h" #include "JniOcRepresentation.h" #include "JniUtils.h" +#ifdef WITH_CLOUD +#include "JniOcAccountManager.h" +#endif + +#define CA_OBSERVE_MAX_SEQUENCE_NUMBER 0xFFFFFF JniOnObserveListener::JniOnObserveListener(JNIEnv *env, jobject jListener, JniOcResource* owner) : m_ownerResource(owner) { m_jwListener = env->NewWeakGlobalRef(jListener); +#ifdef WITH_CLOUD + m_ownerAccountManager = nullptr; +#endif } +#ifdef WITH_CLOUD +JniOnObserveListener::JniOnObserveListener(JNIEnv *env, jobject jListener, JniOcAccountManager* owner) + : m_ownerAccountManager(owner) +{ + m_jwListener = env->NewWeakGlobalRef(jListener); + m_ownerResource = nullptr; +} +#endif + 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; + } + + if (nullptr == m_jwListener) + { + LOGE("listener is not available"); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } + 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) { + env->DeleteLocalRef(jListener); checkExAndRemoveListener(env); - if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } return; } - if (OC_STACK_OK != eCode && OC_STACK_RESOURCE_CREATED != eCode && OC_STACK_RESOURCE_DELETED != eCode) + if (OC_STACK_OK != eCode && OC_STACK_RESOURCE_CREATED != eCode && + OC_STACK_RESOURCE_DELETED != eCode && OC_STACK_RESOURCE_CHANGED != eCode) { jobject ex = GetOcException(eCode, "stack error in onObserveCallback"); if (!ex) { - checkExAndRemoveListener(env); - if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread(); - return; + goto JNI_EXIT; } + jmethodID midL = env->GetMethodID(clsL, "onObserveFailed", "(Ljava/lang/Throwable;)V"); if (!midL) { - checkExAndRemoveListener(env); - if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread(); - return; + env->DeleteLocalRef(ex); + goto JNI_EXIT; } env->CallVoidMethod(jListener, midL, ex); } @@ -90,9 +133,7 @@ void JniOnObserveListener::onObserveCallback(const HeaderOptions headerOptions, jobject jHeaderOptionList = JniUtils::convertHeaderOptionsVectorToJavaList(env, headerOptions); if (!jHeaderOptionList) { - checkExAndRemoveListener(env); - if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread(); - return; + goto JNI_EXIT; } OCRepresentation * rep = new OCRepresentation(ocRepresentation); @@ -102,18 +143,17 @@ void JniOnObserveListener::onObserveCallback(const HeaderOptions headerOptions, if (!jRepresentation) { delete rep; - checkExAndRemoveListener(env); - if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread(); - return; + env->DeleteLocalRef(jHeaderOptionList); + goto JNI_EXIT; } jmethodID midL = env->GetMethodID(clsL, "onObserveCompleted", "(Ljava/util/List;Lorg/iotivity/base/OcRepresentation;I)V"); if (!midL) { - checkExAndRemoveListener(env); - if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread(); - return; + env->DeleteLocalRef(jRepresentation); + env->DeleteLocalRef(jHeaderOptionList); + goto JNI_EXIT; } env->CallVoidMethod(jListener, midL, jHeaderOptionList, jRepresentation, @@ -122,32 +162,89 @@ void JniOnObserveListener::onObserveCallback(const HeaderOptions headerOptions, { LOGE("Java exception is thrown"); delete rep; + env->DeleteLocalRef(jRepresentation); + env->DeleteLocalRef(jHeaderOptionList); jthrowable ex = env->ExceptionOccurred(); env->ExceptionClear(); +#ifndef WITH_CLOUD m_ownerResource->removeOnObserveListener(env, m_jwListener); +#else + if (nullptr != m_ownerResource) + { + m_ownerResource->removeOnObserveListener(env, m_jwListener); + } + if (nullptr != m_ownerAccountManager) + { + m_ownerAccountManager->removeOnObserveListener(env, m_jwListener); + } +#endif env->Throw((jthrowable)ex); } - if (OC_OBSERVE_DEREGISTER == sequenceNumber) + if (CA_OBSERVE_MAX_SEQUENCE_NUMBER + 1 == sequenceNumber) { - checkExAndRemoveListener(env); + LOGI("Observe De-registration action is successful"); + goto JNI_EXIT; } } - if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread(); + env->DeleteLocalRef(clsL); + env->DeleteLocalRef(jListener); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } + return; + +JNI_EXIT: + env->DeleteLocalRef(clsL); + env->DeleteLocalRef(jListener); + checkExAndRemoveListener(env); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } } void JniOnObserveListener::checkExAndRemoveListener(JNIEnv* env) { + LOGI("checkExAndRemoveListener"); if (env->ExceptionCheck()) { jthrowable ex = env->ExceptionOccurred(); env->ExceptionClear(); +#ifndef WITH_CLOUD m_ownerResource->removeOnObserveListener(env, m_jwListener); +#else + if (nullptr != m_ownerResource) + { + m_ownerResource->removeOnObserveListener(env, m_jwListener); + } + if (nullptr != m_ownerAccountManager) + { + m_ownerAccountManager->removeOnObserveListener(env, m_jwListener); + } +#endif env->Throw((jthrowable)ex); } else { +#ifndef WITH_CLOUD m_ownerResource->removeOnObserveListener(env, m_jwListener); +#else + if (nullptr != m_ownerResource) + { + m_ownerResource->removeOnObserveListener(env, m_jwListener); + } + if (nullptr != m_ownerAccountManager) + { + m_ownerAccountManager->removeOnObserveListener(env, m_jwListener); + } +#endif } -} \ No newline at end of file +} + +jweak JniOnObserveListener::getJWListener() +{ + return this->m_jwListener; +} diff --git a/android/android_api/base/jni/JniOnObserveListener.h b/android/android_api/base/jni/JniOnObserveListener.h index 38f9aae5b..3fc478d02 100644 --- a/android/android_api/base/jni/JniOnObserveListener.h +++ b/android/android_api/base/jni/JniOnObserveListener.h @@ -27,18 +27,28 @@ using namespace OC; class JniOcResource; +#ifdef WITH_CLOUD +class JniOcAccountManager; +#endif class JniOnObserveListener { public: JniOnObserveListener(JNIEnv *env, jobject jListener, JniOcResource* owner); +#ifdef WITH_CLOUD + JniOnObserveListener(JNIEnv *env, jobject jListener, JniOcAccountManager* owner); +#endif ~JniOnObserveListener(); void onObserveCallback(const HeaderOptions headerOptions, const OCRepresentation& rep, const int& eCode, const int& sequenceNumber); + jweak getJWListener(); private: jweak m_jwListener; JniOcResource* m_ownerResource; +#ifdef WITH_CLOUD + JniOcAccountManager* m_ownerAccountManager; +#endif void checkExAndRemoveListener(JNIEnv *env); }; -#endif \ No newline at end of file +#endif diff --git a/android/android_api/base/jni/JniOnPlatformInfoListener.cpp b/android/android_api/base/jni/JniOnPlatformInfoListener.cpp index 03e2ed8d3..7a220bf80 100644 --- a/android/android_api/base/jni/JniOnPlatformInfoListener.cpp +++ b/android/android_api/base/jni/JniOnPlatformInfoListener.cpp @@ -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) diff --git a/android/android_api/base/jni/JniOnPostListener.cpp b/android/android_api/base/jni/JniOnPostListener.cpp index 575748ef7..62f6e9699 100644 --- a/android/android_api/base/jni/JniOnPostListener.cpp +++ b/android/android_api/base/jni/JniOnPostListener.cpp @@ -23,64 +23,101 @@ #include "JniOcResource.h" #include "JniOcRepresentation.h" #include "JniUtils.h" +#ifdef WITH_CLOUD +#include "JniOcAccountManager.h" +#endif JniOnPostListener::JniOnPostListener(JNIEnv *env, jobject jListener, JniOcResource* owner) : m_ownerResource(owner) { m_jwListener = env->NewWeakGlobalRef(jListener); +#ifdef WITH_CLOUD + m_ownerAccountManager = nullptr; +#endif } +#ifdef WITH_CLOUD +JniOnPostListener::JniOnPostListener(JNIEnv *env, jobject jListener, JniOcAccountManager* owner) + : m_ownerAccountManager(owner) +{ + m_jwListener = env->NewWeakGlobalRef(jListener); + m_ownerResource = nullptr; +} +#endif + 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; } - if (OC_STACK_OK != eCode && OC_STACK_RESOURCE_CREATED != eCode) + if (OC_STACK_OK != eCode && OC_STACK_RESOURCE_CREATED != eCode && + OC_STACK_RESOURCE_CHANGED != eCode) { jobject ex = GetOcException(eCode, "stack error in onPostCallback"); 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 +128,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 +143,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 +155,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 +171,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) @@ -134,11 +183,33 @@ void JniOnPostListener::checkExAndRemoveListener(JNIEnv* env) { jthrowable ex = env->ExceptionOccurred(); env->ExceptionClear(); +#ifndef WITH_CLOUD m_ownerResource->removeOnPostListener(env, m_jwListener); +#else + if (nullptr != m_ownerResource) + { + m_ownerResource->removeOnPostListener(env, m_jwListener); + } + if (nullptr != m_ownerAccountManager) + { + m_ownerAccountManager->removeOnPostListener(env, m_jwListener); + } +#endif env->Throw((jthrowable)ex); } else { +#ifndef WITH_CLOUD m_ownerResource->removeOnPostListener(env, m_jwListener); +#else + if (nullptr != m_ownerResource) + { + m_ownerResource->removeOnPostListener(env, m_jwListener); + } + if (nullptr != m_ownerAccountManager) + { + m_ownerAccountManager->removeOnPostListener(env, m_jwListener); + } +#endif } -} \ No newline at end of file +} diff --git a/android/android_api/base/jni/JniOnPostListener.h b/android/android_api/base/jni/JniOnPostListener.h index 5dfe5258c..bf3387cc3 100644 --- a/android/android_api/base/jni/JniOnPostListener.h +++ b/android/android_api/base/jni/JniOnPostListener.h @@ -27,11 +27,17 @@ using namespace OC; class JniOcResource; +#ifdef WITH_CLOUD +class JniOcAccountManager; +#endif class JniOnPostListener { public: JniOnPostListener(JNIEnv *env, jobject jListener, JniOcResource* owner); +#ifdef WITH_CLOUD + JniOnPostListener(JNIEnv *env, jobject jListener, JniOcAccountManager* owner); +#endif ~JniOnPostListener(); void onPostCallback(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode); @@ -39,7 +45,10 @@ public: private: jweak m_jwListener; JniOcResource* m_ownerResource; +#ifdef WITH_CLOUD + JniOcAccountManager* m_ownerAccountManager; +#endif void checkExAndRemoveListener(JNIEnv *env); }; -#endif \ No newline at end of file +#endif diff --git a/android/android_api/base/jni/JniOnPresenceListener.cpp b/android/android_api/base/jni/JniOnPresenceListener.cpp index 023c61da4..922325095 100644 --- a/android/android_api/base/jni/JniOnPresenceListener.cpp +++ b/android/android_api/base/jni/JniOnPresenceListener.cpp @@ -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 +} diff --git a/android/android_api/base/jni/JniOnPublishResourceListener.cpp b/android/android_api/base/jni/JniOnPublishResourceListener.cpp new file mode 100644 index 000000000..4adc14a9d --- /dev/null +++ b/android/android_api/base/jni/JniOnPublishResourceListener.cpp @@ -0,0 +1,158 @@ +/* **************************************************************** + * + * Copyright 2016 Samsung Electronics All Rights Reserved. + * + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************/ +#include "JniOnPublishResourceListener.h" + +JniOnPublishResourceListener::JniOnPublishResourceListener(JNIEnv *env, jobject jListener, + RemoveListenerCallback removeListenerCallback) +{ + m_jwListener = env->NewWeakGlobalRef(jListener); + m_removeListenerCallback = removeListenerCallback; +} + +JniOnPublishResourceListener::~JniOnPublishResourceListener() +{ + LOGI("~JniOnPublishResourceListener()"); + if (m_jwListener) + { + jint ret = JNI_ERR; + JNIEnv *env = GetJNIEnv(ret); + if (nullptr == env) + { + return; + } + env->DeleteWeakGlobalRef(m_jwListener); + m_jwListener = nullptr; + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } + } +} + +void JniOnPublishResourceListener::onPublishResourceCallback( + const OCRepresentation& ocRepresentation, + const int eCode) +{ + jint envRet = JNI_ERR; + JNIEnv *env = GetJNIEnv(envRet); + if (nullptr == env) + { + return; + } + + if (nullptr == m_jwListener) + { + LOGE("listener is not available"); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } + return; + } + + jobject jListener = env->NewLocalRef(m_jwListener); + if (!jListener) + { + checkExAndRemoveListener(env); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } + return; + } + jclass clsL = env->GetObjectClass(jListener); + + if (!clsL) + { + checkExAndRemoveListener(env); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } + return; + } + + if (OC_STACK_OK != eCode && OC_STACK_RESOURCE_CREATED != eCode + && OC_STACK_RESOURCE_DELETED != eCode && OC_STACK_CONTINUE != eCode + && OC_STACK_RESOURCE_CHANGED != eCode) + { + jobject ex = GetOcException(eCode, "stack error in onPublishResourceCallback"); + if (!ex) + { + goto CLEANUP; + } + jmethodID midL = env->GetMethodID(clsL, "onPublishResourceFailed", + "(Ljava/lang/Throwable;)V"); + if (!midL) + { + goto CLEANUP; + } + env->CallVoidMethod(jListener, midL, ex); + } + else + { + OCRepresentation* rep = new OCRepresentation(ocRepresentation); + jlong handle = reinterpret_cast(rep); + jobject jRepresentation = env->NewObject(g_cls_OcRepresentation, + g_mid_OcRepresentation_N_ctor_bool, + handle, true); + if (!jRepresentation) + { + delete rep; + goto CLEANUP; + } + + jmethodID midL = env->GetMethodID(clsL, "onPublishResourceCompleted", + "(Lorg/iotivity/base/OcRepresentation;)V"); + if (!midL) + { + delete rep; + goto CLEANUP; + } + env->CallVoidMethod(jListener, midL, jRepresentation); + if (env->ExceptionCheck()) + { + LOGE("Java exception is thrown"); + delete rep; + } + } + +CLEANUP: + checkExAndRemoveListener(env); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } +} + +void JniOnPublishResourceListener::checkExAndRemoveListener(JNIEnv* env) +{ + if (env->ExceptionCheck()) + { + jthrowable ex = env->ExceptionOccurred(); + env->ExceptionClear(); + m_removeListenerCallback(env, m_jwListener); + env->Throw((jthrowable)ex); + } + else + { + m_removeListenerCallback(env, m_jwListener); + } +} diff --git a/android/android_api/base/jni/JniOnPublishResourceListener.h b/android/android_api/base/jni/JniOnPublishResourceListener.h new file mode 100644 index 000000000..a147ba289 --- /dev/null +++ b/android/android_api/base/jni/JniOnPublishResourceListener.h @@ -0,0 +1,40 @@ +/* **************************************************************** + * + * Copyright 2016 Samsung Electronics All Rights Reserved. + * + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************/ +#include "JniOcStack.h" + +#ifndef _Included_org_iotivity_base_OcPlatform_OnPublishResourceListener +#define _Included_org_iotivity_base_OcPlatform_OnPublishResourceListener + +using namespace OC; + +class JniOnPublishResourceListener +{ +public: + JniOnPublishResourceListener(JNIEnv *env, jobject listener, + RemoveListenerCallback removeListenerCallback); + ~JniOnPublishResourceListener(); + void onPublishResourceCallback(const OCRepresentation& rep, const int eCode); +private: + RemoveListenerCallback m_removeListenerCallback; + jweak m_jwListener; + void checkExAndRemoveListener(JNIEnv* env); +}; + +#endif diff --git a/android/android_api/base/jni/JniOnPutListener.cpp b/android/android_api/base/jni/JniOnPutListener.cpp index 7f375b93e..5e2dd4a95 100644 --- a/android/android_api/base/jni/JniOnPutListener.cpp +++ b/android/android_api/base/jni/JniOnPutListener.cpp @@ -34,53 +34,74 @@ 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; } - if (OC_STACK_OK != eCode) + if (OC_STACK_OK != eCode && OC_STACK_RESOURCE_CHANGED != eCode) { jobject ex = GetOcException(eCode, "stack error in onPutCallback"); 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 +} diff --git a/android/android_api/base/jni/JniOnResourceFoundListener.cpp b/android/android_api/base/jni/JniOnResourceFoundListener.cpp index cdc68d316..cbbbbb0ec 100644 --- a/android/android_api/base/jni/JniOnResourceFoundListener.cpp +++ b/android/android_api/base/jni/JniOnResourceFoundListener.cpp @@ -34,34 +34,50 @@ 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 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(); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } return; } jobject jResource = env->NewObject(g_cls_OcResource, g_mid_OcResource_ctor); if (!jResource) { + env->DeleteLocalRef(jListener); checkExAndRemoveListener(env); - if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } return; } @@ -70,24 +86,40 @@ void JniOnResourceFoundListener::foundResourceCallback(std::shared_ptrExceptionCheck()) { delete jniOcResource; + env->DeleteLocalRef(jResource); + env->DeleteLocalRef(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) { delete jniOcResource; + env->DeleteLocalRef(jResource); + env->DeleteLocalRef(jListener); checkExAndRemoveListener(env); - if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } return; } jmethodID midL = env->GetMethodID(clsL, "onResourceFound", "(Lorg/iotivity/base/OcResource;)V"); if (!midL) { delete jniOcResource; + env->DeleteLocalRef(clsL); + env->DeleteLocalRef(jResource); + env->DeleteLocalRef(jListener); checkExAndRemoveListener(env); - if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } return; } env->CallVoidMethod(jListener, midL, jResource); @@ -95,12 +127,87 @@ void JniOnResourceFoundListener::foundResourceCallback(std::shared_ptrDeleteLocalRef(clsL); + env->DeleteLocalRef(jResource); + env->DeleteLocalRef(jListener); + checkExAndRemoveListener(env); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } + return; + } + + env->DeleteLocalRef(clsL); + env->DeleteLocalRef(jResource); + env->DeleteLocalRef(jListener); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } +} + +void JniOnResourceFoundListener::findResourceErrorCallback(const std::string& uri, const int eCode) +{ + LOGI("findResource error callback value : %d", eCode); + jint ret = JNI_ERR; + JNIEnv *env = GetJNIEnv(ret); + if (nullptr == env) + { + return; + } + + jobject jListener = env->NewLocalRef(m_jwListener); + if (!jListener) + { + checkExAndRemoveListener(env); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } + return; + } + + jclass clsL = env->GetObjectClass(jListener); + if (!clsL) + { + checkExAndRemoveListener(env); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } + return; + } + + jobject ex = GetOcException(eCode, "stack error in onFindResourceErrorCallback"); + if (!ex) + { checkExAndRemoveListener(env); - if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } return; } - if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + + jmethodID midL = env->GetMethodID(clsL, "onFindResourceFailed", + "(Ljava/lang/Throwable;Ljava/lang/String;)V"); + if (!midL) + { + checkExAndRemoveListener(env); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } + return; + } + env->CallVoidMethod(jListener, midL, ex, env->NewStringUTF(uri.c_str())); + + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } } void JniOnResourceFoundListener::checkExAndRemoveListener(JNIEnv* env) @@ -116,4 +223,4 @@ void JniOnResourceFoundListener::checkExAndRemoveListener(JNIEnv* env) { m_removeListenerCallback(env, m_jwListener); } -} \ No newline at end of file +} diff --git a/android/android_api/base/jni/JniOnResourceFoundListener.h b/android/android_api/base/jni/JniOnResourceFoundListener.h index 909cc4e96..bac7d45cc 100644 --- a/android/android_api/base/jni/JniOnResourceFoundListener.h +++ b/android/android_api/base/jni/JniOnResourceFoundListener.h @@ -33,6 +33,7 @@ public: ~JniOnResourceFoundListener(); void foundResourceCallback(std::shared_ptr resource); + void findResourceErrorCallback(const std::string& uri, const int eCode); private: RemoveListenerCallback m_removeListenerCallback; diff --git a/android/android_api/base/jni/JniPinCheckListener.cpp b/android/android_api/base/jni/JniPinCheckListener.cpp index 55cdfba25..12377d18f 100644 --- a/android/android_api/base/jni/JniPinCheckListener.cpp +++ b/android/android_api/base/jni/JniPinCheckListener.cpp @@ -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(); + } } diff --git a/android/android_api/base/jni/JniProvisionResultListner.cpp b/android/android_api/base/jni/JniProvisionResultListner.cpp index a600e6456..a25f01582 100644 --- a/android/android_api/base/jni/JniProvisionResultListner.cpp +++ b/android/android_api/base/jni/JniProvisionResultListner.cpp @@ -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; } @@ -94,6 +112,11 @@ void JniProvisionResultListner::ProvisionResultCallback(PMResultList_t *result, calledFunc = "provisionCredentialsListener"; } break; + case ListenerFunc::PROVISIONTRUSTCERTCHAIN: + { + calledFunc = "provisionTrustCertChainListener"; + } + break; case ListenerFunc::UNLINKDEVICES: { calledFunc = "unlinkDevicesListener"; @@ -117,7 +140,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 +153,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 +166,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) diff --git a/android/android_api/base/jni/JniProvisionResultListner.h b/android/android_api/base/jni/JniProvisionResultListner.h index 8bf52421e..59a0945e2 100644 --- a/android/android_api/base/jni/JniProvisionResultListner.h +++ b/android/android_api/base/jni/JniProvisionResultListner.h @@ -33,6 +33,7 @@ enum class ListenerFunc OWNERSHIPTRANSFER = 1, PROVISIONACL, PROVISIONCREDENTIALS, + PROVISIONTRUSTCERTCHAIN, UNLINKDEVICES, REMOVEDEVICE, PROVISIONPAIRWISEDEVICES, diff --git a/android/android_api/base/jni/JniSecureUtils.cpp b/android/android_api/base/jni/JniSecureUtils.cpp index 718bb4aed..e18de5beb 100644 --- a/android/android_api/base/jni/JniSecureUtils.cpp +++ b/android/android_api/base/jni/JniSecureUtils.cpp @@ -150,45 +150,6 @@ jobject JniSecureUtils::convertUUIDVectorToJavaStrList(JNIEnv *env, UuidList_t & return jList; } -static void freeValidities(OicSecValidity_t *head) -{ - OicSecValidity_t *tmp = head; - while(tmp != NULL) - { - head = head->next; - free(tmp->recurrences); - free(tmp); - tmp = head; - } -} - -static void freeResources(OicSecRsrc_t *head) -{ - OicSecRsrc_t *tmp = head; - while(tmp != NULL) - { - head = head->next; - free(tmp->types); - free(tmp->interfaces); - free(tmp); - tmp = head; - } -} - -void JniSecureUtils::FreeACLList(OicSecAcl_t *acl) -{ - if (acl) - { - if (acl->aces) - { - freeResources(acl->aces->resources); - freeValidities(acl->aces->validities); - OICFree(acl->aces); - } - OICFree(acl); - } -} - static OicSecValidity_t* getValiditiesList(JNIEnv *env, jobject validityObject) { jstring jData; @@ -204,38 +165,21 @@ static OicSecValidity_t* getValiditiesList(JNIEnv *env, jobject validityObject) for (int i = 0 ; i < nr_validities; i++) { OicSecValidity_t *tmp = (OicSecValidity_t*)OICCalloc(1, sizeof(OicSecValidity_t)); - if (NULL == tmp) - { - LOGE("Failed to allocate memory"); - freeValidities(valHead); - return nullptr; - } - jobject element = env->GetObjectArrayElement(valList, i); if (!element || env->ExceptionCheck()) { - OICFree(tmp); - freeValidities(valHead); return nullptr; } jData = (jstring)env->CallObjectMethod(element, g_mid_OcOicSecAcl_validity_get_getPeriod); if (!jData || env->ExceptionCheck()) { - OICFree(tmp); - freeValidities(valHead); return nullptr; } tmp->period = (char*)env->GetStringUTFChars(jData, 0); jint jrecurrenceLen = (jint) env->CallIntMethod(element, g_mid_OcOicSecAcl_validity_get_recurrenceLen); - if (env->ExceptionCheck()) - { - OICFree(tmp); - freeValidities(valHead); - return nullptr; - } tmp->recurrenceLen = (int)jrecurrenceLen; if (jrecurrenceLen > 0) @@ -249,9 +193,6 @@ static OicSecValidity_t* getValiditiesList(JNIEnv *env, jobject validityObject) jData = (jstring)env->CallObjectMethodA(element, g_mid_OcOicSecAcl_validity_get_recurrences, argv); if (!jData || env->ExceptionCheck()) { - OICFree(tmp->recurrences); - OICFree(tmp); - freeValidities(valHead); return nullptr; } tmp->recurrences[i] = (char*)env->GetStringUTFChars(jData, 0); @@ -289,24 +230,14 @@ static OicSecRsrc_t * getResourcesList(JNIEnv *env, jobject resourceObject) for (int i = 0 ; i < nr_resc; i++) { OicSecRsrc_t *tmp = (OicSecRsrc_t*)OICCalloc(1, sizeof(OicSecRsrc_t)); - if (NULL == tmp) - { - LOGE("Failed to allocate memory"); - freeResources(rescHead); - return nullptr; - } jobject element = env->GetObjectArrayElement(rescList, i); if (!element || env->ExceptionCheck()) { - OICFree(tmp); - freeResources(rescHead); return nullptr; } jData = (jstring)env->CallObjectMethod(element, g_mid_OcOicSecAcl_resr_get_href); if (!jData || env->ExceptionCheck()) { - OICFree(tmp); - freeResources(rescHead); return nullptr; } tmp->href = (char*)env->GetStringUTFChars(jData, 0); @@ -314,29 +245,16 @@ static OicSecRsrc_t * getResourcesList(JNIEnv *env, jobject resourceObject) jData = (jstring)env->CallObjectMethod(element, g_mid_OcOicSecAcl_resr_get_rel); if (!jData || env->ExceptionCheck()) { - OICFree(tmp); - freeResources(rescHead); return nullptr; } tmp->rel = (char*)env->GetStringUTFChars(jData, 0); jint len = (jint) env->CallIntMethod(element, g_mid_OcOicSecAcl_resr_get_typeLen); - if (env->ExceptionCheck()) - { - OICFree(tmp); - freeResources(rescHead); - return nullptr; - } tmp->typeLen = (int)len; if (len > 0) { jvalue argv[1]; tmp->types = (char**)OICCalloc(len, sizeof(char*)); - if (NULL == tmp->types) - { - LOGE("Failed to allocate memory"); - return nullptr; - } for (int i = 0 ; i < len; i++) { @@ -344,9 +262,6 @@ static OicSecRsrc_t * getResourcesList(JNIEnv *env, jobject resourceObject) jData = (jstring)env->CallObjectMethodA(element, g_mid_OcOicSecAcl_resr_get_types, argv); if (!jData || env->ExceptionCheck()) { - OICFree(tmp->types); - OICFree(tmp); - freeResources(rescHead); return nullptr; } tmp->types[i] = (char*)env->GetStringUTFChars(jData, 0); @@ -354,13 +269,6 @@ static OicSecRsrc_t * getResourcesList(JNIEnv *env, jobject resourceObject) } len = (jint) env->CallIntMethod(element, g_mid_OcOicSecAcl_resr_get_interfaceLen); - if (env->ExceptionCheck()) - { - OICFree(tmp->types); - OICFree(tmp); - freeResources(rescHead); - return nullptr; - } tmp->interfaceLen = len; if (len > 0) { @@ -373,9 +281,6 @@ static OicSecRsrc_t * getResourcesList(JNIEnv *env, jobject resourceObject) jData = (jstring)env->CallObjectMethodA(element, g_mid_OcOicSecAcl_resr_get_interfaces, argv); if (!jData || env->ExceptionCheck()) { - OICFree(tmp->types); - OICFree(tmp); - freeResources(rescHead); return nullptr; } tmp->interfaces[i] = (char*)env->GetStringUTFChars(jData, 0); @@ -409,10 +314,6 @@ OCStackResult JniSecureUtils::convertJavaACLToOCAcl(JNIEnv *env, jobject in, Oic } char *str = (char*) env->GetStringUTFChars(jData, 0); - if (!str) - { - return OC_STACK_ERROR; - } if (OC_STACK_OK == ConvertStrToUuid(str, &acl->rownerID)) { env->ReleaseStringUTFChars(jData, str); @@ -450,11 +351,6 @@ OCStackResult JniSecureUtils::convertJavaACLToOCAcl(JNIEnv *env, jobject in, Oic } str = (char*) env->GetStringUTFChars(jData, 0); - - if (!str) - { - return OC_STACK_ERROR; - } if (OC_STACK_OK == ConvertStrToUuid(str, &tmp->subjectuuid)) { env->ReleaseStringUTFChars(jData, str); diff --git a/android/android_api/base/jni/JniSecureUtils.h b/android/android_api/base/jni/JniSecureUtils.h index c16457de2..c7226a544 100644 --- a/android/android_api/base/jni/JniSecureUtils.h +++ b/android/android_api/base/jni/JniSecureUtils.h @@ -29,7 +29,6 @@ class JniSecureUtils static std::string convertUUIDtoStr(OicUuid_t uuid); static void convertStrToUUID(char *str, OicUuid_t &uuid); public: - static void FreeACLList(OicSecAcl_t *acl); static jobject convertProvisionresultVectorToJavaList(JNIEnv *, const OC::PMResultList_t *); static jobjectArray convertDeviceVectorToJavaArray(JNIEnv *env, diff --git a/android/android_api/base/jni/JniUtils.cpp b/android/android_api/base/jni/JniUtils.cpp index 4e3f2762a..3ee3ada28 100644 --- a/android/android_api/base/jni/JniUtils.cpp +++ b/android/android_api/base/jni/JniUtils.cpp @@ -26,13 +26,22 @@ jobject JniUtils::convertStrVectorToJavaStrList(JNIEnv *env, std::vector &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 &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(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& 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(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 +} diff --git a/android/android_api/base/jni/JniUtils.h b/android/android_api/base/jni/JniUtils.h index fcfa2a130..529729347 100644 --- a/android/android_api/base/jni/JniUtils.h +++ b/android/android_api/base/jni/JniUtils.h @@ -47,84 +47,103 @@ 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; }; } - +#ifdef WITH_CLOUD + static OC::AclGroupType getAclGroupType(JNIEnv *env, int type) + { + switch (type) + { + case 0: + return OC::AclGroupType::PUBLIC; + case 1: + return OC::AclGroupType::PRIVATE; + default: + ThrowOcException(OC_STACK_INVALID_PARAM, "Unexpected acl group type"); + return OC::AclGroupType::PUBLIC; + }; + } +#endif 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 +151,108 @@ 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_RESOURCE_CHANGED: + return "RESOURCE_CHANGED"; + 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 ""; } } }; diff --git a/android/android_api/base/src/androidTest/java/org/iotivity/base/OcRepresentationTest.java b/android/android_api/base/src/androidTest/java/org/iotivity/base/OcRepresentationTest.java index c7b5f30ff..043eda051 100644 --- a/android/android_api/base/src/androidTest/java/org/iotivity/base/OcRepresentationTest.java +++ b/android/android_api/base/src/androidTest/java/org/iotivity/base/OcRepresentationTest.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Intel Corporation. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; @@ -309,6 +309,18 @@ public class OcRepresentationTest extends InstrumentationTestCase { rep.setValue(representationK, representationArrVEmpty); OcRepresentation[] representationArrVEmptyA = rep.getValue(representationK); assertEquals(representationArrVEmpty.length, representationArrVEmptyA.length); + + //byte + String byteK = "byteK"; + byte[] byteArrV = {1, 2, 3, 4, 0, 5, 6, 7}; + rep.setValue(byteK, byteArrV); + byte[] byteArrVa = rep.getValue(byteK); + assertTrue(Arrays.equals(byteArrV, byteArrVa)); + + byte[] byteArrVEmpty = {}; + rep.setValue(byteK, byteArrVEmpty); + byte[] byteArrVEmptyA = rep.getValue(byteK); + assertTrue(Arrays.equals(byteArrVEmpty, byteArrVEmptyA)); } public void testAttributeAccessBy2DType() throws OcException { @@ -580,4 +592,4 @@ public class OcRepresentationTest extends InstrumentationTestCase { } } } -} \ No newline at end of file +} diff --git a/android/android_api/base/src/androidTest/java/org/iotivity/base/SmokeTest.java b/android/android_api/base/src/androidTest/java/org/iotivity/base/SmokeTest.java index 4842ecae8..a3a2ba73b 100644 --- a/android/android_api/base/src/androidTest/java/org/iotivity/base/SmokeTest.java +++ b/android/android_api/base/src/androidTest/java/org/iotivity/base/SmokeTest.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Intel Corporation. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; @@ -85,6 +85,11 @@ public class SmokeTest extends InstrumentationTestCase { } signal.countDown(); } + + @Override + public void onFindResourceFailed(Throwable ex, String uri) { + Log.i(TAG, "Find Resource Failed for Uri: " + uri + " Error: " + ex.getMessage()); + } }; try { @@ -157,6 +162,11 @@ public class SmokeTest extends InstrumentationTestCase { assertTrue(false); } } + + @Override + public void onFindResourceFailed(Throwable ex, String uri) { + Log.i(TAG, "Find Resource Failed for Uri: " + uri + " Error: " + ex.getMessage()); + } }; try { @@ -263,6 +273,11 @@ public class SmokeTest extends InstrumentationTestCase { } signal1.countDown(); } + + @Override + public void onFindResourceFailed(Throwable ex, String uri) { + Log.i(TAG, "Find Resource Failed for Uri: " + uri + " Error: " + ex.getMessage()); + } }; try { @@ -430,6 +445,11 @@ public class SmokeTest extends InstrumentationTestCase { } signal1.countDown(); } + + @Override + public void onFindResourceFailed(Throwable ex, String uri) { + Log.i(TAG, "Find Resource Failed for Uri: " + uri + " Error: " + ex.getMessage()); + } }; try { @@ -603,6 +623,11 @@ public class SmokeTest extends InstrumentationTestCase { } signal1.countDown(); } + + @Override + public void onFindResourceFailed(Throwable ex, String uri) { + Log.i(TAG, "Find Resource Failed for Uri: " + uri + " Error: " + ex.getMessage()); + } }; try { @@ -731,6 +756,11 @@ public class SmokeTest extends InstrumentationTestCase { } signal1.countDown(); } + + @Override + public void onFindResourceFailed(Throwable ex, String uri) { + Log.i(TAG, "Find Resource Failed for Uri: " + uri + " Error: " + ex.getMessage()); + } }; try { @@ -895,6 +925,11 @@ public class SmokeTest extends InstrumentationTestCase { } signal1.countDown(); } + + @Override + public void onFindResourceFailed(Throwable ex, String uri) { + Log.i(TAG, "Find Resource Failed for Uri: " + uri + " Error: " + ex.getMessage()); + } }; try { @@ -1094,6 +1129,11 @@ public class SmokeTest extends InstrumentationTestCase { public void onResourceFound(OcResource resource) { signal1.countDown(); } + + @Override + public void onFindResourceFailed(Throwable ex, String uri) { + Log.i(TAG, "Find Resource Failed for Uri: " + uri + " Error: " + ex.getMessage()); + } }; OcPlatform.OnResourceFoundListener resourceFoundListener2 = new OcPlatform.OnResourceFoundListener() { @@ -1101,6 +1141,11 @@ public class SmokeTest extends InstrumentationTestCase { public void onResourceFound(OcResource resource) { signal2.countDown(); } + + @Override + public void onFindResourceFailed(Throwable ex, String uri) { + Log.i(TAG, "Find Resource Failed for Uri: " + uri + " Error: " + ex.getMessage()); + } }; OcPlatform.OnResourceFoundListener resourceFoundListener3 = new OcPlatform.OnResourceFoundListener() { @@ -1108,6 +1153,11 @@ public class SmokeTest extends InstrumentationTestCase { public void onResourceFound(OcResource resource) { signal3.countDown(); } + + @Override + public void onFindResourceFailed(Throwable ex, String uri) { + Log.i(TAG, "Find Resource Failed for Uri: " + uri + " Error: " + ex.getMessage()); + } }; OcPlatform.OnResourceFoundListener resourceFoundListener4 = new OcPlatform.OnResourceFoundListener() { @@ -1115,6 +1165,11 @@ public class SmokeTest extends InstrumentationTestCase { public void onResourceFound(OcResource resource) { signal4.countDown(); } + + @Override + public void onFindResourceFailed(Throwable ex, String uri) { + Log.i(TAG, "Find Resource Failed for Uri: " + uri + " Error: " + ex.getMessage()); + } }; OcPlatform.OnResourceFoundListener resourceFoundListener5 = new OcPlatform.OnResourceFoundListener() { @@ -1122,6 +1177,11 @@ public class SmokeTest extends InstrumentationTestCase { public void onResourceFound(OcResource resource) { signal5.countDown(); } + + @Override + public void onFindResourceFailed(Throwable ex, String uri) { + Log.i(TAG, "Find Resource Failed for Uri: " + uri + " Error: " + ex.getMessage()); + } }; OcPlatform.OnResourceFoundListener resourceFoundListener6 = new OcPlatform.OnResourceFoundListener() { @@ -1129,6 +1189,11 @@ public class SmokeTest extends InstrumentationTestCase { public void onResourceFound(OcResource resource) { signal6.countDown(); } + + @Override + public void onFindResourceFailed(Throwable ex, String uri) { + Log.i(TAG, "Find Resource Failed for Uri: " + uri + " Error: " + ex.getMessage()); + } }; try { @@ -1270,7 +1335,12 @@ public class SmokeTest extends InstrumentationTestCase { headerOptionList.add(new OcHeaderOption(2885, "OptionData1")); headerOptionList.add(new OcHeaderOption(2886, "OptionData2")); - resource.setHeaderOptions(headerOptionList); + try { + resource.setHeaderOptions(headerOptionList); + } catch (OcException e) { + Log.e(TAG, "onResourceFound, error in setHeaderOptions -- " + e.getMessage()); + } + resource.unsetHeaderOptions(); OcResourceIdentifier resourceIdentifier = resource.getUniqueIdentifier(); @@ -1279,6 +1349,11 @@ public class SmokeTest extends InstrumentationTestCase { signal.countDown(); } + + @Override + public void onFindResourceFailed(Throwable ex, String uri) { + Log.i(TAG, "Find Resource Failed for Uri: " + uri + " Error: " + ex.getMessage()); + } }; try { @@ -1359,6 +1434,11 @@ public class SmokeTest extends InstrumentationTestCase { } signal.countDown(); } + + @Override + public void onFindResourceFailed(Throwable ex, String uri) { + Log.i(TAG, "Find Resource Failed for Uri: " + uri + " Error: " + ex.getMessage()); + } }; try { @@ -1557,6 +1637,11 @@ public class SmokeTest extends InstrumentationTestCase { } } } + + @Override + public void onFindResourceFailed(Throwable ex, String uri) { + Log.i(TAG, "Find Resource Failed for Uri: " + uri + " Error: " + ex.getMessage()); + } }; try { //server diff --git a/android/android_api/base/src/main/java/org/iotivity/base/AclGroupType.java b/android/android_api/base/src/main/java/org/iotivity/base/AclGroupType.java new file mode 100644 index 000000000..abacec919 --- /dev/null +++ b/android/android_api/base/src/main/java/org/iotivity/base/AclGroupType.java @@ -0,0 +1,38 @@ +/* + ******************************************************************* + * + * Copyright 2016 Samsung Electronics All Rights Reserved. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + */ + +package org.iotivity.base; + +public enum AclGroupType { + PUBLIC(0), + PRIVATE(1),; + + private int value; + + private AclGroupType(int value) { + this.value = value; + } + + public int getValue() { + return this.value; + } +} diff --git a/android/android_api/base/src/main/java/org/iotivity/base/CredType.java b/android/android_api/base/src/main/java/org/iotivity/base/CredType.java index bbaeda74b..87a33eb24 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/CredType.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/CredType.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Samsung Electronics All Rights Reserved. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Samsung Electronics All Rights Reserved. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; diff --git a/android/android_api/base/src/main/java/org/iotivity/base/DeviceStatus.java b/android/android_api/base/src/main/java/org/iotivity/base/DeviceStatus.java index b569da819..0eefcaf3f 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/DeviceStatus.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/DeviceStatus.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Samsung Electronics All Rights Reserved. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Samsung Electronics All Rights Reserved. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; diff --git a/android/android_api/base/src/main/java/org/iotivity/base/EncodingType.java b/android/android_api/base/src/main/java/org/iotivity/base/EncodingType.java new file mode 100644 index 000000000..944eadb2d --- /dev/null +++ b/android/android_api/base/src/main/java/org/iotivity/base/EncodingType.java @@ -0,0 +1,42 @@ +/* + ******************************************************************* + * + * Copyright 2016 Samsung Electronics All Rights Reserved. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + */ + +package org.iotivity.base; + +public enum EncodingType { + + OIC_ENCODING_UNKNOW (0), + OIC_ENCODING_RAW (1), + OIC_ENCODING_BASE64 (2), + OIC_ENCODING_PEM (3), + OIC_ENCODING_DER (4); + + private int value; + + private EncodingType(int value) { + this.value = value; + } + + public int getValue() { + return this.value; + } +} diff --git a/android/android_api/base/src/main/java/org/iotivity/base/EntityHandlerResult.java b/android/android_api/base/src/main/java/org/iotivity/base/EntityHandlerResult.java index 17fe3f48a..3306230c2 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/EntityHandlerResult.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/EntityHandlerResult.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Intel Corporation. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; diff --git a/android/android_api/base/src/main/java/org/iotivity/base/ErrorCode.java b/android/android_api/base/src/main/java/org/iotivity/base/ErrorCode.java index bba664ecc..7318a0ced 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/ErrorCode.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/ErrorCode.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Intel Corporation. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; @@ -28,6 +28,7 @@ public enum ErrorCode { RESOURCE_CREATED("RESOURCE_CREATED", ""), RESOURCE_DELETED("RESOURCE_DELETED", ""), CONTINUE("CONTINUE", ""), + RESOURCE_CHANGED("RESOURCE_CHANGED", ""), /** Success status code - END HERE.*/ /* Error status code - START HERE */ INVALID_URI("INVALID_URI", ""), diff --git a/android/android_api/base/src/main/java/org/iotivity/base/KeySize.java b/android/android_api/base/src/main/java/org/iotivity/base/KeySize.java index 6243db607..83c5799cf 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/KeySize.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/KeySize.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Samsung Electronics All Rights Reserved. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Samsung Electronics All Rights Reserved. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; diff --git a/android/android_api/base/src/main/java/org/iotivity/base/ModeType.java b/android/android_api/base/src/main/java/org/iotivity/base/ModeType.java index 52dfb66e0..d12cab751 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/ModeType.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/ModeType.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Intel Corporation. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; diff --git a/android/android_api/base/src/main/java/org/iotivity/base/ObservationInfo.java b/android/android_api/base/src/main/java/org/iotivity/base/ObservationInfo.java index 89876e1cc..064eeaf14 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/ObservationInfo.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/ObservationInfo.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Intel Corporation. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; diff --git a/android/android_api/base/src/main/java/org/iotivity/base/ObserveAction.java b/android/android_api/base/src/main/java/org/iotivity/base/ObserveAction.java index 085ddf33d..5506749e0 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/ObserveAction.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/ObserveAction.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Intel Corporation. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; diff --git a/android/android_api/base/src/main/java/org/iotivity/base/ObserveType.java b/android/android_api/base/src/main/java/org/iotivity/base/ObserveType.java index 13b5b18d2..ca990a9d9 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/ObserveType.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/ObserveType.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Intel Corporation. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; diff --git a/android/android_api/base/src/main/java/org/iotivity/base/OcAccountManager.java b/android/android_api/base/src/main/java/org/iotivity/base/OcAccountManager.java new file mode 100644 index 000000000..e9bb9e8c9 --- /dev/null +++ b/android/android_api/base/src/main/java/org/iotivity/base/OcAccountManager.java @@ -0,0 +1,509 @@ +/* + ******************************************************************* + * + * Copyright 2016 Samsung Electronics All Rights Reserved. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + */ + +package org.iotivity.base; + +import java.util.EnumSet; +import java.util.List; +import java.util.Map; + +public final class OcAccountManager { + + private OcAccountManager(long nativeHandle) { + this.mNativeHandle = nativeHandle; + } + + /** + * Method to get the host address of account server + * + * @return String host address + */ + public native String getHost(); + + /** + * Method to get the connectivity type for account server + * + * @return EnumSet connectivity type set + */ + public EnumSet getConnectivityTypeSet() { + return OcConnectivityType.convertToEnumSet( + this.getConnectivityTypeN() + ); + } + + private native int getConnectivityTypeN(); + + /** + * Method for account registration to account server + * + * @param authProvider Provider name used for authentication. + * @param authCode The authorization code obtained by using an authorization server + * as an intermediary between the client and resource owner. + * @param onPostListener event handler The event handler will be invoked with a map of + * attribute name and values. + * @throws OcException if failure + */ + public void signUp(String authProvider, + String authCode, + OnPostListener onPostListener) throws OcException { + this.signUp0(authProvider, authCode, onPostListener); + } + + private native void signUp0(String authProvider, + String authCode, + OnPostListener onPostListener) throws OcException; + + /** + * overload + * + * @param authProvider Provider name used for authentication. + * @param authCode The authorization code obtained by using an authorization server + * as an intermediary between the client and resource owner. + * @param options The option values depends on auth provider. + * @param onPostListener event handler The event handler will be invoked with a map of + * attribute name and values. + * @throws OcException if failure + */ + public void signUp(String authProvider, + String authCode, + Map options, + OnPostListener onPostListener) throws OcException { + this.signUp1(authProvider, authCode, options, onPostListener); + } + + private native void signUp1(String authProvider, + String authCode, + Map options, + OnPostListener onPostListener) throws OcException; + + /** + * Method for sign-in to account server + * + * @param userUuid Identifier of the user obtained by account registration. + * @param accessToken Identifier of the resource obtained by account registration. + * @param onPostListener event handler The event handler will be invoked with a map of + * attribute name and values. + * @throws OcException if failure + */ + public void signIn(String userUuid, + String accessToken, + OnPostListener onPostListener) throws OcException { + this.signIn0(userUuid, accessToken, onPostListener); + } + + private native void signIn0(String userUuid, + String accessToken, + OnPostListener onPostListener) throws OcException; + + /** + * Method for sign-out to account server + * + * @param onPostListener event handler The event handler will be invoked with a map of + * attribute name and values. + * @throws OcException if failure + */ + public void signOut(OnPostListener onPostListener) throws OcException { + this.signOut0(onPostListener); + } + + private native void signOut0(OnPostListener onPostListener) throws OcException; + + /** + * Method to refresh access token to account server + * + * @param userUuid Identifier of the user obtained by account registration. + * @param refreshToken Refresh token used for access token refresh. + * @param onPostListener event handler The event handler will be invoked with a map of + * attribute name and values. + * @throws OcException if failure + */ + public void refreshAccessToken(String userUuid, + String refreshToken, + OnPostListener onPostListener) throws OcException { + this.refreshAccessToken0(userUuid, refreshToken, onPostListener); + } + + private native void refreshAccessToken0(String userUuid, + String refreshToken, + OnPostListener onPostListener) throws OcException; + + /** + * Method to get information of the user to account server + * + * @param userUuid Identifier of the user to get information. + * @param onGetListener The event handler will be invoked with a map of attribute name and + * values. The event handler will also have the result from this Get + * operation This will have error codes + * @throws OcException if failure + */ + public void searchUser(String userUuid, + OnGetListener onGetListener) throws OcException { + this.searchUser0(userUuid, onGetListener); + } + + private native void searchUser0(String userUuid, + OnGetListener onGetListener) throws OcException; + + /** + * Overload + * + * @param queryMap Map which can have the query key and value for specific users. + * account server can response information of more than one user. + * @param onGetListener The event handler will be invoked with a map of attribute name and + * values. The event handler will also have the result from this Get + * operation This will have error codes + * @throws OcException if failure + */ + public void searchUser(Map queryMap, + OnGetListener onGetListener) throws OcException { + this.searchUser1(queryMap, onGetListener); + } + + private native void searchUser1(Map queryMap, + OnGetListener onGetListener) throws OcException; + + /** + * Method to delete the device registered on the account signed-in + * + * @param deviceId Device ID to delete. + * @param onDeleteListener event handler The event handler will have headerOptionList + * @throws OcException if failure + */ + public void deleteDevice(String deviceId, + OnDeleteListener onDeleteListener) throws OcException { + this.deleteDevice0(deviceId, onDeleteListener); + } + + private native void deleteDevice0(String deviceId, + OnDeleteListener onDeleteListener) throws OcException; + + /** + * Method to delete the device registered on the account signed-in + * + * @param groupType Group type that can be used for referencing default group ACL creation. + * @param onPostListener event handler The event handler will be invoked with a map of + * attribute name and values. + * @throws OcException if failure + */ + public void createGroup(AclGroupType groupType, + OnPostListener onPostListener) throws OcException { + this.createGroup0(groupType.getValue(), onPostListener); + } + + private native void createGroup0(int groupType, + OnPostListener onPostListener) throws OcException; + + /** + * Method to get a list of groups joined from account server + * + * @param onGetListener The event handler will be invoked with a map of attribute name and + * values. The event handler will also have the result from this Get + * operation This will have error codes + * + * @return Returns ::OC_STACK_OK if success + */ + public void getGroupList(OnGetListener onGetListener) throws OcException { + this.getGroupList0(onGetListener); + } + + private native void getGroupList0(OnGetListener onGetListener) throws OcException; + + /** + * Method to delete the group from account server + * + * @param groupId Group ID to delete. + * @param onDeleteListener event handler The event handler will have headerOptionList. + * + * @return Returns ::OC_STACK_OK if success + */ + public void deleteGroup(String groupId, + OnDeleteListener onDeleteListener) throws OcException { + this.deleteGroup0(groupId, onDeleteListener); + } + + private native void deleteGroup0(String groupId, + OnDeleteListener onDeleteListener) throws OcException; + + /** + * Method to join the group on account server + * + * @param groupId Group ID to join + * @param onPostListener event handler The event handler will be invoked with a map of + * attribute name and values. + * + * @return Returns ::OC_STACK_OK if success + */ + public void joinGroup(String groupId, + OnPostListener onPostListener) throws OcException { + this.joinGroup0(groupId, onPostListener); + } + + private native void joinGroup0(String groupId, + OnPostListener onPostListener) throws OcException; + + /** + * Method to add devices to the group on account server + * + * @param groupId Group ID to add devices. + * @param deviceId List of devices to add. + * @param onPostListener event handler The event handler will be invoked with a map of + * attribute name and values. + * + * @return Returns ::OC_STACK_OK if success + */ + public void addDeviceToGroup(String groupId, + List deviceId, + OnPostListener onPostListener) throws OcException { + this.addDeviceToGroup0(groupId, deviceId.toArray(new String[deviceId.size()]), + onPostListener); + } + + private native void addDeviceToGroup0(String groupId, + String[] deviceId, + OnPostListener onPostListener) throws OcException; + + /** + * Method to get information of the group from account server + * + * @param groupId Group ID to get information. + * @param onGetListener The event handler will be invoked with a map of attribute name and + * values. The event handler will also have the result from this Get + * operation This will have error codes + * + * @return Returns ::OC_STACK_OK if success + */ + public void getGroupInfo(String groupId, + OnGetListener onGetListener) throws OcException { + this.getGroupInfo0(groupId, onGetListener); + } + + private native void getGroupInfo0(String groupId, + OnGetListener onGetListener) throws OcException; + + /** + * Method to leave the group joined on account server + * + * @param groupId Group ID to leave. + * @param onDeleteListener event handler The event handler will have headerOptionList. + * + * @return Returns ::OC_STACK_OK if success + */ + public void leaveGroup(String groupId, + OnDeleteListener onDeleteListener) throws OcException { + this.leaveGroup0(groupId, onDeleteListener); + } + + private native void leaveGroup0(String groupId, + OnDeleteListener onDeleteListener) throws OcException; + + /** + * Method to delete devices from the group on account server + * + * @param groupId Group ID to delete devices. + * @param deviceId List of devices to delete. + * @param onDeleteListener event handler The event handler will have headerOptionList. + * + * @return Returns ::OC_STACK_OK if success + */ + public void deleteDeviceFromGroup(String groupId, + List deviceId, + OnDeleteListener onDeleteListener) throws OcException { + this.deleteDeviceFromGroup0(groupId, deviceId.toArray(new String[deviceId.size()]), + onDeleteListener); + } + + private native void deleteDeviceFromGroup0(String groupId, + String[] deviceId, + OnDeleteListener onDeleteListener) throws OcException; + + /** + * Method to register observe to the group on account server + * User can receive a notify when the group get changed (eg. new user/device added) + * + * @param groupId Group ID to observe. + * @param cloudConnectHandler Callback function that will get the result of the operation. + * + * @return Returns ::OC_STACK_OK if success + */ + public void observeGroup(String groupId, + OnObserveListener onObserveListener) throws OcException { + this.observeGroup0(groupId, onObserveListener); + } + + private native void observeGroup0(String groupId, + OnObserveListener onObserveListener) throws OcException; + + /** + * Method to cancel observe to the group on account server + * + * @param groupId Group ID to observe. + * + * @return Returns ::OC_STACK_OK if success + */ + public void cancelObserveGroup(String groupId) throws OcException { + this.cancelObserveGroup0(groupId); + } + + private native void cancelObserveGroup0(String groupId) throws OcException; + + /** + * Method to register observe to invitation resource on account server + * User can receive a invitation which is including group ID to join + * Once receive a invitation, user should call 'deleteInvitation' to delete a invitation + * on account server. + * + * @param cloudConnectHandler Callback function that will get the result of the operation. + * + * @return Returns ::OC_STACK_OK if success + */ + public void observeInvitation(OnObserveListener onObserveListener) throws OcException { + this.observeInvitation0(onObserveListener); + } + + private native void observeInvitation0(OnObserveListener onObserveListener) throws OcException; + + /** + * Method to cancel observe to invitation resource on account server + * + * @return Returns ::OC_STACK_OK if success + */ + public void cancelObserveInvitation() throws OcException { + this.cancelObserveInvitation0(); + } + + private native void cancelObserveInvitation0() throws OcException; + + /** + * Method to send a invitation to invite a user into a group + * + * @param groupId Group ID for inviting. + * @param userUuid Identifier of the user to invite. + * @param onPostListener event handler The event handler will be invoked with a map of + * attribute name and values. + * + * @return Returns ::OC_STACK_OK if success + */ + public void sendInvitation(String groupId, + String userUuid, + OnPostListener onPostListener) throws OcException { + this.sendInvitation0(groupId, userUuid, onPostListener); + } + + private native void sendInvitation0(String groupId, + String userUuid, + OnPostListener onPostListener) throws OcException; + + /** + * Method to cancel a invitation on account server that user has sent + * + * @param groupId Group ID to cancel a invitation. + * @param userUuid Identifier of the user to cancel a invitation. + * @param onDeleteListener event handler The event handler will have headerOptionList. + * + * @return Returns ::OC_STACK_OK if success + */ + public void cancelInvitation(String groupId, + String userUuid, + OnDeleteListener onDeleteListener) throws OcException { + this.cancelInvitation0(groupId, userUuid, onDeleteListener); + } + + private native void cancelInvitation0(String groupId, + String userUuid, + OnDeleteListener onDeleteListener) throws OcException; + + /** + * Method to delete a invitation on account server that user has received + * + * @param groupId Group ID to delete a invitation. + * @param onDeleteListener event handler The event handler will have headerOptionList. + * + * @return Returns ::OC_STACK_OK if success + */ + public void deleteInvitation(String groupId, + OnDeleteListener onDeleteListener) throws OcException { + this.deleteInvitation0(groupId, onDeleteListener); + } + + private native void deleteInvitation0(String groupId, + OnDeleteListener onDeleteListener) throws OcException; + + /** + * An OnGetListener can be registered via the resource get call. + * Event listeners are notified asynchronously + */ + public interface OnGetListener { + public void onGetCompleted(List headerOptionList, + OcRepresentation ocRepresentation); + + public void onGetFailed(Throwable ex); + } + + /** + * An OnPostListener can be registered via the resource post call. + * Event listeners are notified asynchronously + */ + public interface OnPostListener { + public void onPostCompleted(List headerOptionList, + OcRepresentation ocRepresentation); + + public void onPostFailed(Throwable ex); + } + + /** + * An OnDeleteListener can be registered via the resource delete call. + * Event listeners are notified asynchronously + */ + public interface OnDeleteListener { + public void onDeleteCompleted(List headerOptionList); + + public void onDeleteFailed(Throwable ex); + } + + /** + * An OnObserveListener can be registered via the resource observe call. + * Event listeners are notified asynchronously + */ + public interface OnObserveListener { + /** + * To Register. + */ + public static final int REGISTER = 0; + /** + * To Deregister. + */ + public static final int DEREGISTER = 1; + /** + * Others. + */ + public static final int NO_OPTION = 2; + + public void onObserveCompleted(List headerOptionList, + OcRepresentation ocRepresentation, + int sequenceNumber); + + public void onObserveFailed(Throwable ex); + } + + private long mNativeHandle; +} + diff --git a/android/android_api/base/src/main/java/org/iotivity/base/OcCloudProvisioning.java b/android/android_api/base/src/main/java/org/iotivity/base/OcCloudProvisioning.java new file mode 100755 index 000000000..31a071c53 --- /dev/null +++ b/android/android_api/base/src/main/java/org/iotivity/base/OcCloudProvisioning.java @@ -0,0 +1,138 @@ +/* + ******************************************************************* + * + * Copyright 2016 Samsung Electronics All Rights Reserved. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + */ + +package org.iotivity.base; + +import java.util.List; +import java.util.EnumSet; +import java.util.Map; +import java.util.ArrayList; + + + +/** + * OcCloudProvisioning class is responsible for providing methods for cloud + * provisioning. + */ +public class OcCloudProvisioning { + + private long mNativeHandle; + private String mIp; + private int mPort; + + /** + * API to construct the CloudProvisioning + * + * @param ipAddr address of the cloud server + * @param port port of the cloud server + */ + public OcCloudProvisioning(String ip, int port) { + this.mIp = ip; + this.mPort = port; + } + + public String getIP() { + return mIp; + } + + public int getPort() { + return mPort; + } + + private void setNativeHandle(long nativeHandle) { + this.mNativeHandle = nativeHandle; + } + + public interface RequestCertificateListener { + public void requestCertificateListener(boolean result); + } + + public interface GetAclIdByDeviceListener { + public void getAclIdByDeviceListener(boolean result,String aclId); + } + + public interface GetIndividualAclInfoListener { + public void getIndividualAclInfoListener(boolean result); + } + + public interface GetCRLListener { + public void getCRLListener(boolean result); + } + + public interface PostCRLListener { + public void postCRLListener(boolean result); + } + + /** + * Method to Request a certificate from the cloud + * @param certificateIssueRequestListener function called by the stack on completion of request. + * @throws OcException + */ + public native void requestCertificate( + RequestCertificateListener certificateIssueRequestListener) throws OcException; + + /** + * Method to get ACL ID for the device + * @param deviceId device ID for which the Acl ID is requested + * @param cloudAclIdGetByDeviceHandler function called by the stack on completion of request. + * @throws OcException + */ + public native void getAclIdByDevice(String deviceId, + GetAclIdByDeviceListener cloudAclIdGetByDeviceHandler) throws OcException; + + /** + * Method to get ACL information about the given Acl ID + * @param aclId ACL ID for which the Acl information is requested + * @param cloudAclIndividualGetInfoHandler function called by the stack on completion of request. + * @throws OcException + */ + public native void getIndividualAclInfo(String aclId, + GetIndividualAclInfoListener cloudAclIndividualGetInfoHandler) throws OcException; + + /** + * Method to get certificate revocation list + * @param cloudGetCRLHandler function called by the stack on completion of request. + * @throws OcException + */ + public native void getCRL(GetCRLListener cloudGetCRLHandler) + throws OcException; + + /** + * Method to post the certificate revocation list to cloud + * @param thisUpdate thisUpdate [mandatory param]. + * @param nextUpdate nextUpdate [mandatory param]. + * @param crl revocation list [optional]. + * @param serialNumbers [optional]. + * @param cloudPostCRLHandler function called by the stack on completion of request. + * @throws OcException + */ + public void postCRL(String thisUpdate, String nextUpdate, String crl, ArrayList serialNumbers, + PostCRLListener cloudPostCRLHandler) throws OcException + { + String[] serialNums = new String[serialNumbers.size()]; + serialNums = serialNumbers.toArray(serialNums); + this.postCRL0(thisUpdate, nextUpdate, crl, serialNums, cloudPostCRLHandler); + } + public native void postCRL0(String thisUpdate, String nextUpdate, String crl, String[] serialNumbers, + PostCRLListener cloudPostCRLHandler) throws OcException; +} + diff --git a/android/android_api/base/src/main/java/org/iotivity/base/OcConnectivityType.java b/android/android_api/base/src/main/java/org/iotivity/base/OcConnectivityType.java index 2d42a3e61..0eb951ae1 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/OcConnectivityType.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/OcConnectivityType.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Intel Corporation. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; @@ -131,4 +131,4 @@ public enum OcConnectivityType { return CT_DEFAULT; } } -} \ No newline at end of file +} diff --git a/android/android_api/base/src/main/java/org/iotivity/base/OcDeviceInfo.java b/android/android_api/base/src/main/java/org/iotivity/base/OcDeviceInfo.java index 062405f20..4320ad1d8 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/OcDeviceInfo.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/OcDeviceInfo.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Intel Corporation. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; diff --git a/android/android_api/base/src/main/java/org/iotivity/base/OcException.java b/android/android_api/base/src/main/java/org/iotivity/base/OcException.java index 1d56947aa..23af6ae36 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/OcException.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/OcException.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Intel Corporation. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; diff --git a/android/android_api/base/src/main/java/org/iotivity/base/OcHeaderOption.java b/android/android_api/base/src/main/java/org/iotivity/base/OcHeaderOption.java index 6bf442f50..bcabc6639 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/OcHeaderOption.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/OcHeaderOption.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Intel Corporation. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; diff --git a/android/android_api/base/src/main/java/org/iotivity/base/OcPlatform.java b/android/android_api/base/src/main/java/org/iotivity/base/OcPlatform.java index 76cd649b9..6155cea32 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/OcPlatform.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/OcPlatform.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Intel Corporation. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; @@ -172,6 +172,10 @@ public final class OcPlatform { OcResourceResponse ocResourceResponse) throws OcException { OcPlatform.initCheck(); + if (ocObservationIdList == null) { + throw new OcException(ErrorCode.INVALID_PARAM, "ocObservationIdList cannot be null"); + } + byte[] idArr = new byte[ocObservationIdList.size()]; Iterator it = ocObservationIdList.iterator(); int i = 0; @@ -211,6 +215,10 @@ public final class OcPlatform { QualityOfService qualityOfService) throws OcException { OcPlatform.initCheck(); + if (ocObservationIdList == null) { + throw new OcException(ErrorCode.INVALID_PARAM, "ocObservationIdList cannot be null"); + } + byte[] idArr = new byte[ocObservationIdList.size()]; Iterator it = ocObservationIdList.iterator(); int i = 0; @@ -631,6 +639,11 @@ public final class OcPlatform { OcResourceHandle ocResourceCollectionHandle, List ocResourceHandleList) throws OcException { OcPlatform.initCheck(); + + if (ocResourceHandleList == null) { + throw new OcException(ErrorCode.INVALID_PARAM, "ocResourceHandleList cannot be null"); + } + OcPlatform.bindResources0( ocResourceCollectionHandle, ocResourceHandleList.toArray( @@ -672,6 +685,11 @@ public final class OcPlatform { OcResourceHandle ocResourceCollectionHandle, List ocResourceHandleList) throws OcException { OcPlatform.initCheck(); + + if (ocResourceHandleList == null) { + throw new OcException(ErrorCode.INVALID_PARAM, "ocResourceHandleList cannot be null"); + } + OcPlatform.unbindResources0( ocResourceCollectionHandle, ocResourceHandleList.toArray( @@ -833,6 +851,43 @@ public final class OcPlatform { private static native void unsubscribePresence0( OcPresenceHandle ocPresenceHandle) throws OcException; + /** + * Subscribes to a server's device presence change events. + * + * @param host The IP address/addressable name of the server to subscribe to. + * @param di Vector which can have the devices id. + * @param connectivityTypeSet Set of connectivity types, e.g. IP. + * @param onObserveListener The handler method will be invoked with a map + * of attribute name and values. + * @return a handle object that can be used to identify this subscription request. + * It can be used to unsubscribe from these events in the future. + * @throws OcException if failure. + */ + public static OcPresenceHandle subscribeDevicePresence( + String host, + List di, + EnumSet connectivityTypeSet, + OcResource.OnObserveListener onObserveListener) throws OcException { + OcPlatform.initCheck(); + int connTypeInt = 0; + + for (OcConnectivityType connType : OcConnectivityType.values()) { + if (connectivityTypeSet.contains(connType)) + connTypeInt |= connType.getValue(); + } + return OcPlatform.subscribeDevicePresence0( + host, + di.toArray(new String[di.size()]), + connTypeInt, + onObserveListener); + } + + private static native OcPresenceHandle subscribeDevicePresence0( + String host, + String[] di, + int connectivityType, + OcResource.OnObserveListener onObserveListener) throws OcException; + /** * Creates a resource proxy object so that get/put/observe functionality can be used without * discovering the object in advance. Note that the consumer of this method needs to provide @@ -949,6 +1004,313 @@ public final class OcPlatform { int pmSel, String pinNumber, DirectPairingListener onDirectPairingListener) throws OcException; + /** + * API to publish resource to remote resource-directory. + * + * @param host Host Address of a service to publish resource. + * @param connectivityTypeSet Set of types of connectivity. Example: IP + * @param onPublishResourceListener Handles events, success states and failure states. + * @throws OcException if failure + */ + public static void publishResourceToRD( + String host, + EnumSet connectivityTypeSet, + OnPublishResourceListener onPublishResourceListener) throws OcException { + OcPlatform.initCheck(); + + int connTypeInt = 0; + + for (OcConnectivityType connType : OcConnectivityType.values()) { + if (connectivityTypeSet.contains(connType)) { + connTypeInt |= connType.getValue(); + } + } + + OcPlatform.publishResourceToRD0( + host, + connTypeInt, + onPublishResourceListener, + sPlatformQualityOfService.getValue() + ); + } + + /** + * API to publish resource to remote resource-directory. + * + * @param host Host Address of a service to publish resource. + * @param connectivityTypeSet Set of types of connectivity. Example: IP + * @param onPublishResourceListener Handles events, success states and failure states. + * @param qualityOfService the quality of communication. + * @throws OcException if failure + */ + public static void publishResourceToRD( + String host, + EnumSet connectivityTypeSet, + OnPublishResourceListener onPublishResourceListener, + QualityOfService qualityOfService) throws OcException { + OcPlatform.initCheck(); + + int connTypeInt = 0; + + for (OcConnectivityType connType : OcConnectivityType.values()) { + if (connectivityTypeSet.contains(connType)) { + connTypeInt |= connType.getValue(); + } + } + + OcPlatform.publishResourceToRD0( + host, + connTypeInt, + onPublishResourceListener, + qualityOfService.getValue() + ); + } + + private static native void publishResourceToRD0( + String host, + int connectivityType, + OnPublishResourceListener onPublishResourceListener, + int qualityOfService) throws OcException; + + /** + * API to publish resource to remote resource-directory. + * + * @param host Host Address of a service to publish resource. + * @param connectivityTypeSet Set of types of connectivity. Example: IP + * @param ocResourceHandleList reference to list of resource handles to be published. + * @param onPublishResourceListener Handles events, success states and failure states. + * @throws OcException if failure + */ + public static void publishResourceToRD( + String host, + EnumSet connectivityTypeSet, + List ocResourceHandleList, + OnPublishResourceListener onPublishResourceListener) throws OcException { + OcPlatform.initCheck(); + + int connTypeInt = 0; + + for (OcConnectivityType connType : OcConnectivityType.values()) { + if (connectivityTypeSet.contains(connType)) { + connTypeInt |= connType.getValue(); + } + } + + OcPlatform.publishResourceToRD1( + host, + connTypeInt, + ocResourceHandleList.toArray( + new OcResourceHandle[ocResourceHandleList.size()]), + onPublishResourceListener, + sPlatformQualityOfService.getValue() + ); + } + + /** + * API to publish resource to remote resource-directory. + * + * @param host Host IP Address of a service to publish resource. + * @param connectivityTypeSet Set of types of connectivity. Example: IP + * @param ocResourceHandleList reference to list of resource handles to be published. + * @param onPublishResourceListener Handles events, success states and failure states. + * @param qualityOfService the quality of communication + * @throws OcException if failure + */ + public static void publishResourceToRD( + String host, + EnumSet connectivityTypeSet, + List ocResourceHandleList, + OnPublishResourceListener onPublishResourceListener, + QualityOfService qualityOfService) throws OcException { + OcPlatform.initCheck(); + + int connTypeInt = 0; + + for (OcConnectivityType connType : OcConnectivityType.values()) { + if (connectivityTypeSet.contains(connType)) { + connTypeInt |= connType.getValue(); + } + } + + OcPlatform.publishResourceToRD1( + host, + connTypeInt, + ocResourceHandleList.toArray( + new OcResourceHandle[ocResourceHandleList.size()]), + onPublishResourceListener, + qualityOfService.getValue() + ); + } + + private static native void publishResourceToRD1( + String host, + int connectivityType, + OcResourceHandle[] ocResourceHandleArray, + OnPublishResourceListener onPublishResourceListener, + int qualityOfService) throws OcException; + + /** + * API to delete resource from remote resource-directory. + * + * @param host Host Address of a service to publish resource. + * @param connectivityTypeSet Set of types of connectivity. Example: IP + * @param onDeleteResourceListener Handles events, success states and failure states. + * @throws OcException if failure + */ + public static void deleteResourceFromRD( + String host, + EnumSet connectivityTypeSet, + OnDeleteResourceListener onDeleteResourceListener) throws OcException { + OcPlatform.initCheck(); + + int connTypeInt = 0; + + for (OcConnectivityType connType : OcConnectivityType.values()) { + if (connectivityTypeSet.contains(connType)) { + connTypeInt |= connType.getValue(); + } + } + + OcPlatform.deleteResourceFromRD0( + host, + connTypeInt, + onDeleteResourceListener, + sPlatformQualityOfService.getValue() + ); + } + + /** + * API to delete resource from remote resource-directory. + * + * @param host Host Address of a service to publish resource. + * @param connectivityTypeSet Set of types of connectivity. Example: IP + * @param onDeleteResourceListener Handles events, success states and failure states. + * @param qualityOfService the quality of communication. + * @throws OcException if failure + */ + public static void deleteResourceFromRD( + String host, + EnumSet connectivityTypeSet, + OnDeleteResourceListener onDeleteResourceListener, + QualityOfService qualityOfService) throws OcException { + OcPlatform.initCheck(); + + int connTypeInt = 0; + + for (OcConnectivityType connType : OcConnectivityType.values()) { + if (connectivityTypeSet.contains(connType)) { + connTypeInt |= connType.getValue(); + } + } + + OcPlatform.deleteResourceFromRD0( + host, + connTypeInt, + onDeleteResourceListener, + qualityOfService.getValue() + ); + } + + private static native void deleteResourceFromRD0( + String host, + int connectivityType, + OnDeleteResourceListener onDeleteResourceListener, + int qualityOfService) throws OcException; + + /** + * API to delete resource from remote resource-directory. + * + * @param host Host Address of a service to publish resource. + * @param connectivityTypeSet Set of types of connectivity. Example: IP + * @param ocResourceHandleList reference to list of resource handles to be published. + * @param onDeleteResourceListener Handles events, success states and failure states. + * @throws OcException if failure + */ + public static void deleteResourceFromRD( + String host, + EnumSet connectivityTypeSet, + List ocResourceHandleList, + OnDeleteResourceListener onDeleteResourceListener) throws OcException { + OcPlatform.initCheck(); + + int connTypeInt = 0; + + for (OcConnectivityType connType : OcConnectivityType.values()) { + if (connectivityTypeSet.contains(connType)) { + connTypeInt |= connType.getValue(); + } + } + + OcPlatform.deleteResourceFromRD1( + host, + connTypeInt, + ocResourceHandleList.toArray( + new OcResourceHandle[ocResourceHandleList.size()]), + onDeleteResourceListener, + sPlatformQualityOfService.getValue() + ); + } + + /** + * API to delete resource from remote resource-directory. + * + * @param host Host IP Address of a service to publish resource. + * @param connectivityTypeSet Set of types of connectivity. Example: IP + * @param ocResourceHandleList reference to list of resource handles to be published. + * @param onDeleteResourceListener Handles events, success states and failure states. + * @param qualityOfService the quality of communication + * @throws OcException if failure + */ + public static void deleteResourceFromRD( + String host, + EnumSet connectivityTypeSet, + List ocResourceHandleList, + OnDeleteResourceListener onDeleteResourceListener, + QualityOfService qualityOfService) throws OcException { + OcPlatform.initCheck(); + + int connTypeInt = 0; + + for (OcConnectivityType connType : OcConnectivityType.values()) { + if (connectivityTypeSet.contains(connType)) { + connTypeInt |= connType.getValue(); + } + } + + OcPlatform.deleteResourceFromRD1( + host, + connTypeInt, + ocResourceHandleList.toArray( + new OcResourceHandle[ocResourceHandleList.size()]), + onDeleteResourceListener, + qualityOfService.getValue() + ); + } + + private static native void deleteResourceFromRD1( + String host, + int connectivityType, + OcResourceHandle[] ocResourceHandleArray, + OnDeleteResourceListener onDeleteResourceListener, + int qualityOfService) throws OcException; + + /** + * An OnPublishResourceListener can be registered via the OcPlatform.publishResourceToRD call. + * Event listeners are notified asynchronously + */ + public interface OnPublishResourceListener { + public void onPublishResourceCompleted(OcRepresentation ocRepresentation); + public void onPublishResourceFailed(Throwable ex); + } + + /** + * An OnDeleteResourceListener can be registered via the OcPlatform.deleteResourceFromRD call. + * Event listeners are notified asynchronously + */ + public interface OnDeleteResourceListener { + public void onDeleteResourceCompleted(int result); + } + /** * An FindDirectPairingListener can be registered via the OcPlatform.findDirectPairingDevices call. * Event listeners are notified asynchronously @@ -981,6 +1343,7 @@ public final class OcPlatform { */ public interface OnResourceFoundListener { public void onResourceFound(OcResource resource); + public void onFindResourceFailed(Throwable ex, String uri); } /** @@ -1010,6 +1373,14 @@ public final class OcPlatform { /** * An EntityHandler can be registered via the OcPlatform.registerResource call. * Event listeners are notified asynchronously + * + * @note entityhandler callback : + * When you set specific return value like EntityHandlerResult.OK, SLOW + * and etc in entity handler callback, + * ocstack will be not send response automatically to client + * except for error return value like EntityHandlerResult.ERROR + * If you want to send response to client with specific result, + * sendResponse API should be called with the result value. */ public interface EntityHandler { public EntityHandlerResult handleEntity(OcResourceRequest ocResourceRequest); @@ -1031,4 +1402,49 @@ public final class OcPlatform { OcPlatform.initCheck(); return sPlatformQualityOfService; } + + /** + * Create an account manager object that can be used for doing request to account server. + * You can only create this object if OCPlatform was initialized to be a Client or + * Client/Server. Otherwise, this will return an empty shared ptr. + * + * @note For now, OCPlatform SHOULD be initialized to be a Client/Server(Both) for the + * methods of this object to work since device id is not generated on Client mode. + * + * @param host Host IP Address of a account server. + * @param connectivityTypeSet Set of types of connectivity. Example: CT_ADAPTER_IP + * @return new AccountManager object + * @throws OcException if failure + */ + public static OcAccountManager constructAccountManagerObject( + String host, + EnumSet connectivityTypeSet) throws OcException { + OcPlatform.initCheck(); + int connTypeInt = 0; + + for (OcConnectivityType connType : OcConnectivityType.values()) { + if (connectivityTypeSet.contains(connType)) + { + connTypeInt |= connType.getValue(); + } + } + return OcPlatform.constructAccountManagerObject0( + host, + connTypeInt + ); + } + + private static native OcAccountManager constructAccountManagerObject0( + String host, + int connectivityType) throws OcException; + /** + * Method to get device Id in byte array. + * @return My DeviceId. + */ + public static native byte[] getDeviceId(); + + /** + * Method to set DeviceId. + */ + public static native void setDeviceId(byte[] deviceId) throws OcException; } diff --git a/android/android_api/base/src/main/java/org/iotivity/base/OcPlatformInfo.java b/android/android_api/base/src/main/java/org/iotivity/base/OcPlatformInfo.java index 89af6a29a..e896428ad 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/OcPlatformInfo.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/OcPlatformInfo.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Intel Corporation. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; diff --git a/android/android_api/base/src/main/java/org/iotivity/base/OcPlatformStatus.java b/android/android_api/base/src/main/java/org/iotivity/base/OcPlatformStatus.java index 3087e5ad4..c41eb37f3 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/OcPlatformStatus.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/OcPlatformStatus.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Intel Corporation. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; diff --git a/android/android_api/base/src/main/java/org/iotivity/base/OcPresenceHandle.java b/android/android_api/base/src/main/java/org/iotivity/base/OcPresenceHandle.java index ae7ed1509..1107854de 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/OcPresenceHandle.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/OcPresenceHandle.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Intel Corporation. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; diff --git a/android/android_api/base/src/main/java/org/iotivity/base/OcPresenceStatus.java b/android/android_api/base/src/main/java/org/iotivity/base/OcPresenceStatus.java index 02b774fa3..4bc4baaaa 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/OcPresenceStatus.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/OcPresenceStatus.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Intel Corporation. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; diff --git a/android/android_api/base/src/main/java/org/iotivity/base/OcProvisioning.java b/android/android_api/base/src/main/java/org/iotivity/base/OcProvisioning.java index e7debe7a9..8cb282b0c 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/OcProvisioning.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/OcProvisioning.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Samsung Electronics All Rights Reserved. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Samsung Electronics All Rights Reserved. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; @@ -112,4 +112,17 @@ public class OcProvisioning { return Arrays.asList(OcProvisioning.getDeviceStatusList1(timeout)); } private static native OcSecureResource[] getDeviceStatusList1(int timeout) throws OcException; + + /** + * Method to save the Trust certificate chain to SVR. + * + * @param byte[] trustCertChain + * @param EncodingType encodingType + * @throws OcException + */ + public static int saveTrustCertChain(byte[] trustCertChain, EncodingType encodingType) throws OcException { + return saveTrustCertChain1(trustCertChain,encodingType.getValue()); + } + private static native int saveTrustCertChain1(byte[] trustCertChain, int encodingType) + throws OcException; } diff --git a/android/android_api/base/src/main/java/org/iotivity/base/OcRepresentation.java b/android/android_api/base/src/main/java/org/iotivity/base/OcRepresentation.java index 309ab70d2..24d8b8848 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/OcRepresentation.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/OcRepresentation.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Intel Corporation. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; @@ -25,6 +25,7 @@ package org.iotivity.base; import java.security.InvalidParameterException; import java.util.Arrays; import java.util.List; +import java.util.Map; /** * @@ -52,6 +53,8 @@ public class OcRepresentation { this.mNativeNeedsDelete = nativeNeedsDelete; } + public native Map getValues(); + public T getValue(String key) throws OcException { Object obj = this.getValueN(key); @SuppressWarnings("unchecked") @@ -141,6 +144,10 @@ public class OcRepresentation { this.setValueRepresentation3DArray(key, value); } + public void setValue(String key, byte[] value) throws OcException { + this.setValueByteArray(key, value); + } + private native void setValueInteger(String key, int value) throws OcException; private native void setValueDouble(String key, double value) throws OcException; @@ -181,6 +188,8 @@ public class OcRepresentation { private native void setValueRepresentation3DArray(String key, OcRepresentation[][][] value) throws OcException; + private native void setValueByteArray(String key, byte[] value) throws OcException; + /** * @deprecated use {@link #getValue(String key)} instead. */ @@ -355,4 +364,4 @@ public class OcRepresentation { private long mNativeHandle; private boolean mNativeNeedsDelete; -} \ No newline at end of file +} diff --git a/android/android_api/base/src/main/java/org/iotivity/base/OcRequestHandle.java b/android/android_api/base/src/main/java/org/iotivity/base/OcRequestHandle.java index 7e021dcbb..69216a871 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/OcRequestHandle.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/OcRequestHandle.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Intel Corporation. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; diff --git a/android/android_api/base/src/main/java/org/iotivity/base/OcResource.java b/android/android_api/base/src/main/java/org/iotivity/base/OcResource.java index bb22465c8..f9cc04f40 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/OcResource.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/OcResource.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Intel Corporation. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; @@ -65,6 +65,11 @@ public class OcResource { public void get(Map queryParamsMap, OnGetListener onGetListener, QualityOfService qualityOfService) throws OcException { + + if (qualityOfService == null) { + throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null"); + } + this.get1(queryParamsMap, onGetListener, qualityOfService.getValue()); } @@ -116,6 +121,11 @@ public class OcResource { Map queryParamsMap, OnGetListener onGetListener, QualityOfService qualityOfService) throws OcException { + + if (qualityOfService == null) { + throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null"); + } + this.get3( resourceType, resourceInterface, @@ -157,6 +167,11 @@ public class OcResource { Map queryParamsMap, OnPutListener onPutListener, QualityOfService qualityOfService) throws OcException { + + if (qualityOfService == null) { + throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null"); + } + this.put1( ocRepresentation, queryParamsMap, @@ -217,6 +232,11 @@ public class OcResource { Map queryParamsMap, OnPutListener onPutListener, QualityOfService qualityOfService) throws OcException { + + if (qualityOfService == null) { + throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null"); + } + this.put3( resourceType, resourceInterface, @@ -260,6 +280,11 @@ public class OcResource { Map queryParamsMap, OnPostListener onPostListener, QualityOfService qualityOfService) throws OcException { + + if (qualityOfService == null) { + throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null"); + } + this.post1( ocRepresentation, queryParamsMap, @@ -320,6 +345,11 @@ public class OcResource { Map queryParamsMap, OnPostListener onPostListener, QualityOfService qualityOfService) throws OcException { + + if (qualityOfService == null) { + throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null"); + } + this.post3( resourceType, resourceInterface, @@ -351,6 +381,11 @@ public class OcResource { */ public void deleteResource(OnDeleteListener onDeleteListener, QualityOfService qualityOfService) throws OcException { + + if (qualityOfService == null) { + throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null"); + } + this.deleteResource1(onDeleteListener, qualityOfService.getValue()); } @@ -370,6 +405,11 @@ public class OcResource { public void observe(ObserveType observeType, Map queryParamsMap, OnObserveListener onObserveListener) throws OcException { + + if (observeType == null) { + throw new OcException(ErrorCode.INVALID_PARAM, "observeType cannot be null"); + } + this.observe( observeType.getValue(), queryParamsMap, @@ -394,6 +434,15 @@ public class OcResource { Map queryParamsMap, OnObserveListener onObserveListener, QualityOfService qualityOfService) throws OcException { + + if (observeType == null) { + throw new OcException(ErrorCode.INVALID_PARAM, "observeType cannot be null"); + } + + if (qualityOfService == null) { + throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null"); + } + this.observe1( observeType.getValue(), queryParamsMap, @@ -422,6 +471,11 @@ public class OcResource { * @throws OcException */ public void cancelObserve(QualityOfService qualityOfService) throws OcException { + + if (qualityOfService == null) { + throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null"); + } + this.cancelObserve1(qualityOfService.getValue()); } @@ -432,8 +486,14 @@ public class OcResource { * * @param headerOptionList List where header information(header optionID and * optionData is passed + * @throws OcException */ - public void setHeaderOptions(List headerOptionList) { + public void setHeaderOptions(List headerOptionList) throws OcException { + + if (headerOptionList == null) { + throw new OcException(ErrorCode.INVALID_PARAM, "headerOptionList cannot be null"); + } + this.setHeaderOptions(headerOptionList.toArray( new OcHeaderOption[headerOptionList.size()]) ); @@ -591,4 +651,205 @@ public class OcResource { private native void dispose(); private long mNativeHandle; + + /** + * Method to discovery Topics + * + * @param queryParamsMap map which can have the query parameter name and value + * @param onTopicFoundListener event handler The handler method will be invoked with a map + * of attribute name and values. + * @param qualityOfService the quality of communication. + * @throws OcException + */ + public void discoveryMQTopics(Map queryParamsMap, + OnMQTopicFoundListener onTopicFoundListener, + QualityOfService qualityOfService) throws OcException { + + if (qualityOfService == null) { + throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null"); + } + + this.discoveryMQTopicsImpl(queryParamsMap, onTopicFoundListener, + qualityOfService.getValue()); + } + + private synchronized native void discoveryMQTopicsImpl( + Map queryParamsMap, + OnMQTopicFoundListener onTopicFoundListener, + int qualityOfService) throws OcException; + + /** + * Method to create Topic into MQ Brober. + * + * @param ocRepresentation representation of the MQ Broker. + * @param uri new MQ Topic uri which want to create. + * @param queryParamsMap map which can have the query parameter name and value. + * @param onTopicCreatedListener event handler The handler method will be invoked with a map + * of attribute name and values. + * @param qualityOfService the quality of communication. + * @throws OcException + */ + public void createMQTopic(OcRepresentation ocRepresentation, + String uri, + Map queryParamsMap, + OnMQTopicCreatedListener onTopicCreatedListener, + QualityOfService qualityOfService) throws OcException { + + if (qualityOfService == null) { + throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null"); + } + + this.createMQTopicImpl(ocRepresentation, uri, queryParamsMap, + onTopicCreatedListener, qualityOfService.getValue()); + } + + private synchronized native void createMQTopicImpl( + OcRepresentation ocRepresentation, + String uri, + Map queryParamsMap, + OnMQTopicCreatedListener onTopicCreatedListener, + int qualityOfService) throws OcException; + + /** + * Method to set subscribe on the Topic. + * + * @param queryParamsMap map which can have the query parameter name and value. + * @param onObserveListener event handler The handler method will be invoked with a map + * of attribute name and values. + * @param qualityOfService the quality of communication. + * @throws OcException + */ + public void subscribeMQTopic(Map queryParamsMap, + OnObserveListener onObserveListener, + QualityOfService qualityOfService) throws OcException { + + if (qualityOfService == null) { + throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null"); + } + + this.subscribeMQTopicImpl(queryParamsMap, + onObserveListener, + qualityOfService.getValue()); + } + + private synchronized native void subscribeMQTopicImpl(Map queryParamsMap, + OnObserveListener onObserveListener, + int qualityOfService) throws OcException; + + /** + * Method to cancel the observation on the Topic. + * + * @param qualityOfService the quality of communication. + * @throws OcException + */ + public void unsubscribeMQTopic(QualityOfService qualityOfService) throws OcException{ + + if (qualityOfService == null) { + throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null"); + } + + this.unsubscribeMQTopicImpl(qualityOfService.getValue()); + } + + private native void unsubscribeMQTopicImpl( + int qualityOfService) throws OcException; + + /** + * Method to requestMQPublish on a Topic + * + * @param queryParamsMap Map which can have the query parameter name and value + * @param onPostListener event handler The event handler will be invoked with a map of + * attribute name and values. + * @param qualityOfService the quality of communication. + * @throws OcException + */ + public void requestMQPublish(Map queryParamsMap, + OnPostListener onPostListener, + QualityOfService qualityOfService) throws OcException { + + if (qualityOfService == null) { + throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null"); + } + + this.requestMQPublishImpl(queryParamsMap, + onPostListener, + qualityOfService.getValue()); + } + + private native void requestMQPublishImpl(Map queryParamsMap, + OnPostListener onPostListener, + int qualityOfService) throws OcException; + + /** + * Method to publishMQTopic on a Topic + * + * @param ocRepresentation representation of the resource + * @param queryParamsMap Map which can have the query parameter name and value + * @param onPostListener event handler The event handler will be invoked with a map of + * attribute name and values. + * @param qualityOfService the quality of communication. + * @throws OcException + */ + public void publishMQTopic(OcRepresentation ocRepresentation, + Map queryParamsMap, + OnPostListener onPostListener, + QualityOfService qualityOfService) throws OcException { + + if (qualityOfService == null) { + throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null"); + } + + this.publishMQTopicImpl(ocRepresentation, + queryParamsMap, + onPostListener, + qualityOfService.getValue()); + } + + private native void publishMQTopicImpl(OcRepresentation ocRepresentation, + Map queryParamsMap, + OnPostListener onPostListener, + int qualityOfService) throws OcException; + + /** + * An OnMQTopicFoundListener can be registered via the OcResource.discoveryMQTopics call. + * Event listeners are notified asynchronously + */ + public interface OnMQTopicFoundListener { + public void onTopicDiscoveried(OcResource resource); + public void onDiscoveryTopicFailed(Throwable ex, String uri); + } + + /** + * An OnMQTopicCreatedListener can be registered via the OcResource.createMQTopic call. + * Event listeners are notified asynchronously + */ + public interface OnMQTopicCreatedListener { + public void onTopicResourceCreated(OcResource resource); + public void onCreateTopicFailed(Throwable ex, String uri); + } + + /** + * An OnMQTopicSubscribeListener can be registered via the OcResource.subscribeMQTopic call. + * Event listeners are notified asynchronously + */ + public interface OnMQTopicSubscribeListener { + /** + * To Subscriber. + */ + public static final int SUBSCRIBER = 0; + /** + * To Unrubscriber. + */ + public static final int UNSUBSCRIBER = 1; + /** + * Others. + */ + public static final int NO_OPTION = 2; + public void onSubScribeCompleted(List headerOptionList, + OcRepresentation ocRepresentation, + int sequenceNumber); + public void onUnsubScribeCompleted(OcRepresentation ocRepresentation, + int sequenceNumber); + public void onSubScribeFailed(Throwable ex); + } } diff --git a/android/android_api/base/src/main/java/org/iotivity/base/OcResourceHandle.java b/android/android_api/base/src/main/java/org/iotivity/base/OcResourceHandle.java index b55ce65df..ac6e098ff 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/OcResourceHandle.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/OcResourceHandle.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Intel Corporation. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; diff --git a/android/android_api/base/src/main/java/org/iotivity/base/OcResourceIdentifier.java b/android/android_api/base/src/main/java/org/iotivity/base/OcResourceIdentifier.java index b1ce94a97..751d37bb9 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/OcResourceIdentifier.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/OcResourceIdentifier.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Intel Corporation. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; diff --git a/android/android_api/base/src/main/java/org/iotivity/base/OcResourceRequest.java b/android/android_api/base/src/main/java/org/iotivity/base/OcResourceRequest.java index 7e0367f91..b94689c47 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/OcResourceRequest.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/OcResourceRequest.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Intel Corporation. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; diff --git a/android/android_api/base/src/main/java/org/iotivity/base/OcResourceResponse.java b/android/android_api/base/src/main/java/org/iotivity/base/OcResourceResponse.java index 0356b8558..4e0879f86 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/OcResourceResponse.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/OcResourceResponse.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Intel Corporation. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; diff --git a/android/android_api/base/src/main/java/org/iotivity/base/OcSecureResource.java b/android/android_api/base/src/main/java/org/iotivity/base/OcSecureResource.java index b1daf6c69..0a6d096e3 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/OcSecureResource.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/OcSecureResource.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Samsung Electronics All Rights Reserved. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Samsung Electronics All Rights Reserved. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; @@ -89,6 +89,30 @@ public class OcSecureResource { ProvisionCredentialsListener provisionCredentialsListener) throws OcException; + /** + * Method to provision the Trust certificate chain to secured device. + * + * @param EnumSet OR'ed Cred Types + * @param int credId + * @param ProvisionTrustCertChainListener Callback function, which will be called after + * proviosion trust certificate chain. + * @throws OcException + */ + public void provisionTrustCertChain(EnumSet credTypeSet, int credId, + ProvisionTrustCertChainListener provisionTrustCertChainListener) throws OcException { + int credTypeInt = 0; + + for (CredType credType : CredType.values()) { + if (credTypeSet.contains(credType)) + credTypeInt |= credType.getValue(); + } + this.provisionTrustCertChain1(credTypeInt, credId, + provisionTrustCertChainListener); + } + private native void provisionTrustCertChain1(int credType, int credId, + ProvisionTrustCertChainListener provisionTrustCertChainListener) + throws OcException; + /** * Method send ACL information to resource. * @@ -210,6 +234,16 @@ public class OcSecureResource { int hasError); } + /** + * provisionTrustCertChainListener can be registered with ProvisionTrustCertChainListener + * call. + * Listener notified asynchronously. + */ + public interface ProvisionTrustCertChainListener { + public void provisionTrustCertChainListener(List provisionResultList, + int hasError); + } + /** * provisionAclListener can be registered with provisionAclListener * call. diff --git a/android/android_api/base/src/main/java/org/iotivity/base/OwnedStatus.java b/android/android_api/base/src/main/java/org/iotivity/base/OwnedStatus.java index 1c9057836..4abfc3ee0 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/OwnedStatus.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/OwnedStatus.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright Samsung Electronics All Rights Reserved. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright Samsung Electronics All Rights Reserved. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; diff --git a/android/android_api/base/src/main/java/org/iotivity/base/OxmType.java b/android/android_api/base/src/main/java/org/iotivity/base/OxmType.java index 177105e92..c8247deee 100755 --- a/android/android_api/base/src/main/java/org/iotivity/base/OxmType.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/OxmType.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Samsung Electronics All Rights Reserved. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Samsung Electronics All Rights Reserved. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; diff --git a/android/android_api/base/src/main/java/org/iotivity/base/PlatformConfig.java b/android/android_api/base/src/main/java/org/iotivity/base/PlatformConfig.java index 487f6a92d..b41b65ca7 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/PlatformConfig.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/PlatformConfig.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Intel Corporation. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; diff --git a/android/android_api/base/src/main/java/org/iotivity/base/QualityOfService.java b/android/android_api/base/src/main/java/org/iotivity/base/QualityOfService.java index e6d6659ac..5da2be189 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/QualityOfService.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/QualityOfService.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Intel Corporation. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; diff --git a/android/android_api/base/src/main/java/org/iotivity/base/RequestHandlerFlag.java b/android/android_api/base/src/main/java/org/iotivity/base/RequestHandlerFlag.java index b67cee811..3536f7851 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/RequestHandlerFlag.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/RequestHandlerFlag.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Intel Corporation. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; diff --git a/android/android_api/base/src/main/java/org/iotivity/base/RequestType.java b/android/android_api/base/src/main/java/org/iotivity/base/RequestType.java index 832c891b5..8c55a745b 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/RequestType.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/RequestType.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Intel Corporation. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; diff --git a/android/android_api/base/src/main/java/org/iotivity/base/ResourceProperty.java b/android/android_api/base/src/main/java/org/iotivity/base/ResourceProperty.java index 71e8b6fda..705565b8b 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/ResourceProperty.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/ResourceProperty.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Intel Corporation. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; diff --git a/android/android_api/base/src/main/java/org/iotivity/base/ServiceType.java b/android/android_api/base/src/main/java/org/iotivity/base/ServiceType.java index 929c4dae4..4d9027ea8 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/ServiceType.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/ServiceType.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Intel Corporation. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; diff --git a/android/android_api/base/src/main/java/org/iotivity/ca/CaBtPairingInterface.java b/android/android_api/base/src/main/java/org/iotivity/ca/CaBtPairingInterface.java index 57b87388d..e06d57416 100644 --- a/android/android_api/base/src/main/java/org/iotivity/ca/CaBtPairingInterface.java +++ b/android/android_api/base/src/main/java/org/iotivity/ca/CaBtPairingInterface.java @@ -31,7 +31,9 @@ public class CaBtPairingInterface { private static Context mContext; private CaBtPairingInterface(Context context) { - mContext = context; + synchronized(CaBtPairingInterface.class) { + mContext = context; + } registerIntentFilter(); } diff --git a/android/android_api/base/src/main/java/org/iotivity/ca/CaEdrInterface.java b/android/android_api/base/src/main/java/org/iotivity/ca/CaEdrInterface.java index 7a07b246b..aaf8bc6f5 100644 --- a/android/android_api/base/src/main/java/org/iotivity/ca/CaEdrInterface.java +++ b/android/android_api/base/src/main/java/org/iotivity/ca/CaEdrInterface.java @@ -26,12 +26,15 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.util.Log; public class CaEdrInterface { private static Context mContext; private CaEdrInterface(Context context) { - mContext = context; + synchronized(CaEdrInterface.class) { + mContext = context; + } registerIntentFilter(); } @@ -39,6 +42,7 @@ public class CaEdrInterface { IntentFilter filter = new IntentFilter(); filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED); filter.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED); + filter.addAction(BluetoothDevice.ACTION_ACL_DISCONNECTED); mContext.registerReceiver(mReceiver, filter); return filter; } @@ -52,6 +56,8 @@ public class CaEdrInterface { private native static void caEdrBondStateChangedCallback(String addr); + private native static void caEdrConnectionStateChangedCallback(String addr, int isConnected); + private static final BroadcastReceiver mReceiver = new BroadcastReceiver() { @Override @@ -87,6 +93,15 @@ public class CaEdrInterface { } } } + + if (action != null && action.equals(BluetoothDevice.ACTION_ACL_DISCONNECTED)) { + BluetoothDevice device + = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); + if (BluetoothDevice.DEVICE_TYPE_CLASSIC == device.getType()) + { + caEdrConnectionStateChangedCallback(device.getAddress(), 0); + } + } } }; } diff --git a/android/android_api/base/src/main/java/org/iotivity/ca/CaInterface.java b/android/android_api/base/src/main/java/org/iotivity/ca/CaInterface.java index 3711f972c..6924eb417 100644 --- a/android/android_api/base/src/main/java/org/iotivity/ca/CaInterface.java +++ b/android/android_api/base/src/main/java/org/iotivity/ca/CaInterface.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Intel Corporation. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.ca; @@ -177,4 +177,26 @@ public class CaInterface { private static native void caBtPairingStartScan(); private static native void caBtPairingStopScan(); private static native void caBtPairingCreateBond(BluetoothDevice device); -} \ No newline at end of file + + /** + * set BLE scan interval time and working count. + * scanning logic (start scan -> stop scan) will be worked repeatly for workingCount. + * and if you choose '0' value for workingCount parameter, + * scanning will be worked continually as interval time. + * @param intervalTime interval time(Seconds). + * @param workingCount working count with interval time. + */ + + public synchronized static void setLeScanIntervalTime(int intervalTime, int workingCount){ + CaInterface.setLeScanIntervalTimeImpl(intervalTime, workingCount); + } + + private static native void setLeScanIntervalTimeImpl(int intervalTime, int workingCount); + + + public synchronized static int setCipherSuite(OicCipher cipher, OcConnectivityType connType){ + return CaInterface.setCipherSuiteImpl(cipher.getValue(), connType.getValue()); + } + private static native int setCipherSuiteImpl(int cipher, int adapter); + +} diff --git a/android/android_api/base/src/main/java/org/iotivity/ca/CaIpInterface.java b/android/android_api/base/src/main/java/org/iotivity/ca/CaIpInterface.java index 2314df9ff..a747953f9 100644 --- a/android/android_api/base/src/main/java/org/iotivity/ca/CaIpInterface.java +++ b/android/android_api/base/src/main/java/org/iotivity/ca/CaIpInterface.java @@ -53,7 +53,9 @@ public class CaIpInterface { } private CaIpInterface(Context context) { - mContext = context; + synchronized(CaIpInterface.class) { + mContext = context; + } registerIpStateReceiver(); } diff --git a/android/android_api/base/src/main/java/org/iotivity/ca/CaLeClientInterface.java b/android/android_api/base/src/main/java/org/iotivity/ca/CaLeClientInterface.java index 8b383a7e5..695359b0d 100644 --- a/android/android_api/base/src/main/java/org/iotivity/ca/CaLeClientInterface.java +++ b/android/android_api/base/src/main/java/org/iotivity/ca/CaLeClientInterface.java @@ -47,10 +47,14 @@ public class CaLeClientInterface { private CaLeClientInterface(Context context) { caLeRegisterLeScanCallback(mLeScanCallback); caLeRegisterGattCallback(mGattCallback); - mContext = context; + synchronized(CaLeClientInterface.class) { + mContext = context; + } registerIntentFilter(); } + + public static void getLeScanCallback() { caLeRegisterLeScanCallback(mLeScanCallback); } @@ -91,6 +95,11 @@ public class CaLeClientInterface { private native static void caLeGattServicesDiscoveredCallback(BluetoothGatt gatt, int status); + private native static void caLeGattNWServicesDiscoveredCallback(BluetoothGatt gatt, + int status); + + private native static void caLeGattNWDescriptorWriteCallback(BluetoothGatt gatt, int status); + private native static void caLeGattCharacteristicWriteCallback( BluetoothGatt gatt, byte[] data, int status); @@ -211,6 +220,7 @@ public class CaLeClientInterface { caLeGattServicesDiscoveredCallback(gatt, status); caManagerLeServicesDiscoveredCallback(gatt, status); + caLeGattNWServicesDiscoveredCallback(gatt, status); } @Override @@ -247,6 +257,7 @@ public class CaLeClientInterface { super.onDescriptorWrite(gatt, descriptor, status); caLeGattDescriptorWriteCallback(gatt, status); + caLeGattNWDescriptorWriteCallback(gatt, status); } @Override diff --git a/android/android_api/base/src/main/java/org/iotivity/ca/CaNfcInterface.java b/android/android_api/base/src/main/java/org/iotivity/ca/CaNfcInterface.java index ebb273b6d..dee2ac154 100644 --- a/android/android_api/base/src/main/java/org/iotivity/ca/CaNfcInterface.java +++ b/android/android_api/base/src/main/java/org/iotivity/ca/CaNfcInterface.java @@ -49,7 +49,9 @@ public class CaNfcInterface implements NfcAdapter.CreateNdefMessageCallback { private CaNfcInterface(Context context, Activity activity) { Log.d(MYTAG, "NFC registerNfcReceiver"); - mContext = context; + synchronized(CaNfcInterface.class) { + mContext = context; + } mActivity = activity; mAdapter = NfcAdapter.getDefaultAdapter(mContext); diff --git a/android/android_api/base/src/main/java/org/iotivity/ca/OicCipher.java b/android/android_api/base/src/main/java/org/iotivity/ca/OicCipher.java new file mode 100644 index 000000000..60f9f164a --- /dev/null +++ b/android/android_api/base/src/main/java/org/iotivity/ca/OicCipher.java @@ -0,0 +1,38 @@ +/* **************************************************************** + * + * Copyright 2016 Samsung Electronics All Rights Reserved. + * + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************/ + +package org.iotivity.ca; + +public enum OicCipher { + TLS_ECDH_anon_WITH_AES_128_CBC_SHA(0xC018), + TLS_PSK_WITH_AES_128_CCM_8(0xC0A8), + TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8(0xC0AE), + TLS_RSA_WITH_AES_256_CBC_SHA(0x35); + + private int cipher; + + private OicCipher(int cipher) { + this.cipher = cipher; + } + + public int getValue(){ + return cipher; + } +} diff --git a/android/android_api/build.gradle b/android/android_api/build.gradle index b8a6bed19..cfcb3a21f 100755 --- a/android/android_api/build.gradle +++ b/android/android_api/build.gradle @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2014 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2014 Intel Corporation. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ // Top-level build file where you can add configuration options common to all sub-projects/modules. diff --git a/android/android_api/gradlew b/android/android_api/gradlew index 583ae0810..91a7e269e 100755 --- a/android/android_api/gradlew +++ b/android/android_api/gradlew @@ -1,164 +1,164 @@ -#!/usr/bin/env bash - -############################################################################## -## -## Gradle start up script for UN*X -## -############################################################################## - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" - -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` - -# Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" - -warn ( ) { - echo "$*" -} - -die ( ) { - echo - echo "$*" - echo - exit 1 -} - -# OS specific support (must be 'true' or 'false'). -cygwin=false -msys=false -darwin=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; -esac - -# For Cygwin, ensure paths are in UNIX format before anything is touched. -if $cygwin ; then - [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` -fi - -# Attempt to set APP_HOME -# Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi -done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >&- -APP_HOME="`pwd -P`" -cd "$SAVED" >&- - -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar - -# Determine the Java command to use to start the JVM. -if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - if [ ! -x "$JAVACMD" ] ; then - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." - fi -else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." -fi - -# Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi -fi - -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi - -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi - # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" - fi - i=$((i+1)) - done - case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac -fi - -# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules -function splitJvmOpts() { - JVM_OPTS=("$@") -} -eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS -JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" - -exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" +#!/usr/bin/env bash + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn ( ) { + echo "$*" +} + +die ( ) { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; +esac + +# For Cygwin, ensure paths are in UNIX format before anything is touched. +if $cygwin ; then + [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` +fi + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >&- +APP_HOME="`pwd -P`" +cd "$SAVED" >&- + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules +function splitJvmOpts() { + JVM_OPTS=("$@") +} +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS +JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" + +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/android/android_api/settings.gradle b/android/android_api/settings.gradle index d1bcc8a5b..5d0d8347a 100755 --- a/android/android_api/settings.gradle +++ b/android/android_api/settings.gradle @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Intel Corporation. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ include ':base' diff --git a/android/examples/DirectPairing/src/main/assets/oic_svr_db_client_directpairing.dat b/android/examples/DirectPairing/src/main/assets/oic_svr_db_client_directpairing.dat index 43b7a1c5c..146d24033 100644 Binary files a/android/examples/DirectPairing/src/main/assets/oic_svr_db_client_directpairing.dat and b/android/examples/DirectPairing/src/main/assets/oic_svr_db_client_directpairing.dat differ diff --git a/android/examples/cloudprovisioningclient/build.gradle b/android/examples/cloudprovisioningclient/build.gradle new file mode 100755 index 000000000..4e2bb4b05 --- /dev/null +++ b/android/examples/cloudprovisioningclient/build.gradle @@ -0,0 +1,37 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 21 + buildToolsVersion "20.0.0" + + defaultConfig { + applicationId "org.iotivity.base.examples.cloudprovisioningclient" + minSdkVersion 21 + targetSdkVersion 21 + versionCode 1 + versionName "1.0" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } + lintOptions { + abortOnError false + } +} +repositories { + flatDir { + dirs "../../android_api/base/build/outputs/aar/" + } +} + +try { + dependencies { + compile ":iotivity-base-${TARGET_ARCH}-${RELEASE}@aar" + } +} catch (all) { + print "${ERROR_MSG}" + assert all +} diff --git a/android/examples/cloudprovisioningclient/cloudprovisioningclient.iml b/android/examples/cloudprovisioningclient/cloudprovisioningclient.iml new file mode 100755 index 000000000..5d408e71d --- /dev/null +++ b/android/examples/cloudprovisioningclient/cloudprovisioningclient.iml @@ -0,0 +1,96 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/android/examples/cloudprovisioningclient/proguard-rules.pro b/android/examples/cloudprovisioningclient/proguard-rules.pro new file mode 100755 index 000000000..4fd6c9379 --- /dev/null +++ b/android/examples/cloudprovisioningclient/proguard-rules.pro @@ -0,0 +1,17 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in /home/sandeep/iot/android-sdk/android-sdk-linux/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/android/examples/cloudprovisioningclient/src/main/AndroidManifest.xml b/android/examples/cloudprovisioningclient/src/main/AndroidManifest.xml new file mode 100755 index 000000000..5de8a6ac5 --- /dev/null +++ b/android/examples/cloudprovisioningclient/src/main/AndroidManifest.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + diff --git a/android/examples/cloudprovisioningclient/src/main/assets/oic_svr_db_client.dat b/android/examples/cloudprovisioningclient/src/main/assets/oic_svr_db_client.dat new file mode 100755 index 000000000..4b5b91881 Binary files /dev/null and b/android/examples/cloudprovisioningclient/src/main/assets/oic_svr_db_client.dat differ diff --git a/android/examples/cloudprovisioningclient/src/main/assets/oic_svr_db_client.json b/android/examples/cloudprovisioningclient/src/main/assets/oic_svr_db_client.json new file mode 100755 index 000000000..09cc117b7 --- /dev/null +++ b/android/examples/cloudprovisioningclient/src/main/assets/oic_svr_db_client.json @@ -0,0 +1,82 @@ +{ + "acl": { + "aclist": { + "aces": [ + { + "subjectuuid": "*", + "resources": [ + { + "href": "/oic/res", + "rel": "", + "rt": ["oic.wk.res"], + "if": ["oic.if.ll"] + }, + { + "href": "/oic/d", + "rel": "", + "rt": ["oic.wk.d"], + "if": ["oic.if.baseline", "oic.if.r"] + }, + { + "href": "/oic/p", + "rel": "", + "rt": ["oic.wk.p"], + "if": ["oic.if.baseline", "oic.if.r"] + }, + { + "href": "/oic/ad", + "rel": "", + "rt": ["oic.wk.ad"], + "if": ["oic.if.baseline"] + }, + { + "href": "/oic/sec/amacl", + "rel": "", + "rt": ["oic.r.amacl"], + "if": ["oic.if.baseline"] + } + ], + "permission": 2 + }, + { + "subjectuuid": "*", + "resources": [ + { + "href": "/oic/sec/doxm", + "rel": "", + "rt": ["oic.r.doxm"], + "if": ["oic.if.baseline"] + }, + { + "href": "/oic/sec/pstat", + "rel": "", + "rt": ["oic.r.pstat"], + "if": ["oic.if.baseline"] + } + ], + "permission": 2 + } + ] + }, + "rowneruuid" : "61646D69-6E44-6576-6963-655575696430" + }, + "pstat": { + "isop": true, + "cm": 2, + "tm": 0, + "om": 3, + "sm": 3, + "deviceuuid": "61646D69-6E44-6576-6963-655575696430", + "rowneruuid": "61646D69-6E44-6576-6963-655575696430" + }, + "doxm": { + "oxms": [0], + "oxmsel": 0, + "sct": 1, + "owned": true, + "deviceuuid": "61646D69-6E44-6576-6963-655575696430", + "x.org.iotivity.dpc": false, + "devowneruuid": "61646D69-6E44-6576-6963-655575696430", + "rowneruuid": "61646D69-6E44-6576-6963-655575696430" + } +} diff --git a/android/examples/cloudprovisioningclient/src/main/java/org/iotivity/base/examples/cloudprovisioningclient/CloudProvisioningClient.java b/android/examples/cloudprovisioningclient/src/main/java/org/iotivity/base/examples/cloudprovisioningclient/CloudProvisioningClient.java new file mode 100755 index 000000000..3475d7f82 --- /dev/null +++ b/android/examples/cloudprovisioningclient/src/main/java/org/iotivity/base/examples/cloudprovisioningclient/CloudProvisioningClient.java @@ -0,0 +1,666 @@ +/* + * ****************************************************************** + * + * Copyright 2016 Samsung Electronics All Rights Reserved. + * + * -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + */ +package org.iotivity.base.examples.cloudprovisioningclient; + +import android.app.Activity; +import android.app.AlertDialog; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; +import android.content.SharedPreferences; +import android.os.Bundle; +import android.os.Message; +import android.preference.PreferenceManager; +import android.util.Log; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.LinearLayout; +import android.widget.TextView; + +import org.iotivity.base.ErrorCode; +import org.iotivity.base.ModeType; +import org.iotivity.base.OcAccountManager; +import org.iotivity.base.OcCloudProvisioning; +import org.iotivity.base.OcConnectivityType; +import org.iotivity.base.OcException; +import org.iotivity.base.OcHeaderOption; +import org.iotivity.base.OcPlatform; +import org.iotivity.base.OcProvisioning; +import org.iotivity.base.OcRepresentation; +import org.iotivity.base.PlatformConfig; +import org.iotivity.base.QualityOfService; +import org.iotivity.base.ServiceType; +import org.iotivity.base.examples.cloudprovisioningclient.R; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.EnumSet; +import java.util.List; + +public class CloudProvisioningClient extends Activity implements OcAccountManager.OnPostListener { + + private static final String TAG = "Cloud Provisioning Client: "; + OcAccountManager.OnPostListener onSignUp = new OcAccountManager.OnPostListener() { + @Override + public synchronized void onPostCompleted(List list, + OcRepresentation ocRepresentation) { + logMessage("signUp was successful"); + try { + String mUserUuid = ocRepresentation.getValue("uid"); + String mAccesstoken = ocRepresentation.getValue("accesstoken"); + + String mRefreshtoken = ocRepresentation.getValue("refreshtoken"); + String tokenType = ocRepresentation.getValue("tokentype"); + + SharedPreferences.Editor editor = settingPreference.edit(); + editor.putString("useruuid", mUserUuid); + editor.putString("accesstoken", mAccesstoken); + editor.commit(); + + logMessage("\tuserID: " + mUserUuid); + logMessage("\taccessToken: " + mAccesstoken); + logMessage("\trefreshToken: " + mRefreshtoken); + logMessage("\ttokenType: " + tokenType); + + if (ocRepresentation.hasAttribute("expiresin")) { + int expiresIn = ocRepresentation.getValue("expiresin"); + logMessage("\texpiresIn: " + expiresIn); + } + + runOnUiThread(new Runnable() { + @Override + public void run() { + signupLyt.setVisibility(View.GONE); + signinLyt.setVisibility(View.VISIBLE); + } + }); + + + } catch (OcException e) { + Log.e(TAG, e.toString()); + } + } + + + @Override + public synchronized void onPostFailed(Throwable throwable) { + logMessage("Failed to signUp"); + if (throwable instanceof OcException) { + OcException ocEx = (OcException) throwable; + Log.e(TAG, ocEx.toString()); + ErrorCode errCode = ocEx.getErrorCode(); + logMessage("Error code: " + errCode); + } + } + }; + OcAccountManager.OnPostListener onSignIn = new OcAccountManager.OnPostListener() { + @Override + public synchronized void onPostCompleted(List list, + OcRepresentation ocRepresentation) { + logMessage("signIn was successful"); + runOnUiThread(new Runnable() { + @Override + public void run() { + signinLyt.setVisibility(View.GONE); + userid.setText(settingPreference.getString("useruuid", "")); + lyt1.setVisibility(View.VISIBLE); + lyt2.setVisibility(View.VISIBLE); + } + }); + + + } + + @Override + public synchronized void onPostFailed(Throwable throwable) { + logMessage("Failed to signIn"); + if (throwable instanceof OcException) { + OcException ocEx = (OcException) throwable; + Log.e(TAG, ocEx.toString()); + ErrorCode errCode = ocEx.getErrorCode(); + logMessage("Error code: " + errCode); + } + } + }; + OcCloudProvisioning.GetIndividualAclInfoListener getIndividualAclInfoListener = + new OcCloudProvisioning.GetIndividualAclInfoListener() { + @Override + public void getIndividualAclInfoListener(boolean result) { + Log.d(TAG, "Inside getIndividualAclInfoListener "); + if (!result) { + logMessage("Individual ACL Info Successfull !!"); + } else { + logMessage("Error: Individual ACL Info failed !!"); + } + } + }; + OcCloudProvisioning.RequestCertificateListener requestCertificateListener = + new OcCloudProvisioning.RequestCertificateListener() { + @Override + public void requestCertificateListener(boolean result) { + Log.d(TAG, "Inside requestCertificateListener "); + if (!result) { + logMessage("Request certificate Successfull !!"); + } else { + logMessage("Error: Request certificate failed !!"); + } + } + }; + OcCloudProvisioning.GetCRLListener getCRLListener = + new OcCloudProvisioning.GetCRLListener() { + @Override + public void getCRLListener(boolean result) { + Log.d(TAG, "Inside getCRLListener "); + if (!result) { + logMessage("Get CRL Successfull !!"); + } else { + logMessage("Error: Get CRL failed !!"); + } + } + }; + OcCloudProvisioning.PostCRLListener postCRLListener = + new OcCloudProvisioning.PostCRLListener() { + @Override + public void postCRLListener(boolean result) { + Log.d(TAG, "Inside postCRLListener "); + if (!result) { + logMessage("Post CRL Successfull !!"); + } else { + logMessage("Error: Post CRL failed !!"); + } + } + }; + private static final int BUFFER_SIZE = 1024; + private final int REQUEST_LOGIN = 1; + Button signUp, signIn, signOut, getAclId, getAclInfo, requestCert, postCrl, getCrl; + TextView userid; + LinearLayout lyt1, lyt2, signupLyt, signinLyt; + // private TextView eventView; + SharedPreferences settingPreference; + OcCloudProvisioning ocCloudProvisioning; + String acl_Id; + OcCloudProvisioning.GetAclIdByDeviceListener getAclIdByDeviceListener = + new OcCloudProvisioning.GetAclIdByDeviceListener() { + @Override + public void getAclIdByDeviceListener(boolean result, String aclId) { + Log.d(TAG, "Inside getAclIdByDeviceListener "); + if (!result) { + acl_Id = aclId; + logMessage("Acl Id by device !!" + acl_Id); + } else { + logMessage("Error: Acl Id by device failed !!"); + } + } + }; + private OcAccountManager mAccountManager; + private String filePath = ""; + private TextView mEventsTextView; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.main_activity); + + signUp = (Button) findViewById(R.id.signup); + signIn = (Button) findViewById(R.id.signin); + signOut = (Button) findViewById(R.id.signout); + getAclId = (Button) findViewById(R.id.getAclId); + getAclInfo = (Button) findViewById(R.id.getAclInfo); + requestCert = (Button) findViewById(R.id.request); + postCrl = (Button) findViewById(R.id.postCRL); + getCrl = (Button) findViewById(R.id.getCRL); + + lyt1 = (LinearLayout) findViewById(R.id.lyt1); + lyt2 = (LinearLayout) findViewById(R.id.lyt2); + signupLyt = (LinearLayout) findViewById(R.id.signupLyt); + signinLyt = (LinearLayout) findViewById(R.id.signinLyt); + + + userid = (TextView) findViewById(R.id.userid); + + mEventsTextView = (TextView) findViewById(R.id.eventView); + + filePath = getFilesDir().getPath() + "/"; // data/data//files/ + //copy CBOR file when application runs first time + settingPreference = PreferenceManager.getDefaultSharedPreferences(this); + boolean isFirstRun = settingPreference.getBoolean("FIRSTRUN", true); + if (isFirstRun) { + copyCborFromAsset(); + SharedPreferences.Editor editor = settingPreference.edit(); + editor.putBoolean("FIRSTRUN", false); + editor.putString("IP", StringConstants.DEFAULT_COAP_DERVER_IP); + editor.putString("PORT", StringConstants.DEFAULT_COAP_DERVER_PORT); + editor.putString("DEVICEID", StringConstants.DEFAULT_DEVICE_ID); + editor.commit(); + } + if (settingPreference.getString("useruuid", "").equals("")) { + + lyt1.setVisibility(View.GONE); + lyt2.setVisibility(View.GONE); + signupLyt.setVisibility(View.VISIBLE); + signinLyt.setVisibility(View.GONE); + + + } else { + userid.setText(settingPreference.getString("useruuid", "")); + lyt1.setVisibility(View.VISIBLE); + lyt2.setVisibility(View.VISIBLE); + signupLyt.setVisibility(View.GONE); + signinLyt.setVisibility(View.VISIBLE); + } + + initOICStack(); + ocCloudProvisioning = new OcCloudProvisioning(settingPreference.getString("IP", ""), + Integer.valueOf(settingPreference.getString("PORT", ""))); + + signUp.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + signUp(); + } + }); + signIn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + signIn(); + } + }); + signOut.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + signOut(); + } + }); + getAclId.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + getAclId(); + } + }); + getAclInfo.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + getAclInfo(); + } + }); + requestCert.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + requestCert(); + } + }); + postCrl.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + postCrl(); + } + }); + getCrl.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + getCrl(); + } + }); + } + + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + // Inflate the menu; this adds items to the action bar if it is present. + getMenuInflater().inflate(R.menu.menu_cloud_provision, menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.action_settings: + setDefualtSettings(); + return (true); + + + } + return (super.onOptionsItemSelected(item)); + } + + private void signIn() { + try { + logMessage("signIn"); + if(mAccountManager==null) + { + mAccountManager = OcPlatform.constructAccountManagerObject( + StringConstants.COAP_TCP + settingPreference.getString("IP", + StringConstants.DEFAULT_COAP_DERVER_IP) + ":" + + settingPreference.getString("PORT", StringConstants.DEFAULT_COAP_DERVER_PORT), + EnumSet.of(OcConnectivityType.CT_ADAPTER_TCP)); + } + + mAccountManager.signIn(settingPreference.getString("useruuid", ""), + settingPreference.getString("accesstoken", ""), onSignIn); + } catch (OcException e) { + e.printStackTrace(); + } + } + + private void signOut() { + try { + logMessage("signOut"); + if(mAccountManager==null) + { + mAccountManager = OcPlatform.constructAccountManagerObject( + StringConstants.COAP_TCP + settingPreference.getString("IP", + StringConstants.DEFAULT_COAP_DERVER_IP) + ":" + + settingPreference.getString("PORT", StringConstants.DEFAULT_COAP_DERVER_PORT), + EnumSet.of(OcConnectivityType.CT_ADAPTER_TCP)); + } + + mAccountManager.signOut(CloudProvisioningClient.this); + lyt1.setVisibility(View.GONE); + lyt2.setVisibility(View.GONE); + signinLyt.setVisibility(View.VISIBLE); + } catch (OcException e) { + e.printStackTrace(); + } + } + + + private void getAclId() { + try { + logMessage("getAclId"); + logMessage("\tdeviceId= " + settingPreference.getString("DEVICEID", "")); + ocCloudProvisioning.getAclIdByDevice(settingPreference.getString("DEVICEID", ""), getAclIdByDeviceListener); + } catch (OcException e) { + e.printStackTrace(); + } + } + + private void getAclInfo() { + try { + logMessage("getAclInfo"); + logMessage("\taclid="+acl_Id); + ocCloudProvisioning.getIndividualAclInfo(acl_Id, getIndividualAclInfoListener); + + } catch (OcException e) { + e.printStackTrace(); + } + } + + private void requestCert() { + try { + logMessage("requestCert"); + ocCloudProvisioning = new OcCloudProvisioning(settingPreference.getString("IP", ""), + Integer.valueOf(settingPreference.getString("PORT", ""))); + ocCloudProvisioning.requestCertificate(requestCertificateListener); + + } catch (OcException e) { + e.printStackTrace(); + } + } + + private void postCrl() { + try { + logMessage("postCrl"); + ArrayList arrayList = new ArrayList<>(); + arrayList.add("1234"); + + ocCloudProvisioning.postCRL("20160727000000", "20161027000000", null, arrayList, postCRLListener); + + } catch (OcException e) { + e.printStackTrace(); + } + } + + private void getCrl() { + try { + logMessage("getCrl"); + ocCloudProvisioning.getCRL(getCRLListener); + + } catch (OcException e) { + e.printStackTrace(); + } + } + + private void signUp() { + try { + mAccountManager = OcPlatform.constructAccountManagerObject( + StringConstants.COAP_TCP + settingPreference.getString("IP", + StringConstants.DEFAULT_COAP_DERVER_IP) + settingPreference.getString("PORT", + StringConstants.DEFAULT_COAP_DERVER_PORT), + EnumSet.of(OcConnectivityType.CT_ADAPTER_TCP)); + logMessage(StringConstants.COAP_TCP + settingPreference.getString("IP", + StringConstants.DEFAULT_COAP_DERVER_IP) + settingPreference.getString("PORT", + StringConstants.DEFAULT_COAP_DERVER_PORT)); + } catch (OcException e) { + e.printStackTrace(); + } + + Intent intentLogin = new Intent(this, LoginActivity.class); + startActivityForResult(intentLogin, REQUEST_LOGIN); + } + + + /** + * configure OIC platform and call findResource + */ + private void initOICStack() { + //create platform config + PlatformConfig cfg = new PlatformConfig( + this, + ServiceType.IN_PROC, + ModeType.CLIENT_SERVER, + "0.0.0.0", // bind to all available interfaces + 0, + QualityOfService.LOW, filePath + StringConstants.OIC_CLIENT_CBOR_DB_FILE); + OcPlatform.Configure(cfg); + try { + /* + * Initialize DataBase + */ + String sqlDbPath = getFilesDir().getAbsolutePath().replace("files", "databases") + + File.separator; + File file = new File(sqlDbPath); + //check files directory exists + if (!(file.isDirectory())) { + file.mkdirs(); + Log.d(TAG, "Sql db directory created at " + sqlDbPath); + } + Log.d(TAG, "Sql db directory exists at " + sqlDbPath); + OcProvisioning.provisionInit(sqlDbPath + StringConstants.OIC_SQL_DB_FILE); + } catch (OcException e) { + logMessage(TAG + "provisionInit error: " + e.getMessage()); + Log.e(TAG, e.getMessage()); + } + } + + @Override + public void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + if (resultCode == Activity.RESULT_OK && requestCode == REQUEST_LOGIN) { + String mAuthCode = data.getStringExtra("authCode"); + + + logMessage("\tauthCode: " + mAuthCode); + + try { + logMessage("Sign Up"); + mAccountManager = OcPlatform.constructAccountManagerObject( + StringConstants.COAP_TCP + settingPreference.getString("IP", + StringConstants.DEFAULT_COAP_DERVER_IP) + ":" + + settingPreference.getString("PORT", StringConstants.DEFAULT_COAP_DERVER_PORT), + EnumSet.of(OcConnectivityType.CT_ADAPTER_TCP)); + + mAccountManager.signUp("github", mAuthCode, onSignUp); + } catch (OcException e) { + e.printStackTrace(); + } + } + } + + + /** + * Copy svr db CBOR dat file from assets folder to app data files dir + */ + private void copyCborFromAsset() { + InputStream inputStream = null; + OutputStream outputStream = null; + int length; + byte[] buffer = new byte[BUFFER_SIZE]; + try { + inputStream = getAssets().open(StringConstants.OIC_CLIENT_CBOR_DB_FILE); + File file = new File(filePath); + //check files directory exists + if (!(file.exists() && file.isDirectory())) { + file.mkdirs(); + } + outputStream = new FileOutputStream(filePath + StringConstants.OIC_CLIENT_CBOR_DB_FILE); + while ((length = inputStream.read(buffer)) != -1) { + outputStream.write(buffer, 0, length); + } + } catch (NullPointerException e) { + logMessage(TAG + "Null pointer exception " + e.getMessage()); + Log.e(TAG, e.getMessage()); + } catch (FileNotFoundException e) { + logMessage(TAG + "CBOR svr db file not found " + e.getMessage()); + Log.e(TAG, e.getMessage()); + } catch (IOException e) { + logMessage(TAG + StringConstants.OIC_CLIENT_CBOR_DB_FILE + " file copy failed"); + Log.e(TAG, e.getMessage()); + } finally { + if (inputStream != null) { + try { + inputStream.close(); + } catch (IOException e) { + Log.e(TAG, e.getMessage()); + } + } + if (outputStream != null) { + try { + outputStream.close(); + } catch (IOException e) { + Log.e(TAG, e.getMessage()); + } + } + } + } + + public void logMessage(String text) { + logMsg(text); + } + + public void logMsg(final String text) { + runOnUiThread(new Runnable() { + public void run() { + Message msg = new Message(); + msg.obj = text; + mEventsTextView.append(text); + mEventsTextView.append("\n"); + } + }); + Log.i(TAG, text); + Intent intent = new Intent(getPackageName()); + intent.putExtra(StringConstants.MESSAGE, text); + sendBroadcast(intent); + } + + + private void setDefualtSettings() { + View setingLayout = getLayoutInflater().inflate(R.layout.setting_layout, null); + + final EditText ip = (EditText) setingLayout.findViewById(R.id.ip); + final EditText port = (EditText) setingLayout.findViewById(R.id.port); + final EditText deviceId = (EditText) setingLayout.findViewById(R.id.deviceId); + + ip.setText(settingPreference.getString("IP", "")); + port.setText(settingPreference.getString("PORT", "")); + deviceId.setText(settingPreference.getString("DEVICEID", "")); + + + final AlertDialog.Builder builder = new AlertDialog.Builder(CloudProvisioningClient.this); + builder.setView(setingLayout); + builder.setPositiveButton("Submit", null).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + Log.d(TAG, "AlertDialog onClick"); + + } + }); + final AlertDialog alertDialog = builder.create(); + alertDialog.setMessage("Settings"); + alertDialog.show(); + alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + + String ip_address = ip.getText().toString(); + String port_num = port.getText().toString(); + String deviceId_val = deviceId.getText().toString(); + + SharedPreferences.Editor editor = settingPreference.edit(); + + editor.putString("IP", ip_address); + editor.putString("PORT", port_num); + editor.putString("DEVICEID", deviceId_val); + editor.commit(); + + alertDialog.cancel(); + } + }); + alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + + alertDialog.cancel(); + } + }); + + } + + @Override + public void onPostCompleted(List ocHeaderOptions, OcRepresentation ocRepresentation) { + + } + + @Override + public void onPostFailed(Throwable throwable) { + + } + + + /** + * to display on Server Message on Client screen + */ + public class MessageReceiver extends BroadcastReceiver { + @Override + public void onReceive(Context context, Intent intent) { + final String message = intent.getStringExtra(StringConstants.MESSAGE); + logMessage(message); + } + } +} diff --git a/android/examples/cloudprovisioningclient/src/main/java/org/iotivity/base/examples/cloudprovisioningclient/LoginActivity.java b/android/examples/cloudprovisioningclient/src/main/java/org/iotivity/base/examples/cloudprovisioningclient/LoginActivity.java new file mode 100755 index 000000000..09f808721 --- /dev/null +++ b/android/examples/cloudprovisioningclient/src/main/java/org/iotivity/base/examples/cloudprovisioningclient/LoginActivity.java @@ -0,0 +1,86 @@ +/* + * ****************************************************************** + * + * Copyright 2016 Samsung Electronics All Rights Reserved. + * + * -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + */ + +package org.iotivity.base.examples.cloudprovisioningclient; + +import android.app.Activity; +import android.content.Intent; +import android.net.UrlQuerySanitizer; +import android.os.Bundle; +import android.util.Log; +import android.view.View; +import android.webkit.WebView; +import android.webkit.WebViewClient; + +import org.iotivity.base.examples.cloudprovisioningclient.R; + +/** + * This class is for login to the provider. + * Can be get auth code via web page. + */ +public class LoginActivity extends Activity { + private static final String TAG = "OIC_SIMPLE_LOGIN"; + + private WebView mWebView = null; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_login); + + mWebView = (WebView) findViewById(R.id.webView); + mWebView.setInitialScale(200); + mWebView.getSettings().setJavaScriptEnabled(true); + mWebView.getSettings().setBuiltInZoomControls(true); + mWebView.setWebViewClient(new WebViewClientClass()); + + mWebView.loadUrl("https://github.com/login?return_to=%2Flogin%2Foauth" + + "%2Fauthorize%3Fclient_id%3Dea9c18f540323b0213d0%26redirect_uri" + + "%3Dhttp%253A%252F%252Fwww.example.com%252Foauth_callback%252F"); + } + + private class WebViewClientClass extends WebViewClient { + + @Override + public void onPageFinished(WebView view, String url) { + Log.i(TAG, "called url=" + url); + + if (url.contains("http://www.example.com/oauth_callback")) { + + mWebView.setVisibility(View.INVISIBLE); + + // parsing url + UrlQuerySanitizer sanitizer = new UrlQuerySanitizer(); + sanitizer.setAllowUnregisteredParamaters(true); + sanitizer.parseUrl(url); + + String mAuthCode = sanitizer.getValue("code"); + + Intent intent = getIntent(); + intent.putExtra("authCode", mAuthCode); + setResult(RESULT_OK, intent); + + finish(); + } + } + } +} diff --git a/android/examples/cloudprovisioningclient/src/main/java/org/iotivity/base/examples/cloudprovisioningclient/StringConstants.java b/android/examples/cloudprovisioningclient/src/main/java/org/iotivity/base/examples/cloudprovisioningclient/StringConstants.java new file mode 100755 index 000000000..18c4974fe --- /dev/null +++ b/android/examples/cloudprovisioningclient/src/main/java/org/iotivity/base/examples/cloudprovisioningclient/StringConstants.java @@ -0,0 +1,35 @@ +/* + * ****************************************************************** + * + * Copyright 2016 Samsung Electronics All Rights Reserved. + * + * -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + */ +package org.iotivity.base.examples.cloudprovisioningclient; + +public interface StringConstants { + + public static final String DEFAULT_DEVICE_ID = "9cfbeb8e-5a1e-4d1c-9d01-2ae6fdb"; + public static final String COAP_TCP = "coap+tcp://"; + public static final String DEFAULT_COAP_DERVER_IP = "107.109.229.111"; + public static final String DEFAULT_COAP_DERVER_PORT = "5684"; + + public static final String OIC_CLIENT_CBOR_DB_FILE = "oic_svr_db_client.dat"; + public static final String MESSAGE = "message"; + public static final String OIC_SQL_DB_FILE = "Pdm.db"; + +} diff --git a/android/examples/cloudprovisioningclient/src/main/res/drawable/dash_nil_border.xml b/android/examples/cloudprovisioningclient/src/main/res/drawable/dash_nil_border.xml new file mode 100755 index 000000000..be2775804 --- /dev/null +++ b/android/examples/cloudprovisioningclient/src/main/res/drawable/dash_nil_border.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/android/examples/cloudprovisioningclient/src/main/res/drawable/round_button.xml b/android/examples/cloudprovisioningclient/src/main/res/drawable/round_button.xml new file mode 100755 index 000000000..f4ccab0fb --- /dev/null +++ b/android/examples/cloudprovisioningclient/src/main/res/drawable/round_button.xml @@ -0,0 +1,8 @@ + + + + + + diff --git a/android/examples/cloudprovisioningclient/src/main/res/layout/activity_login.xml b/android/examples/cloudprovisioningclient/src/main/res/layout/activity_login.xml new file mode 100755 index 000000000..dfd8e3cc8 --- /dev/null +++ b/android/examples/cloudprovisioningclient/src/main/res/layout/activity_login.xml @@ -0,0 +1,16 @@ + + + + + + \ No newline at end of file diff --git a/android/examples/cloudprovisioningclient/src/main/res/layout/main_activity.xml b/android/examples/cloudprovisioningclient/src/main/res/layout/main_activity.xml new file mode 100755 index 000000000..3ce36d264 --- /dev/null +++ b/android/examples/cloudprovisioningclient/src/main/res/layout/main_activity.xml @@ -0,0 +1,207 @@ + + + + + + + + + + +