• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_DHCP_CONTROLLER_H
17 #define INCLUDE_DHCP_CONTROLLER_H
18 
19 #include "dhcp_service_api.h"
20 #include "i_dhcp_result_notify.h"
21 #include "i_notify_callback.h"
22 
23 namespace OHOS {
24 namespace nmd {
25 class DhcpController {
26 public:
27     class DhcpControllerResultNotify : public OHOS::Wifi::IDhcpResultNotify {
28     public:
29         explicit DhcpControllerResultNotify(DhcpController &dhcpController);
30         virtual ~DhcpControllerResultNotify() override;
31         void OnSuccess(int status, const std::string &ifname, OHOS::Wifi::DhcpResult &result) override;
32         void OnFailed(int status, const std::string &ifname, const std::string &reason) override;
33         void OnSerExitNotify(const std::string &ifname) override;
34 
35     private:
36         DhcpController &dhcpController_;
37     };
38 
39 public:
40     DhcpController();
41     ~DhcpController();
42 
43     int32_t RegisterNotifyCallback(sptr<OHOS::NetsysNative::INotifyCallback> &callback);
44     void StartDhcpClient(const std::string &iface, bool bIpv6);
45     void StopDhcpClient(const std::string &iface, bool bIpv6);
46     bool StartDhcpService(const std::string &iface, const std::string &ipv4addr);
47     bool StopDhcpService(const std::string &iface);
48 
49     void Process(const std::string &iface, OHOS::Wifi::DhcpResult &result);
50 
51 private:
52     std::unique_ptr<DhcpControllerResultNotify> dhcpResultNotify_ = nullptr;
53     sptr<OHOS::NetsysNative::INotifyCallback> callback_ = nullptr;
54 };
55 } // namespace nmd
56 } // namespace OHOS
57 #endif // !INCLUDE_DHCP_CONTROLLER_H
58