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_ISTARTABLE_CONTROLLER_H 17 #define META_INTERFACE_ISTARTABLE_CONTROLLER_H 18 19 #include <meta/base/interface_macros.h> 20 #include <meta/interface/interface_macros.h> 21 #include <meta/interface/intf_startable.h> 22 #include <meta/interface/intf_task_queue.h> 23 24 META_BEGIN_NAMESPACE() 25 26 META_REGISTER_INTERFACE(IStartableController, "dd8e8c3d-f81a-4e33-8c42-6db05eb65e24") 27 28 /** 29 * @brief The IStartableController interface is implemented by controller objects for startables. 30 * @note The default implementation is META_NS::ClassId::StartableController. 31 */ 32 class IStartableController : public CORE_NS::IInterface { 33 META_INTERFACE(CORE_NS::IInterface, IStartableController) 34 public: 35 /** 36 * @brief The ControlBehavior enum defines the modes which can be used to set which 37 * startables are affected by a control operation such as StartAll or StopAll. 38 */ 39 enum class ControlBehavior : uint32_t { 40 /** Control startables whose StartableMode=StartBehavior::AUTOMATIC. */ 41 CONTROL_AUTOMATIC = 0, 42 /** Control all startables regardless of their StartableMode, both AUTOMATIC and 43 * MANUAL startables are affected by the operation. */ 44 CONTROL_ALL = 1, 45 }; 46 /** 47 * @brief The traversal order in which the hierarchy should be traversed when starting/stopping 48 * the startables. 49 */ 50 META_PROPERTY(META_NS::TraversalType, TraversalType) 51 /** 52 * @brief Controls how the controller should handle new startables that are added to the hierarchy. 53 * If StartBehavior::AUTOMATIC, new startables whose StartableMode==StartBehavior::AUTOMATIC 54 * are started automatically, and startables that are removed from the hierarchy are stopped 55 * automatically. 56 * If StartBehavior::MANUAL, new startables are not started/stopped by the controller 57 * automatically. 58 */ 59 META_PROPERTY(META_NS::StartBehavior, StartBehavior) 60 /** 61 * @brief Start all startables which are part of the target hierarchy, using the order specified 62 * by TraversalType. 63 * @param behavior Control which startables are started. 64 * @return True if successful, false otherwise. 65 */ 66 virtual bool StartAll(ControlBehavior behavior) = 0; 67 /** 68 * @brief Stops all startables which are part of the target hierarchy, in reverse order to 69 * the order in which the startables were started by StartAll. 70 * @param behavior Control which startables are started. 71 * @return True if successful, false otherwise. 72 */ 73 virtual bool StopAll(ControlBehavior behavior) = 0; 74 /** 75 * @brief Returns all startables currently being controlled. 76 */ 77 virtual BASE_NS::vector<IStartable::Ptr> GetAllStartables() const = 0; 78 /** 79 * @brief Sets the task queue id of the task queue which should be used to Start/Stop startables 80 * handled by the controller. 81 * @param startStartableQueueId Task queue id to use for starting startables. If {}, use current thread for all 82 * operations. 83 * @param stopStartableQueueId Task queue id to use for stopping startables. If {}, use current thread for all 84 * operations. Note that setting stopStartableQueueId may alter the order in which Detach and Stop operations 85 * happen for a startable which also implements IAttachment, as Stop operation is deferred to the given task 86 * queue. This may cause Stop to be called after Detach. 87 * @return True if queue id was valid, false otherise. 88 */ 89 virtual bool SetStartableQueueId( 90 const BASE_NS::Uid& startStartableQueueId, const BASE_NS::Uid& stopStartableQueueId) = 0; 91 /** 92 * @see SetStartableQueueId 93 */ 94 virtual bool SetStartableQueue( 95 const META_NS::ITaskQueue::Ptr& startStartableQueue, const META_NS::ITaskQueue::Ptr& stopStartableQueue) = 0; 96 /** 97 * @brief Starts all StartBehavior::AUTOMATIC startables 98 */ StartAll()99 bool StartAll() 100 { 101 return StartAll(ControlBehavior::CONTROL_AUTOMATIC); 102 } 103 /** 104 * @brief Stops all StartBehavior::AUTOMATIC startables 105 */ StopAll()106 bool StopAll() 107 { 108 return StopAll(ControlBehavior::CONTROL_AUTOMATIC); 109 } 110 }; 111 112 META_END_NAMESPACE() 113 114 #endif 115