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_SA_EVENT_H
16518678f8Sopenharmony_ci#define OHOS_DHCP_SA_EVENT_H
17518678f8Sopenharmony_ci
18518678f8Sopenharmony_ci#include "dhcp_logger.h"
19518678f8Sopenharmony_ci#ifndef OHOS_ARCH_LITE
20518678f8Sopenharmony_ci#include "iremote_broker.h"
21518678f8Sopenharmony_ci#include "iremote_object.h"
22518678f8Sopenharmony_ci#include "iservice_registry.h"
23518678f8Sopenharmony_ci#endif
24518678f8Sopenharmony_ci#include <map>
25518678f8Sopenharmony_ci#include "securec.h"
26518678f8Sopenharmony_ci#include "dhcp_errcode.h"
27518678f8Sopenharmony_ci#include "kits/c/dhcp_result_event.h"
28518678f8Sopenharmony_ci#include "i_dhcp_client_callback.h"
29518678f8Sopenharmony_ci#include "i_dhcp_server_callback.h"
30518678f8Sopenharmony_ci#include "inner_api/include/dhcp_define.h"
31518678f8Sopenharmony_ci
32518678f8Sopenharmony_ciclass DhcpClientCallBack : public OHOS::DHCP::IDhcpClientCallBack {
33518678f8Sopenharmony_cipublic:
34518678f8Sopenharmony_ci    DhcpClientCallBack();
35518678f8Sopenharmony_ci    virtual ~DhcpClientCallBack();
36518678f8Sopenharmony_cipublic:
37518678f8Sopenharmony_ci    void OnIpSuccessChanged(int status, const std::string& ifname, OHOS::DHCP::DhcpResult& result) override;
38518678f8Sopenharmony_ci    void OnIpFailChanged(int status, const std::string& ifname, const std::string& reason) override;
39518678f8Sopenharmony_ci#ifndef OHOS_ARCH_LITE
40518678f8Sopenharmony_ci    void OnDhcpOfferReport(int status, const std::string& ifname, OHOS::DHCP::DhcpResult& result) override;
41518678f8Sopenharmony_ci    OHOS::sptr<OHOS::IRemoteObject> AsObject() override;
42518678f8Sopenharmony_ci#endif
43518678f8Sopenharmony_ci    void RegisterCallBack(const std::string& ifname, const ClientCallBack *event);
44518678f8Sopenharmony_ci    void UnRegisterCallBack(const std::string& ifname);
45518678f8Sopenharmony_ci    void RegisterDhcpClientReportCallBack(const std::string& ifname, const DhcpClientReport *event);
46518678f8Sopenharmony_ci    void ResultInfoCopy(DhcpResult &dhcpResult, OHOS::DHCP::DhcpResult& result);
47518678f8Sopenharmony_ci    std::mutex callBackMutex;
48518678f8Sopenharmony_ci    std::map<std::string, const ClientCallBack *> mapClientCallBack;
49518678f8Sopenharmony_ci    std::mutex mapReportMutex_;
50518678f8Sopenharmony_ci    std::map<std::string, const DhcpClientReport *> mapDhcpClientReport_;
51518678f8Sopenharmony_ci};
52518678f8Sopenharmony_ci
53518678f8Sopenharmony_ciclass DhcpServerCallBack : public OHOS::DHCP::IDhcpServerCallBack {
54518678f8Sopenharmony_cipublic:
55518678f8Sopenharmony_ci    DhcpServerCallBack();
56518678f8Sopenharmony_ci    virtual ~DhcpServerCallBack();
57518678f8Sopenharmony_cipublic:
58518678f8Sopenharmony_ci    void OnServerStatusChanged(int status) override;
59518678f8Sopenharmony_ci    void OnServerLeasesChanged(const std::string& ifname, std::vector<std::string>& leases) override;
60518678f8Sopenharmony_ci    void OnServerSerExitChanged(const std::string& ifname) override;
61518678f8Sopenharmony_ci    void OnServerSuccess(const std::string& ifname, std::vector<DhcpStationInfo>& stationInfos) override;
62518678f8Sopenharmony_ci#ifndef OHOS_ARCH_LITE
63518678f8Sopenharmony_ci    OHOS::sptr<OHOS::IRemoteObject> AsObject() override;
64518678f8Sopenharmony_ci#endif
65518678f8Sopenharmony_ci    void RegisterCallBack(const std::string& ifname, const ServerCallBack *event);
66518678f8Sopenharmony_ci    void UnRegisterCallBack(const std::string& ifname);
67518678f8Sopenharmony_ci    std::mutex callBackServerMutex;
68518678f8Sopenharmony_ci    std::map<std::string, const ServerCallBack *> mapServerCallBack;
69518678f8Sopenharmony_ci};
70518678f8Sopenharmony_ci#endif