1 #ifndef DALI_ASYNC_TASK_MANAGER_H
2 #define DALI_ASYNC_TASK_MANAGER_H
5 * Copyright (c) 2022 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
52 * @param[in] callback The callback to up the main thread. The ownership of callback is taken by this class
54 AsyncTask(CallbackBase* callback);
57 * Get the complated callback
60 CallbackBase* GetCompletedCallback();
66 virtual ~AsyncTask() = default;
72 virtual void Process() = 0;
75 * Whether the task is ready to process.
77 * @return True if the task is ready to process.
79 virtual bool IsReady() = 0;
82 std::unique_ptr<CallbackBase> mCompletedCallback;
85 AsyncTask(const AsyncTask& task) = delete;
88 AsyncTask& operator=(const AsyncTask& task) = delete;
92 * The manager for async task
95 class DALI_ADAPTOR_API AsyncTaskManager : public BaseHandle
111 * @brief Gets the singleton of AsyncTaskManager object.
114 * @return A handle to the AsyncTaskManager
116 static AsyncTaskManager Get();
119 * @brief Add the async task into the waiting queue, called by main thread.
122 * @param[in] task The task added to the queue.
124 void AddTask(AsyncTaskPtr task);
127 * @brief Remove the task from the waiting queue, called by main thread.
130 * @param[in] task The task pointer.
132 void RemoveTask(AsyncTaskPtr task);
137 * @brief Allows the creation of a AsyncTaskManager handle from an internal pointer.
139 * @note Not intended for application developers
141 * @param[in] impl A pointer to the object
143 explicit DALI_INTERNAL AsyncTaskManager(Internal::Adaptor::AsyncTaskManager* impl);