18e745fdaSopenharmony_ci/* 28e745fdaSopenharmony_ci * Copyright (C) 2022 Huawei Device Co., Ltd. 38e745fdaSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 48e745fdaSopenharmony_ci * you may not use this file except in compliance with the License. 58e745fdaSopenharmony_ci * You may obtain a copy of the License at 68e745fdaSopenharmony_ci * 78e745fdaSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 88e745fdaSopenharmony_ci * 98e745fdaSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 108e745fdaSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 118e745fdaSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 128e745fdaSopenharmony_ci * See the License for the specific language governing permissions and 138e745fdaSopenharmony_ci * limitations under the License. 148e745fdaSopenharmony_ci */ 158e745fdaSopenharmony_ci 168e745fdaSopenharmony_ci#ifndef ETHERNET_DHCP_CONTROLLER_H 178e745fdaSopenharmony_ci#define ETHERNET_DHCP_CONTROLLER_H 188e745fdaSopenharmony_ci 198e745fdaSopenharmony_ci#include <cstdint> 208e745fdaSopenharmony_ci#include <iosfwd> 218e745fdaSopenharmony_ci#include <memory> 228e745fdaSopenharmony_ci 238e745fdaSopenharmony_ci#include "ethernet_dhcp_callback.h" 248e745fdaSopenharmony_ci#include "refbase.h" 258e745fdaSopenharmony_ci#include "dhcp_c_api.h" 268e745fdaSopenharmony_ci 278e745fdaSopenharmony_cinamespace OHOS { 288e745fdaSopenharmony_cinamespace NetManagerStandard { 298e745fdaSopenharmony_ciclass EthernetDhcpController { 308e745fdaSopenharmony_cipublic: 318e745fdaSopenharmony_ci class EthernetDhcpControllerResultNotify { 328e745fdaSopenharmony_ci public: 338e745fdaSopenharmony_ci EthernetDhcpControllerResultNotify() 348e745fdaSopenharmony_ci { 358e745fdaSopenharmony_ci } 368e745fdaSopenharmony_ci ~EthernetDhcpControllerResultNotify() = default; 378e745fdaSopenharmony_ci static void OnSuccess(int status, const char *ifname, DhcpResult *result); 388e745fdaSopenharmony_ci static void OnFailed(int status, const char *ifname, const char *reason); 398e745fdaSopenharmony_ci static void SetEthernetDhcpController(EthernetDhcpController *ethDhcpController); 408e745fdaSopenharmony_ci private: 418e745fdaSopenharmony_ci static EthernetDhcpController *ethDhcpController_; 428e745fdaSopenharmony_ci }; 438e745fdaSopenharmony_cipublic: 448e745fdaSopenharmony_ci EthernetDhcpController() : dhcpResultNotify_(std::make_unique<EthernetDhcpControllerResultNotify>()) 458e745fdaSopenharmony_ci { 468e745fdaSopenharmony_ci clientEvent.OnIpSuccessChanged = EthernetDhcpControllerResultNotify::OnSuccess; 478e745fdaSopenharmony_ci clientEvent.OnIpFailChanged = EthernetDhcpControllerResultNotify::OnFailed; 488e745fdaSopenharmony_ci } 498e745fdaSopenharmony_ci ~EthernetDhcpController() = default; 508e745fdaSopenharmony_ci void RegisterDhcpCallback(sptr<EthernetDhcpCallback> callback); 518e745fdaSopenharmony_ci void StartClient(const std::string &iface, bool bIpv6); 528e745fdaSopenharmony_ci void StopClient(const std::string &iface, bool bIpv6); 538e745fdaSopenharmony_ciprivate: 548e745fdaSopenharmony_ci void OnDhcpSuccess(const std::string &iface, DhcpResult *result); 558e745fdaSopenharmony_ci void OnDhcpFailed(int status, const std::string &ifname, const char *reason); 568e745fdaSopenharmony_ciprivate: 578e745fdaSopenharmony_ci ClientCallBack clientEvent; 588e745fdaSopenharmony_ci std::unique_ptr<EthernetDhcpControllerResultNotify> dhcpResultNotify_ = nullptr; 598e745fdaSopenharmony_ci sptr<EthernetDhcpCallback> cbObject_ = nullptr; 608e745fdaSopenharmony_ci}; 618e745fdaSopenharmony_ci} // namespace NetManagerStandard 628e745fdaSopenharmony_ci} // namespace OHOS 638e745fdaSopenharmony_ci#endif // ETHERNET_DHCP_CONTROLLER_H