1518678f8Sopenharmony_ci/*
2518678f8Sopenharmony_ci * Copyright (C) 2021 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
16518678f8Sopenharmony_ci#ifndef OHOS_DHCP_CLIENT_STUB_H
17518678f8Sopenharmony_ci#define OHOS_DHCP_CLIENT_STUB_H
18518678f8Sopenharmony_ci
19518678f8Sopenharmony_ci#include <map>
20518678f8Sopenharmony_ci#include <string_ex.h>
21518678f8Sopenharmony_ci#ifndef OHOS_ARCH_LITE
22518678f8Sopenharmony_ci#include "iremote_stub.h"
23518678f8Sopenharmony_ci#include <iremote_broker.h>
24518678f8Sopenharmony_ci#include "message_parcel.h"
25518678f8Sopenharmony_ci#include "message_option.h"
26518678f8Sopenharmony_ci#endif
27518678f8Sopenharmony_ci#include "i_dhcp_client.h"
28518678f8Sopenharmony_ci#include "dhcp_client_callback_stub.h"
29518678f8Sopenharmony_ci
30518678f8Sopenharmony_cinamespace OHOS {
31518678f8Sopenharmony_cinamespace DHCP {
32518678f8Sopenharmony_ciclass DhcpClientStub : public IRemoteStub<IDhcpClient> {
33518678f8Sopenharmony_cipublic:
34518678f8Sopenharmony_ci    using handleFunc = std::function<int(uint32_t &, MessageParcel &, MessageParcel &, MessageOption &)>;
35518678f8Sopenharmony_ci    using HandleFuncMap = std::map<int, handleFunc>;
36518678f8Sopenharmony_ci    using RemoteDeathMap = std::map<sptr<IRemoteObject>, sptr<IRemoteObject::DeathRecipient>>;
37518678f8Sopenharmony_ci    DhcpClientStub();
38518678f8Sopenharmony_ci
39518678f8Sopenharmony_ci    virtual ~DhcpClientStub();
40518678f8Sopenharmony_ci    virtual int OnRemoteRequest(
41518678f8Sopenharmony_ci        uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option);
42518678f8Sopenharmony_ciprivate:
43518678f8Sopenharmony_ci    void InitHandleMap(void);
44518678f8Sopenharmony_ci    int OnRegisterCallBack(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option);
45518678f8Sopenharmony_ci    int OnStartDhcpClient(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option);
46518678f8Sopenharmony_ci    int OnSetConfiguration(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option);
47518678f8Sopenharmony_ci    int OnStopDhcpClient(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option);
48518678f8Sopenharmony_ci#ifndef OHOS_ARCH_LITE
49518678f8Sopenharmony_cipublic:
50518678f8Sopenharmony_ci    class ClientDeathRecipient : public IRemoteObject::DeathRecipient {
51518678f8Sopenharmony_ci    public:
52518678f8Sopenharmony_ci        explicit ClientDeathRecipient(DhcpClientStub &client) : client_(client) {}
53518678f8Sopenharmony_ci        ~ClientDeathRecipient() override = default;
54518678f8Sopenharmony_ci        virtual void OnRemoteDied(const wptr<IRemoteObject>& remote) override
55518678f8Sopenharmony_ci        {
56518678f8Sopenharmony_ci            client_.OnRemoteDied(remote);
57518678f8Sopenharmony_ci        }
58518678f8Sopenharmony_ci    private:
59518678f8Sopenharmony_ci        DhcpClientStub &client_;
60518678f8Sopenharmony_ci    };
61518678f8Sopenharmony_ci    void OnRemoteDied(const wptr<IRemoteObject> &remoteObject);
62518678f8Sopenharmony_ci    void RemoveDeviceCbDeathRecipient(void);
63518678f8Sopenharmony_ci    void RemoveDeviceCbDeathRecipient(const wptr<IRemoteObject> &remoteObject);
64518678f8Sopenharmony_ci
65518678f8Sopenharmony_ci    RemoteDeathMap remoteDeathMap;
66518678f8Sopenharmony_ci    std::mutex mutex_;
67518678f8Sopenharmony_ci#endif
68518678f8Sopenharmony_ciprivate:
69518678f8Sopenharmony_ci    HandleFuncMap handleFuncMap;
70518678f8Sopenharmony_ci    sptr<IRemoteObject::DeathRecipient> deathRecipient_;
71518678f8Sopenharmony_ci};
72518678f8Sopenharmony_ci}  // namespace DHCP
73518678f8Sopenharmony_ci}  // namespace OHOS
74518678f8Sopenharmony_ci#endif