1 /* 2 * Copyright (c) 2025 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 NETMANAGER_BASE_NET_INTERFACE_CALLBACK_OBSERVER_H 17 #define NETMANAGER_BASE_NET_INTERFACE_CALLBACK_OBSERVER_H 18 19 #include "event_manager.h" 20 #include "napi_utils.h" 21 #include "net_interface_callback_stub.h" 22 23 namespace OHOS::NetManagerStandard { 24 class NetInterfaceCallbackObserver : public NetInterfaceStateCallbackStub { 25 public: 26 int32_t OnInterfaceAddressUpdated(const std::string &addr, const std::string &ifName, int32_t flags, 27 int32_t scope) override; 28 int32_t OnInterfaceAddressRemoved(const std::string &addr, const std::string &ifName, int32_t flags, 29 int32_t scope) override; 30 int32_t OnInterfaceAdded(const std::string &ifName) override; 31 int32_t OnInterfaceRemoved(const std::string &ifName) override; 32 int32_t OnInterfaceChanged(const std::string &ifName, bool up) override; 33 int32_t OnInterfaceLinkStateChanged(const std::string &ifName, bool up) override; 34 int32_t OnRouteChanged(bool updated, const std::string &route, const std::string &gateway, 35 const std::string &ifName) override; 36 37 private: 38 static napi_value CreateInterfaceAddressUpdateParam(napi_env env, const std::string &addr, 39 const std::string &ifName, int32_t flags, int32_t scope); 40 static napi_value CreateInterfaceUpdateParam(napi_env env, 41 const std::string &ifName); 42 static napi_value CreateInterfaceChangedParam(napi_env env, 43 const std::string &ifName, bool up); 44 static napi_value CreateRouteChangeParam(napi_env env, bool updated, 45 const std::string &route, const std::string &gateway, const std::string &ifName); 46 }; 47 } // namespace OHOS::NetManagerStandard 48 49 #endif /* NETMANAGER_BASE_NET_INTERFACE_CALLBACK_OBSERVER_H */ 50