1 /*
2  * Copyright (C) 2021-2022 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 
16 #include "dhcp_server_callback_proxy.h"
17 #include "dhcp_logger.h"
18 #include "dhcp_manager_service_ipc_interface_code.h"
19 
20 DEFINE_DHCPLOG_DHCP_LABEL("DhcpServerCallbackProxy");
21 
22 namespace OHOS {
23 namespace DHCP {
DhcpServerCallbackProxy(const sptr<IRemoteObject> & impl)24 DhcpServerCallbackProxy::DhcpServerCallbackProxy(const sptr<IRemoteObject> &impl) :
25     IRemoteProxy<IDhcpServerCallBack>(impl)
26 {}
27 
~DhcpServerCallbackProxy()28 DhcpServerCallbackProxy::~DhcpServerCallbackProxy()
29 {}
30 
OnServerStatusChanged(int status)31 void DhcpServerCallbackProxy::OnServerStatusChanged(int status)
32 {
33     DHCP_LOGI("DhcpServerCallbackProxy::OnServerStatusChanged");
34     MessageOption option;
35     MessageParcel data;
36     MessageParcel reply;
37     if (!data.WriteInterfaceToken(GetDescriptor())) {
38         DHCP_LOGE("Write interface token error: %{public}s", __func__);
39         return;
40     }
41     data.WriteInt32(0);
42     data.WriteInt32(status);
43     DHCP_LOGI("start server requeset");
44     int error = Remote()->SendRequest(
45         static_cast<uint32_t>(DhcpServerInterfaceCode::DHCP_SERVER_CBK_SERVER_STATUS_CHANGE), data, reply, option);
46     if (error != ERR_NONE) {
47         DHCP_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
48             static_cast<int32_t>(DhcpServerInterfaceCode::DHCP_SERVER_CBK_SERVER_STATUS_CHANGE), error);
49         return;
50     }
51     int exception = reply.ReadInt32();
52     if (exception) {
53         DHCP_LOGE("notify wifi state change failed!");
54     }
55     DHCP_LOGI("send server request success");
56 
57     return;
58 }
59 
OnServerLeasesChanged(const std::string & ifname,std::vector<std::string> & leases)60 void DhcpServerCallbackProxy::OnServerLeasesChanged(const std::string& ifname, std::vector<std::string>& leases)
61 {
62     DHCP_LOGI("DhcpServerCallbackProxy::OnServerLeasesChanged");
63     return;
64 }
65 
OnServerSuccess(const std::string & ifname,std::vector<DhcpStationInfo> & stationInfos)66 void DhcpServerCallbackProxy::OnServerSuccess(const std::string& ifname, std::vector<DhcpStationInfo>& stationInfos)
67 {
68     DHCP_LOGI("DhcpServerCallbackProxy::OnServerSuccess");
69     MessageOption option;
70     MessageParcel data;
71     MessageParcel reply;
72     if (!data.WriteInterfaceToken(GetDescriptor())) {
73         DHCP_LOGE("Write interface token error: %{public}s", __func__);
74         return;
75     }
76     data.WriteInt32(0);
77     data.WriteInt32(stationInfos.size());
78     for (auto stationInfo: stationInfos) {
79         data.WriteString(stationInfo.deviceName);
80         data.WriteString(stationInfo.macAddr);
81         data.WriteString(stationInfo.ipAddr);
82     }
83     DHCP_LOGI("start server requeset");
84     int error = Remote()->SendRequest(
85         static_cast<uint32_t>(DhcpServerInterfaceCode::DHCP_SERVER_CBK_SERVER_SUCCESS), data, reply, option);
86     if (error != ERR_NONE) {
87         DHCP_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
88             static_cast<int32_t>(DhcpServerInterfaceCode::DHCP_SERVER_CBK_SERVER_SUCCESS), error);
89         return;
90     }
91     int exception = reply.ReadInt32();
92     if (exception) {
93         DHCP_LOGE("notify wifi state change failed!");
94         return;
95     }
96     DHCP_LOGI("send server request success");
97     return;
98 }
99 
OnServerSerExitChanged(const std::string & ifname)100 void DhcpServerCallbackProxy::OnServerSerExitChanged(const std::string& ifname)
101 {
102     DHCP_LOGI("DhcpServerCallbackProxy::OnServerSerExitChanged");
103     return;
104 }
105 
106 }  // namespace DHCP
107 }  // namespace OHOS
108