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 #include "net_dns_health_callback_stub.h"
16 #include "netnative_log_wrapper.h"
17 #include "netsys_ipc_interface_code.h"
18 #include "net_conn_constants.h"
19 
20 namespace OHOS {
21 namespace NetsysNative {
NetDnsHealthCallbackStub()22 NetDnsHealthCallbackStub::NetDnsHealthCallbackStub()
23 {
24     memberFuncMap_[static_cast<uint32_t>(NetDnsHealthInterfaceCode::ON_DNS_HEALTH_REPORT)] =
25         &NetDnsHealthCallbackStub::CmdDnsHealthReport;
26 }
27 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)28 int32_t NetDnsHealthCallbackStub::OnRemoteRequest(
29     uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
30 {
31     NETNATIVE_LOGI("Stub call start, code:[%{public}d]", code);
32     std::u16string myDescripter = NetDnsHealthCallbackStub::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 }
CmdDnsHealthReport(MessageParcel & data,MessageParcel & reply)50 int32_t NetDnsHealthCallbackStub::CmdDnsHealthReport(MessageParcel &data, MessageParcel &reply)
51 {
52     NetDnsHealthReport dnsHealthReport;
53     if (!NetDnsHealthReport::Unmarshalling(data, dnsHealthReport)) {
54         return NetManagerStandard::NETMANAGER_ERR_READ_DATA_FAIL;
55     }
56 
57     int32_t result = OnDnsHealthReport(dnsHealthReport);
58     if (!reply.WriteInt32(result)) {
59         NETNATIVE_LOGE("Write parcel failed");
60         return result;
61     }
62 
63     return ERR_NONE;
64 }
65 
OnDnsHealthReport(const NetDnsHealthReport & dnsHealthReport)66 int32_t NetDnsHealthCallbackStub::OnDnsHealthReport(const NetDnsHealthReport &dnsHealthReport)
67 {
68     return 0;
69 }
70 } // namespace NetsysNative
71 } // namespace OHOS
72