1 /*
2  * Copyright (c) 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 #ifndef FOUNDATION_ACE_ADAPTER_OHOS_CPP_ACE_ROSEN_SYNC_TASK_H
17 #define FOUNDATION_ACE_ADAPTER_OHOS_CPP_ACE_ROSEN_SYNC_TASK_H
18 
19 #include "render_service_client/core/ui/rs_ui_director.h"
20 #include "transaction/rs_transaction_proxy.h"
21 
22 namespace OHOS::Ace::Platform {
23 
24 class AceRosenSyncTask : public Rosen::RSSyncTask {
25 public:
26     explicit AceRosenSyncTask(std::function<void()>&& task, unsigned long long timeoutNS = 30e9)
27         : Rosen::RSSyncTask(timeoutNS), task_(std::move(task))
28     {}
29     virtual ~AceRosenSyncTask() = default;
30 
31 #ifdef ROSEN_OHOS
CheckHeader(Parcel & parcel)32     bool CheckHeader(Parcel& parcel) const override
33     {
34         return true;
35     }
36 
ReadFromParcel(Parcel & parcel)37     bool ReadFromParcel(Parcel& parcel) override
38     {
39         return true;
40     }
41 
Marshalling(Parcel & parcel)42     bool Marshalling(Parcel& parcel) const override
43     {
44         return true;
45     }
46 #endif // ROSEN_OHOS
47 
Process(Rosen::RSContext & context)48     void Process(Rosen::RSContext& context) override
49     {
50         if (task_) {
51             task_();
52         }
53     }
54 
55 private:
56     std::function<void()> task_;
57 };
58 } // namespace OHOS::Ace::Platform
59 
60 #endif // FOUNDATION_ACE_ADAPTER_OHOS_CPP_ACE_ROSEN_SYNC_TASK_H