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 "insight_intent_execute_callback_stub.h"
17 #include "insight_intent_host_client.h"
18 #include "hilog_wrapper.h"
19
20 namespace OHOS {
21 namespace AAFwk {
22
InsightIntentExecuteCallbackStub()23 InsightIntentExecuteCallbackStub::InsightIntentExecuteCallbackStub()
24 {
25 requestFuncMap_[ON_INSIGHT_INTENT_EXECUTE_DONE] = &InsightIntentExecuteCallbackStub::OnExecuteDoneInner;
26 }
27
~InsightIntentExecuteCallbackStub()28 InsightIntentExecuteCallbackStub::~InsightIntentExecuteCallbackStub()
29 {
30 HILOG_DEBUG("call");
31 requestFuncMap_.clear();
32 }
33
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)34 int32_t InsightIntentExecuteCallbackStub::OnRemoteRequest(
35 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
36 {
37 if (data.ReadInterfaceToken() != IInsightIntentExecuteCallback::GetDescriptor()) {
38 HILOG_ERROR("InterfaceToken not equal IInsightIntentExecuteCallback's descriptor.");
39 return ERR_INVALID_STATE;
40 }
41
42 auto itFunc = requestFuncMap_.find(code);
43 if (itFunc != requestFuncMap_.end()) {
44 auto requestFunc = itFunc->second;
45 if (requestFunc != nullptr) {
46 return (this->*requestFunc)(data, reply);
47 }
48 }
49 HILOG_WARN("default case, need check.");
50 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
51 }
52
OnExecuteDoneInner(MessageParcel & data,MessageParcel & reply)53 int32_t InsightIntentExecuteCallbackStub::OnExecuteDoneInner(MessageParcel &data, MessageParcel &reply)
54 {
55 HILOG_DEBUG("call");
56 uint64_t key = data.ReadUint64();
57 int32_t resultCode = data.ReadInt32();
58 std::shared_ptr<AppExecFwk::InsightIntentExecuteResult> executeResult(
59 data.ReadParcelable<AppExecFwk::InsightIntentExecuteResult>());
60 if (executeResult == nullptr) {
61 HILOG_ERROR("executeResult is nullptr");
62 return ERR_INVALID_VALUE;
63 }
64 OnExecuteDone(key, resultCode, *executeResult);
65 return ERR_OK;
66 }
67 } // namespace AAFwk
68 } // namespace OHOS
69