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 "prepare_terminate_callback_stub.h"
17 #include "hilog_wrapper.h"
18
19 namespace OHOS {
20 namespace AAFwk {
21
PrepareTerminateCallbackStub()22 PrepareTerminateCallbackStub::PrepareTerminateCallbackStub()
23 {
24 requestFuncMap_[ON_DO_PREPARE_TERMINATE] = &PrepareTerminateCallbackStub::DoPrepareTerminateInner;
25 }
26
~PrepareTerminateCallbackStub()27 PrepareTerminateCallbackStub::~PrepareTerminateCallbackStub()
28 {
29 HILOG_INFO("call");
30 requestFuncMap_.clear();
31 }
32
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)33 int32_t PrepareTerminateCallbackStub::OnRemoteRequest(
34 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
35 {
36 if (data.ReadInterfaceToken() != IPrepareTerminateCallback::GetDescriptor()) {
37 HILOG_ERROR("InterfaceToken not equal IPrepareTerminateCallback's descriptor.");
38 return ERR_INVALID_STATE;
39 }
40
41 auto itFunc = requestFuncMap_.find(code);
42 if (itFunc != requestFuncMap_.end()) {
43 auto requestFunc = itFunc->second;
44 if (requestFunc != nullptr) {
45 return (this->*requestFunc)(data, reply);
46 }
47 }
48 HILOG_WARN("default case, needs to be checked.");
49 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
50 }
51
DoPrepareTerminateInner(MessageParcel & data,MessageParcel & reply)52 int32_t PrepareTerminateCallbackStub::DoPrepareTerminateInner(MessageParcel &data, MessageParcel &reply)
53 {
54 HILOG_DEBUG("call");
55 DoPrepareTerminate();
56 return ERR_OK;
57 }
58 }
59 }
60