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_factoryreset_callback_proxy.h"
17 #include "net_manager_constants.h"
18 #include "net_mgr_log_wrapper.h"
19 
20 namespace OHOS {
21 namespace NetManagerStandard {
NetFactoryResetCallbackProxy(const sptr<IRemoteObject> & impl)22 NetFactoryResetCallbackProxy::NetFactoryResetCallbackProxy(const sptr<IRemoteObject> &impl)
23     : IRemoteProxy<INetFactoryResetCallback>(impl)
24 {}
25 
~NetFactoryResetCallbackProxy()26 NetFactoryResetCallbackProxy::~NetFactoryResetCallbackProxy() {}
27 
OnNetFactoryReset()28 int32_t NetFactoryResetCallbackProxy::OnNetFactoryReset()
29 {
30     MessageParcel data;
31     if (!WriteInterfaceToken(data)) {
32         NETMGR_LOG_E("WriteInterfaceToken failed");
33         return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
34     }
35 
36     sptr<IRemoteObject> remote = Remote();
37     if (remote == nullptr) {
38         NETMGR_LOG_E("Remote is null");
39         return NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL;
40     }
41     MessageParcel replyParcel;
42     MessageOption option;
43     int32_t retCode = remote->SendRequest(static_cast<uint32_t>(FactoryResetCallbackInterfaceCode::NET_FACTORYRESET),
44                                           data, replyParcel, option);
45     if (retCode != ERR_NONE) {
46         NETMGR_LOG_E("proxy SendRequest failed, retCode: [%{public}d]", retCode);
47         return retCode;
48     }
49 
50     return replyParcel.ReadInt32();
51 }
52 
WriteInterfaceToken(MessageParcel & data)53 bool NetFactoryResetCallbackProxy::WriteInterfaceToken(MessageParcel &data)
54 {
55     if (!data.WriteInterfaceToken(NetFactoryResetCallbackProxy::GetDescriptor())) {
56         NETMGR_LOG_E("WriteInterfaceToken failed");
57         return false;
58     }
59     return true;
60 }
61 
62 } // namespace NetManagerStandard
63 } // namespace OHOS
64