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_stub.h"
17 #include "netnative_log_wrapper.h"
18 #include "netsys_ipc_interface_code.h"
19
20 namespace OHOS {
21 namespace NetsysNative {
NetDnsResultCallbackStub()22 NetDnsResultCallbackStub::NetDnsResultCallbackStub()
23 {
24 memberFuncMap_[static_cast<uint32_t>(NetDnsResultInterfaceCode::ON_DNS_RESULT_REPORT)] =
25 &NetDnsResultCallbackStub::CmdDnsResultReport;
26 }
27
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)28 int32_t NetDnsResultCallbackStub::OnRemoteRequest(
29 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
30 {
31 NETNATIVE_LOG_D("Stub call start, code:[%{public}d]", code);
32 std::u16string myDescripter = NetDnsResultCallbackStub::GetDescriptor();
33 std::u16string remoteDescripter = data.ReadInterfaceToken();
34 if (myDescripter != remoteDescripter) {
35 NETNATIVE_LOGE("Descriptor checked failed");
36 return ERR_FLATTEN_OBJECT;
37 }
38
39 auto itFunc = memberFuncMap_.find(code);
40 if (itFunc != memberFuncMap_.end()) {
41 auto requestFunc = itFunc->second;
42 if (requestFunc != nullptr) {
43 return (this->*requestFunc)(data, reply);
44 }
45 }
46
47 NETNATIVE_LOGI("Stub default case, need check");
48 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
49 }
50
CmdDnsResultReport(MessageParcel & data,MessageParcel & reply)51 int32_t NetDnsResultCallbackStub::CmdDnsResultReport(MessageParcel &data, MessageParcel &reply)
52 {
53 std::list<NetDnsResultReport> dnsResultReport;
54
55 uint32_t size = data.ReadUint32();
56
57 for (uint32_t i = 0; i < size; ++i) {
58 NetDnsResultReport report;
59 if (!NetDnsResultReport::Unmarshalling(data, report)) {
60 return -1;
61 }
62 dnsResultReport.push_back(report);
63 }
64
65 int32_t result = OnDnsResultReport(size, dnsResultReport);
66 if (!reply.WriteInt32(result)) {
67 NETNATIVE_LOGE("Write parcel failed");
68 return result;
69 }
70
71 return ERR_NONE;
72 }
73
OnDnsResultReport(uint32_t size,std::list<NetDnsResultReport> dnsResultReport)74 int32_t NetDnsResultCallbackStub::OnDnsResultReport(uint32_t size, std::list<NetDnsResultReport> dnsResultReport)
75 {
76 return 0;
77 }
78 } // namespace NetsysNative
79 } // namespace OHOS
80