From: Jaewook Jung Date: Wed, 19 Oct 2016 04:49:45 +0000 (+0900) Subject: modified OCAccountManager APIs X-Git-Tag: 1.3.0~1022^2~24 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5701603b0aceecdba85351677d4a51e751691c90;p=platform%2Fupstream%2Fiotivity.git modified OCAccountManager APIs modified some APIs on OCAccountManager since the OCF cloud specification has been changed. (C++/Android API, sampleApp and unittest are modified) - added a string parameter for accessToken on signOut() and deleteDevice(). - removed AclGroupType for createGroup() and added new overloaded one that has a map parameter for optional property values. - changed getGroupList() to getGroupInfoAll() because it does not get a list anymore but information of all my group from account server. - removed joinGroup(), deleteInvitation() and added replyToInvitation(). - removed addDeviceToGroup(), deleteDeviceFromGroup(), leaveGroup() and added addPropertyValueToGroup(), deletePropertyValueFromGroup(), updatePropertyValueOnGroup(). Change-Id: Ibf462a6667990c1786d8b4111263d96e5c618166 Signed-off-by: Jaewook Jung Reviewed-on: https://gerrit.iotivity.org/gerrit/14335 Tested-by: jenkins-iotivity Reviewed-by: Ashok Babu Channa Signed-off-by: Jaewook Jung Reviewed-on: https://gerrit.iotivity.org/gerrit/15211 --- diff --git a/android/android_api/base/jni/JniOcAccountManager.cpp b/android/android_api/base/jni/JniOcAccountManager.cpp index 9556111..677e6d0 100644 --- a/android/android_api/base/jni/JniOcAccountManager.cpp +++ b/android/android_api/base/jni/JniOcAccountManager.cpp @@ -24,6 +24,13 @@ #include "JniOcRepresentation.h" #include "JniUtils.h" +#define VERIFY_NON_NULL_THROW_EXCEPTION(arg, log_message, exc) \ + if (!(arg)) \ + { \ + ThrowOcException(exc, log_message); \ + return; \ + } \ + JniOcAccountManager::JniOcAccountManager(std::shared_ptr accountManager) : m_sharedAccountManager(accountManager) { @@ -121,6 +128,11 @@ OCStackResult JniOcAccountManager::signUp(JNIEnv* env, const std::string& authPr const std::string& authCode, jobject jListener) { JniOnPostListener *onPostListener = addOnPostListener(env, jListener); + if (nullptr == onPostListener) + { + LOGE("onPostListener is null"); + return OC_STACK_ERROR; + } PostCallback postCallback = [onPostListener](const HeaderOptions& opts, const OCRepresentation& rep, const int eCode) @@ -136,6 +148,11 @@ OCStackResult JniOcAccountManager::signUp(JNIEnv* env, const std::string& authPr const QueryParamsMap& options, jobject jListener) { JniOnPostListener *onPostListener = addOnPostListener(env, jListener); + if (nullptr == onPostListener) + { + LOGE("onPostListener is null"); + return OC_STACK_ERROR; + } PostCallback postCallback = [onPostListener](const HeaderOptions& opts, const OCRepresentation& rep, const int eCode) @@ -150,6 +167,11 @@ OCStackResult JniOcAccountManager::signIn(JNIEnv* env, const std::string& userUu const std::string& accessToken, jobject jListener) { JniOnPostListener *onPostListener = addOnPostListener(env, jListener); + if (nullptr == onPostListener) + { + LOGE("onPostListener is null"); + return OC_STACK_ERROR; + } PostCallback postCallback = [onPostListener](const HeaderOptions& opts, const OCRepresentation& rep, const int eCode) @@ -160,9 +182,15 @@ OCStackResult JniOcAccountManager::signIn(JNIEnv* env, const std::string& userUu return m_sharedAccountManager->signIn(userUuid, accessToken, postCallback); } -OCStackResult JniOcAccountManager::signOut(JNIEnv* env, jobject jListener) +OCStackResult JniOcAccountManager::signOut(JNIEnv* env, const std::string& accessToken, + jobject jListener) { JniOnPostListener *onPostListener = addOnPostListener(env, jListener); + if (nullptr == onPostListener) + { + LOGE("onPostListener is null"); + return OC_STACK_ERROR; + } PostCallback postCallback = [onPostListener](const HeaderOptions& opts, const OCRepresentation& rep, const int eCode) @@ -170,7 +198,7 @@ OCStackResult JniOcAccountManager::signOut(JNIEnv* env, jobject jListener) onPostListener->onPostCallback(opts, rep, eCode); }; - return m_sharedAccountManager->signOut(postCallback); + return m_sharedAccountManager->signOut(accessToken, postCallback); } OCStackResult JniOcAccountManager::refreshAccessToken(JNIEnv* env, const std::string& userUuid, @@ -178,6 +206,11 @@ OCStackResult JniOcAccountManager::refreshAccessToken(JNIEnv* env, const std::st jobject jListener) { JniOnPostListener *onPostListener = addOnPostListener(env, jListener); + if (nullptr == onPostListener) + { + LOGE("onPostListener is null"); + return OC_STACK_ERROR; + } PostCallback postCallback = [onPostListener](const HeaderOptions& opts, const OCRepresentation& rep, const int eCode) @@ -192,6 +225,11 @@ OCStackResult JniOcAccountManager::searchUser(JNIEnv* env, const std::string& us jobject jListener) { JniOnGetListener *onGetListener = addOnGetListener(env, jListener); + if (nullptr == onGetListener) + { + LOGE("onGetListener is null"); + return OC_STACK_ERROR; + } GetCallback getCallback = [onGetListener](const HeaderOptions& opts, const OCRepresentation& rep, const int eCode) @@ -206,6 +244,11 @@ OCStackResult JniOcAccountManager::searchUser(JNIEnv* env, const QueryParamsMap& jobject jListener) { JniOnGetListener *onGetListener = addOnGetListener(env, jListener); + if (nullptr == onGetListener) + { + LOGE("onGetListener is null"); + return OC_STACK_ERROR; + } GetCallback getCallback = [onGetListener](const HeaderOptions& opts, const OCRepresentation& rep, const int eCode) @@ -216,10 +259,15 @@ OCStackResult JniOcAccountManager::searchUser(JNIEnv* env, const QueryParamsMap& return m_sharedAccountManager->searchUser(queryMap, getCallback); } -OCStackResult JniOcAccountManager::deleteDevice(JNIEnv* env, const std::string& deviceId, - jobject jListener) +OCStackResult JniOcAccountManager::deleteDevice(JNIEnv* env, const std::string& accessToken, + const std::string& deviceId, jobject jListener) { JniOnDeleteListener *onDeleteListener = addOnDeleteListener(env, jListener); + if (nullptr == onDeleteListener) + { + LOGE("onDeleteListener is null"); + return OC_STACK_ERROR; + } DeleteCallback deleteCallback = [onDeleteListener](const HeaderOptions& opts, const int eCode) @@ -227,13 +275,17 @@ OCStackResult JniOcAccountManager::deleteDevice(JNIEnv* env, const std::string& onDeleteListener->onDeleteCallback(opts, eCode); }; - return m_sharedAccountManager->deleteDevice(deviceId, deleteCallback); + return m_sharedAccountManager->deleteDevice(accessToken, deviceId, deleteCallback); } -OCStackResult JniOcAccountManager::createGroup(JNIEnv* env, AclGroupType groupType, - jobject jListener) +OCStackResult JniOcAccountManager::createGroup(JNIEnv* env, jobject jListener) { JniOnPostListener *onPostListener = addOnPostListener(env, jListener); + if (nullptr == onPostListener) + { + LOGE("onPostListener is null"); + return OC_STACK_ERROR; + } PostCallback postCallback = [onPostListener](const HeaderOptions& opts, const OCRepresentation& rep, const int eCode) @@ -241,26 +293,37 @@ OCStackResult JniOcAccountManager::createGroup(JNIEnv* env, AclGroupType groupTy onPostListener->onPostCallback(opts, rep, eCode); }; - return m_sharedAccountManager->createGroup(groupType, postCallback); + return m_sharedAccountManager->createGroup(postCallback); } -OCStackResult JniOcAccountManager::getGroupList(JNIEnv* env, jobject jListener) +OCStackResult JniOcAccountManager::createGroup(JNIEnv* env, const QueryParamsMap& queryMap, + jobject jListener) { - JniOnGetListener *onGetListener = addOnGetListener(env, jListener); + JniOnPostListener *onPostListener = addOnPostListener(env, jListener); + if (nullptr == onPostListener) + { + LOGE("onPostListener is null"); + return OC_STACK_ERROR; + } - GetCallback getCallback = [onGetListener](const HeaderOptions& opts, + PostCallback postCallback = [onPostListener](const HeaderOptions& opts, const OCRepresentation& rep, const int eCode) { - onGetListener->onGetCallback(opts, rep, eCode); + onPostListener->onPostCallback(opts, rep, eCode); }; - return m_sharedAccountManager->getGroupList(getCallback); + return m_sharedAccountManager->createGroup(queryMap, postCallback); } OCStackResult JniOcAccountManager::deleteGroup(JNIEnv* env, const std::string& groupId, jobject jListener) { JniOnDeleteListener *onDeleteListener = addOnDeleteListener(env, jListener); + if (nullptr == onDeleteListener) + { + LOGE("onDeleteListener is null"); + return OC_STACK_ERROR; + } DeleteCallback deleteCallback = [onDeleteListener](const HeaderOptions& opts, const int eCode) @@ -271,82 +334,115 @@ OCStackResult JniOcAccountManager::deleteGroup(JNIEnv* env, const std::string& g return m_sharedAccountManager->deleteGroup(groupId, deleteCallback); } -OCStackResult JniOcAccountManager::joinGroup(JNIEnv* env, const std::string& groupId, - jobject jListener) +OCStackResult JniOcAccountManager::getGroupInfoAll(JNIEnv* env, jobject jListener) { - JniOnPostListener *onPostListener = addOnPostListener(env, jListener); + JniOnGetListener *onGetListener = addOnGetListener(env, jListener); + if (nullptr == onGetListener) + { + LOGE("onGetListener is null"); + return OC_STACK_ERROR; + } - PostCallback postCallback = [onPostListener](const HeaderOptions& opts, + GetCallback getCallback = [onGetListener](const HeaderOptions& opts, const OCRepresentation& rep, const int eCode) { - onPostListener->onPostCallback(opts, rep, eCode); + onGetListener->onGetCallback(opts, rep, eCode); }; - return m_sharedAccountManager->joinGroup(groupId, postCallback); + return m_sharedAccountManager->getGroupInfoAll(getCallback); } -OCStackResult JniOcAccountManager::addDeviceToGroup(JNIEnv* env, const std::string& groupId, - const std::vector& deviceId, - jobject jListener) +OCStackResult JniOcAccountManager::getGroupInfo(JNIEnv* env, const std::string& groupId, + jobject jListener) { - JniOnPostListener *onPostListener = addOnPostListener(env, jListener); + JniOnGetListener *onGetListener = addOnGetListener(env, jListener); + if (nullptr == onGetListener) + { + LOGE("onGetListener is null"); + return OC_STACK_ERROR; + } - PostCallback postCallback = [onPostListener](const HeaderOptions& opts, + GetCallback getCallback = [onGetListener](const HeaderOptions& opts, const OCRepresentation& rep, const int eCode) { - onPostListener->onPostCallback(opts, rep, eCode); + onGetListener->onGetCallback(opts, rep, eCode); }; - return m_sharedAccountManager->addDeviceToGroup(groupId, deviceId, postCallback); + return m_sharedAccountManager->getGroupInfo(groupId, getCallback); } -OCStackResult JniOcAccountManager::getGroupInfo(JNIEnv* env, const std::string& groupId, - jobject jListener) +OCStackResult JniOcAccountManager::addPropertyValueToGroup(JNIEnv* env, const std::string& groupId, + const OCRepresentation& propertyValue, + jobject jListener) { - JniOnGetListener *onGetListener = addOnGetListener(env, jListener); + JniOnPostListener *onPostListener = addOnPostListener(env, jListener); + if (nullptr == onPostListener) + { + LOGE("onPostListener is null"); + return OC_STACK_ERROR; + } - GetCallback getCallback = [onGetListener](const HeaderOptions& opts, + PostCallback postCallback = [onPostListener](const HeaderOptions& opts, const OCRepresentation& rep, const int eCode) { - onGetListener->onGetCallback(opts, rep, eCode); + onPostListener->onPostCallback(opts, rep, eCode); }; - return m_sharedAccountManager->getGroupInfo(groupId, getCallback); + return m_sharedAccountManager->addPropertyValueToGroup(groupId, propertyValue, postCallback); } -OCStackResult JniOcAccountManager::leaveGroup(JNIEnv* env, const std::string& groupId, - jobject jListener) +OCStackResult JniOcAccountManager::deletePropertyValueFromGroup(JNIEnv* env, + const std::string& groupId, + const OCRepresentation& propertyValue, + jobject jListener) { - JniOnDeleteListener *onDeleteListener = addOnDeleteListener(env, jListener); + JniOnPostListener *onPostListener = addOnPostListener(env, jListener); + if (nullptr == onPostListener) + { + LOGE("onPostListener is null"); + return OC_STACK_ERROR; + } - DeleteCallback deleteCallback = [onDeleteListener](const HeaderOptions& opts, - const int eCode) + PostCallback postCallback = [onPostListener](const HeaderOptions& opts, + const OCRepresentation& rep, const int eCode) { - onDeleteListener->onDeleteCallback(opts, eCode); + onPostListener->onPostCallback(opts, rep, eCode); }; - return m_sharedAccountManager->leaveGroup(groupId, deleteCallback); + return m_sharedAccountManager->deletePropertyValueFromGroup(groupId, propertyValue, + postCallback); } -OCStackResult JniOcAccountManager::deleteDeviceFromGroup(JNIEnv* env, const std::string& groupId, - const std::vector& deviceId, - jobject jListener) +OCStackResult JniOcAccountManager::updatePropertyValueOnGroup(JNIEnv* env, + const std::string& groupId, + const OCRepresentation& propertyValue, + jobject jListener) { - JniOnDeleteListener *onDeleteListener = addOnDeleteListener(env, jListener); + JniOnPostListener *onPostListener = addOnPostListener(env, jListener); + if (nullptr == onPostListener) + { + LOGE("onPostListener is null"); + return OC_STACK_ERROR; + } - DeleteCallback deleteCallback = [onDeleteListener](const HeaderOptions& opts, - const int eCode) + PostCallback postCallback = [onPostListener](const HeaderOptions& opts, + const OCRepresentation& rep, const int eCode) { - onDeleteListener->onDeleteCallback(opts, eCode); + onPostListener->onPostCallback(opts, rep, eCode); }; - return m_sharedAccountManager->deleteDeviceFromGroup(groupId, deviceId, deleteCallback); + return m_sharedAccountManager->updatePropertyValueOnGroup(groupId, propertyValue, + postCallback); } -OCStackResult JniOcAccountManager::observeGroup(JNIEnv* env, const std::string& groupId, - jobject jListener) +OCStackResult JniOcAccountManager::observeGroup(JNIEnv* env, jobject jListener) { JniOnObserveListener *onObserveListener = addOnObserveListener(env, jListener); + if (nullptr == onObserveListener) + { + LOGE("onObserveListener is null"); + return OC_STACK_ERROR; + } ObserveCallback observeCallback = [onObserveListener](const HeaderOptions& opts, const OCRepresentation& rep, const int& eCode, const int& sequenceNumber) @@ -354,17 +450,22 @@ OCStackResult JniOcAccountManager::observeGroup(JNIEnv* env, const std::string& onObserveListener->onObserveCallback(opts, rep, eCode, sequenceNumber); }; - return m_sharedAccountManager->observeGroup(groupId, observeCallback); + return m_sharedAccountManager->observeGroup(observeCallback); } -OCStackResult JniOcAccountManager::cancelObserveGroup(const std::string& groupId) +OCStackResult JniOcAccountManager::cancelObserveGroup() { - return m_sharedAccountManager->cancelObserveGroup(groupId); + return m_sharedAccountManager->cancelObserveGroup(); } OCStackResult JniOcAccountManager::observeInvitation(JNIEnv* env, jobject jListener) { JniOnObserveListener *onObserveListener = addOnObserveListener(env, jListener); + if (nullptr == onObserveListener) + { + LOGE("onObserveListener is null"); + return OC_STACK_ERROR; + } ObserveCallback observeCallback = [onObserveListener](const HeaderOptions& opts, const OCRepresentation& rep, const int& eCode, const int& sequenceNumber) @@ -384,6 +485,11 @@ OCStackResult JniOcAccountManager::sendInvitation(JNIEnv* env, const std::string const std::string& userUuid, jobject jListener) { JniOnPostListener *onPostListener = addOnPostListener(env, jListener); + if (nullptr == onPostListener) + { + LOGE("onPostListener is null"); + return OC_STACK_ERROR; + } PostCallback postCallback = [onPostListener](const HeaderOptions& opts, const OCRepresentation& rep, const int eCode) @@ -398,6 +504,11 @@ OCStackResult JniOcAccountManager::cancelInvitation(JNIEnv* env, const std::stri const std::string& userUuid, jobject jListener) { JniOnDeleteListener *onDeleteListener = addOnDeleteListener(env, jListener); + if (nullptr == onDeleteListener) + { + LOGE("onDeleteListener is null"); + return OC_STACK_ERROR; + } DeleteCallback deleteCallback = [onDeleteListener](const HeaderOptions& opts, const int eCode) @@ -408,10 +519,15 @@ OCStackResult JniOcAccountManager::cancelInvitation(JNIEnv* env, const std::stri return m_sharedAccountManager->cancelInvitation(groupId, userUuid, deleteCallback); } -OCStackResult JniOcAccountManager::deleteInvitation(JNIEnv* env, const std::string& groupId, - jobject jListener) +OCStackResult JniOcAccountManager::replyToInvitation(JNIEnv* env, const std::string& groupId, + const bool accept, jobject jListener) { JniOnDeleteListener *onDeleteListener = addOnDeleteListener(env, jListener); + if (nullptr == onDeleteListener) + { + LOGE("onDeleteListener is null"); + return OC_STACK_ERROR; + } DeleteCallback deleteCallback = [onDeleteListener](const HeaderOptions& opts, const int eCode) @@ -419,10 +535,9 @@ OCStackResult JniOcAccountManager::deleteInvitation(JNIEnv* env, const std::stri onDeleteListener->onDeleteCallback(opts, eCode); }; - return m_sharedAccountManager->deleteInvitation(groupId, deleteCallback); + return m_sharedAccountManager->replyToInvitation(groupId, accept, deleteCallback); } - /* * Class: org_iotivity_base_OcAccountManager * Method: getHost @@ -465,17 +580,18 @@ JNIEXPORT jint JNICALL Java_org_iotivity_base_OcAccountManager_getConnectivityTy /* * Class: org_iotivity_base_OcAccountManager * Method: signUp0 -* Signature: (Ljava/lang/String;Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/OnPostListener;)V +* Signature: (Ljava/lang/String;Ljava/lang/String; +* Lorg/iotivity/base/OcAccountManager/OnPostListener;)V */ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_signUp0 (JNIEnv *env, jobject thiz, jstring jAuthProvider, jstring jAuthCode, jobject jListener) { LOGD("OcAccountManager_signUp"); - if (!jListener) - { - ThrowOcException(OC_STACK_INVALID_PARAM, "onPostListener cannot be null"); - return; - } + VERIFY_NON_NULL_THROW_EXCEPTION(jAuthProvider, "authProvider cannot be null", + OC_STACK_INVALID_PARAM); + VERIFY_NON_NULL_THROW_EXCEPTION(jAuthCode, "authCode cannot be null", OC_STACK_INVALID_PARAM); + VERIFY_NON_NULL_THROW_EXCEPTION(jListener, "onPostListener cannot be null", + OC_STACK_INVALID_PARAM); JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, thiz); @@ -484,16 +600,15 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_signUp0 return; } - std::string authProvider; - std::string authCode; - if (jAuthProvider) - { - authProvider = env->GetStringUTFChars(jAuthProvider, nullptr); - } - if (jAuthCode) - { - authCode = env->GetStringUTFChars(jAuthCode, nullptr); - } + const char *charAuthProvider = env->GetStringUTFChars(jAuthProvider, nullptr); + VERIFY_NON_NULL_THROW_EXCEPTION(charAuthProvider, "charAuthProvider is null", JNI_EXCEPTION); + std::string authProvider(charAuthProvider); + env->ReleaseStringUTFChars(jAuthProvider, charAuthProvider); + + const char *charAuthCode = env->GetStringUTFChars(jAuthCode, nullptr); + VERIFY_NON_NULL_THROW_EXCEPTION(charAuthCode, "charAuthCode is null", JNI_EXCEPTION); + std::string authCode(charAuthCode); + env->ReleaseStringUTFChars(jAuthCode, charAuthCode); try { @@ -501,7 +616,6 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_signUp0 authProvider, authCode, jListener); - if (OC_STACK_OK != result) { ThrowOcException(result, "OcAccountManager_signUp"); @@ -517,23 +631,20 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_signUp0 /* * Class: org_iotivity_base_OcAccountManager * Method: signUp1 -* Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/util/Map;Lorg/iotivity/base/OcAccountManager/OnPostListener;)V +* Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/util/Map; +* Lorg/iotivity/base/OcAccountManager/OnPostListener;)V */ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_signUp1 (JNIEnv *env, jobject thiz, jstring jAuthProvider, jstring jAuthCode, jobject jOptionsMap, jobject jListener) { LOGD("OcAccountManager_signUp"); - if (!jListener) - { - ThrowOcException(OC_STACK_INVALID_PARAM, "onPostListener cannot be null"); - return; - } - if (!jOptionsMap) - { - ThrowOcException(OC_STACK_INVALID_PARAM, "options cannot be null"); - return; - } + VERIFY_NON_NULL_THROW_EXCEPTION(jAuthProvider, "authProvider cannot be null", + OC_STACK_INVALID_PARAM); + VERIFY_NON_NULL_THROW_EXCEPTION(jAuthCode, "authCode cannot be null", OC_STACK_INVALID_PARAM); + VERIFY_NON_NULL_THROW_EXCEPTION(jOptionsMap, "options cannot be null", OC_STACK_INVALID_PARAM); + VERIFY_NON_NULL_THROW_EXCEPTION(jListener, "onPostListener cannot be null", + OC_STACK_INVALID_PARAM); JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, thiz); @@ -542,16 +653,15 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_signUp1 return; } - std::string authProvider; - std::string authCode; - if (jAuthProvider) - { - authProvider = env->GetStringUTFChars(jAuthProvider, nullptr); - } - if (jAuthCode) - { - authCode = env->GetStringUTFChars(jAuthCode, nullptr); - } + const char *charAuthProvider = env->GetStringUTFChars(jAuthProvider, nullptr); + VERIFY_NON_NULL_THROW_EXCEPTION(charAuthProvider, "charAuthProvider is null", JNI_EXCEPTION); + std::string authProvider(charAuthProvider); + env->ReleaseStringUTFChars(jAuthProvider, charAuthProvider); + + const char *charAuthCode = env->GetStringUTFChars(jAuthCode, nullptr); + VERIFY_NON_NULL_THROW_EXCEPTION(charAuthCode, "charAuthCode is null", JNI_EXCEPTION); + std::string authCode(charAuthCode); + env->ReleaseStringUTFChars(jAuthCode, charAuthCode); QueryParamsMap optionsMap; JniUtils::convertJavaMapToQueryParamsMap(env, jOptionsMap, optionsMap); @@ -563,7 +673,6 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_signUp1 authCode, optionsMap, jListener); - if (OC_STACK_OK != result) { ThrowOcException(result, "OcAccountManager_signUp"); @@ -579,17 +688,18 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_signUp1 /* * Class: org_iotivity_base_OcAccountManager * Method: signIn0 -* Signature: (Ljava/lang/String;Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/OnPostListener;)V +* Signature: (Ljava/lang/String;Ljava/lang/String; +* Lorg/iotivity/base/OcAccountManager/OnPostListener;)V */ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_signIn0 (JNIEnv *env, jobject thiz, jstring jUserUuid, jstring jAccessToken, jobject jListener) { LOGD("OcAccountManager_signIn"); - if (!jListener) - { - ThrowOcException(OC_STACK_INVALID_PARAM, "onPostListener cannot be null"); - return; - } + VERIFY_NON_NULL_THROW_EXCEPTION(jUserUuid, "userUuid cannot be null", OC_STACK_INVALID_PARAM); + VERIFY_NON_NULL_THROW_EXCEPTION(jAccessToken, "accessToken cannot be null", + OC_STACK_INVALID_PARAM); + VERIFY_NON_NULL_THROW_EXCEPTION(jListener, "onPostListener cannot be null", + OC_STACK_INVALID_PARAM); JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, thiz); @@ -598,16 +708,15 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_signIn0 return; } - std::string userUuid; - std::string accessToken; - if (jUserUuid) - { - userUuid = env->GetStringUTFChars(jUserUuid, nullptr); - } - if (jAccessToken) - { - accessToken = env->GetStringUTFChars(jAccessToken, nullptr); - } + const char *charUserUuid = env->GetStringUTFChars(jUserUuid, nullptr); + VERIFY_NON_NULL_THROW_EXCEPTION(charUserUuid, "charUserUuid is null", JNI_EXCEPTION); + std::string userUuid(charUserUuid); + env->ReleaseStringUTFChars(jUserUuid, charUserUuid); + + const char *charAccessToken = env->GetStringUTFChars(jAccessToken, nullptr); + VERIFY_NON_NULL_THROW_EXCEPTION(charAccessToken, "charAccessToken is null", JNI_EXCEPTION); + std::string accessToken(charAccessToken); + env->ReleaseStringUTFChars(jAccessToken, charAccessToken); try { @@ -615,7 +724,6 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_signIn0 userUuid, accessToken, jListener); - if (OC_STACK_OK != result) { ThrowOcException(result, "OcAccountManager_signIn"); @@ -631,17 +739,16 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_signIn0 /* * Class: org_iotivity_base_OcAccountManager * Method: signOut0 -* Signature: (Lorg/iotivity/base/OcAccountManager/OnPostListener;)V +* Signature: (Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/OnPostListener;)V */ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_signOut0 - (JNIEnv *env, jobject thiz, jobject jListener) + (JNIEnv *env, jobject thiz, jstring jAccessToken, jobject jListener) { LOGD("OcAccountManager_signOut"); - if (!jListener) - { - ThrowOcException(OC_STACK_INVALID_PARAM, "onPostListener cannot be null"); - return; - } + VERIFY_NON_NULL_THROW_EXCEPTION(jAccessToken, "accessToken cannot be null", + OC_STACK_INVALID_PARAM); + VERIFY_NON_NULL_THROW_EXCEPTION(jListener, "onPostListener cannot be null", + OC_STACK_INVALID_PARAM); JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, thiz); @@ -650,11 +757,16 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_signOut0 return; } + const char *charAccessToken = env->GetStringUTFChars(jAccessToken, nullptr); + VERIFY_NON_NULL_THROW_EXCEPTION(charAccessToken, "charAccessToken is null", JNI_EXCEPTION); + std::string accessToken(charAccessToken); + env->ReleaseStringUTFChars(jAccessToken, charAccessToken); + try { OCStackResult result = accountManager->signOut(env, + accessToken, jListener); - if (OC_STACK_OK != result) { ThrowOcException(result, "OcAccountManager_signOut"); @@ -670,17 +782,18 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_signOut0 /* * Class: org_iotivity_base_OcAccountManager * Method: refreshAccessToken0 -* Signature: (Ljava/lang/String;Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/OnPostListener;)V +* Signature: (Ljava/lang/String;Ljava/lang/String; +* Lorg/iotivity/base/OcAccountManager/OnPostListener;)V */ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_refreshAccessToken0 (JNIEnv *env, jobject thiz, jstring jUserUuid, jstring jRefreshAccessToken, jobject jListener) { LOGD("OcAccountManager_refreshAccessToken"); - if (!jListener) - { - ThrowOcException(OC_STACK_INVALID_PARAM, "onPostListener cannot be null"); - return; - } + VERIFY_NON_NULL_THROW_EXCEPTION(jUserUuid, "userUuid cannot be null", OC_STACK_INVALID_PARAM); + VERIFY_NON_NULL_THROW_EXCEPTION(jRefreshAccessToken, "refreshAccessToken cannot be null", + OC_STACK_INVALID_PARAM); + VERIFY_NON_NULL_THROW_EXCEPTION(jListener, "onPostListener cannot be null", + OC_STACK_INVALID_PARAM); JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, thiz); @@ -689,16 +802,16 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_refreshAccessToke return; } - std::string userUuid; - std::string refreshAccessToken; - if (jUserUuid) - { - userUuid = env->GetStringUTFChars(jUserUuid, nullptr); - } - if (jRefreshAccessToken) - { - refreshAccessToken = env->GetStringUTFChars(jRefreshAccessToken, nullptr); - } + const char *charUserUuid = env->GetStringUTFChars(jUserUuid, nullptr); + VERIFY_NON_NULL_THROW_EXCEPTION(charUserUuid, "charUserUuid is null", JNI_EXCEPTION); + std::string userUuid(charUserUuid); + env->ReleaseStringUTFChars(jUserUuid, charUserUuid); + + const char *charRefreshAccessToken = env->GetStringUTFChars(jRefreshAccessToken, nullptr); + VERIFY_NON_NULL_THROW_EXCEPTION(charRefreshAccessToken, "charRefreshAccessToken is null", + JNI_EXCEPTION); + std::string refreshAccessToken(charRefreshAccessToken); + env->ReleaseStringUTFChars(jRefreshAccessToken, charRefreshAccessToken); try { @@ -706,7 +819,6 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_refreshAccessToke userUuid, refreshAccessToken, jListener); - if (OC_STACK_OK != result) { ThrowOcException(result, "OcAccountManager_refreshAccessToken"); @@ -728,11 +840,9 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_searchUser0 (JNIEnv *env, jobject thiz, jstring jUserUuid, jobject jListener) { LOGD("OcAccountManager_searchUser"); - if (!jListener) - { - ThrowOcException(OC_STACK_INVALID_PARAM, "onGetListener cannot be null"); - return; - } + VERIFY_NON_NULL_THROW_EXCEPTION(jUserUuid, "userUuid cannot be null", OC_STACK_INVALID_PARAM); + VERIFY_NON_NULL_THROW_EXCEPTION(jListener, "onGetListener cannot be null", + OC_STACK_INVALID_PARAM); JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, thiz); @@ -741,18 +851,16 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_searchUser0 return; } - std::string userUuid; - if (jUserUuid) - { - userUuid = env->GetStringUTFChars(jUserUuid, nullptr); - } + const char *charUserUuid = env->GetStringUTFChars(jUserUuid, nullptr); + VERIFY_NON_NULL_THROW_EXCEPTION(charUserUuid, "charUserUuid is null", JNI_EXCEPTION); + std::string userUuid(charUserUuid); + env->ReleaseStringUTFChars(jUserUuid, charUserUuid); try { OCStackResult result = accountManager->searchUser(env, userUuid, jListener); - if (OC_STACK_OK != result) { ThrowOcException(result, "OcAccountManager_searchUser"); @@ -774,16 +882,9 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_searchUser1 (JNIEnv *env, jobject thiz, jobject jQueryMap, jobject jListener) { LOGD("OcAccountManager_searchUser"); - if (!jListener) - { - ThrowOcException(OC_STACK_INVALID_PARAM, "onGetListener cannot be null"); - return; - } - if (!jQueryMap) - { - ThrowOcException(OC_STACK_INVALID_PARAM, "queryMap cannot be null"); - return; - } + VERIFY_NON_NULL_THROW_EXCEPTION(jQueryMap, "queryMap cannot be null", OC_STACK_INVALID_PARAM); + VERIFY_NON_NULL_THROW_EXCEPTION(jListener, "onGetListener cannot be null", + OC_STACK_INVALID_PARAM); JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, thiz); @@ -800,7 +901,6 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_searchUser1 OCStackResult result = accountManager->searchUser(env, queryMap, jListener); - if (OC_STACK_OK != result) { ThrowOcException(result, "OcAccountManager_searchUser"); @@ -816,17 +916,18 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_searchUser1 /* * Class: org_iotivity_base_OcAccountManager * Method: deleteDevice0 -* Signature: (Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/onDeleteListener;)V +* Signature: (Ljava/lang/String;Ljava/lang/String; +* Lorg/iotivity/base/OcAccountManager/onDeleteListener;)V */ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_deleteDevice0 - (JNIEnv *env, jobject thiz, jstring jDeviceId, jobject jListener) + (JNIEnv *env, jobject thiz, jstring jAccessToken, jstring jDeviceId, jobject jListener) { LOGD("OcAccountManager_deleteDevice"); - if (!jListener) - { - ThrowOcException(OC_STACK_INVALID_PARAM, "onDeleteListener cannot be null"); - return; - } + VERIFY_NON_NULL_THROW_EXCEPTION(jAccessToken, "accessToken cannot be null", + OC_STACK_INVALID_PARAM); + VERIFY_NON_NULL_THROW_EXCEPTION(jDeviceId, "deviceId cannot be null", OC_STACK_INVALID_PARAM); + VERIFY_NON_NULL_THROW_EXCEPTION(jListener, "onDeleteListener cannot be null", + OC_STACK_INVALID_PARAM); JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, thiz); @@ -835,18 +936,22 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_deleteDevice0 return; } - std::string deviceId; - if (jDeviceId) - { - deviceId = env->GetStringUTFChars(jDeviceId, nullptr); - } + const char *charAccessToken = env->GetStringUTFChars(jAccessToken, nullptr); + VERIFY_NON_NULL_THROW_EXCEPTION(charAccessToken, "charAccessToken is null", JNI_EXCEPTION); + std::string accessToken(charAccessToken); + env->ReleaseStringUTFChars(jAccessToken, charAccessToken); + + const char *charDeviceId = env->GetStringUTFChars(jDeviceId, nullptr); + VERIFY_NON_NULL_THROW_EXCEPTION(charDeviceId, "charDeviceId is null", JNI_EXCEPTION); + std::string deviceId(charDeviceId); + env->ReleaseStringUTFChars(jDeviceId, charDeviceId); try { OCStackResult result = accountManager->deleteDevice(env, + accessToken, deviceId, jListener); - if (OC_STACK_OK != result) { ThrowOcException(result, "OcAccountManager_deleteDevice"); @@ -862,17 +967,14 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_deleteDevice0 /* * Class: org_iotivity_base_OcAccountManager * Method: createGroup0 -* Signature: (Lorg/iotivity/base/AclGroupType;Lorg/iotivity/base/OcAccountManager/OnPostListener;)V +* Signature: (Lorg/iotivity/base/OcAccountManager/OnPostListener;)V */ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_createGroup0 - (JNIEnv *env, jobject thiz, jint groupType, jobject jListener) + (JNIEnv *env, jobject thiz, jobject jListener) { LOGD("OcAccountManager_createGroup"); - if (!jListener) - { - ThrowOcException(OC_STACK_INVALID_PARAM, "onPostListener cannot be null"); - return; - } + VERIFY_NON_NULL_THROW_EXCEPTION(jListener, "onPostListener cannot be null", + OC_STACK_INVALID_PARAM); JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, thiz); @@ -884,9 +986,7 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_createGroup0 try { OCStackResult result = accountManager->createGroup(env, - JniUtils::getAclGroupType(env, static_cast(groupType)), - jListener); - + jListener); if (OC_STACK_OK != result) { ThrowOcException(result, "OcAccountManager_createGroup"); @@ -901,18 +1001,16 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_createGroup0 /* * Class: org_iotivity_base_OcAccountManager -* Method: getGroupList0 -* Signature: (Lorg/iotivity/base/OcAccountManager/OnGetListener;)V +* Method: createGroup1 +* Signature: (Ljava/util/Map;Lorg/iotivity/base/OcAccountManager/OnPostListener;)V */ -JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_getGroupList0 - (JNIEnv *env, jobject thiz, jobject jListener) +JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_createGroup1 + (JNIEnv *env, jobject thiz, jobject jQueryMap, jobject jListener) { - LOGD("OcAccountManager_getGroupList"); - if (!jListener) - { - ThrowOcException(OC_STACK_INVALID_PARAM, "onGetListener cannot be null"); - return; - } + LOGD("OcAccountManager_createGroup"); + VERIFY_NON_NULL_THROW_EXCEPTION(jQueryMap, "queryMap cannot be null", OC_STACK_INVALID_PARAM); + VERIFY_NON_NULL_THROW_EXCEPTION(jListener, "onPostListener cannot be null", + OC_STACK_INVALID_PARAM); JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, thiz); @@ -921,14 +1019,17 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_getGroupList0 return; } + QueryParamsMap queryMap; + JniUtils::convertJavaMapToQueryParamsMap(env, jQueryMap, queryMap); + try { - OCStackResult result = accountManager->getGroupList(env, - jListener); - + OCStackResult result = accountManager->createGroup(env, + queryMap, + jListener); if (OC_STACK_OK != result) { - ThrowOcException(result, "OcAccountManager_getGroupList"); + ThrowOcException(result, "OcAccountManager_createGroup"); } } catch (OCException& e) @@ -947,11 +1048,9 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_deleteGroup0 (JNIEnv *env, jobject thiz, jstring jGroupId, jobject jListener) { LOGD("OcAccountManager_deleteGroup"); - if (!jListener) - { - ThrowOcException(OC_STACK_INVALID_PARAM, "onDeleteListener cannot be null"); - return; - } + VERIFY_NON_NULL_THROW_EXCEPTION(jGroupId, "groupId cannot be null", OC_STACK_INVALID_PARAM); + VERIFY_NON_NULL_THROW_EXCEPTION(jListener, "onDeleteListener cannot be null", + OC_STACK_INVALID_PARAM); JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, thiz); @@ -960,18 +1059,16 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_deleteGroup0 return; } - std::string groupId; - if (jGroupId) - { - groupId = env->GetStringUTFChars(jGroupId, nullptr); - } + const char *charGroupId = env->GetStringUTFChars(jGroupId, nullptr); + VERIFY_NON_NULL_THROW_EXCEPTION(charGroupId, "charGroupId is null", JNI_EXCEPTION); + std::string groupId(charGroupId); + env->ReleaseStringUTFChars(jGroupId, charGroupId); try { OCStackResult result = accountManager->deleteGroup(env, groupId, jListener); - if (OC_STACK_OK != result) { ThrowOcException(result, "OcAccountManager_deleteGroup"); @@ -986,18 +1083,15 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_deleteGroup0 /* * Class: org_iotivity_base_OcAccountManager -* Method: joinGroup0 -* Signature: (Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/OnPostListener;)V +* Method: getGroupInfoAll0 +* Signature: (Lorg/iotivity/base/OcAccountManager/OnGetListener;)V */ -JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_joinGroup0 - (JNIEnv *env, jobject thiz, jstring jGroupId, jobject jListener) +JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_getGroupInfoAll0 + (JNIEnv *env, jobject thiz, jobject jListener) { - LOGD("OcAccountManager_joinGroup"); - if (!jListener) - { - ThrowOcException(OC_STACK_INVALID_PARAM, "onPostListener cannot be null"); - return; - } + LOGD("OcAccountManager_getGroupInfoAll"); + VERIFY_NON_NULL_THROW_EXCEPTION(jListener, "onGetListener cannot be null", + OC_STACK_INVALID_PARAM); JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, thiz); @@ -1006,21 +1100,13 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_joinGroup0 return; } - std::string groupId; - if (jGroupId) - { - groupId = env->GetStringUTFChars(jGroupId, nullptr); - } - try { - OCStackResult result = accountManager->joinGroup(env, - groupId, - jListener); - + OCStackResult result = accountManager->getGroupInfoAll(env, + jListener); if (OC_STACK_OK != result) { - ThrowOcException(result, "OcAccountManager_joinGroup"); + ThrowOcException(result, "OcAccountManager_getGroupInfoAll"); } } catch (OCException& e) @@ -1032,23 +1118,16 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_joinGroup0 /* * Class: org_iotivity_base_OcAccountManager -* Method: addDeviceToGroup0 -* Signature: (Ljava/lang/String;[Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/OnPostListener;)V +* Method: getGroupInfo0 +* Signature: (Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/OnGetListener;)V */ -JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_addDeviceToGroup0 - (JNIEnv *env, jobject thiz, jstring jGroupId, jobjectArray jDeviceIdArray, jobject jListener) +JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_getGroupInfo0 + (JNIEnv *env, jobject thiz, jstring jGroupId, jobject jListener) { - LOGD("OcAccountManager_addDeviceToGroup"); - if (!jListener) - { - ThrowOcException(OC_STACK_INVALID_PARAM, "onPostListener cannot be null"); - return; - } - if (!jDeviceIdArray) - { - ThrowOcException(OC_STACK_INVALID_PARAM, "deviceId cannot be null"); - return; - } + LOGD("OcAccountManager_getGroupInfo"); + VERIFY_NON_NULL_THROW_EXCEPTION(jGroupId, "groupId cannot be null", OC_STACK_INVALID_PARAM); + VERIFY_NON_NULL_THROW_EXCEPTION(jListener, "onGetListener cannot be null", + OC_STACK_INVALID_PARAM); JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, thiz); @@ -1057,25 +1136,19 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_addDeviceToGroup0 return; } - std::string groupId; - if (jGroupId) - { - groupId = env->GetStringUTFChars(jGroupId, nullptr); - } - - std::vector deviceIds; - JniUtils::convertJavaStrArrToStrVector(env, jDeviceIdArray, deviceIds); + const char *charGroupId = env->GetStringUTFChars(jGroupId, nullptr); + VERIFY_NON_NULL_THROW_EXCEPTION(charGroupId, "charGroupId is null", JNI_EXCEPTION); + std::string groupId(charGroupId); + env->ReleaseStringUTFChars(jGroupId, charGroupId); try { - OCStackResult result = accountManager->addDeviceToGroup(env, - groupId, - deviceIds, - jListener); - + OCStackResult result = accountManager->getGroupInfo(env, + groupId, + jListener); if (OC_STACK_OK != result) { - ThrowOcException(result, "OcAccountManager_addDeviceToGroup"); + ThrowOcException(result, "OcAccountManager_getGroupInfo"); } } catch (OCException& e) @@ -1087,18 +1160,19 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_addDeviceToGroup0 /* * Class: org_iotivity_base_OcAccountManager -* Method: getGroupInfo0 -* Signature: (Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/OnGetListener;)V +* Method: addPropertyValueToGroup0 +* Signature: (Ljava/lang/String;Lorg/iotivity/base/OcRepresentation; +* Lorg/iotivity/base/OcAccountManager/OnPostListener;)V */ -JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_getGroupInfo0 - (JNIEnv *env, jobject thiz, jstring jGroupId, jobject jListener) +JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_addPropertyValueToGroup0 + (JNIEnv *env, jobject thiz, jstring jGroupId, jobject jPropertyValue, jobject jListener) { - LOGD("OcAccountManager_getGroupInfo"); - if (!jListener) - { - ThrowOcException(OC_STACK_INVALID_PARAM, "onGetListener cannot be null"); - return; - } + LOGD("OcAccountManager_addPropertyValueToGroup"); + VERIFY_NON_NULL_THROW_EXCEPTION(jGroupId, "groupId cannot be null", OC_STACK_INVALID_PARAM); + VERIFY_NON_NULL_THROW_EXCEPTION(jPropertyValue, "propertyValue cannot be null", + OC_STACK_INVALID_PARAM); + VERIFY_NON_NULL_THROW_EXCEPTION(jListener, "onPostListener cannot be null", + OC_STACK_INVALID_PARAM); JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, thiz); @@ -1107,21 +1181,28 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_getGroupInfo0 return; } - std::string groupId; - if (jGroupId) + OCRepresentation *propertyValue = JniOcRepresentation::getOCRepresentationPtr(env, + jPropertyValue); + if (!propertyValue) { - groupId = env->GetStringUTFChars(jGroupId, nullptr); + return; } + const char *charGroupId = env->GetStringUTFChars(jGroupId, nullptr); + VERIFY_NON_NULL_THROW_EXCEPTION(charGroupId, "charGroupId is null", JNI_EXCEPTION); + std::string groupId(charGroupId); + env->ReleaseStringUTFChars(jGroupId, charGroupId); + try { - OCStackResult result = accountManager->getGroupInfo(env, - groupId, - jListener); + OCStackResult result = accountManager->addPropertyValueToGroup(env, + groupId, + *propertyValue, + jListener); if (OC_STACK_OK != result) { - ThrowOcException(result, "OcAccountManager_getGroupInfo"); + ThrowOcException(result, "OcAccountManager_addPropertyValueToGroup"); } } catch (OCException& e) @@ -1133,18 +1214,19 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_getGroupInfo0 /* * Class: org_iotivity_base_OcAccountManager -* Method: leaveGroup0 -* Signature: (Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/onDeleteListener;)V +* Method: deletePropertyValueFromGroup0 +* Signature: (Ljava/lang/String;Lorg/iotivity/base/OcRepresentation; +* Lorg/iotivity/base/OcAccountManager/OnPostListener;)V */ -JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_leaveGroup0 - (JNIEnv *env, jobject thiz, jstring jGroupId, jobject jListener) +JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_deletePropertyValueFromGroup0 + (JNIEnv *env, jobject thiz, jstring jGroupId, jobject jPropertyValue, jobject jListener) { - LOGD("OcAccountManager_leaveGroup"); - if (!jListener) - { - ThrowOcException(OC_STACK_INVALID_PARAM, "onDeleteListener cannot be null"); - return; - } + LOGD("OcAccountManager_deletePropertyValueFromGroup"); + VERIFY_NON_NULL_THROW_EXCEPTION(jGroupId, "groupId cannot be null", OC_STACK_INVALID_PARAM); + VERIFY_NON_NULL_THROW_EXCEPTION(jPropertyValue, "propertyValue cannot be null", + OC_STACK_INVALID_PARAM); + VERIFY_NON_NULL_THROW_EXCEPTION(jListener, "onPostListener cannot be null", + OC_STACK_INVALID_PARAM); JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, thiz); @@ -1153,21 +1235,28 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_leaveGroup0 return; } - std::string groupId; - if (jGroupId) + OCRepresentation *propertyValue = JniOcRepresentation::getOCRepresentationPtr(env, + jPropertyValue); + if (!propertyValue) { - groupId = env->GetStringUTFChars(jGroupId, nullptr); + return; } + const char *charGroupId = env->GetStringUTFChars(jGroupId, nullptr); + VERIFY_NON_NULL_THROW_EXCEPTION(charGroupId, "charGroupId is null", JNI_EXCEPTION); + std::string groupId(charGroupId); + env->ReleaseStringUTFChars(jGroupId, charGroupId); + try { - OCStackResult result = accountManager->leaveGroup(env, - groupId, - jListener); + OCStackResult result = accountManager->deletePropertyValueFromGroup(env, + groupId, + *propertyValue, + jListener); if (OC_STACK_OK != result) { - ThrowOcException(result, "OcAccountManager_leaveGroup"); + ThrowOcException(result, "OcAccountManager_deletePropertyValueFromGroup"); } } catch (OCException& e) @@ -1179,23 +1268,19 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_leaveGroup0 /* * Class: org_iotivity_base_OcAccountManager -* Method: deleteDeviceFromGroup0 -* Signature: (Ljava/lang/String;[Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/onDeleteListener;)V +* Method: updatePropertyValueOnGroup0 +* Signature: (Ljava/lang/String;Lorg/iotivity/base/OcRepresentation; +* Lorg/iotivity/base/OcAccountManager/OnPostListener;)V */ -JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_deleteDeviceFromGroup0 - (JNIEnv *env, jobject thiz, jstring jGroupId, jobjectArray jDeviceIdArray, jobject jListener) +JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_updatePropertyValueOnGroup0 + (JNIEnv *env, jobject thiz, jstring jGroupId, jobject jPropertyValue, jobject jListener) { - LOGD("OcAccountManager_deleteDeviceFromGroup"); - if (!jListener) - { - ThrowOcException(OC_STACK_INVALID_PARAM, "onDeleteListener cannot be null"); - return; - } - if (!jDeviceIdArray) - { - ThrowOcException(OC_STACK_INVALID_PARAM, "deviceId cannot be null"); - return; - } + LOGD("OcAccountManager_updatePropertyValueOnGroup"); + VERIFY_NON_NULL_THROW_EXCEPTION(jGroupId, "groupId cannot be null", OC_STACK_INVALID_PARAM); + VERIFY_NON_NULL_THROW_EXCEPTION(jPropertyValue, "propertyValue cannot be null", + OC_STACK_INVALID_PARAM); + VERIFY_NON_NULL_THROW_EXCEPTION(jListener, "onPostListener cannot be null", + OC_STACK_INVALID_PARAM); JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, thiz); @@ -1204,25 +1289,28 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_deleteDeviceFromG return; } - std::string groupId; - if (jGroupId) + OCRepresentation *propertyValue = JniOcRepresentation::getOCRepresentationPtr(env, + jPropertyValue); + if (!propertyValue) { - groupId = env->GetStringUTFChars(jGroupId, nullptr); + return; } - std::vector deviceIds; - JniUtils::convertJavaStrArrToStrVector(env, jDeviceIdArray, deviceIds); + const char *charGroupId = env->GetStringUTFChars(jGroupId, nullptr); + VERIFY_NON_NULL_THROW_EXCEPTION(charGroupId, "charGroupId is null", JNI_EXCEPTION); + std::string groupId(charGroupId); + env->ReleaseStringUTFChars(jGroupId, charGroupId); try { - OCStackResult result = accountManager->deleteDeviceFromGroup(env, - groupId, - deviceIds, - jListener); + OCStackResult result = accountManager->updatePropertyValueOnGroup(env, + groupId, + *propertyValue, + jListener); if (OC_STACK_OK != result) { - ThrowOcException(result, "OcAccountManager_deleteDeviceFromGroup"); + ThrowOcException(result, "OcAccountManager_updatePropertyValueOnGroup"); } } catch (OCException& e) @@ -1235,17 +1323,14 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_deleteDeviceFromG /* * Class: org_iotivity_base_OcAccountManager * Method: observeGroup0 -* Signature: (Ljava/lang/String;Lorg/iotivity/base/OcResource/OnObserveListener;)V +* Signature: (Lorg/iotivity/base/OcResource/OnObserveListener;)V */ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_observeGroup0 - (JNIEnv *env, jobject thiz, jstring jGroupId, jobject jListener) + (JNIEnv *env, jobject thiz, jobject jListener) { LOGD("OcAccountManager_observeGroup"); - if (!jListener) - { - ThrowOcException(OC_STACK_INVALID_PARAM, "onObserveListener cannot be null"); - return; - } + VERIFY_NON_NULL_THROW_EXCEPTION(jListener, "onObserveListener cannot be null", + OC_STACK_INVALID_PARAM); JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, thiz); @@ -1254,18 +1339,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_observeGroup0 return; } - std::string groupId; - if (jGroupId) - { - groupId = env->GetStringUTFChars(jGroupId, nullptr); - } - try { OCStackResult result = accountManager->observeGroup(env, - groupId, jListener); - if (OC_STACK_OK != result) { ThrowOcException(result, "OcAccountManager_observeGroup"); @@ -1281,10 +1358,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_observeGroup0 /* * Class: org_iotivity_base_OcAccountManager * Method: cancelObserveGroup0 -* Signature: (Ljava/lang/String;)V +* Signature: ()V */ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_cancelObserveGroup0 - (JNIEnv *env, jobject thiz, jstring jGroupId) + (JNIEnv *env, jobject thiz) { LOGD("OcAccountManager_cancelObserveGroup"); @@ -1295,16 +1372,9 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_cancelObserveGrou return; } - std::string groupId; - if (jGroupId) - { - groupId = env->GetStringUTFChars(jGroupId, nullptr); - } - try { - OCStackResult result = accountManager->cancelObserveGroup(groupId); - + OCStackResult result = accountManager->cancelObserveGroup(); if (OC_STACK_OK != result) { ThrowOcException(result, "OcAccountManager_cancelObserveGroup"); @@ -1326,11 +1396,8 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_observeInvitation (JNIEnv *env, jobject thiz, jobject jListener) { LOGD("OcAccountManager_observeInvitation"); - if (!jListener) - { - ThrowOcException(OC_STACK_INVALID_PARAM, "onObserveListener cannot be null"); - return; - } + VERIFY_NON_NULL_THROW_EXCEPTION(jListener, "onObserveListener cannot be null", + OC_STACK_INVALID_PARAM); JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, thiz); @@ -1343,7 +1410,6 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_observeInvitation { OCStackResult result = accountManager->observeInvitation(env, jListener); - if (OC_STACK_OK != result) { ThrowOcException(result, "OcAccountManager_observeInvitation"); @@ -1376,7 +1442,6 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_cancelObserveInvi try { OCStackResult result = accountManager->cancelObserveInvitation(); - if (OC_STACK_OK != result) { ThrowOcException(result, "OcAccountManager_cancelObserveInvitation"); @@ -1392,17 +1457,17 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_cancelObserveInvi /* * Class: org_iotivity_base_OcAccountManager * Method: sendInvitation0 -* Signature: (Ljava/lang/String;Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/OnPostListener;)V +* Signature: (Ljava/lang/String;Ljava/lang/String; +* Lorg/iotivity/base/OcAccountManager/OnPostListener;)V */ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_sendInvitation0 (JNIEnv *env, jobject thiz, jstring jGroupId, jstring jUserUuid, jobject jListener) { LOGD("OcAccountManager_sendInvitation"); - if (!jListener) - { - ThrowOcException(OC_STACK_INVALID_PARAM, "onPostListener cannot be null"); - return; - } + VERIFY_NON_NULL_THROW_EXCEPTION(jGroupId, "groupId cannot be null", OC_STACK_INVALID_PARAM); + VERIFY_NON_NULL_THROW_EXCEPTION(jUserUuid, "userUuid cannot be null", OC_STACK_INVALID_PARAM); + VERIFY_NON_NULL_THROW_EXCEPTION(jListener, "onPostListener cannot be null", + OC_STACK_INVALID_PARAM); JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, thiz); @@ -1411,15 +1476,15 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_sendInvitation0 return; } - std::string groupId, userUuid; - if (jGroupId) - { - groupId = env->GetStringUTFChars(jGroupId, nullptr); - } - if (jUserUuid) - { - userUuid = env->GetStringUTFChars(jUserUuid, nullptr); - } + const char *charGroupId = env->GetStringUTFChars(jGroupId, nullptr); + VERIFY_NON_NULL_THROW_EXCEPTION(charGroupId, "charGroupId is null", JNI_EXCEPTION); + std::string groupId(charGroupId); + env->ReleaseStringUTFChars(jGroupId, charGroupId); + + const char *charUserUuid = env->GetStringUTFChars(jUserUuid, nullptr); + VERIFY_NON_NULL_THROW_EXCEPTION(charUserUuid, "charUserUuid is null", JNI_EXCEPTION); + std::string userUuid(charUserUuid); + env->ReleaseStringUTFChars(jUserUuid, charUserUuid); try { @@ -1427,7 +1492,6 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_sendInvitation0 groupId, userUuid, jListener); - if (OC_STACK_OK != result) { ThrowOcException(result, "OcAccountManager_sendInvitation"); @@ -1443,17 +1507,17 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_sendInvitation0 /* * Class: org_iotivity_base_OcAccountManager * Method: cancelInvitation0 -* Signature: (Ljava/lang/String;Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/onDeleteListener;)V +* Signature: (Ljava/lang/String;Ljava/lang/String; +* Lorg/iotivity/base/OcAccountManager/onDeleteListener;)V */ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_cancelInvitation0 (JNIEnv *env, jobject thiz, jstring jGroupId, jstring jUserUuid, jobject jListener) { LOGD("OcAccountManager_cancelInvitation"); - if (!jListener) - { - ThrowOcException(OC_STACK_INVALID_PARAM, "onDeleteListener cannot be null"); - return; - } + VERIFY_NON_NULL_THROW_EXCEPTION(jGroupId, "groupId cannot be null", OC_STACK_INVALID_PARAM); + VERIFY_NON_NULL_THROW_EXCEPTION(jUserUuid, "userUuid cannot be null", OC_STACK_INVALID_PARAM); + VERIFY_NON_NULL_THROW_EXCEPTION(jListener, "onDeleteListener cannot be null", + OC_STACK_INVALID_PARAM); JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, thiz); @@ -1462,15 +1526,15 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_cancelInvitation0 return; } - std::string groupId, userUuid; - if (jGroupId) - { - groupId = env->GetStringUTFChars(jGroupId, nullptr); - } - if (jUserUuid) - { - userUuid = env->GetStringUTFChars(jUserUuid, nullptr); - } + const char *charGroupId = env->GetStringUTFChars(jGroupId, nullptr); + VERIFY_NON_NULL_THROW_EXCEPTION(charGroupId, "charGroupId is null", JNI_EXCEPTION); + std::string groupId(charGroupId); + env->ReleaseStringUTFChars(jGroupId, charGroupId); + + const char *charUserUuid = env->GetStringUTFChars(jUserUuid, nullptr); + VERIFY_NON_NULL_THROW_EXCEPTION(charUserUuid, "charUserUuid is null", JNI_EXCEPTION); + std::string userUuid(charUserUuid); + env->ReleaseStringUTFChars(jUserUuid, charUserUuid); try { @@ -1478,7 +1542,6 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_cancelInvitation0 groupId, userUuid, jListener); - if (OC_STACK_OK != result) { ThrowOcException(result, "OcAccountManager_cancelInvitation"); @@ -1493,18 +1556,16 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_cancelInvitation0 /* * Class: org_iotivity_base_OcAccountManager -* Method: deleteInvitation0 -* Signature: (Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/onDeleteListener;)V +* Method: replyToInvitation0 +* Signature: (Ljava/lang/String;ZLorg/iotivity/base/OcAccountManager/onDeleteListener;)V */ -JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_deleteInvitation0 - (JNIEnv *env, jobject thiz, jstring jGroupId, jobject jListener) +JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_replyToInvitation0 + (JNIEnv *env, jobject thiz, jstring jGroupId, jboolean jAccept, jobject jListener) { - LOGD("OcAccountManager_deleteInvitation"); - if (!jListener) - { - ThrowOcException(OC_STACK_INVALID_PARAM, "onDeleteListener cannot be null"); - return; - } + LOGD("OcAccountManager_replyToInvitation"); + VERIFY_NON_NULL_THROW_EXCEPTION(jGroupId, "groupId cannot be null", OC_STACK_INVALID_PARAM); + VERIFY_NON_NULL_THROW_EXCEPTION(jListener, "onDeleteListener cannot be null", + OC_STACK_INVALID_PARAM); JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, thiz); @@ -1513,21 +1574,20 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_deleteInvitation0 return; } - std::string groupId; - if (jGroupId) - { - groupId = env->GetStringUTFChars(jGroupId, nullptr); - } + const char *charGroupId = env->GetStringUTFChars(jGroupId, nullptr); + VERIFY_NON_NULL_THROW_EXCEPTION(charGroupId, "charGroupId is null", JNI_EXCEPTION); + std::string groupId(charGroupId); + env->ReleaseStringUTFChars(jGroupId, charGroupId); try { - OCStackResult result = accountManager->deleteInvitation(env, - groupId, - jListener); - + OCStackResult result = accountManager->replyToInvitation(env, + groupId, + static_cast(jAccept), + jListener); if (OC_STACK_OK != result) { - ThrowOcException(result, "OcAccountManager_deleteInvitation"); + ThrowOcException(result, "OcAccountManager_replyToInvitation"); } } catch (OCException& e) diff --git a/android/android_api/base/jni/JniOcAccountManager.h b/android/android_api/base/jni/JniOcAccountManager.h index 7ff841e..8aa9a21 100644 --- a/android/android_api/base/jni/JniOcAccountManager.h +++ b/android/android_api/base/jni/JniOcAccountManager.h @@ -50,32 +50,34 @@ public: const QueryParamsMap& options, jobject jListener); OCStackResult signIn(JNIEnv* env, const std::string& userUuid, const std::string& accessToken, jobject jListener); - OCStackResult signOut(JNIEnv* env, jobject jListener); + OCStackResult signOut(JNIEnv* env, const std::string& accessToken, jobject jListener); OCStackResult refreshAccessToken(JNIEnv* env, const std::string& userUuid, const std::string& refreshToken, jobject jListener); OCStackResult searchUser(JNIEnv* env, const std::string& userUuid, jobject jListener); OCStackResult searchUser(JNIEnv* env, const QueryParamsMap& queryMap, jobject jListener); - OCStackResult deleteDevice(JNIEnv* env, const std::string& deviceId, jobject jListener); - OCStackResult createGroup(JNIEnv* env, AclGroupType groupType, jobject jListener); - OCStackResult getGroupList(JNIEnv* env, jobject jListener); + OCStackResult deleteDevice(JNIEnv* env, const std::string& accessToken, + const std::string& deviceId, jobject jListener); + OCStackResult createGroup(JNIEnv* env, jobject jListener); + OCStackResult createGroup(JNIEnv* env, const QueryParamsMap& queryMap, jobject jListener); OCStackResult deleteGroup(JNIEnv* env, const std::string& groupId, jobject jListener); - OCStackResult joinGroup(JNIEnv* env, const std::string& groupId, jobject jListener); - OCStackResult addDeviceToGroup(JNIEnv* env, const std::string& groupId, - const std::vector& deviceId, jobject jListener); + OCStackResult getGroupInfoAll(JNIEnv* env, jobject jListener); OCStackResult getGroupInfo(JNIEnv* env, const std::string& groupId, jobject jListener); - OCStackResult leaveGroup(JNIEnv* env, const std::string& groupId, jobject jListener); - OCStackResult deleteDeviceFromGroup(JNIEnv* env, const std::string& groupId, - const std::vector& deviceId, - jobject jListener); - OCStackResult observeGroup(JNIEnv* env, const std::string& groupId, jobject jListener); - OCStackResult cancelObserveGroup(const std::string& groupId); + OCStackResult addPropertyValueToGroup(JNIEnv* env, const std::string& groupId, + const OCRepresentation& propertyValue, jobject jListener); + OCStackResult deletePropertyValueFromGroup(JNIEnv* env, const std::string& groupId, + const OCRepresentation& propertyValue, jobject jListener); + OCStackResult updatePropertyValueOnGroup(JNIEnv* env, const std::string& groupId, + const OCRepresentation& propertyValue, jobject jListener); + OCStackResult observeGroup(JNIEnv* env, jobject jListener); + OCStackResult cancelObserveGroup(); OCStackResult observeInvitation(JNIEnv* env, jobject jListener); OCStackResult cancelObserveInvitation(); OCStackResult sendInvitation(JNIEnv* env, const std::string& groupId, const std::string& userUuid, jobject jListener); OCStackResult cancelInvitation(JNIEnv* env, const std::string& groupId, const std::string& userUuid, jobject jListener); - OCStackResult deleteInvitation(JNIEnv* env, const std::string& groupId, jobject jListener); + OCStackResult replyToInvitation(JNIEnv* env, const std::string& groupId, const bool accept, + jobject jListener); JniOnGetListener* addOnGetListener(JNIEnv* env, jobject jListener); JniOnPostListener* addOnPostListener(JNIEnv* env, jobject jListener); @@ -164,7 +166,7 @@ extern "C" { * Signature: (Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/OnGetListener;)V */ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_searchUser0 - (JNIEnv *env, jobject thiz, jstring juserUuid, jobject jListener); + (JNIEnv *, jobject, jstring, jobject); /* * Class: org_iotivity_base_OcAccountManager @@ -172,7 +174,7 @@ extern "C" { * Signature: (Ljava/util/Map;Lorg/iotivity/base/OcAccountManager/OnGetListener;)V */ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_searchUser1 - (JNIEnv *env, jobject thiz, jobject jQueryMap, jobject jListener); + (JNIEnv *, jobject, jobject, jobject); /* * Class: org_iotivity_base_OcAccountManager @@ -180,23 +182,23 @@ extern "C" { * Signature: (Ljava/lang/String;Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/onDeleteListener;)V */ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_deleteDevice0 - (JNIEnv *env, jobject thiz, jstring jDeviceId, jobject jListener); + (JNIEnv *, jobject, jstring, jstring, jobject); /* * Class: org_iotivity_base_OcAccountManager * Method: createGroup0 - * Signature: (Lorg/iotivity/base/AclGroupType;Lorg/iotivity/base/OcAccountManager/OnPostListener;)V + * Signature: (Lorg/iotivity/base/OcAccountManager/OnPostListener;)V */ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_createGroup0 - (JNIEnv *env, jobject thiz, jint groupType, jobject jListener); + (JNIEnv *, jobject, jobject); /* * Class: org_iotivity_base_OcAccountManager - * Method: getGroupList0 - * Signature: (Lorg/iotivity/base/OcAccountManager/OnGetListener;)V + * Method: createGroup1 + * Signature: (Ljava/util/Map;Lorg/iotivity/base/OcAccountManager/OnPostListener;)V */ - JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_getGroupList0 - (JNIEnv *env, jobject thiz, jobject jListener); + JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_createGroup1 + (JNIEnv *, jobject, jobject, jobject); /* * Class: org_iotivity_base_OcAccountManager @@ -204,63 +206,66 @@ extern "C" { * Signature: (Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/onDeleteListener;)V */ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_deleteGroup0 - (JNIEnv *env, jobject thiz, jstring jGroupId, jobject jListener); + (JNIEnv *, jobject, jstring, jobject); /* * Class: org_iotivity_base_OcAccountManager - * Method: joinGroup0 - * Signature: (Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/OnPostListener;)V + * Method: getGroupInfoAll0 + * Signature: (Lorg/iotivity/base/OcAccountManager/OnGetListener;)V */ - JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_joinGroup0 - (JNIEnv *env, jobject thiz, jstring jGroupId, jobject jListener); + JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_getGroupInfoAll0 + (JNIEnv *, jobject, jobject); /* * Class: org_iotivity_base_OcAccountManager - * Method: addDeviceToGroup0 - * Signature: (Ljava/lang/String;[Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/OnPostListener;)V + * Method: getGroupInfo0 + * Signature: (Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/OnGetListener;)V */ - JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_addDeviceToGroup0 - (JNIEnv *env, jobject thiz, jstring jGroupId, jobjectArray jDeviceIdArray, jobject jListener); + JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_getGroupInfo0 + (JNIEnv *, jobject, jstring, jobject); /* * Class: org_iotivity_base_OcAccountManager - * Method: getGroupInfo0 - * Signature: (Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/OnGetListener;)V + * Method: addPropertyValueToGroup0 + * Signature: (Ljava/lang/String;Lorg/iotivity/base/OcRepresentation; + * Lorg/iotivity/base/OcAccountManager/OnPostListener;)V */ - JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_getGroupInfo0 - (JNIEnv *env, jobject thiz, jstring jGroupId, jobject jListener); + JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_addPropertyValueToGroup0 + (JNIEnv *, jobject, jstring, jobject, jobject); /* * Class: org_iotivity_base_OcAccountManager - * Method: leaveGroup0 - * Signature: (Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/onDeleteListener;)V + * Method: deletePropertyValueFromGroup0 + * Signature: (Ljava/lang/String;Lorg/iotivity/base/OcRepresentation; + * Lorg/iotivity/base/OcAccountManager/OnPostListener;)V */ - JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_leaveGroup0 - (JNIEnv *env, jobject thiz, jstring jGroupId, jobject jListener); + JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_deletePropertyValueFromGroup0 + (JNIEnv *, jobject, jstring, jobject, jobject); /* * Class: org_iotivity_base_OcAccountManager - * Method: deleteDeviceFromGroup0 - * Signature: (Ljava/lang/String;[Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/onDeleteListener;)V + * Method: updatePropertyValueOnGroup0 + * Signature: (Ljava/lang/String;Lorg/iotivity/base/OcRepresentation; + * Lorg/iotivity/base/OcAccountManager/OnPostListener;)V */ - JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_deleteDeviceFromGroup0 - (JNIEnv *env, jobject thiz, jstring jGroupId, jobjectArray jDeviceIdArray, jobject jListener); + JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_updatePropertyValueOnGroup0 + (JNIEnv *, jobject, jstring, jobject, jobject); /* * Class: org_iotivity_base_OcAccountManager * Method: observeGroup0 - * Signature: (Ljava/lang/String;Lorg/iotivity/base/OcResource/OnObserveListener;)V + * Signature: (Lorg/iotivity/base/OcResource/OnObserveListener;)V */ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_observeGroup0 - (JNIEnv *env, jobject thiz, jstring jGroupId, jobject jListener); + (JNIEnv *, jobject, jobject); /* * Class: org_iotivity_base_OcAccountManager * Method: cancelObserveGroup0 - * Signature: (Ljava/lang/String;)V + * Signature: ()V */ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_cancelObserveGroup0 - (JNIEnv *env, jobject thiz, jstring jGroupId); + (JNIEnv *, jobject); /* * Class: org_iotivity_base_OcAccountManager @@ -268,7 +273,7 @@ extern "C" { * Signature: (Lorg/iotivity/base/OcResource/OnObserveListener;)V */ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_observeInvitation0 - (JNIEnv *env, jobject thiz, jobject jListener); + (JNIEnv *, jobject, jobject); /* * Class: org_iotivity_base_OcAccountManager @@ -276,7 +281,7 @@ extern "C" { * Signature: ()V */ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_cancelObserveInvitation0 - (JNIEnv *env, jobject thiz); + (JNIEnv *, jobject); /* * Class: org_iotivity_base_OcAccountManager @@ -284,7 +289,7 @@ extern "C" { * Signature: (Ljava/lang/String;Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/OnPostListener;)V */ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_sendInvitation0 - (JNIEnv *env, jobject thiz, jstring jGroupId, jstring jUserUuid, jobject jListener); + (JNIEnv *, jobject, jstring, jstring, jobject); /* * Class: org_iotivity_base_OcAccountManager @@ -292,15 +297,15 @@ extern "C" { * Signature: (Ljava/lang/String;Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/onDeleteListener;)V */ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_cancelInvitation0 - (JNIEnv *env, jobject thiz, jstring jGroupId, jstring jUserUuid, jobject jListener); + (JNIEnv *, jobject, jstring, jstring, jobject); /* * Class: org_iotivity_base_OcAccountManager - * Method: deleteInvitation0 - * Signature: (Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/onDeleteListener;)V + * Method: replyToInvitation0 + * Signature: (Ljava/lang/String;ZLorg/iotivity/base/OcAccountManager/onDeleteListener;)V */ - JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_deleteInvitation0 - (JNIEnv *env, jobject thiz, jstring jGroupId, jobject jListener); + JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_replyToInvitation0 + (JNIEnv *, jobject, jstring, jboolean, jobject); #ifdef __cplusplus } diff --git a/android/android_api/base/jni/JniUtils.h b/android/android_api/base/jni/JniUtils.h index 5297293..74e48e6 100644 --- a/android/android_api/base/jni/JniUtils.h +++ b/android/android_api/base/jni/JniUtils.h @@ -108,21 +108,7 @@ public: return OC::ObserveType::ObserveAll; }; } -#ifdef WITH_CLOUD - static OC::AclGroupType getAclGroupType(JNIEnv *env, int type) - { - switch (type) - { - case 0: - return OC::AclGroupType::PUBLIC; - case 1: - return OC::AclGroupType::PRIVATE; - default: - ThrowOcException(OC_STACK_INVALID_PARAM, "Unexpected acl group type"); - return OC::AclGroupType::PUBLIC; - }; - } -#endif + static OCEntityHandlerResult getOCEntityHandlerResult(JNIEnv *env, int type) { switch (type) diff --git a/android/android_api/base/src/main/java/org/iotivity/base/AclGroupType.java b/android/android_api/base/src/main/java/org/iotivity/base/AclGroupType.java deleted file mode 100644 index abacec9..0000000 --- a/android/android_api/base/src/main/java/org/iotivity/base/AclGroupType.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - ******************************************************************* - * - * Copyright 2016 Samsung Electronics All Rights Reserved. - * - *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - */ - -package org.iotivity.base; - -public enum AclGroupType { - PUBLIC(0), - PRIVATE(1),; - - private int value; - - private AclGroupType(int value) { - this.value = value; - } - - public int getValue() { - return this.value; - } -} diff --git a/android/android_api/base/src/main/java/org/iotivity/base/OcAccountManager.java b/android/android_api/base/src/main/java/org/iotivity/base/OcAccountManager.java index f2a995b..783f709 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/OcAccountManager.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/OcAccountManager.java @@ -73,7 +73,7 @@ public final class OcAccountManager { OnPostListener onPostListener) throws OcException; /** - * overload + * Method for account registration to account server * * @param authProvider Provider name used for authentication. * @param authCode The authorization code obtained by using an authorization server @@ -117,15 +117,18 @@ public final class OcAccountManager { /** * Method for sign-out to account server * + * @param accessToken Identifier of the resource obtained by account registration. * @param onPostListener event handler The event handler will be invoked with a map of * attribute name and values. * @throws OcException if failure */ - public void signOut(OnPostListener onPostListener) throws OcException { - this.signOut0(onPostListener); + public void signOut(String accessToken, + OnPostListener onPostListener) throws OcException { + this.signOut0(accessToken, onPostListener); } - private native void signOut0(OnPostListener onPostListener) throws OcException; + private native void signOut0(String accessToken, + OnPostListener onPostListener) throws OcException; /** * Method to refresh access token to account server @@ -151,8 +154,7 @@ public final class OcAccountManager { * * @param userUuid Identifier of the user to get information. * @param onGetListener The event handler will be invoked with a map of attribute name and - * values. The event handler will also have the result from this Get - * operation This will have error codes + * values. It will also have the result from this Get operation. * @throws OcException if failure */ public void searchUser(String userUuid, @@ -164,13 +166,12 @@ public final class OcAccountManager { OnGetListener onGetListener) throws OcException; /** - * Overload + * Method to get information of the user to account server * * @param queryMap Map which can have the query key and value for specific users. * account server can response information of more than one user. * @param onGetListener The event handler will be invoked with a map of attribute name and - * values. The event handler will also have the result from this Get - * operation This will have error codes + * values. It will also have the result from this Get operation. * @throws OcException if failure */ public void searchUser(Map queryMap, @@ -184,56 +185,58 @@ public final class OcAccountManager { /** * Method to delete the device registered on the account signed-in * + * @param accessToken Identifier of the resource obtained by account registration. * @param deviceId Device ID to delete. * @param onDeleteListener event handler The event handler will have headerOptionList * @throws OcException if failure */ - public void deleteDevice(String deviceId, + public void deleteDevice(String accessToken, + String deviceId, OnDeleteListener onDeleteListener) throws OcException { - this.deleteDevice0(deviceId, onDeleteListener); + this.deleteDevice0(accessToken, deviceId, onDeleteListener); } - private native void deleteDevice0(String deviceId, + private native void deleteDevice0(String accessToken, + String deviceId, OnDeleteListener onDeleteListener) throws OcException; /** * Method to delete the device registered on the account signed-in * - * @param groupType Group type that can be used for referencing default group ACL creation. * @param onPostListener event handler The event handler will be invoked with a map of * attribute name and values. * @throws OcException if failure */ - public void createGroup(AclGroupType groupType, - OnPostListener onPostListener) throws OcException { - this.createGroup0(groupType.getValue(), onPostListener); + public void createGroup(OnPostListener onPostListener) throws OcException { + this.createGroup0(onPostListener); } - private native void createGroup0(int groupType, - OnPostListener onPostListener) throws OcException; + private native void createGroup0(OnPostListener onPostListener) throws OcException; /** - * Method to get a list of groups joined from account server - * - * @param onGetListener The event handler will be invoked with a map of attribute name and - * values. The event handler will also have the result from this Get - * operation This will have error codes + * Method to delete the device registered on the account signed-in * - * @return Returns ::OC_STACK_OK if success + * @param queryMap Map that has optional properties and values to create a group. + * Defined properties on the OCF spec are [gname, parent] so far. + * (2016/10/19) + * @param onPostListener event handler The event handler will be invoked with a map of + * attribute name and values. + * @throws OcException if failure */ - public void getGroupList(OnGetListener onGetListener) throws OcException { - this.getGroupList0(onGetListener); + public void createGroup(Map queryMap, + OnPostListener onPostListener) throws OcException { + this.createGroup1(queryMap, onPostListener); } - private native void getGroupList0(OnGetListener onGetListener) throws OcException; + private native void createGroup1(Map queryMap, + OnPostListener onPostListener) throws OcException; /** - * Method to delete the group from account server + * Method to delete the group from account server. * * @param groupId Group ID to delete. * @param onDeleteListener event handler The event handler will have headerOptionList. - * - * @return Returns ::OC_STACK_OK if success + * @throws OcException if failure */ public void deleteGroup(String groupId, OnDeleteListener onDeleteListener) throws OcException { @@ -244,55 +247,27 @@ public final class OcAccountManager { OnDeleteListener onDeleteListener) throws OcException; /** - * Method to join the group on account server + * Method to get infomation of all your group from account server. * - * @param groupId Group ID to join - * @param onPostListener event handler The event handler will be invoked with a map of - * attribute name and values. - * - * @return Returns ::OC_STACK_OK if success - */ - public void joinGroup(String groupId, - OnPostListener onPostListener) throws OcException { - this.joinGroup0(groupId, onPostListener); - } - - private native void joinGroup0(String groupId, - OnPostListener onPostListener) throws OcException; - - /** - * Method to add devices to the group on account server - * - * @param groupId Group ID to add devices. - * @param deviceId List of devices to add. - * @param onPostListener event handler The event handler will be invoked with a map of - * attribute name and values. - * - * @return Returns ::OC_STACK_OK if success + * @param onGetListener The event handler will be invoked with a map of attribute name and + * values. It will also have the result from this Get operation. + * @throws OcException if failure */ - public void addDeviceToGroup(String groupId, - List deviceId, - OnPostListener onPostListener) throws OcException { - this.addDeviceToGroup0(groupId, deviceId.toArray(new String[deviceId.size()]), - onPostListener); + public void getGroupInfoAll(OnGetListener onGetListener) throws OcException { + this.getGroupInfoAll0(onGetListener); } - private native void addDeviceToGroup0(String groupId, - String[] deviceId, - OnPostListener onPostListener) throws OcException; + private native void getGroupInfoAll0(OnGetListener onGetListener) throws OcException; /** - * Method to get information of the group from account server + * Method to get information of the specific group from account server. * * @param groupId Group ID to get information. * @param onGetListener The event handler will be invoked with a map of attribute name and - * values. The event handler will also have the result from this Get - * operation This will have error codes - * - * @return Returns ::OC_STACK_OK if success + * values. It will also have the result from this Get operation. + * @throws OcException if failure */ - public void getGroupInfo(String groupId, - OnGetListener onGetListener) throws OcException { + public void getGroupInfo(String groupId, OnGetListener onGetListener) throws OcException { this.getGroupInfo0(groupId, onGetListener); } @@ -300,80 +275,106 @@ public final class OcAccountManager { OnGetListener onGetListener) throws OcException; /** - * Method to leave the group joined on account server - * - * @param groupId Group ID to leave. - * @param onDeleteListener event handler The event handler will have headerOptionList. + * Method to add values for properties to the group on account server. * - * @return Returns ::OC_STACK_OK if success + * @param groupId Group ID to add property values. + * @param propertyValue OCRepresentation info that has pairs of property and value. + * Defined properties on the OCF spec are [members, masters, devices, + * resources, links] so far. (2016/10/19) + * @param onPostListener event handler The event handler will be invoked with a map of + * attribute name and values. + * @throws OcException if failure */ - public void leaveGroup(String groupId, - OnDeleteListener onDeleteListener) throws OcException { - this.leaveGroup0(groupId, onDeleteListener); + public void addPropertyValueToGroup(String groupId, + OcRepresentation propertyValue, + OnPostListener onPostListener) throws OcException { + this.addPropertyValueToGroup0(groupId, propertyValue, onPostListener); } - private native void leaveGroup0(String groupId, - OnDeleteListener onDeleteListener) throws OcException; + private native void addPropertyValueToGroup0(String groupId, + OcRepresentation propertyValue, + OnPostListener onPostListener) throws OcException; /** - * Method to delete devices from the group on account server - * - * @param groupId Group ID to delete devices. - * @param deviceId List of devices to delete. - * @param onDeleteListener event handler The event handler will have headerOptionList. + * Method to delete values for properties from the group on account server. * - * @return Returns ::OC_STACK_OK if success + * @param groupId Group ID to add property values. + * @param propertyValue OCRepresentation info that has pairs of property and value. + * Defined properties on the OCF spec are [members, masters, devices, + * resources, links] so far. (2016/10/19) + * @param onPostListener event handler The event handler will be invoked with a map of + * attribute name and values. + * @throws OcException if failure */ - public void deleteDeviceFromGroup(String groupId, - List deviceId, - OnDeleteListener onDeleteListener) throws OcException { - this.deleteDeviceFromGroup0(groupId, deviceId.toArray(new String[deviceId.size()]), - onDeleteListener); + public void deletePropertyValueFromGroup(String groupId, + OcRepresentation propertyValue, + OnPostListener onPostListener) throws OcException { + this.deletePropertyValueFromGroup0(groupId, propertyValue, onPostListener); } - private native void deleteDeviceFromGroup0(String groupId, - String[] deviceId, - OnDeleteListener onDeleteListener) throws OcException; + private native void deletePropertyValueFromGroup0(String groupId, + OcRepresentation propertyValue, + OnPostListener onPostListener) throws OcException; /** - * Method to register observe to the group on account server - * User can receive a notify when the group get changed (eg. new user/device added) - * - * @param groupId Group ID to observe. - * @param cloudConnectHandler Callback function that will get the result of the operation. - * - * @return Returns ::OC_STACK_OK if success + * Method to update values for properties on the group on account server. + * It completely replaces existing values for specific properties. + * + * @param groupId Group ID to add property values. + * @param propertyValue OCRepresentation info that has pairs of property and value. + * Defined properties on the OCF spec are [members, gname, owner, + * masters, devices, resources, latitude, longitude, radius, + * backgroundImage] so far. (2016/10/19) + * @param onPostListener event handler The event handler will be invoked with a map of + * attribute name and values. + * @throws OcException if failure */ - public void observeGroup(String groupId, - OnObserveListener onObserveListener) throws OcException { - this.observeGroup0(groupId, onObserveListener); + public void updatePropertyValueOnGroup(String groupId, + OcRepresentation propertyValue, + OnPostListener onPostListener) throws OcException { + this.updatePropertyValueOnGroup0(groupId, propertyValue, onPostListener); } - private native void observeGroup0(String groupId, - OnObserveListener onObserveListener) throws OcException; + private native void updatePropertyValueOnGroup0(String groupId, + OcRepresentation propertyValue, + OnPostListener onPostListener) throws OcException; /** - * Method to cancel observe to the group on account server - * - * @param groupId Group ID to observe. + * Method to register observe to group resource on account server. + * You can receive a notification when any value of property get changed in the group you + * joined. * - * @return Returns ::OC_STACK_OK if success + * @param onObserveListener event handler The handler method will be invoked with a map + * of attribute name and values. + * @throws OcException if failure */ - public void cancelObserveGroup(String groupId) throws OcException { - this.cancelObserveGroup0(groupId); + public void observeGroup(OnObserveListener onObserveListener) throws OcException { + this.observeGroup0(onObserveListener); } - private native void cancelObserveGroup0(String groupId) throws OcException; + private native void observeGroup0(OnObserveListener onObserveListener) throws OcException; /** - * Method to register observe to invitation resource on account server - * User can receive a invitation which is including group ID to join - * Once receive a invitation, user should call 'deleteInvitation' to delete a invitation - * on account server. - * - * @param cloudConnectHandler Callback function that will get the result of the operation. + * Method to cancel observe to group resource on account server. * - * @return Returns ::OC_STACK_OK if success + * @throws OcException if failure + */ + public void cancelObserveGroup() throws OcException { + this.cancelObserveGroup0(); + } + + private native void cancelObserveGroup0() throws OcException; + + /** + * Method to register observe to invitation resource on account server. + * You can receive a notification when you send or receive a invitation. + * Sending a invitation will be notified as 'invite' and Receiving will be as 'invited'. + * If you receive a invitation from other user, you should call 'replyToInvitation' to + * delete the invitation on account server, otherwise it will remain on the server. + * + * @param onObserveListener event handler The handler method will be invoked with a map + * of attribute name and values. + * @throws OcException if failure */ public void observeInvitation(OnObserveListener onObserveListener) throws OcException { this.observeInvitation0(onObserveListener); @@ -384,7 +385,7 @@ public final class OcAccountManager { /** * Method to cancel observe to invitation resource on account server * - * @return Returns ::OC_STACK_OK if success + * @throws OcException if failure */ public void cancelObserveInvitation() throws OcException { this.cancelObserveInvitation0(); @@ -393,14 +394,13 @@ public final class OcAccountManager { private native void cancelObserveInvitation0() throws OcException; /** - * Method to send a invitation to invite a user into a group + * Method to send a invitation to invite a user into a group. * * @param groupId Group ID for inviting. * @param userUuid Identifier of the user to invite. * @param onPostListener event handler The event handler will be invoked with a map of * attribute name and values. - * - * @return Returns ::OC_STACK_OK if success + * @throws OcException if failure */ public void sendInvitation(String groupId, String userUuid, @@ -413,13 +413,13 @@ public final class OcAccountManager { OnPostListener onPostListener) throws OcException; /** - * Method to cancel a invitation on account server that user has sent + * Method to cancel a invitation on account server you has sent before the invited user + * replies. * * @param groupId Group ID to cancel a invitation. * @param userUuid Identifier of the user to cancel a invitation. * @param onDeleteListener event handler The event handler will have headerOptionList. - * - * @return Returns ::OC_STACK_OK if success + * @throws OcException if failure */ public void cancelInvitation(String groupId, String userUuid, @@ -432,20 +432,24 @@ public final class OcAccountManager { OnDeleteListener onDeleteListener) throws OcException; /** - * Method to delete a invitation on account server that user has received + * Method to reply to the invitation that you has received. + * If you set accept as true, you will join the group as a member and the invitation will be + * deleted on account server. If false, only the invitation will be deleted. * * @param groupId Group ID to delete a invitation. + * @param accept boolean whether to join the group or not. * @param onDeleteListener event handler The event handler will have headerOptionList. - * - * @return Returns ::OC_STACK_OK if success + * @throws OcException if failure */ - public void deleteInvitation(String groupId, - OnDeleteListener onDeleteListener) throws OcException { - this.deleteInvitation0(groupId, onDeleteListener); + public void replyToInvitation(String groupId, + boolean accept, + OnDeleteListener onDeleteListener) throws OcException { + this.replyToInvitation0(groupId, accept, onDeleteListener); } - private native void deleteInvitation0(String groupId, - OnDeleteListener onDeleteListener) throws OcException; + private native void replyToInvitation0(String groupId, + boolean accept, + OnDeleteListener onDeleteListener) throws OcException; /** * An OnGetListener can be registered via the resource get call. diff --git a/android/examples/simplebase/src/main/java/org/iotivity/base/examples/CloudFragment.java b/android/examples/simplebase/src/main/java/org/iotivity/base/examples/CloudFragment.java index 3d21bb7..1365353 100644 --- a/android/examples/simplebase/src/main/java/org/iotivity/base/examples/CloudFragment.java +++ b/android/examples/simplebase/src/main/java/org/iotivity/base/examples/CloudFragment.java @@ -46,7 +46,6 @@ import android.widget.Switch; import android.widget.TextView; import android.widget.Toast; -import org.iotivity.base.AclGroupType; import org.iotivity.base.EntityHandlerResult; import org.iotivity.base.ErrorCode; import org.iotivity.base.ModeType; @@ -78,6 +77,7 @@ import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.regex.Pattern; /** @@ -184,7 +184,7 @@ public class CloudFragment extends Fragment implements private void signOut() { try { msg("signOut"); - mAccountManager.signOut(onSignOut); + mAccountManager.signOut(mAccessToken, onSignOut); } catch (OcException e) { e.printStackTrace(); } @@ -193,12 +193,25 @@ public class CloudFragment extends Fragment implements private void createGroup() { try { msg("createGroup"); - mAccountManager.createGroup(AclGroupType.PUBLIC, onCreateGroup); + mAccountManager.createGroup(onCreateGroup); } catch (OcException e) { e.printStackTrace(); } } + private void deleteGroup() { + if (mGroupId == null) { + msg("there is no any group"); + } else { + try { + msg("deleteGroup"); + mAccountManager.deleteGroup(mGroupId, onDeleteGroup); + } catch (OcException e) { + e.printStackTrace(); + } + } + } + private void inviteUser() { if (mGroupId == null) { msg("there is no any group"); @@ -207,19 +220,29 @@ public class CloudFragment extends Fragment implements } } - private void leaveGroup() { - try { - if (mGroupId == null) { - msg("there is no any group"); - } else { - msg("leaveGroup"); - mAccountManager.leaveGroup(mGroupId, onLeaveGroup); - } - } catch (OcException e) { - e.printStackTrace(); + private void addPropertyValueToGroup() { + if (mGroupId == null) { + msg("there is no any group"); + } else { + showPostPropertyValueToGroup(0); } } + private void deletePropertyValueFromGroup() { + if (mGroupId == null) { + msg("there is no any group"); + } else { + showPostPropertyValueToGroup(1); + } + } + + private void updatePropertyValueOnGroup() { + if (mGroupId == null) { + msg("there is no any group"); + } else { + showPostPropertyValueToGroup(2); + } + } // FOR WEB-VIEW @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { @@ -281,8 +304,10 @@ public class CloudFragment extends Fragment implements try { msg("observeInvitation"); mAccountManager.observeInvitation(onObserveInvitation); + msg("observeGroup"); + mAccountManager.observeGroup(onObserveGroup); msg("getGroupList"); - mAccountManager.getGroupList(onGetGroupList); + mAccountManager.getGroupInfoAll(onGetGroupInfoAll); } catch (OcException e) { Log.e(TAG, e.toString()); } @@ -319,20 +344,49 @@ public class CloudFragment extends Fragment implements } }; - OcAccountManager.OnGetListener onGetGroupList = new OcAccountManager.OnGetListener() { + OcAccountManager.OnGetListener onGetGroupInfoAll = new OcAccountManager.OnGetListener() { @Override public void onGetCompleted(List list, OcRepresentation ocRepresentation) { - msg("getGroupList was successful"); + msg("getGroupInfoAll was successful"); try { - String[] gidlist = ocRepresentation.getValue("gidlist"); - if (gidlist == null) { + + OcRepresentation[] gidlist = ocRepresentation.getValue("groups"); + if (gidlist == null || gidlist.length == 0) { msg("\tgroup list is empty"); mGroupId = null; } else { msg("\tgroup list"); - for (String group : gidlist) { - msg("\t\t" + group); - mGroupId = group; + + for (OcRepresentation group : gidlist) { + String gid = group.getValue("gid"); + String gname = group.getValue("gname"); + String owner = group.getValue("owner"); + + msg("\t\t-GroupID : " + gid); + msg("\t\t Group name : " + gname); + msg("\t\t Owner : " + owner); + + String[] members = group.getValue("members"); + if (members != null && members.length != 0) { + msg("\t\t members :"); + for (String member : members) { + msg("\t\t\t" + member); + } + } + + String[] devices = group.getValue("devices"); + if (devices != null && devices.length != 0) { + msg("\t\t devices"); + for (String device : devices) { + msg("\t\t\t" + device); + } + } + + if (group.hasAttribute("parent")) { + msg("\t\t parent group : " + group.getValue("parent")); + } + + mGroupId = gid; } msg("\tcurrent group is " + mGroupId); } @@ -343,7 +397,31 @@ public class CloudFragment extends Fragment implements @Override public void onGetFailed(Throwable throwable) { - msg("Failed to getGroupList"); + msg("Failed to getGroupInfoAll"); + if (throwable instanceof OcException) { + OcException ocEx = (OcException) throwable; + Log.e(TAG, ocEx.toString()); + ErrorCode errCode = ocEx.getErrorCode(); + msg("Error code: " + errCode); + } + } + }; + + OcAccountManager.OnGetListener onGetGroupInfo = new OcAccountManager.OnGetListener() { + @Override + public void onGetCompleted(List list, OcRepresentation ocRepresentation) { + msg("getGroupInfo was successful"); + + Map valueMap = ocRepresentation.getValues(); + + for (Map.Entry entry : valueMap.entrySet()) { + msg("\tproperty: " + entry.getKey() + " value: " + entry.getValue()); + } + } + + @Override + public void onGetFailed(Throwable throwable) { + msg("Failed to getGroupInfo"); if (throwable instanceof OcException) { OcException ocEx = (OcException) throwable; Log.e(TAG, ocEx.toString()); @@ -365,7 +443,7 @@ public class CloudFragment extends Fragment implements OcRepresentation[] sendInvitationList = ocRepresentation.getValue("invite"); - if (sendInvitationList != null) { + if (sendInvitationList != null && sendInvitationList.length != 0) { msg("\tList of invitation that I sent"); for (OcRepresentation invitation : sendInvitationList) { String gid = invitation.getValue("gid"); @@ -377,7 +455,7 @@ public class CloudFragment extends Fragment implements OcRepresentation[] receiveInvitationList = ocRepresentation.getValue("invited"); - if (receiveInvitationList != null) { + if (receiveInvitationList != null && receiveInvitationList.length != 0) { msg("\tList of invitation that I received"); for (OcRepresentation invitation : receiveInvitationList) { String gid = invitation.getValue("gid"); @@ -391,7 +469,7 @@ public class CloudFragment extends Fragment implements } else { OcRepresentation[] sendInvitationList = ocRepresentation.getValue("invite"); - if (sendInvitationList != null) { + if (sendInvitationList != null && sendInvitationList.length != 0) { msg("\tList of invitation that I sent"); for (OcRepresentation invitation : sendInvitationList) { String gid = invitation.getValue("gid"); @@ -403,7 +481,7 @@ public class CloudFragment extends Fragment implements OcRepresentation[] receivInvitationList = ocRepresentation.getValue("invited"); - if (receivInvitationList != null) { + if (receivInvitationList != null && receivInvitationList.length != 0) { msg("\tList of invitation that I received"); for (OcRepresentation invitation : receivInvitationList) { mGroupId = invitation.getValue("gid"); @@ -470,37 +548,24 @@ public class CloudFragment extends Fragment implements } }; - OcAccountManager.OnPostListener onJoinGroup = new OcAccountManager.OnPostListener() { + OcAccountManager.OnDeleteListener onDeleteGroup = new OcAccountManager.OnDeleteListener() { @Override - public synchronized void onPostCompleted(List list, - OcRepresentation ocRepresentation) { - msg("joinGroup was successful"); - try { - msg("observeGroup"); - mAccountManager.observeGroup(mGroupId, onObserveGroup); - } catch (OcException e) { - Log.e(TAG, e.toString()); - } + public void onDeleteCompleted(List list) { + msg("deleteGroup was successful"); } @Override - public synchronized void onPostFailed(Throwable throwable) { - msg("Failed to joinGroup"); - if (throwable instanceof OcException) { - OcException ocEx = (OcException) throwable; - Log.e(TAG, ocEx.toString()); - ErrorCode errCode = ocEx.getErrorCode(); - msg("Error code: " + errCode); - } + public void onDeleteFailed(Throwable throwable) { + msg("Failed to deleteGroup"); } }; - OcAccountManager.OnDeleteListener onDeleteInvitation = new OcAccountManager.OnDeleteListener() { + OcAccountManager.OnDeleteListener onReplyToInvitation = new OcAccountManager.OnDeleteListener() { @Override public void onDeleteCompleted(List list) { - msg("deleteInvitation was successful"); + msg("replyToInvitation was successful"); try { - mAccountManager.getGroupList(onGetGroupList); + mAccountManager.getGroupInfoAll(onGetGroupInfoAll); } catch (OcException e) { e.printStackTrace(); } @@ -553,8 +618,8 @@ public class CloudFragment extends Fragment implements mGroupId = ocRepresentation.getValue("gid"); msg("\tgroupId: " + mGroupId); - msg("observeGroup"); - mAccountManager.observeGroup(mGroupId, onObserveGroup); + msg("getGroupInfo"); + mAccountManager.getGroupInfo(mGroupId, onGetGroupInfo); } catch (OcException e) { Log.e(TAG, e.toString()); } @@ -590,7 +655,7 @@ public class CloudFragment extends Fragment implements msg("\tGroupMasterID: " + gmid); String[] midlist = ocRepresentation.getValue("midlist"); - if (midlist == null) { + if (midlist == null || midlist.length == 0) { msg("\tMember List is empty"); } else { msg("\tMember List(" + midlist.length + ")"); @@ -600,7 +665,7 @@ public class CloudFragment extends Fragment implements } String[] dilist = ocRepresentation.getValue("dilist"); - if (dilist == null) { + if (dilist == null || dilist.length == 0) { msg("\tDevice List is empty"); } else { msg("\tDevice List(" + dilist.length + ")"); @@ -626,16 +691,16 @@ public class CloudFragment extends Fragment implements } }; - OcAccountManager.OnPostListener onSendInvitation = new OcAccountManager.OnPostListener() { + OcAccountManager.OnPostListener onPostPropertyValue = new OcAccountManager.OnPostListener() { @Override public synchronized void onPostCompleted(List list, OcRepresentation ocRepresentation) { - msg("sendInvitation was successful"); + msg("Post was successful (changed property value)"); } @Override public synchronized void onPostFailed(Throwable throwable) { - msg("Failed to sendInvitation"); + msg("Failed to Post (changed property value)"); if (throwable instanceof OcException) { OcException ocEx = (OcException) throwable; Log.e(TAG, ocEx.toString()); @@ -645,21 +710,22 @@ public class CloudFragment extends Fragment implements } }; - OcAccountManager.OnDeleteListener onLeaveGroup = new OcAccountManager.OnDeleteListener() { + OcAccountManager.OnPostListener onSendInvitation = new OcAccountManager.OnPostListener() { @Override - public void onDeleteCompleted(List list) { - msg("leaveGroup was successful"); - try { - msg("getGroupList"); - mAccountManager.getGroupList(onGetGroupList); - } catch (OcException e) { - e.printStackTrace(); - } + public synchronized void onPostCompleted(List list, + OcRepresentation ocRepresentation) { + msg("sendInvitation was successful"); } @Override - public void onDeleteFailed(Throwable throwable) { - msg("Failed to leaveGroup"); + public synchronized void onPostFailed(Throwable throwable) { + msg("Failed to sendInvitation"); + if (throwable instanceof OcException) { + OcException ocEx = (OcException) throwable; + Log.e(TAG, ocEx.toString()); + ErrorCode errCode = ocEx.getErrorCode(); + msg("Error code: " + errCode); + } } }; @@ -1451,6 +1517,65 @@ public class CloudFragment extends Fragment implements alert.show(); } + + private void showPostPropertyValueToGroup(int operation) { + LayoutInflater layoutInflater = LayoutInflater.from(mContext); + View inputView = layoutInflater.inflate(R.layout.input, null); + AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(mActivity); + alertDialogBuilder.setView(inputView); + + final int op = operation; + + final TextView textView = (TextView) inputView.getRootView().findViewById(R.id.inputView); + final EditText editText = (EditText) inputView.getRootView().findViewById(R.id.inputText); + final TextView textView2 = (TextView) inputView.getRootView().findViewById(R.id.inputView2); + final EditText editText2 = (EditText) inputView.getRootView().findViewById(R.id.inputText2); + + textView.setText("Please enter property."); + textView2.setText("Please enter value(String Array)."); + textView2.setVisibility(View.VISIBLE); + editText2.setVisibility(View.VISIBLE); + + + alertDialogBuilder + .setCancelable(true) + .setPositiveButton("OK", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + if (editText.getText().length() != 0 && editText2.getText().length() != 0){ + final String property = editText.getText().toString(); + final String value = editText2.getText().toString(); + String[] values = {value}; + + try { + OcRepresentation propertyValue = new OcRepresentation(); + propertyValue.setValue(property, values); + + if (op == 0) { + msg("addPropertyValueToGroup"); + mAccountManager.addPropertyValueToGroup(mGroupId, propertyValue, onPostPropertyValue); + } else if (op == 1){ + msg("deletePropertyValueFromGroup"); + mAccountManager.deletePropertyValueFromGroup(mGroupId, propertyValue, onPostPropertyValue); + } else if (op == 2){ + msg("updatePropertyValueOnGroup"); + mAccountManager.updatePropertyValueOnGroup(mGroupId, propertyValue, onPostPropertyValue); + } + } catch (OcException e) { + e.printStackTrace(); + } + } + } + }) + .setNegativeButton("Cancel", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + dialog.cancel(); + } + }); + + AlertDialog alert = alertDialogBuilder.create(); + alert.show(); + } + private void showInviteMsg(String userID) { AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(mActivity); @@ -1466,10 +1591,8 @@ public class CloudFragment extends Fragment implements .setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { try { - msg("joinGroup"); - mAccountManager.joinGroup(mGroupId, onJoinGroup); - msg("deleteInvitation"); - mAccountManager.deleteInvitation(mGroupId, onDeleteInvitation); + msg("replyToInvitation (accept:yes)"); + mAccountManager.replyToInvitation(mGroupId, true, onReplyToInvitation); } catch (OcException e) { e.printStackTrace(); } @@ -1479,9 +1602,8 @@ public class CloudFragment extends Fragment implements public void onClick(DialogInterface dialog, int id) { dialog.cancel(); try { - msg("gid: " + mGroupId); - msg("deleteInvitation"); - mAccountManager.deleteInvitation(mGroupId, onDeleteInvitation); + msg("replyToInvitation (accept:no)"); + mAccountManager.replyToInvitation(mGroupId, false, onReplyToInvitation); } catch (OcException e) { e.printStackTrace(); } @@ -1533,7 +1655,8 @@ public class CloudFragment extends Fragment implements int viewID = view.getId(); if (mAccountManager == null && (viewID == R.id.signin_button || viewID == R.id.signout_button || viewID == R.id.creategroup_button - || viewID == R.id.invite_button || viewID == R.id.leavegroup_button)) { + || viewID == R.id.invite_button || viewID == R.id.addpropertyvalue_button + || viewID == R.id.deletepropertyvalue_button || viewID == R.id.updatepropertyvalue_button)) { mActionLog.append("Do 'SignUp' first" + EOL); return; } @@ -1560,13 +1683,25 @@ public class CloudFragment extends Fragment implements mActionLog.append("Create Group" + EOL); createGroup(); break; + case R.id.deletegroup_button: + mActionLog.append("Delete Group" + EOL); + deleteGroup(); + break; case R.id.invite_button: mActionLog.append("Invite User" + EOL); inviteUser(); break; - case R.id.leavegroup_button: - mActionLog.append("Leave Group" + EOL); - leaveGroup(); + case R.id.addpropertyvalue_button: + mActionLog.append("Add Property Value To Group" + EOL); + addPropertyValueToGroup(); + break; + case R.id.deletepropertyvalue_button: + mActionLog.append("Delete Property Value From Group" + EOL); + deletePropertyValueFromGroup(); + break; + case R.id.updatepropertyvalue_button: + mActionLog.append("Update Property Value On Group" + EOL); + updatePropertyValueOnGroup(); break; // RD @@ -1652,14 +1787,18 @@ public class CloudFragment extends Fragment implements Button signOutButton = (Button) rootView.findViewById(R.id.signout_button); Button createGroupButton = (Button) rootView.findViewById(R.id.creategroup_button); Button inviteButton = (Button) rootView.findViewById(R.id.invite_button); - Button leaveGroupButton = (Button) rootView.findViewById(R.id.leavegroup_button); + Button addValueToGroup = (Button) rootView.findViewById(R.id.addpropertyvalue_button); + Button deleteValueFromGroup = (Button) rootView.findViewById(R.id.deletepropertyvalue_button); + Button updateValueOnGroup = (Button) rootView.findViewById(R.id.updatepropertyvalue_button); setIPButton.setOnClickListener(this); signUpButton.setOnClickListener(this); signInButton.setOnClickListener(this); signOutButton.setOnClickListener(this); createGroupButton.setOnClickListener(this); inviteButton.setOnClickListener(this); - leaveGroupButton.setOnClickListener(this); + addValueToGroup.setOnClickListener(this); + deleteValueFromGroup.setOnClickListener(this); + updateValueOnGroup.setOnClickListener(this); Button rdPubButton = (Button) rootView.findViewById(R.id.rdpub_button); Button rdDelButton = (Button) rootView.findViewById(R.id.rddel_button); diff --git a/android/examples/simplebase/src/main/res/layout/fragment_cloud.xml b/android/examples/simplebase/src/main/res/layout/fragment_cloud.xml index 6610566..b53f873 100644 --- a/android/examples/simplebase/src/main/res/layout/fragment_cloud.xml +++ b/android/examples/simplebase/src/main/res/layout/fragment_cloud.xml @@ -103,18 +103,49 @@ android:text="CREATE\nGROUP" />