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_replica.h"
17 #include "hilog_wrapper.h"
18
19 namespace OHOS {
20 namespace AppExecFwk {
ReverseContinuationSchedulerReplica(const std::shared_ptr<AbilityHandler> & mainHandler,const std::weak_ptr<IReverseContinuationSchedulerReplicaHandler> & replicaHandler)21 ReverseContinuationSchedulerReplica::ReverseContinuationSchedulerReplica(
22 const std::shared_ptr<AbilityHandler> &mainHandler,
23 const std::weak_ptr<IReverseContinuationSchedulerReplicaHandler> &replicaHandler)
24 {
25 mainHandler_ = mainHandler;
26 replicaHandler_ = replicaHandler;
27 }
28
PassPrimary(const sptr<IRemoteObject> & primary)29 void ReverseContinuationSchedulerReplica::PassPrimary(const sptr<IRemoteObject> &primary)
30 {
31 HILOG_INFO("%{public}s called begin", __func__);
32 auto task = [reverseContinuationSchedulerReplica = this, primary]() {
33 reverseContinuationSchedulerReplica->HandlerPassPrimary(primary);
34 };
35
36 if (mainHandler_ == nullptr) {
37 HILOG_ERROR("ReverseContinuationSchedulerReplica::PassPrimary mainHandler_ == nullptr");
38 return;
39 }
40
41 bool ret = mainHandler_->PostTask(task);
42 if (!ret) {
43 HILOG_ERROR("ReverseContinuationSchedulerReplica::PassPrimary PostTask error");
44 }
45 HILOG_INFO("%{public}s called end", __func__);
46 }
47
ReverseContinuation()48 bool ReverseContinuationSchedulerReplica::ReverseContinuation()
49 {
50 HILOG_INFO("%{public}s called begin", __func__);
51 auto task = [reverseContinuationSchedulerReplica = this]() {
52 reverseContinuationSchedulerReplica->HandlerReverseContinuation();
53 };
54
55 if (mainHandler_ == nullptr) {
56 HILOG_ERROR("ReverseContinuationSchedulerReplica::ReverseContinuation mainHandler_ == nullptr");
57 return false;
58 }
59
60 bool ret = mainHandler_->PostTask(task);
61 if (!ret) {
62 HILOG_ERROR("ReverseContinuationSchedulerReplica::ReverseContinuation PostTask error");
63 }
64 HILOG_INFO("%{public}s called end", __func__);
65 return true;
66 }
67
NotifyReverseResult(int reverseResult)68 void ReverseContinuationSchedulerReplica::NotifyReverseResult(int reverseResult)
69 {
70 HILOG_INFO("%{public}s called begin", __func__);
71 auto task = [reverseContinuationSchedulerReplica = this, reverseResult]() {
72 reverseContinuationSchedulerReplica->HandlerNotifyReverseResult(reverseResult);
73 };
74
75 if (mainHandler_ == nullptr) {
76 HILOG_ERROR("ReverseContinuationSchedulerReplica::NotifyReverseResult mainHandler_ == nullptr");
77 return;
78 }
79
80 bool ret = mainHandler_->PostTask(task);
81 if (!ret) {
82 HILOG_ERROR("ReverseContinuationSchedulerReplica::NotifyReverseResult PostTask error");
83 }
84 HILOG_INFO("%{public}s called end", __func__);
85 }
86
HandlerPassPrimary(const sptr<IRemoteObject> & primary)87 void ReverseContinuationSchedulerReplica::HandlerPassPrimary(const sptr<IRemoteObject> &primary)
88 {
89 HILOG_INFO("%{public}s called begin", __func__);
90 std::shared_ptr<IReverseContinuationSchedulerReplicaHandler> replicaHandlerTmp = nullptr;
91 replicaHandlerTmp = replicaHandler_.lock();
92 if (replicaHandlerTmp == nullptr) {
93 HILOG_ERROR("ReverseContinuationSchedulerReplica::PassPrimary get replicaHandlerTmp is nullptr");
94 return;
95 }
96 replicaHandlerTmp->PassPrimary(primary);
97 HILOG_INFO("%{public}s called end", __func__);
98 }
99
HandlerReverseContinuation()100 bool ReverseContinuationSchedulerReplica::HandlerReverseContinuation()
101 {
102 HILOG_INFO("%{public}s called begin", __func__);
103 std::shared_ptr<IReverseContinuationSchedulerReplicaHandler> replicaHandlerTmp = nullptr;
104 replicaHandlerTmp = replicaHandler_.lock();
105 if (replicaHandlerTmp == nullptr) {
106 HILOG_ERROR("ReverseContinuationSchedulerReplica::PassPrimary get replicaHandlerTmp is nullptr");
107 return false;
108 }
109 HILOG_INFO("%{public}s called end", __func__);
110 return replicaHandlerTmp->ReverseContinuation();
111 }
112
HandlerNotifyReverseResult(int reverseResult)113 void ReverseContinuationSchedulerReplica::HandlerNotifyReverseResult(int reverseResult)
114 {
115 HILOG_INFO("%{public}s called begin", __func__);
116 std::shared_ptr<IReverseContinuationSchedulerReplicaHandler> replicaHandlerTmp = nullptr;
117 replicaHandlerTmp = replicaHandler_.lock();
118 if (replicaHandlerTmp == nullptr) {
119 HILOG_ERROR("ReverseContinuationSchedulerReplica::PassPrimary get replicaHandlerTmp is nullptr");
120 return;
121 }
122 replicaHandlerTmp->NotifyReverseResult(reverseResult);
123 HILOG_INFO("%{public}s called end", __func__);
124 }
125 } // namespace AppExecFwk
126 } // namespace OHOS
127