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_factoryreset_callback_stub.h"
16 
17 #include "net_mgr_log_wrapper.h"
18 
19 namespace OHOS {
20 namespace NetManagerStandard {
NetFactoryResetCallbackStub()21 NetFactoryResetCallbackStub::NetFactoryResetCallbackStub()
22 {
23     memberFuncMap_[static_cast<uint32_t>(FactoryResetCallbackInterfaceCode::NET_FACTORYRESET)] =
24         &NetFactoryResetCallbackStub::OnFactoryReset;
25 }
26 
~NetFactoryResetCallbackStub()27 NetFactoryResetCallbackStub::~NetFactoryResetCallbackStub() {}
28 
OnNetFactoryReset()29 int32_t NetFactoryResetCallbackStub::OnNetFactoryReset()
30 {
31     NETMGR_LOG_D("OnNetFactoryReset");
32     return NETMANAGER_SUCCESS;
33 }
34 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)35 int32_t NetFactoryResetCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
36     MessageOption &option)
37 {
38     NETMGR_LOG_D("Stub call start, code:[%{public}d]", code);
39     std::u16string myDescripter = NetFactoryResetCallbackStub::GetDescriptor();
40     std::u16string remoteDescripter = data.ReadInterfaceToken();
41     if (myDescripter != remoteDescripter) {
42         NETMGR_LOG_E("Descriptor checked failed");
43         return NETMANAGER_ERR_DESCRIPTOR_MISMATCH;
44     }
45 
46     auto itFunc = memberFuncMap_.find(code);
47     if (itFunc != memberFuncMap_.end()) {
48         auto requestFunc = itFunc->second;
49         if (requestFunc != nullptr) {
50             return (this->*requestFunc)(data, reply);
51         }
52     }
53 
54     return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
55 }
56 
OnFactoryReset(MessageParcel & data,MessageParcel & reply)57 int32_t NetFactoryResetCallbackStub::OnFactoryReset(MessageParcel &data, MessageParcel &reply)
58 {
59     if (!data.ContainFileDescriptors()) {
60         NETMGR_LOG_E("Execute ContainFileDescriptors failed");
61     }
62 
63     int32_t ret = OnNetFactoryReset();
64     if (!reply.WriteInt32(ret)) {
65         NETMGR_LOG_E("Write parcel failed");
66         return ret;
67     }
68 
69     return NETMANAGER_SUCCESS;
70 }
71 } // namespace NetManagerStandard
72 } // namespace OHOS
73