1 /*
2 * Copyright (c) 2024 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 META_INTERFACE_ITASKQUEUE_REGISTRY_H
17 #define META_INTERFACE_ITASKQUEUE_REGISTRY_H
18
19 #include <core/plugin/intf_interface.h>
20 #include <core/plugin/intf_plugin.h>
21 #include <core/plugin/intf_plugin_register.h>
22
23 #include <meta/base/meta_types.h>
24 #include <meta/base/namespace.h>
25 #include <meta/interface/intf_meta_object_lib.h>
26 #include <meta/interface/intf_task_queue.h>
27
28 META_BEGIN_NAMESPACE()
29
30 META_REGISTER_INTERFACE(ITaskQueueRegistry, "9dd2907e-dc6c-4090-8873-fa84f367b87e")
31
32 /**
33 * @brief The ITaskQueueRegistry interface can be used to register task queue objects which
34 * need to be used across the application.
35 */
36 class ITaskQueueRegistry : public CORE_NS::IInterface {
37 META_INTERFACE(CORE_NS::IInterface, ITaskQueueRegistry)
38 public:
39 /**
40 * @brief Get a task queue with a given queue id.
41 * @param queueId The id of the queue to get.
42 * @return The task queue with a given id or nullptr if no queue has been registered with the id.
43 */
44 virtual ITaskQueue::Ptr GetTaskQueue(const BASE_NS::Uid& queueId) const = 0;
45 /**
46 * @brief Register a task queue instance with a given id.
47 * @param queue The task queue to register.
48 * If queue = {} this call is equivalent to calling UnregisterTaskQueue(queueId).
49 * @param queueId Id to register the queue with.
50 * If a queue has already been registered with the given id, the previous registration
51 * is replaced with the new one.
52 * @return True if registration was successful, false otherwise.
53 */
54 virtual bool RegisterTaskQueue(const ITaskQueue::Ptr& queue, const BASE_NS::Uid& queueId) = 0;
55 /**
56 * @brief Unregister a previous registered task queue.
57 * @param queueId Id of the task queue to unregister.
58 * @return True if a queue was unregistered, false otherwise.
59 */
60 virtual bool UnregisterTaskQueue(const BASE_NS::Uid& queueId) = 0;
61 /**
62 * @brief Check if a queue with a given id has been registered.
63 * @param queueId Id of the queue to check.
64 * @return True if a task queue with a given id has been registered, false otherwise.
65 */
66 virtual bool HasTaskQueue(const BASE_NS::Uid& queueId) const = 0;
67 /**
68 * @brief Unregisters all task queues.
69 * @return True if task queue registry is empty after this call.
70 */
71 virtual bool UnregisterAllTaskQueues() = 0;
72 /**
73 * @brief If execution of current thread comes via task queue (i.e. executing a task), this returns that queue.
74 * Note: Not all task queues have to implement this feature.
75 * Note: This is single variable, if executing tasks in a task, one has to take care to reset it correctly.
76 */
77 virtual ITaskQueue::Ptr GetCurrentTaskQueue() const = 0;
78 /**
79 * @brief Sets the currently executing task queue. One should always set the queue to nullptr when not executing a
80 * task.
81 * @return The previously set task queue.
82 */
83 virtual ITaskQueue::WeakPtr SetCurrentTaskQueue(ITaskQueue::WeakPtr) = 0;
84 };
85
86 /** Returns a reference to the global ITaskQueueRegistry instance. */
GetTaskQueueRegistry()87 inline META_NS::ITaskQueueRegistry& GetTaskQueueRegistry()
88 {
89 return GetMetaObjectLib().GetTaskQueueRegistry();
90 }
91
92 META_END_NAMESPACE()
93
94 #endif // META_INTERFACE_ITASKQUEUE_REGISTRY_H
95