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 16 #ifndef RENDER_SERVICE_BASE_CORE_COMMON_RS_THREAD_HANDLER_H 17 #define RENDER_SERVICE_BASE_CORE_COMMON_RS_THREAD_HANDLER_H 18 19 #include <functional> 20 #include <memory> 21 22 namespace OHOS { 23 namespace Rosen { 24 class RSTaskMessage { 25 public: 26 using RSTask = std::function<void()>; 27 }; 28 29 using RSTaskHandle = std::shared_ptr<RSTaskMessage>; 30 31 class RSThreadHandler { 32 public: 33 RSThreadHandler() = default; 34 virtual ~RSThreadHandler() = default; 35 36 static std::unique_ptr<RSThreadHandler> Create(); 37 virtual RSTaskHandle CreateTask(const RSTaskMessage::RSTask task) const = 0; 38 virtual void PostTask(const RSTaskHandle task, int param = 0) = 0; 39 virtual void PostTaskDelay(const RSTaskHandle task, int64_t nsecs, int param = 0) = 0; 40 virtual void CancelTask(RSTaskHandle task) = 0; 41 virtual bool IsValid() const = 0; 42 static RSTaskHandle StaticCreateTask(const RSTaskMessage::RSTask task); 43 44 private: 45 RSThreadHandler(const RSThreadHandler&) = delete; 46 const RSThreadHandler& operator=(const RSThreadHandler&) = delete; 47 RSThreadHandler(const RSThreadHandler&&) = delete; 48 const RSThreadHandler& operator=(const RSThreadHandler&&) = delete; 49 }; 50 } // namespace Rosen 51 } // namespace OHOS 52 53 #endif // RENDER_SERVICE_BASE_CORE_COMMON_RS_THREAD_HANDLER_H 54