• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_replica.h"
17 #include "hilog_tag_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     TAG_LOGI(AAFwkTag::CONTINUATION, "begin");
32     auto task = [reverseContinuationSchedulerReplica = this, primary]() {
33         reverseContinuationSchedulerReplica->HandlerPassPrimary(primary);
34     };
35 
36     if (mainHandler_ == nullptr) {
37         TAG_LOGE(AAFwkTag::CONTINUATION, "null mainHandler_");
38         return;
39     }
40 
41     bool ret = mainHandler_->PostTask(task);
42     if (!ret) {
43         TAG_LOGE(AAFwkTag::CONTINUATION, "PostTask error");
44     }
45 }
46 
ReverseContinuation()47 bool ReverseContinuationSchedulerReplica::ReverseContinuation()
48 {
49     TAG_LOGI(AAFwkTag::CONTINUATION, "begin");
50     auto task = [reverseContinuationSchedulerReplica = this]() {
51         reverseContinuationSchedulerReplica->HandlerReverseContinuation();
52     };
53 
54     if (mainHandler_ == nullptr) {
55         TAG_LOGE(AAFwkTag::CONTINUATION, "null mainHandler_");
56         return false;
57     }
58 
59     bool ret = mainHandler_->PostTask(task);
60     if (!ret) {
61         TAG_LOGE(AAFwkTag::CONTINUATION, "PostTask error");
62     }
63     return true;
64 }
65 
NotifyReverseResult(int reverseResult)66 void ReverseContinuationSchedulerReplica::NotifyReverseResult(int reverseResult)
67 {
68     TAG_LOGI(AAFwkTag::CONTINUATION, "begin");
69     auto task = [reverseContinuationSchedulerReplica = this, reverseResult]() {
70         reverseContinuationSchedulerReplica->HandlerNotifyReverseResult(reverseResult);
71     };
72 
73     if (mainHandler_ == nullptr) {
74         TAG_LOGE(AAFwkTag::CONTINUATION, "null mainHandler_");
75         return;
76     }
77 
78     bool ret = mainHandler_->PostTask(task);
79     if (!ret) {
80         TAG_LOGE(AAFwkTag::CONTINUATION, "PostTask error");
81     }
82 }
83 
HandlerPassPrimary(const sptr<IRemoteObject> & primary)84 void ReverseContinuationSchedulerReplica::HandlerPassPrimary(const sptr<IRemoteObject> &primary)
85 {
86     TAG_LOGI(AAFwkTag::CONTINUATION, "begin");
87     std::shared_ptr<IReverseContinuationSchedulerReplicaHandler> replicaHandlerTmp = nullptr;
88     replicaHandlerTmp = replicaHandler_.lock();
89     if (replicaHandlerTmp == nullptr) {
90         TAG_LOGE(AAFwkTag::CONTINUATION, "null replicaHandlerTmp");
91         return;
92     }
93     replicaHandlerTmp->PassPrimary(primary);
94 }
95 
HandlerReverseContinuation()96 bool ReverseContinuationSchedulerReplica::HandlerReverseContinuation()
97 {
98     TAG_LOGI(AAFwkTag::CONTINUATION, "begin");
99     std::shared_ptr<IReverseContinuationSchedulerReplicaHandler> replicaHandlerTmp = nullptr;
100     replicaHandlerTmp = replicaHandler_.lock();
101     if (replicaHandlerTmp == nullptr) {
102         TAG_LOGE(AAFwkTag::CONTINUATION, "null replicaHandlerTmp");
103         return false;
104     }
105     return replicaHandlerTmp->ReverseContinuation();
106 }
107 
HandlerNotifyReverseResult(int reverseResult)108 void ReverseContinuationSchedulerReplica::HandlerNotifyReverseResult(int reverseResult)
109 {
110     TAG_LOGI(AAFwkTag::CONTINUATION, "begin");
111     std::shared_ptr<IReverseContinuationSchedulerReplicaHandler> replicaHandlerTmp = nullptr;
112     replicaHandlerTmp = replicaHandler_.lock();
113     if (replicaHandlerTmp == nullptr) {
114         TAG_LOGE(AAFwkTag::CONTINUATION, "null replicaHandlerTmp");
115         return;
116     }
117     replicaHandlerTmp->NotifyReverseResult(reverseResult);
118 }
119 }  // namespace AppExecFwk
120 }  // namespace OHOS
121