1
2 /*
3 * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "reverse_continuation_scheduler_primary_proxy.h"
18 #include "hilog_tag_wrapper.h"
19
20 namespace OHOS {
21 namespace AppExecFwk {
ReverseContinuationSchedulerPrimaryProxy(const sptr<IRemoteObject> & remoteObject)22 ReverseContinuationSchedulerPrimaryProxy::ReverseContinuationSchedulerPrimaryProxy(
23 const sptr<IRemoteObject> &remoteObject)
24 : IRemoteProxy<IReverseContinuationSchedulerPrimary>(remoteObject)
25 {}
26
27 /**
28 * @brief Replica call this method when it terminated.
29 */
NotifyReplicaTerminated()30 void ReverseContinuationSchedulerPrimaryProxy::NotifyReplicaTerminated()
31 {
32 MessageParcel data;
33 MessageParcel reply;
34 MessageOption option(MessageOption::TF_SYNC);
35 if (!data.WriteInterfaceToken(ReverseContinuationSchedulerPrimaryProxy::GetDescriptor())) {
36 TAG_LOGE(AAFwkTag::CONTINUATION,
37 "write interface token failed");
38 return;
39 }
40 sptr<IRemoteObject> remoteObject = Remote();
41 if (remoteObject == nullptr) {
42 TAG_LOGE(AAFwkTag::CONTINUATION,
43 "Remote is nullptr");
44 return;
45 }
46 if (!remoteObject->SendRequest(
47 IReverseContinuationSchedulerPrimary::NOTIFY_REPLICA_TERMINATED, data, reply, option)) {
48 TAG_LOGE(AAFwkTag::CONTINUATION,
49 "SendRequest failed");
50 return;
51 }
52 }
53
54 /**
55 * @brief Replica call this method to notify primary go on.
56 *
57 * @param want Contains data to be restore.
58 * @return True if success, otherwise false.
59 */
ContinuationBack(const AAFwk::Want & want)60 bool ReverseContinuationSchedulerPrimaryProxy::ContinuationBack(const AAFwk::Want &want)
61 {
62 MessageParcel data;
63 MessageParcel reply;
64 MessageOption option(MessageOption::TF_SYNC);
65 if (!data.WriteInterfaceToken(ReverseContinuationSchedulerPrimaryProxy::GetDescriptor())) {
66 TAG_LOGE(AAFwkTag::CONTINUATION,
67 "write interface token failed");
68 return false;
69 }
70 if (!data.WriteParcelable(&want)) {
71 TAG_LOGE(AAFwkTag::CONTINUATION,
72 "failed to write want");
73 return false;
74 }
75 sptr<IRemoteObject> remoteObject = Remote();
76 if (remoteObject == nullptr) {
77 TAG_LOGE(AAFwkTag::CONTINUATION,
78 "Remote is nullptr");
79 return false;
80 }
81 if (!remoteObject->SendRequest(IReverseContinuationSchedulerPrimary::CONTINUATION_BACK, data, reply, option)) {
82 TAG_LOGE(AAFwkTag::CONTINUATION,
83 "SendRequest failed");
84 return false;
85 }
86 return true;
87 }
88 } // namespace AppExecFwk
89 } // namespace OHOS
90