Clean up some SonarQube warnings (trailing whitespace, etc).
[platform/upstream/iotivity.git] / android / android_api / base / jni / JniListenerManager.cpp
1 ///*
2 //* //******************************************************************
3 //* //
4 //* // Copyright 2015 Intel Corporation.
5 //* //
6 //* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 //* //
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
11 //* //
12 //* //      http://www.apache.org/licenses/LICENSE-2.0
13 //* //
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.
19 //* //
20 //* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 //*/
22 //
23 //#include "JniListenerManager.h"
24 //
25 //#include "JniOnGetListener.h"
26 //
27 //template<class T>
28 //T* JniListenerManager<T>::addListener(JNIEnv* env, jobject jListener)
29 //{
30 //      T *onEventListener = NULL;
31 //
32 //      m_mapMutex.lock();
33 //
34 //      for (auto it = m_listenerMap.begin(); it != m_listenerMap.end(); ++it)
35 //      {
36 //              if (env->IsSameObject(jListener, it->first))
37 //              {
38 //                      auto refPair = it->second;
39 //                      onEventListener = refPair.first;
40 //                      refPair.second++;
41 //                      it->second = refPair;
42 //                      m_listenerMap.insert(*it);
43 //                      LOGD("OnEventListener: ref. count is incremented");
44 //                      break;
45 //              }
46 //      }
47 //
48 //      if (!onEventListener)
49 //      {
50 //              onEventListener = new T(env, jListener, this);
51 //              jobject jgListener = env->NewGlobalRef(jListener);
52 //
53 //              m_listenerMap.insert(std::pair<jobject, std::pair<T*, int>>(jgListener, std::pair<T*, int>(onEventListener, 1)));
54 //              LOGD("OnEventListener: new listener");
55 //      }
56 //
57 //      m_mapMutex.unlock();
58 //
59 //      return onEventListener;
60 //}
61 //
62 //template<class T>
63 //void JniListenerManager<T>::removeListener(JNIEnv* env, jobject jListener)
64 //{
65 //      m_mapMutex.lock();
66 //
67 //      bool isFound = false;
68 //
69 //      for (auto it = m_listenerMap.begin(); it != m_listenerMap.end(); ++it)
70 //      {
71 //              if (env->IsSameObject(jListener, it->first))
72 //              {
73 //                      auto refPair = it->second;
74 //                      if (refPair.second > 1)
75 //                      {
76 //                              refPair.second--;
77 //                              it->second = refPair;
78 //                              m_listenerMap.insert(*it);
79 //                              LOGI("OnEventListener: ref. count is decremented");
80 //                      }
81 //                      else
82 //                      {
83 //                              env->DeleteGlobalRef(it->first);
84 //                              T* listener = refPair.first;
85 //                              delete listener;
86 //                              m_listenerMap.erase(it);
87 //
88 //                              LOGI("OnEventListener is removed");
89 //                      }
90 //
91 //                      isFound = true;
92 //                      break;
93 //              }
94 //      }
95 //
96 //      if (!isFound)
97 //      {
98 //              ThrowOcException(JNI_EXCEPTION, "OnEventListener isn't found");
99 //      }
100 //
101 //      m_mapMutex.unlock();
102 //}
103 //