• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 WRAPPER_DISTRIBUTOR_H
17 #define WRAPPER_DISTRIBUTOR_H
18 
19 #include "data_receiver.h"
20 #include "i_notify_callback.h"
21 #include "netsys_event_message.h"
22 
23 namespace OHOS {
24 namespace nmd {
25 class WrapperDistributor {
26 public:
27     WrapperDistributor(int32_t socket, const int32_t format);
28     ~WrapperDistributor() = default;
29 
30     int32_t Start();
31     int32_t Stop();
32     int32_t
33         RegisterNetlinkCallbacks(std::shared_ptr<std::vector<sptr<NetsysNative::INotifyCallback>>> netlinkCallbacks);
34 
35 private:
36     void HandleDecodeSuccess(const std::shared_ptr<NetsysEventMessage> &message);
37     void HandleStateChanged(const std::shared_ptr<NetsysEventMessage> &message);
38     void HandleAddressChange(const std::shared_ptr<NetsysEventMessage> &message);
39     void HandleRouteChange(const std::shared_ptr<NetsysEventMessage> &message);
40     void HandleSubSysNet(const std::shared_ptr<NetsysEventMessage> &message);
41     void HandleSubSysQlog(const std::shared_ptr<NetsysEventMessage> &message);
42     void NotifyInterfaceAdd(const std::string &ifName);
43     void NotifyInterfaceRemove(const std::string &ifName);
44     void NotifyInterfaceChange(const std::string &ifName, bool isUp);
45     void NotifyInterfaceLinkStateChange(const std::string &ifName, bool isUp);
46     void NotifyQuotaLimitReache(const std::string &labelName, const std::string &ifName);
47     void NotifyInterfaceAddressUpdate(const std::string &addr, const std::string &ifName, int32_t flags,
48                                       int32_t scope);
49     void NotifyInterfaceAddressRemove(const std::string &addr, const std::string &ifName, int32_t flags,
50                                       int32_t scope);
51     void NotifyRouteChange(bool updated, const std::string &route, const std::string &gateway,
52                            const std::string &ifName);
53 
54     std::unique_ptr<DataReceiver> receiver_;
55     std::shared_ptr<std::vector<sptr<NetsysNative::INotifyCallback>>> netlinkCallbacks_;
56 };
57 } // namespace nmd
58 } // namespace OHOS
59 
60 #endif // WRAPPER_DISTRIBUTOR_H
61