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_health_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
NetDnsHealthCallbackProxy(const sptr<IRemoteObject> & impl)27 NetDnsHealthCallbackProxy::NetDnsHealthCallbackProxy(const sptr<IRemoteObject> &impl)
28 : IRemoteProxy<INetDnsHealthCallback>(impl) {}
29
OnDnsHealthReport(const NetDnsHealthReport & dnsHealthReport)30 int32_t NetDnsHealthCallbackProxy::OnDnsHealthReport(const NetDnsHealthReport &dnsHealthReport)
31 {
32 NETNATIVE_LOGI("Proxy OnDnsHealthReport");
33 MessageParcel data;
34 if (!data.WriteInterfaceToken(NetDnsHealthCallbackProxy::GetDescriptor())) {
35 NETNATIVE_LOGE("WriteInterfaceToken failed");
36 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
37 }
38
39 if (!dnsHealthReport.Marshalling(data)) {
40 NETNATIVE_LOGE("NetDnsHealthReport Marshalling failed");
41 return NETMANAGER_ERR_WRITE_DATA_FAIL;
42 }
43
44 sptr<IRemoteObject> remote = Remote();
45 if (remote == nullptr) {
46 NETNATIVE_LOGE("Remote is null");
47 return NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL;
48 }
49
50 MessageParcel reply;
51 MessageOption option;
52 int32_t ret =
53 remote->SendRequest(static_cast<uint32_t>(NetDnsHealthInterfaceCode::ON_DNS_HEALTH_REPORT),
54 data, reply, option);
55 if (ret != ERR_NONE) {
56 NETNATIVE_LOGE("proxy SendRequest failed, error: [%{public}d]", ret);
57 return NETMANAGER_ERR_OPERATION_FAILED;
58 }
59 return NETMANAGER_SUCCESS;
60 }
61 } // namespace NetsysNative
62 } // namespace OHOS
63