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  #ifndef NET_POLICY_BASE_H
17  #define NET_POLICY_BASE_H
18  
19  #include <string>
20  #include <vector>
21  
22  #include "event_handler.h"
23  
24  #include "net_manager_center.h"
25  #include "net_policy_callback.h"
26  #include "net_policy_core.h"
27  #include "net_policy_event_handler.h"
28  #include "net_policy_file.h"
29  #include "netmanager_hitrace.h"
30  #include "netsys_policy_wrapper.h"
31  
32  namespace OHOS {
33  namespace NetManagerStandard {
34  class NetPolicyBase : public std::enable_shared_from_this<NetPolicyBase> {
35  public:
36      NetPolicyBase();
37      virtual ~NetPolicyBase();
38      virtual void Init() = 0;
39  
40      /**
41       * Handle the event from NetPolicyCore
42       *
43       * @param eventId The event id
44       * @param policyEvent The infomations passed from other core
45       */
46      virtual void HandleEvent(int32_t eventId, const std::shared_ptr<PolicyEvent> &policyEvent) = 0;
47  
48      /**
49       * Send events to other policy cores.
50       *
51       * @param eventId The event id
52       * @param delayTime The delay time, if need the message send delay
53       */
54      void SendEvent(int32_t eventId, int64_t delayTime = 0);
55  
56      /**
57       * Send events to other policy cores.
58       *
59       * @param eventId The event id
60       * @param eventData The event data
61       * @param delayTime The delay time, if need the message send delay
62       */
63      void SendEvent(int32_t eventId, std::shared_ptr<PolicyEvent> &policyEvent, int64_t delayTime = 0);
64  
65  protected:
66      std::shared_ptr<NetPolicyCallback> GetCbInst();
67      std::shared_ptr<NetPolicyFile> GetFileInst();
68      std::shared_ptr<NetsysPolicyWrapper> GetNetsysInst();
69      NetManagerCenter &GetNetCenterInst();
70  };
71  } // namespace NetManagerStandard
72  } // namespace OHOS
73  #endif // NET_POLICY_BASE_H