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