• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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_detection_callback_proxy.h"
16 
17 #include "net_mgr_log_wrapper.h"
18 
19 namespace OHOS {
20 namespace NetManagerStandard {
NetDetectionCallbackProxy(const sptr<IRemoteObject> & impl)21 NetDetectionCallbackProxy::NetDetectionCallbackProxy(const sptr<IRemoteObject> &impl)
22     : IRemoteProxy<INetDetectionCallback>(impl)
23 {}
24 
~NetDetectionCallbackProxy()25 NetDetectionCallbackProxy::~NetDetectionCallbackProxy() {}
26 
OnNetDetectionResultChanged(NetDetectionResultCode detectionResult,const std::string & urlRedirect)27 int32_t NetDetectionCallbackProxy::OnNetDetectionResultChanged(NetDetectionResultCode detectionResult,
28     const std::string &urlRedirect)
29 {
30     MessageParcel dataParcel;
31     if (!WriteInterfaceToken(dataParcel)) {
32         NETMGR_LOG_E("WriteInterfaceToken failed");
33         return NET_CONN_ERR_INVALID_PARAMETER;
34     }
35 
36     if (!dataParcel.WriteString(urlRedirect)) {
37         return NET_CONN_ERR_INVALID_PARAMETER;
38     }
39     if (!dataParcel.WriteInt32(static_cast<int32_t>(detectionResult))) {
40         return NET_CONN_ERR_INVALID_PARAMETER;
41     }
42 
43     sptr<IRemoteObject> remote = Remote();
44     if (remote == nullptr) {
45         NETMGR_LOG_E("Remote is null");
46         return NET_CONN_ERR_GET_REMOTE_OBJECT_FAILED;
47     }
48     MessageParcel replyParcel;
49     MessageOption option;
50     int32_t retCode = remote->SendRequest(NET_DETECTION_RESULT, dataParcel, replyParcel, option);
51     if (retCode != ERR_NONE) {
52         NETMGR_LOG_E("proxy SendRequest failed, retCode: [%{public}d]", retCode);
53         return retCode;
54     }
55 
56     return replyParcel.ReadInt32();
57 }
58 
WriteInterfaceToken(MessageParcel & data)59 bool NetDetectionCallbackProxy::WriteInterfaceToken(MessageParcel &data)
60 {
61     if (!data.WriteInterfaceToken(NetDetectionCallbackProxy::GetDescriptor())) {
62         NETMGR_LOG_E("WriteInterfaceToken failed");
63         return false;
64     }
65     return true;
66 }
67 } // namespace NetManagerStandard
68 } // namespace OHOS
69