• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 RouterConfig &config) override;
51     ErrCode DealWifiDhcpCache(int32_t cmd, const IpCacheInfo &ipCacheInfo) override;
52     ErrCode StopDhcpClient(const std::string& ifname, bool bIpv6, bool bIpv4 = true) override;
53     bool IsRemoteDied() override;
54     ErrCode StopClientSa(void) override;
55 #ifdef OHOS_ARCH_LITE
56     void OnRemoteDied(void);
57 private:
58     static DhcpClientProxy *g_instance;
59     IClientProxy *remote_ = nullptr;
60     SvcIdentity svcIdentity_ = { 0 };
61     bool remoteDied_;
62 #else
63 private:
64     class DhcpClientDeathRecipient : public IRemoteObject::DeathRecipient {
65     public:
DhcpClientDeathRecipient(DhcpClientProxy & client)66         explicit DhcpClientDeathRecipient(DhcpClientProxy &client) : client_(client) {}
67         ~DhcpClientDeathRecipient() override = default;
OnRemoteDied(const wptr<IRemoteObject> & remote)68         void OnRemoteDied(const wptr<IRemoteObject> &remote) override
69         {
70             client_.OnRemoteDied(remote);
71         }
72 
73     private:
74         DhcpClientProxy &client_;
75     };
76     void OnRemoteDied(const wptr<IRemoteObject> &remoteObject);
77     void RemoveDeathRecipient(void);
78 
79     static inline BrokerDelegator<DhcpClientProxy> delegator_;
80     sptr<IRemoteObject> remote_ = nullptr;
81     bool mRemoteDied;
82     std::mutex mutex_;
83     sptr<IRemoteObject::DeathRecipient> deathRecipient_ = nullptr;
84 #endif
85 };
86 }  // namespace DHCP
87 }  // namespace OHOS
88 #endif
89