1 /*
2  * Copyright (c) 2021-2024 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_tag_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 
~ReverseContinuationSchedulerPrimaryStub()28 ReverseContinuationSchedulerPrimaryStub::~ReverseContinuationSchedulerPrimaryStub() {}
29 
30 /**
31  * @brief Sets an entry for receiving requests.
32  *
33  * @param code Indicates the service request code sent from the peer end.
34  * @param data Indicates the MessageParcel object sent from the peer end.
35  * @param reply Indicates the response message object sent from the remote service. The local service writes the
36  * response data to the MessageParcel object.
37  * @param option Indicates whether the operation is synchronous or asynchronous.
38  * @return ERR_NONE if success, otherwise false.
39  */
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)40 int ReverseContinuationSchedulerPrimaryStub::OnRemoteRequest(
41     uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
42 {
43     std::u16string token = data.ReadInterfaceToken();
44     std::u16string descriptor = Str8ToStr16(DESCRIPTOR);
45     if (descriptor != token) {
46         TAG_LOGE(AAFwkTag::CONTINUATION,
47             "DESCRIPTOR != token");
48         return -1;
49     }
50     switch (code) {
51         case NOTIFY_REPLICA_TERMINATED:
52             return NotifyReplicaTerminatedInner(data, reply);
53         case CONTINUATION_BACK:
54             return ContinuationBackInner(data, reply);
55     }
56     return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
57 }
58 
NotifyReplicaTerminatedInner(MessageParcel & data,MessageParcel & reply)59 int ReverseContinuationSchedulerPrimaryStub::NotifyReplicaTerminatedInner(MessageParcel &data, MessageParcel &reply)
60 {
61     NotifyReplicaTerminated();
62     return 0;
63 }
ContinuationBackInner(MessageParcel & data,MessageParcel & reply)64 int ReverseContinuationSchedulerPrimaryStub::ContinuationBackInner(MessageParcel &data, MessageParcel &reply)
65 {
66     std::unique_ptr<AAFwk::Want> want(data.ReadParcelable<AAFwk::Want>());
67     if (want == nullptr) {
68         TAG_LOGE(AAFwkTag::CONTINUATION,
69             "want is nullptr");
70         return -1;
71     }
72 
73     if (!ContinuationBack(*want)) {
74         TAG_LOGE(AAFwkTag::CONTINUATION,
75             "ContinuationBack failed");
76         return -1;
77     }
78     return 0;
79 }
80 }  // namespace AppExecFwk
81 }  // namespace OHOS
82