1 #ifndef DALI_ASYNC_TASK_MANAGER_H
2 #define DALI_ASYNC_TASK_MANAGER_H
5 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
21 #include <dali/public-api/common/intrusive-ptr.h>
22 #include <dali/public-api/object/base-handle.h>
23 #include <dali/public-api/signals/callback.h>
27 #include <dali/public-api/dali-adaptor-common.h>
31 namespace Internal DALI_INTERNAL
35 class AsyncTaskManager;
37 } // namespace DALI_INTERNAL
40 using AsyncTaskPtr = IntrusivePtr<AsyncTask>;
43 * The async tasks to be processed in the worker thread.
46 class DALI_ADAPTOR_API AsyncTask : public RefObject
49 // The Type of invocation thread
59 * @param[in] callback The callback to invoke on task completion, either on the main thread on the worker thread. The ownership of callback is taken by this class.
60 * @param[in] threadType The thread type of invocation callback.
62 AsyncTask(CallbackBase* callback, ThreadType threadType = AsyncTask::ThreadType::MAIN_THREAD);
65 * Get the complated callback
68 CallbackBase* GetCompletedCallback();
71 * Get the thread of the invocation callback
73 * @return the type of invocation callback.
75 ThreadType GetCallbackInvocationThread();
81 virtual ~AsyncTask() = default;
87 virtual void Process() = 0;
90 * Whether the task is ready to process.
92 * @return True if the task is ready to process.
94 virtual bool IsReady() = 0;
97 std::unique_ptr<CallbackBase> mCompletedCallback;
98 ThreadType mThreadType;
101 AsyncTask(const AsyncTask& task) = delete;
104 AsyncTask& operator=(const AsyncTask& task) = delete;
108 * The manager for async task
111 class DALI_ADAPTOR_API AsyncTaskManager : public BaseHandle
127 * @brief Gets the singleton of AsyncTaskManager object.
130 * @return A handle to the AsyncTaskManager
132 static AsyncTaskManager Get();
135 * @brief Add the async task into the waiting queue, called by main thread.
138 * @param[in] task The task added to the queue.
140 void AddTask(AsyncTaskPtr task);
143 * @brief Remove the task from the waiting queue, called by main thread.
146 * @param[in] task The task pointer.
148 void RemoveTask(AsyncTaskPtr task);
153 * @brief Allows the creation of a AsyncTaskManager handle from an internal pointer.
155 * @note Not intended for application developers
157 * @param[in] impl A pointer to the object
159 explicit DALI_INTERNAL AsyncTaskManager(Internal::Adaptor::AsyncTaskManager* impl);