1 /* 2 * Copyright (c) 2022-2023 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 NET_POLICY_EVENT_HANDLER_H 17 #define NET_POLICY_EVENT_HANDLER_H 18 19 #include <iostream> 20 21 #include "event_handler.h" 22 #include "event_runner.h" 23 #include "ffrt.h" 24 #include "net_policy_core.h" 25 #include "singleton.h" 26 27 namespace OHOS { 28 namespace NetManagerStandard { 29 class NetPolicyCore; 30 class NetPolicyEventHandler { 31 public: 32 static constexpr int32_t MSG_DEVICE_IDLE_LIST_UPDATED = 1; 33 static constexpr int32_t MSG_DEVICE_IDLE_MODE_CHANGED = 2; 34 static constexpr int32_t MSG_POWER_SAVE_MODE_CHANGED = 3; 35 static constexpr int32_t MSG_UID_REMOVED = 4; 36 static constexpr int32_t MSG_POWER_SAVE_LIST_UPDATED = 5; 37 static constexpr int32_t MSG_UID_STATE_FOREGROUND = 6; 38 static constexpr int32_t MSG_UID_STATE_BACKGROUND = 7; 39 40 NetPolicyEventHandler(const std::shared_ptr<NetPolicyCore> &core, ffrt::queue& ffrtQueue); 41 ~NetPolicyEventHandler() = default; 42 43 /** 44 * Process the event from EventHandler 45 * 46 * @param eventId The event id 47 * @param policyEvent The informations passed from other core 48 */ 49 void ProcessEvent(int32_t eventId, std::shared_ptr<PolicyEvent> eventData); 50 51 void SendEvent(const AppExecFwk::InnerEvent::Pointer &event, int64_t delayTime); 52 53 private: 54 std::shared_ptr<NetPolicyCore> core_; 55 ffrt::queue& ffrtQueue_; 56 }; 57 } // namespace NetManagerStandard 58 } // namespace OHOS 59 #endif // NET_POLICY_EVENT_HANDLER_H