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_CLIENT_PROXY_H 16 #define OHOS_DHCP_CLIENT_PROXY_H 17 18 #ifdef OHOS_ARCH_LITE 19 #include "iproxy_client.h" 20 #include "serializer.h" 21 #else 22 #include "iremote_proxy.h" 23 #endif 24 #include <string> 25 #include "i_dhcp_client.h" 26 #include "i_dhcp_client_callback.h" 27 #include "inner_api/dhcp_client.h" 28 29 namespace OHOS { 30 namespace DHCP { 31 #ifdef OHOS_ARCH_LITE 32 class DhcpClientProxy : public IDhcpClient { 33 public: 34 static DhcpClientProxy *GetInstance(void); 35 static void ReleaseInstance(void); 36 explicit DhcpClientProxy(); 37 #else 38 class DhcpClientProxy : public IRemoteProxy<IDhcpClient> { 39 public: 40 explicit DhcpClientProxy(const sptr<IRemoteObject> &impl); 41 #endif 42 ~DhcpClientProxy(); 43 44 #ifdef OHOS_ARCH_LITE 45 ErrCode RegisterDhcpClientCallBack(const std::string& ifname, 46 const std::shared_ptr<IDhcpClientCallBack> &callback) override; 47 #else 48 ErrCode RegisterDhcpClientCallBack(const std::string& ifname, const sptr<IDhcpClientCallBack> &callback) override; 49 #endif 50 ErrCode StartDhcpClient(const std::string& ifname, bool bIpv6) override; 51 ErrCode SetConfiguration(const std::string& ifname, const RouterConfig& config) override; 52 ErrCode StopDhcpClient(const std::string& ifname, bool bIpv6) override; 53 bool IsRemoteDied() override; 54 #ifdef OHOS_ARCH_LITE 55 void OnRemoteDied(void); 56 private: 57 static DhcpClientProxy *g_instance; 58 IClientProxy *remote_ = nullptr; 59 SvcIdentity svcIdentity_ = { 0 }; 60 bool remoteDied_; 61 #else 62 private: 63 class DhcpClientDeathRecipient : public IRemoteObject::DeathRecipient { 64 public: DhcpClientDeathRecipient(DhcpClientProxy & client)65 explicit DhcpClientDeathRecipient(DhcpClientProxy &client) : client_(client) {} 66 ~DhcpClientDeathRecipient() override = default; OnRemoteDied(const wptr<IRemoteObject> & remote)67 void OnRemoteDied(const wptr<IRemoteObject> &remote) override 68 { 69 client_.OnRemoteDied(remote); 70 } 71 72 private: 73 DhcpClientProxy &client_; 74 }; 75 void OnRemoteDied(const wptr<IRemoteObject> &remoteObject); 76 void RemoveDeathRecipient(void); 77 78 static inline BrokerDelegator<DhcpClientProxy> delegator_; 79 sptr<IRemoteObject> remote_ = nullptr; 80 bool mRemoteDied; 81 std::mutex mutex_; 82 sptr<IRemoteObject::DeathRecipient> deathRecipient_ = nullptr; 83 #endif 84 }; 85 } // namespace DHCP 86 } // namespace OHOS 87 #endif 88