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