• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "event_listener_manager.h"
17 
18 #include "telephony_update_event_type.h"
19 
20 namespace OHOS {
21 namespace Telephony {
RegisterEventListener(EventListener & eventListener)22 int32_t EventListenerManager::RegisterEventListener(EventListener &eventListener)
23 {
24     auto handler = DelayedSingleton<EventListenerHandler>::GetInstance();
25     if (handler == nullptr) {
26         TELEPHONY_LOGE("Get event handler failed");
27         return TELEPHONY_ERR_LOCAL_PTR_NULL;
28     }
29     return handler->RegisterEventListener(eventListener);
30 }
31 
UnregisterEventListener(napi_env env,const TelephonyUpdateEventType eventType,napi_ref ref,std::list<EventListener> & removeListenerList)32 int32_t EventListenerManager::UnregisterEventListener(
33     napi_env env, const TelephonyUpdateEventType eventType, napi_ref ref, std::list<EventListener> &removeListenerList)
34 {
35     auto handler = DelayedSingleton<EventListenerHandler>::GetInstance();
36     if (handler == nullptr) {
37         TELEPHONY_LOGE("Get event handler failed");
38         return TELEPHONY_ERR_LOCAL_PTR_NULL;
39     }
40     return handler->UnregisterEventListener(env, eventType, ref, removeListenerList);
41 }
42 
UnregisterEventListener(napi_env env,TelephonyUpdateEventType eventType,std::list<EventListener> & removeListenerList)43 int32_t EventListenerManager::UnregisterEventListener(
44     napi_env env, TelephonyUpdateEventType eventType, std::list<EventListener> &removeListenerList)
45 {
46     auto handler = DelayedSingleton<EventListenerHandler>::GetInstance();
47     if (handler == nullptr) {
48         TELEPHONY_LOGE("Get event handler failed");
49         return TELEPHONY_ERR_LOCAL_PTR_NULL;
50     }
51     return handler->UnregisterEventListener(env, eventType, removeListenerList);
52 }
53 
UnRegisterAllListener(napi_env env)54 void EventListenerManager::UnRegisterAllListener(napi_env env)
55 {
56     auto handler = DelayedSingleton<EventListenerHandler>::GetInstance();
57     if (handler == nullptr) {
58         TELEPHONY_LOGE("Get event handler failed");
59         return;
60     }
61     handler->UnRegisterAllListener(env);
62 }
63 } // namespace Telephony
64 } // namespace OHOS
65