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_ITICKABLE_CONTROLLER_H 17 #define META_INTERFACE_ITICKABLE_CONTROLLER_H 18 19 #include <meta/base/interface_macros.h> 20 #include <meta/base/time_span.h> 21 #include <meta/interface/interface_macros.h> 22 #include <meta/interface/intf_iterable.h> 23 #include <meta/interface/intf_tickable.h> 24 25 META_BEGIN_NAMESPACE() 26 27 REGISTER_INTERFACE(ITickableController, "6b730c19-8a43-4a00-8e41-fda0bc78d294") 28 29 /** 30 * @brief The ITickableController interface is implemented by a controller objects for startables. 31 * @note The default implementation is META_NS::ClassId::StartableController. 32 */ 33 class ITickableController : public CORE_NS::IInterface { 34 META_INTERFACE(CORE_NS::IInterface, ITickableController) 35 public: 36 /** 37 * @brief Return a list of all tickable objects handled by a controller. 38 */ 39 virtual BASE_NS::vector<ITickable::Ptr> GetTickables() const = 0; 40 /** 41 * @brief Call ITickable::Tick for all tickable objects handled by the controller in a given 42 * order. 43 * @param time Current time. 44 */ 45 virtual void TickAll(const TimeSpan& time) = 0; 46 /** 47 * @brief Interval for ticking the tickables which are part of the controller's hierarchy. 48 * The default value is TimeSpan::Infinite, meaning that the tickables are not automatically ticked. 49 */ 50 META_PROPERTY(META_NS::TimeSpan, TickInterval) 51 /** 52 * @brief The order in which the tickables should be ticked. 53 * The default value is TraversalType::DEPTH_FIRST_PRE_ORDER. 54 */ 55 META_PROPERTY(META_NS::TraversalType, TickOrder) 56 /** 57 * @brief Set the queue id of the queue where ITickable::Tick() should be called when ticking. 58 * @param queueId The id of the task queue. if {}, a new thread should be created for ticking. 59 * @return True if the queue id was successfully set, false otherwise. 60 */ 61 virtual bool SetTickableQueueuId(const BASE_NS::Uid& queueId) = 0; 62 }; 63 64 META_END_NAMESPACE() 65 66 #endif // META_INTERFACE_ITICKABLE_CONTROLLER_H 67