m_onGetManager.removeAllListeners(env);
m_onPostManager.removeAllListeners(env);
m_onDeleteManager.removeAllListeners(env);
+ m_onObserveManager.removeAllListeners(env);
if (JNI_EDETACHED == envRet)
{
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);
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)
{
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
/*
* 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)
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());
+ }
+}
+
+
#include "JniOnGetListener.h"
#include "JniOnPostListener.h"
#include "JniOnDeleteListener.h"
+#include "JniOnObserveListener.h"
using namespace OC;
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;
};
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
}
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>>(
: m_ownerResource(owner)
{
m_jwListener = env->NewWeakGlobalRef(jListener);
+#ifdef WITH_CLOUD
+ m_ownerAccountManager = nullptr;
+#endif
}
#ifdef WITH_CLOUD
: m_ownerAccountManager(owner)
{
m_jwListener = env->NewWeakGlobalRef(jListener);
+ m_ownerResource = nullptr;
}
#endif
#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);
}
#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);
}
: m_ownerResource(owner)
{
m_jwListener = env->NewWeakGlobalRef(jListener);
+#ifdef WITH_CLOUD
+ m_ownerAccountManager = nullptr;
+#endif
}
#ifdef WITH_CLOUD
: m_ownerAccountManager(owner)
{
m_jwListener = env->NewWeakGlobalRef(jListener);
+ m_ownerResource = nullptr;
}
#endif
#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);
}
#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);
}
#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)
{
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
}
}
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);
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
: m_ownerResource(owner)
{
m_jwListener = env->NewWeakGlobalRef(jListener);
+#ifdef WITH_CLOUD
+ m_ownerAccountManager = nullptr;
+#endif
}
#ifdef WITH_CLOUD
: m_ownerAccountManager(owner)
{
m_jwListener = env->NewWeakGlobalRef(jListener);
+ m_ownerResource = nullptr;
}
#endif
#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);
}
#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);
}
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)
--- /dev/null
+/*
+ *******************************************************************
+ *
+ * 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;
+ }
+}
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
*/
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;
}
#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"
} OCDPDev_t;
//#endif // DIRECT_PAIRING
-/**
- * Type of Group for ACL.
- */
-typedef enum
-{
- GT_PUBLIC = 0,
- GT_PRIVATE,
-} OCAclGroupType;
-
/*
* -------------------------------------------------------------------------------------------
* Callback function definitions
*
* @return Returns ::OC_STACK_OK if success
*/
- OCStackResult createGroup(OCAclGroupType groupType,
+ OCStackResult createGroup(AclGroupType groupType,
PostCallback cloudConnectHandler);
/**
Observe,
ObserveAll
};
-
+#ifdef WITH_CLOUD
+ enum class AclGroupType
+ {
+ PUBLIC,
+ PRIVATE
+ };
+#endif
// Typedef for list of resource handles.
typedef std::vector<OCResourceHandle> ResourceHandles;
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;
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:
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)
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