1 /* 2 * Copyright (c) 2021-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 INCLUDE_NETSYS_NETWORK_H 17 #define INCLUDE_NETSYS_NETWORK_H 18 19 #include <mutex> 20 #include <set> 21 #include <string> 22 23 namespace OHOS { 24 namespace nmd { 25 class NetsysNetwork { 26 public: 27 NetsysNetwork() = default; 28 virtual ~NetsysNetwork() = default; 29 30 /** 31 * Get network type 32 * 33 * @return Returns network type, it could be either 34 */ 35 virtual std::string GetNetworkType() const = 0; 36 37 /** 38 * Add an interface to a network 39 * 40 * @param interafceName The name of the interface to add 41 * 42 * @return Returns 0, successfully add an interface to a network, otherwise it will fail 43 */ 44 virtual int32_t AddInterface(std::string &) = 0; 45 46 /** 47 * Remove an interface from a network 48 * 49 * @param interafceName The name of the interface 50 * 51 * @return Returns 0, successfully remove an interface from a network, otherwise it will fail 52 */ 53 virtual int32_t RemoveInterface(std::string &) = 0; 54 55 /** 56 * Clear all interfaces 57 * 58 * @return Returns 0, successfully clear all interfaces, otherwise it will fail 59 */ 60 int32_t ClearInterfaces(); 61 62 /** 63 * Clear all interfaces 64 * 65 * @param interafceName The name of the interface 66 * 67 * @return Returns true exist interface, false otherwise 68 */ 69 bool ExistInterface(std::string &interfaceName); 70 71 /** 72 * Judge network type whether or not physical 73 * 74 * @return Returns true physical, false otherwise 75 */ IsPhysical()76 virtual bool IsPhysical() 77 { 78 return false; 79 } 80 81 /** 82 * Get all interfaces 83 * 84 * @return Returns interfaces_ 85 */ GetAllInterface()86 const std::set<std::string> &GetAllInterface() const 87 { 88 return interfaces_; 89 } 90 91 /** 92 * Get netId 93 * 94 * @return Returns netId_ 95 */ GetNetId()96 uint16_t GetNetId() const 97 { 98 return netId_; 99 } 100 101 protected: 102 explicit NetsysNetwork(uint16_t netId); 103 uint16_t netId_; 104 std::set<std::string> interfaces_; 105 std::mutex mutex_; 106 }; 107 } // namespace nmd 108 } // namespace OHOS 109 #endif // INCLUDE_NETSYS_NETWORK_H 110