From: Sachin Agrawal Date: Wed, 15 Jul 2015 16:40:26 +0000 (-0700) Subject: Merge 'security-basecamp' branch into master with CBOR X-Git-Tag: 1.2.0+RC1~1461^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5afbbb1a9974d2fc1251fcab00c4100fb5ac4f3d;p=platform%2Fupstream%2Fiotivity.git Merge 'security-basecamp' branch into master with CBOR security-basecamp for 0.9.2 is merged in master brach. Change-Id: Ia5cd2710a688d3e631009ed03f7e5eb97aba5d24 Signed-off-by: Sachin Agrawal --- 5afbbb1a9974d2fc1251fcab00c4100fb5ac4f3d diff --cc android/android_api/base/jni/JniOcPlatform.cpp index 5dfe78b,10cde35..2023fa4 --- a/android/android_api/base/jni/JniOcPlatform.cpp +++ b/android/android_api/base/jni/JniOcPlatform.cpp @@@ -1,1814 -1,1512 +1,1823 @@@ - /* - * //****************************************************************** - * // - * // 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 "JniOcPlatform.h" - #include "OCPlatform.h" - #include "JniOcResource.h" - #include "JniOcResourceHandle.h" - #include "JniOcPresenceHandle.h" - #include "JniOcResourceResponse.h" - #include "JniUtils.h" - - using namespace OC; - - JniOnResourceFoundListener* AddOnResourceFoundListener(JNIEnv* env, jobject jListener) - { - JniOnResourceFoundListener *onResourceFoundListener = NULL; - - resourceFoundMapLock.lock(); - - for (auto it = onResourceFoundListenerMap.begin(); it != onResourceFoundListenerMap.end(); ++it) - { - if (env->IsSameObject(jListener, it->first)) - { - auto refPair = it->second; - onResourceFoundListener = refPair.first; - refPair.second++; - it->second = refPair; - onResourceFoundListenerMap.insert(*it); - LOGD("OnResourceFoundListener: ref. count incremented"); - break; - } - } - - if (!onResourceFoundListener) - { - onResourceFoundListener = new JniOnResourceFoundListener(env, jListener, RemoveOnResourceFoundListener); - jobject jgListener = env->NewGlobalRef(jListener); - - onResourceFoundListenerMap.insert(std::pair < jobject, std::pair < JniOnResourceFoundListener*, - int >> (jgListener, std::pair(onResourceFoundListener, 1))); - LOGD("OnResourceFoundListener: new listener"); - } - resourceFoundMapLock.unlock(); - return onResourceFoundListener; - } - - void RemoveOnResourceFoundListener(JNIEnv* env, jobject jListener) - { - resourceFoundMapLock.lock(); - - for (auto it = onResourceFoundListenerMap.begin(); it != onResourceFoundListenerMap.end(); ++it) - { - if (env->IsSameObject(jListener, it->first)) - { - auto refPair = it->second; - if (refPair.second > 1) - { - refPair.second--; - it->second = refPair; - onResourceFoundListenerMap.insert(*it); - LOGI("OnResourceFoundListener: ref. count decremented"); - } - else - { - env->DeleteGlobalRef(it->first); - JniOnResourceFoundListener* listener = refPair.first; - delete listener; - onResourceFoundListenerMap.erase(it); - LOGI("OnResourceFoundListener removed"); - } - break; - } - } - resourceFoundMapLock.unlock(); - } - - JniOnDeviceInfoListener* AddOnDeviceInfoListener(JNIEnv* env, jobject jListener) - { - JniOnDeviceInfoListener *onDeviceInfoListener = NULL; - - deviceInfoMapLock.lock(); - - for (auto it = onDeviceInfoListenerMap.begin(); it != onDeviceInfoListenerMap.end(); ++it) - { - if (env->IsSameObject(jListener, it->first)) - { - auto refPair = it->second; - onDeviceInfoListener = refPair.first; - refPair.second++; - it->second = refPair; - onDeviceInfoListenerMap.insert(*it); - LOGD("OnDeviceInfoListener: ref. count incremented"); - break; - } - } - - if (!onDeviceInfoListener) - { - onDeviceInfoListener = new JniOnDeviceInfoListener(env, jListener, RemoveOnDeviceInfoListener); - jobject jgListener = env->NewGlobalRef(jListener); - - onDeviceInfoListenerMap.insert(std::pair < jobject, std::pair < JniOnDeviceInfoListener*, - int >> (jgListener, std::pair(onDeviceInfoListener, 1))); - LOGI("OnDeviceInfoListener: new listener"); - } - - deviceInfoMapLock.unlock(); - return onDeviceInfoListener; - } - - void RemoveOnDeviceInfoListener(JNIEnv* env, jobject jListener) - { - deviceInfoMapLock.lock(); - bool isFound = false; - for (auto it = onDeviceInfoListenerMap.begin(); it != onDeviceInfoListenerMap.end(); ++it) - { - if (env->IsSameObject(jListener, it->first)) - { - auto refPair = it->second; - if (refPair.second > 1) - { - refPair.second--; - it->second = refPair; - onDeviceInfoListenerMap.insert(*it); - LOGI("OnDeviceInfoListener: ref. count decremented"); - } - else - { - env->DeleteGlobalRef(it->first); - JniOnDeviceInfoListener* listener = refPair.first; - delete listener; - onDeviceInfoListenerMap.erase(it); - - LOGI("OnDeviceInfoListener removed"); - } - - isFound = true; - break; - } - } - - if (!isFound) - { - ThrowOcException(JNI_EXCEPTION, "OnDeviceInfoListenet not found"); - } - deviceInfoMapLock.unlock(); + /* + * //****************************************************************** + * // + * // 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 "JniOcPlatform.h" + #include "OCPlatform.h" + #include "JniOcResource.h" + #include "JniOcResourceHandle.h" + #include "JniOcPresenceHandle.h" + #include "JniOcResourceResponse.h" + #include "JniOcSecurity.h" + #include "JniUtils.h" + + using namespace OC; + + JniOnResourceFoundListener* AddOnResourceFoundListener(JNIEnv* env, jobject jListener) + { + JniOnResourceFoundListener *onResourceFoundListener = NULL; + + resourceFoundMapLock.lock(); + + for (auto it = onResourceFoundListenerMap.begin(); it != onResourceFoundListenerMap.end(); ++it) + { + if (env->IsSameObject(jListener, it->first)) + { + auto refPair = it->second; + onResourceFoundListener = refPair.first; + refPair.second++; + it->second = refPair; + onResourceFoundListenerMap.insert(*it); + LOGD("OnResourceFoundListener: ref. count incremented"); + break; + } + } + + if (!onResourceFoundListener) + { + onResourceFoundListener = new JniOnResourceFoundListener(env, jListener, RemoveOnResourceFoundListener); + jobject jgListener = env->NewGlobalRef(jListener); + + onResourceFoundListenerMap.insert(std::pair < jobject, std::pair < JniOnResourceFoundListener*, + int >> (jgListener, std::pair(onResourceFoundListener, 1))); + LOGD("OnResourceFoundListener: new listener"); + } + resourceFoundMapLock.unlock(); + return onResourceFoundListener; + } + + void RemoveOnResourceFoundListener(JNIEnv* env, jobject jListener) + { + resourceFoundMapLock.lock(); + + for (auto it = onResourceFoundListenerMap.begin(); it != onResourceFoundListenerMap.end(); ++it) + { + if (env->IsSameObject(jListener, it->first)) + { + auto refPair = it->second; + if (refPair.second > 1) + { + refPair.second--; + it->second = refPair; + onResourceFoundListenerMap.insert(*it); + LOGI("OnResourceFoundListener: ref. count decremented"); + } + else + { + env->DeleteGlobalRef(it->first); + JniOnResourceFoundListener* listener = refPair.first; + delete listener; + onResourceFoundListenerMap.erase(it); + LOGI("OnResourceFoundListener removed"); + } + break; + } + } + resourceFoundMapLock.unlock(); + } + + JniOnDeviceInfoListener* AddOnDeviceInfoListener(JNIEnv* env, jobject jListener) + { + JniOnDeviceInfoListener *onDeviceInfoListener = NULL; + + deviceInfoMapLock.lock(); + + for (auto it = onDeviceInfoListenerMap.begin(); it != onDeviceInfoListenerMap.end(); ++it) + { + if (env->IsSameObject(jListener, it->first)) + { + auto refPair = it->second; + onDeviceInfoListener = refPair.first; + refPair.second++; + it->second = refPair; + onDeviceInfoListenerMap.insert(*it); + LOGD("OnDeviceInfoListener: ref. count incremented"); + break; + } + } + + if (!onDeviceInfoListener) + { + onDeviceInfoListener = new JniOnDeviceInfoListener(env, jListener, RemoveOnDeviceInfoListener); + jobject jgListener = env->NewGlobalRef(jListener); + + onDeviceInfoListenerMap.insert(std::pair < jobject, std::pair < JniOnDeviceInfoListener*, + int >> (jgListener, std::pair(onDeviceInfoListener, 1))); + LOGI("OnDeviceInfoListener: new listener"); + } + + deviceInfoMapLock.unlock(); + return onDeviceInfoListener; + } + + void RemoveOnDeviceInfoListener(JNIEnv* env, jobject jListener) + { + deviceInfoMapLock.lock(); + bool isFound = false; + for (auto it = onDeviceInfoListenerMap.begin(); it != onDeviceInfoListenerMap.end(); ++it) + { + if (env->IsSameObject(jListener, it->first)) + { + auto refPair = it->second; + if (refPair.second > 1) + { + refPair.second--; + it->second = refPair; + onDeviceInfoListenerMap.insert(*it); + LOGI("OnDeviceInfoListener: ref. count decremented"); + } + else + { + env->DeleteGlobalRef(it->first); + JniOnDeviceInfoListener* listener = refPair.first; + delete listener; + onDeviceInfoListenerMap.erase(it); + + LOGI("OnDeviceInfoListener removed"); + } + + isFound = true; + break; + } + } + + if (!isFound) + { + ThrowOcException(JNI_EXCEPTION, "OnDeviceInfoListenet not found"); + } + deviceInfoMapLock.unlock(); +} + +JniOnPlatformInfoListener* AddOnPlatformInfoListener(JNIEnv* env, jobject jListener) +{ + JniOnPlatformInfoListener *onPlatformInfoListener = NULL; + + platformInfoMapLock.lock(); + + for (auto it = onPlatformInfoListenerMap.begin(); it != onPlatformInfoListenerMap.end(); ++it) + { + if (env->IsSameObject(jListener, it->first)) + { + auto refPair = it->second; + onPlatformInfoListener = refPair.first; + refPair.second++; + it->second = refPair; + onPlatformInfoListenerMap.insert(*it); + LOGD("OnPlatformInfoListener: ref. count incremented"); + break; + } + } + + if (!onPlatformInfoListener) + { + onPlatformInfoListener = new JniOnPlatformInfoListener(env, jListener, RemoveOnPlatformInfoListener); + jobject jgListener = env->NewGlobalRef(jListener); + + onPlatformInfoListenerMap.insert(std::pair < jobject, std::pair < JniOnPlatformInfoListener*, + int >> (jgListener, std::pair(onPlatformInfoListener, 1))); + LOGI("OnPlatformInfoListener: new listener"); + } + + platformInfoMapLock.unlock(); + return onPlatformInfoListener; +} + +void RemoveOnPlatformInfoListener(JNIEnv* env, jobject jListener) +{ + platformInfoMapLock.lock(); + bool isFound = false; + for (auto it = onPlatformInfoListenerMap.begin(); it != onPlatformInfoListenerMap.end(); ++it) + { + if (env->IsSameObject(jListener, it->first)) + { + auto refPair = it->second; + if (refPair.second > 1) + { + refPair.second--; + it->second = refPair; + onPlatformInfoListenerMap.insert(*it); + LOGI("OnPlatformInfoListener: ref. count decremented"); + } + else + { + env->DeleteGlobalRef(it->first); + JniOnPlatformInfoListener* listener = refPair.first; + delete listener; + onPlatformInfoListenerMap.erase(it); + + LOGI("OnPlatformInfoListener removed"); + } + + isFound = true; + break; + } + } + + if (!isFound) + { + ThrowOcException(JNI_EXCEPTION, "OnPlatformInfoListenet not found"); + } + platformInfoMapLock.unlock(); - } - - JniOnPresenceListener* AddOnPresenceListener(JNIEnv* env, jobject jListener) - { - JniOnPresenceListener *onPresenceListener = NULL; - - presenceMapLock.lock(); - - for (auto it = onPresenceListenerMap.begin(); it != onPresenceListenerMap.end(); ++it) - { - if (env->IsSameObject(jListener, it->first)) - { - auto refPair = it->second; - onPresenceListener = refPair.first; - refPair.second++; - it->second = refPair; - onPresenceListenerMap.insert(*it); - LOGD("OnPresenceListener: ref. count incremented"); - break; - } - } - if (!onPresenceListener) - { - onPresenceListener = new JniOnPresenceListener(env, jListener, RemoveOnPresenceListener); - jobject jgListener = env->NewGlobalRef(jListener); - onPresenceListenerMap.insert(std::pair < jobject, std::pair < JniOnPresenceListener*, - int >> (jgListener, std::pair(onPresenceListener, 1))); - LOGI("OnPresenceListener: new listener"); - } - presenceMapLock.unlock(); - return onPresenceListener; - } - - void RemoveOnPresenceListener(JNIEnv* env, jobject jListener) - { - presenceMapLock.lock(); - bool isFound = false; - for (auto it = onPresenceListenerMap.begin(); it != onPresenceListenerMap.end(); ++it) - { - if (env->IsSameObject(jListener, it->first)) - { - auto refPair = it->second; - if (refPair.second > 1) - { - refPair.second--; - it->second = refPair; - onPresenceListenerMap.insert(*it); - LOGI("OnPresenceListener: ref. count decremented"); - } - else - { - env->DeleteGlobalRef(it->first); - JniOnPresenceListener* listener = refPair.first; - delete listener; - onPresenceListenerMap.erase(it); - LOGI("OnPresenceListener is removed"); - } - isFound = true; - break; - } - } - if (!isFound) - { - ThrowOcException(JNI_EXCEPTION, "OnPresenceListener not found"); - } - presenceMapLock.unlock(); - } - - /* - * Class: org_iotivity_base_OcPlatform - * Method: configure - * Signature: (IILjava/lang/String;II)V - */ - JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_configure - (JNIEnv *env, jclass clazz, jint jServiceType, jint jModeType, jstring jIpAddress, jint jPort, jint jQOS) - { - LOGI("OcPlatform_configure"); - - std::string ipAddress; - if (jIpAddress) - { - ipAddress = env->GetStringUTFChars(jIpAddress, NULL); - } - uint16_t port; - if (jPort > 0) - { - port = static_cast(jPort); - } - PlatformConfig cfg{ - JniUtils::getServiceType(env, jServiceType), - JniUtils::getModeType(env, jModeType), - ipAddress, - port, - JniUtils::getQOS(env, static_cast(jQOS)) - }; - - OCPlatform::Configure(cfg); - } - - /* - * Class: org_iotivity_base_OcPlatform - * Method: notifyAllObservers0 - * Signature: (Lorg/iotivity/base/OcResourceHandle;)V - */ - JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_notifyAllObservers0 - (JNIEnv *env, jclass clazz, jobject jResourceHandle) - { - LOGI("OcPlatform_notifyAllObservers"); - if (!jResourceHandle) - { - ThrowOcException(OC_STACK_INVALID_PARAM, "resourceHandle cannot be null"); - return; - } - - JniOcResourceHandle* jniOcResourceHandle = JniOcResourceHandle::getJniOcResourceHandlePtr( - env, jResourceHandle); - if (!jniOcResourceHandle) return; - - try - { - OCStackResult result = OCPlatform::notifyAllObservers(jniOcResourceHandle->getOCResourceHandle()); - - if (OC_STACK_OK != result) - { - ThrowOcException(result, "Failed to notify all observers"); - return; - } - } - catch (OCException& e) - { - LOGE("%s", e.reason().c_str()); - ThrowOcException(OC_STACK_ERROR, e.reason().c_str()); - } - } - - /* - * Class: org_iotivity_base_OcPlatform - * Method: notifyAllObservers1 - * Signature: (Lorg/iotivity/base/OcResourceHandle;I)V - */ - JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_notifyAllObservers1 - (JNIEnv *env, jclass clazz, jobject jResourceHandle, jint jQoS) - { - LOGI("OcPlatform_notifyAllObservers1"); - - if (!jResourceHandle) - { - ThrowOcException(OC_STACK_INVALID_PARAM, "resourceHandle cannot be null"); - return; - } - - JniOcResourceHandle* jniOcResourceHandle = JniOcResourceHandle::getJniOcResourceHandlePtr( - env, jResourceHandle); - if (!jniOcResourceHandle) return; - - try{ - OCStackResult result = OCPlatform::notifyAllObservers( - jniOcResourceHandle->getOCResourceHandle(), - JniUtils::getQOS(env, static_cast(jQoS))); - - if (OC_STACK_OK != result) - { - ThrowOcException(result, "Failed to notify all observers"); - return; + } + + JniOnPresenceListener* AddOnPresenceListener(JNIEnv* env, jobject jListener) + { + JniOnPresenceListener *onPresenceListener = NULL; + + presenceMapLock.lock(); + + for (auto it = onPresenceListenerMap.begin(); it != onPresenceListenerMap.end(); ++it) + { + if (env->IsSameObject(jListener, it->first)) + { + auto refPair = it->second; + onPresenceListener = refPair.first; + refPair.second++; + it->second = refPair; + onPresenceListenerMap.insert(*it); + LOGD("OnPresenceListener: ref. count incremented"); + break; + } + } + if (!onPresenceListener) + { + onPresenceListener = new JniOnPresenceListener(env, jListener, RemoveOnPresenceListener); + jobject jgListener = env->NewGlobalRef(jListener); + onPresenceListenerMap.insert(std::pair < jobject, std::pair < JniOnPresenceListener*, + int >> (jgListener, std::pair(onPresenceListener, 1))); + LOGI("OnPresenceListener: new listener"); + } + presenceMapLock.unlock(); + return onPresenceListener; + } + + void RemoveOnPresenceListener(JNIEnv* env, jobject jListener) + { + presenceMapLock.lock(); + bool isFound = false; + for (auto it = onPresenceListenerMap.begin(); it != onPresenceListenerMap.end(); ++it) + { + if (env->IsSameObject(jListener, it->first)) + { + auto refPair = it->second; + if (refPair.second > 1) + { + refPair.second--; + it->second = refPair; + onPresenceListenerMap.insert(*it); + LOGI("OnPresenceListener: ref. count decremented"); + } + else + { + env->DeleteGlobalRef(it->first); + JniOnPresenceListener* listener = refPair.first; + delete listener; + onPresenceListenerMap.erase(it); + LOGI("OnPresenceListener is removed"); + } + isFound = true; + break; + } + } + if (!isFound) + { + ThrowOcException(JNI_EXCEPTION, "OnPresenceListener not found"); + } + presenceMapLock.unlock(); + } + + /* + * Class: org_iotivity_base_OcPlatform + * Method: configure -* Signature: (IILjava/lang/String;IILjava/lang/String;)V ++* Signature: (IILjava/lang/String;II)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_configure + (JNIEnv *env, jclass clazz, jint jServiceType, jint jModeType, jstring jIpAddress, jint jPort, + jint jQOS, jstring jDbPath) + { + LOGI("OcPlatform_configure"); + + std::string ipAddress; + std::string dbfile; + if (jIpAddress) + { + ipAddress = env->GetStringUTFChars(jIpAddress, NULL); + } + if (jDbPath) + { + dbfile = env->GetStringUTFChars(jDbPath, nullptr); + JniOcSecurity::StoreDbPath(dbfile); + } + uint16_t port; + if (jPort > 0) + { + port = static_cast(jPort); + } + PlatformConfig cfg{ + JniUtils::getServiceType(env, jServiceType), + JniUtils::getModeType(env, jModeType), + ipAddress, + port, + JniUtils::getQOS(env, static_cast(jQOS)), + JniOcSecurity::getOCPersistentStorage() + }; + + OCPlatform::Configure(cfg); + } + + /* + * Class: org_iotivity_base_OcPlatform + * Method: notifyAllObservers0 + * Signature: (Lorg/iotivity/base/OcResourceHandle;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_notifyAllObservers0 + (JNIEnv *env, jclass clazz, jobject jResourceHandle) + { + LOGI("OcPlatform_notifyAllObservers"); + if (!jResourceHandle) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "resourceHandle cannot be null"); + return; + } + + JniOcResourceHandle* jniOcResourceHandle = JniOcResourceHandle::getJniOcResourceHandlePtr( + env, jResourceHandle); + if (!jniOcResourceHandle) return; + + try + { + OCStackResult result = OCPlatform::notifyAllObservers(jniOcResourceHandle->getOCResourceHandle()); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "Failed to notify all observers"); + return; + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(OC_STACK_ERROR, e.reason().c_str()); + } + } + + /* + * Class: org_iotivity_base_OcPlatform + * Method: notifyAllObservers1 + * Signature: (Lorg/iotivity/base/OcResourceHandle;I)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_notifyAllObservers1 + (JNIEnv *env, jclass clazz, jobject jResourceHandle, jint jQoS) + { + LOGI("OcPlatform_notifyAllObservers1"); + + if (!jResourceHandle) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "resourceHandle cannot be null"); + return; + } + + JniOcResourceHandle* jniOcResourceHandle = JniOcResourceHandle::getJniOcResourceHandlePtr( + env, jResourceHandle); + if (!jniOcResourceHandle) return; + + try{ + OCStackResult result = OCPlatform::notifyAllObservers( + jniOcResourceHandle->getOCResourceHandle(), + JniUtils::getQOS(env, static_cast(jQoS))); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "Failed to notify all observers"); + return; + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(OC_STACK_ERROR, e.reason().c_str()); + } + } + + /* + * Class: org_iotivity_base_OcPlatform + * Method: notifyListOfObservers2 + * Signature: (Lorg/iotivity/base/OcResourceHandle;[Ljava/lang/Byte;Lorg/iotivity/base/OcResourceResponse;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_notifyListOfObservers2 + (JNIEnv *env, jclass clazz, jobject jResourceHandle, jbyteArray jObservationIdArr, jobject jResourceResponse) + { + LOGD("OcPlatform_notifyListOfObservers2"); + if (!jResourceHandle) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "resourceHandle cannot be null"); + return; + } + if (!jObservationIdArr) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "observationIdList cannot be null"); + return; + } + if (!jResourceResponse) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "resourceResponse cannot be null"); + return; + } + + JniOcResourceHandle* jniOcResourceHandle = JniOcResourceHandle::getJniOcResourceHandlePtr( + env, jResourceHandle); + if (!jniOcResourceHandle) return; + + JniOcResourceResponse* jniOcResourceResponse = JniOcResourceResponse::getJniOcResourceResponsePtr( + env, jResourceResponse); + if (!jniOcResourceResponse) return; + + int len = env->GetArrayLength(jObservationIdArr); + uint8_t* bArr = (uint8_t*)env->GetByteArrayElements(jObservationIdArr, 0); + + ObservationIds observationIds; + for (int i = 0; i < len; ++i) + { + observationIds.push_back(bArr[i]); + } + + env->ReleaseByteArrayElements(jObservationIdArr, (jbyte*)bArr, 0); + + try{ + OCStackResult result = OCPlatform::notifyListOfObservers( + jniOcResourceHandle->getOCResourceHandle(), + observationIds, + jniOcResourceResponse->getOCResourceResponse()); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "Failed to notify all observers"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(OC_STACK_ERROR, e.reason().c_str()); + } + } + + /* + * Class: org_iotivity_base_OcPlatform + * Method: notifyListOfObservers3 + * Signature: (Lorg/iotivity/base/OcResourceHandle;[Ljava/lang/Byte;Lorg/iotivity/base/OcResourceResponse;I)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_notifyListOfObservers3 + (JNIEnv *env, jclass clazz, jobject jResourceHandle, jbyteArray jObservationIdArr, jobject jResourceResponse, jint jQoS) + { + LOGD("OcPlatform_notifyListOfObservers3"); + if (!jResourceHandle) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "resourceHandle cannot be null"); + return; + } + if (!jObservationIdArr) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "observationIdList cannot be null"); + return; + } + if (!jResourceResponse) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "resourceResponse cannot be null"); + return; + } + + JniOcResourceHandle* jniOcResourceHandle = JniOcResourceHandle::getJniOcResourceHandlePtr( + env, jResourceHandle); + if (!jniOcResourceHandle) return; + + JniOcResourceResponse* jniOcResourceResponse = JniOcResourceResponse::getJniOcResourceResponsePtr( + env, jResourceResponse); + if (!jniOcResourceResponse) return; + + int len = env->GetArrayLength(jObservationIdArr); + uint8_t* bArr = (uint8_t*)env->GetByteArrayElements(jObservationIdArr, 0); + + ObservationIds observationIds; + for (int i = 0; i < len; ++i) + { + observationIds.push_back(bArr[i]); + } + + env->ReleaseByteArrayElements(jObservationIdArr, (jbyte*)bArr, 0); + + try{ + OCStackResult result = OCPlatform::notifyListOfObservers( + jniOcResourceHandle->getOCResourceHandle(), + observationIds, + jniOcResourceResponse->getOCResourceResponse(), + JniUtils::getQOS(env, static_cast(jQoS))); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "Failed to notify all observers"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(OC_STACK_ERROR, e.reason().c_str()); + } + } + + /* + * Class: org_iotivity_base_OcPlatform + * Method: findResource0 + * Signature: (Ljava/lang/String;Ljava/lang/String;ILorg/iotivity/base/OcPlatform/OnResourceFoundListener;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_findResource0 + (JNIEnv *env, jclass clazz, jstring jHost, jstring jResourceUri, jint jConnectivityType, jobject jListener) + { + LOGD("OcPlatform_findResource"); + std::string host; + if (jHost) + { + host = env->GetStringUTFChars(jHost, NULL); + } + std::string resourceUri; + if (jResourceUri) + { + resourceUri = env->GetStringUTFChars(jResourceUri, NULL); + } + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "onResourceFoundListener cannot be null"); + return; + } + + JniOnResourceFoundListener *onResFoundListener = AddOnResourceFoundListener(env, jListener); + + FindCallback findCallback = [onResFoundListener](std::shared_ptr resource) + { + onResFoundListener->foundResourceCallback(resource); + }; + + try + { + OCStackResult result = OCPlatform::findResource( + host, + resourceUri, + JniUtils::getConnectivityType(env, static_cast(jConnectivityType)), + findCallback); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "Find resource has failed"); + return; + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(OC_STACK_ERROR, e.reason().c_str()); + } + } + + /* + * Class: org_iotivity_base_OcPlatform + * Method: findResource1 + * Signature: (Ljava/lang/String;Ljava/lang/String;ILorg/iotivity/base/OcPlatform/OnResourceFoundListener;I)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_findResource1 + (JNIEnv *env, jclass clazz, jstring jHost, jstring jResourceUri, jint jConnectivityType, jobject jListener, jint jQoS) + { + LOGD("OcPlatform_findResource"); + std::string host; + if (jHost) + { + host = env->GetStringUTFChars(jHost, NULL); + } + std::string resourceUri; + if (jResourceUri) + { + resourceUri = env->GetStringUTFChars(jResourceUri, NULL); + } + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "onResourceFoundListener cannot be null"); + return; + } + JniOnResourceFoundListener *onResFoundListener = AddOnResourceFoundListener(env, jListener); + + FindCallback findCallback = [onResFoundListener](std::shared_ptr resource) + { + onResFoundListener->foundResourceCallback(resource); + }; + + try + { + OCStackResult result = OCPlatform::findResource( + host, + resourceUri, + JniUtils::getConnectivityType(env, static_cast(jConnectivityType)), + findCallback, + JniUtils::getQOS(env, static_cast(jQoS))); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "Find resource has failed"); + return; + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(OC_STACK_ERROR, e.reason().c_str()); + } + } + + /* + * Class: org_iotivity_base_OcPlatform + * Method: getDeviceInfo0 + * Signature: (Ljava/lang/String;Ljava/lang/String;ILorg/iotivity/base/OcPlatform/OnDeviceFoundListener;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_getDeviceInfo0 + (JNIEnv *env, jclass clazz, jstring jHost, jstring jResourceUri, jint jConnectivityType, jobject jListener) + { + LOGD("OcPlatform_getDeviceInfo0"); + std::string host; + if (jHost) + { + host = env->GetStringUTFChars(jHost, NULL); + } + std::string resourceUri; + if (jResourceUri) + { + resourceUri = env->GetStringUTFChars(jResourceUri, NULL); + } + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "onDeviceFoundListener cannot be null"); + return; + } + JniOnDeviceInfoListener *onDeviceInfoListener = AddOnDeviceInfoListener(env, jListener); + + FindDeviceCallback findDeviceCallback = [onDeviceInfoListener](const OCRepresentation& ocRepresentation) + { + onDeviceInfoListener->foundDeviceCallback(ocRepresentation); + }; + + try + { + OCStackResult result = OCPlatform::getDeviceInfo( + host, + resourceUri, + JniUtils::getConnectivityType(env, static_cast(jConnectivityType)), + findDeviceCallback); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "Find device has failed"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(OC_STACK_ERROR, e.reason().c_str()); + } + } + + /* + * Class: org_iotivity_base_OcPlatform + * Method: getDeviceInfo1 + * Signature: (Ljava/lang/String;Ljava/lang/String;ILorg/iotivity/base/OcPlatform/OnDeviceFoundListener;I)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_getDeviceInfo1 + (JNIEnv *env, jclass clazz, jstring jHost, jstring jResourceUri, jint jConnectivityType, jobject jListener, jint jQoS) + { + LOGD("OcPlatform_getDeviceInfo1"); + std::string host; + if (jHost) + { + host = env->GetStringUTFChars(jHost, NULL); + } + std::string resourceUri; + if (jResourceUri) + { + resourceUri = env->GetStringUTFChars(jResourceUri, NULL); + } + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "onDeviceFoundListener cannot be null"); + return; + } + JniOnDeviceInfoListener *onDeviceInfoListener = AddOnDeviceInfoListener(env, jListener); + + FindDeviceCallback findDeviceCallback = [onDeviceInfoListener](const OCRepresentation& ocRepresentation) + { + onDeviceInfoListener->foundDeviceCallback(ocRepresentation); + }; + + try + { + OCStackResult result = OCPlatform::getDeviceInfo( + host, + resourceUri, + JniUtils::getConnectivityType(env, static_cast(jConnectivityType)), + findDeviceCallback, + JniUtils::getQOS(env, static_cast(jQoS))); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "Find device has failed"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(OC_STACK_ERROR, e.reason().c_str()); + } +} + +/* +* Class: org_iotivity_base_OcPlatform - * Method: notifyListOfObservers2 - * Signature: (Lorg/iotivity/base/OcResourceHandle;[Ljava/lang/Byte;Lorg/iotivity/base/OcResourceResponse;)V ++* Method: getPlatformInfo0 ++* Signature: (Ljava/lang/String;Ljava/lang/String;ILorg/iotivity/base/OcPlatform/OnPlatformFoundListener;)V +*/ - JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_notifyListOfObservers2 - (JNIEnv *env, jclass clazz, jobject jResourceHandle, jbyteArray jObservationIdArr, jobject jResourceResponse) ++JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_getPlatformInfo0 ++(JNIEnv *env, jclass clazz, jstring jHost, jstring jResourceUri, jint jConnectivityType, jobject jListener) +{ - LOGD("OcPlatform_notifyListOfObservers2"); - if (!jResourceHandle) ++ LOGD("OcPlatform_getPlatformInfo0"); ++ std::string host; ++ if (jHost) + { - ThrowOcException(OC_STACK_INVALID_PARAM, "resourceHandle cannot be null"); - return; ++ host = env->GetStringUTFChars(jHost, NULL); + } - if (!jObservationIdArr) ++ std::string resourceUri; ++ if (jResourceUri) + { - ThrowOcException(OC_STACK_INVALID_PARAM, "observationIdList cannot be null"); - return; ++ resourceUri = env->GetStringUTFChars(jResourceUri, NULL); + } - if (!jResourceResponse) ++ if (!jListener) + { - ThrowOcException(OC_STACK_INVALID_PARAM, "resourceResponse cannot be null"); ++ ThrowOcException(OC_STACK_INVALID_PARAM, "onPlatformFoundListener cannot be null"); + return; + } ++ JniOnPlatformInfoListener *onPlatformInfoListener = AddOnPlatformInfoListener(env, jListener); + - JniOcResourceHandle* jniOcResourceHandle = JniOcResourceHandle::getJniOcResourceHandlePtr( - env, jResourceHandle); - if (!jniOcResourceHandle) return; - - JniOcResourceResponse* jniOcResourceResponse = JniOcResourceResponse::getJniOcResourceResponsePtr( - env, jResourceResponse); - if (!jniOcResourceResponse) return; - - int len = env->GetArrayLength(jObservationIdArr); - uint8_t* bArr = (uint8_t*)env->GetByteArrayElements(jObservationIdArr, 0); - - ObservationIds observationIds; - for (int i = 0; i < len; ++i) ++ FindPlatformCallback findPlatformCallback = [onPlatformInfoListener](const OCRepresentation& ocRepresentation) + { - observationIds.push_back(bArr[i]); - } - - env->ReleaseByteArrayElements(jObservationIdArr, (jbyte*)bArr, 0); ++ onPlatformInfoListener->foundPlatformCallback(ocRepresentation); ++ }; + - try{ - OCStackResult result = OCPlatform::notifyListOfObservers( - jniOcResourceHandle->getOCResourceHandle(), - observationIds, - jniOcResourceResponse->getOCResourceResponse()); ++ try ++ { ++ OCStackResult result = OCPlatform::getPlatformInfo( ++ host, ++ resourceUri, ++ JniUtils::getConnectivityType(env, static_cast(jConnectivityType)), ++ findPlatformCallback); + + if (OC_STACK_OK != result) + { - ThrowOcException(result, "Failed to notify all observers"); ++ ThrowOcException(result, "Find platform has failed"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(OC_STACK_ERROR, e.reason().c_str()); + } +} + +/* +* Class: org_iotivity_base_OcPlatform - * Method: notifyListOfObservers3 - * Signature: (Lorg/iotivity/base/OcResourceHandle;[Ljava/lang/Byte;Lorg/iotivity/base/OcResourceResponse;I)V ++* Method: getPlatformInfo1 ++* Signature: (Ljava/lang/String;Ljava/lang/String;ILorg/iotivity/base/OcPlatform/OnPlatformFoundListener;I)V +*/ - JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_notifyListOfObservers3 - (JNIEnv *env, jclass clazz, jobject jResourceHandle, jbyteArray jObservationIdArr, jobject jResourceResponse, jint jQoS) ++JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_getPlatformInfo1 ++(JNIEnv *env, jclass clazz, jstring jHost, jstring jResourceUri, jint jConnectivityType, jobject jListener, jint jQoS) +{ - LOGD("OcPlatform_notifyListOfObservers3"); - if (!jResourceHandle) ++ LOGD("OcPlatform_getPlatformInfo1"); ++ std::string host; ++ if (jHost) + { - ThrowOcException(OC_STACK_INVALID_PARAM, "resourceHandle cannot be null"); - return; ++ host = env->GetStringUTFChars(jHost, NULL); + } - if (!jObservationIdArr) ++ std::string resourceUri; ++ if (jResourceUri) + { - ThrowOcException(OC_STACK_INVALID_PARAM, "observationIdList cannot be null"); - return; ++ resourceUri = env->GetStringUTFChars(jResourceUri, NULL); + } - if (!jResourceResponse) ++ if (!jListener) + { - ThrowOcException(OC_STACK_INVALID_PARAM, "resourceResponse cannot be null"); ++ ThrowOcException(OC_STACK_INVALID_PARAM, "onPlatformFoundListener cannot be null"); + return; + } ++ JniOnDeviceInfoListener *onDeviceInfoListener = AddOnDeviceInfoListener(env, jListener); + - JniOcResourceHandle* jniOcResourceHandle = JniOcResourceHandle::getJniOcResourceHandlePtr( - env, jResourceHandle); - if (!jniOcResourceHandle) return; - - JniOcResourceResponse* jniOcResourceResponse = JniOcResourceResponse::getJniOcResourceResponsePtr( - env, jResourceResponse); - if (!jniOcResourceResponse) return; - - int len = env->GetArrayLength(jObservationIdArr); - uint8_t* bArr = (uint8_t*)env->GetByteArrayElements(jObservationIdArr, 0); - - ObservationIds observationIds; - for (int i = 0; i < len; ++i) ++ FindDeviceCallback findDeviceCallback = [onDeviceInfoListener](const OCRepresentation& ocRepresentation) + { - observationIds.push_back(bArr[i]); - } - - env->ReleaseByteArrayElements(jObservationIdArr, (jbyte*)bArr, 0); ++ onDeviceInfoListener->foundDeviceCallback(ocRepresentation); ++ }; + - try{ - OCStackResult result = OCPlatform::notifyListOfObservers( - jniOcResourceHandle->getOCResourceHandle(), - observationIds, - jniOcResourceResponse->getOCResourceResponse(), ++ try ++ { ++ OCStackResult result = OCPlatform::getPlatformInfo( ++ host, ++ resourceUri, ++ JniUtils::getConnectivityType(env, static_cast(jConnectivityType)), ++ findDeviceCallback, + JniUtils::getQOS(env, static_cast(jQoS))); + + if (OC_STACK_OK != result) + { - ThrowOcException(result, "Failed to notify all observers"); - } - } - catch (OCException& e) - { - LOGE("%s", e.reason().c_str()); - ThrowOcException(OC_STACK_ERROR, e.reason().c_str()); - } - } - - /* - * Class: org_iotivity_base_OcPlatform - * Method: findResource0 - * Signature: (Ljava/lang/String;Ljava/lang/String;ILorg/iotivity/base/OcPlatform/OnResourceFoundListener;)V - */ - JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_findResource0 - (JNIEnv *env, jclass clazz, jstring jHost, jstring jResourceUri, jint jConnectivityType, jobject jListener) - { - LOGD("OcPlatform_findResource"); - std::string host; - if (jHost) - { - host = env->GetStringUTFChars(jHost, NULL); - } - std::string resourceUri; - if (jResourceUri) - { - resourceUri = env->GetStringUTFChars(jResourceUri, NULL); - } - if (!jListener) - { - ThrowOcException(OC_STACK_INVALID_PARAM, "onResourceFoundListener cannot be null"); - return; - } - - JniOnResourceFoundListener *onResFoundListener = AddOnResourceFoundListener(env, jListener); - - FindCallback findCallback = [onResFoundListener](std::shared_ptr resource) - { - onResFoundListener->foundResourceCallback(resource); - }; - - try - { - OCStackResult result = OCPlatform::findResource( - host, - resourceUri, - JniUtils::getConnectivityType(env, static_cast(jConnectivityType)), - findCallback); - - if (OC_STACK_OK != result) - { - ThrowOcException(result, "Find resource has failed"); - return; - } - } - catch (OCException& e) - { - LOGE("%s", e.reason().c_str()); - ThrowOcException(OC_STACK_ERROR, e.reason().c_str()); - } - } - - /* - * Class: org_iotivity_base_OcPlatform - * Method: findResource1 - * Signature: (Ljava/lang/String;Ljava/lang/String;ILorg/iotivity/base/OcPlatform/OnResourceFoundListener;I)V - */ - JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_findResource1 - (JNIEnv *env, jclass clazz, jstring jHost, jstring jResourceUri, jint jConnectivityType, jobject jListener, jint jQoS) - { - LOGD("OcPlatform_findResource"); - std::string host; - if (jHost) - { - host = env->GetStringUTFChars(jHost, NULL); - } - std::string resourceUri; - if (jResourceUri) - { - resourceUri = env->GetStringUTFChars(jResourceUri, NULL); - } - if (!jListener) - { - ThrowOcException(OC_STACK_INVALID_PARAM, "onResourceFoundListener cannot be null"); - return; - } - JniOnResourceFoundListener *onResFoundListener = AddOnResourceFoundListener(env, jListener); - - FindCallback findCallback = [onResFoundListener](std::shared_ptr resource) - { - onResFoundListener->foundResourceCallback(resource); - }; - - try - { - OCStackResult result = OCPlatform::findResource( - host, - resourceUri, - JniUtils::getConnectivityType(env, static_cast(jConnectivityType)), - findCallback, - JniUtils::getQOS(env, static_cast(jQoS))); - - if (OC_STACK_OK != result) - { - ThrowOcException(result, "Find resource has failed"); - return; - } - } - catch (OCException& e) - { - LOGE("%s", e.reason().c_str()); - ThrowOcException(OC_STACK_ERROR, e.reason().c_str()); - } - } - - /* - * Class: org_iotivity_base_OcPlatform - * Method: getDeviceInfo0 - * Signature: (Ljava/lang/String;Ljava/lang/String;ILorg/iotivity/base/OcPlatform/OnDeviceFoundListener;)V - */ - JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_getDeviceInfo0 - (JNIEnv *env, jclass clazz, jstring jHost, jstring jResourceUri, jint jConnectivityType, jobject jListener) - { - LOGD("OcPlatform_getDeviceInfo0"); - std::string host; - if (jHost) - { - host = env->GetStringUTFChars(jHost, NULL); - } - std::string resourceUri; - if (jResourceUri) - { - resourceUri = env->GetStringUTFChars(jResourceUri, NULL); - } - if (!jListener) - { - ThrowOcException(OC_STACK_INVALID_PARAM, "onDeviceFoundListener cannot be null"); - return; - } - JniOnDeviceInfoListener *onDeviceInfoListener = AddOnDeviceInfoListener(env, jListener); - - FindDeviceCallback findDeviceCallback = [onDeviceInfoListener](const OCRepresentation& ocRepresentation) - { - onDeviceInfoListener->foundDeviceCallback(ocRepresentation); - }; - - try - { - OCStackResult result = OCPlatform::getDeviceInfo( - host, - resourceUri, - JniUtils::getConnectivityType(env, static_cast(jConnectivityType)), - findDeviceCallback); - - if (OC_STACK_OK != result) - { - ThrowOcException(result, "Find device has failed"); - } - } - catch (OCException& e) - { - LOGE("%s", e.reason().c_str()); - ThrowOcException(OC_STACK_ERROR, e.reason().c_str()); - } - } - - /* - * Class: org_iotivity_base_OcPlatform - * Method: getDeviceInfo1 - * Signature: (Ljava/lang/String;Ljava/lang/String;ILorg/iotivity/base/OcPlatform/OnDeviceFoundListener;I)V - */ - JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_getDeviceInfo1 - (JNIEnv *env, jclass clazz, jstring jHost, jstring jResourceUri, jint jConnectivityType, jobject jListener, jint jQoS) - { - LOGD("OcPlatform_getDeviceInfo1"); - std::string host; - if (jHost) - { - host = env->GetStringUTFChars(jHost, NULL); - } - std::string resourceUri; - if (jResourceUri) - { - resourceUri = env->GetStringUTFChars(jResourceUri, NULL); - } - if (!jListener) - { - ThrowOcException(OC_STACK_INVALID_PARAM, "onDeviceFoundListener cannot be null"); - return; - } - JniOnDeviceInfoListener *onDeviceInfoListener = AddOnDeviceInfoListener(env, jListener); - - FindDeviceCallback findDeviceCallback = [onDeviceInfoListener](const OCRepresentation& ocRepresentation) - { - onDeviceInfoListener->foundDeviceCallback(ocRepresentation); - }; - - try - { - OCStackResult result = OCPlatform::getDeviceInfo( - host, - resourceUri, - JniUtils::getConnectivityType(env, static_cast(jConnectivityType)), - findDeviceCallback, - JniUtils::getQOS(env, static_cast(jQoS))); - - if (OC_STACK_OK != result) - { - ThrowOcException(result, "Find device has failed"); - } - } - catch (OCException& e) - { - LOGE("%s", e.reason().c_str()); - ThrowOcException(OC_STACK_ERROR, e.reason().c_str()); - } - } - - /* - * Class: org_iotivity_base_OcPlatform - * Method: getPlatformInfo0 - * Signature: (Ljava/lang/String;Ljava/lang/String;ILorg/iotivity/base/OcPlatform/OnPlatformFoundListener;)V - */ - JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_getPlatformInfo0 - (JNIEnv *env, jclass clazz, jstring jHost, jstring jResourceUri, jint jConnectivityType, jobject jListener) - { - LOGD("OcPlatform_getPlatformInfo0"); - std::string host; - if (jHost) - { - host = env->GetStringUTFChars(jHost, NULL); - } - std::string resourceUri; - if (jResourceUri) - { - resourceUri = env->GetStringUTFChars(jResourceUri, NULL); - } - if (!jListener) - { - ThrowOcException(OC_STACK_INVALID_PARAM, "onPlatformFoundListener cannot be null"); - return; - } - JniOnPlatformInfoListener *onPlatformInfoListener = AddOnPlatformInfoListener(env, jListener); - - FindPlatformCallback findPlatformCallback = [onPlatformInfoListener](const OCRepresentation& ocRepresentation) - { - onPlatformInfoListener->foundPlatformCallback(ocRepresentation); - }; - - try - { - OCStackResult result = OCPlatform::getPlatformInfo( - host, - resourceUri, - JniUtils::getConnectivityType(env, static_cast(jConnectivityType)), - findPlatformCallback); - - if (OC_STACK_OK != result) - { - ThrowOcException(result, "Find platform has failed"); - } - } - catch (OCException& e) - { - LOGE("%s", e.reason().c_str()); - ThrowOcException(OC_STACK_ERROR, e.reason().c_str()); - } - } - - /* - * Class: org_iotivity_base_OcPlatform - * Method: getPlatformInfo1 - * Signature: (Ljava/lang/String;Ljava/lang/String;ILorg/iotivity/base/OcPlatform/OnPlatformFoundListener;I)V - */ - JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_getPlatformInfo1 - (JNIEnv *env, jclass clazz, jstring jHost, jstring jResourceUri, jint jConnectivityType, jobject jListener, jint jQoS) - { - LOGD("OcPlatform_getPlatformInfo1"); - std::string host; - if (jHost) - { - host = env->GetStringUTFChars(jHost, NULL); - } - std::string resourceUri; - if (jResourceUri) - { - resourceUri = env->GetStringUTFChars(jResourceUri, NULL); - } - if (!jListener) - { - ThrowOcException(OC_STACK_INVALID_PARAM, "onPlatformFoundListener cannot be null"); - return; - } - JniOnDeviceInfoListener *onDeviceInfoListener = AddOnDeviceInfoListener(env, jListener); - - FindDeviceCallback findDeviceCallback = [onDeviceInfoListener](const OCRepresentation& ocRepresentation) - { - onDeviceInfoListener->foundDeviceCallback(ocRepresentation); - }; - - try - { - OCStackResult result = OCPlatform::getPlatformInfo( - host, - resourceUri, - JniUtils::getConnectivityType(env, static_cast(jConnectivityType)), - findDeviceCallback, - JniUtils::getQOS(env, static_cast(jQoS))); - - if (OC_STACK_OK != result) - { - ThrowOcException(result, "Find platform has failed"); - } - } - catch (OCException& e) - { - LOGE("%s", e.reason().c_str()); - ThrowOcException(OC_STACK_ERROR, e.reason().c_str()); - } - } - - /* - * Class: org_iotivity_base_OcPlatform - * Method: registerResource0 - * Signature: (Lorg/iotivity/base/OcResource;)Lorg/iotivity/base/OcResourceHandle; - */ - JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcPlatform_registerResource0 - (JNIEnv *env, jclass clazz, jobject jResource) - { - LOGD("OcPlatform_registerResource"); - if (!jResource) - { - ThrowOcException(OC_STACK_INVALID_PARAM, "Resource cannot be null"); - return nullptr; - } - JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, jResource); - if (!resource) return nullptr; - LOGD("OcPlatform_registerResource1"); - OCResourceHandle resourceHandle; - try - { - LOGD("OcPlatform_registerResource2"); - OCStackResult result = OCPlatform::registerResource( - resourceHandle, - resource->getOCResource()); - LOGD("OcPlatform_registerResource3"); - - if (OC_STACK_OK != result) - { - ThrowOcException(result, "register resource"); - } - } - catch (OCException& e) - { - LOGE("%s", e.reason().c_str()); - ThrowOcException(OC_STACK_ERROR, e.reason().c_str()); - return nullptr; - } - LOGD("OcPlatform_registerResource4"); - JniOcResourceHandle* jniHandle = new JniOcResourceHandle(resourceHandle); - jlong handle = reinterpret_cast(jniHandle); - jobject jResourceHandle = env->NewObject(g_cls_OcResourceHandle, g_mid_OcResourceHandle_N_ctor, handle); - LOGD("OcPlatform_registerResource5"); - if (!jResourceHandle) - { - LOGE("Failed to create OcResourceHandle"); - delete jniHandle; - } - return jResourceHandle; - } - - /* - * Class: org_iotivity_base_OcPlatform - * Method: registerResource1 - * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lorg/iotivity/base/OcPlatform/EntityHandler;I)Lorg/iotivity/base/OcResourceHandle; - */ - JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcPlatform_registerResource1 - (JNIEnv *env, jclass clazz, jstring jResourceUri, jstring jResourceTypeName, jstring jResourceInterface, - jobject jListener, jint jResourceProperty) - { - LOGI("OcPlatform_registerResource1"); - std::string resourceUri; - if (jResourceUri) - { - resourceUri = env->GetStringUTFChars(jResourceUri, NULL); - } - std::string resourceTypeName; - if (jResourceTypeName) - { - resourceTypeName = env->GetStringUTFChars(jResourceTypeName, NULL); - } - std::string resourceInterface; - if (jResourceInterface) - { - resourceInterface = env->GetStringUTFChars(jResourceInterface, NULL); - } - if (!jListener) - { - ThrowOcException(OC_STACK_INVALID_PARAM, "entityHandler cannot be null"); - return nullptr; - } - JniEntityHandler* entityHandler = new JniEntityHandler(env, jListener); - EntityHandler handleEntityCallback = [entityHandler](const std::shared_ptr request) -> - OCEntityHandlerResult{ - return entityHandler->handleEntity(request); - }; - - OCResourceHandle resourceHandle; - try - { - OCStackResult result = OCPlatform::registerResource( - resourceHandle, - resourceUri, - resourceTypeName, - resourceInterface, - handleEntityCallback, - static_cast(jResourceProperty)); - - if (OC_STACK_OK != result) - { - delete entityHandler; - ThrowOcException(result, "register resource"); - return nullptr; - } - } - catch (OCException& e) - { - LOGE("%s", e.reason().c_str()); - delete entityHandler; - ThrowOcException(OC_STACK_ERROR, e.reason().c_str()); - return nullptr; - } - - JniOcResourceHandle* jniHandle = new JniOcResourceHandle(resourceHandle); - jlong handle = reinterpret_cast(jniHandle); - jobject jResourceHandle = env->NewObject(g_cls_OcResourceHandle, g_mid_OcResourceHandle_N_ctor, handle); - if (!jResourceHandle) - { - LOGE("Failed to create OcResourceHandle"); - delete jniHandle; - } - - return jResourceHandle; - } - - /* - * Class: org_iotivity_base_OcPlatform - * Method: registerDeviceInfo0 - * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V - */ - JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_registerDeviceInfo0 - (JNIEnv *env, - jclass clazz, - jstring jDeviceName) - { - LOGI("OcPlatform_registerDeviceInfo"); - - std::string deviceName; - if (jDeviceName) - { - deviceName = env->GetStringUTFChars(jDeviceName, NULL); - } - - OCDeviceInfo deviceInfo; - try - { - DuplicateString(&deviceInfo.deviceName, deviceName); - } - catch (std::exception &e) - { - ThrowOcException(JNI_EXCEPTION, "Failed to construct device info"); - return; - } - - try - { - OCStackResult result = OCPlatform::registerDeviceInfo(deviceInfo); - - delete deviceInfo.deviceName; - - if (OC_STACK_OK != result) - { - ThrowOcException(result, "Failed to register device info"); - return; - } - } - catch (OCException& e) - { - LOGE("%s", e.reason().c_str()); - ThrowOcException(OC_STACK_ERROR, e.reason().c_str()); - } - } - - /* - * Class: org_iotivity_base_OcPlatform ++ ThrowOcException(result, "Find platform has failed"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(OC_STACK_ERROR, e.reason().c_str()); + } + } + + /* + * Class: org_iotivity_base_OcPlatform + * Method: registerResource0 + * Signature: (Lorg/iotivity/base/OcResource;)Lorg/iotivity/base/OcResourceHandle; + */ + JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcPlatform_registerResource0 + (JNIEnv *env, jclass clazz, jobject jResource) + { + LOGD("OcPlatform_registerResource"); + if (!jResource) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "Resource cannot be null"); + return nullptr; + } + JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, jResource); + if (!resource) return nullptr; - ++ LOGD("OcPlatform_registerResource1"); + OCResourceHandle resourceHandle; + try + { ++ LOGD("OcPlatform_registerResource2"); + OCStackResult result = OCPlatform::registerResource( + resourceHandle, + resource->getOCResource()); ++ LOGD("OcPlatform_registerResource3"); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "register resource"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(OC_STACK_ERROR, e.reason().c_str()); + return nullptr; + } - ++ LOGD("OcPlatform_registerResource4"); + JniOcResourceHandle* jniHandle = new JniOcResourceHandle(resourceHandle); + jlong handle = reinterpret_cast(jniHandle); + jobject jResourceHandle = env->NewObject(g_cls_OcResourceHandle, g_mid_OcResourceHandle_N_ctor, handle); ++ LOGD("OcPlatform_registerResource5"); + if (!jResourceHandle) + { + LOGE("Failed to create OcResourceHandle"); + delete jniHandle; + } + return jResourceHandle; + } + + /* + * Class: org_iotivity_base_OcPlatform + * Method: registerResource1 + * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lorg/iotivity/base/OcPlatform/EntityHandler;I)Lorg/iotivity/base/OcResourceHandle; + */ + JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcPlatform_registerResource1 + (JNIEnv *env, jclass clazz, jstring jResourceUri, jstring jResourceTypeName, jstring jResourceInterface, + jobject jListener, jint jResourceProperty) + { + LOGI("OcPlatform_registerResource1"); + std::string resourceUri; + if (jResourceUri) + { + resourceUri = env->GetStringUTFChars(jResourceUri, NULL); + } + std::string resourceTypeName; + if (jResourceTypeName) + { + resourceTypeName = env->GetStringUTFChars(jResourceTypeName, NULL); + } + std::string resourceInterface; + if (jResourceInterface) + { + resourceInterface = env->GetStringUTFChars(jResourceInterface, NULL); + } + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "entityHandler cannot be null"); + return nullptr; + } + JniEntityHandler* entityHandler = new JniEntityHandler(env, jListener); + EntityHandler handleEntityCallback = [entityHandler](const std::shared_ptr request) -> + OCEntityHandlerResult{ + return entityHandler->handleEntity(request); + }; + + OCResourceHandle resourceHandle; + try + { + OCStackResult result = OCPlatform::registerResource( + resourceHandle, + resourceUri, + resourceTypeName, + resourceInterface, + handleEntityCallback, + static_cast(jResourceProperty)); + + if (OC_STACK_OK != result) + { + delete entityHandler; + ThrowOcException(result, "register resource"); + return nullptr; + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + delete entityHandler; + ThrowOcException(OC_STACK_ERROR, e.reason().c_str()); + return nullptr; + } + + JniOcResourceHandle* jniHandle = new JniOcResourceHandle(resourceHandle); + jlong handle = reinterpret_cast(jniHandle); + jobject jResourceHandle = env->NewObject(g_cls_OcResourceHandle, g_mid_OcResourceHandle_N_ctor, handle); + if (!jResourceHandle) + { + LOGE("Failed to create OcResourceHandle"); + delete jniHandle; + } + + return jResourceHandle; + } + + /* + * Class: org_iotivity_base_OcPlatform + * Method: registerDeviceInfo0 + * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_registerDeviceInfo0 + (JNIEnv *env, + jclass clazz, + jstring jDeviceName) + { + LOGI("OcPlatform_registerDeviceInfo"); + + std::string deviceName; + if (jDeviceName) + { + deviceName = env->GetStringUTFChars(jDeviceName, NULL); + } + + OCDeviceInfo deviceInfo; + try + { + DuplicateString(&deviceInfo.deviceName, deviceName); + } + catch (std::exception &e) + { + ThrowOcException(JNI_EXCEPTION, "Failed to construct device info"); + return; + } + + try + { + OCStackResult result = OCPlatform::registerDeviceInfo(deviceInfo); + + delete deviceInfo.deviceName; + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "Failed to register device info"); + return; + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(OC_STACK_ERROR, e.reason().c_str()); + } + } + + /* + * Class: org_iotivity_base_OcPlatform +* Method: registerPlatformInfo0 +* Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V +*/ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_registerPlatformInfo0 +(JNIEnv *env, +jclass clazz, +jstring jPlatformID, +jstring jManufacturerName, +jstring jManufacturerUrl, +jstring jModelNumber, +jstring jDateOfManufacture, +jstring jPlatformVersion, +jstring jOperatingSystemVersion, +jstring jHardwareVersion, +jstring jFirmwareVersion, +jstring jSupportUrl, +jstring jSystemTime) +{ + LOGI("OcPlatform_registerPlatformInfo"); + + + std::string platformID; + std::string manufacturerName; + std::string manufacturerUrl; + std::string modelNumber; + std::string dateOfManufacture; + std::string platformVersion; + std::string operatingSystemVersion; + std::string hardwareVersion; + std::string firmwareVersion; + std::string supportUrl; + std::string systemTime; + + if (jPlatformID) + { + platformID = env->GetStringUTFChars(jPlatformID, NULL); + } + if (jManufacturerName) + { + manufacturerName = env->GetStringUTFChars(jManufacturerName, NULL); + } + if (jManufacturerUrl) + { + manufacturerUrl = env->GetStringUTFChars(jManufacturerUrl, NULL); + } + if (jModelNumber) + { - modelNumber = env->GetStringUTFChars(jModelNumber, NULL); - } - if (jDateOfManufacture) - { - dateOfManufacture = env->GetStringUTFChars(jDateOfManufacture, NULL); - } - if (jPlatformVersion) - { - platformVersion = env->GetStringUTFChars(jPlatformVersion, NULL); - } - if (jOperatingSystemVersion) - { - operatingSystemVersion = env->GetStringUTFChars(jOperatingSystemVersion, NULL); - } - if (jHardwareVersion) - { - hardwareVersion = env->GetStringUTFChars(jHardwareVersion, NULL); - } - if (jFirmwareVersion) - { - firmwareVersion = env->GetStringUTFChars(jFirmwareVersion, NULL); - } - if (jSupportUrl) - { - supportUrl = env->GetStringUTFChars(jSupportUrl, NULL); - } - if (jSystemTime) - { - systemTime = env->GetStringUTFChars(jSystemTime, NULL); - } - - OCPlatformInfo platformInfo; - try - { - DuplicateString(&platformInfo.platformID, platformID); - DuplicateString(&platformInfo.manufacturerName, manufacturerName); - DuplicateString(&platformInfo.manufacturerUrl, manufacturerUrl); - DuplicateString(&platformInfo.modelNumber, modelNumber); - DuplicateString(&platformInfo.dateOfManufacture, dateOfManufacture); - DuplicateString(&platformInfo.platformVersion, platformVersion); - DuplicateString(&platformInfo.operatingSystemVersion, operatingSystemVersion); - DuplicateString(&platformInfo.hardwareVersion, hardwareVersion); - DuplicateString(&platformInfo.firmwareVersion, firmwareVersion); - DuplicateString(&platformInfo.supportUrl, supportUrl); - DuplicateString(&platformInfo.systemTime, systemTime); - } - catch (std::exception &e) - { - ThrowOcException(JNI_EXCEPTION, "Failed to construct platform info"); - return; - } - - // __android_log_print(ANDROID_LOG_INFO, "Rahul", "platformID = %s", platformID); - try - { - OCStackResult result = OCPlatform::registerPlatformInfo(platformInfo); - - delete platformInfo.platformID; - delete platformInfo.manufacturerName; - delete platformInfo.manufacturerUrl; - delete platformInfo.modelNumber; - delete platformInfo.dateOfManufacture; - delete platformInfo.platformVersion; - delete platformInfo.operatingSystemVersion; - delete platformInfo.hardwareVersion; - delete platformInfo.firmwareVersion; - delete platformInfo.supportUrl; - delete platformInfo.systemTime; - - if (OC_STACK_OK != result) - { - ThrowOcException(result, "Failed to register platform info"); - return; - } - } - catch (OCException& e) - { - LOGE("Error is due to %s", e.reason().c_str()); - ThrowOcException(OC_STACK_ERROR, e.reason().c_str()); - } - - - - } - - /* - * Class: org_iotivity_base_OcPlatform - * Method: unregisterResource0 - * Signature: (Lorg/iotivity/base/OcResourceHandle;)V - */ - JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_unregisterResource0 - (JNIEnv *env, jclass clazz, jobject jResourceHandle) - { - LOGI("OcPlatform_unregisterResource"); - if (!jResourceHandle) - { - ThrowOcException(OC_STACK_INVALID_PARAM, "resourceHandle cannot be null"); - return; - } - JniOcResourceHandle* jniOcResourceHandle = JniOcResourceHandle::getJniOcResourceHandlePtr( - env, jResourceHandle); - if (!jniOcResourceHandle) return; - - try - { - OCResourceHandle resHandle = jniOcResourceHandle->getOCResourceHandle(); - OCStackResult result = OCPlatform::unregisterResource(resHandle); - if (OC_STACK_OK != result) - { - ThrowOcException(result, "Failed to unregister resource"); - } - } - catch (OCException& e) - { - LOGE("%s", e.reason().c_str()); - ThrowOcException(OC_STACK_ERROR, e.reason().c_str()); - } - } - - /* - * Class: org_iotivity_base_OcPlatform - * Method: bindResource0 - * Signature: (Lorg/iotivity/base/OcResourceHandle;Lorg/iotivity/base/OcResourceHandle;)V - */ - JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_bindResource0 - (JNIEnv *env, jclass clazz, jobject jResourceCollectionHandle, jobject jResourceHandle) - { - LOGI("OcPlatform_bindResource"); - if (!jResourceCollectionHandle) - { - ThrowOcException(OC_STACK_INVALID_PARAM, "resourceCollectionHandle cannot be null"); - return; - } - if (!jResourceHandle) - { - ThrowOcException(OC_STACK_INVALID_PARAM, "resourceHandle cannot be null"); - return; - } - JniOcResourceHandle* jniOcResourceCollectionHandle = JniOcResourceHandle::getJniOcResourceHandlePtr( - env, jResourceCollectionHandle); - if (!jniOcResourceCollectionHandle) return; - - JniOcResourceHandle* jniOcResourceHandle = JniOcResourceHandle::getJniOcResourceHandlePtr( - env, jResourceHandle); - if (!jniOcResourceHandle) return; - - try - { - OCStackResult result = OCPlatform::bindResource( - jniOcResourceCollectionHandle->getOCResourceHandle(), - jniOcResourceHandle->getOCResourceHandle() - ); - - if (OC_STACK_OK != result) - { - ThrowOcException(result, "Failed to bind resource"); - } - } - catch (OCException& e) - { - LOGE("%s", e.reason().c_str()); - ThrowOcException(OC_STACK_ERROR, e.reason().c_str()); - } - } - - /* - * Class: org_iotivity_base_OcPlatform - * Method: bindResources0 - * Signature: (Lorg/iotivity/base/OcResourceHandle;[Lorg/iotivity/base/OcResourceHandle;)V - */ - JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_bindResources0 - (JNIEnv *env, jclass clazz, jobject jResourceCollectionHandle, jobjectArray jResourceHandleArray) - { - LOGI("OcPlatform_bindResources"); - - if (!jResourceCollectionHandle) - { - ThrowOcException(OC_STACK_INVALID_PARAM, "resourceCollectionHandle cannot be null"); - return; - } - if (!jResourceHandleArray) - { - ThrowOcException(OC_STACK_INVALID_PARAM, "resourceHandleList cannot be null"); - return; - } - - JniOcResourceHandle* jniOcResourceCollectionHandle = JniOcResourceHandle::getJniOcResourceHandlePtr( - env, jResourceCollectionHandle); - if (!jniOcResourceCollectionHandle) return; - - std::vector resourceHandleList; - int len = env->GetArrayLength(jResourceHandleArray); - for (int 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) return; - - resourceHandleList.push_back( - jniOcResourceHandle->getOCResourceHandle()); - } - - try - { - OCStackResult result = OCPlatform::bindResources( - jniOcResourceCollectionHandle->getOCResourceHandle(), - resourceHandleList - ); - - if (OC_STACK_OK != result) - { - ThrowOcException(result, "Failed to bind resources"); - } - } - catch (OCException& e) - { - LOGE("%s", e.reason().c_str()); - ThrowOcException(OC_STACK_ERROR, e.reason().c_str()); - } - } - - /* - * Class: org_iotivity_base_OcPlatform - * Method: unbindResource0 - * Signature: (Lorg/iotivity/base/OcResourceHandle;Lorg/iotivity/base/OcResourceHandle;)V - */ - JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_unbindResource0 - (JNIEnv *env, jclass clazz, jobject jResourceCollectionHandle, jobject jResourceHandle) - { - LOGI("OcPlatform_unbindResource"); - if (!jResourceCollectionHandle) - { - ThrowOcException(OC_STACK_INVALID_PARAM, "resourceCollectionHandle cannot be null"); - return; - } - if (!jResourceHandle) - { - ThrowOcException(OC_STACK_INVALID_PARAM, "resourceHandle cannot be null"); - return; - } - - JniOcResourceHandle* jniOcResourceCollectionHandle = JniOcResourceHandle::getJniOcResourceHandlePtr( - env, jResourceCollectionHandle); - if (!jniOcResourceCollectionHandle) return; - - JniOcResourceHandle* jniOcResourceHandle = JniOcResourceHandle::getJniOcResourceHandlePtr( - env, jResourceHandle); - if (!jniOcResourceHandle) return; - - try - { - OCStackResult result = OCPlatform::unbindResource( - jniOcResourceCollectionHandle->getOCResourceHandle(), - jniOcResourceHandle->getOCResourceHandle() - ); - - if (OC_STACK_OK != result) - { - ThrowOcException(result, "Failed to unbind resource"); - } - } - catch (OCException& e) - { - LOGE("%s", e.reason().c_str()); - ThrowOcException(OC_STACK_ERROR, e.reason().c_str()); - } - } - - /* - * Class: org_iotivity_base_OcPlatform - * Method: unbindResources0 - * Signature: (Lorg/iotivity/base/OcResourceHandle;[Lorg/iotivity/base/OcResourceHandle;)V - */ - JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_unbindResources0 - (JNIEnv *env, jclass clazz, jobject jResourceCollectionHandle, jobjectArray jResourceHandleArray) - { - LOGI("OcPlatform_unbindResources"); - if (!jResourceCollectionHandle) - { - ThrowOcException(OC_STACK_INVALID_PARAM, "resourceCollectionHandle cannot be null"); - return; - } - if (!jResourceHandleArray) - { - ThrowOcException(OC_STACK_INVALID_PARAM, "resourceHandleList cannot be null"); - return; - } - - JniOcResourceHandle* jniOcResourceCollectionHandle = JniOcResourceHandle::getJniOcResourceHandlePtr( - env, jResourceCollectionHandle); - if (!jniOcResourceCollectionHandle) return; - - std::vector resourceHandleList; - int len = env->GetArrayLength(jResourceHandleArray); - for (int 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) return; - - resourceHandleList.push_back( - jniOcResourceHandle->getOCResourceHandle()); - } - - try - { - OCStackResult result = OCPlatform::unbindResources( - jniOcResourceCollectionHandle->getOCResourceHandle(), - resourceHandleList - ); - - if (OC_STACK_OK != result) - { - ThrowOcException(result, "Failed to unbind resources"); - } - } - catch (OCException& e) - { - LOGE("%s", e.reason().c_str()); - ThrowOcException(OC_STACK_ERROR, e.reason().c_str()); - } - } - - /* - * Class: org_iotivity_base_OcPlatform - * Method: bindTypeToResource0 - * Signature: (Lorg/iotivity/base/OcResourceHandle;Ljava/lang/String;)V - */ - JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_bindTypeToResource0 - (JNIEnv *env, jclass clazz, jobject jResourceHandle, jstring jResourceTypeName) - { - LOGI("OcPlatform_bindTypeToResource"); - if (!jResourceHandle) - { - ThrowOcException(OC_STACK_INVALID_PARAM, "resourceHandle cannot be null"); - return; - } - std::string typeName; - if (jResourceTypeName) - { - typeName = env->GetStringUTFChars(jResourceTypeName, NULL); - } - - JniOcResourceHandle* jniOcResourceHandle = JniOcResourceHandle::getJniOcResourceHandlePtr( - env, jResourceHandle); - if (!jniOcResourceHandle) return; - - try - { - OCStackResult result = OCPlatform::bindTypeToResource( - jniOcResourceHandle->getOCResourceHandle(), - typeName - ); - - if (OC_STACK_OK != result) ++ modelNumber = env->GetStringUTFChars(jModelNumber, NULL); ++ } ++ if (jDateOfManufacture) + { - ThrowOcException(result, "Failed to bind type to resource"); ++ dateOfManufacture = env->GetStringUTFChars(jDateOfManufacture, NULL); + } - } - catch (OCException& e) - { - LOGE("%s", e.reason().c_str()); - ThrowOcException(OC_STACK_ERROR, e.reason().c_str()); - } - } - - /* - * Class: org_iotivity_base_OcPlatform - * Method: bindInterfaceToResource0 - * Signature: (Lorg/iotivity/base/OcResourceHandle;Ljava/lang/String;)V - */ - JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_bindInterfaceToResource0 - (JNIEnv *env, jclass clazz, jobject jResourceHandle, jstring jResourceInterfaceName) - { - LOGI("OcPlatform_bindInterfaceToResource"); - if (!jResourceHandle) - { - ThrowOcException(OC_STACK_INVALID_PARAM, "resourceHandle cannot be null"); - return; - } - std::string interfaceName; - if (jResourceInterfaceName) - { - interfaceName = env->GetStringUTFChars(jResourceInterfaceName, NULL); - } - - JniOcResourceHandle* jniOcResourceHandle = JniOcResourceHandle::getJniOcResourceHandlePtr( - env, jResourceHandle); - if (!jniOcResourceHandle) return; - - try - { - OCStackResult result = OCPlatform::bindInterfaceToResource( - jniOcResourceHandle->getOCResourceHandle(), - interfaceName - ); - - if (OC_STACK_OK != result) ++ if (jPlatformVersion) + { - ThrowOcException(result, "Failed to bind interface to resource"); ++ platformVersion = env->GetStringUTFChars(jPlatformVersion, NULL); + } - } - catch (OCException& e) - { - LOGE("%s", e.reason().c_str()); - ThrowOcException(OC_STACK_ERROR, e.reason().c_str()); - } - } - - /* - * Class: org_iotivity_base_OcPlatform - * Method: startPresence0 - * Signature: (I)V - */ - JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_startPresence0 - (JNIEnv *env, jclass clazz, jint ttl) - { - LOGI("OcPlatform_startPresence"); - - try - { - OCStackResult result = OCPlatform::startPresence((unsigned int)ttl); - - if (OC_STACK_OK != result) ++ if (jOperatingSystemVersion) + { - ThrowOcException(result, "Failed to start presence"); ++ operatingSystemVersion = env->GetStringUTFChars(jOperatingSystemVersion, NULL); + } - } - catch (OCException& e) - { - LOGE("%s", e.reason().c_str()); - ThrowOcException(OC_STACK_ERROR, e.reason().c_str()); - } - } - - /* - * Class: org_iotivity_base_OcPlatform - * Method: stopPresence0 - * Signature: ()V - */ - JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_stopPresence0 - (JNIEnv *env, jclass clazz) - { - LOGI("OcPlatform_stopPresence"); - - try - { - OCStackResult result = OCPlatform::stopPresence(); - - if (OC_STACK_OK != result) ++ if (jHardwareVersion) + { - ThrowOcException(result, "Failed to stop presence"); ++ hardwareVersion = env->GetStringUTFChars(jHardwareVersion, NULL); + } - } - catch (OCException& e) - { - LOGE("%s", e.reason().c_str()); - ThrowOcException(OC_STACK_ERROR, e.reason().c_str()); - } - } - - /* - * Class: org_iotivity_base_OcPlatform - * Method: subscribePresence0 - * Signature: (Ljava/lang/String;ILorg/iotivity/base/OcPlatform/OnPresenceListener;)Lorg/iotivity/base/OcPresenceHandle; - */ - JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcPlatform_subscribePresence0 - (JNIEnv *env, jclass clazz, jstring jHost, jint jConnectivityType, jobject jListener) - { - LOGD("OcPlatform_subscribePresence"); - std::string host; - if (jHost) - { - host = env->GetStringUTFChars(jHost, NULL); - } - if (!jListener) - { - ThrowOcException(OC_STACK_INVALID_PARAM, "onPresenceListener cannot be null"); - return nullptr; - } - - JniOnPresenceListener *onPresenceListener = AddOnPresenceListener(env, jListener); - - SubscribeCallback subscribeCallback = [onPresenceListener](OCStackResult result, const unsigned int nonce, - const std::string& hostAddress) - { - onPresenceListener->onPresenceCallback(result, nonce, hostAddress); - }; - - OCPlatform::OCPresenceHandle presenceHandle; - try - { - OCStackResult result = OCPlatform::subscribePresence( - presenceHandle, - host, - JniUtils::getConnectivityType(env, static_cast(jConnectivityType)), - subscribeCallback); - - if (OC_STACK_OK != result) ++ if (jFirmwareVersion) + { - ThrowOcException(result, "subscribe presence has failed"); ++ firmwareVersion = env->GetStringUTFChars(jFirmwareVersion, NULL); + } - } - catch (OCException& e) - { - LOGE("%s", e.reason().c_str()); - ThrowOcException(OC_STACK_ERROR, e.reason().c_str()); - return nullptr; - } - - JniOcPresenceHandle* jniPresenceHandle = new JniOcPresenceHandle(onPresenceListener, 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; - } - - /* - * Class: org_iotivity_base_OcPlatform - * Method: subscribePresence1 - * Signature: (Ljava/lang/String;Ljava/lang/String;I - Lorg/iotivity/base/OcPlatform/OnPresenceListener;)Lorg/iotivity/base/OcPresenceHandle; - */ - JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcPlatform_subscribePresence1 - (JNIEnv *env, jclass clazz, jstring jHost, jstring jResourceType, jint jConnectivityType, jobject jListener) - { - LOGD("OcPlatform_subscribePresence1"); - std::string host; - if (jHost) - { - host = env->GetStringUTFChars(jHost, NULL); - } - std::string resourceType; - if (jResourceType) - { - resourceType = env->GetStringUTFChars(jResourceType, NULL); - } - if (!jListener) - { - ThrowOcException(OC_STACK_INVALID_PARAM, "onPresenceListener cannot be null"); - return nullptr; - } - - JniOnPresenceListener *onPresenceListener = AddOnPresenceListener(env, jListener); - - SubscribeCallback subscribeCallback = [onPresenceListener](OCStackResult result, - const unsigned int nonce, const std::string& hostAddress) - { - onPresenceListener->onPresenceCallback(result, nonce, hostAddress); - }; - - OCPlatform::OCPresenceHandle presenceHandle; - try - { - OCStackResult result = OCPlatform::subscribePresence( - presenceHandle, - host, - resourceType, - JniUtils::getConnectivityType(env, static_cast(jConnectivityType)), - subscribeCallback); - - if (OC_STACK_OK != result) ++ if (jSupportUrl) + { - ThrowOcException(result, "subscribe presence has failed"); ++ supportUrl = env->GetStringUTFChars(jSupportUrl, NULL); ++ } ++ if (jSystemTime) ++ { ++ systemTime = env->GetStringUTFChars(jSystemTime, NULL); + } - } - catch (OCException& e) - { - LOGE("%s", e.reason().c_str()); - ThrowOcException(OC_STACK_ERROR, e.reason().c_str()); - return nullptr; - } - - JniOcPresenceHandle* jniPresenceHandle = new JniOcPresenceHandle(onPresenceListener, 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; - } - - /* - * Class: org_iotivity_base_OcPlatform - * Method: unsubscribePresence0 - * Signature: (Lorg/iotivity/base/OcPresenceHandle;)V - */ - JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_unsubscribePresence0 - (JNIEnv *env, jclass clazz, jobject jPresenceHandle) - { - LOGD("OcPlatform_unsubscribePresence"); - if (!jPresenceHandle) - { - ThrowOcException(OC_STACK_INVALID_PARAM, "presenceHandle cannot be null"); - return; - } - JniOcPresenceHandle* jniPresenceHandle = JniOcPresenceHandle::getJniOcPresenceHandlePtr(env, jPresenceHandle); - if (!jniPresenceHandle) return; - - OCPresenceHandle presenceHandle = jniPresenceHandle->getOCPresenceHandle(); - - try - { - OCStackResult result = OCPlatform::unsubscribePresence(presenceHandle); + - if (OC_STACK_OK != result) ++ OCPlatformInfo platformInfo; ++ try + { - ThrowOcException(result, "unsubscribe presence has failed"); - return; ++ DuplicateString(&platformInfo.platformID, platformID); ++ DuplicateString(&platformInfo.manufacturerName, manufacturerName); ++ DuplicateString(&platformInfo.manufacturerUrl, manufacturerUrl); ++ DuplicateString(&platformInfo.modelNumber, modelNumber); ++ DuplicateString(&platformInfo.dateOfManufacture, dateOfManufacture); ++ DuplicateString(&platformInfo.platformVersion, platformVersion); ++ DuplicateString(&platformInfo.operatingSystemVersion, operatingSystemVersion); ++ DuplicateString(&platformInfo.hardwareVersion, hardwareVersion); ++ DuplicateString(&platformInfo.firmwareVersion, firmwareVersion); ++ DuplicateString(&platformInfo.supportUrl, supportUrl); ++ DuplicateString(&platformInfo.systemTime, systemTime); + } - jweak jwOnPresenceListener = jniPresenceHandle->getJniOnPresenceListener()->getJWListener(); - if (jwOnPresenceListener) ++ catch (std::exception &e) + { - RemoveOnPresenceListener(env, jwOnPresenceListener); ++ ThrowOcException(JNI_EXCEPTION, "Failed to construct platform info"); ++ return; + } - } - catch (OCException& e) - { - LOGE("%s", e.reason().c_str()); - ThrowOcException(OC_STACK_ERROR, e.reason().c_str()); - } - } - - /* - * Class: org_iotivity_base_OcPlatform - * Method: constructResourceObject0 - * Signature: (Ljava/lang/String;Ljava/lang/String;IZ[Ljava/lang/String;[Ljava/lang/String;) - Lorg/iotivity/base/OcResource; - */ - JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcPlatform_constructResourceObject0 - (JNIEnv *env, jclass clazz, jstring jHost, jstring jUri, jint jConnectivityType, - jboolean jIsObservable, jobjectArray jResourceTypeArray, jobjectArray jInterfaceArray) - { - LOGD("OcPlatform_constructResourceObject"); - std::string host; - if (jHost) - { - host = env->GetStringUTFChars(jHost, NULL); - } - std::string uri; - if (jUri) - { - uri = env->GetStringUTFChars(jUri, NULL); - } - if (!jResourceTypeArray) - { - ThrowOcException(OC_STACK_INVALID_PARAM, "resourceTypeList cannot be null"); - return nullptr; - } - if (!jInterfaceArray) - { - ThrowOcException(OC_STACK_INVALID_PARAM, "interfaceList cannot be null"); - return nullptr; - } + - std::vector resourceTypes; - JniUtils::convertJavaStrArrToStrVector(env, jResourceTypeArray, resourceTypes); ++ // __android_log_print(ANDROID_LOG_INFO, "Rahul", "platformID = %s", platformID); ++ try ++ { ++ OCStackResult result = OCPlatform::registerPlatformInfo(platformInfo); + - std::vector interfaces; - JniUtils::convertJavaStrArrToStrVector(env, jInterfaceArray, interfaces); ++ delete platformInfo.platformID; ++ delete platformInfo.manufacturerName; ++ delete platformInfo.manufacturerUrl; ++ delete platformInfo.modelNumber; ++ delete platformInfo.dateOfManufacture; ++ delete platformInfo.platformVersion; ++ delete platformInfo.operatingSystemVersion; ++ delete platformInfo.hardwareVersion; ++ delete platformInfo.firmwareVersion; ++ delete platformInfo.supportUrl; ++ delete platformInfo.systemTime; + - std::shared_ptr resource = OCPlatform::constructResourceObject( - host, - uri, - JniUtils::getConnectivityType(env, static_cast(jConnectivityType)), - static_cast(jIsObservable), - resourceTypes, - interfaces); ++ if (OC_STACK_OK != result) ++ { ++ ThrowOcException(result, "Failed to register platform info"); ++ return; ++ } ++ } ++ catch (OCException& e) ++ { ++ LOGE("Error is due to %s", e.reason().c_str()); ++ ThrowOcException(OC_STACK_ERROR, e.reason().c_str()); ++ } + - if (!resource) - { - ThrowOcException(OC_STACK_ERROR, "Failed to create OCResource"); - return nullptr; - } + - JniOcResource *jniOcResource = new JniOcResource(resource); - jlong handle = reinterpret_cast(jniOcResource); + - jobject jResource = env->NewObject(g_cls_OcResource, g_mid_OcResource_ctor); - if (!jResource) - { - delete jniOcResource; - return nullptr; - } - SetHandle(env, jResource, jniOcResource); - if (env->ExceptionCheck()) - { - delete jniOcResource; - return nullptr; - } - return jResource; +} + +/* +* Class: org_iotivity_base_OcPlatform - * Method: sendResponse0 - * Signature: (Lorg/iotivity/base/OcResourceResponse;)V - */ - JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_sendResponse0 - (JNIEnv *env, jclass clazz, jobject jResourceResponse) - { - LOGD("OcPlatform_sendResponse"); - if (!jResourceResponse) - { - ThrowOcException(OC_STACK_INVALID_PARAM, "resourceResponse cannot be null"); - return; - } - - JniOcResourceResponse *jniResponse = JniOcResourceResponse::getJniOcResourceResponsePtr( - env, jResourceResponse); - if (!jniResponse) return; - - try - { - OCStackResult result = OCPlatform::sendResponse(jniResponse->getOCResourceResponse()); - - if (OC_STACK_OK != result) - { - ThrowOcException(result, "failed to send response"); - } - } - catch (OCException& e) - { - LOGE("%s", e.reason().c_str()); - ThrowOcException(OC_STACK_ERROR, e.reason().c_str()); - } + * Method: unregisterResource0 + * Signature: (Lorg/iotivity/base/OcResourceHandle;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_unregisterResource0 + (JNIEnv *env, jclass clazz, jobject jResourceHandle) + { + LOGI("OcPlatform_unregisterResource"); + if (!jResourceHandle) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "resourceHandle cannot be null"); + return; + } + JniOcResourceHandle* jniOcResourceHandle = JniOcResourceHandle::getJniOcResourceHandlePtr( + env, jResourceHandle); + if (!jniOcResourceHandle) return; + + try + { + OCResourceHandle resHandle = jniOcResourceHandle->getOCResourceHandle(); + OCStackResult result = OCPlatform::unregisterResource(resHandle); + if (OC_STACK_OK != result) + { + ThrowOcException(result, "Failed to unregister resource"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(OC_STACK_ERROR, e.reason().c_str()); + } + } + + /* + * Class: org_iotivity_base_OcPlatform + * Method: bindResource0 + * Signature: (Lorg/iotivity/base/OcResourceHandle;Lorg/iotivity/base/OcResourceHandle;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_bindResource0 + (JNIEnv *env, jclass clazz, jobject jResourceCollectionHandle, jobject jResourceHandle) + { + LOGI("OcPlatform_bindResource"); + if (!jResourceCollectionHandle) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "resourceCollectionHandle cannot be null"); + return; + } + if (!jResourceHandle) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "resourceHandle cannot be null"); + return; + } + JniOcResourceHandle* jniOcResourceCollectionHandle = JniOcResourceHandle::getJniOcResourceHandlePtr( + env, jResourceCollectionHandle); + if (!jniOcResourceCollectionHandle) return; + + JniOcResourceHandle* jniOcResourceHandle = JniOcResourceHandle::getJniOcResourceHandlePtr( + env, jResourceHandle); + if (!jniOcResourceHandle) return; + + try + { + OCStackResult result = OCPlatform::bindResource( + jniOcResourceCollectionHandle->getOCResourceHandle(), + jniOcResourceHandle->getOCResourceHandle() + ); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "Failed to bind resource"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(OC_STACK_ERROR, e.reason().c_str()); + } + } + + /* + * Class: org_iotivity_base_OcPlatform + * Method: bindResources0 + * Signature: (Lorg/iotivity/base/OcResourceHandle;[Lorg/iotivity/base/OcResourceHandle;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_bindResources0 + (JNIEnv *env, jclass clazz, jobject jResourceCollectionHandle, jobjectArray jResourceHandleArray) + { + LOGI("OcPlatform_bindResources"); + + if (!jResourceCollectionHandle) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "resourceCollectionHandle cannot be null"); + return; + } + if (!jResourceHandleArray) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "resourceHandleList cannot be null"); + return; + } + + JniOcResourceHandle* jniOcResourceCollectionHandle = JniOcResourceHandle::getJniOcResourceHandlePtr( + env, jResourceCollectionHandle); + if (!jniOcResourceCollectionHandle) return; + + std::vector resourceHandleList; + int len = env->GetArrayLength(jResourceHandleArray); + for (int 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) return; + + resourceHandleList.push_back( + jniOcResourceHandle->getOCResourceHandle()); + } + + try + { + OCStackResult result = OCPlatform::bindResources( + jniOcResourceCollectionHandle->getOCResourceHandle(), + resourceHandleList + ); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "Failed to bind resources"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(OC_STACK_ERROR, e.reason().c_str()); + } + } + + /* + * Class: org_iotivity_base_OcPlatform + * Method: unbindResource0 + * Signature: (Lorg/iotivity/base/OcResourceHandle;Lorg/iotivity/base/OcResourceHandle;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_unbindResource0 + (JNIEnv *env, jclass clazz, jobject jResourceCollectionHandle, jobject jResourceHandle) + { + LOGI("OcPlatform_unbindResource"); + if (!jResourceCollectionHandle) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "resourceCollectionHandle cannot be null"); + return; + } + if (!jResourceHandle) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "resourceHandle cannot be null"); + return; + } + + JniOcResourceHandle* jniOcResourceCollectionHandle = JniOcResourceHandle::getJniOcResourceHandlePtr( + env, jResourceCollectionHandle); + if (!jniOcResourceCollectionHandle) return; + + JniOcResourceHandle* jniOcResourceHandle = JniOcResourceHandle::getJniOcResourceHandlePtr( + env, jResourceHandle); + if (!jniOcResourceHandle) return; + + try + { + OCStackResult result = OCPlatform::unbindResource( + jniOcResourceCollectionHandle->getOCResourceHandle(), + jniOcResourceHandle->getOCResourceHandle() + ); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "Failed to unbind resource"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(OC_STACK_ERROR, e.reason().c_str()); + } + } + + /* + * Class: org_iotivity_base_OcPlatform + * Method: unbindResources0 + * Signature: (Lorg/iotivity/base/OcResourceHandle;[Lorg/iotivity/base/OcResourceHandle;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_unbindResources0 + (JNIEnv *env, jclass clazz, jobject jResourceCollectionHandle, jobjectArray jResourceHandleArray) + { + LOGI("OcPlatform_unbindResources"); + if (!jResourceCollectionHandle) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "resourceCollectionHandle cannot be null"); + return; + } + if (!jResourceHandleArray) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "resourceHandleList cannot be null"); + return; + } + + JniOcResourceHandle* jniOcResourceCollectionHandle = JniOcResourceHandle::getJniOcResourceHandlePtr( + env, jResourceCollectionHandle); + if (!jniOcResourceCollectionHandle) return; + + std::vector resourceHandleList; + int len = env->GetArrayLength(jResourceHandleArray); + for (int 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) return; + + resourceHandleList.push_back( + jniOcResourceHandle->getOCResourceHandle()); + } + + try + { + OCStackResult result = OCPlatform::unbindResources( + jniOcResourceCollectionHandle->getOCResourceHandle(), + resourceHandleList + ); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "Failed to unbind resources"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(OC_STACK_ERROR, e.reason().c_str()); + } + } + + /* + * Class: org_iotivity_base_OcPlatform + * Method: bindTypeToResource0 + * Signature: (Lorg/iotivity/base/OcResourceHandle;Ljava/lang/String;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_bindTypeToResource0 + (JNIEnv *env, jclass clazz, jobject jResourceHandle, jstring jResourceTypeName) + { + LOGI("OcPlatform_bindTypeToResource"); + if (!jResourceHandle) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "resourceHandle cannot be null"); + return; + } + std::string typeName; + if (jResourceTypeName) + { + typeName = env->GetStringUTFChars(jResourceTypeName, NULL); + } + + JniOcResourceHandle* jniOcResourceHandle = JniOcResourceHandle::getJniOcResourceHandlePtr( + env, jResourceHandle); + if (!jniOcResourceHandle) return; + + try + { + OCStackResult result = OCPlatform::bindTypeToResource( + jniOcResourceHandle->getOCResourceHandle(), + typeName + ); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "Failed to bind type to resource"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(OC_STACK_ERROR, e.reason().c_str()); + } + } + + /* + * Class: org_iotivity_base_OcPlatform + * Method: bindInterfaceToResource0 + * Signature: (Lorg/iotivity/base/OcResourceHandle;Ljava/lang/String;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_bindInterfaceToResource0 + (JNIEnv *env, jclass clazz, jobject jResourceHandle, jstring jResourceInterfaceName) + { + LOGI("OcPlatform_bindInterfaceToResource"); + if (!jResourceHandle) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "resourceHandle cannot be null"); + return; + } + std::string interfaceName; + if (jResourceInterfaceName) + { + interfaceName = env->GetStringUTFChars(jResourceInterfaceName, NULL); + } + + JniOcResourceHandle* jniOcResourceHandle = JniOcResourceHandle::getJniOcResourceHandlePtr( + env, jResourceHandle); + if (!jniOcResourceHandle) return; + + try + { + OCStackResult result = OCPlatform::bindInterfaceToResource( + jniOcResourceHandle->getOCResourceHandle(), + interfaceName + ); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "Failed to bind interface to resource"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(OC_STACK_ERROR, e.reason().c_str()); + } + } + + /* + * Class: org_iotivity_base_OcPlatform + * Method: startPresence0 + * Signature: (I)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_startPresence0 + (JNIEnv *env, jclass clazz, jint ttl) + { + LOGI("OcPlatform_startPresence"); + + try + { + OCStackResult result = OCPlatform::startPresence((unsigned int)ttl); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "Failed to start presence"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(OC_STACK_ERROR, e.reason().c_str()); + } + } + + /* + * Class: org_iotivity_base_OcPlatform + * Method: stopPresence0 + * Signature: ()V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_stopPresence0 + (JNIEnv *env, jclass clazz) + { + LOGI("OcPlatform_stopPresence"); + + try + { + OCStackResult result = OCPlatform::stopPresence(); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "Failed to stop presence"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(OC_STACK_ERROR, e.reason().c_str()); + } + } + + /* + * Class: org_iotivity_base_OcPlatform + * Method: subscribePresence0 + * Signature: (Ljava/lang/String;ILorg/iotivity/base/OcPlatform/OnPresenceListener;)Lorg/iotivity/base/OcPresenceHandle; + */ + JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcPlatform_subscribePresence0 + (JNIEnv *env, jclass clazz, jstring jHost, jint jConnectivityType, jobject jListener) + { + LOGD("OcPlatform_subscribePresence"); + std::string host; + if (jHost) + { + host = env->GetStringUTFChars(jHost, NULL); + } + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "onPresenceListener cannot be null"); + return nullptr; + } + + JniOnPresenceListener *onPresenceListener = AddOnPresenceListener(env, jListener); + + SubscribeCallback subscribeCallback = [onPresenceListener](OCStackResult result, const unsigned int nonce, + const std::string& hostAddress) + { + onPresenceListener->onPresenceCallback(result, nonce, hostAddress); + }; + + OCPlatform::OCPresenceHandle presenceHandle; + try + { + OCStackResult result = OCPlatform::subscribePresence( + presenceHandle, + host, + JniUtils::getConnectivityType(env, static_cast(jConnectivityType)), + subscribeCallback); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "subscribe presence has failed"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(OC_STACK_ERROR, e.reason().c_str()); + return nullptr; + } + + JniOcPresenceHandle* jniPresenceHandle = new JniOcPresenceHandle(onPresenceListener, 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; + } + + /* + * Class: org_iotivity_base_OcPlatform + * Method: subscribePresence1 + * Signature: (Ljava/lang/String;Ljava/lang/String;I + Lorg/iotivity/base/OcPlatform/OnPresenceListener;)Lorg/iotivity/base/OcPresenceHandle; + */ + JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcPlatform_subscribePresence1 + (JNIEnv *env, jclass clazz, jstring jHost, jstring jResourceType, jint jConnectivityType, jobject jListener) + { + LOGD("OcPlatform_subscribePresence1"); + std::string host; + if (jHost) + { + host = env->GetStringUTFChars(jHost, NULL); + } + std::string resourceType; + if (jResourceType) + { + resourceType = env->GetStringUTFChars(jResourceType, NULL); + } + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "onPresenceListener cannot be null"); + return nullptr; + } + + JniOnPresenceListener *onPresenceListener = AddOnPresenceListener(env, jListener); + + SubscribeCallback subscribeCallback = [onPresenceListener](OCStackResult result, + const unsigned int nonce, const std::string& hostAddress) + { + onPresenceListener->onPresenceCallback(result, nonce, hostAddress); + }; + + OCPlatform::OCPresenceHandle presenceHandle; + try + { + OCStackResult result = OCPlatform::subscribePresence( + presenceHandle, + host, + resourceType, + JniUtils::getConnectivityType(env, static_cast(jConnectivityType)), + subscribeCallback); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "subscribe presence has failed"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(OC_STACK_ERROR, e.reason().c_str()); + return nullptr; + } + + JniOcPresenceHandle* jniPresenceHandle = new JniOcPresenceHandle(onPresenceListener, 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; + } + + /* + * Class: org_iotivity_base_OcPlatform + * Method: unsubscribePresence0 + * Signature: (Lorg/iotivity/base/OcPresenceHandle;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_unsubscribePresence0 + (JNIEnv *env, jclass clazz, jobject jPresenceHandle) + { + LOGD("OcPlatform_unsubscribePresence"); + if (!jPresenceHandle) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "presenceHandle cannot be null"); + return; + } + JniOcPresenceHandle* jniPresenceHandle = JniOcPresenceHandle::getJniOcPresenceHandlePtr(env, jPresenceHandle); + if (!jniPresenceHandle) return; + + OCPresenceHandle presenceHandle = jniPresenceHandle->getOCPresenceHandle(); + + try + { + OCStackResult result = OCPlatform::unsubscribePresence(presenceHandle); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "unsubscribe presence has failed"); + return; + } + jweak jwOnPresenceListener = jniPresenceHandle->getJniOnPresenceListener()->getJWListener(); + if (jwOnPresenceListener) + { + RemoveOnPresenceListener(env, jwOnPresenceListener); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(OC_STACK_ERROR, e.reason().c_str()); + } + } + + /* + * Class: org_iotivity_base_OcPlatform + * Method: constructResourceObject0 + * Signature: (Ljava/lang/String;Ljava/lang/String;IZ[Ljava/lang/String;[Ljava/lang/String;) + Lorg/iotivity/base/OcResource; + */ + JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcPlatform_constructResourceObject0 + (JNIEnv *env, jclass clazz, jstring jHost, jstring jUri, jint jConnectivityType, + jboolean jIsObservable, jobjectArray jResourceTypeArray, jobjectArray jInterfaceArray) + { + LOGD("OcPlatform_constructResourceObject"); + std::string host; + if (jHost) + { + host = env->GetStringUTFChars(jHost, NULL); + } + std::string uri; + if (jUri) + { + uri = env->GetStringUTFChars(jUri, NULL); + } + if (!jResourceTypeArray) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "resourceTypeList cannot be null"); + return nullptr; + } + if (!jInterfaceArray) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "interfaceList cannot be null"); + return nullptr; + } + + std::vector resourceTypes; + JniUtils::convertJavaStrArrToStrVector(env, jResourceTypeArray, resourceTypes); + + std::vector interfaces; + JniUtils::convertJavaStrArrToStrVector(env, jInterfaceArray, interfaces); + + std::shared_ptr resource = OCPlatform::constructResourceObject( + host, + uri, + JniUtils::getConnectivityType(env, static_cast(jConnectivityType)), + static_cast(jIsObservable), + resourceTypes, + interfaces); + + if (!resource) + { + ThrowOcException(OC_STACK_ERROR, "Failed to create OCResource"); + return nullptr; + } + + JniOcResource *jniOcResource = new JniOcResource(resource); + jlong handle = reinterpret_cast(jniOcResource); + + jobject jResource = env->NewObject(g_cls_OcResource, g_mid_OcResource_ctor); + if (!jResource) + { + delete jniOcResource; + return nullptr; + } + SetHandle(env, jResource, jniOcResource); + if (env->ExceptionCheck()) + { + delete jniOcResource; + return nullptr; + } + return jResource; + } + + /* + * Class: org_iotivity_base_OcPlatform + * Method: sendResponse0 + * Signature: (Lorg/iotivity/base/OcResourceResponse;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_sendResponse0 + (JNIEnv *env, jclass clazz, jobject jResourceResponse) + { + LOGD("OcPlatform_sendResponse"); + if (!jResourceResponse) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "resourceResponse cannot be null"); + return; + } + + JniOcResourceResponse *jniResponse = JniOcResourceResponse::getJniOcResourceResponsePtr( + env, jResourceResponse); + if (!jniResponse) return; + + try + { + OCStackResult result = OCPlatform::sendResponse(jniResponse->getOCResourceResponse()); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "failed to send response"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(OC_STACK_ERROR, e.reason().c_str()); + } } diff --cc android/android_api/base/jni/JniOcPlatform.h index 62c9938,eb23a8b..ca7051e --- a/android/android_api/base/jni/JniOcPlatform.h +++ b/android/android_api/base/jni/JniOcPlatform.h @@@ -1,295 -1,264 +1,295 @@@ - /* - * //****************************************************************** - * // - * // 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 "JniOcStack.h" - #include "JniOnResourceFoundListener.h" - #include "JniOnDeviceInfoListener.h" + /* + * //****************************************************************** + * // + * // 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 "JniOcStack.h" + #include "JniOnResourceFoundListener.h" + #include "JniOnDeviceInfoListener.h" +#include "JniOnPlatformInfoListener.h" - #include "JniOnPresenceListener.h" - #include - - #ifndef _Included_org_iotivity_base_OcPlatform - #define _Included_org_iotivity_base_OcPlatform - - using namespace OC; - - JniOnResourceFoundListener* AddOnResourceFoundListener(JNIEnv* env, jobject jListener); - void RemoveOnResourceFoundListener(JNIEnv* env, jobject jListener); - - JniOnDeviceInfoListener* AddOnDeviceInfoListener(JNIEnv* env, jobject jListener); - void RemoveOnDeviceInfoListener(JNIEnv* env, jobject jListener); - + #include "JniOnPresenceListener.h" + #include + + #ifndef _Included_org_iotivity_base_OcPlatform + #define _Included_org_iotivity_base_OcPlatform + + using namespace OC; + + JniOnResourceFoundListener* AddOnResourceFoundListener(JNIEnv* env, jobject jListener); + void RemoveOnResourceFoundListener(JNIEnv* env, jobject jListener); + + JniOnDeviceInfoListener* AddOnDeviceInfoListener(JNIEnv* env, jobject jListener); + void RemoveOnDeviceInfoListener(JNIEnv* env, jobject jListener); + +JniOnPlatformInfoListener* AddOnPlatformInfoListener(JNIEnv* env, jobject jListener); +void RemoveOnPlatformInfoListener(JNIEnv* env, jobject jListener); + - JniOnPresenceListener* AddOnPresenceListener(JNIEnv* env, jobject jListener); - void RemoveOnPresenceListener(JNIEnv* env, jobject jListener); - - std::map> onResourceFoundListenerMap; - std::map> onDeviceInfoListenerMap; + JniOnPresenceListener* AddOnPresenceListener(JNIEnv* env, jobject jListener); + void RemoveOnPresenceListener(JNIEnv* env, jobject jListener); + + std::map> onResourceFoundListenerMap; + std::map> onDeviceInfoListenerMap; +std::map> onPlatformInfoListenerMap; - std::map> onPresenceListenerMap; - - std::mutex resourceFoundMapLock; - std::mutex deviceInfoMapLock; + std::map> onPresenceListenerMap; + + std::mutex resourceFoundMapLock; + std::mutex deviceInfoMapLock; +std::mutex platformInfoMapLock; - std::mutex presenceMapLock; - - #ifdef __cplusplus - extern "C" { - #endif - /* - * Class: org_iotivity_base_OcPlatform - * Method: configure - * Signature: (IILjava/lang/String;II)V - */ - JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_configure - (JNIEnv *, jclass, jint, jint, jstring, jint, jint); - - /* - * Class: org_iotivity_base_OcPlatform - * Method: notifyAllObservers0 - * Signature: (Lorg/iotivity/base/OcResourceHandle;)V - */ - JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_notifyAllObservers0 - (JNIEnv *, jclass, jobject); - - /* - * Class: org_iotivity_base_OcPlatform - * Method: notifyAllObservers1 - * Signature: (Lorg/iotivity/base/OcResourceHandle;I)V - */ - JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_notifyAllObservers1 - (JNIEnv *, jclass, jobject, jint); - - /* - * Class: org_iotivity_base_OcPlatform - * Method: notifyListOfObservers2 - * Signature: (Lorg/iotivity/base/OcResourceHandle;[BLorg/iotivity/base/OcResourceResponse;)V - */ - JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_notifyListOfObservers2 - (JNIEnv *, jclass, jobject, jbyteArray, jobject); - - /* - * Class: org_iotivity_base_OcPlatform - * Method: notifyListOfObservers3 - * Signature: (Lorg/iotivity/base/OcResourceHandle;[BLorg/iotivity/base/OcResourceResponse;I)V - */ - JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_notifyListOfObservers3 - (JNIEnv *, jclass, jobject, jbyteArray, jobject, jint); - - /* - * Class: org_iotivity_base_OcPlatform - * Method: findResource0 - * Signature: (Ljava/lang/String;Ljava/lang/String;ILorg/iotivity/base/OcPlatform/OnResourceFoundListener;)V - */ - JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_findResource0 - (JNIEnv *, jclass, jstring, jstring, jint, jobject); - - /* - * Class: org_iotivity_base_OcPlatform - * Method: findResource1 - * Signature: (Ljava/lang/String;Ljava/lang/String;ILorg/iotivity/base/OcPlatform/OnResourceFoundListener;I)V - */ - JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_findResource1 - (JNIEnv *, jclass, jstring, jstring, jint, jobject, jint); - - /* - * Class: org_iotivity_base_OcPlatform - * Method: getDeviceInfo0 - * Signature: (Ljava/lang/String;Ljava/lang/String;ILorg/iotivity/base/OcPlatform/OnDeviceFoundListener;)V - */ - JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_getDeviceInfo0 - (JNIEnv *, jclass, jstring, jstring, jint, jobject); - - /* - * Class: org_iotivity_base_OcPlatform - * Method: getDeviceInfo1 - * Signature: (Ljava/lang/String;Ljava/lang/String;ILorg/iotivity/base/OcPlatform/OnDeviceFoundListener;I)V - */ - JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_getDeviceInfo1 + std::mutex presenceMapLock; + + #ifdef __cplusplus + extern "C" { + #endif + /* + * Class: org_iotivity_base_OcPlatform + * Method: configure + * Signature: (IILjava/lang/String;II)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_configure + (JNIEnv *, jclass, jint, jint, jstring, jint, jint, jstring); + + /* + * Class: org_iotivity_base_OcPlatform + * Method: notifyAllObservers0 + * Signature: (Lorg/iotivity/base/OcResourceHandle;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_notifyAllObservers0 + (JNIEnv *, jclass, jobject); + + /* + * Class: org_iotivity_base_OcPlatform + * Method: notifyAllObservers1 + * Signature: (Lorg/iotivity/base/OcResourceHandle;I)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_notifyAllObservers1 + (JNIEnv *, jclass, jobject, jint); + + /* + * Class: org_iotivity_base_OcPlatform + * Method: notifyListOfObservers2 + * Signature: (Lorg/iotivity/base/OcResourceHandle;[BLorg/iotivity/base/OcResourceResponse;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_notifyListOfObservers2 + (JNIEnv *, jclass, jobject, jbyteArray, jobject); + + /* + * Class: org_iotivity_base_OcPlatform + * Method: notifyListOfObservers3 + * Signature: (Lorg/iotivity/base/OcResourceHandle;[BLorg/iotivity/base/OcResourceResponse;I)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_notifyListOfObservers3 + (JNIEnv *, jclass, jobject, jbyteArray, jobject, jint); + + /* + * Class: org_iotivity_base_OcPlatform + * Method: findResource0 + * Signature: (Ljava/lang/String;Ljava/lang/String;ILorg/iotivity/base/OcPlatform/OnResourceFoundListener;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_findResource0 + (JNIEnv *, jclass, jstring, jstring, jint, jobject); + + /* + * Class: org_iotivity_base_OcPlatform + * Method: findResource1 + * Signature: (Ljava/lang/String;Ljava/lang/String;ILorg/iotivity/base/OcPlatform/OnResourceFoundListener;I)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_findResource1 + (JNIEnv *, jclass, jstring, jstring, jint, jobject, jint); + + /* + * Class: org_iotivity_base_OcPlatform + * Method: getDeviceInfo0 + * Signature: (Ljava/lang/String;Ljava/lang/String;ILorg/iotivity/base/OcPlatform/OnDeviceFoundListener;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_getDeviceInfo0 + (JNIEnv *, jclass, jstring, jstring, jint, jobject); + + /* + * Class: org_iotivity_base_OcPlatform + * Method: getDeviceInfo1 + * Signature: (Ljava/lang/String;Ljava/lang/String;ILorg/iotivity/base/OcPlatform/OnDeviceFoundListener;I)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_getDeviceInfo1 + (JNIEnv *, jclass, jstring, jstring, jint, jobject, jint); + + /* + * Class: org_iotivity_base_OcPlatform + * Method: getPlatformInfo0 + * Signature: (Ljava/lang/String;Ljava/lang/String;ILorg/iotivity/base/OcPlatform/OnPlatformFoundListener;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_getPlatformInfo0 + (JNIEnv *, jclass, jstring, jstring, jint, jobject); + + /* + * Class: org_iotivity_base_OcPlatform + * Method: getPlatformInfo1 + * Signature: (Ljava/lang/String;Ljava/lang/String;ILorg/iotivity/base/OcPlatform/OnPlatformFoundListener;I)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_getPlatformInfo1 - (JNIEnv *, jclass, jstring, jstring, jint, jobject, jint); - - /* - * Class: org_iotivity_base_OcPlatform - * Method: registerResource0 - * Signature: (Lorg/iotivity/base/OcResource;)Lorg/iotivity/base/OcResourceHandle; - */ - JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcPlatform_registerResource0 - (JNIEnv *, jclass, jobject); - - /* - * Class: org_iotivity_base_OcPlatform - * Method: registerResource1 - * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lorg/iotivity/base/OcPlatform/EntityHandler;I)Lorg/iotivity/base/OcResourceHandle; - */ - JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcPlatform_registerResource1 - (JNIEnv *, jclass, jstring, jstring, jstring, jobject, jint); - - /* - * Class: org_iotivity_base_OcPlatform - * Method: registerDeviceInfo0 + (JNIEnv *, jclass, jstring, jstring, jint, jobject, jint); + + /* + * Class: org_iotivity_base_OcPlatform + * Method: registerResource0 + * Signature: (Lorg/iotivity/base/OcResource;)Lorg/iotivity/base/OcResourceHandle; + */ + JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcPlatform_registerResource0 + (JNIEnv *, jclass, jobject); + + /* + * Class: org_iotivity_base_OcPlatform + * Method: registerResource1 + * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lorg/iotivity/base/OcPlatform/EntityHandler;I)Lorg/iotivity/base/OcResourceHandle; + */ + JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcPlatform_registerResource1 + (JNIEnv *, jclass, jstring, jstring, jstring, jobject, jint); + + /* + * Class: org_iotivity_base_OcPlatform + * Method: registerDeviceInfo0 - * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V + * Signature: (Ljava/lang/String;)V - */ - JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_registerDeviceInfo0 + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_registerDeviceInfo0 - (JNIEnv *, jclass, jstring, jstring, jstring, jstring, jstring, jstring, jstring, jstring, jstring, jstring, jstring, jstring); + (JNIEnv *, jclass, jstring); + + /* + * Class: org_iotivity_base_OcPlatform + * Method: registerPlatformInfo0 + * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_registerPlatformInfo0 + (JNIEnv *, jclass, jstring, jstring, jstring, jstring, jstring, jstring, jstring, jstring, jstring, jstring, jstring); - - /* - * Class: org_iotivity_base_OcPlatform - * Method: unregisterResource0 - * Signature: (Lorg/iotivity/base/OcResourceHandle;)V - */ - JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_unregisterResource0 - (JNIEnv *, jclass, jobject); - - /* - * Class: org_iotivity_base_OcPlatform - * Method: bindResource0 - * Signature: (Lorg/iotivity/base/OcResourceHandle;Lorg/iotivity/base/OcResourceHandle;)V - */ - JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_bindResource0 - (JNIEnv *, jclass, jobject, jobject); - - /* - * Class: org_iotivity_base_OcPlatform - * Method: bindResources0 - * Signature: (Lorg/iotivity/base/OcResourceHandle;[Lorg/iotivity/base/OcResourceHandle;)V - */ - JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_bindResources0 - (JNIEnv *, jclass, jobject, jobjectArray); - - /* - * Class: org_iotivity_base_OcPlatform - * Method: unbindResource0 - * Signature: (Lorg/iotivity/base/OcResourceHandle;Lorg/iotivity/base/OcResourceHandle;)V - */ - JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_unbindResource0 - (JNIEnv *, jclass, jobject, jobject); - - /* - * Class: org_iotivity_base_OcPlatform - * Method: unbindResources0 - * Signature: (Lorg/iotivity/base/OcResourceHandle;[Lorg/iotivity/base/OcResourceHandle;)V - */ - JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_unbindResources0 - (JNIEnv *, jclass, jobject, jobjectArray); - - /* - * Class: org_iotivity_base_OcPlatform - * Method: bindTypeToResource0 - * Signature: (Lorg/iotivity/base/OcResourceHandle;Ljava/lang/String;)V - */ - JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_bindTypeToResource0 - (JNIEnv *, jclass, jobject, jstring); - - /* - * Class: org_iotivity_base_OcPlatform - * Method: bindInterfaceToResource0 - * Signature: (Lorg/iotivity/base/OcResourceHandle;Ljava/lang/String;)V - */ - JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_bindInterfaceToResource0 - (JNIEnv *, jclass, jobject, jstring); - - /* - * Class: org_iotivity_base_OcPlatform - * Method: startPresence0 - * Signature: (I)V - */ - JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_startPresence0 - (JNIEnv *, jclass, jint); - - /* - * Class: org_iotivity_base_OcPlatform - * Method: stopPresence0 - * Signature: ()V - */ - JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_stopPresence0 - (JNIEnv *, jclass); - - /* - * Class: org_iotivity_base_OcPlatform - * Method: subscribePresence0 - * Signature: (Ljava/lang/String;ILorg/iotivity/base/OcPlatform/OnPresenceListener;)Lorg/iotivity/base/OcPresenceHandle; - */ - JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcPlatform_subscribePresence0 - (JNIEnv *, jclass, jstring, jint, jobject); - - /* - * Class: org_iotivity_base_OcPlatform - * Method: subscribePresence1 - * Signature: (Ljava/lang/String;Ljava/lang/String;ILorg/iotivity/base/OcPlatform/OnPresenceListener;)Lorg/iotivity/base/OcPresenceHandle; - */ - JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcPlatform_subscribePresence1 - (JNIEnv *, jclass, jstring, jstring, jint, jobject); - - /* - * Class: org_iotivity_base_OcPlatform - * Method: unsubscribePresence0 - * Signature: (Lorg/iotivity/base/OcPresenceHandle;)V - */ - JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_unsubscribePresence0 - (JNIEnv *, jclass, jobject); - - /* - * Class: org_iotivity_base_OcPlatform - * Method: constructResourceObject0 - * Signature: (Ljava/lang/String;Ljava/lang/String;IZ[Ljava/lang/String;[Ljava/lang/String;)Lorg/iotivity/base/OcResource; - */ - JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcPlatform_constructResourceObject0 - (JNIEnv *, jclass, jstring, jstring, jint, jboolean, jobjectArray, jobjectArray); - - /* - * Class: org_iotivity_base_OcPlatform0 - * Method: sendResponse0 - * Signature: (Lorg/iotivity/base/OcResourceResponse;)V - */ - JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_sendResponse0 - (JNIEnv *, jclass, jobject); - - #ifdef __cplusplus - } - #endif - #endif + + /* + * Class: org_iotivity_base_OcPlatform + * Method: unregisterResource0 + * Signature: (Lorg/iotivity/base/OcResourceHandle;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_unregisterResource0 + (JNIEnv *, jclass, jobject); + + /* + * Class: org_iotivity_base_OcPlatform + * Method: bindResource0 + * Signature: (Lorg/iotivity/base/OcResourceHandle;Lorg/iotivity/base/OcResourceHandle;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_bindResource0 + (JNIEnv *, jclass, jobject, jobject); + + /* + * Class: org_iotivity_base_OcPlatform + * Method: bindResources0 + * Signature: (Lorg/iotivity/base/OcResourceHandle;[Lorg/iotivity/base/OcResourceHandle;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_bindResources0 + (JNIEnv *, jclass, jobject, jobjectArray); + + /* + * Class: org_iotivity_base_OcPlatform + * Method: unbindResource0 + * Signature: (Lorg/iotivity/base/OcResourceHandle;Lorg/iotivity/base/OcResourceHandle;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_unbindResource0 + (JNIEnv *, jclass, jobject, jobject); + + /* + * Class: org_iotivity_base_OcPlatform + * Method: unbindResources0 + * Signature: (Lorg/iotivity/base/OcResourceHandle;[Lorg/iotivity/base/OcResourceHandle;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_unbindResources0 + (JNIEnv *, jclass, jobject, jobjectArray); + + /* + * Class: org_iotivity_base_OcPlatform + * Method: bindTypeToResource0 + * Signature: (Lorg/iotivity/base/OcResourceHandle;Ljava/lang/String;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_bindTypeToResource0 + (JNIEnv *, jclass, jobject, jstring); + + /* + * Class: org_iotivity_base_OcPlatform + * Method: bindInterfaceToResource0 + * Signature: (Lorg/iotivity/base/OcResourceHandle;Ljava/lang/String;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_bindInterfaceToResource0 + (JNIEnv *, jclass, jobject, jstring); + + /* + * Class: org_iotivity_base_OcPlatform + * Method: startPresence0 + * Signature: (I)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_startPresence0 + (JNIEnv *, jclass, jint); + + /* + * Class: org_iotivity_base_OcPlatform + * Method: stopPresence0 + * Signature: ()V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_stopPresence0 + (JNIEnv *, jclass); + + /* + * Class: org_iotivity_base_OcPlatform + * Method: subscribePresence0 + * Signature: (Ljava/lang/String;ILorg/iotivity/base/OcPlatform/OnPresenceListener;)Lorg/iotivity/base/OcPresenceHandle; + */ + JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcPlatform_subscribePresence0 + (JNIEnv *, jclass, jstring, jint, jobject); + + /* + * Class: org_iotivity_base_OcPlatform + * Method: subscribePresence1 + * Signature: (Ljava/lang/String;Ljava/lang/String;ILorg/iotivity/base/OcPlatform/OnPresenceListener;)Lorg/iotivity/base/OcPresenceHandle; + */ + JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcPlatform_subscribePresence1 + (JNIEnv *, jclass, jstring, jstring, jint, jobject); + + /* + * Class: org_iotivity_base_OcPlatform + * Method: unsubscribePresence0 + * Signature: (Lorg/iotivity/base/OcPresenceHandle;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_unsubscribePresence0 + (JNIEnv *, jclass, jobject); + + /* + * Class: org_iotivity_base_OcPlatform + * Method: constructResourceObject0 + * Signature: (Ljava/lang/String;Ljava/lang/String;IZ[Ljava/lang/String;[Ljava/lang/String;)Lorg/iotivity/base/OcResource; + */ + JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcPlatform_constructResourceObject0 + (JNIEnv *, jclass, jstring, jstring, jint, jboolean, jobjectArray, jobjectArray); + + /* + * Class: org_iotivity_base_OcPlatform0 + * Method: sendResponse0 + * Signature: (Lorg/iotivity/base/OcResourceResponse;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_sendResponse0 + (JNIEnv *, jclass, jobject); + + #ifdef __cplusplus + } + #endif + #endif + diff --cc android/android_api/base/src/main/java/org/iotivity/base/OcPlatform.java index 891d487,3d672d0..46dedf2 --- 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,862 -1,759 +1,864 @@@ - /* - * //****************************************************************** - * // - * // 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; - - import org.iotivity.ca.CaInterface; - - import java.util.EnumSet; - import java.util.Iterator; - import java.util.List; - - /** - * Contains the main entrance/functionality of the product. To set a custom configuration, the - * implementer must make a call to OcPlatform.Configure before the first usage of a function in this - * class. - */ - public final class OcPlatform { - - static { - System.loadLibrary("oc_logger"); - System.loadLibrary("octbstack"); - System.loadLibrary("connectivity_abstraction"); - System.loadLibrary("oc"); - System.loadLibrary("ocstack-jni"); - } - - /** - * Default interface - */ - public static final String DEFAULT_INTERFACE = "oic.if.baseline"; - - /** - * Used in discovering (GET) links to other resources of a collection - */ - public static final String LINK_INTERFACE = "oic.if.ll"; - - /** - * Used in GET, PUT, POST, DELETE methods on links to other resources of a collection - */ - public static final String BATCH_INTERFACE = "oic.if.b"; - - /** - * Used in GET, PUT, POST methods on links to other remote resources of a group - */ - public static final String GROUP_INTERFACE = "oic.mi.grp"; - - public static final String WELL_KNOWN_QUERY = "224.0.1.187:5683/oic/res"; - public static final String MULTICAST_PREFIX = "224.0.1.187:5683"; - public static final String MULTICAST_IP = "224.0.1.187"; - public static final int MULTICAST_PORT = 5683; - public static final int DEFAULT_PRESENCE_TTL = 60; - public static final String DEVICE_URI = "/oic/d"; - public static final String PRESENCE_URI = "/oic/ad"; - - private static volatile boolean sIsPlatformInitialized = false; - - private OcPlatform() { - } - - /** - * API for setting the configuration of the OcPlatform. - * Note: Any calls made to this AFTER the first call to OcPlatform.Configure will have no affect - * - * @param platformConfig platform configuration - */ - public synchronized static void Configure(PlatformConfig platformConfig) { - if (!sIsPlatformInitialized) { - CaInterface.initialize(platformConfig.getContext()); - - OcPlatform.configure( - platformConfig.getServiceType().getValue(), - platformConfig.getModeType().getValue(), - platformConfig.getIpAddress(), - platformConfig.getPort(), - platformConfig.getQualityOfService().getValue() - ); - - sIsPlatformInitialized = true; - } - } - - private static native void configure(int serviceType, - int modeType, - String ipAddress, - int port, - int qualityOfService); - - /** - * API for notifying base that resource's attributes have changed. - * - * @param ocResourceHandle resource handle of the resource - * @throws OcException - */ - public static void notifyAllObservers( - OcResourceHandle ocResourceHandle) throws OcException { - OcPlatform.initCheck(); - OcPlatform.notifyAllObservers0(ocResourceHandle); - } - - private static native void notifyAllObservers0( - OcResourceHandle ocResourceHandle) throws OcException; - - /** - * API for notifying base that resource's attributes have changed. - * - * @param ocResourceHandle resource handle of the resource - * @param qualityOfService the quality of communication - * @throws OcException - */ - public static void notifyAllObservers( - OcResourceHandle ocResourceHandle, - QualityOfService qualityOfService) throws OcException { - OcPlatform.initCheck(); - OcPlatform.notifyAllObservers1(ocResourceHandle, qualityOfService.getValue()); - } - - private static native void notifyAllObservers1( - OcResourceHandle ocResourceHandle, - int qualityOfService) throws OcException; - - /** - * API for notifying only specific clients that resource's attributes have changed. - * - * @param ocResourceHandle resource handle of the resource - * @param ocObservationIdList These set of ids are ones which which will be notified upon - * resource change. - * @param ocResourceResponse OcResourceResponse object used by app to fill the response for - * this resource change - * @throws OcException - */ - public static void notifyListOfObservers( - OcResourceHandle ocResourceHandle, - List ocObservationIdList, - OcResourceResponse ocResourceResponse) throws OcException { - OcPlatform.initCheck(); - - byte[] idArr = new byte[ocObservationIdList.size()]; - Iterator it = ocObservationIdList.iterator(); - int i = 0; - while (it.hasNext()) { - idArr[i++] = (byte) it.next(); - } - - OcPlatform.notifyListOfObservers2( - ocResourceHandle, - idArr, - ocResourceResponse); - } - - private static native void notifyListOfObservers2( - OcResourceHandle ocResourceHandle, - byte[] ocObservationIdArray, - OcResourceResponse ocResourceResponse) throws OcException; - - /** - * API for notifying only specific clients that resource's attributes have changed. - * - * @param ocResourceHandle resource handle of the resource - * @param ocObservationIdList These set of ids are ones which which will be notified upon - * resource change. - * @param ocResourceResponse OcResourceResponse object used by app to fill the response for - * this resource change - * @param qualityOfService the quality of communication - * @throws OcException - */ - public static void notifyListOfObservers( - OcResourceHandle ocResourceHandle, - List ocObservationIdList, - OcResourceResponse ocResourceResponse, - QualityOfService qualityOfService) throws OcException { - OcPlatform.initCheck(); - - byte[] idArr = new byte[ocObservationIdList.size()]; - Iterator it = ocObservationIdList.iterator(); - int i = 0; - while (it.hasNext()) { - idArr[i++] = (byte) it.next(); - } - - OcPlatform.notifyListOfObservers3( - ocResourceHandle, - idArr, - ocResourceResponse, - qualityOfService.getValue() - ); - } - - private static native void notifyListOfObservers3( - OcResourceHandle ocResourceHandle, - byte[] ocObservationIdArray, - OcResourceResponse ocResourceResponse, - int qualityOfService) throws OcException; - - /** - * API for Service and Resource Discovery. NOTE: This API applies to client side only - * - * @param host Host IP Address of a service to direct resource discovery query. - * If empty, performs multicast resource discovery query - * @param resourceUri name of the resource. If null or empty, performs search for all - * resource names - * @param connectivityType a type of connectivity indicating the interface. Example: IPV4, - * IPV6, ALL - * @param onResourceFoundListener Handles events, success states and failure states. - * @throws OcException - */ - public static void findResource( - String host, - String resourceUri, - OcConnectivityType connectivityType, - OnResourceFoundListener onResourceFoundListener) throws OcException { - OcPlatform.initCheck(); - OcPlatform.findResource0( - host, - resourceUri, - connectivityType.getValue(), - onResourceFoundListener - ); - } - - private static native void findResource0( - String host, - String resourceUri, - int connectivityType, - OnResourceFoundListener onResourceFoundListener) throws OcException; - - /** - * API for Service and Resource Discovery. NOTE: This API applies to client side only - * - * @param host Host IP Address of a service to direct resource discovery query. - * If empty, performs multicast resource discovery query - * @param resourceUri name of the resource. If null or empty, performs search for all - * resource names - * @param connectivityType a type of connectivity indicating the interface. Example: IPV4, - * IPV6, ALL - * @param onResourceFoundListener Handles events, success states and failure states. - * @param qualityOfService the quality of communication - * @throws OcException - */ - public static void findResource( - String host, - String resourceUri, - OcConnectivityType connectivityType, - OnResourceFoundListener onResourceFoundListener, - QualityOfService qualityOfService) throws OcException { - OcPlatform.initCheck(); - OcPlatform.findResource1(host, - resourceUri, - connectivityType.getValue(), - onResourceFoundListener, - qualityOfService.getValue() - ); - } - - private static native void findResource1( - String host, - String resourceUri, - int connectivityType, - OnResourceFoundListener onResourceFoundListener, - int qualityOfService) throws OcException; - - /** - * API for Device Discovery - * - * @param host Host IP Address. If null or empty, Multicast is performed. - * @param deviceUri Uri containing address to the virtual device - * @param connectivityType a type of connectivity indicating the interface. Example: IPV4, - * IPV6, ALL - * @param onDeviceFoundListener Handles events, success states and failure states. - * @throws OcException - */ - public static void getDeviceInfo( - String host, - String deviceUri, - OcConnectivityType connectivityType, - OnDeviceFoundListener onDeviceFoundListener) throws OcException { - OcPlatform.initCheck(); - OcPlatform.getDeviceInfo0( - host, - deviceUri, - connectivityType.getValue(), - onDeviceFoundListener - ); - } - - private static native void getDeviceInfo0( - String host, - String deviceUri, - int connectivityType, - OnDeviceFoundListener onDeviceFoundListener) throws OcException; - - /** - * API for Device Discovery - * - * @param host Host IP Address. If null or empty, Multicast is performed. - * @param deviceUri Uri containing address to the virtual device - * @param connectivityType a type of connectivity indicating the interface. Example: IPV4, - * IPV6, ALL - * @param onDeviceFoundListener Handles events, success states and failure states. - * @param qualityOfService the quality of communication - * @throws OcException - */ - public static void getDeviceInfo( - String host, - String deviceUri, - OcConnectivityType connectivityType, - OnDeviceFoundListener onDeviceFoundListener, - QualityOfService qualityOfService) throws OcException { - OcPlatform.initCheck(); - OcPlatform.getDeviceInfo1( - host, - deviceUri, - connectivityType.getValue(), - onDeviceFoundListener, - qualityOfService.getValue() - ); - } - - private static native void getDeviceInfo1( - String host, - String deviceUri, - int connectivityType, - OnDeviceFoundListener onDeviceFoundListener, + /* + * //****************************************************************** + * // + * // 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; + + import org.iotivity.ca.CaInterface; + + import java.util.EnumSet; + import java.util.Iterator; + import java.util.List; + + /** + * Contains the main entrance/functionality of the product. To set a custom configuration, the + * implementer must make a call to OcPlatform.Configure before the first usage of a function in this + * class. + */ + public final class OcPlatform { + + static { + System.loadLibrary("oc_logger"); + System.loadLibrary("octbstack"); + System.loadLibrary("connectivity_abstraction"); + System.loadLibrary("oc"); + System.loadLibrary("ocstack-jni"); + } + + /** + * Default interface + */ + public static final String DEFAULT_INTERFACE = "oic.if.baseline"; + + /** + * Used in discovering (GET) links to other resources of a collection + */ + public static final String LINK_INTERFACE = "oic.if.ll"; + + /** + * Used in GET, PUT, POST, DELETE methods on links to other resources of a collection + */ + public static final String BATCH_INTERFACE = "oic.if.b"; + + /** + * Used in GET, PUT, POST methods on links to other remote resources of a group + */ + public static final String GROUP_INTERFACE = "oic.mi.grp"; + + public static final String WELL_KNOWN_QUERY = "224.0.1.187:5683/oic/res"; + public static final String MULTICAST_PREFIX = "224.0.1.187:5683"; + public static final String MULTICAST_IP = "224.0.1.187"; + public static final int MULTICAST_PORT = 5683; + public static final int DEFAULT_PRESENCE_TTL = 60; + public static final String DEVICE_URI = "/oic/d"; + public static final String PRESENCE_URI = "/oic/ad"; + + private static volatile boolean sIsPlatformInitialized = false; + + private OcPlatform() { + } + + /** + * API for setting the configuration of the OcPlatform. + * Note: Any calls made to this AFTER the first call to OcPlatform.Configure will have no affect + * + * @param platformConfig platform configuration + */ + public synchronized static void Configure(PlatformConfig platformConfig) { + if (!sIsPlatformInitialized) { + CaInterface.initialize(platformConfig.getContext()); + + OcPlatform.configure( + platformConfig.getServiceType().getValue(), + platformConfig.getModeType().getValue(), + platformConfig.getIpAddress(), + platformConfig.getPort(), + platformConfig.getQualityOfService().getValue(), + platformConfig.getSvrDbPath() + ); + + sIsPlatformInitialized = true; + } + } + + private static native void configure(int serviceType, + int modeType, + String ipAddress, + int port, + int qualityOfService, + String dbPath); + + /** + * API for notifying base that resource's attributes have changed. + * + * @param ocResourceHandle resource handle of the resource + * @throws OcException + */ + public static void notifyAllObservers( + OcResourceHandle ocResourceHandle) throws OcException { + OcPlatform.initCheck(); + OcPlatform.notifyAllObservers0(ocResourceHandle); + } + + private static native void notifyAllObservers0( + OcResourceHandle ocResourceHandle) throws OcException; + + /** + * API for notifying base that resource's attributes have changed. + * + * @param ocResourceHandle resource handle of the resource + * @param qualityOfService the quality of communication + * @throws OcException + */ + public static void notifyAllObservers( + OcResourceHandle ocResourceHandle, + QualityOfService qualityOfService) throws OcException { + OcPlatform.initCheck(); + OcPlatform.notifyAllObservers1(ocResourceHandle, qualityOfService.getValue()); + } + + private static native void notifyAllObservers1( + OcResourceHandle ocResourceHandle, + int qualityOfService) throws OcException; + + /** + * API for notifying only specific clients that resource's attributes have changed. + * + * @param ocResourceHandle resource handle of the resource + * @param ocObservationIdList These set of ids are ones which which will be notified upon + * resource change. + * @param ocResourceResponse OcResourceResponse object used by app to fill the response for + * this resource change + * @throws OcException + */ + public static void notifyListOfObservers( + OcResourceHandle ocResourceHandle, + List ocObservationIdList, + OcResourceResponse ocResourceResponse) throws OcException { + OcPlatform.initCheck(); + + byte[] idArr = new byte[ocObservationIdList.size()]; + Iterator it = ocObservationIdList.iterator(); + int i = 0; + while (it.hasNext()) { + idArr[i++] = (byte) it.next(); + } + + OcPlatform.notifyListOfObservers2( + ocResourceHandle, + idArr, + ocResourceResponse); + } + + private static native void notifyListOfObservers2( + OcResourceHandle ocResourceHandle, + byte[] ocObservationIdArray, + OcResourceResponse ocResourceResponse) throws OcException; + + /** + * API for notifying only specific clients that resource's attributes have changed. + * + * @param ocResourceHandle resource handle of the resource + * @param ocObservationIdList These set of ids are ones which which will be notified upon + * resource change. + * @param ocResourceResponse OcResourceResponse object used by app to fill the response for + * this resource change + * @param qualityOfService the quality of communication + * @throws OcException + */ + public static void notifyListOfObservers( + OcResourceHandle ocResourceHandle, + List ocObservationIdList, + OcResourceResponse ocResourceResponse, + QualityOfService qualityOfService) throws OcException { + OcPlatform.initCheck(); + + byte[] idArr = new byte[ocObservationIdList.size()]; + Iterator it = ocObservationIdList.iterator(); + int i = 0; + while (it.hasNext()) { + idArr[i++] = (byte) it.next(); + } + + OcPlatform.notifyListOfObservers3( + ocResourceHandle, + idArr, + ocResourceResponse, + qualityOfService.getValue() + ); + } + + private static native void notifyListOfObservers3( + OcResourceHandle ocResourceHandle, + byte[] ocObservationIdArray, + OcResourceResponse ocResourceResponse, + int qualityOfService) throws OcException; + + /** + * API for Service and Resource Discovery. NOTE: This API applies to client side only + * + * @param host Host IP Address of a service to direct resource discovery query. + * If empty, performs multicast resource discovery query + * @param resourceUri name of the resource. If null or empty, performs search for all + * resource names + * @param connectivityType a type of connectivity indicating the interface. Example: IPV4, + * IPV6, ALL + * @param onResourceFoundListener Handles events, success states and failure states. + * @throws OcException + */ + public static void findResource( + String host, + String resourceUri, + OcConnectivityType connectivityType, + OnResourceFoundListener onResourceFoundListener) throws OcException { + OcPlatform.initCheck(); + OcPlatform.findResource0( + host, + resourceUri, + connectivityType.getValue(), + onResourceFoundListener + ); + } + + private static native void findResource0( + String host, + String resourceUri, + int connectivityType, + OnResourceFoundListener onResourceFoundListener) throws OcException; + + /** + * API for Service and Resource Discovery. NOTE: This API applies to client side only + * + * @param host Host IP Address of a service to direct resource discovery query. + * If empty, performs multicast resource discovery query + * @param resourceUri name of the resource. If null or empty, performs search for all + * resource names + * @param connectivityType a type of connectivity indicating the interface. Example: IPV4, + * IPV6, ALL + * @param onResourceFoundListener Handles events, success states and failure states. + * @param qualityOfService the quality of communication + * @throws OcException + */ + public static void findResource( + String host, + String resourceUri, + OcConnectivityType connectivityType, + OnResourceFoundListener onResourceFoundListener, + QualityOfService qualityOfService) throws OcException { + OcPlatform.initCheck(); + OcPlatform.findResource1(host, + resourceUri, + connectivityType.getValue(), + onResourceFoundListener, + qualityOfService.getValue() + ); + } + + private static native void findResource1( + String host, + String resourceUri, + int connectivityType, + OnResourceFoundListener onResourceFoundListener, + int qualityOfService) throws OcException; + + /** + * API for Device Discovery + * + * @param host Host IP Address. If null or empty, Multicast is performed. + * @param deviceUri Uri containing address to the virtual device + * @param connectivityType a type of connectivity indicating the interface. Example: IPV4, + * IPV6, ALL + * @param onDeviceFoundListener Handles events, success states and failure states. + * @throws OcException + */ + public static void getDeviceInfo( + String host, + String deviceUri, + OcConnectivityType connectivityType, + OnDeviceFoundListener onDeviceFoundListener) throws OcException { + OcPlatform.initCheck(); + OcPlatform.getDeviceInfo0( + host, + deviceUri, + connectivityType.getValue(), + onDeviceFoundListener + ); + } + + private static native void getDeviceInfo0( + String host, + String deviceUri, + int connectivityType, + OnDeviceFoundListener onDeviceFoundListener) throws OcException; + + /** + * API for Device Discovery + * + * @param host Host IP Address. If null or empty, Multicast is performed. + * @param deviceUri Uri containing address to the virtual device + * @param connectivityType a type of connectivity indicating the interface. Example: IPV4, + * IPV6, ALL + * @param onDeviceFoundListener Handles events, success states and failure states. + * @param qualityOfService the quality of communication + * @throws OcException + */ + public static void getDeviceInfo( + String host, + String deviceUri, + OcConnectivityType connectivityType, + OnDeviceFoundListener onDeviceFoundListener, + QualityOfService qualityOfService) throws OcException { + OcPlatform.initCheck(); + OcPlatform.getDeviceInfo1( + host, + deviceUri, + connectivityType.getValue(), + onDeviceFoundListener, + qualityOfService.getValue() + ); + } + + private static native void getDeviceInfo1( + String host, + String deviceUri, + int connectivityType, + OnDeviceFoundListener onDeviceFoundListener, + int qualityOfService) throws OcException; + + /** + * API for Platform Discovery + * + * @param host Host IP Address. If null or empty, Multicast is performed. + * @param platformUri Uri containing address to the platform + * @param connectivityType a type of connectivity indicating the interface. Example: IPV4, + * IPV6, ALL + * @param onPlatformFoundListener Handles events, success states and failure states. + * @throws OcException + */ + + public static void getPlatformInfo( + String host, + String platformUri, + OcConnectivityType connectivityType, + OnPlatformFoundListener onPlatformFoundListener) throws OcException { + OcPlatform.initCheck(); + OcPlatform.getPlatformInfo0( + host, + platformUri, + connectivityType.getValue(), + onPlatformFoundListener + ); + } + + private static native void getPlatformInfo0( + String host, + String platformUri, + int connectivityType, + OnPlatformFoundListener onPlatformInfoFoundListener) throws OcException; + + /** + * API for Platform Discovery + * + * @param host Host IP Address. If null or empty, Multicast is performed. + * @param platformUri Uri containing address to the platform + * @param connectivityType a type of connectivity indicating the interface. Example: IPV4, + * IPV6, ALL + * @param onPlatformFoundListener Handles events, success states and failure states. + * @param qualityOfService the quality of communication + * @throws OcException + */ + + public static void getPlatformInfo( + String host, + String platformUri, + OcConnectivityType connectivityType, + OnPlatformFoundListener onPlatformFoundListener, + QualityOfService qualityOfService) throws OcException { + OcPlatform.initCheck(); + OcPlatform.getPlatformInfo1( + host, + platformUri, + connectivityType.getValue(), + onPlatformFoundListener, + qualityOfService.getValue() + ); + } + + private static native void getPlatformInfo1( + String host, + String platformUri, + int connectivityType, + OnPlatformFoundListener onPlatformFoundListener, - int qualityOfService) throws OcException; - - /** - * This API registers a resource with the server NOTE: This API applies to server side only. - * - * @param ocResource The instance of OcResource with all data filled - * @return resource handle - * @throws OcException - */ - public static OcResourceHandle registerResource( - OcResource ocResource) throws OcException { - OcPlatform.initCheck(); - return OcPlatform.registerResource0(ocResource); - } - - private static native OcResourceHandle registerResource0( - OcResource ocResource) throws OcException; - - /** - * This API registers a resource with the server NOTE: This API applies to server side only. - * - * @param resourceUri The URI of the resource. Example: "a/light" - * @param resourceTypeName The resource type. Example: "light" - * @param resourceInterface The resource interface (whether it is collection etc). - * @param entityHandler entity handler. - * @param resourcePropertySet indicates the property of the resource - * @return resource handle - * @throws OcException - */ - public static OcResourceHandle registerResource( - String resourceUri, - String resourceTypeName, - String resourceInterface, - EntityHandler entityHandler, - EnumSet resourcePropertySet) throws OcException { - OcPlatform.initCheck(); - - int resProperty = 0; - - for (ResourceProperty prop : ResourceProperty.values()) { - if (resourcePropertySet.contains(prop)) - resProperty |= prop.getValue(); - } - - return OcPlatform.registerResource1(resourceUri, - resourceTypeName, - resourceInterface, - entityHandler, - resProperty); - } - - private static native OcResourceHandle registerResource1( - String resourceUri, - String resourceTypeName, - String resourceInterface, - EntityHandler entityHandler, - int resourceProperty) throws OcException; - - /** - * Register Device Info - * - * @param ocDeviceInfo object containing all the device specific information - * @throws OcException - */ - public static void registerDeviceInfo( - OcDeviceInfo ocDeviceInfo) throws OcException { - OcPlatform.initCheck(); - OcPlatform.registerDeviceInfo0( - ocDeviceInfo.getDeviceName() - ); - } - - private static native void registerDeviceInfo0( - String deviceName - ) throws OcException; - - /** + int qualityOfService) throws OcException; + + /** + * This API registers a resource with the server NOTE: This API applies to server side only. + * + * @param ocResource The instance of OcResource with all data filled + * @return resource handle + * @throws OcException + */ + public static OcResourceHandle registerResource( + OcResource ocResource) throws OcException { + OcPlatform.initCheck(); + return OcPlatform.registerResource0(ocResource); + } + + private static native OcResourceHandle registerResource0( + OcResource ocResource) throws OcException; + + /** + * This API registers a resource with the server NOTE: This API applies to server side only. + * + * @param resourceUri The URI of the resource. Example: "a/light" + * @param resourceTypeName The resource type. Example: "light" + * @param resourceInterface The resource interface (whether it is collection etc). + * @param entityHandler entity handler. + * @param resourcePropertySet indicates the property of the resource + * @return resource handle + * @throws OcException + */ + public static OcResourceHandle registerResource( + String resourceUri, + String resourceTypeName, + String resourceInterface, + EntityHandler entityHandler, + EnumSet resourcePropertySet) throws OcException { + OcPlatform.initCheck(); + + int resProperty = 0; + + for (ResourceProperty prop : ResourceProperty.values()) { + if (resourcePropertySet.contains(prop)) + resProperty |= prop.getValue(); + } + + return OcPlatform.registerResource1(resourceUri, + resourceTypeName, + resourceInterface, + entityHandler, + resProperty); + } + + private static native OcResourceHandle registerResource1( + String resourceUri, + String resourceTypeName, + String resourceInterface, + EntityHandler entityHandler, + int resourceProperty) throws OcException; + + /** + * Register Device Info + * + * @param ocDeviceInfo object containing all the device specific information + * @throws OcException + */ + public static void registerDeviceInfo( + OcDeviceInfo ocDeviceInfo) throws OcException { + OcPlatform.initCheck(); + OcPlatform.registerDeviceInfo0( + ocDeviceInfo.getDeviceName() + ); + } + + private static native void registerDeviceInfo0( + String deviceName + ) throws OcException; + + /** + * Register Platform Info + * + * @param ocPlatformInfo object containing all the platform specific information + * @throws OcException + */ + public static void registerPlatformInfo( + OcPlatformInfo ocPlatformInfo) throws OcException { + OcPlatform.initCheck(); + OcPlatform.registerPlatformInfo0( + ocPlatformInfo.getPlatformID(), + ocPlatformInfo.getManufacturerName(), + ocPlatformInfo.getManufacturerUrl(), + ocPlatformInfo.getModelNumber(), + ocPlatformInfo.getDateOfManufacture(), + ocPlatformInfo.getPlatformVersion(), + ocPlatformInfo.getOperatingSystemVersion(), + ocPlatformInfo.getHardwareVersion(), + ocPlatformInfo.getFirmwareVersion(), + ocPlatformInfo.getSupportUrl(), + ocPlatformInfo.getSystemTime() + ); + } + + private static native void registerPlatformInfo0( + String platformId, String manufacturerName, String manufacturerUrl, + String modelNumber, String dateOfManufacture, String platformVersion, + String operatingSystemVersion, String hardwareVersion, String firmwareVersion, + String supportUrl, String systemTime + ) throws OcException; + + /** - * This API unregisters a resource with the server NOTE: This API applies to server side only. - * - * @param ocResourceHandle This is the resource handle which we which to unregister from the - * server - * @throws OcException - */ - public static void unregisterResource( - OcResourceHandle ocResourceHandle) throws OcException { - OcPlatform.initCheck(); - OcPlatform.unregisterResource0(ocResourceHandle); - } - - private static native void unregisterResource0( - OcResourceHandle ocResourceHandle) throws OcException; - - - /** - * Add a resource to a collection resource - * - * @param ocResourceCollectionHandle handle to the collection resource - * @param ocResourceHandle handle to resource to be added to the collection resource - * @throws OcException - */ - public static void bindResource( - OcResourceHandle ocResourceCollectionHandle, - OcResourceHandle ocResourceHandle) throws OcException { - OcPlatform.initCheck(); - OcPlatform.bindResource0(ocResourceCollectionHandle, ocResourceHandle); - } - - private static native void bindResource0( - OcResourceHandle ocResourceCollectionHandle, - OcResourceHandle ocResourceHandle) throws OcException; - - /** - * Add multiple resources to a collection resource. - * - * @param ocResourceCollectionHandle handle to the collection resource - * @param ocResourceHandleList reference to list of resource handles to be added to the - * collection resource - * @throws OcException - */ - public static void bindResources( - OcResourceHandle ocResourceCollectionHandle, - List ocResourceHandleList) throws OcException { - OcPlatform.initCheck(); - OcPlatform.bindResources0( - ocResourceCollectionHandle, - ocResourceHandleList.toArray( - new OcResourceHandle[ocResourceHandleList.size()]) - ); - } - - private static native void bindResources0( - OcResourceHandle ocResourceCollectionHandle, - OcResourceHandle[] ocResourceHandleArray) throws OcException; - - /** - * Unbind a resource from a collection resource. - * - * @param ocResourceCollectionHandle handle to the collection resource - * @param ocResourceHandle resource handle to be unbound from the collection resource - * @throws OcException - */ - public static void unbindResource( - OcResourceHandle ocResourceCollectionHandle, - OcResourceHandle ocResourceHandle) throws OcException { - OcPlatform.initCheck(); - OcPlatform.unbindResource0(ocResourceCollectionHandle, ocResourceHandle); - } - - private static native void unbindResource0( - OcResourceHandle ocResourceCollectionHandle, - OcResourceHandle ocResourceHandle) throws OcException; - - /** - * Unbind resources from a collection resource. - * - * @param ocResourceCollectionHandle Handle to the collection resource - * @param ocResourceHandleList List of resource handles to be unbound from the collection - * resource - * @throws OcException - */ - public static void unbindResources( - OcResourceHandle ocResourceCollectionHandle, - List ocResourceHandleList) throws OcException { - OcPlatform.initCheck(); - OcPlatform.unbindResources0( - ocResourceCollectionHandle, - ocResourceHandleList.toArray( - new OcResourceHandle[ocResourceHandleList.size()]) - ); - } - - private static native void unbindResources0( - OcResourceHandle ocResourceCollectionHandle, - OcResourceHandle[] ocResourceHandleArray) throws OcException; - - /** - * Binds a type to a particular resource - * - * @param ocResourceHandle handle to the resource - * @param resourceTypeName new typename to bind to the resource - * @throws OcException - */ - public static void bindTypeToResource( - OcResourceHandle ocResourceHandle, - String resourceTypeName) throws OcException { - OcPlatform.initCheck(); - OcPlatform.bindTypeToResource0(ocResourceHandle, resourceTypeName); - } - - private static native void bindTypeToResource0( - OcResourceHandle ocResourceHandle, - String resourceTypeName) throws OcException; - - /** - * Binds an interface to a particular resource - * - * @param ocResourceHandle handle to the resource - * @param resourceInterfaceName new interface to bind to the resource - * @throws OcException - */ - public static void bindInterfaceToResource( - OcResourceHandle ocResourceHandle, - String resourceInterfaceName) throws OcException { - OcPlatform.initCheck(); - OcPlatform.bindInterfaceToResource0(ocResourceHandle, resourceInterfaceName); - } - - private static native void bindInterfaceToResource0( - OcResourceHandle ocResourceHandle, - String resourceInterfaceName) throws OcException; - - /** - * Start Presence announcements. - * - * @param ttl time to live in seconds - * @throws OcException - */ - public static void startPresence(int ttl) throws OcException { - OcPlatform.initCheck(); - OcPlatform.startPresence0(ttl); - } - - private static native void startPresence0(int ttl) throws OcException; - - /** - * Stop Presence announcements. - * - * @throws OcException - */ - public static void stopPresence() throws OcException { - OcPlatform.initCheck(); - OcPlatform.stopPresence0(); - } - - private static native void stopPresence0() throws OcException; - - /** - * Subscribes to a server's presence change events. By making this subscription, every time a - * server adds/removes/alters a resource, starts or is intentionally stopped - * - * @param host The IP address/addressable name of the server to subscribe to - * @param connectivityType a type of connectivity indicating the interface. Example: IPV4, - * IPV6, ALL - * @param onPresenceListener listener that will receive notifications/subscription events - * @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 - */ - public static OcPresenceHandle subscribePresence( - String host, - OcConnectivityType connectivityType, - OnPresenceListener onPresenceListener) throws OcException { - OcPlatform.initCheck(); - return OcPlatform.subscribePresence0( - host, - connectivityType.getValue(), - onPresenceListener - ); - } - - private static native OcPresenceHandle subscribePresence0( - String host, - int connectivityType, - OnPresenceListener onPresenceListener) throws OcException; - - /** - * Subscribes to a server's presence change events. By making this subscription, every time a - * server adds/removes/alters a resource, starts or is intentionally stopped - * - * @param host The IP address/addressable name of the server to subscribe to - * @param resourceType a resource type specified as a filter for subscription events. - * @param connectivityType a type of connectivity indicating the interface. Example: IPV4, - * IPV6, ALL - * @param onPresenceListener listener that will receive notifications/subscription events - * @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 - */ - public static OcPresenceHandle subscribePresence( - String host, - String resourceType, - OcConnectivityType connectivityType, - OnPresenceListener onPresenceListener) throws OcException { - OcPlatform.initCheck(); - return OcPlatform.subscribePresence1( - host, - resourceType, - connectivityType.getValue(), - onPresenceListener); - } - - private static native OcPresenceHandle subscribePresence1( - String host, - String resourceType, - int connectivityType, - OnPresenceListener onPresenceListener) throws OcException; - - /** - * Unsubscribes from a previously subscribed server's presence events. Note that you may for - * a short time still receive events from the server since it may take time for the - * unsubscribe to take effect. - * - * @param ocPresenceHandle the handle object provided by the subscribePresence call that - * identifies this subscription - * @throws OcException - */ - public static void unsubscribePresence( - OcPresenceHandle ocPresenceHandle) throws OcException { - OcPlatform.initCheck(); - OcPlatform.unsubscribePresence0(ocPresenceHandle); - } - - private static native void unsubscribePresence0( - OcPresenceHandle ocPresenceHandle) 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 - * all of the details required to correctly contact and observe the object. If the consumer - * lacks any of this information, they should discover the resource object normally. - * Additionally, you can only create this object if OcPlatform was initialized to be a Client - * or Client/Server. - * - * @param host a string containing a resolvable host address of the server holding - * the resource - * @param uri the rest of the resource's URI that will permit messages to be - * properly routed. - * Example: /a/light - * @param connectivityType a type of connectivity indicating the interface. Example: IPV4, - * IPV6, ALL - * @param isObservable a boolean containing whether the resource supports observation - * @param resourceTypeList a collection of resource types implemented by the resource - * @param interfaceList a collection of interfaces that the resource supports/implements - * @return new resource object - * @throws OcException - */ - public static OcResource constructResourceObject( - String host, - String uri, - OcConnectivityType connectivityType, - boolean isObservable, - List resourceTypeList, - List interfaceList) throws OcException { - OcPlatform.initCheck(); - return OcPlatform.constructResourceObject0( - host, - uri, - connectivityType.getValue(), - isObservable, - resourceTypeList.toArray(new String[resourceTypeList.size()]), - interfaceList.toArray(new String[interfaceList.size()]) - ); - } - - private static native OcResource constructResourceObject0( - String host, - String uri, - int connectivityType, - boolean isObservable, - String[] resourceTypes, - String[] interfaces) throws OcException; - - /** - * Allows application entity handler to send response to an incoming request. - * - * @param ocResourceResponse resource response - * @throws OcException - */ - public static void sendResponse(OcResourceResponse ocResourceResponse) - throws OcException { - OcPlatform.initCheck(); - OcPlatform.sendResponse0(ocResourceResponse); - } - - private static native void sendResponse0(OcResourceResponse ocResourceResponse) - throws OcException; - - /** - * An OnResourceFoundListener can be registered via the OcPlatform.findResource call. - * Event listeners are notified asynchronously - */ - public interface OnResourceFoundListener { - public void onResourceFound(OcResource resource); - } - - /** - * An OnDeviceFoundListener can be registered via the OcPlatform.getDeviceInfo call. - * Event listeners are notified asynchronously - */ - public interface OnDeviceFoundListener { - public void onDeviceFound(OcRepresentation ocRepresentation); + * This API unregisters a resource with the server NOTE: This API applies to server side only. + * + * @param ocResourceHandle This is the resource handle which we which to unregister from the + * server + * @throws OcException + */ + public static void unregisterResource( + OcResourceHandle ocResourceHandle) throws OcException { + OcPlatform.initCheck(); + OcPlatform.unregisterResource0(ocResourceHandle); + } + + private static native void unregisterResource0( + OcResourceHandle ocResourceHandle) throws OcException; + + + /** + * Add a resource to a collection resource + * + * @param ocResourceCollectionHandle handle to the collection resource + * @param ocResourceHandle handle to resource to be added to the collection resource + * @throws OcException + */ + public static void bindResource( + OcResourceHandle ocResourceCollectionHandle, + OcResourceHandle ocResourceHandle) throws OcException { + OcPlatform.initCheck(); + OcPlatform.bindResource0(ocResourceCollectionHandle, ocResourceHandle); + } + + private static native void bindResource0( + OcResourceHandle ocResourceCollectionHandle, + OcResourceHandle ocResourceHandle) throws OcException; + + /** + * Add multiple resources to a collection resource. + * + * @param ocResourceCollectionHandle handle to the collection resource + * @param ocResourceHandleList reference to list of resource handles to be added to the + * collection resource + * @throws OcException + */ + public static void bindResources( + OcResourceHandle ocResourceCollectionHandle, + List ocResourceHandleList) throws OcException { + OcPlatform.initCheck(); + OcPlatform.bindResources0( + ocResourceCollectionHandle, + ocResourceHandleList.toArray( + new OcResourceHandle[ocResourceHandleList.size()]) + ); + } + + private static native void bindResources0( + OcResourceHandle ocResourceCollectionHandle, + OcResourceHandle[] ocResourceHandleArray) throws OcException; + + /** + * Unbind a resource from a collection resource. + * + * @param ocResourceCollectionHandle handle to the collection resource + * @param ocResourceHandle resource handle to be unbound from the collection resource + * @throws OcException + */ + public static void unbindResource( + OcResourceHandle ocResourceCollectionHandle, + OcResourceHandle ocResourceHandle) throws OcException { + OcPlatform.initCheck(); + OcPlatform.unbindResource0(ocResourceCollectionHandle, ocResourceHandle); + } + + private static native void unbindResource0( + OcResourceHandle ocResourceCollectionHandle, + OcResourceHandle ocResourceHandle) throws OcException; + + /** + * Unbind resources from a collection resource. + * + * @param ocResourceCollectionHandle Handle to the collection resource + * @param ocResourceHandleList List of resource handles to be unbound from the collection + * resource + * @throws OcException + */ + public static void unbindResources( + OcResourceHandle ocResourceCollectionHandle, + List ocResourceHandleList) throws OcException { + OcPlatform.initCheck(); + OcPlatform.unbindResources0( + ocResourceCollectionHandle, + ocResourceHandleList.toArray( + new OcResourceHandle[ocResourceHandleList.size()]) + ); + } + + private static native void unbindResources0( + OcResourceHandle ocResourceCollectionHandle, + OcResourceHandle[] ocResourceHandleArray) throws OcException; + + /** + * Binds a type to a particular resource + * + * @param ocResourceHandle handle to the resource + * @param resourceTypeName new typename to bind to the resource + * @throws OcException + */ + public static void bindTypeToResource( + OcResourceHandle ocResourceHandle, + String resourceTypeName) throws OcException { + OcPlatform.initCheck(); + OcPlatform.bindTypeToResource0(ocResourceHandle, resourceTypeName); + } + + private static native void bindTypeToResource0( + OcResourceHandle ocResourceHandle, + String resourceTypeName) throws OcException; + + /** + * Binds an interface to a particular resource + * + * @param ocResourceHandle handle to the resource + * @param resourceInterfaceName new interface to bind to the resource + * @throws OcException + */ + public static void bindInterfaceToResource( + OcResourceHandle ocResourceHandle, + String resourceInterfaceName) throws OcException { + OcPlatform.initCheck(); + OcPlatform.bindInterfaceToResource0(ocResourceHandle, resourceInterfaceName); + } + + private static native void bindInterfaceToResource0( + OcResourceHandle ocResourceHandle, + String resourceInterfaceName) throws OcException; + + /** + * Start Presence announcements. + * + * @param ttl time to live in seconds + * @throws OcException + */ + public static void startPresence(int ttl) throws OcException { + OcPlatform.initCheck(); + OcPlatform.startPresence0(ttl); + } + + private static native void startPresence0(int ttl) throws OcException; + + /** + * Stop Presence announcements. + * + * @throws OcException + */ + public static void stopPresence() throws OcException { + OcPlatform.initCheck(); + OcPlatform.stopPresence0(); + } + + private static native void stopPresence0() throws OcException; + + /** + * Subscribes to a server's presence change events. By making this subscription, every time a + * server adds/removes/alters a resource, starts or is intentionally stopped + * + * @param host The IP address/addressable name of the server to subscribe to + * @param connectivityType a type of connectivity indicating the interface. Example: IPV4, + * IPV6, ALL + * @param onPresenceListener listener that will receive notifications/subscription events + * @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 + */ + public static OcPresenceHandle subscribePresence( + String host, + OcConnectivityType connectivityType, + OnPresenceListener onPresenceListener) throws OcException { + OcPlatform.initCheck(); + return OcPlatform.subscribePresence0( + host, + connectivityType.getValue(), + onPresenceListener + ); + } + + private static native OcPresenceHandle subscribePresence0( + String host, + int connectivityType, + OnPresenceListener onPresenceListener) throws OcException; + + /** + * Subscribes to a server's presence change events. By making this subscription, every time a + * server adds/removes/alters a resource, starts or is intentionally stopped + * + * @param host The IP address/addressable name of the server to subscribe to + * @param resourceType a resource type specified as a filter for subscription events. + * @param connectivityType a type of connectivity indicating the interface. Example: IPV4, + * IPV6, ALL + * @param onPresenceListener listener that will receive notifications/subscription events + * @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 + */ + public static OcPresenceHandle subscribePresence( + String host, + String resourceType, + OcConnectivityType connectivityType, + OnPresenceListener onPresenceListener) throws OcException { + OcPlatform.initCheck(); + return OcPlatform.subscribePresence1( + host, + resourceType, + connectivityType.getValue(), + onPresenceListener); + } + + private static native OcPresenceHandle subscribePresence1( + String host, + String resourceType, + int connectivityType, + OnPresenceListener onPresenceListener) throws OcException; + + /** + * Unsubscribes from a previously subscribed server's presence events. Note that you may for + * a short time still receive events from the server since it may take time for the + * unsubscribe to take effect. + * + * @param ocPresenceHandle the handle object provided by the subscribePresence call that + * identifies this subscription + * @throws OcException + */ + public static void unsubscribePresence( + OcPresenceHandle ocPresenceHandle) throws OcException { + OcPlatform.initCheck(); + OcPlatform.unsubscribePresence0(ocPresenceHandle); + } + + private static native void unsubscribePresence0( + OcPresenceHandle ocPresenceHandle) 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 + * all of the details required to correctly contact and observe the object. If the consumer + * lacks any of this information, they should discover the resource object normally. + * Additionally, you can only create this object if OcPlatform was initialized to be a Client + * or Client/Server. + * + * @param host a string containing a resolvable host address of the server holding + * the resource + * @param uri the rest of the resource's URI that will permit messages to be + * properly routed. + * Example: /a/light + * @param connectivityType a type of connectivity indicating the interface. Example: IPV4, + * IPV6, ALL + * @param isObservable a boolean containing whether the resource supports observation + * @param resourceTypeList a collection of resource types implemented by the resource + * @param interfaceList a collection of interfaces that the resource supports/implements + * @return new resource object + * @throws OcException + */ + public static OcResource constructResourceObject( + String host, + String uri, + OcConnectivityType connectivityType, + boolean isObservable, + List resourceTypeList, + List interfaceList) throws OcException { + OcPlatform.initCheck(); + return OcPlatform.constructResourceObject0( + host, + uri, + connectivityType.getValue(), + isObservable, + resourceTypeList.toArray(new String[resourceTypeList.size()]), + interfaceList.toArray(new String[interfaceList.size()]) + ); + } + + private static native OcResource constructResourceObject0( + String host, + String uri, + int connectivityType, + boolean isObservable, + String[] resourceTypes, + String[] interfaces) throws OcException; + + /** + * Allows application entity handler to send response to an incoming request. + * + * @param ocResourceResponse resource response + * @throws OcException + */ + public static void sendResponse(OcResourceResponse ocResourceResponse) + throws OcException { + OcPlatform.initCheck(); + OcPlatform.sendResponse0(ocResourceResponse); + } + + private static native void sendResponse0(OcResourceResponse ocResourceResponse) + throws OcException; + + /** + * An OnResourceFoundListener can be registered via the OcPlatform.findResource call. + * Event listeners are notified asynchronously + */ + public interface OnResourceFoundListener { + public void onResourceFound(OcResource resource); + } + + /** + * An OnDeviceFoundListener can be registered via the OcPlatform.getDeviceInfo call. + * Event listeners are notified asynchronously + */ + public interface OnDeviceFoundListener { + public void onDeviceFound(OcRepresentation ocRepresentation); + } + + /** + * An OnPlatformFoundListener can be registered via the OcPlatform.getPlatformInfo call. + * Event listeners are notified asynchronously + */ + public interface OnPlatformFoundListener { + public void onPlatformFound(OcRepresentation ocRepresentation); - } - - /** - * An OnPresenceListener can be registered via the OcPlatform.subscribePresence call. - * Event listeners are notified asynchronously - */ - public interface OnPresenceListener { - public void onPresence(OcPresenceStatus ocPresenceStatus, int nonce, String hostAddress); - } - - /** - * An EntityHandler can be registered via the OcPlatform.registerResource call. - * Event listeners are notified asynchronously - */ - public interface EntityHandler { - public EntityHandlerResult handleEntity(OcResourceRequest ocResourceRequest); - } - - private static void initCheck() { - if (!sIsPlatformInitialized) { - throw new IllegalStateException("OcPlatform must be configured by making a call to " + - "OcPlatform.Configure before any other API calls are permitted"); - } - } - } + } + + /** + * An OnPresenceListener can be registered via the OcPlatform.subscribePresence call. + * Event listeners are notified asynchronously + */ + public interface OnPresenceListener { + public void onPresence(OcPresenceStatus ocPresenceStatus, int nonce, String hostAddress); + } + + /** + * An EntityHandler can be registered via the OcPlatform.registerResource call. + * Event listeners are notified asynchronously + */ + public interface EntityHandler { + public EntityHandlerResult handleEntity(OcResourceRequest ocResourceRequest); + } + + private static void initCheck() { + if (!sIsPlatformInitialized) { + throw new IllegalStateException("OcPlatform must be configured by making a call to " + + "OcPlatform.Configure before any other API calls are permitted"); + } + } + } diff --cc resource/csdk/security/provisioning/SConscript index d093b12,8b06ed6..d5cc915 --- a/resource/csdk/security/provisioning/SConscript +++ b/resource/csdk/security/provisioning/SConscript @@@ -84,6 -83,7 +84,8 @@@ provisioning_src = provisioningserver = provisioning_env.StaticLibrary('ocspapi', provisioning_src) provisioning_env.InstallTarget(provisioningserver, 'libocspapi') +provisioning_env.UserInstallTargetLib(provisioningserver, 'libocspapi') - SConscript('sample/SConscript') + if target_os in ['linux']: + SConscript('sample/SConscript') + diff --cc resource/csdk/security/provisioning/src/provisioningmanager.c index 14eed5f,dc1ec31..a91df2a --- a/resource/csdk/security/provisioning/src/provisioningmanager.c +++ b/resource/csdk/security/provisioning/src/provisioningmanager.c @@@ -311,6 -311,6 +313,12 @@@ static CAResult_t sendCARequest(CAMetho const char *resourceUri, char *payload, int payloadLen) { ++ if (payload && '\0' != (*(payload + payloadLen))) ++ { ++ OC_LOG(ERROR, TAG, "Payload not properly terminated."); ++ return CA_STATUS_INVALID_PARAM; ++ } ++ if (CA_STATUS_OK != CAGenerateToken(&gToken, CA_MAX_TOKEN_LEN)) { OC_LOG(ERROR, TAG, "Error while generating token"); @@@ -325,27 -326,24 +334,22 @@@ CADestroyEndpoint(endpoint); return CA_STATUS_FAILED; } -- CAMessageType_t msgType = CA_MSG_CONFIRM; - CAInfo_t requestData = { 0 }; - requestData.token = gToken; - requestData.tokenLength = CA_MAX_TOKEN_LEN; -- if (payload && '\0' != (*(payload + payloadLen))) -- { -- OC_LOG(ERROR, TAG, "Payload not properly terminated."); -- CADestroyEndpoint(endpoint); -- return CA_STATUS_INVALID_PARAM; -- } - OCSecurityPayload secPayload; - requestData.payload = payload; - requestData.type = msgType; - requestData.resourceUri = (CAURI_t)resourceUri; + - CARequestInfo_t requestInfo = { 0 }; ++ OCSecurityPayload secPayload = {}; + secPayload.securityData = payload; + secPayload.base.type = PAYLOAD_TYPE_SECURITY; - CARequestInfo_t requestInfo = { 0 }; ++ ++ CARequestInfo_t requestInfo = {}; requestInfo.method = method; - requestInfo.info = requestData; requestInfo.isMulticast = false; + OCConvertPayload((OCPayload*)(&secPayload), &requestInfo.info.payload, + &requestInfo.info.payloadSize); - requestInfo.info.type = msgType; ++ ++ requestInfo.info.type = CA_MSG_CONFIRM; + requestInfo.info.token = gToken; + requestInfo.info.tokenLength = CA_MAX_TOKEN_LEN; - requestInfo.info.resourceUri = resourceUri; ++ requestInfo.info.resourceUri = (CAURI_t)resourceUri; + - requestInfo.isMulticast = false; CAResult_t caResult = CA_STATUS_OK; caResult = CASendRequest(endpoint, &requestInfo); if (CA_STATUS_OK != caResult) @@@ -378,12 -374,8 +380,9 @@@ static SPResult addDevice(const CAEndpo return SP_RESULT_MEM_ALLOCATION_FAIL; } - SPStringCopy(ptr->endpoint.addr, ip, MAX_ADDR_STR_SIZE); - ptr->endpoint.port = port; - ptr->endpoint.adapter = adapter; - + memcpy(&(ptr->endpoint), endpoint, sizeof(CAEndpoint_t)); ptr->doxm = doxm; + ptr->next = NULL; if (NULL == gStartOfDiscoveredDevices) @@@ -539,26 -542,29 +544,26 @@@ static bool ListMethodsHandler(const CA { OC_LOG(ERROR, TAG, "response payload is null."); gStateManager |= SP_LIST_METHODS_ERROR; - return; + return true; } - char *pTempPayload = (char *)OICMalloc(strlen(responseInfo->info.payload)); - if (NULL == pTempPayload) + OCPayload* payload; + OCStackResult result = OCParsePayload(&payload, responseInfo->info.payload, + responseInfo->info.payloadSize); + + OicSecPstat_t *pstat = NULL; + + if(result == OC_STACK_OK && payload->type == PAYLOAD_TYPE_SECURITY) { - OC_LOG(ERROR, TAG, "Error in memory allocation."); - gStateManager |= SP_LIST_METHODS_ERROR; - return true; + pstat = JSONToPstatBin(((OCSecurityPayload*)payload)->securityData); } - strcpy(pTempPayload, responseInfo->info.payload + 8); - pTempPayload[strlen(pTempPayload) - 2] = '\0'; - - OicSecPstat_t *pstat = JSONToPstatBin(pTempPayload); if (NULL == pstat) { OC_LOG(ERROR, TAG, "Error while converting json to pstat bin"); - OICFree(pTempPayload); gStateManager |= SP_LIST_METHODS_ERROR; - return; + return true; } - OICFree(pTempPayload); DeletePstatBinData(gPstat); gPstat = pstat; diff --cc resource/include/OCApi.h index d3431ba,2014ce3..d38eb47 mode 100755,100644..100755 --- a/resource/include/OCApi.h +++ b/resource/include/OCApi.h @@@ -112,7 -111,8 +111,8 @@@ namespace O * ModeType : indicate whether we want to do server, client or both * ServerConnectivity : default flags for server * ClientConnectivity : default flags for client - * QoS : indicate Quality of Service : LowQos, MidQos,HighQos and NaQos(No quality Defined). - * QoS : Quality of Service : CONFIRMABLE or NON CONFIRMABLE. ++ * QoS : indicate Quality of Service : LowQos, MidQos,HighQos and NaQos(No quality Defined). + * ps : persistant storage Handler structure (open/read/write/close/unlink) */ struct PlatformConfig { diff --cc resource/include/OCSerialization.h index 41cea2c,2c71341..63668d5 --- a/resource/include/OCSerialization.h +++ b/resource/include/OCSerialization.h @@@ -27,58 -30,6 +27,69 @@@ namespace O class ListenOCContainer { private: + static std::vector StringLLToVector(OCStringLL* ll) + { + std::vector strs; + while(ll) + { + strs.push_back(ll->value); + ll = ll->next; + } + return strs; + } + + public: + ListenOCContainer(std::weak_ptr cw, - const OCDevAddr& devAddr, OCDiscoveryPayload* payload) ++ OCDevAddr& devAddr, OCDiscoveryPayload* payload) + : m_clientWrapper(cw), m_devAddr(devAddr) + { + OCResourcePayload* res = payload->resources; + + while(res) + { + char uuidString[UUID_STRING_SIZE]; + if(OCConvertUuidToString(res->sid, uuidString) != RAND_UUID_OK) + { + uuidString[0]= '\0'; + } + ++ if (res->secure) ++ { ++ m_devAddr.flags = ++ (OCTransportFlags)(OC_FLAG_SECURE | m_devAddr.flags); ++ } ++ ++ if (res->port != 0) ++ { ++ m_devAddr.port = res->port; ++ } ++ + m_resources.push_back(std::shared_ptr( + new OC::OCResource(m_clientWrapper, m_devAddr, + std::string(res->uri), + std::string(uuidString), + (res->bitmap & OC_OBSERVABLE) == OC_OBSERVABLE, + StringLLToVector(res->types), + StringLLToVector(res->interfaces) + ))); + res = res->next; + } + + } + + const std::vector>& Resources() const + { + return m_resources; + } + private: + std::vector> m_resources; + std::weak_ptr m_clientWrapper; - const OCDevAddr& m_devAddr; ++ OCDevAddr& m_devAddr; + }; + /* + class ListenOCContainer + { + private: enum class OCSecureType { NotSecure,