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