add JNI methods related to group&invite
authorJaewook Jung <jw0213.jung@samsung.com>
Thu, 18 Aug 2016 13:41:33 +0000 (22:41 +0900)
committerAshok Babu Channa <ashok.channa@samsung.com>
Thu, 25 Aug 2016 08:28:56 +0000 (08:28 +0000)
As I added new C++ APIs related to group and invite, I implemented JNI
methods too.
(https://gerrit.iotivity.org/gerrit/#/c/10149/)

Change-Id: I48be652cec7eb6d85cd8e406481e62a7d3f2dc5f
Signed-off-by: Jaewook Jung <jw0213.jung@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/10625
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: jihwan seo <jihwan.seo@samsung.com>
Reviewed-by: Ashok Babu Channa <ashok.channa@samsung.com>
16 files changed:
android/android_api/base/jni/JniOcAccountManager.cpp
android/android_api/base/jni/JniOcAccountManager.h
android/android_api/base/jni/JniOcPlatform.cpp
android/android_api/base/jni/JniOnDeleteListener.cpp
android/android_api/base/jni/JniOnGetListener.cpp
android/android_api/base/jni/JniOnObserveListener.cpp
android/android_api/base/jni/JniOnObserveListener.h
android/android_api/base/jni/JniOnPostListener.cpp
android/android_api/base/jni/JniUtils.h
android/android_api/base/src/main/java/org/iotivity/base/AclGroupType.java [new file with mode: 0644]
android/android_api/base/src/main/java/org/iotivity/base/OcAccountManager.java
resource/csdk/stack/include/octypes.h
resource/include/OCAccountManager.h
resource/include/OCApi.h
resource/src/OCAccountManager.cpp
resource/unittests/OCAccountManagerTest.cpp

index 228bc49..9556111 100644 (file)
@@ -45,6 +45,7 @@ JniOcAccountManager::~JniOcAccountManager()
     m_onGetManager.removeAllListeners(env);
     m_onPostManager.removeAllListeners(env);
     m_onDeleteManager.removeAllListeners(env);
+    m_onObserveManager.removeAllListeners(env);
 
     if (JNI_EDETACHED == envRet)
     {
@@ -91,6 +92,11 @@ JniOnDeleteListener* JniOcAccountManager::addOnDeleteListener(JNIEnv* env, jobje
     return this->m_onDeleteManager.addListener(env, jListener, this);
 }
 
+JniOnObserveListener* JniOcAccountManager::addOnObserveListener(JNIEnv* env, jobject jListener)
+{
+    return this->m_onObserveManager.addListener(env, jListener, this);
+}
+
 void JniOcAccountManager::removeOnGetListener(JNIEnv* env, jobject jListener)
 {
     this->m_onGetManager.removeListener(env, jListener);
@@ -106,6 +112,11 @@ void JniOcAccountManager::removeOnDeleteListener(JNIEnv* env, jobject jListener)
     this->m_onDeleteManager.removeListener(env, jListener);
 }
 
+void JniOcAccountManager::removeOnObserveListener(JNIEnv* env, jobject jListener)
+{
+    this->m_onObserveManager.removeListener(env, jListener);
+}
+
 OCStackResult JniOcAccountManager::signUp(JNIEnv* env, const std::string& authProvider,
                                           const std::string& authCode, jobject jListener)
 {
@@ -219,6 +230,199 @@ OCStackResult JniOcAccountManager::deleteDevice(JNIEnv* env, const std::string&
     return m_sharedAccountManager->deleteDevice(deviceId, deleteCallback);
 }
 
+OCStackResult JniOcAccountManager::createGroup(JNIEnv* env, AclGroupType groupType,
+                                               jobject jListener)
+{
+    JniOnPostListener *onPostListener = addOnPostListener(env, jListener);
+
+    PostCallback postCallback = [onPostListener](const HeaderOptions& opts,
+        const OCRepresentation& rep, const int eCode)
+    {
+        onPostListener->onPostCallback(opts, rep, eCode);
+    };
+
+    return m_sharedAccountManager->createGroup(groupType, postCallback);
+}
+
+OCStackResult JniOcAccountManager::getGroupList(JNIEnv* env, jobject jListener)
+{
+    JniOnGetListener *onGetListener = addOnGetListener(env, jListener);
+
+    GetCallback getCallback = [onGetListener](const HeaderOptions& opts,
+        const OCRepresentation& rep, const int eCode)
+    {
+        onGetListener->onGetCallback(opts, rep, eCode);
+    };
+
+    return m_sharedAccountManager->getGroupList(getCallback);
+}
+
+OCStackResult JniOcAccountManager::deleteGroup(JNIEnv* env, const std::string& groupId,
+                                               jobject jListener)
+{
+    JniOnDeleteListener *onDeleteListener = addOnDeleteListener(env, jListener);
+
+    DeleteCallback deleteCallback = [onDeleteListener](const HeaderOptions& opts,
+        const int eCode)
+    {
+        onDeleteListener->onDeleteCallback(opts, eCode);
+    };
+
+    return m_sharedAccountManager->deleteGroup(groupId, deleteCallback);
+}
+
+OCStackResult JniOcAccountManager::joinGroup(JNIEnv* env, const std::string& groupId,
+                                             jobject jListener)
+{
+    JniOnPostListener *onPostListener = addOnPostListener(env, jListener);
+
+    PostCallback postCallback = [onPostListener](const HeaderOptions& opts,
+        const OCRepresentation& rep, const int eCode)
+    {
+        onPostListener->onPostCallback(opts, rep, eCode);
+    };
+
+    return m_sharedAccountManager->joinGroup(groupId, postCallback);
+}
+
+OCStackResult JniOcAccountManager::addDeviceToGroup(JNIEnv* env, const std::string& groupId,
+                                                    const std::vector<std::string>& deviceId,
+                                                    jobject jListener)
+{
+    JniOnPostListener *onPostListener = addOnPostListener(env, jListener);
+
+    PostCallback postCallback = [onPostListener](const HeaderOptions& opts,
+        const OCRepresentation& rep, const int eCode)
+    {
+        onPostListener->onPostCallback(opts, rep, eCode);
+    };
+
+    return m_sharedAccountManager->addDeviceToGroup(groupId, deviceId, postCallback);
+}
+
+OCStackResult JniOcAccountManager::getGroupInfo(JNIEnv* env, const std::string& groupId,
+                                                jobject jListener)
+{
+    JniOnGetListener *onGetListener = addOnGetListener(env, jListener);
+
+    GetCallback getCallback = [onGetListener](const HeaderOptions& opts,
+        const OCRepresentation& rep, const int eCode)
+    {
+        onGetListener->onGetCallback(opts, rep, eCode);
+    };
+
+    return m_sharedAccountManager->getGroupInfo(groupId, getCallback);
+}
+
+OCStackResult JniOcAccountManager::leaveGroup(JNIEnv* env, const std::string& groupId,
+                                              jobject jListener)
+{
+    JniOnDeleteListener *onDeleteListener = addOnDeleteListener(env, jListener);
+
+    DeleteCallback deleteCallback = [onDeleteListener](const HeaderOptions& opts,
+        const int eCode)
+    {
+        onDeleteListener->onDeleteCallback(opts, eCode);
+    };
+
+    return m_sharedAccountManager->leaveGroup(groupId, deleteCallback);
+}
+
+OCStackResult JniOcAccountManager::deleteDeviceFromGroup(JNIEnv* env, const std::string& groupId,
+                                                         const std::vector<std::string>& deviceId,
+                                                         jobject jListener)
+{
+    JniOnDeleteListener *onDeleteListener = addOnDeleteListener(env, jListener);
+
+    DeleteCallback deleteCallback = [onDeleteListener](const HeaderOptions& opts,
+        const int eCode)
+    {
+        onDeleteListener->onDeleteCallback(opts, eCode);
+    };
+
+    return m_sharedAccountManager->deleteDeviceFromGroup(groupId, deviceId, deleteCallback);
+}
+
+OCStackResult JniOcAccountManager::observeGroup(JNIEnv* env, const std::string& groupId,
+                                                jobject jListener)
+{
+    JniOnObserveListener *onObserveListener = addOnObserveListener(env, jListener);
+
+    ObserveCallback observeCallback = [onObserveListener](const HeaderOptions& opts,
+        const OCRepresentation& rep, const int& eCode, const int& sequenceNumber)
+    {
+        onObserveListener->onObserveCallback(opts, rep, eCode, sequenceNumber);
+    };
+
+    return m_sharedAccountManager->observeGroup(groupId, observeCallback);
+}
+
+OCStackResult JniOcAccountManager::cancelObserveGroup(const std::string& groupId)
+{
+    return m_sharedAccountManager->cancelObserveGroup(groupId);
+}
+
+OCStackResult JniOcAccountManager::observeInvitation(JNIEnv* env, jobject jListener)
+{
+    JniOnObserveListener *onObserveListener = addOnObserveListener(env, jListener);
+
+    ObserveCallback observeCallback = [onObserveListener](const HeaderOptions& opts,
+        const OCRepresentation& rep, const int& eCode, const int& sequenceNumber)
+    {
+        onObserveListener->onObserveCallback(opts, rep, eCode, sequenceNumber);
+    };
+
+    return m_sharedAccountManager->observeInvitation(observeCallback);
+}
+
+OCStackResult JniOcAccountManager::cancelObserveInvitation()
+{
+    return m_sharedAccountManager->cancelObserveInvitation();
+}
+
+OCStackResult JniOcAccountManager::sendInvitation(JNIEnv* env, const std::string& groupId,
+                                                  const std::string& userUuid, jobject jListener)
+{
+    JniOnPostListener *onPostListener = addOnPostListener(env, jListener);
+
+    PostCallback postCallback = [onPostListener](const HeaderOptions& opts,
+        const OCRepresentation& rep, const int eCode)
+    {
+        onPostListener->onPostCallback(opts, rep, eCode);
+    };
+
+    return m_sharedAccountManager->sendInvitation(groupId, userUuid, postCallback);
+}
+
+OCStackResult JniOcAccountManager::cancelInvitation(JNIEnv* env, const std::string& groupId,
+                                                    const std::string& userUuid, jobject jListener)
+{
+    JniOnDeleteListener *onDeleteListener = addOnDeleteListener(env, jListener);
+
+    DeleteCallback deleteCallback = [onDeleteListener](const HeaderOptions& opts,
+        const int eCode)
+    {
+        onDeleteListener->onDeleteCallback(opts, eCode);
+    };
+
+    return m_sharedAccountManager->cancelInvitation(groupId, userUuid, deleteCallback);
+}
+
+OCStackResult JniOcAccountManager::deleteInvitation(JNIEnv* env, const std::string& groupId,
+                                                    jobject jListener)
+{
+    JniOnDeleteListener *onDeleteListener = addOnDeleteListener(env, jListener);
+
+    DeleteCallback deleteCallback = [onDeleteListener](const HeaderOptions& opts,
+        const int eCode)
+    {
+        onDeleteListener->onDeleteCallback(opts, eCode);
+    };
+
+    return m_sharedAccountManager->deleteInvitation(groupId, deleteCallback);
+}
+
+
 /*
 * Class:     org_iotivity_base_OcAccountManager
 * Method:    getHost
@@ -612,7 +816,7 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_searchUser1
 /*
 * Class:     org_iotivity_base_OcAccountManager
 * Method:    deleteDevice0
-* Signature: (Ljava/lang/String;Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/onDeleteListener;)V
+* Signature: (Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/onDeleteListener;)V
 */
 JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_deleteDevice0
     (JNIEnv *env, jobject thiz, jstring jDeviceId, jobject jListener)
@@ -654,3 +858,683 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_deleteDevice0
         ThrowOcException(e.code(), e.reason().c_str());
     }
 }
+
+/*
+* Class:     org_iotivity_base_OcAccountManager
+* Method:    createGroup0
+* Signature: (Lorg/iotivity/base/AclGroupType;Lorg/iotivity/base/OcAccountManager/OnPostListener;)V
+*/
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_createGroup0
+    (JNIEnv *env, jobject thiz, jint groupType, jobject jListener)
+{
+    LOGD("OcAccountManager_createGroup");
+    if (!jListener)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "onPostListener cannot be null");
+        return;
+    }
+
+    JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env,
+                                                                                         thiz);
+    if (!accountManager)
+    {
+        return;
+    }
+
+    try
+    {
+        OCStackResult result = accountManager->createGroup(env,
+            JniUtils::getAclGroupType(env, static_cast<int>(groupType)),
+            jListener);
+
+        if (OC_STACK_OK != result)
+        {
+            ThrowOcException(result, "OcAccountManager_createGroup");
+        }
+    }
+    catch (OCException& e)
+    {
+        LOGE("%s", e.reason().c_str());
+        ThrowOcException(e.code(), e.reason().c_str());
+    }
+}
+
+/*
+* Class:     org_iotivity_base_OcAccountManager
+* Method:    getGroupList0
+* Signature: (Lorg/iotivity/base/OcAccountManager/OnGetListener;)V
+*/
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_getGroupList0
+    (JNIEnv *env, jobject thiz, jobject jListener)
+{
+    LOGD("OcAccountManager_getGroupList");
+    if (!jListener)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "onGetListener cannot be null");
+        return;
+    }
+
+    JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env,
+                                                                                         thiz);
+    if (!accountManager)
+    {
+        return;
+    }
+
+    try
+    {
+        OCStackResult result = accountManager->getGroupList(env,
+                                                            jListener);
+
+        if (OC_STACK_OK != result)
+        {
+            ThrowOcException(result, "OcAccountManager_getGroupList");
+        }
+    }
+    catch (OCException& e)
+    {
+        LOGE("%s", e.reason().c_str());
+        ThrowOcException(e.code(), e.reason().c_str());
+    }
+}
+
+/*
+* Class:     org_iotivity_base_OcAccountManager
+* Method:    deleteGroup0
+* Signature: (Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/onDeleteListener;)V
+*/
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_deleteGroup0
+    (JNIEnv *env, jobject thiz, jstring jGroupId, jobject jListener)
+{
+    LOGD("OcAccountManager_deleteGroup");
+    if (!jListener)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "onDeleteListener cannot be null");
+        return;
+    }
+
+    JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env,
+                                                                                         thiz);
+    if (!accountManager)
+    {
+        return;
+    }
+
+    std::string groupId;
+    if (jGroupId)
+    {
+        groupId = env->GetStringUTFChars(jGroupId, nullptr);
+    }
+
+    try
+    {
+        OCStackResult result = accountManager->deleteGroup(env,
+                                                           groupId,
+                                                           jListener);
+
+        if (OC_STACK_OK != result)
+        {
+            ThrowOcException(result, "OcAccountManager_deleteGroup");
+        }
+    }
+    catch (OCException& e)
+    {
+        LOGE("%s", e.reason().c_str());
+        ThrowOcException(e.code(), e.reason().c_str());
+    }
+}
+
+/*
+* Class:     org_iotivity_base_OcAccountManager
+* Method:    joinGroup0
+* Signature: (Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/OnPostListener;)V
+*/
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_joinGroup0
+    (JNIEnv *env, jobject thiz, jstring jGroupId, jobject jListener)
+{
+    LOGD("OcAccountManager_joinGroup");
+    if (!jListener)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "onPostListener cannot be null");
+        return;
+    }
+
+    JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env,
+                                                                                         thiz);
+    if (!accountManager)
+    {
+        return;
+    }
+
+    std::string groupId;
+    if (jGroupId)
+    {
+        groupId = env->GetStringUTFChars(jGroupId, nullptr);
+    }
+
+    try
+    {
+        OCStackResult result = accountManager->joinGroup(env,
+                                                         groupId,
+                                                         jListener);
+
+        if (OC_STACK_OK != result)
+        {
+            ThrowOcException(result, "OcAccountManager_joinGroup");
+        }
+    }
+    catch (OCException& e)
+    {
+        LOGE("%s", e.reason().c_str());
+        ThrowOcException(e.code(), e.reason().c_str());
+    }
+}
+
+/*
+* Class:     org_iotivity_base_OcAccountManager
+* Method:    addDeviceToGroup0
+* Signature: (Ljava/lang/String;[Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/OnPostListener;)V
+*/
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_addDeviceToGroup0
+    (JNIEnv *env, jobject thiz, jstring jGroupId, jobjectArray jDeviceIdArray, jobject jListener)
+{
+    LOGD("OcAccountManager_addDeviceToGroup");
+    if (!jListener)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "onPostListener cannot be null");
+        return;
+    }
+    if (!jDeviceIdArray)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "deviceId cannot be null");
+        return;
+    }
+
+    JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env,
+                                                                                         thiz);
+    if (!accountManager)
+    {
+        return;
+    }
+
+    std::string groupId;
+    if (jGroupId)
+    {
+        groupId = env->GetStringUTFChars(jGroupId, nullptr);
+    }
+
+    std::vector<std::string> deviceIds;
+    JniUtils::convertJavaStrArrToStrVector(env, jDeviceIdArray, deviceIds);
+
+    try
+    {
+        OCStackResult result = accountManager->addDeviceToGroup(env,
+                                                                groupId,
+                                                                deviceIds,
+                                                                jListener);
+
+        if (OC_STACK_OK != result)
+        {
+            ThrowOcException(result, "OcAccountManager_addDeviceToGroup");
+        }
+    }
+    catch (OCException& e)
+    {
+        LOGE("%s", e.reason().c_str());
+        ThrowOcException(e.code(), e.reason().c_str());
+    }
+}
+
+/*
+* Class:     org_iotivity_base_OcAccountManager
+* Method:    getGroupInfo0
+* Signature: (Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/OnGetListener;)V
+*/
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_getGroupInfo0
+    (JNIEnv *env, jobject thiz, jstring jGroupId, jobject jListener)
+{
+    LOGD("OcAccountManager_getGroupInfo");
+    if (!jListener)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "onGetListener cannot be null");
+        return;
+    }
+
+    JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env,
+                                                                                         thiz);
+    if (!accountManager)
+    {
+        return;
+    }
+
+    std::string groupId;
+    if (jGroupId)
+    {
+        groupId = env->GetStringUTFChars(jGroupId, nullptr);
+    }
+
+    try
+    {
+        OCStackResult result = accountManager->getGroupInfo(env,
+                                                            groupId,
+                                                            jListener);
+
+        if (OC_STACK_OK != result)
+        {
+            ThrowOcException(result, "OcAccountManager_getGroupInfo");
+        }
+    }
+    catch (OCException& e)
+    {
+        LOGE("%s", e.reason().c_str());
+        ThrowOcException(e.code(), e.reason().c_str());
+    }
+}
+
+/*
+* Class:     org_iotivity_base_OcAccountManager
+* Method:    leaveGroup0
+* Signature: (Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/onDeleteListener;)V
+*/
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_leaveGroup0
+    (JNIEnv *env, jobject thiz, jstring jGroupId, jobject jListener)
+{
+    LOGD("OcAccountManager_leaveGroup");
+    if (!jListener)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "onDeleteListener cannot be null");
+        return;
+    }
+
+    JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env,
+                                                                                         thiz);
+    if (!accountManager)
+    {
+        return;
+    }
+
+    std::string groupId;
+    if (jGroupId)
+    {
+        groupId = env->GetStringUTFChars(jGroupId, nullptr);
+    }
+
+    try
+    {
+        OCStackResult result = accountManager->leaveGroup(env,
+                                                          groupId,
+                                                          jListener);
+
+        if (OC_STACK_OK != result)
+        {
+            ThrowOcException(result, "OcAccountManager_leaveGroup");
+        }
+    }
+    catch (OCException& e)
+    {
+        LOGE("%s", e.reason().c_str());
+        ThrowOcException(e.code(), e.reason().c_str());
+    }
+}
+
+/*
+* Class:     org_iotivity_base_OcAccountManager
+* Method:    deleteDeviceFromGroup0
+* Signature: (Ljava/lang/String;[Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/onDeleteListener;)V
+*/
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_deleteDeviceFromGroup0
+    (JNIEnv *env, jobject thiz, jstring jGroupId, jobjectArray jDeviceIdArray, jobject jListener)
+{
+    LOGD("OcAccountManager_deleteDeviceFromGroup");
+    if (!jListener)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "onDeleteListener cannot be null");
+        return;
+    }
+    if (!jDeviceIdArray)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "deviceId cannot be null");
+        return;
+    }
+
+    JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env,
+                                                                                         thiz);
+    if (!accountManager)
+    {
+        return;
+    }
+
+    std::string groupId;
+    if (jGroupId)
+    {
+        groupId = env->GetStringUTFChars(jGroupId, nullptr);
+    }
+
+    std::vector<std::string> deviceIds;
+    JniUtils::convertJavaStrArrToStrVector(env, jDeviceIdArray, deviceIds);
+
+    try
+    {
+        OCStackResult result = accountManager->deleteDeviceFromGroup(env,
+                                                                     groupId,
+                                                                     deviceIds,
+                                                                     jListener);
+
+        if (OC_STACK_OK != result)
+        {
+            ThrowOcException(result, "OcAccountManager_deleteDeviceFromGroup");
+        }
+    }
+    catch (OCException& e)
+    {
+        LOGE("%s", e.reason().c_str());
+        ThrowOcException(e.code(), e.reason().c_str());
+    }
+}
+
+/*
+* Class:     org_iotivity_base_OcAccountManager
+* Method:    observeGroup0
+* Signature: (Ljava/lang/String;Lorg/iotivity/base/OcResource/OnObserveListener;)V
+*/
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_observeGroup0
+    (JNIEnv *env, jobject thiz, jstring jGroupId, jobject jListener)
+{
+    LOGD("OcAccountManager_observeGroup");
+    if (!jListener)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "onObserveListener cannot be null");
+        return;
+    }
+
+    JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env,
+                                                                                         thiz);
+    if (!accountManager)
+    {
+        return;
+    }
+
+    std::string groupId;
+    if (jGroupId)
+    {
+        groupId = env->GetStringUTFChars(jGroupId, nullptr);
+    }
+
+    try
+    {
+        OCStackResult result = accountManager->observeGroup(env,
+                                                            groupId,
+                                                            jListener);
+
+        if (OC_STACK_OK != result)
+        {
+            ThrowOcException(result, "OcAccountManager_observeGroup");
+        }
+    }
+    catch (OCException& e)
+    {
+        LOGE("%s", e.reason().c_str());
+        ThrowOcException(e.code(), e.reason().c_str());
+    }
+}
+
+/*
+* Class:     org_iotivity_base_OcAccountManager
+* Method:    cancelObserveGroup0
+* Signature: (Ljava/lang/String;)V
+*/
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_cancelObserveGroup0
+    (JNIEnv *env, jobject thiz, jstring jGroupId)
+{
+    LOGD("OcAccountManager_cancelObserveGroup");
+
+    JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env,
+                                                                                         thiz);
+    if (!accountManager)
+    {
+        return;
+    }
+
+    std::string groupId;
+    if (jGroupId)
+    {
+        groupId = env->GetStringUTFChars(jGroupId, nullptr);
+    }
+
+    try
+    {
+        OCStackResult result = accountManager->cancelObserveGroup(groupId);
+
+        if (OC_STACK_OK != result)
+        {
+            ThrowOcException(result, "OcAccountManager_cancelObserveGroup");
+        }
+    }
+    catch (OCException& e)
+    {
+        LOGE("%s", e.reason().c_str());
+        ThrowOcException(e.code(), e.reason().c_str());
+    }
+}
+
+/*
+* Class:     org_iotivity_base_OcAccountManager
+* Method:    observeInvitation0
+* Signature: (Lorg/iotivity/base/OcResource/OnObserveListener;)V
+*/
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_observeInvitation0
+    (JNIEnv *env, jobject thiz, jobject jListener)
+{
+    LOGD("OcAccountManager_observeInvitation");
+    if (!jListener)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "onObserveListener cannot be null");
+        return;
+    }
+
+    JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env,
+                                                                                         thiz);
+    if (!accountManager)
+    {
+        return;
+    }
+
+    try
+    {
+        OCStackResult result = accountManager->observeInvitation(env,
+                                                                 jListener);
+
+        if (OC_STACK_OK != result)
+        {
+            ThrowOcException(result, "OcAccountManager_observeInvitation");
+        }
+    }
+    catch (OCException& e)
+    {
+        LOGE("%s", e.reason().c_str());
+        ThrowOcException(e.code(), e.reason().c_str());
+    }
+}
+
+/*
+* Class:     org_iotivity_base_OcAccountManager
+* Method:    cancelObserveInvitation0
+* Signature: ()V
+*/
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_cancelObserveInvitation0
+    (JNIEnv *env, jobject thiz)
+{
+    LOGD("OcAccountManager_cancelObserveInvitation");
+
+    JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env,
+                                                                                         thiz);
+    if (!accountManager)
+    {
+        return;
+    }
+
+    try
+    {
+        OCStackResult result = accountManager->cancelObserveInvitation();
+
+        if (OC_STACK_OK != result)
+        {
+            ThrowOcException(result, "OcAccountManager_cancelObserveInvitation");
+        }
+    }
+    catch (OCException& e)
+    {
+        LOGE("%s", e.reason().c_str());
+        ThrowOcException(e.code(), e.reason().c_str());
+    }
+}
+
+/*
+* Class:     org_iotivity_base_OcAccountManager
+* Method:    sendInvitation0
+* Signature: (Ljava/lang/String;Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/OnPostListener;)V
+*/
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_sendInvitation0
+    (JNIEnv *env, jobject thiz, jstring jGroupId, jstring jUserUuid, jobject jListener)
+{
+    LOGD("OcAccountManager_sendInvitation");
+    if (!jListener)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "onPostListener cannot be null");
+        return;
+    }
+
+    JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env,
+                                                                                         thiz);
+    if (!accountManager)
+    {
+        return;
+    }
+
+    std::string groupId, userUuid;
+    if (jGroupId)
+    {
+        groupId = env->GetStringUTFChars(jGroupId, nullptr);
+    }
+    if (jUserUuid)
+    {
+        userUuid = env->GetStringUTFChars(jUserUuid, nullptr);
+    }
+
+    try
+    {
+        OCStackResult result = accountManager->sendInvitation(env,
+                                                              groupId,
+                                                              userUuid,
+                                                              jListener);
+
+        if (OC_STACK_OK != result)
+        {
+            ThrowOcException(result, "OcAccountManager_sendInvitation");
+        }
+    }
+    catch (OCException& e)
+    {
+        LOGE("%s", e.reason().c_str());
+        ThrowOcException(e.code(), e.reason().c_str());
+    }
+}
+
+/*
+* Class:     org_iotivity_base_OcAccountManager
+* Method:    cancelInvitation0
+* Signature: (Ljava/lang/String;Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/onDeleteListener;)V
+*/
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_cancelInvitation0
+    (JNIEnv *env, jobject thiz, jstring jGroupId, jstring jUserUuid, jobject jListener)
+{
+    LOGD("OcAccountManager_cancelInvitation");
+    if (!jListener)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "onDeleteListener cannot be null");
+        return;
+    }
+
+    JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env,
+                                                                                         thiz);
+    if (!accountManager)
+    {
+        return;
+    }
+
+    std::string groupId, userUuid;
+    if (jGroupId)
+    {
+        groupId = env->GetStringUTFChars(jGroupId, nullptr);
+    }
+    if (jUserUuid)
+    {
+        userUuid = env->GetStringUTFChars(jUserUuid, nullptr);
+    }
+
+    try
+    {
+        OCStackResult result = accountManager->cancelInvitation(env,
+                                                                groupId,
+                                                                userUuid,
+                                                                jListener);
+
+        if (OC_STACK_OK != result)
+        {
+            ThrowOcException(result, "OcAccountManager_cancelInvitation");
+        }
+    }
+    catch (OCException& e)
+    {
+        LOGE("%s", e.reason().c_str());
+        ThrowOcException(e.code(), e.reason().c_str());
+    }
+}
+
+/*
+* Class:     org_iotivity_base_OcAccountManager
+* Method:    deleteInvitation0
+* Signature: (Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/onDeleteListener;)V
+*/
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_deleteInvitation0
+    (JNIEnv *env, jobject thiz, jstring jGroupId, jobject jListener)
+{
+    LOGD("OcAccountManager_deleteInvitation");
+    if (!jListener)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "onDeleteListener cannot be null");
+        return;
+    }
+
+    JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env,
+                                                                                         thiz);
+    if (!accountManager)
+    {
+        return;
+    }
+
+    std::string groupId;
+    if (jGroupId)
+    {
+        groupId = env->GetStringUTFChars(jGroupId, nullptr);
+    }
+
+    try
+    {
+        OCStackResult result = accountManager->deleteInvitation(env,
+                                                                groupId,
+                                                                jListener);
+
+        if (OC_STACK_OK != result)
+        {
+            ThrowOcException(result, "OcAccountManager_deleteInvitation");
+        }
+    }
+    catch (OCException& e)
+    {
+        LOGE("%s", e.reason().c_str());
+        ThrowOcException(e.code(), e.reason().c_str());
+    }
+}
+
+
index 24ae56f..7ff841e 100644 (file)
@@ -29,6 +29,7 @@
 #include "JniOnGetListener.h"
 #include "JniOnPostListener.h"
 #include "JniOnDeleteListener.h"
+#include "JniOnObserveListener.h"
 
 using namespace OC;
 
@@ -55,19 +56,42 @@ public:
     OCStackResult searchUser(JNIEnv* env, const std::string& userUuid, jobject jListener);
     OCStackResult searchUser(JNIEnv* env, const QueryParamsMap& queryMap, jobject jListener);
     OCStackResult deleteDevice(JNIEnv* env, const std::string& deviceId, jobject jListener);
+    OCStackResult createGroup(JNIEnv* env, AclGroupType groupType, jobject jListener);
+    OCStackResult getGroupList(JNIEnv* env, jobject jListener);
+    OCStackResult deleteGroup(JNIEnv* env, const std::string& groupId, jobject jListener);
+    OCStackResult joinGroup(JNIEnv* env, const std::string& groupId, jobject jListener);
+    OCStackResult addDeviceToGroup(JNIEnv* env, const std::string& groupId,
+                                   const std::vector<std::string>& deviceId, jobject jListener);
+    OCStackResult getGroupInfo(JNIEnv* env, const std::string& groupId, jobject jListener);
+    OCStackResult leaveGroup(JNIEnv* env, const std::string& groupId, jobject jListener);
+    OCStackResult deleteDeviceFromGroup(JNIEnv* env, const std::string& groupId,
+                                        const std::vector<std::string>& deviceId,
+                                        jobject jListener);
+    OCStackResult observeGroup(JNIEnv* env, const std::string& groupId, jobject jListener);
+    OCStackResult cancelObserveGroup(const std::string& groupId);
+    OCStackResult observeInvitation(JNIEnv* env, jobject jListener);
+    OCStackResult cancelObserveInvitation();
+    OCStackResult sendInvitation(JNIEnv* env, const std::string& groupId,
+                                 const std::string& userUuid, jobject jListener);
+    OCStackResult cancelInvitation(JNIEnv* env, const std::string& groupId,
+                                   const std::string& userUuid, jobject jListener);
+    OCStackResult deleteInvitation(JNIEnv* env, const std::string& groupId, jobject jListener);
 
     JniOnGetListener* addOnGetListener(JNIEnv* env, jobject jListener);
     JniOnPostListener* addOnPostListener(JNIEnv* env, jobject jListener);
     JniOnDeleteListener* addOnDeleteListener(JNIEnv* env, jobject jListener);
+    JniOnObserveListener* addOnObserveListener(JNIEnv* env, jobject jListener);
 
     void removeOnGetListener(JNIEnv* env, jobject jListener);
     void removeOnPostListener(JNIEnv* env, jobject jListener);
     void removeOnDeleteListener(JNIEnv* env, jobject jListener);
+    void removeOnObserveListener(JNIEnv* env, jobject jListener);
 
 private:
     JniListenerManager<JniOnGetListener> m_onGetManager;
     JniListenerManager<JniOnPostListener> m_onPostManager;
     JniListenerManager<JniOnDeleteListener> m_onDeleteManager;
+    JniListenerManager<JniOnObserveListener> m_onObserveManager;
 
     std::shared_ptr<OCAccountManager> m_sharedAccountManager;
 };
@@ -158,6 +182,126 @@ extern "C" {
     JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_deleteDevice0
         (JNIEnv *env, jobject thiz, jstring jDeviceId, jobject jListener);
 
+    /*
+    * Class:     org_iotivity_base_OcAccountManager
+    * Method:    createGroup0
+    * Signature: (Lorg/iotivity/base/AclGroupType;Lorg/iotivity/base/OcAccountManager/OnPostListener;)V
+    */
+    JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_createGroup0
+        (JNIEnv *env, jobject thiz, jint groupType, jobject jListener);
+
+    /*
+    * Class:     org_iotivity_base_OcAccountManager
+    * Method:    getGroupList0
+    * Signature: (Lorg/iotivity/base/OcAccountManager/OnGetListener;)V
+    */
+    JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_getGroupList0
+        (JNIEnv *env, jobject thiz, jobject jListener);
+
+    /*
+    * Class:     org_iotivity_base_OcAccountManager
+    * Method:    deleteGroup0
+    * Signature: (Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/onDeleteListener;)V
+    */
+    JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_deleteGroup0
+        (JNIEnv *env, jobject thiz, jstring jGroupId, jobject jListener);
+
+    /*
+    * Class:     org_iotivity_base_OcAccountManager
+    * Method:    joinGroup0
+    * Signature: (Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/OnPostListener;)V
+    */
+    JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_joinGroup0
+        (JNIEnv *env, jobject thiz, jstring jGroupId, jobject jListener);
+
+    /*
+    * Class:     org_iotivity_base_OcAccountManager
+    * Method:    addDeviceToGroup0
+    * Signature: (Ljava/lang/String;[Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/OnPostListener;)V
+    */
+    JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_addDeviceToGroup0
+        (JNIEnv *env, jobject thiz, jstring jGroupId, jobjectArray jDeviceIdArray, jobject jListener);
+
+    /*
+    * Class:     org_iotivity_base_OcAccountManager
+    * Method:    getGroupInfo0
+    * Signature: (Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/OnGetListener;)V
+    */
+    JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_getGroupInfo0
+        (JNIEnv *env, jobject thiz, jstring jGroupId, jobject jListener);
+
+    /*
+    * Class:     org_iotivity_base_OcAccountManager
+    * Method:    leaveGroup0
+    * Signature: (Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/onDeleteListener;)V
+    */
+    JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_leaveGroup0
+        (JNIEnv *env, jobject thiz, jstring jGroupId, jobject jListener);
+
+    /*
+    * Class:     org_iotivity_base_OcAccountManager
+    * Method:    deleteDeviceFromGroup0
+    * Signature: (Ljava/lang/String;[Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/onDeleteListener;)V
+    */
+    JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_deleteDeviceFromGroup0
+        (JNIEnv *env, jobject thiz, jstring jGroupId, jobjectArray jDeviceIdArray, jobject jListener);
+
+    /*
+    * Class:     org_iotivity_base_OcAccountManager
+    * Method:    observeGroup0
+    * Signature: (Ljava/lang/String;Lorg/iotivity/base/OcResource/OnObserveListener;)V
+    */
+    JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_observeGroup0
+        (JNIEnv *env, jobject thiz, jstring jGroupId, jobject jListener);
+
+    /*
+    * Class:     org_iotivity_base_OcAccountManager
+    * Method:    cancelObserveGroup0
+    * Signature: (Ljava/lang/String;)V
+    */
+    JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_cancelObserveGroup0
+        (JNIEnv *env, jobject thiz, jstring jGroupId);
+
+    /*
+    * Class:     org_iotivity_base_OcAccountManager
+    * Method:    observeInvitation0
+    * Signature: (Lorg/iotivity/base/OcResource/OnObserveListener;)V
+    */
+    JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_observeInvitation0
+        (JNIEnv *env, jobject thiz, jobject jListener);
+
+    /*
+    * Class:     org_iotivity_base_OcAccountManager
+    * Method:    cancelObserveInvitation0
+    * Signature: ()V
+    */
+    JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_cancelObserveInvitation0
+        (JNIEnv *env, jobject thiz);
+
+    /*
+    * Class:     org_iotivity_base_OcAccountManager
+    * Method:    sendInvitation0
+    * Signature: (Ljava/lang/String;Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/OnPostListener;)V
+    */
+    JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_sendInvitation0
+        (JNIEnv *env, jobject thiz, jstring jGroupId, jstring jUserUuid, jobject jListener);
+
+    /*
+    * Class:     org_iotivity_base_OcAccountManager
+    * Method:    cancelInvitation0
+    * Signature: (Ljava/lang/String;Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/onDeleteListener;)V
+    */
+    JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_cancelInvitation0
+        (JNIEnv *env, jobject thiz, jstring jGroupId, jstring jUserUuid, jobject jListener);
+
+    /*
+    * Class:     org_iotivity_base_OcAccountManager
+    * Method:    deleteInvitation0
+    * Signature: (Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/onDeleteListener;)V
+    */
+    JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_deleteInvitation0
+        (JNIEnv *env, jobject thiz, jstring jGroupId, jobject jListener);
+
 #ifdef __cplusplus
 }
 #endif
index c9c2cbf..4a5c846 100644 (file)
@@ -347,7 +347,7 @@ JniOnObserveListener* AddOnObserveListener(JNIEnv* env, jobject jListener)
     }
     if (!onObserveListener)
     {
-        onObserveListener = new JniOnObserveListener(env, jListener, nullptr);
+        onObserveListener = new JniOnObserveListener(env, jListener, (JniOcResource*)nullptr);
         jobject jgListener = env->NewGlobalRef(jListener);
         onObserveListenerMap.insert(
             std::pair<jobject, std::pair<JniOnObserveListener*, int>>(
index 70871e9..bb0f5db 100644 (file)
@@ -31,6 +31,9 @@ JniOnDeleteListener::JniOnDeleteListener(JNIEnv *env, jobject jListener, JniOcRe
     : m_ownerResource(owner)
 {
     m_jwListener = env->NewWeakGlobalRef(jListener);
+#ifdef WITH_CLOUD
+    m_ownerAccountManager = nullptr;
+#endif
 }
 
 #ifdef WITH_CLOUD
@@ -38,6 +41,7 @@ JniOnDeleteListener::JniOnDeleteListener(JNIEnv *env, jobject jListener, JniOcAc
     : m_ownerAccountManager(owner)
 {
     m_jwListener = env->NewWeakGlobalRef(jListener);
+    m_ownerResource = nullptr;
 }
 #endif
 
@@ -157,11 +161,11 @@ void JniOnDeleteListener::checkExAndRemoveListener(JNIEnv* env)
 #ifndef WITH_CLOUD
         m_ownerResource->removeOnDeleteListener(env, m_jwListener);
 #else
-        if (m_ownerResource)
+        if (nullptr != m_ownerResource)
         {
             m_ownerResource->removeOnDeleteListener(env, m_jwListener);
         }
-        if (m_ownerAccountManager)
+        if (nullptr != m_ownerAccountManager)
         {
             m_ownerAccountManager->removeOnDeleteListener(env, m_jwListener);
         }
@@ -173,11 +177,11 @@ void JniOnDeleteListener::checkExAndRemoveListener(JNIEnv* env)
 #ifndef WITH_CLOUD
         m_ownerResource->removeOnDeleteListener(env, m_jwListener);
 #else
-        if (m_ownerResource)
+        if (nullptr != m_ownerResource)
         {
             m_ownerResource->removeOnDeleteListener(env, m_jwListener);
         }
-        if (m_ownerAccountManager)
+        if (nullptr != m_ownerAccountManager)
         {
             m_ownerAccountManager->removeOnDeleteListener(env, m_jwListener);
         }
index 496c5a6..9a801f1 100644 (file)
@@ -31,6 +31,9 @@ JniOnGetListener::JniOnGetListener(JNIEnv *env, jobject jListener, JniOcResource
     : m_ownerResource(owner)
 {
     m_jwListener = env->NewWeakGlobalRef(jListener);
+#ifdef WITH_CLOUD
+    m_ownerAccountManager = nullptr;
+#endif
 }
 
 #ifdef WITH_CLOUD
@@ -38,6 +41,7 @@ JniOnGetListener::JniOnGetListener(JNIEnv *env, jobject jListener, JniOcAccountM
     : m_ownerAccountManager(owner)
 {
     m_jwListener = env->NewWeakGlobalRef(jListener);
+    m_ownerResource = nullptr;
 }
 #endif
 
@@ -183,11 +187,11 @@ void JniOnGetListener::checkExAndRemoveListener(JNIEnv* env)
 #ifndef WITH_CLOUD
         m_ownerResource->removeOnGetListener(env, m_jwListener);
 #else
-        if (m_ownerResource)
+        if (nullptr != m_ownerResource)
         {
             m_ownerResource->removeOnGetListener(env, m_jwListener);
         }
-        if (m_ownerAccountManager)
+        if (nullptr != m_ownerAccountManager)
         {
             m_ownerAccountManager->removeOnGetListener(env, m_jwListener);
         }
@@ -199,11 +203,11 @@ void JniOnGetListener::checkExAndRemoveListener(JNIEnv* env)
 #ifndef WITH_CLOUD
         m_ownerResource->removeOnGetListener(env, m_jwListener);
 #else
-        if (m_ownerResource)
+        if (nullptr != m_ownerResource)
         {
             m_ownerResource->removeOnGetListener(env, m_jwListener);
         }
-        if (m_ownerAccountManager)
+        if (nullptr != m_ownerAccountManager)
         {
             m_ownerAccountManager->removeOnGetListener(env, m_jwListener);
         }
index 48eda10..cbf1d2d 100644 (file)
 #include "JniOcResource.h"
 #include "JniOcRepresentation.h"
 #include "JniUtils.h"
+#ifdef WITH_CLOUD
+#include "JniOcAccountManager.h"
+#endif
 
 JniOnObserveListener::JniOnObserveListener(JNIEnv *env, jobject jListener, JniOcResource* owner)
     : m_ownerResource(owner)
 {
     m_jwListener = env->NewWeakGlobalRef(jListener);
+#ifdef WITH_CLOUD
+    m_ownerAccountManager = nullptr;
+#endif
 }
 
+#ifdef WITH_CLOUD
+JniOnObserveListener::JniOnObserveListener(JNIEnv *env, jobject jListener, JniOcAccountManager* owner)
+    : m_ownerAccountManager(owner)
+{
+    m_jwListener = env->NewWeakGlobalRef(jListener);
+    m_ownerResource = nullptr;
+}
+#endif
+
 JniOnObserveListener::~JniOnObserveListener()
 {
     if (m_jwListener)
@@ -177,12 +192,34 @@ void JniOnObserveListener::checkExAndRemoveListener(JNIEnv* env)
     {
         jthrowable ex = env->ExceptionOccurred();
         env->ExceptionClear();
+#ifndef WITH_CLOUD
         m_ownerResource->removeOnObserveListener(env, m_jwListener);
+#else
+        if (nullptr != m_ownerResource)
+        {
+            m_ownerResource->removeOnObserveListener(env, m_jwListener);
+        }
+        if (nullptr != m_ownerAccountManager)
+        {
+            m_ownerAccountManager->removeOnObserveListener(env, m_jwListener);
+        }
+#endif
         env->Throw((jthrowable)ex);
     }
     else
     {
+#ifndef WITH_CLOUD
         m_ownerResource->removeOnObserveListener(env, m_jwListener);
+#else
+        if (nullptr != m_ownerResource)
+        {
+            m_ownerResource->removeOnObserveListener(env, m_jwListener);
+        }
+        if (nullptr != m_ownerAccountManager)
+        {
+            m_ownerAccountManager->removeOnObserveListener(env, m_jwListener);
+        }
+#endif
     }
 }
 
index 5092dc1..3fc478d 100644 (file)
 using namespace OC;
 
 class JniOcResource;
+#ifdef WITH_CLOUD
+class JniOcAccountManager;
+#endif
 
 class JniOnObserveListener
 {
 public:
     JniOnObserveListener(JNIEnv *env, jobject jListener, JniOcResource* owner);
+#ifdef WITH_CLOUD
+    JniOnObserveListener(JNIEnv *env, jobject jListener, JniOcAccountManager* owner);
+#endif
     ~JniOnObserveListener();
     void onObserveCallback(const HeaderOptions headerOptions, const OCRepresentation& rep,
         const int& eCode, const int& sequenceNumber);
@@ -39,7 +45,10 @@ public:
 private:
     jweak m_jwListener;
     JniOcResource* m_ownerResource;
+#ifdef WITH_CLOUD
+    JniOcAccountManager* m_ownerAccountManager;
+#endif
     void checkExAndRemoveListener(JNIEnv *env);
 };
 
-#endif
\ No newline at end of file
+#endif
index e28079b..62f6e96 100644 (file)
@@ -31,6 +31,9 @@ JniOnPostListener::JniOnPostListener(JNIEnv *env, jobject jListener, JniOcResour
     : m_ownerResource(owner)
 {
     m_jwListener = env->NewWeakGlobalRef(jListener);
+#ifdef WITH_CLOUD
+    m_ownerAccountManager = nullptr;
+#endif
 }
 
 #ifdef WITH_CLOUD
@@ -38,6 +41,7 @@ JniOnPostListener::JniOnPostListener(JNIEnv *env, jobject jListener, JniOcAccoun
     : m_ownerAccountManager(owner)
 {
     m_jwListener = env->NewWeakGlobalRef(jListener);
+    m_ownerResource = nullptr;
 }
 #endif
 
@@ -182,11 +186,11 @@ void JniOnPostListener::checkExAndRemoveListener(JNIEnv* env)
 #ifndef WITH_CLOUD
         m_ownerResource->removeOnPostListener(env, m_jwListener);
 #else
-        if (m_ownerResource)
+        if (nullptr != m_ownerResource)
         {
             m_ownerResource->removeOnPostListener(env, m_jwListener);
         }
-        if (m_ownerAccountManager)
+        if (nullptr != m_ownerAccountManager)
         {
             m_ownerAccountManager->removeOnPostListener(env, m_jwListener);
         }
@@ -198,11 +202,11 @@ void JniOnPostListener::checkExAndRemoveListener(JNIEnv* env)
 #ifndef WITH_CLOUD
         m_ownerResource->removeOnPostListener(env, m_jwListener);
 #else
-        if (m_ownerResource)
+        if (nullptr != m_ownerResource)
         {
             m_ownerResource->removeOnPostListener(env, m_jwListener);
         }
-        if (m_ownerAccountManager)
+        if (nullptr != m_ownerAccountManager)
         {
             m_ownerAccountManager->removeOnPostListener(env, m_jwListener);
         }
index 74e48e6..5297293 100644 (file)
@@ -108,7 +108,21 @@ 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
new file mode 100644 (file)
index 0000000..abacec9
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ *******************************************************************
+ *
+ * Copyright 2016 Samsung Electronics All Rights Reserved.
+ *
+ *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ */
+
+package org.iotivity.base;
+
+public enum AclGroupType {
+    PUBLIC(0),
+    PRIVATE(1),;
+
+    private int value;
+
+    private AclGroupType(int value) {
+        this.value = value;
+    }
+
+    public int getValue() {
+        return this.value;
+    }
+}
index 28b7377..e9bb9e8 100644 (file)
@@ -197,6 +197,257 @@ public final class OcAccountManager {
                                       OnDeleteListener onDeleteListener) throws OcException;
 
     /**
+     * Method to delete the device registered on the account signed-in
+     *
+     * @param groupType      Group type that can be used for referencing default group ACL creation.
+     * @param onPostListener event handler The event handler will be invoked with a map of
+     *                       attribute name and values.
+     * @throws OcException if failure
+     */
+    public void createGroup(AclGroupType groupType,
+                            OnPostListener onPostListener) throws OcException {
+        this.createGroup0(groupType.getValue(), onPostListener);
+    }
+
+    private native void createGroup0(int groupType,
+                                     OnPostListener onPostListener) throws OcException;
+
+    /**
+     * Method to get a list of groups joined from account server
+     *
+     * @param onGetListener  The event handler will be invoked with a map of attribute name and
+     *                       values. The event handler will also have the result from this Get
+     *                       operation This will have error codes
+     *
+     * @return Returns ::OC_STACK_OK if success
+     */
+    public void getGroupList(OnGetListener onGetListener) throws OcException {
+        this.getGroupList0(onGetListener);
+    }
+
+    private native void getGroupList0(OnGetListener onGetListener) throws OcException;
+
+    /**
+     * Method to delete the group from account server
+     *
+     * @param groupId          Group ID to delete.
+     * @param onDeleteListener event handler The event handler will have headerOptionList.
+     *
+     * @return Returns ::OC_STACK_OK if success
+     */
+    public void deleteGroup(String groupId,
+                            OnDeleteListener onDeleteListener) throws OcException {
+        this.deleteGroup0(groupId, onDeleteListener);
+    }
+
+    private native void deleteGroup0(String groupId,
+                                     OnDeleteListener onDeleteListener) throws OcException;
+
+    /**
+     * Method to join the group on account server
+     *
+     * @param groupId        Group ID to join
+     * @param onPostListener event handler The event handler will be invoked with a map of
+     *                       attribute name and values.
+     *
+     * @return Returns ::OC_STACK_OK if success
+     */
+    public void joinGroup(String groupId,
+                          OnPostListener onPostListener) throws OcException {
+        this.joinGroup0(groupId, onPostListener);
+    }
+
+    private native void joinGroup0(String groupId,
+                                   OnPostListener onPostListener) throws OcException;
+
+    /**
+     * Method to add devices to the group on account server
+     *
+     * @param groupId        Group ID to add devices.
+     * @param deviceId       List of devices to add.
+     * @param onPostListener event handler The event handler will be invoked with a map of
+     *                       attribute name and values.
+     *
+     * @return Returns ::OC_STACK_OK if success
+     */
+    public void addDeviceToGroup(String groupId,
+                                 List<String> deviceId,
+                                 OnPostListener onPostListener) throws OcException {
+        this.addDeviceToGroup0(groupId, deviceId.toArray(new String[deviceId.size()]),
+                               onPostListener);
+    }
+
+    private native void addDeviceToGroup0(String groupId,
+                                          String[] deviceId,
+                                          OnPostListener onPostListener) throws OcException;
+
+    /**
+     * Method to get information of the group from account server
+     *
+     * @param groupId        Group ID to get information.
+     * @param onGetListener  The event handler will be invoked with a map of attribute name and
+     *                       values. The event handler will also have the result from this Get
+     *                       operation This will have error codes
+     *
+     * @return Returns ::OC_STACK_OK if success
+     */
+    public void getGroupInfo(String groupId,
+                             OnGetListener onGetListener) throws OcException {
+        this.getGroupInfo0(groupId, onGetListener);
+    }
+
+    private native void getGroupInfo0(String groupId,
+                                      OnGetListener onGetListener) throws OcException;
+
+    /**
+     * Method to leave the group joined on account server
+     *
+     * @param groupId          Group ID to leave.
+     * @param onDeleteListener event handler The event handler will have headerOptionList.
+     *
+     * @return Returns ::OC_STACK_OK if success
+     */
+    public void leaveGroup(String groupId,
+                           OnDeleteListener onDeleteListener) throws OcException {
+        this.leaveGroup0(groupId, onDeleteListener);
+    }
+
+    private native void leaveGroup0(String groupId,
+                                    OnDeleteListener onDeleteListener) throws OcException;
+
+    /**
+     * Method to delete devices from the group on account server
+     *
+     * @param groupId          Group ID to delete devices.
+     * @param deviceId         List of devices to delete.
+     * @param onDeleteListener event handler The event handler will have headerOptionList.
+     *
+     * @return Returns ::OC_STACK_OK if success
+     */
+    public void deleteDeviceFromGroup(String groupId,
+                                      List<String> deviceId,
+                                      OnDeleteListener onDeleteListener) throws OcException {
+        this.deleteDeviceFromGroup0(groupId, deviceId.toArray(new String[deviceId.size()]),
+                                    onDeleteListener);
+    }
+
+    private native void deleteDeviceFromGroup0(String groupId,
+                                               String[] deviceId,
+                                               OnDeleteListener onDeleteListener) throws OcException;
+
+    /**
+     * Method to register observe to the group on account server
+     * User can receive a notify when the group get changed (eg. new user/device added)
+     *
+     * @param groupId             Group ID to observe.
+     * @param cloudConnectHandler Callback function that will get the result of the operation.
+     *
+     * @return Returns ::OC_STACK_OK if success
+     */
+    public void observeGroup(String groupId,
+                             OnObserveListener onObserveListener) throws OcException {
+        this.observeGroup0(groupId, onObserveListener);
+    }
+
+    private native void observeGroup0(String groupId,
+                                      OnObserveListener onObserveListener) throws OcException;
+
+    /**
+     * Method to cancel observe to the group on account server
+     *
+     * @param groupId Group ID to observe.
+     *
+     * @return Returns ::OC_STACK_OK if success
+     */
+    public void cancelObserveGroup(String groupId) throws OcException {
+        this.cancelObserveGroup0(groupId);
+    }
+
+    private native void cancelObserveGroup0(String groupId) throws OcException;
+
+    /**
+     * Method to register observe to invitation resource on account server
+     * User can receive a invitation which is including group ID to join
+     * Once receive a invitation, user should call 'deleteInvitation' to delete a invitation
+     * on account server.
+     *
+     * @param cloudConnectHandler Callback function that will get the result of the operation.
+     *
+     * @return Returns ::OC_STACK_OK if success
+     */
+    public void observeInvitation(OnObserveListener onObserveListener) throws OcException {
+        this.observeInvitation0(onObserveListener);
+    }
+
+    private native void observeInvitation0(OnObserveListener onObserveListener) throws OcException;
+
+    /**
+     * Method to cancel observe to invitation resource on account server
+     *
+     * @return Returns ::OC_STACK_OK if success
+     */
+    public void cancelObserveInvitation() throws OcException {
+        this.cancelObserveInvitation0();
+    }
+
+    private native void cancelObserveInvitation0() throws OcException;
+
+    /**
+     * Method to send a invitation to invite a user into a group
+     *
+     * @param groupId        Group ID for inviting.
+     * @param userUuid       Identifier of the user to invite.
+     * @param onPostListener event handler The event handler will be invoked with a map of
+     *                       attribute name and values.
+     *
+     * @return Returns ::OC_STACK_OK if success
+     */
+    public void sendInvitation(String groupId,
+                               String userUuid,
+                               OnPostListener onPostListener) throws OcException {
+        this.sendInvitation0(groupId, userUuid, onPostListener);
+    }
+
+    private native void sendInvitation0(String groupId,
+                                        String userUuid,
+                                        OnPostListener onPostListener) throws OcException;
+
+    /**
+     * Method to cancel a invitation on account server that user has sent
+     *
+     * @param groupId          Group ID to cancel a invitation.
+     * @param userUuid         Identifier of the user to cancel a invitation.
+     * @param onDeleteListener event handler The event handler will have headerOptionList.
+     *
+     * @return Returns ::OC_STACK_OK if success
+     */
+    public void cancelInvitation(String groupId,
+                                 String userUuid,
+                                 OnDeleteListener onDeleteListener) throws OcException {
+        this.cancelInvitation0(groupId, userUuid, onDeleteListener);
+    }
+
+    private native void cancelInvitation0(String groupId,
+                                          String userUuid,
+                                          OnDeleteListener onDeleteListener) throws OcException;
+
+    /**
+     * Method to delete a invitation on account server that user has received
+     *
+     * @param groupId          Group ID to delete a invitation.
+     * @param onDeleteListener event handler The event handler will have headerOptionList.
+     *
+     * @return Returns ::OC_STACK_OK if success
+     */
+    public void deleteInvitation(String groupId,
+                                 OnDeleteListener onDeleteListener) throws OcException {
+        this.deleteInvitation0(groupId, onDeleteListener);
+    }
+
+    private native void deleteInvitation0(String groupId,
+                                          OnDeleteListener onDeleteListener) throws OcException;
+
+    /**
      * An OnGetListener can be registered via the resource get call.
      * Event listeners are notified asynchronously
      */
@@ -228,6 +479,31 @@ public final class OcAccountManager {
         public void onDeleteFailed(Throwable ex);
     }
 
+    /**
+     * An OnObserveListener can be registered via the resource observe call.
+     * Event listeners are notified asynchronously
+     */
+    public interface OnObserveListener {
+        /**
+         * To Register.
+         */
+        public static final int REGISTER = 0;
+        /**
+         * To Deregister.
+         */
+        public static final int DEREGISTER = 1;
+        /**
+         * Others.
+         */
+        public static final int NO_OPTION = 2;
+
+        public void onObserveCompleted(List<OcHeaderOption> headerOptionList,
+                                       OcRepresentation ocRepresentation,
+                                       int sequenceNumber);
+
+        public void onObserveFailed(Throwable ex);
+    }
+
     private long mNativeHandle;
 }
 
index 39b8aa6..f30568b 100644 (file)
@@ -368,10 +368,10 @@ extern "C" {
 #define OC_RSRVD_ACCOUNT_TOKEN_REFRESH_URI "/oic/account/tokenrefresh"
 
 /** ACL group URI.*/
-#define OC_RSRVD_ACL_GROUP_URI             "/ocf/acl/group"
+#define OC_RSRVD_ACL_GROUP_URI             "/oic/acl/group"
 
 /** ACL invite URI.*/
-#define OC_RSRVD_ACL_INVITE_URI            "/ocf/acl/invite"
+#define OC_RSRVD_ACL_INVITE_URI            "/oic/acl/invite"
 
 /** Defines auth provider. */
 #define OC_RSRVD_AUTHPROVIDER              "authprovider"
@@ -1539,15 +1539,6 @@ typedef struct OCDPDev
 } OCDPDev_t;
 //#endif // DIRECT_PAIRING
 
-/**
- * Type of Group for ACL.
- */
-typedef enum
-{
-    GT_PUBLIC = 0,
-    GT_PRIVATE,
-} OCAclGroupType;
-
 /*
  * -------------------------------------------------------------------------------------------
  * Callback function definitions
index 24868d6..65ea576 100644 (file)
@@ -164,7 +164,7 @@ namespace OC
          *
          * @return Returns ::OC_STACK_OK if success
          */
-        OCStackResult createGroup(OCAclGroupType groupType,
+        OCStackResult createGroup(AclGroupType groupType,
                                   PostCallback cloudConnectHandler);
 
         /**
index f2b06b3..2510f74 100644 (file)
@@ -213,7 +213,13 @@ namespace OC
         Observe,
         ObserveAll
     };
-
+#ifdef WITH_CLOUD
+    enum class AclGroupType
+    {
+        PUBLIC,
+        PRIVATE
+    };
+#endif
     // Typedef for list of resource handles.
     typedef std::vector<OCResourceHandle> ResourceHandles;
 
index 27bb247..5da112a 100644 (file)
@@ -201,7 +201,7 @@ OCStackResult OCAccountManager::deleteDevice(const std::string& deviceId,
                          m_connType, cloudConnectHandler, m_defaultQos);
 }
 
-OCStackResult OCAccountManager::createGroup(OCAclGroupType groupType,
+OCStackResult OCAccountManager::createGroup(AclGroupType groupType,
                                             PostCallback cloudConnectHandler)
 {
     std::string uri = m_host + OC_RSRVD_ACL_GROUP_URI;
@@ -209,10 +209,10 @@ OCStackResult OCAccountManager::createGroup(OCAclGroupType groupType,
     std::string gtype;
     switch (groupType)
     {
-        case GT_PUBLIC:
+        case AclGroupType::PUBLIC:
             gtype = OC_RSRVD_PUBLIC;
             break;
-        case GT_PRIVATE:
+        case AclGroupType::PRIVATE:
             gtype = OC_RSRVD_PRIVATE;
             break;
         default:
index f183c95..76acecf 100644 (file)
@@ -223,7 +223,7 @@ namespace OCAccountManagerTest
         std::string host("coap://192.168.1.2:5000");
         OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
         EXPECT_TRUE(NULL != accountManager);
-        EXPECT_EQ(OC_STACK_OK, accountManager->createGroup(GT_PUBLIC, &accountHandler));
+        EXPECT_EQ(OC_STACK_OK, accountManager->createGroup(AclGroupType::PUBLIC, &accountHandler));
     }
 
     TEST(CreateGroupTest, CreateGroupWithNullCallback)
@@ -231,7 +231,7 @@ namespace OCAccountManagerTest
         std::string host("coap://192.168.1.2:5000");
         OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
         EXPECT_TRUE(NULL != accountManager);
-        EXPECT_ANY_THROW(accountManager->createGroup(GT_PUBLIC, nullptr));
+        EXPECT_ANY_THROW(accountManager->createGroup(AclGroupType::PUBLIC, nullptr));
     }
 
     // GetGroupList Test