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 "i_notify_callback.h"
20 #include "dhcp_c_api.h"
21 
22 namespace OHOS {
23 namespace nmd {
24 class DhcpController {
25 public:
26     class DhcpControllerResultNotify {
27     public:
28         explicit DhcpControllerResultNotify();
29         ~DhcpControllerResultNotify();
30         static void OnSuccess(int status, const char *ifname, DhcpResult *result);
31         static void OnFailed(int status, const char *ifname, const char *reason);
32         static void SetDhcpController(DhcpController *dhcpController);
33     private:
34         static DhcpController *dhcpController_;
35     };
36 
37 public:
38     DhcpController();
39     ~DhcpController();
40 
41     int32_t RegisterNotifyCallback(sptr<OHOS::NetsysNative::INotifyCallback> &callback);
42     void StartClient(const std::string &iface, bool bIpv6);
43     void StopClient(const std::string &iface, bool bIpv6);
44     bool StartDhcpService(const std::string &iface, const std::string &ipv4addr);
45     bool StopDhcpService(const std::string &iface);
46 
47     void Process(const std::string &iface, DhcpResult *result);
48 
49 private:
50     ClientCallBack clientEvent;
51     std::unique_ptr<DhcpControllerResultNotify> dhcpResultNotify_ = nullptr;
52     sptr<OHOS::NetsysNative::INotifyCallback> callback_ = nullptr;
53 };
54 } // namespace nmd
55 } // namespace OHOS
56 #endif // !INCLUDE_DHCP_CONTROLLER_H
57