Merge tizen_5.0 codes into tizen_4.0
[platform/upstream/iotivity.git] / android / android_api / base / jni / JniOcAccountManager.cpp
1 /*
2  *******************************************************************
3  *
4  * Copyright 2016 Samsung Electronics All Rights Reserved.
5  *
6  *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21  */
22
23 #include "JniOcAccountManager.h"
24 #include "JniOcRepresentation.h"
25 #include "JniUtils.h"
26
27 #define VERIFY_NON_NULL_THROW_EXCEPTION(arg, log_message, exc) \
28     if (!(arg)) \
29     { \
30         ThrowOcException(exc, log_message); \
31         return; \
32     } \
33
34 JniOcAccountManager::JniOcAccountManager(std::shared_ptr<OCAccountManager> accountManager)
35     : m_sharedAccountManager(accountManager)
36 {
37 }
38
39 JniOcAccountManager::~JniOcAccountManager()
40 {
41     LOGD("~JniOcAccountManager()");
42
43     m_sharedAccountManager = nullptr;
44
45     jint envRet = JNI_ERR;
46     JNIEnv *env = GetJNIEnv(envRet);
47     if (nullptr == env)
48     {
49         return;
50     }
51
52     m_onGetManager.removeAllListeners(env);
53     m_onPostManager.removeAllListeners(env);
54     m_onDeleteManager.removeAllListeners(env);
55     m_onObserveManager.removeAllListeners(env);
56
57     if (JNI_EDETACHED == envRet)
58     {
59         g_jvm->DetachCurrentThread();
60     }
61 }
62
63 std::string JniOcAccountManager::host()
64 {
65     return m_sharedAccountManager->host();
66 }
67
68 OCConnectivityType JniOcAccountManager::connectivityType() const
69 {
70     return m_sharedAccountManager->connectivityType();
71 }
72
73 JniOcAccountManager* JniOcAccountManager::getJniOcAccountManagerPtr(JNIEnv *env, jobject thiz)
74 {
75     JniOcAccountManager *accountManager = GetHandle<JniOcAccountManager>(env, thiz);
76     if (env->ExceptionCheck())
77     {
78         LOGE("Failed to get native handle from OcAccountManager");
79     }
80     if (!accountManager)
81     {
82         ThrowOcException(JNI_NO_NATIVE_POINTER, "");
83     }
84     return accountManager;
85 }
86
87 JniOnGetListener* JniOcAccountManager::addOnGetListener(JNIEnv* env, jobject jListener)
88 {
89     return this->m_onGetManager.addListener(env, jListener,
90                                             std::bind(&JniOcAccountManager::removeOnGetListener, this,
91                                             std::placeholders::_1, std::placeholders::_2));
92 }
93
94 JniOnPostListener* JniOcAccountManager::addOnPostListener(JNIEnv* env, jobject jListener)
95 {
96     return this->m_onPostManager.addListener(env, jListener,
97                                              std::bind(&JniOcAccountManager::removeOnPostListener, this,
98                                              std::placeholders::_1, std::placeholders::_2));
99 }
100
101 JniOnDeleteListener* JniOcAccountManager::addOnDeleteListener(JNIEnv* env, jobject jListener)
102 {
103     return this->m_onDeleteManager.addListener(env, jListener,
104                                                std::bind(&JniOcAccountManager::removeOnDeleteListener, this,
105                                                std::placeholders::_1, std::placeholders::_2));
106 }
107
108 JniOnObserveListener* JniOcAccountManager::addOnObserveListener(JNIEnv* env, jobject jListener)
109 {
110     return this->m_onObserveManager.addListener(env, jListener,
111                                                 std::bind(&JniOcAccountManager::removeOnObserveListener, this,
112                                                 std::placeholders::_1, std::placeholders::_2));
113 }
114
115 void JniOcAccountManager::removeOnGetListener(JNIEnv* env, jobject jListener)
116 {
117     this->m_onGetManager.removeListener(env, jListener);
118 }
119
120 void JniOcAccountManager::removeOnPostListener(JNIEnv* env, jobject jListener)
121 {
122     this->m_onPostManager.removeListener(env, jListener);
123 }
124
125 void JniOcAccountManager::removeOnDeleteListener(JNIEnv* env, jobject jListener)
126 {
127     this->m_onDeleteManager.removeListener(env, jListener);
128 }
129
130 void JniOcAccountManager::removeOnObserveListener(JNIEnv* env, jobject jListener)
131 {
132     this->m_onObserveManager.removeListener(env, jListener);
133 }
134
135 OCStackResult JniOcAccountManager::signUp(JNIEnv* env, const std::string& authProvider,
136                                           const std::string& authCode, jobject jListener)
137 {
138     JniOnPostListener *onPostListener = addOnPostListener(env, jListener);
139     if (nullptr == onPostListener)
140     {
141         LOGE("onPostListener is null");
142         return OC_STACK_ERROR;
143     }
144
145     PostCallback postCallback = [onPostListener](const HeaderOptions& opts,
146         const OCRepresentation& rep, const int eCode)
147     {
148         onPostListener->onPostCallback(opts, rep, eCode);
149     };
150
151     return m_sharedAccountManager->signUp(authProvider, authCode, postCallback);
152 }
153
154 OCStackResult JniOcAccountManager::signUp(JNIEnv* env, const std::string& authProvider,
155                                           const std::string& authCode,
156                                           const QueryParamsMap& options, jobject jListener)
157 {
158     JniOnPostListener *onPostListener = addOnPostListener(env, jListener);
159     if (nullptr == onPostListener)
160     {
161         LOGE("onPostListener is null");
162         return OC_STACK_ERROR;
163     }
164
165     PostCallback postCallback = [onPostListener](const HeaderOptions& opts,
166         const OCRepresentation& rep, const int eCode)
167     {
168         onPostListener->onPostCallback(opts, rep, eCode);
169     };
170
171     return m_sharedAccountManager->signUp(authProvider, authCode, options, postCallback);
172 }
173
174 OCStackResult JniOcAccountManager::signIn(JNIEnv* env, const std::string& userUuid,
175                                           const std::string& accessToken, jobject jListener)
176 {
177     JniOnPostListener *onPostListener = addOnPostListener(env, jListener);
178     if (nullptr == onPostListener)
179     {
180         LOGE("onPostListener is null");
181         return OC_STACK_ERROR;
182     }
183
184     PostCallback postCallback = [onPostListener](const HeaderOptions& opts,
185         const OCRepresentation& rep, const int eCode)
186     {
187         onPostListener->onPostCallback(opts, rep, eCode);
188     };
189
190     return m_sharedAccountManager->signIn(userUuid, accessToken, postCallback);
191 }
192
193 OCStackResult JniOcAccountManager::signOut(JNIEnv* env, const std::string& accessToken,
194                                            jobject jListener)
195 {
196     JniOnPostListener *onPostListener = addOnPostListener(env, jListener);
197     if (nullptr == onPostListener)
198     {
199         LOGE("onPostListener is null");
200         return OC_STACK_ERROR;
201     }
202
203     PostCallback postCallback = [onPostListener](const HeaderOptions& opts,
204         const OCRepresentation& rep, const int eCode)
205     {
206         onPostListener->onPostCallback(opts, rep, eCode);
207     };
208
209     return m_sharedAccountManager->signOut(accessToken, postCallback);
210 }
211
212 OCStackResult JniOcAccountManager::refreshAccessToken(JNIEnv* env, const std::string& userUuid,
213                                                       const std::string& refreshToken,
214                                                       jobject jListener)
215 {
216     JniOnPostListener *onPostListener = addOnPostListener(env, jListener);
217     if (nullptr == onPostListener)
218     {
219         LOGE("onPostListener is null");
220         return OC_STACK_ERROR;
221     }
222
223     PostCallback postCallback = [onPostListener](const HeaderOptions& opts,
224         const OCRepresentation& rep, const int eCode)
225     {
226         onPostListener->onPostCallback(opts, rep, eCode);
227     };
228
229     return m_sharedAccountManager->refreshAccessToken(userUuid, refreshToken, postCallback);
230 }
231
232 OCStackResult JniOcAccountManager::searchUser(JNIEnv* env, const QueryParamsMap& queryMap,
233                                               jobject jListener)
234 {
235     JniOnGetListener *onGetListener = addOnGetListener(env, jListener);
236     if (nullptr == onGetListener)
237     {
238         LOGE("onGetListener is null");
239         return OC_STACK_ERROR;
240     }
241
242     GetCallback getCallback = [onGetListener](const HeaderOptions& opts,
243         const OCRepresentation& rep, const int eCode)
244     {
245         onGetListener->onGetCallback(opts, rep, eCode);
246     };
247
248     return m_sharedAccountManager->searchUser(queryMap, getCallback);
249 }
250
251 OCStackResult JniOcAccountManager::deleteDevice(JNIEnv* env, const std::string& accessToken,
252                                                 const std::string& deviceId, jobject jListener)
253 {
254     JniOnDeleteListener *onDeleteListener = addOnDeleteListener(env, jListener);
255     if (nullptr == onDeleteListener)
256     {
257         LOGE("onDeleteListener is null");
258         return OC_STACK_ERROR;
259     }
260
261     DeleteCallback deleteCallback = [onDeleteListener](const HeaderOptions& opts,
262         const int eCode)
263     {
264         onDeleteListener->onDeleteCallback(opts, eCode);
265     };
266
267     return m_sharedAccountManager->deleteDevice(accessToken, deviceId, deleteCallback);
268 }
269
270 OCStackResult JniOcAccountManager::createGroup(JNIEnv* env, jobject jListener)
271 {
272     JniOnPostListener *onPostListener = addOnPostListener(env, jListener);
273     if (nullptr == onPostListener)
274     {
275         LOGE("onPostListener is null");
276         return OC_STACK_ERROR;
277     }
278
279     PostCallback postCallback = [onPostListener](const HeaderOptions& opts,
280         const OCRepresentation& rep, const int eCode)
281     {
282         onPostListener->onPostCallback(opts, rep, eCode);
283     };
284
285     return m_sharedAccountManager->createGroup(postCallback);
286 }
287
288 OCStackResult JniOcAccountManager::createGroup(JNIEnv* env, const QueryParamsMap& queryMap,
289                                                jobject jListener)
290 {
291     JniOnPostListener *onPostListener = addOnPostListener(env, jListener);
292     if (nullptr == onPostListener)
293     {
294         LOGE("onPostListener is null");
295         return OC_STACK_ERROR;
296     }
297
298     PostCallback postCallback = [onPostListener](const HeaderOptions& opts,
299         const OCRepresentation& rep, const int eCode)
300     {
301         onPostListener->onPostCallback(opts, rep, eCode);
302     };
303
304     return m_sharedAccountManager->createGroup(queryMap, postCallback);
305 }
306
307 OCStackResult JniOcAccountManager::deleteGroup(JNIEnv* env, const std::string& groupId,
308                                                jobject jListener)
309 {
310     JniOnDeleteListener *onDeleteListener = addOnDeleteListener(env, jListener);
311     if (nullptr == onDeleteListener)
312     {
313         LOGE("onDeleteListener is null");
314         return OC_STACK_ERROR;
315     }
316
317     DeleteCallback deleteCallback = [onDeleteListener](const HeaderOptions& opts,
318         const int eCode)
319     {
320         onDeleteListener->onDeleteCallback(opts, eCode);
321     };
322
323     return m_sharedAccountManager->deleteGroup(groupId, deleteCallback);
324 }
325
326 OCStackResult JniOcAccountManager::getGroupInfoAll(JNIEnv* env, jobject jListener)
327 {
328     JniOnGetListener *onGetListener = addOnGetListener(env, jListener);
329     if (nullptr == onGetListener)
330     {
331         LOGE("onGetListener is null");
332         return OC_STACK_ERROR;
333     }
334
335     GetCallback getCallback = [onGetListener](const HeaderOptions& opts,
336         const OCRepresentation& rep, const int eCode)
337     {
338         onGetListener->onGetCallback(opts, rep, eCode);
339     };
340
341     return m_sharedAccountManager->getGroupInfoAll(getCallback);
342 }
343
344 OCStackResult JniOcAccountManager::getGroupInfo(JNIEnv* env, const std::string& groupId,
345                                                 jobject jListener)
346 {
347     JniOnGetListener *onGetListener = addOnGetListener(env, jListener);
348     if (nullptr == onGetListener)
349     {
350         LOGE("onGetListener is null");
351         return OC_STACK_ERROR;
352     }
353
354     GetCallback getCallback = [onGetListener](const HeaderOptions& opts,
355         const OCRepresentation& rep, const int eCode)
356     {
357         onGetListener->onGetCallback(opts, rep, eCode);
358     };
359
360     return m_sharedAccountManager->getGroupInfo(groupId, getCallback);
361 }
362
363 OCStackResult JniOcAccountManager::addPropertyValueToGroup(JNIEnv* env, const std::string& groupId,
364                                                            const OCRepresentation& propertyValue,
365                                                            jobject jListener)
366 {
367     JniOnPostListener *onPostListener = addOnPostListener(env, jListener);
368     if (nullptr == onPostListener)
369     {
370         LOGE("onPostListener is null");
371         return OC_STACK_ERROR;
372     }
373
374     PostCallback postCallback = [onPostListener](const HeaderOptions& opts,
375         const OCRepresentation& rep, const int eCode)
376     {
377         onPostListener->onPostCallback(opts, rep, eCode);
378     };
379
380     return m_sharedAccountManager->addPropertyValueToGroup(groupId, propertyValue, postCallback);
381 }
382
383 OCStackResult JniOcAccountManager::deletePropertyValueFromGroup(JNIEnv* env,
384                                                         const std::string& groupId,
385                                                         const OCRepresentation& propertyValue,
386                                                         jobject jListener)
387 {
388     JniOnPostListener *onPostListener = addOnPostListener(env, jListener);
389     if (nullptr == onPostListener)
390     {
391         LOGE("onPostListener is null");
392         return OC_STACK_ERROR;
393     }
394
395     PostCallback postCallback = [onPostListener](const HeaderOptions& opts,
396         const OCRepresentation& rep, const int eCode)
397     {
398         onPostListener->onPostCallback(opts, rep, eCode);
399     };
400
401     return m_sharedAccountManager->deletePropertyValueFromGroup(groupId, propertyValue,
402                                                                 postCallback);
403 }
404
405 OCStackResult JniOcAccountManager::updatePropertyValueOnGroup(JNIEnv* env,
406                                                         const std::string& groupId,
407                                                         const OCRepresentation& propertyValue,
408                                                         jobject jListener)
409 {
410     JniOnPostListener *onPostListener = addOnPostListener(env, jListener);
411     if (nullptr == onPostListener)
412     {
413         LOGE("onPostListener is null");
414         return OC_STACK_ERROR;
415     }
416
417     PostCallback postCallback = [onPostListener](const HeaderOptions& opts,
418         const OCRepresentation& rep, const int eCode)
419     {
420         onPostListener->onPostCallback(opts, rep, eCode);
421     };
422
423     return m_sharedAccountManager->updatePropertyValueOnGroup(groupId, propertyValue,
424                                                               postCallback);
425 }
426
427 OCStackResult JniOcAccountManager::observeGroup(JNIEnv* env, jobject jListener)
428 {
429     JniOnObserveListener *onObserveListener = addOnObserveListener(env, jListener);
430     if (nullptr == onObserveListener)
431     {
432         LOGE("onObserveListener is null");
433         return OC_STACK_ERROR;
434     }
435
436     ObserveCallback observeCallback = [onObserveListener](const HeaderOptions& opts,
437         const OCRepresentation& rep, const int& eCode, const int& sequenceNumber)
438     {
439         onObserveListener->onObserveCallback(opts, rep, eCode, sequenceNumber);
440     };
441
442     return m_sharedAccountManager->observeGroup(observeCallback);
443 }
444
445 OCStackResult JniOcAccountManager::cancelObserveGroup()
446 {
447     return m_sharedAccountManager->cancelObserveGroup();
448 }
449
450 OCStackResult JniOcAccountManager::observeInvitation(JNIEnv* env, jobject jListener)
451 {
452     JniOnObserveListener *onObserveListener = addOnObserveListener(env, jListener);
453     if (nullptr == onObserveListener)
454     {
455         LOGE("onObserveListener is null");
456         return OC_STACK_ERROR;
457     }
458
459     ObserveCallback observeCallback = [onObserveListener](const HeaderOptions& opts,
460         const OCRepresentation& rep, const int& eCode, const int& sequenceNumber)
461     {
462         onObserveListener->onObserveCallback(opts, rep, eCode, sequenceNumber);
463     };
464
465     return m_sharedAccountManager->observeInvitation(observeCallback);
466 }
467
468 OCStackResult JniOcAccountManager::cancelObserveInvitation()
469 {
470     return m_sharedAccountManager->cancelObserveInvitation();
471 }
472
473 OCStackResult JniOcAccountManager::sendInvitation(JNIEnv* env, const std::string& groupId,
474                                                   const std::string& userUuid, jobject jListener)
475 {
476     JniOnPostListener *onPostListener = addOnPostListener(env, jListener);
477     if (nullptr == onPostListener)
478     {
479         LOGE("onPostListener is null");
480         return OC_STACK_ERROR;
481     }
482
483     PostCallback postCallback = [onPostListener](const HeaderOptions& opts,
484         const OCRepresentation& rep, const int eCode)
485     {
486         onPostListener->onPostCallback(opts, rep, eCode);
487     };
488
489     return m_sharedAccountManager->sendInvitation(groupId, userUuid, postCallback);
490 }
491
492 OCStackResult JniOcAccountManager::cancelInvitation(JNIEnv* env, const std::string& groupId,
493                                                     const std::string& userUuid, jobject jListener)
494 {
495     JniOnDeleteListener *onDeleteListener = addOnDeleteListener(env, jListener);
496     if (nullptr == onDeleteListener)
497     {
498         LOGE("onDeleteListener is null");
499         return OC_STACK_ERROR;
500     }
501
502     DeleteCallback deleteCallback = [onDeleteListener](const HeaderOptions& opts,
503         const int eCode)
504     {
505         onDeleteListener->onDeleteCallback(opts, eCode);
506     };
507
508     return m_sharedAccountManager->cancelInvitation(groupId, userUuid, deleteCallback);
509 }
510
511 OCStackResult JniOcAccountManager::replyToInvitation(JNIEnv* env, const std::string& groupId,
512                                                      const bool accept, jobject jListener)
513 {
514     JniOnDeleteListener *onDeleteListener = addOnDeleteListener(env, jListener);
515     if (nullptr == onDeleteListener)
516     {
517         LOGE("onDeleteListener is null");
518         return OC_STACK_ERROR;
519     }
520
521     DeleteCallback deleteCallback = [onDeleteListener](const HeaderOptions& opts,
522         const int eCode)
523     {
524         onDeleteListener->onDeleteCallback(opts, eCode);
525     };
526
527     return m_sharedAccountManager->replyToInvitation(groupId, accept, deleteCallback);
528 }
529
530 /*
531 * Class:     org_iotivity_base_OcAccountManager
532 * Method:    getHost
533 * Signature: ()Ljava/lang/String;
534 */
535 JNIEXPORT jstring JNICALL Java_org_iotivity_base_OcAccountManager_getHost
536     (JNIEnv *env, jobject thiz)
537 {
538     LOGD("OcAccountManager_getHost");
539     JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env,
540                                                                                          thiz);
541     if (!accountManager)
542     {
543         return nullptr;
544     }
545
546     return env->NewStringUTF(accountManager->host().c_str());
547 }
548
549 /*
550 * Class:     org_iotivity_base_OcAccountManager
551 * Method:    getConnectivityTypeN
552 * Signature: ()I
553 */
554 JNIEXPORT jint JNICALL Java_org_iotivity_base_OcAccountManager_getConnectivityTypeN
555     (JNIEnv *env, jobject thiz)
556 {
557     LOGD("OcAccountManager_getConnectivityType");
558     JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env,
559                                                                                          thiz);
560     if (!accountManager)
561     {
562         return -1;
563     }
564
565     OCConnectivityType connectivityType = accountManager->connectivityType();
566     return static_cast<jint>(connectivityType);
567 }
568
569 /*
570 * Class:     org_iotivity_base_OcAccountManager
571 * Method:    signUp0
572 * Signature: (Ljava/lang/String;Ljava/lang/String;
573 *             Lorg/iotivity/base/OcAccountManager/OnPostListener;)V
574 */
575 JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_signUp0
576     (JNIEnv *env, jobject thiz, jstring jAuthProvider, jstring jAuthCode, jobject jListener)
577 {
578     LOGD("OcAccountManager_signUp");
579     VERIFY_NON_NULL_THROW_EXCEPTION(jAuthProvider, "authProvider cannot be null",
580                                     OC_STACK_INVALID_PARAM);
581     VERIFY_NON_NULL_THROW_EXCEPTION(jAuthCode, "authCode cannot be null", OC_STACK_INVALID_PARAM);
582     VERIFY_NON_NULL_THROW_EXCEPTION(jListener, "onPostListener cannot be null",
583                                     OC_STACK_INVALID_PARAM);
584
585     JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env,
586                                                                                          thiz);
587     if (!accountManager)
588     {
589         return;
590     }
591
592     const char *charAuthProvider = env->GetStringUTFChars(jAuthProvider, nullptr);
593     VERIFY_NON_NULL_THROW_EXCEPTION(charAuthProvider, "charAuthProvider is null", JNI_EXCEPTION);
594     std::string authProvider(charAuthProvider);
595     env->ReleaseStringUTFChars(jAuthProvider, charAuthProvider);
596
597     const char *charAuthCode = env->GetStringUTFChars(jAuthCode, nullptr);
598     VERIFY_NON_NULL_THROW_EXCEPTION(charAuthCode, "charAuthCode is null", JNI_EXCEPTION);
599     std::string authCode(charAuthCode);
600     env->ReleaseStringUTFChars(jAuthCode, charAuthCode);
601
602     try
603     {
604         OCStackResult result = accountManager->signUp(env,
605                                                       authProvider,
606                                                       authCode,
607                                                       jListener);
608         if (OC_STACK_OK != result)
609         {
610             ThrowOcException(result, "OcAccountManager_signUp");
611         }
612     }
613     catch (OCException& e)
614     {
615         LOGE("%s", e.reason().c_str());
616         ThrowOcException(e.code(), e.reason().c_str());
617     }
618 }
619
620 /*
621 * Class:     org_iotivity_base_OcAccountManager
622 * Method:    signUp1
623 * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/util/Map;
624 *             Lorg/iotivity/base/OcAccountManager/OnPostListener;)V
625 */
626 JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_signUp1
627     (JNIEnv *env, jobject thiz, jstring jAuthProvider, jstring jAuthCode, jobject jOptionsMap,
628      jobject jListener)
629 {
630     LOGD("OcAccountManager_signUp");
631     VERIFY_NON_NULL_THROW_EXCEPTION(jAuthProvider, "authProvider cannot be null",
632                                     OC_STACK_INVALID_PARAM);
633     VERIFY_NON_NULL_THROW_EXCEPTION(jAuthCode, "authCode cannot be null", OC_STACK_INVALID_PARAM);
634     VERIFY_NON_NULL_THROW_EXCEPTION(jOptionsMap, "options cannot be null", OC_STACK_INVALID_PARAM);
635     VERIFY_NON_NULL_THROW_EXCEPTION(jListener, "onPostListener cannot be null",
636                                     OC_STACK_INVALID_PARAM);
637
638     JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env,
639                                                                                          thiz);
640     if (!accountManager)
641     {
642         return;
643     }
644
645     const char *charAuthProvider = env->GetStringUTFChars(jAuthProvider, nullptr);
646     VERIFY_NON_NULL_THROW_EXCEPTION(charAuthProvider, "charAuthProvider is null", JNI_EXCEPTION);
647     std::string authProvider(charAuthProvider);
648     env->ReleaseStringUTFChars(jAuthProvider, charAuthProvider);
649
650     const char *charAuthCode = env->GetStringUTFChars(jAuthCode, nullptr);
651     VERIFY_NON_NULL_THROW_EXCEPTION(charAuthCode, "charAuthCode is null", JNI_EXCEPTION);
652     std::string authCode(charAuthCode);
653     env->ReleaseStringUTFChars(jAuthCode, charAuthCode);
654
655     QueryParamsMap optionsMap;
656     JniUtils::convertJavaMapToQueryParamsMap(env, jOptionsMap, optionsMap);
657
658     try
659     {
660         OCStackResult result = accountManager->signUp(env,
661                                                       authProvider,
662                                                       authCode,
663                                                       optionsMap,
664                                                       jListener);
665         if (OC_STACK_OK != result)
666         {
667             ThrowOcException(result, "OcAccountManager_signUp");
668         }
669     }
670     catch (OCException& e)
671     {
672         LOGE("%s", e.reason().c_str());
673         ThrowOcException(e.code(), e.reason().c_str());
674     }
675 }
676
677 /*
678 * Class:     org_iotivity_base_OcAccountManager
679 * Method:    signIn0
680 * Signature: (Ljava/lang/String;Ljava/lang/String;
681 *             Lorg/iotivity/base/OcAccountManager/OnPostListener;)V
682 */
683 JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_signIn0
684     (JNIEnv *env, jobject thiz, jstring jUserUuid, jstring jAccessToken, jobject jListener)
685 {
686     LOGD("OcAccountManager_signIn");
687     VERIFY_NON_NULL_THROW_EXCEPTION(jUserUuid, "userUuid cannot be null", OC_STACK_INVALID_PARAM);
688     VERIFY_NON_NULL_THROW_EXCEPTION(jAccessToken, "accessToken cannot be null",
689                                     OC_STACK_INVALID_PARAM);
690     VERIFY_NON_NULL_THROW_EXCEPTION(jListener, "onPostListener cannot be null",
691                                     OC_STACK_INVALID_PARAM);
692
693     JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env,
694                                                                                          thiz);
695     if (!accountManager)
696     {
697         return;
698     }
699
700     const char *charUserUuid = env->GetStringUTFChars(jUserUuid, nullptr);
701     VERIFY_NON_NULL_THROW_EXCEPTION(charUserUuid, "charUserUuid is null", JNI_EXCEPTION);
702     std::string userUuid(charUserUuid);
703     env->ReleaseStringUTFChars(jUserUuid, charUserUuid);
704
705     const char *charAccessToken = env->GetStringUTFChars(jAccessToken, nullptr);
706     VERIFY_NON_NULL_THROW_EXCEPTION(charAccessToken, "charAccessToken is null", JNI_EXCEPTION);
707     std::string accessToken(charAccessToken);
708     env->ReleaseStringUTFChars(jAccessToken, charAccessToken);
709
710     try
711     {
712         OCStackResult result = accountManager->signIn(env,
713                                                       userUuid,
714                                                       accessToken,
715                                                       jListener);
716         if (OC_STACK_OK != result)
717         {
718             ThrowOcException(result, "OcAccountManager_signIn");
719         }
720     }
721     catch (OCException& e)
722     {
723         LOGE("%s", e.reason().c_str());
724         ThrowOcException(e.code(), e.reason().c_str());
725     }
726 }
727
728 /*
729 * Class:     org_iotivity_base_OcAccountManager
730 * Method:    signOut0
731 * Signature: (Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/OnPostListener;)V
732 */
733 JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_signOut0
734     (JNIEnv *env, jobject thiz, jstring jAccessToken, jobject jListener)
735 {
736     LOGD("OcAccountManager_signOut");
737     VERIFY_NON_NULL_THROW_EXCEPTION(jAccessToken, "accessToken cannot be null",
738                                     OC_STACK_INVALID_PARAM);
739     VERIFY_NON_NULL_THROW_EXCEPTION(jListener, "onPostListener cannot be null",
740                                     OC_STACK_INVALID_PARAM);
741
742     JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env,
743                                                                                          thiz);
744     if (!accountManager)
745     {
746         return;
747     }
748
749     const char *charAccessToken = env->GetStringUTFChars(jAccessToken, nullptr);
750     VERIFY_NON_NULL_THROW_EXCEPTION(charAccessToken, "charAccessToken is null", JNI_EXCEPTION);
751     std::string accessToken(charAccessToken);
752     env->ReleaseStringUTFChars(jAccessToken, charAccessToken);
753
754     try
755     {
756         OCStackResult result = accountManager->signOut(env,
757                                                        accessToken,
758                                                        jListener);
759         if (OC_STACK_OK != result)
760         {
761             ThrowOcException(result, "OcAccountManager_signOut");
762         }
763     }
764     catch (OCException& e)
765     {
766         LOGE("%s", e.reason().c_str());
767         ThrowOcException(e.code(), e.reason().c_str());
768     }
769 }
770
771 /*
772 * Class:     org_iotivity_base_OcAccountManager
773 * Method:    refreshAccessToken0
774 * Signature: (Ljava/lang/String;Ljava/lang/String;
775 *             Lorg/iotivity/base/OcAccountManager/OnPostListener;)V
776 */
777 JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_refreshAccessToken0
778     (JNIEnv *env, jobject thiz, jstring jUserUuid, jstring jRefreshAccessToken, jobject jListener)
779 {
780     LOGD("OcAccountManager_refreshAccessToken");
781     VERIFY_NON_NULL_THROW_EXCEPTION(jUserUuid, "userUuid cannot be null", OC_STACK_INVALID_PARAM);
782     VERIFY_NON_NULL_THROW_EXCEPTION(jRefreshAccessToken, "refreshAccessToken cannot be null",
783                                     OC_STACK_INVALID_PARAM);
784     VERIFY_NON_NULL_THROW_EXCEPTION(jListener, "onPostListener cannot be null",
785                                     OC_STACK_INVALID_PARAM);
786
787     JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env,
788                                                                                          thiz);
789     if (!accountManager)
790     {
791         return;
792     }
793
794     const char *charUserUuid = env->GetStringUTFChars(jUserUuid, nullptr);
795     VERIFY_NON_NULL_THROW_EXCEPTION(charUserUuid, "charUserUuid is null", JNI_EXCEPTION);
796     std::string userUuid(charUserUuid);
797     env->ReleaseStringUTFChars(jUserUuid, charUserUuid);
798
799     const char *charRefreshAccessToken = env->GetStringUTFChars(jRefreshAccessToken, nullptr);
800     VERIFY_NON_NULL_THROW_EXCEPTION(charRefreshAccessToken, "charRefreshAccessToken is null",
801                                     JNI_EXCEPTION);
802     std::string refreshAccessToken(charRefreshAccessToken);
803     env->ReleaseStringUTFChars(jRefreshAccessToken, charRefreshAccessToken);
804
805     try
806     {
807         OCStackResult result = accountManager->refreshAccessToken(env,
808                                                                   userUuid,
809                                                                   refreshAccessToken,
810                                                                   jListener);
811         if (OC_STACK_OK != result)
812         {
813             ThrowOcException(result, "OcAccountManager_refreshAccessToken");
814         }
815     }
816     catch (OCException& e)
817     {
818         LOGE("%s", e.reason().c_str());
819         ThrowOcException(e.code(), e.reason().c_str());
820     }
821 }
822
823 /*
824 * Class:     org_iotivity_base_OcAccountManager
825 * Method:    searchUser0
826 * Signature: (Ljava/util/Map;Lorg/iotivity/base/OcAccountManager/OnGetListener;)V
827 */
828 JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_searchUser0
829     (JNIEnv *env, jobject thiz, jobject jQueryMap, jobject jListener)
830 {
831     LOGD("OcAccountManager_searchUser");
832     VERIFY_NON_NULL_THROW_EXCEPTION(jQueryMap, "queryMap cannot be null", OC_STACK_INVALID_PARAM);
833     VERIFY_NON_NULL_THROW_EXCEPTION(jListener, "onGetListener cannot be null",
834                                     OC_STACK_INVALID_PARAM);
835
836     JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env,
837                                                                                          thiz);
838     if (!accountManager)
839     {
840         return;
841     }
842
843     QueryParamsMap queryMap;
844     JniUtils::convertJavaMapToQueryParamsMap(env, jQueryMap, queryMap);
845
846     try
847     {
848         OCStackResult result = accountManager->searchUser(env,
849                                                           queryMap,
850                                                           jListener);
851         if (OC_STACK_OK != result)
852         {
853             ThrowOcException(result, "OcAccountManager_searchUser");
854         }
855     }
856     catch (OCException& e)
857     {
858         LOGE("%s", e.reason().c_str());
859         ThrowOcException(e.code(), e.reason().c_str());
860     }
861 }
862
863 /*
864 * Class:     org_iotivity_base_OcAccountManager
865 * Method:    deleteDevice0
866 * Signature: (Ljava/lang/String;Ljava/lang/String;
867 *             Lorg/iotivity/base/OcAccountManager/onDeleteListener;)V
868 */
869 JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_deleteDevice0
870     (JNIEnv *env, jobject thiz, jstring jAccessToken, jstring jDeviceId, jobject jListener)
871 {
872     LOGD("OcAccountManager_deleteDevice");
873     VERIFY_NON_NULL_THROW_EXCEPTION(jAccessToken, "accessToken cannot be null",
874                                     OC_STACK_INVALID_PARAM);
875     VERIFY_NON_NULL_THROW_EXCEPTION(jDeviceId, "deviceId cannot be null", OC_STACK_INVALID_PARAM);
876     VERIFY_NON_NULL_THROW_EXCEPTION(jListener, "onDeleteListener cannot be null",
877                                     OC_STACK_INVALID_PARAM);
878
879     JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env,
880                                                                                          thiz);
881     if (!accountManager)
882     {
883         return;
884     }
885
886     const char *charAccessToken = env->GetStringUTFChars(jAccessToken, nullptr);
887     VERIFY_NON_NULL_THROW_EXCEPTION(charAccessToken, "charAccessToken is null", JNI_EXCEPTION);
888     std::string accessToken(charAccessToken);
889     env->ReleaseStringUTFChars(jAccessToken, charAccessToken);
890
891     const char *charDeviceId = env->GetStringUTFChars(jDeviceId, nullptr);
892     VERIFY_NON_NULL_THROW_EXCEPTION(charDeviceId, "charDeviceId is null", JNI_EXCEPTION);
893     std::string deviceId(charDeviceId);
894     env->ReleaseStringUTFChars(jDeviceId, charDeviceId);
895
896     try
897     {
898         OCStackResult result = accountManager->deleteDevice(env,
899                                                             accessToken,
900                                                             deviceId,
901                                                             jListener);
902         if (OC_STACK_OK != result)
903         {
904             ThrowOcException(result, "OcAccountManager_deleteDevice");
905         }
906     }
907     catch (OCException& e)
908     {
909         LOGE("%s", e.reason().c_str());
910         ThrowOcException(e.code(), e.reason().c_str());
911     }
912 }
913
914 /*
915 * Class:     org_iotivity_base_OcAccountManager
916 * Method:    createGroup0
917 * Signature: (Lorg/iotivity/base/OcAccountManager/OnPostListener;)V
918 */
919 JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_createGroup0
920     (JNIEnv *env, jobject thiz, jobject jListener)
921 {
922     LOGD("OcAccountManager_createGroup");
923     VERIFY_NON_NULL_THROW_EXCEPTION(jListener, "onPostListener cannot be null",
924                                     OC_STACK_INVALID_PARAM);
925
926     JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env,
927                                                                                          thiz);
928     if (!accountManager)
929     {
930         return;
931     }
932
933     try
934     {
935         OCStackResult result = accountManager->createGroup(env,
936                                                            jListener);
937         if (OC_STACK_OK != result)
938         {
939             ThrowOcException(result, "OcAccountManager_createGroup");
940         }
941     }
942     catch (OCException& e)
943     {
944         LOGE("%s", e.reason().c_str());
945         ThrowOcException(e.code(), e.reason().c_str());
946     }
947 }
948
949 /*
950 * Class:     org_iotivity_base_OcAccountManager
951 * Method:    createGroup1
952 * Signature: (Ljava/util/Map;Lorg/iotivity/base/OcAccountManager/OnPostListener;)V
953 */
954 JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_createGroup1
955     (JNIEnv *env, jobject thiz, jobject jQueryMap, jobject jListener)
956 {
957     LOGD("OcAccountManager_createGroup");
958     VERIFY_NON_NULL_THROW_EXCEPTION(jQueryMap, "queryMap cannot be null", OC_STACK_INVALID_PARAM);
959     VERIFY_NON_NULL_THROW_EXCEPTION(jListener, "onPostListener cannot be null",
960                                     OC_STACK_INVALID_PARAM);
961
962     JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env,
963                                                                                          thiz);
964     if (!accountManager)
965     {
966         return;
967     }
968
969     QueryParamsMap queryMap;
970     JniUtils::convertJavaMapToQueryParamsMap(env, jQueryMap, queryMap);
971
972     try
973     {
974         OCStackResult result = accountManager->createGroup(env,
975                                                            queryMap,
976                                                            jListener);
977         if (OC_STACK_OK != result)
978         {
979             ThrowOcException(result, "OcAccountManager_createGroup");
980         }
981     }
982     catch (OCException& e)
983     {
984         LOGE("%s", e.reason().c_str());
985         ThrowOcException(e.code(), e.reason().c_str());
986     }
987 }
988
989 /*
990 * Class:     org_iotivity_base_OcAccountManager
991 * Method:    deleteGroup0
992 * Signature: (Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/onDeleteListener;)V
993 */
994 JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_deleteGroup0
995     (JNIEnv *env, jobject thiz, jstring jGroupId, jobject jListener)
996 {
997     LOGD("OcAccountManager_deleteGroup");
998     VERIFY_NON_NULL_THROW_EXCEPTION(jGroupId, "groupId cannot be null", OC_STACK_INVALID_PARAM);
999     VERIFY_NON_NULL_THROW_EXCEPTION(jListener, "onDeleteListener cannot be null",
1000                                     OC_STACK_INVALID_PARAM);
1001
1002     JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env,
1003                                                                                          thiz);
1004     if (!accountManager)
1005     {
1006         return;
1007     }
1008
1009     const char *charGroupId = env->GetStringUTFChars(jGroupId, nullptr);
1010     VERIFY_NON_NULL_THROW_EXCEPTION(charGroupId, "charGroupId is null", JNI_EXCEPTION);
1011     std::string groupId(charGroupId);
1012     env->ReleaseStringUTFChars(jGroupId, charGroupId);
1013
1014     try
1015     {
1016         OCStackResult result = accountManager->deleteGroup(env,
1017                                                            groupId,
1018                                                            jListener);
1019         if (OC_STACK_OK != result)
1020         {
1021             ThrowOcException(result, "OcAccountManager_deleteGroup");
1022         }
1023     }
1024     catch (OCException& e)
1025     {
1026         LOGE("%s", e.reason().c_str());
1027         ThrowOcException(e.code(), e.reason().c_str());
1028     }
1029 }
1030
1031 /*
1032 * Class:     org_iotivity_base_OcAccountManager
1033 * Method:    getGroupInfoAll0
1034 * Signature: (Lorg/iotivity/base/OcAccountManager/OnGetListener;)V
1035 */
1036 JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_getGroupInfoAll0
1037     (JNIEnv *env, jobject thiz, jobject jListener)
1038 {
1039     LOGD("OcAccountManager_getGroupInfoAll");
1040     VERIFY_NON_NULL_THROW_EXCEPTION(jListener, "onGetListener cannot be null",
1041                                     OC_STACK_INVALID_PARAM);
1042
1043     JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env,
1044                                                                                          thiz);
1045     if (!accountManager)
1046     {
1047         return;
1048     }
1049
1050     try
1051     {
1052         OCStackResult result = accountManager->getGroupInfoAll(env,
1053                                                                jListener);
1054         if (OC_STACK_OK != result)
1055         {
1056             ThrowOcException(result, "OcAccountManager_getGroupInfoAll");
1057         }
1058     }
1059     catch (OCException& e)
1060     {
1061         LOGE("%s", e.reason().c_str());
1062         ThrowOcException(e.code(), e.reason().c_str());
1063     }
1064 }
1065
1066 /*
1067 * Class:     org_iotivity_base_OcAccountManager
1068 * Method:    getGroupInfo0
1069 * Signature: (Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/OnGetListener;)V
1070 */
1071 JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_getGroupInfo0
1072     (JNIEnv *env, jobject thiz, jstring jGroupId, jobject jListener)
1073 {
1074     LOGD("OcAccountManager_getGroupInfo");
1075     VERIFY_NON_NULL_THROW_EXCEPTION(jGroupId, "groupId cannot be null", OC_STACK_INVALID_PARAM);
1076     VERIFY_NON_NULL_THROW_EXCEPTION(jListener, "onGetListener cannot be null",
1077                                     OC_STACK_INVALID_PARAM);
1078
1079     JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env,
1080                                                                                          thiz);
1081     if (!accountManager)
1082     {
1083         return;
1084     }
1085
1086     const char *charGroupId = env->GetStringUTFChars(jGroupId, nullptr);
1087     VERIFY_NON_NULL_THROW_EXCEPTION(charGroupId, "charGroupId is null", JNI_EXCEPTION);
1088     std::string groupId(charGroupId);
1089     env->ReleaseStringUTFChars(jGroupId, charGroupId);
1090
1091     try
1092     {
1093         OCStackResult result = accountManager->getGroupInfo(env,
1094                                                             groupId,
1095                                                             jListener);
1096         if (OC_STACK_OK != result)
1097         {
1098             ThrowOcException(result, "OcAccountManager_getGroupInfo");
1099         }
1100     }
1101     catch (OCException& e)
1102     {
1103         LOGE("%s", e.reason().c_str());
1104         ThrowOcException(e.code(), e.reason().c_str());
1105     }
1106 }
1107
1108 /*
1109 * Class:     org_iotivity_base_OcAccountManager
1110 * Method:    addPropertyValueToGroup0
1111 * Signature: (Ljava/lang/String;Lorg/iotivity/base/OcRepresentation;
1112 *             Lorg/iotivity/base/OcAccountManager/OnPostListener;)V
1113 */
1114 JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_addPropertyValueToGroup0
1115     (JNIEnv *env, jobject thiz, jstring jGroupId, jobject jPropertyValue, jobject jListener)
1116 {
1117     LOGD("OcAccountManager_addPropertyValueToGroup");
1118     VERIFY_NON_NULL_THROW_EXCEPTION(jGroupId, "groupId cannot be null", OC_STACK_INVALID_PARAM);
1119     VERIFY_NON_NULL_THROW_EXCEPTION(jPropertyValue, "propertyValue cannot be null",
1120                                     OC_STACK_INVALID_PARAM);
1121     VERIFY_NON_NULL_THROW_EXCEPTION(jListener, "onPostListener cannot be null",
1122                                     OC_STACK_INVALID_PARAM);
1123
1124     JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env,
1125                                                                                          thiz);
1126     if (!accountManager)
1127     {
1128         return;
1129     }
1130
1131     OCRepresentation *propertyValue = JniOcRepresentation::getOCRepresentationPtr(env,
1132                                                                                   jPropertyValue);
1133     if (!propertyValue)
1134     {
1135         return;
1136     }
1137
1138     const char *charGroupId = env->GetStringUTFChars(jGroupId, nullptr);
1139     VERIFY_NON_NULL_THROW_EXCEPTION(charGroupId, "charGroupId is null", JNI_EXCEPTION);
1140     std::string groupId(charGroupId);
1141     env->ReleaseStringUTFChars(jGroupId, charGroupId);
1142
1143     try
1144     {
1145         OCStackResult result = accountManager->addPropertyValueToGroup(env,
1146                                                                        groupId,
1147                                                                        *propertyValue,
1148                                                                        jListener);
1149
1150         if (OC_STACK_OK != result)
1151         {
1152             ThrowOcException(result, "OcAccountManager_addPropertyValueToGroup");
1153         }
1154     }
1155     catch (OCException& e)
1156     {
1157         LOGE("%s", e.reason().c_str());
1158         ThrowOcException(e.code(), e.reason().c_str());
1159     }
1160 }
1161
1162 /*
1163 * Class:     org_iotivity_base_OcAccountManager
1164 * Method:    deletePropertyValueFromGroup0
1165 * Signature: (Ljava/lang/String;Lorg/iotivity/base/OcRepresentation;
1166 *             Lorg/iotivity/base/OcAccountManager/OnPostListener;)V
1167 */
1168 JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_deletePropertyValueFromGroup0
1169     (JNIEnv *env, jobject thiz, jstring jGroupId, jobject jPropertyValue, jobject jListener)
1170 {
1171     LOGD("OcAccountManager_deletePropertyValueFromGroup");
1172     VERIFY_NON_NULL_THROW_EXCEPTION(jGroupId, "groupId cannot be null", OC_STACK_INVALID_PARAM);
1173     VERIFY_NON_NULL_THROW_EXCEPTION(jPropertyValue, "propertyValue cannot be null",
1174                                     OC_STACK_INVALID_PARAM);
1175     VERIFY_NON_NULL_THROW_EXCEPTION(jListener, "onPostListener cannot be null",
1176                                     OC_STACK_INVALID_PARAM);
1177
1178     JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env,
1179                                                                                          thiz);
1180     if (!accountManager)
1181     {
1182         return;
1183     }
1184
1185     OCRepresentation *propertyValue = JniOcRepresentation::getOCRepresentationPtr(env,
1186                                                                                   jPropertyValue);
1187     if (!propertyValue)
1188     {
1189         return;
1190     }
1191
1192     const char *charGroupId = env->GetStringUTFChars(jGroupId, nullptr);
1193     VERIFY_NON_NULL_THROW_EXCEPTION(charGroupId, "charGroupId is null", JNI_EXCEPTION);
1194     std::string groupId(charGroupId);
1195     env->ReleaseStringUTFChars(jGroupId, charGroupId);
1196
1197     try
1198     {
1199         OCStackResult result = accountManager->deletePropertyValueFromGroup(env,
1200                                                                             groupId,
1201                                                                             *propertyValue,
1202                                                                             jListener);
1203
1204         if (OC_STACK_OK != result)
1205         {
1206             ThrowOcException(result, "OcAccountManager_deletePropertyValueFromGroup");
1207         }
1208     }
1209     catch (OCException& e)
1210     {
1211         LOGE("%s", e.reason().c_str());
1212         ThrowOcException(e.code(), e.reason().c_str());
1213     }
1214 }
1215
1216 /*
1217 * Class:     org_iotivity_base_OcAccountManager
1218 * Method:    updatePropertyValueOnGroup0
1219 * Signature: (Ljava/lang/String;Lorg/iotivity/base/OcRepresentation;
1220 *             Lorg/iotivity/base/OcAccountManager/OnPostListener;)V
1221 */
1222 JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_updatePropertyValueOnGroup0
1223     (JNIEnv *env, jobject thiz, jstring jGroupId, jobject jPropertyValue, jobject jListener)
1224 {
1225     LOGD("OcAccountManager_updatePropertyValueOnGroup");
1226     VERIFY_NON_NULL_THROW_EXCEPTION(jGroupId, "groupId cannot be null", OC_STACK_INVALID_PARAM);
1227     VERIFY_NON_NULL_THROW_EXCEPTION(jPropertyValue, "propertyValue cannot be null",
1228                                     OC_STACK_INVALID_PARAM);
1229     VERIFY_NON_NULL_THROW_EXCEPTION(jListener, "onPostListener cannot be null",
1230                                     OC_STACK_INVALID_PARAM);
1231
1232     JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env,
1233                                                                                          thiz);
1234     if (!accountManager)
1235     {
1236         return;
1237     }
1238
1239     OCRepresentation *propertyValue = JniOcRepresentation::getOCRepresentationPtr(env,
1240                                                                                   jPropertyValue);
1241     if (!propertyValue)
1242     {
1243         return;
1244     }
1245
1246     const char *charGroupId = env->GetStringUTFChars(jGroupId, nullptr);
1247     VERIFY_NON_NULL_THROW_EXCEPTION(charGroupId, "charGroupId is null", JNI_EXCEPTION);
1248     std::string groupId(charGroupId);
1249     env->ReleaseStringUTFChars(jGroupId, charGroupId);
1250
1251     try
1252     {
1253         OCStackResult result = accountManager->updatePropertyValueOnGroup(env,
1254                                                                           groupId,
1255                                                                           *propertyValue,
1256                                                                           jListener);
1257
1258         if (OC_STACK_OK != result)
1259         {
1260             ThrowOcException(result, "OcAccountManager_updatePropertyValueOnGroup");
1261         }
1262     }
1263     catch (OCException& e)
1264     {
1265         LOGE("%s", e.reason().c_str());
1266         ThrowOcException(e.code(), e.reason().c_str());
1267     }
1268 }
1269
1270 /*
1271 * Class:     org_iotivity_base_OcAccountManager
1272 * Method:    observeGroup0
1273 * Signature: (Lorg/iotivity/base/OcResource/OnObserveListener;)V
1274 */
1275 JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_observeGroup0
1276     (JNIEnv *env, jobject thiz, jobject jListener)
1277 {
1278     LOGD("OcAccountManager_observeGroup");
1279     VERIFY_NON_NULL_THROW_EXCEPTION(jListener, "onObserveListener cannot be null",
1280                                     OC_STACK_INVALID_PARAM);
1281
1282     JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env,
1283                                                                                          thiz);
1284     if (!accountManager)
1285     {
1286         return;
1287     }
1288
1289     try
1290     {
1291         OCStackResult result = accountManager->observeGroup(env,
1292                                                             jListener);
1293         if (OC_STACK_OK != result)
1294         {
1295             ThrowOcException(result, "OcAccountManager_observeGroup");
1296         }
1297     }
1298     catch (OCException& e)
1299     {
1300         LOGE("%s", e.reason().c_str());
1301         ThrowOcException(e.code(), e.reason().c_str());
1302     }
1303 }
1304
1305 /*
1306 * Class:     org_iotivity_base_OcAccountManager
1307 * Method:    cancelObserveGroup0
1308 * Signature: ()V
1309 */
1310 JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_cancelObserveGroup0
1311     (JNIEnv *env, jobject thiz)
1312 {
1313     LOGD("OcAccountManager_cancelObserveGroup");
1314
1315     JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env,
1316                                                                                          thiz);
1317     if (!accountManager)
1318     {
1319         return;
1320     }
1321
1322     try
1323     {
1324         OCStackResult result = accountManager->cancelObserveGroup();
1325         if (OC_STACK_OK != result)
1326         {
1327             ThrowOcException(result, "OcAccountManager_cancelObserveGroup");
1328         }
1329     }
1330     catch (OCException& e)
1331     {
1332         LOGE("%s", e.reason().c_str());
1333         ThrowOcException(e.code(), e.reason().c_str());
1334     }
1335 }
1336
1337 /*
1338 * Class:     org_iotivity_base_OcAccountManager
1339 * Method:    observeInvitation0
1340 * Signature: (Lorg/iotivity/base/OcResource/OnObserveListener;)V
1341 */
1342 JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_observeInvitation0
1343     (JNIEnv *env, jobject thiz, jobject jListener)
1344 {
1345     LOGD("OcAccountManager_observeInvitation");
1346     VERIFY_NON_NULL_THROW_EXCEPTION(jListener, "onObserveListener cannot be null",
1347                                     OC_STACK_INVALID_PARAM);
1348
1349     JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env,
1350                                                                                          thiz);
1351     if (!accountManager)
1352     {
1353         return;
1354     }
1355
1356     try
1357     {
1358         OCStackResult result = accountManager->observeInvitation(env,
1359                                                                  jListener);
1360         if (OC_STACK_OK != result)
1361         {
1362             ThrowOcException(result, "OcAccountManager_observeInvitation");
1363         }
1364     }
1365     catch (OCException& e)
1366     {
1367         LOGE("%s", e.reason().c_str());
1368         ThrowOcException(e.code(), e.reason().c_str());
1369     }
1370 }
1371
1372 /*
1373 * Class:     org_iotivity_base_OcAccountManager
1374 * Method:    cancelObserveInvitation0
1375 * Signature: ()V
1376 */
1377 JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_cancelObserveInvitation0
1378     (JNIEnv *env, jobject thiz)
1379 {
1380     LOGD("OcAccountManager_cancelObserveInvitation");
1381
1382     JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env,
1383                                                                                          thiz);
1384     if (!accountManager)
1385     {
1386         return;
1387     }
1388
1389     try
1390     {
1391         OCStackResult result = accountManager->cancelObserveInvitation();
1392         if (OC_STACK_OK != result)
1393         {
1394             ThrowOcException(result, "OcAccountManager_cancelObserveInvitation");
1395         }
1396     }
1397     catch (OCException& e)
1398     {
1399         LOGE("%s", e.reason().c_str());
1400         ThrowOcException(e.code(), e.reason().c_str());
1401     }
1402 }
1403
1404 /*
1405 * Class:     org_iotivity_base_OcAccountManager
1406 * Method:    sendInvitation0
1407 * Signature: (Ljava/lang/String;Ljava/lang/String;
1408 *             Lorg/iotivity/base/OcAccountManager/OnPostListener;)V
1409 */
1410 JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_sendInvitation0
1411     (JNIEnv *env, jobject thiz, jstring jGroupId, jstring jUserUuid, jobject jListener)
1412 {
1413     LOGD("OcAccountManager_sendInvitation");
1414     VERIFY_NON_NULL_THROW_EXCEPTION(jGroupId, "groupId cannot be null", OC_STACK_INVALID_PARAM);
1415     VERIFY_NON_NULL_THROW_EXCEPTION(jUserUuid, "userUuid cannot be null", OC_STACK_INVALID_PARAM);
1416     VERIFY_NON_NULL_THROW_EXCEPTION(jListener, "onPostListener cannot be null",
1417                                     OC_STACK_INVALID_PARAM);
1418
1419     JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env,
1420                                                                                          thiz);
1421     if (!accountManager)
1422     {
1423         return;
1424     }
1425
1426     const char *charGroupId = env->GetStringUTFChars(jGroupId, nullptr);
1427     VERIFY_NON_NULL_THROW_EXCEPTION(charGroupId, "charGroupId is null", JNI_EXCEPTION);
1428     std::string groupId(charGroupId);
1429     env->ReleaseStringUTFChars(jGroupId, charGroupId);
1430
1431     const char *charUserUuid = env->GetStringUTFChars(jUserUuid, nullptr);
1432     VERIFY_NON_NULL_THROW_EXCEPTION(charUserUuid, "charUserUuid is null", JNI_EXCEPTION);
1433     std::string userUuid(charUserUuid);
1434     env->ReleaseStringUTFChars(jUserUuid, charUserUuid);
1435
1436     try
1437     {
1438         OCStackResult result = accountManager->sendInvitation(env,
1439                                                               groupId,
1440                                                               userUuid,
1441                                                               jListener);
1442         if (OC_STACK_OK != result)
1443         {
1444             ThrowOcException(result, "OcAccountManager_sendInvitation");
1445         }
1446     }
1447     catch (OCException& e)
1448     {
1449         LOGE("%s", e.reason().c_str());
1450         ThrowOcException(e.code(), e.reason().c_str());
1451     }
1452 }
1453
1454 /*
1455 * Class:     org_iotivity_base_OcAccountManager
1456 * Method:    cancelInvitation0
1457 * Signature: (Ljava/lang/String;Ljava/lang/String;
1458 *             Lorg/iotivity/base/OcAccountManager/onDeleteListener;)V
1459 */
1460 JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_cancelInvitation0
1461     (JNIEnv *env, jobject thiz, jstring jGroupId, jstring jUserUuid, jobject jListener)
1462 {
1463     LOGD("OcAccountManager_cancelInvitation");
1464     VERIFY_NON_NULL_THROW_EXCEPTION(jGroupId, "groupId cannot be null", OC_STACK_INVALID_PARAM);
1465     VERIFY_NON_NULL_THROW_EXCEPTION(jUserUuid, "userUuid cannot be null", OC_STACK_INVALID_PARAM);
1466     VERIFY_NON_NULL_THROW_EXCEPTION(jListener, "onDeleteListener cannot be null",
1467                                     OC_STACK_INVALID_PARAM);
1468
1469     JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env,
1470                                                                                          thiz);
1471     if (!accountManager)
1472     {
1473         return;
1474     }
1475
1476     const char *charGroupId = env->GetStringUTFChars(jGroupId, nullptr);
1477     VERIFY_NON_NULL_THROW_EXCEPTION(charGroupId, "charGroupId is null", JNI_EXCEPTION);
1478     std::string groupId(charGroupId);
1479     env->ReleaseStringUTFChars(jGroupId, charGroupId);
1480
1481     const char *charUserUuid = env->GetStringUTFChars(jUserUuid, nullptr);
1482     VERIFY_NON_NULL_THROW_EXCEPTION(charUserUuid, "charUserUuid is null", JNI_EXCEPTION);
1483     std::string userUuid(charUserUuid);
1484     env->ReleaseStringUTFChars(jUserUuid, charUserUuid);
1485
1486     try
1487     {
1488         OCStackResult result = accountManager->cancelInvitation(env,
1489                                                                 groupId,
1490                                                                 userUuid,
1491                                                                 jListener);
1492         if (OC_STACK_OK != result)
1493         {
1494             ThrowOcException(result, "OcAccountManager_cancelInvitation");
1495         }
1496     }
1497     catch (OCException& e)
1498     {
1499         LOGE("%s", e.reason().c_str());
1500         ThrowOcException(e.code(), e.reason().c_str());
1501     }
1502 }
1503
1504 /*
1505 * Class:     org_iotivity_base_OcAccountManager
1506 * Method:    replyToInvitation0
1507 * Signature: (Ljava/lang/String;ZLorg/iotivity/base/OcAccountManager/onDeleteListener;)V
1508 */
1509 JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_replyToInvitation0
1510     (JNIEnv *env, jobject thiz, jstring jGroupId, jboolean jAccept, jobject jListener)
1511 {
1512     LOGD("OcAccountManager_replyToInvitation");
1513     VERIFY_NON_NULL_THROW_EXCEPTION(jGroupId, "groupId cannot be null", OC_STACK_INVALID_PARAM);
1514     VERIFY_NON_NULL_THROW_EXCEPTION(jListener, "onDeleteListener cannot be null",
1515                                     OC_STACK_INVALID_PARAM);
1516
1517     JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env,
1518                                                                                          thiz);
1519     if (!accountManager)
1520     {
1521         return;
1522     }
1523
1524     const char *charGroupId = env->GetStringUTFChars(jGroupId, nullptr);
1525     VERIFY_NON_NULL_THROW_EXCEPTION(charGroupId, "charGroupId is null", JNI_EXCEPTION);
1526     std::string groupId(charGroupId);
1527     env->ReleaseStringUTFChars(jGroupId, charGroupId);
1528
1529     try
1530     {
1531         OCStackResult result = accountManager->replyToInvitation(env,
1532                                                                  groupId,
1533                                                                  static_cast<bool>(jAccept),
1534                                                                  jListener);
1535         if (OC_STACK_OK != result)
1536         {
1537             ThrowOcException(result, "OcAccountManager_replyToInvitation");
1538         }
1539     }
1540     catch (OCException& e)
1541     {
1542         LOGE("%s", e.reason().c_str());
1543         ThrowOcException(e.code(), e.reason().c_str());
1544     }
1545 }
1546
1547