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 "JniGetAclIdByDeviceListener.h"
24 JniGetAclIdByDeviceListener::JniGetAclIdByDeviceListener(JNIEnv *env, jobject jListener,
25 RemoveCallback removeListener)
27 m_jwListener = env->NewWeakGlobalRef(jListener);
28 m_removeGetAclbyIDListener = removeListener;
31 JniGetAclIdByDeviceListener::~JniGetAclIdByDeviceListener()
33 LOGI("~JniGetAclIdByDeviceListener()");
37 JNIEnv *env = GetJNIEnv(ret);
42 env->DeleteWeakGlobalRef(m_jwListener);
43 if (JNI_EDETACHED == ret)
45 g_jvm->DetachCurrentThread();
50 void JniGetAclIdByDeviceListener::GetAclIdByDeviceListenerCB(int result, std::string aclID)
53 JNIEnv *env = GetJNIEnv(ret);
59 jobject jListener = env->NewLocalRef(m_jwListener);
62 checkExAndRemoveListener(env);
63 if (JNI_EDETACHED == ret)
65 g_jvm->DetachCurrentThread();
70 jclass clsL = env->GetObjectClass(jListener);
74 checkExAndRemoveListener(env);
75 if (JNI_EDETACHED == ret)
77 g_jvm->DetachCurrentThread();
82 jmethodID midL = env->GetMethodID(clsL, "getAclIdByDeviceListener", "(ZLjava/lang/String;)V");
85 checkExAndRemoveListener(env);
86 if (JNI_EDETACHED == ret)
88 g_jvm->DetachCurrentThread();
92 jstring jStr = env-> NewStringUTF(aclID.c_str());
95 checkExAndRemoveListener(env);
96 if (JNI_EDETACHED == ret)
98 g_jvm->DetachCurrentThread();
103 env->CallVoidMethod(jListener, midL, (jboolean)result, jStr);
104 if (env->ExceptionCheck())
106 LOGE("Java exception is thrown");
108 checkExAndRemoveListener(env);
109 if (JNI_EDETACHED == ret)
111 g_jvm->DetachCurrentThread();
115 void JniGetAclIdByDeviceListener::checkExAndRemoveListener(JNIEnv* env)
117 if (env->ExceptionCheck())
119 jthrowable ex = env->ExceptionOccurred();
120 env->ExceptionClear();
121 m_removeGetAclbyIDListener(env, m_jwListener);
122 env->Throw((jthrowable)ex);
126 m_removeGetAclbyIDListener(env, m_jwListener);