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_H 17 #define META_INTERFACE_ISTARTABLE_H 18 19 #include <meta/base/interface_macros.h> 20 #include <meta/interface/interface_macros.h> 21 #include <meta/interface/intf_container.h> 22 23 META_BEGIN_NAMESPACE() 24 25 REGISTER_INTERFACE(IStartable, "b27ea024-7ebf-4d2a-a166-309bc0cf4d4f") 26 27 enum class StartBehavior : uint32_t { 28 /** The startable should not be started automatically */ 29 MANUAL = 0, 30 /** The startable should be started automatically when it has been made part of an object hierarchy 31 managed by a StartableObjectController. */ 32 AUTOMATIC = 1, 33 }; 34 35 enum class StartableState : uint32_t { 36 /** The startable has not been attached to a hierarchy. */ 37 DETACHED = 0, 38 /** The startable is part of a hierarchy but has not been started. */ 39 ATTACHED = 1, 40 /** The startable is started. */ 41 STARTED = 2 42 }; 43 44 META_END_NAMESPACE() 45 46 META_TYPE(META_NS::StartableState) 47 META_TYPE(META_NS::StartBehavior) 48 49 META_BEGIN_NAMESPACE() 50 51 /** 52 * @brief The IStartable interface can be implemented by objects which can be started and stopped. 53 * @note Usually IStartable is implemented by objects that are placed in an object hierarchy and 54 * whose running state is controller by an IStartableController implementation. 55 */ 56 class IStartable : public CORE_NS::IInterface { 57 META_INTERFACE(CORE_NS::IInterface, IStartable) 58 59 public: 60 /** 61 * @brief The startable mode. If StartBehavior::AUTOMATIC, the startable will be 62 * started automatically by a controller. 63 */ 64 META_PROPERTY(META_NS::StartBehavior, StartableMode) 65 /** 66 * @brief State of the startable. 67 */ 68 META_READONLY_PROPERTY(META_NS::StartableState, StartableState) 69 /** 70 * @brief Start the startable. 71 * @return True if successful, false otherwise. 72 */ 73 virtual bool Start() = 0; 74 /** 75 * @brief Stop the startable. 76 * @return True if successful, false otherwise. 77 */ 78 virtual bool Stop() = 0; 79 }; 80 81 META_END_NAMESPACE() 82 83 #endif 84