2 //* //******************************************************************
\r
4 //* // Copyright 2015 Intel Corporation.
\r
6 //* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
\r
8 //* // Licensed under the Apache License, Version 2.0 (the "License");
\r
9 //* // you may not use this file except in compliance with the License.
\r
10 //* // You may obtain a copy of the License at
\r
12 //* // http://www.apache.org/licenses/LICENSE-2.0
\r
14 //* // Unless required by applicable law or agreed to in writing, software
\r
15 //* // distributed under the License is distributed on an "AS IS" BASIS,
\r
16 //* // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
17 //* // See the License for the specific language governing permissions and
\r
18 //* // limitations under the License.
\r
20 //* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
\r
23 //#include "JniListenerManager.h"
\r
25 //#include "JniOnGetListener.h"
\r
28 //T* JniListenerManager<T>::addListener(JNIEnv* env, jobject jListener)
\r
30 // T *onEventListener = NULL;
\r
32 // m_mapMutex.lock();
\r
34 // for (auto it = m_listenerMap.begin(); it != m_listenerMap.end(); ++it)
\r
36 // if (env->IsSameObject(jListener, it->first))
\r
38 // auto refPair = it->second;
\r
39 // onEventListener = refPair.first;
\r
40 // refPair.second++;
\r
41 // it->second = refPair;
\r
42 // m_listenerMap.insert(*it);
\r
43 // LOGD("OnEventListener: ref. count is incremented");
\r
48 // if (!onEventListener)
\r
50 // onEventListener = new T(env, jListener, this);
\r
51 // jobject jgListener = env->NewGlobalRef(jListener);
\r
53 // m_listenerMap.insert(std::pair<jobject, std::pair<T*, int>>(jgListener, std::pair<T*, int>(onEventListener, 1)));
\r
54 // LOGD("OnEventListener: new listener");
\r
57 // m_mapMutex.unlock();
\r
59 // return onEventListener;
\r
63 //void JniListenerManager<T>::removeListener(JNIEnv* env, jobject jListener)
\r
65 // m_mapMutex.lock();
\r
67 // bool isFound = false;
\r
69 // for (auto it = m_listenerMap.begin(); it != m_listenerMap.end(); ++it)
\r
71 // if (env->IsSameObject(jListener, it->first))
\r
73 // auto refPair = it->second;
\r
74 // if (refPair.second > 1)
\r
76 // refPair.second--;
\r
77 // it->second = refPair;
\r
78 // m_listenerMap.insert(*it);
\r
79 // LOGI("OnEventListener: ref. count is decremented");
\r
83 // env->DeleteGlobalRef(it->first);
\r
84 // T* listener = refPair.first;
\r
86 // m_listenerMap.erase(it);
\r
88 // LOGI("OnEventListener is removed");
\r
98 // ThrowOcException(JNI_EXCEPTION, "OnEventListener isn't found");
\r
101 // m_mapMutex.unlock();
\r