2 * //******************************************************************
4 * // Copyright 2016 Samsung Electronics All Rights Reserved.
6 * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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
12 * // http://www.apache.org/licenses/LICENSE-2.0
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.
20 * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
22 #include "JniDisplayVerifyNumListener.h"
23 #include "oic_malloc.h"
25 JniDisplayVerifyNumListener::JniDisplayVerifyNumListener(JNIEnv *env, jobject jListener)
27 m_jgListener = env->NewGlobalRef(jListener);
30 JniDisplayVerifyNumListener::~JniDisplayVerifyNumListener()
32 LOGI("~JniDisplayVerifyNumListener()");
36 JNIEnv *env = GetJNIEnv(ret);
37 if (NULL == env) return;
38 env->DeleteGlobalRef(m_jgListener);
39 if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
43 OCStackResult JniDisplayVerifyNumListener::displayMutualVerifNumCallback(uint8_t verifNum[3])
46 JNIEnv *env = GetJNIEnv(ret);
51 return OC_STACK_ERROR;
54 jclass clsL = env->GetObjectClass(m_jgListener);
58 if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
59 return OC_STACK_ERROR;
62 jmethodID midL = env->GetMethodID(clsL, "displayNumListener", "(Ljava/lang/String;)I");
65 if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
66 return OC_STACK_ERROR;
69 byteArray = (char*)OICCalloc(20, sizeof(char));
71 if (NULL == byteArray)
73 if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
74 return OC_STACK_NO_MEMORY;
77 sprintf(byteArray, "%02X%02X%02X", verifNum[0], verifNum[1], verifNum[2]);
79 jstring jStr = env->NewStringUTF(byteArray);
82 if (JNI_EDETACHED == ret)
84 g_jvm->DetachCurrentThread();
86 return OC_STACK_ERROR;
88 OCStackResult result = (OCStackResult)env->CallIntMethod(m_jgListener, midL, jStr);
90 if (env->ExceptionCheck())
92 LOGE("Java exception is thrown");
93 env->ExceptionClear();
96 if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();