1 /*
2 * Copyright (c) 2021-2022 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 "reverse_continuation_scheduler_primary_stub.h"
17 #include "ability_scheduler_interface.h"
18 #include "hilog_wrapper.h"
19 #include "string_ex.h"
20
21 namespace OHOS {
22 namespace AppExecFwk {
23 const std::string ReverseContinuationSchedulerPrimaryStub::DESCRIPTOR(
24 "ohos.abilityshell.ReverseContinuationSchedulerMaster");
25
ReverseContinuationSchedulerPrimaryStub()26 ReverseContinuationSchedulerPrimaryStub::ReverseContinuationSchedulerPrimaryStub()
27 {
28 requestFuncMap_[NOTIFY_REPLICA_TERMINATED] = &ReverseContinuationSchedulerPrimaryStub::NotifyReplicaTerminatedInner;
29 requestFuncMap_[CONTINUATION_BACK] = &ReverseContinuationSchedulerPrimaryStub::ContinuationBackInner;
30 }
31
~ReverseContinuationSchedulerPrimaryStub()32 ReverseContinuationSchedulerPrimaryStub::~ReverseContinuationSchedulerPrimaryStub()
33 {
34 requestFuncMap_.clear();
35 }
36
37 /**
38 * @brief Sets an entry for receiving requests.
39 *
40 * @param code Indicates the service request code sent from the peer end.
41 * @param data Indicates the MessageParcel object sent from the peer end.
42 * @param reply Indicates the response message object sent from the remote service. The local service writes the
43 * response data to the MessageParcel object.
44 * @param option Indicates whether the operation is synchronous or asynchronous.
45 * @return ERR_NONE if success, otherwise false.
46 */
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)47 int ReverseContinuationSchedulerPrimaryStub::OnRemoteRequest(
48 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
49 {
50 HILOG_INFO("%{public}s called begin", __func__);
51 std::u16string token = data.ReadInterfaceToken();
52 std::u16string descriptor = Str8ToStr16(DESCRIPTOR);
53 if (descriptor != token) {
54 HILOG_ERROR("ReverseContinuationSchedulerPrimaryStub::OnRemoteRequest failed, DESCRIPTOR != touken");
55 return -1;
56 }
57
58 auto iter = requestFuncMap_.find(code);
59 if (iter != requestFuncMap_.end()) {
60 auto func = iter->second;
61 if (func != nullptr) {
62 return (this->*func)(data, reply);
63 } else {
64 HILOG_WARN("ReverseContinuationSchedulerPrimaryStub::OnRemoteRequest failed, func is nullptr");
65 }
66 } else {
67 HILOG_WARN("ReverseContinuationSchedulerPrimaryStub::OnRemoteRequest failed, iter not find");
68 }
69 HILOG_INFO("%{public}s called end", __func__);
70 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
71 }
72
NotifyReplicaTerminatedInner(MessageParcel & data,MessageParcel & reply)73 int ReverseContinuationSchedulerPrimaryStub::NotifyReplicaTerminatedInner(MessageParcel &data, MessageParcel &reply)
74 {
75 HILOG_INFO("%{public}s called begin", __func__);
76 NotifyReplicaTerminated();
77 HILOG_INFO("%{public}s called end", __func__);
78 return 0;
79 }
ContinuationBackInner(MessageParcel & data,MessageParcel & reply)80 int ReverseContinuationSchedulerPrimaryStub::ContinuationBackInner(MessageParcel &data, MessageParcel &reply)
81 {
82 HILOG_INFO("%{public}s called begin", __func__);
83 std::unique_ptr<AAFwk::Want> want(data.ReadParcelable<AAFwk::Want>());
84 if (want == nullptr) {
85 HILOG_ERROR("ReverseContinuationSchedulerPrimaryStub::ContinuationBackInner want is nullptr");
86 return -1;
87 }
88
89 if (!ContinuationBack(*want)) {
90 HILOG_ERROR("ReverseContinuationSchedulerPrimaryStub::NotifyReverseaTerminatedInner failed, ContinuationBack() "
91 "return false");
92 return -1;
93 }
94 HILOG_INFO("%{public}s called end", __func__);
95 return 0;
96 }
97 } // namespace AppExecFwk
98 } // namespace OHOS
99