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 ETHERNET_CLIENT_H 17 #define ETHERNET_CLIENT_H 18 19 #include <string> 20 21 #include "i_ethernet_service.h" 22 #include "interface_state_callback.h" 23 #include "parcel.h" 24 #include "singleton.h" 25 26 namespace OHOS { 27 namespace NetManagerStandard { 28 class EthernetClient { 29 DECLARE_DELAYED_SINGLETON(EthernetClient) 30 31 public: 32 /** 33 * Set the network interface configuration 34 * 35 * @param iface interface name 36 * @param ic interface configuration 37 * @return Return NETMANAGER_EXT_SUCCESS if process normal, others is error 38 * @permission ohos.permission.CONNECTIVITY_INTERNAL 39 * @systemapi Hide this for inner system use. 40 */ 41 int32_t SetIfaceConfig(const std::string &iface, sptr<InterfaceConfiguration> &ic); 42 43 /** 44 * Gets the network interface configuration parameters 45 * 46 * @param iface interface name 47 * @param ifaceConfig interface configuration 48 * @return Return NETMANAGER_EXT_SUCCESS if process normal, others is error 49 * @permission ohos.permission.CONNECTIVITY_INTERNAL 50 * @systemapi Hide this for inner system use. 51 */ 52 int32_t GetIfaceConfig(const std::string &iface, sptr<InterfaceConfiguration> &ifaceConfig); 53 54 /** 55 * check the network interface is active or not 56 * 57 * @param iface interface name 58 * @param activeStatus active status 59 * @return Return NETMANAGER_EXT_SUCCESS if process normal, others is error 60 * @permission ohos.permission.CONNECTIVITY_INTERNAL 61 * @systemapi Hide this for inner system use. 62 */ 63 int32_t IsIfaceActive(const std::string &iface, int32_t &activeStatus); 64 65 /** 66 * Gets the list of active devices 67 * 68 * @param activeIfaces list of active interface 69 * @return Return NETMANAGER_EXT_SUCCESS if process normal, others is error 70 * @permission ohos.permission.CONNECTIVITY_INTERNAL 71 * @systemapi Hide this for inner system use. 72 */ 73 int32_t GetAllActiveIfaces(std::vector<std::string> &activeIfaces); 74 75 /** 76 * Reset all configuration information 77 * 78 * @return Return NETMANAGER_EXT_SUCCESS if process normal, others is error 79 * @permission ohos.permission.CONNECTIVITY_INTERNAL 80 * @systemapi Hide this for inner system use. 81 */ 82 int32_t ResetFactory(); 83 84 /** 85 * Register the callback to monitor interface add/remove state 86 * 87 * @param callback use to receive interface add/remove event. 88 * @return Returns NETMANAGER_EXT_SUCCESS as success, other values as failure 89 * @permission ohos.permission.CONNECTIVITY_INTERNAL 90 * @systemapi Hide this for inner system use. 91 */ 92 int32_t RegisterIfacesStateChanged(const sptr<InterfaceStateCallback> &callback); 93 94 /** 95 * Cancel register the callback to monitor interface add/remove state 96 * 97 * @param callback use to receive interface add/remove event. 98 * @return Returns NETMANAGER_EXT_SUCCESS as success, other values as failure 99 * @permission ohos.permission.CONNECTIVITY_INTERNAL 100 * @systemapi Hide this for inner system use. 101 */ 102 int32_t UnregisterIfacesStateChanged(const sptr<InterfaceStateCallback> &callback); 103 104 /** 105 * Set the specified network port up 106 * 107 * @param iface interface name 108 * @return Return NETMANAGER_EXT_SUCCESS if process normal, others is error 109 * @permission ohos.permission.CONNECTIVITY_INTERNAL 110 * @systemapi Hide this for inner system use. 111 */ 112 int32_t SetInterfaceUp(const std::string &iface); 113 114 /** 115 * Set the specified network port down 116 * 117 * @param iface interface name 118 * @return Return NETMANAGER_EXT_SUCCESS if process normal, others is error 119 * @permission ohos.permission.CONNECTIVITY_INTERNAL 120 * @systemapi Hide this for inner system use. 121 */ 122 int32_t SetInterfaceDown(const std::string &iface); 123 124 /** 125 * Get the specified network port configuration 126 * 127 * @param iface interface name 128 * @param cfg interface configuration 129 * @return Return NETMANAGER_EXT_SUCCESS if process normal, others is error 130 * @permission ohos.permission.CONNECTIVITY_INTERNAL 131 * @systemapi Hide this for inner system use. 132 */ 133 int32_t GetInterfaceConfig(const std::string &iface, OHOS::nmd::InterfaceConfigurationParcel &cfg); 134 135 /** 136 * Set the specified network port configuration 137 * 138 * @param iface interface name 139 * @param cfg interface configuration 140 * @return Return NETMANAGER_EXT_SUCCESS if process normal, others is error 141 * @permission ohos.permission.CONNECTIVITY_INTERNAL 142 * @systemapi Hide this for inner system use. 143 */ 144 int32_t SetInterfaceConfig(const std::string &iface, OHOS::nmd::InterfaceConfigurationParcel &cfg); 145 146 private: 147 class EthernetDeathRecipient : public IRemoteObject::DeathRecipient { 148 public: EthernetDeathRecipient(EthernetClient & client)149 explicit EthernetDeathRecipient(EthernetClient &client) : client_(client) {} 150 ~EthernetDeathRecipient() override = default; OnRemoteDied(const wptr<IRemoteObject> & remote)151 void OnRemoteDied(const wptr<IRemoteObject> &remote) override 152 { 153 client_.OnRemoteDied(remote); 154 } 155 156 private: 157 EthernetClient &client_; 158 }; 159 160 private: 161 sptr<IEthernetService> GetProxy(); 162 void OnRemoteDied(const wptr<IRemoteObject> &remote); 163 164 private: 165 std::mutex mutex_; 166 sptr<IEthernetService> ethernetService_; 167 sptr<IRemoteObject::DeathRecipient> deathRecipient_; 168 }; 169 } // namespace NetManagerStandard 170 } // namespace OHOS 171 #endif // ETHERNET_CLIENT_H