1 /*
2  * Copyright (C) 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_manager_service_ipc_interface_code.h"
18 #include "dhcp_sdk_define.h"
19 #include "ipc_skeleton.h"
20 #include "rpc_errno.h"
21 #include "dhcp_logger.h"
22 DEFINE_DHCPLOG_DHCP_LABEL("DhcpServerCallbackProxyLite");
23 
24 namespace OHOS {
25 namespace DHCP {
DhcpServerCallbackProxy(SvcIdentity * sid)26 DhcpServerCallbackProxy::DhcpServerCallbackProxy(SvcIdentity *sid) : sid_(*sid)
27 {}
28 
~DhcpServerCallbackProxy()29 DhcpServerCallbackProxy::~DhcpServerCallbackProxy()
30 {
31     ReleaseSvc(sid_);
32 }
33 
OnServerStatusChanged(int status)34 void DhcpServerCallbackProxy::OnServerStatusChanged(int status)
35 {
36     DHCP_LOGI("DhcpServerCallbackProxy::OnServerStatusChanged");
37     IpcIo data;
38     uint8_t buff[DEFAULT_IPC_SIZE];
39     IpcIoInit(&data, buff, DEFAULT_IPC_SIZE, 0);
40     if (!WriteInterfaceToken(&data, DECLARE_INTERFACE_DESCRIPTOR_L1, DECLARE_INTERFACE_DESCRIPTOR_L1_LENGTH)) {
41         DHCP_LOGE("Write interface token error: %{public}s", __func__);
42         return;
43     }
44     (void)WriteInt32(&data, 0);
45     (void)WriteInt32(&data, status);
46     IpcIo reply;
47     MessageOption option;
48     MessageOptionInit(&option);
49     option.flags = TF_OP_ASYNC;
50     int ret = SendRequest(sid_, static_cast<uint32_t>(DhcpServerInterfaceCode::DHCP_SERVER_CBK_SERVER_STATUS_CHANGE),
51         &data, &reply, option, nullptr);
52     switch (ret) {
53         case ERR_NONE:
54             DHCP_LOGD("OnServerStatusChanged callback succeeded!");
55             break;
56         default: {
57             DHCP_LOGE("OnServerStatusChanged,connect done failed, error: %{public}d!", ret);
58             break;
59         }
60     }
61 }
62 
OnServerLeasesChanged(const std::string & ifname,std::vector<std::string> & leases)63 void DhcpServerCallbackProxy::OnServerLeasesChanged(const std::string& ifname, std::vector<std::string>& leases)
64 {
65     DHCP_LOGI("DhcpServerCallbackProxy::OnServerLeasesChanged");
66     return;
67 }
68 
OnServerSerExitChanged(const std::string & ifname)69 void DhcpServerCallbackProxy::OnServerSerExitChanged(const std::string& ifname)
70 {
71     DHCP_LOGI("DhcpServerCallbackProxy::OnServerSerExitChanged");
72     return;
73 }
74 
OnServerSuccess(const std::string & ifname,std::vector<DhcpStationInfo> & stationInfos)75 void DhcpServerCallbackProxy::OnServerSuccess(const std::string& ifname, std::vector<DhcpStationInfo>& stationInfos)
76 {
77     DHCP_LOGI("DhcpServerCallbackProxy::OnServerSuccess");
78     return;
79 }
80 }  // namespace DHCP
81 }  // namespace OHOS
82