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 "JniOcCloudResultListener.h"
24 JniOcCloudResultListener::JniOcCloudResultListener(JNIEnv *env, jobject jListener,
25 RemoveCallback removeCloudResultListener)
27 m_jwListener = env->NewWeakGlobalRef(jListener);
28 m_removeCloudResultListener = removeCloudResultListener;
31 JniOcCloudResultListener::~JniOcCloudResultListener()
33 LOGI("~JniOcCloudResultListener()");
37 JNIEnv *env = GetJNIEnv(ret);
42 env->DeleteWeakGlobalRef(m_jwListener);
43 if (JNI_EDETACHED == ret)
45 g_jvm->DetachCurrentThread();
50 void JniOcCloudResultListener::CloudResultListenerCB(int result, void *data,
54 JNIEnv *env = GetJNIEnv(ret);
60 jobject jListener = env->NewLocalRef(m_jwListener);
63 checkExAndRemoveListener(env);
64 if (JNI_EDETACHED == ret)
66 g_jvm->DetachCurrentThread();
71 jclass clsL = env->GetObjectClass(jListener);
75 checkExAndRemoveListener(env);
76 if (JNI_EDETACHED == ret)
78 g_jvm->DetachCurrentThread();
83 std::string calledFunc;
86 case ListenerFunc::REQUEST_CERTIFICATE:
88 calledFunc = "requestCertificateListener";
91 case ListenerFunc::GET_ACLINFO:
93 calledFunc = "getIndividualAclInfoListener";
96 case ListenerFunc::GET_CRL:
98 calledFunc = "getCRLListener";
101 case ListenerFunc::POST_CRL:
103 calledFunc = "postCRLListener";
108 checkExAndRemoveListener(env);
109 if (JNI_EDETACHED == ret)
111 g_jvm->DetachCurrentThread();
118 jmethodID midL = env->GetMethodID(clsL, calledFunc.c_str(), "(Z)V");
121 checkExAndRemoveListener(env);
122 if (JNI_EDETACHED == ret)
124 g_jvm->DetachCurrentThread();
129 env->CallVoidMethod(jListener, midL, (jboolean)result);
130 if (env->ExceptionCheck())
132 LOGE("Java exception is thrown");
135 checkExAndRemoveListener(env);
136 if (JNI_EDETACHED == ret)
138 g_jvm->DetachCurrentThread();
142 void JniOcCloudResultListener::checkExAndRemoveListener(JNIEnv* env)
144 if (env->ExceptionCheck())
146 jthrowable ex = env->ExceptionOccurred();
147 env->ExceptionClear();
148 m_removeCloudResultListener(env, m_jwListener);
149 env->Throw((jthrowable)ex);
153 m_removeCloudResultListener(env, m_jwListener);