1 /*
2 * Copyright (c) 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
16 #include "net_dns_result_callback_proxy.h"
17 #include "net_manager_constants.h"
18 #include "netnative_log_wrapper.h"
19 #include "netsys_ipc_interface_code.h"
20
21 namespace OHOS {
22 namespace NetsysNative {
23 namespace {
24 using namespace OHOS::NetManagerStandard;
25 } // namespace
26
NetDnsResultCallbackProxy(const sptr<IRemoteObject> & impl)27 NetDnsResultCallbackProxy::NetDnsResultCallbackProxy(const sptr<IRemoteObject> &impl)
28 : IRemoteProxy<INetDnsResultCallback>(impl) {}
29
OnDnsResultReport(uint32_t listsize,const std::list<NetDnsResultReport> dnsResultReport)30 int32_t NetDnsResultCallbackProxy::OnDnsResultReport(uint32_t listsize,
31 const std::list<NetDnsResultReport> dnsResultReport)
32 {
33 NETNATIVE_LOG_D("Proxy OnDnsResultReport");
34 MessageParcel data;
35 if (!data.WriteInterfaceToken(NetDnsResultCallbackProxy::GetDescriptor())) {
36 NETNATIVE_LOGE("WriteInterfaceToken failed");
37 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
38 }
39
40 uint32_t size = listsize;
41 if (!data.WriteUint32(size)) {
42 return false;
43 }
44
45 if (size > 0) {
46 for (NetDnsResultReport report: dnsResultReport) {
47 if (!report.Marshalling(data)) {
48 NETNATIVE_LOGE("NetDnsResultReport Marshalling failed");
49 return NETMANAGER_ERR_WRITE_DATA_FAIL;
50 }
51 }
52 }
53
54 sptr<IRemoteObject> remote = Remote();
55 if (remote == nullptr) {
56 NETNATIVE_LOGE("Remote is null");
57 return NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL;
58 }
59
60 MessageParcel reply;
61 MessageOption option;
62 option.SetFlags(MessageOption::TF_ASYNC);
63 int32_t ret =
64 remote->SendRequest(static_cast<uint32_t>(NetDnsResultInterfaceCode::ON_DNS_RESULT_REPORT),
65 data, reply, option);
66 if (ret != ERR_NONE) {
67 NETNATIVE_LOGE("proxy SendRequest failed, error: [%{public}d]", ret);
68 return NETMANAGER_ERR_OPERATION_FAILED;
69 }
70 return NETMANAGER_SUCCESS;
71 }
72 } // namespace NetsysNative
73 } // namespace OHOS
74