1 /* 2 * Copyright (C) 2021-2023 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 #ifndef OHOS_DHCP_SERVER_IMPL_H 16 #define OHOS_DHCP_SERVER_IMPL_H 17 18 #include <string> 19 #include "singleton.h" 20 #include "i_dhcp_server.h" 21 #include "i_dhcp_server_callback.h" 22 #include "inner_api/include/dhcp_define.h" 23 #include "inner_api/dhcp_server.h" 24 25 namespace OHOS { 26 namespace DHCP { 27 class DhcpServerImpl : public DhcpServer { 28 DECLARE_DELAYED_SINGLETON(DhcpServerImpl); 29 public: 30 bool Init(int systemAbilityId); 31 bool IsRemoteDied(); 32 #ifdef OHOS_ARCH_LITE 33 ErrCode RegisterDhcpServerCallBack(const std::string& ifname, 34 const std::shared_ptr<IDhcpServerCallBack> &callback) override; 35 #else 36 ErrCode RegisterDhcpServerCallBack(const std::string& ifname, 37 const sptr<IDhcpServerCallBack> &callback) override; 38 #endif 39 ErrCode StartDhcpServer(const std::string& ifname) override; 40 ErrCode StopDhcpServer(const std::string& ifname) override; 41 ErrCode PutDhcpRange(const std::string& tagName, const DhcpRange& range) override; 42 ErrCode RemoveDhcpRange(const std::string& tagName, const DhcpRange& range) override; 43 ErrCode RemoveAllDhcpRange(const std::string& tagName) override; 44 ErrCode SetDhcpRange(const std::string& ifname, const DhcpRange& range) override; 45 ErrCode SetDhcpName(const std::string& ifname, const std::string& tagName) override; 46 ErrCode GetDhcpClientInfos(const std::string& ifname, std::vector<std::string>& dhcpClientInfo) override; 47 ErrCode UpdateLeasesTime(const std::string& leaseTime) override; 48 private: 49 bool GetDhcpServerProxy(); 50 int systemAbilityId_; 51 std::mutex mutex_; 52 #ifdef OHOS_ARCH_LITE 53 std::shared_ptr<IDhcpServer> client_; 54 #else 55 sptr<IDhcpServer> client_; 56 #endif 57 }; 58 } // namespace DHCP 59 } // namespace OHOS 60 #endif 61