2 //* //******************************************************************
4 //* // Copyright 2015 Intel Corporation.
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 //* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
23 //#include "JniListenerManager.h"
25 //#include "JniOnGetListener.h"
28 //T* JniListenerManager<T>::addListener(JNIEnv* env, jobject jListener)
30 // T *onEventListener = NULL;
34 // for (auto it = m_listenerMap.begin(); it != m_listenerMap.end(); ++it)
36 // if (env->IsSameObject(jListener, it->first))
38 // auto refPair = it->second;
39 // onEventListener = refPair.first;
41 // it->second = refPair;
42 // m_listenerMap.insert(*it);
43 // LOGD("OnEventListener: ref. count is incremented");
48 // if (!onEventListener)
50 // onEventListener = new T(env, jListener, this);
51 // jobject jgListener = env->NewGlobalRef(jListener);
53 // m_listenerMap.insert(std::pair<jobject, std::pair<T*, int>>(jgListener, std::pair<T*, int>(onEventListener, 1)));
54 // LOGD("OnEventListener: new listener");
57 // m_mapMutex.unlock();
59 // return onEventListener;
63 //void JniListenerManager<T>::removeListener(JNIEnv* env, jobject jListener)
67 // bool isFound = false;
69 // for (auto it = m_listenerMap.begin(); it != m_listenerMap.end(); ++it)
71 // if (env->IsSameObject(jListener, it->first))
73 // auto refPair = it->second;
74 // if (refPair.second > 1)
77 // it->second = refPair;
78 // m_listenerMap.insert(*it);
79 // LOGI("OnEventListener: ref. count is decremented");
83 // env->DeleteGlobalRef(it->first);
84 // T* listener = refPair.first;
86 // m_listenerMap.erase(it);
88 // LOGI("OnEventListener is removed");
98 // ThrowOcException(JNI_EXCEPTION, "OnEventListener isn't found");
101 // m_mapMutex.unlock();