1
2 /*
3 * Copyright (c) 2021-2022 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_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 HILOG_INFO("%{public}s called begin", __func__);
33 MessageParcel data;
34 MessageParcel reply;
35 MessageOption option(MessageOption::TF_SYNC);
36 if (!data.WriteInterfaceToken(ReverseContinuationSchedulerPrimaryProxy::GetDescriptor())) {
37 HILOG_ERROR("ReverseContinuationSchedulerPrimaryProxy::NotifyReplicaTerminated write interface token failed");
38 return;
39 }
40 sptr<IRemoteObject> remoteObject = Remote();
41 if (remoteObject == nullptr) {
42 HILOG_ERROR("ReverseContinuationSchedulerPrimaryProxy::NotifyReplicaTerminated Remote() is nullptr");
43 return;
44 }
45 if (!remoteObject->SendRequest(
46 IReverseContinuationSchedulerPrimary::NOTIFY_REPLICA_TERMINATED, data, reply, option)) {
47 HILOG_ERROR("ReverseContinuationSchedulerPrimaryProxy::NotifyReplicaTerminated SendRequest return false");
48 return;
49 }
50 HILOG_INFO("%{public}s called end", __func__);
51 }
52
53 /**
54 * @brief Replica call this method to notify primary go on.
55 *
56 * @param want Contains data to be restore.
57 * @return True if success, otherwise false.
58 */
ContinuationBack(const AAFwk::Want & want)59 bool ReverseContinuationSchedulerPrimaryProxy::ContinuationBack(const AAFwk::Want &want)
60 {
61 HILOG_INFO("%{public}s called begin", __func__);
62 MessageParcel data;
63 MessageParcel reply;
64 MessageOption option(MessageOption::TF_SYNC);
65 if (!data.WriteInterfaceToken(ReverseContinuationSchedulerPrimaryProxy::GetDescriptor())) {
66 HILOG_ERROR("ReverseContinuationSchedulerPrimaryProxy::ContinuationBack write interface token failed");
67 return false;
68 }
69 if (!data.WriteParcelable(&want)) {
70 HILOG_ERROR("ReverseContinuationSchedulerPrimaryProxy::ContinuationBack fail to WriteParcelable");
71 return false;
72 }
73 sptr<IRemoteObject> remoteObject = Remote();
74 if (remoteObject == nullptr) {
75 HILOG_ERROR("ReverseContinuationSchedulerPrimaryProxy::ContinuationBack Remote() is nullptr");
76 return false;
77 }
78 if (!remoteObject->SendRequest(IReverseContinuationSchedulerPrimary::CONTINUATION_BACK, data, reply, option)) {
79 HILOG_ERROR("ReverseContinuationSchedulerPrimaryProxy::ContinuationBack SendRequest return false");
80 return false;
81 }
82 HILOG_INFO("%{public}s called end", __func__);
83 return true;
84 }
85 } // namespace AppExecFwk
86 } // namespace OHOS
87