• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 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_DHCP_CONTROLLER_H
17 #define ETHERNET_DHCP_CONTROLLER_H
18 
19 #include <cstdint>
20 #include <iosfwd>
21 #include <memory>
22 
23 #include "dhcp_service.h"
24 #include "ethernet_dhcp_callback.h"
25 #include "i_dhcp_result_notify.h"
26 #include "i_dhcp_service.h"
27 #include "refbase.h"
28 
29 namespace OHOS {
30 namespace NetManagerStandard {
31 class EthernetDhcpController {
32 public:
33     class EthernetDhcpControllerResultNotify : public OHOS::Wifi::IDhcpResultNotify {
34     public:
EthernetDhcpControllerResultNotify(EthernetDhcpController & dhcpController)35         explicit EthernetDhcpControllerResultNotify(EthernetDhcpController &dhcpController)
36             : ethDhcpController_(dhcpController)
37         {
38         }
39 
40         ~EthernetDhcpControllerResultNotify() = default;
41         void OnSuccess(int status, const std::string &ifname, OHOS::Wifi::DhcpResult &result) override;
42         void OnFailed(int status, const std::string &ifname, const std::string &reason) override;
43         void OnSerExitNotify(const std::string &ifname) override;
44 
45     private:
46         EthernetDhcpController &ethDhcpController_;
47     };
48 
49 public:
EthernetDhcpController()50     EthernetDhcpController()
51         : dhcpService_(std::make_unique<OHOS::Wifi::DhcpService>()),
52           dhcpResultNotify_(std::make_unique<EthernetDhcpControllerResultNotify>(*this))
53     {
54     }
55     ~EthernetDhcpController() = default;
56 
57     void RegisterDhcpCallback(sptr<EthernetDhcpCallback> callback);
58     void StartDhcpClient(const std::string &iface, bool bIpv6);
59     void StopDhcpClient(const std::string &iface, bool bIpv6);
60 
61 private:
62     void OnDhcpSuccess(const std::string &iface, OHOS::Wifi::DhcpResult &result);
63     void OnDhcpFailed(int status, const std::string &ifname, const std::string &reason);
64 
65 private:
66     std::unique_ptr<OHOS::Wifi::IDhcpService> dhcpService_ = nullptr;
67     std::unique_ptr<EthernetDhcpControllerResultNotify> dhcpResultNotify_ = nullptr;
68     sptr<EthernetDhcpCallback> cbObject_ = nullptr;
69 };
70 } // namespace NetManagerStandard
71 } // namespace OHOS
72 #endif // ETHERNET_DHCP_CONTROLLER_H