1 /*
2 * Copyright (c) 2022 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 "net_policy_base.h"
17
18 #include "net_policy_event_handler.h"
19
20 namespace OHOS {
21 namespace NetManagerStandard {
22 NetPolicyBase::NetPolicyBase() = default;
23
24 NetPolicyBase::~NetPolicyBase() = default;
25
GetCbInst()26 std::shared_ptr<NetPolicyCallback> NetPolicyBase::GetCbInst()
27 {
28 return DelayedSingleton<NetPolicyCallback>::GetInstance();
29 }
30
GetFileInst()31 std::shared_ptr<NetPolicyFile> NetPolicyBase::GetFileInst()
32 {
33 return DelayedSingleton<NetPolicyFile>::GetInstance();
34 }
35
GetNetsysInst()36 std::shared_ptr<NetsysPolicyWrapper> NetPolicyBase::GetNetsysInst()
37 {
38 return DelayedSingleton<NetsysPolicyWrapper>::GetInstance();
39 }
40
GetNetCenterInst()41 NetManagerCenter &NetPolicyBase::GetNetCenterInst()
42 {
43 return NetManagerCenter::GetInstance();
44 }
45
SendEvent(int32_t eventId,int64_t delayTime)46 void NetPolicyBase::SendEvent(int32_t eventId, int64_t delayTime)
47 {
48 std::shared_ptr<PolicyEvent> policyEvent = std::make_shared<PolicyEvent>();
49 SendEvent(eventId, policyEvent, delayTime);
50 }
51
SendEvent(int32_t eventId,std::shared_ptr<PolicyEvent> & policyEvent,int64_t delayTime)52 void NetPolicyBase::SendEvent(int32_t eventId, std::shared_ptr<PolicyEvent> &policyEvent, int64_t delayTime)
53 {
54 policyEvent->eventId = eventId;
55 policyEvent->sender = shared_from_this();
56 DelayedSingleton<NetPolicyCore>::GetInstance()->SendEvent(eventId, policyEvent, delayTime);
57 }
58 } // namespace NetManagerStandard
59 } // namespace OHOS
60