1518678f8Sopenharmony_ci/*
2518678f8Sopenharmony_ci * Copyright (C) 2021-2023 Huawei Device Co., Ltd.
3518678f8Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4518678f8Sopenharmony_ci * you may not use this file except in compliance with the License.
5518678f8Sopenharmony_ci * You may obtain a copy of the License at
6518678f8Sopenharmony_ci *
7518678f8Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8518678f8Sopenharmony_ci *
9518678f8Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10518678f8Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11518678f8Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12518678f8Sopenharmony_ci * See the License for the specific language governing permissions and
13518678f8Sopenharmony_ci * limitations under the License.
14518678f8Sopenharmony_ci */
15518678f8Sopenharmony_ci#ifndef OHOS_DHCP_SERVER_PROXY_H
16518678f8Sopenharmony_ci#define OHOS_DHCP_SERVER_PROXY_H
17518678f8Sopenharmony_ci
18518678f8Sopenharmony_ci#include <string>
19518678f8Sopenharmony_ci#ifdef OHOS_ARCH_LITE
20518678f8Sopenharmony_ci#include "iproxy_client.h"
21518678f8Sopenharmony_ci#else
22518678f8Sopenharmony_ci#include "iremote_proxy.h"
23518678f8Sopenharmony_ci#endif
24518678f8Sopenharmony_ci#include "i_dhcp_server.h"
25518678f8Sopenharmony_ci#include "i_dhcp_server_callback.h"
26518678f8Sopenharmony_ci#include "inner_api/dhcp_server.h"
27518678f8Sopenharmony_ci
28518678f8Sopenharmony_cinamespace OHOS {
29518678f8Sopenharmony_cinamespace DHCP {
30518678f8Sopenharmony_ci#ifdef OHOS_ARCH_LITE
31518678f8Sopenharmony_ciclass DhcpServerProxy : public IDhcpServer {
32518678f8Sopenharmony_cipublic:
33518678f8Sopenharmony_ci    static DhcpServerProxy *GetInstance(void);
34518678f8Sopenharmony_ci    static void ReleaseInstance(void);
35518678f8Sopenharmony_ci    explicit DhcpServerProxy(void);
36518678f8Sopenharmony_ci    ErrCode Init(void);
37518678f8Sopenharmony_ci#else
38518678f8Sopenharmony_ciclass DhcpServerProxy : public IRemoteProxy<IDhcpServer> {
39518678f8Sopenharmony_cipublic:
40518678f8Sopenharmony_ci    explicit DhcpServerProxy(const sptr<IRemoteObject> &impl);
41518678f8Sopenharmony_ci#endif
42518678f8Sopenharmony_ci    ~DhcpServerProxy();
43518678f8Sopenharmony_ci#ifdef OHOS_ARCH_LITE
44518678f8Sopenharmony_ci    ErrCode RegisterDhcpServerCallBack(const std::string& ifname,
45518678f8Sopenharmony_ci        const std::shared_ptr<IDhcpServerCallBack> &callback) override;
46518678f8Sopenharmony_ci#else
47518678f8Sopenharmony_ci    ErrCode RegisterDhcpServerCallBack(const std::string& ifname, const sptr<IDhcpServerCallBack> &callback) override;
48518678f8Sopenharmony_ci#endif
49518678f8Sopenharmony_ci    ErrCode StartDhcpServer(const std::string& ifname) override;
50518678f8Sopenharmony_ci    ErrCode StopDhcpServer(const std::string& ifname) override;
51518678f8Sopenharmony_ci    ErrCode PutDhcpRange(const std::string& tagName, const DhcpRange& range) override;
52518678f8Sopenharmony_ci    ErrCode RemoveDhcpRange(const std::string& tagName, const DhcpRange& range) override;
53518678f8Sopenharmony_ci    ErrCode RemoveAllDhcpRange(const std::string& tagName) override;
54518678f8Sopenharmony_ci    ErrCode SetDhcpRange(const std::string& ifname, const DhcpRange& range) override;
55518678f8Sopenharmony_ci    ErrCode SetDhcpName(const std::string& ifname, const std::string& tagName) override;
56518678f8Sopenharmony_ci    ErrCode GetDhcpClientInfos(const std::string& ifname, std::vector<std::string>& dhcpClientInfo) override;
57518678f8Sopenharmony_ci    ErrCode UpdateLeasesTime(const std::string& leaseTime) override;
58518678f8Sopenharmony_ci    bool IsRemoteDied() override;
59518678f8Sopenharmony_ci
60518678f8Sopenharmony_ci#ifdef OHOS_ARCH_LITE
61518678f8Sopenharmony_ci    void OnRemoteDied(void);
62518678f8Sopenharmony_ciprivate:
63518678f8Sopenharmony_ci    static DhcpServerProxy *g_instance;
64518678f8Sopenharmony_ci    IClientProxy *remote_ = nullptr;
65518678f8Sopenharmony_ci    SvcIdentity svcIdentity_ = { 0 };
66518678f8Sopenharmony_ci    bool remoteDied_;
67518678f8Sopenharmony_ci#else
68518678f8Sopenharmony_ciprivate:
69518678f8Sopenharmony_ci    class DhcpServerDeathRecipient : public IRemoteObject::DeathRecipient {
70518678f8Sopenharmony_ci    public:
71518678f8Sopenharmony_ci        explicit DhcpServerDeathRecipient(DhcpServerProxy &client) : client_(client) {}
72518678f8Sopenharmony_ci        ~DhcpServerDeathRecipient() override = default;
73518678f8Sopenharmony_ci        void OnRemoteDied(const wptr<IRemoteObject> &remote) override
74518678f8Sopenharmony_ci        {
75518678f8Sopenharmony_ci            client_.OnRemoteDied(remote);
76518678f8Sopenharmony_ci        }
77518678f8Sopenharmony_ci
78518678f8Sopenharmony_ci    private:
79518678f8Sopenharmony_ci        DhcpServerProxy &client_;
80518678f8Sopenharmony_ci    };
81518678f8Sopenharmony_ci    void OnRemoteDied(const wptr<IRemoteObject> &remoteObject);
82518678f8Sopenharmony_ci    void RemoveDeathRecipient(void);
83518678f8Sopenharmony_ci
84518678f8Sopenharmony_ci    static inline BrokerDelegator<DhcpServerProxy> delegator_;
85518678f8Sopenharmony_ci    sptr<IRemoteObject> remote_ = nullptr;
86518678f8Sopenharmony_ci    bool mRemoteDied;
87518678f8Sopenharmony_ci    std::mutex mutex_;
88518678f8Sopenharmony_ci    sptr<IRemoteObject::DeathRecipient> deathRecipient_ = nullptr;
89518678f8Sopenharmony_ci#endif
90518678f8Sopenharmony_ci};
91518678f8Sopenharmony_ci}  // namespace DHCP
92518678f8Sopenharmony_ci}  // namespace OHOS
93518678f8Sopenharmony_ci#endif
94