• 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_SERVER_PROXY_H
16 #define OHOS_DHCP_SERVER_PROXY_H
17 
18 #include <string>
19 #ifdef OHOS_ARCH_LITE
20 #include "iproxy_client.h"
21 #else
22 #include "iremote_proxy.h"
23 #endif
24 #include "i_dhcp_server.h"
25 #include "i_dhcp_server_callback.h"
26 #include "inner_api/dhcp_server.h"
27 
28 namespace OHOS {
29 namespace DHCP {
30 #ifdef OHOS_ARCH_LITE
31 class DhcpServerProxy : public IDhcpServer {
32 public:
33     static DhcpServerProxy *GetInstance(void);
34     static void ReleaseInstance(void);
35     explicit DhcpServerProxy(void);
36     ErrCode Init(void);
37 #else
38 class DhcpServerProxy : public IRemoteProxy<IDhcpServer> {
39 public:
40     explicit DhcpServerProxy(const sptr<IRemoteObject> &impl);
41 #endif
42     ~DhcpServerProxy();
43 #ifdef OHOS_ARCH_LITE
44     ErrCode RegisterDhcpServerCallBack(const std::string& ifname,
45         const std::shared_ptr<IDhcpServerCallBack> &callback) override;
46 #else
47     ErrCode RegisterDhcpServerCallBack(const std::string& ifname, const sptr<IDhcpServerCallBack> &callback) override;
48 #endif
49     ErrCode StartDhcpServer(const std::string& ifname) override;
50     ErrCode StopDhcpServer(const std::string& ifname) override;
51     ErrCode PutDhcpRange(const std::string& tagName, const DhcpRange& range) override;
52     ErrCode RemoveDhcpRange(const std::string& tagName, const DhcpRange& range) override;
53     ErrCode RemoveAllDhcpRange(const std::string& tagName) override;
54     ErrCode SetDhcpRange(const std::string& ifname, const DhcpRange& range) override;
55     ErrCode SetDhcpName(const std::string& ifname, const std::string& tagName) override;
56     ErrCode GetDhcpClientInfos(const std::string& ifname, std::vector<std::string>& dhcpClientInfo) override;
57     ErrCode UpdateLeasesTime(const std::string& leaseTime) override;
58     bool IsRemoteDied() override;
59     ErrCode StopServerSa(void) override;
60 
61 #ifdef OHOS_ARCH_LITE
62     void OnRemoteDied(void);
63 private:
64     static DhcpServerProxy *g_instance;
65     IClientProxy *remote_ = nullptr;
66     SvcIdentity svcIdentity_ = { 0 };
67     bool remoteDied_;
68 #else
69 private:
70     class DhcpServerDeathRecipient : public IRemoteObject::DeathRecipient {
71     public:
DhcpServerDeathRecipient(DhcpServerProxy & client)72         explicit DhcpServerDeathRecipient(DhcpServerProxy &client) : client_(client) {}
73         ~DhcpServerDeathRecipient() override = default;
OnRemoteDied(const wptr<IRemoteObject> & remote)74         void OnRemoteDied(const wptr<IRemoteObject> &remote) override
75         {
76             client_.OnRemoteDied(remote);
77         }
78 
79     private:
80         DhcpServerProxy &client_;
81     };
82     void OnRemoteDied(const wptr<IRemoteObject> &remoteObject);
83     void RemoveDeathRecipient(void);
84 
85     static inline BrokerDelegator<DhcpServerProxy> delegator_;
86     sptr<IRemoteObject> remote_ = nullptr;
87     bool mRemoteDied;
88     std::mutex mutex_;
89     sptr<IRemoteObject::DeathRecipient> deathRecipient_ = nullptr;
90 #endif
91 };
92 }  // namespace DHCP
93 }  // namespace OHOS
94 #endif
95