replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / android / android_api / base / jni / JniConfirmNumListener.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 #include "JniConfirmNumListener.h"
23
24 JniConfirmNumListener::JniConfirmNumListener(JNIEnv *env, jobject jListener)
25 {
26     m_jgListener = env->NewGlobalRef(jListener);
27 }
28
29 JniConfirmNumListener::~JniConfirmNumListener()
30 {
31     LOGI("~JniConfirmNumListener()");
32     if (m_jgListener)
33     {
34         jint ret = JNI_ERR;
35         JNIEnv *env = GetJNIEnv(ret);
36         if (NULL == env) return;
37         env->DeleteGlobalRef(m_jgListener);
38         if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
39     }
40 }
41
42 OCStackResult JniConfirmNumListener::confirmMutualVerifNumCallback()
43 {
44     jint ret = JNI_ERR;
45     JNIEnv *env = GetJNIEnv(ret);
46     if (NULL == env)
47     {
48         return OC_STACK_ERROR;
49     }
50
51     jclass clsL = env->GetObjectClass(m_jgListener);
52
53     if (!clsL)
54     {
55         if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
56         return OC_STACK_ERROR;
57     }
58
59     jmethodID midL = env->GetMethodID(clsL, "confirmNumListener", "()I");
60     if (!midL)
61     {
62         if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
63         return OC_STACK_ERROR;
64     }
65
66     OCStackResult result = (OCStackResult) env->CallIntMethod(m_jgListener, midL);
67
68     if (env->ExceptionCheck())
69     {
70         LOGE("Java exception is thrown");
71         env->ExceptionClear();
72     }
73
74     if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
75     return result;
76 }