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