1 /* 2 * Copyright (c) 2024 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 OBSERVER_EVENT_HANDLER_H 17 #define OBSERVER_EVENT_HANDLER_H 18 19 #include <cstdint> 20 #include <list> 21 #include <map> 22 #include <memory> 23 #include <optional> 24 #include <set> 25 #include <uv.h> 26 27 #include "event_handler.h" 28 #include "network_state.h" 29 #include "refbase.h" 30 #include "signal_information.h" 31 #include "singleton.h" 32 #include "telephony_observer_utils.h" 33 34 namespace OHOS { 35 namespace Telephony { 36 constexpr int32_t EVENT_LISTENER_DIFF = -1; 37 constexpr int32_t EVENT_LISTENER_SAME = 0; 38 constexpr int32_t EVENT_LISTENER_SLOTID_AND_EVENTTYPE_SAME = 1; 39 40 class ObserverEventHandler : public AppExecFwk::EventHandler { 41 DECLARE_DELAYED_SINGLETON(ObserverEventHandler) 42 public: 43 ObserverEventHandler(const ObserverEventHandler &) = delete; 44 ObserverEventHandler &operator=(const ObserverEventHandler &) = delete; 45 void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) override; 46 int32_t RegisterEventListener(EventListener &eventListener); 47 int32_t UnregisterEventListener(const TelephonyUpdateEventType eventType, int64_t funcId); 48 49 private: 50 static std::mutex operatorMutex_; 51 std::list<EventListener> listenerList_; 52 53 bool CheckEventTypeExist(int32_t slotId, TelephonyUpdateEventType eventType); 54 void SetEventListenerDeleting(std::shared_ptr<bool> isDeleting); 55 void RemoveEventListenerRegister(const TelephonyUpdateEventType eventType, int64_t funcId, 56 std::set<int32_t> &soltIdSet); 57 void CheckRemoveStateObserver(TelephonyUpdateEventType eventType, int32_t slotId, int32_t &result); 58 int32_t CheckEventListenerRegister(EventListener &eventListener); 59 60 static void WorkUpdated(const EventListener &listener, uv_work_t *work, std::unique_lock<std::mutex> &lock); 61 static void WorkCallStateUpdated(const EventListener &listener, 62 uv_work_t *work, std::unique_lock<std::mutex> &lock); 63 static void WorkSignalUpdated(const EventListener &listener, 64 uv_work_t *work, std::unique_lock<std::mutex> &lock); 65 static void WorkNetworkStateUpdated(const EventListener &listener, 66 uv_work_t *work, std::unique_lock<std::mutex> &lock); 67 static void WorkSimStateUpdated(const EventListener &listener, 68 uv_work_t *work, std::unique_lock<std::mutex> &lock); 69 static void WorkCellInfomationUpdated(const EventListener &listener, 70 uv_work_t *work, std::unique_lock<std::mutex> &lock); 71 static void WorkCellularDataConnectStateUpdated(const EventListener &listener, 72 uv_work_t *work, std::unique_lock<std::mutex> &lock); 73 static void WorkCellularDataFlowUpdated(const EventListener &listener, 74 uv_work_t *work, std::unique_lock<std::mutex> &lock); 75 static void WorkCfuIndicatorUpdated(const EventListener &listener, 76 uv_work_t *work, std::unique_lock<std::mutex> &lock); 77 static void WorkVoiceMailMsgIndicatorUpdated(const EventListener &listener, 78 uv_work_t *work, std::unique_lock<std::mutex> &lock); 79 static void WorkIccAccountUpdated(const EventListener &listener, 80 uv_work_t *work, std::unique_lock<std::mutex> &lock); 81 82 template<typename D, TelephonyUpdateEventType eventType> 83 void HandleCallbackInfoUpdate(const AppExecFwk::InnerEvent::Pointer &event); 84 template<TelephonyUpdateEventType eventType> 85 void HandleCallbackVoidUpdate(const AppExecFwk::InnerEvent::Pointer &event); 86 }; 87 88 } 89 } 90 91 #endif