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_SA_EVENT_H
16 #define OHOS_DHCP_SA_EVENT_H
17 
18 #include "dhcp_logger.h"
19 #ifndef OHOS_ARCH_LITE
20 #include "iremote_broker.h"
21 #include "iremote_object.h"
22 #include "iservice_registry.h"
23 #endif
24 #include <map>
25 #include "securec.h"
26 #include "dhcp_errcode.h"
27 #include "kits/c/dhcp_result_event.h"
28 #include "i_dhcp_client_callback.h"
29 #include "i_dhcp_server_callback.h"
30 #include "inner_api/include/dhcp_define.h"
31 
32 class DhcpClientCallBack : public OHOS::DHCP::IDhcpClientCallBack {
33 public:
34     DhcpClientCallBack();
35     virtual ~DhcpClientCallBack();
36 public:
37     void OnIpSuccessChanged(int status, const std::string& ifname, OHOS::DHCP::DhcpResult& result) override;
38     void OnIpFailChanged(int status, const std::string& ifname, const std::string& reason) override;
39 #ifndef OHOS_ARCH_LITE
40     void OnDhcpOfferReport(int status, const std::string& ifname, OHOS::DHCP::DhcpResult& result) override;
41     OHOS::sptr<OHOS::IRemoteObject> AsObject() override;
42 #endif
43     void RegisterCallBack(const std::string& ifname, const ClientCallBack *event);
44     void UnRegisterCallBack(const std::string& ifname);
45     void RegisterDhcpClientReportCallBack(const std::string& ifname, const DhcpClientReport *event);
46     void ResultInfoCopy(DhcpResult &dhcpResult, OHOS::DHCP::DhcpResult& result);
47     std::mutex callBackMutex;
48     std::map<std::string, const ClientCallBack *> mapClientCallBack;
49     std::mutex mapReportMutex_;
50     std::map<std::string, const DhcpClientReport *> mapDhcpClientReport_;
51 };
52 
53 class DhcpServerCallBack : public OHOS::DHCP::IDhcpServerCallBack {
54 public:
55     DhcpServerCallBack();
56     virtual ~DhcpServerCallBack();
57 public:
58     void OnServerStatusChanged(int status) override;
59     void OnServerLeasesChanged(const std::string& ifname, std::vector<std::string>& leases) override;
60     void OnServerSerExitChanged(const std::string& ifname) override;
61     void OnServerSuccess(const std::string& ifname, std::vector<DhcpStationInfo>& stationInfos) override;
62 #ifndef OHOS_ARCH_LITE
63     OHOS::sptr<OHOS::IRemoteObject> AsObject() override;
64 #endif
65     void RegisterCallBack(const std::string& ifname, const ServerCallBack *event);
66     void UnRegisterCallBack(const std::string& ifname);
67     std::mutex callBackServerMutex;
68     std::map<std::string, const ServerCallBack *> mapServerCallBack;
69 };
70 #endif