• 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 #ifndef EVENT_LISTENER_MANAGER_H
17 #define EVENT_LISTENER_MANAGER_H
18 
19 #include <cstdint>
20 #include <memory>
21 
22 #include "event_listener.h"
23 #include "event_listener_handler.h"
24 #include "telephony_log_wrapper.h"
25 #include "telephony_update_event_type.h"
26 
27 namespace OHOS {
28 namespace Telephony {
29 class EventListenerManager {
30 public:
31     template<typename T, typename D>
32     inline static bool SendEvent(uint32_t innerEventId, std::unique_ptr<T, D> &object, int64_t delayTime = 0)
33     {
34         auto handler = DelayedSingleton<EventListenerHandler>::GetInstance();
35         if (handler == nullptr) {
36             TELEPHONY_LOGE("Get handler failed");
37             return false;
38         }
39         return handler->SendEvent(innerEventId, object, delayTime);
40     }
41     static int32_t RegisterEventListener(EventListener &eventListener);
42     static int32_t UnregisterEventListener(napi_env env, const TelephonyUpdateEventType eventType, napi_ref ref,
43         std::list<EventListener> &removeListenerList);
44     static int32_t UnregisterEventListener(
45         napi_env env, TelephonyUpdateEventType eventType, std::list<EventListener> &removeListenerList);
46     static void UnRegisterAllListener(napi_env env);
47 };
48 } // namespace Telephony
49 } // namespace OHOS
50 #endif // EVENT_LISTENER_MANAGER_H
51