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_ILIFECYCLE_H 17 #define META_INTERFACE_ILIFECYCLE_H 18 19 #include <core/plugin/intf_interface.h> 20 21 #include <meta/base/interface_macros.h> 22 #include <meta/base/types.h> 23 24 META_BEGIN_NAMESPACE() 25 26 class IMetadata; 27 28 META_REGISTER_INTERFACE(ILifecycle, "643ebb4f-bf7b-43b0-9900-9082b992ca0e") 29 /** 30 * @brief Interface for constructing and destructing objects 31 * Constructing: 32 * - Build is called automatically for all objects constructed by Object Registry, 33 * base-classes are build first and then derived. 34 * - Destroy is called automatically just before the object is about to be destroyed if META_IMPLEMENT_REF_COUNT has 35 * been used (This happens for each separate object in the hierarchy, the top most object first). 36 */ 37 class ILifecycle : public CORE_NS::IInterface { 38 META_INTERFACE(CORE_NS::IInterface, ILifecycle) 39 public: 40 /** 41 * @brief Called by the framework when this object should build its content. 42 * @param parameters User provided arbitrary parameters for construction. 43 * @return True if successful, otherwise false. 44 */ 45 virtual bool Build(const BASE_NS::shared_ptr<IMetadata>& parameters) = 0; 46 /** 47 * @brief Assign the instance UID. 48 * @warning This should ONLY be called during object creation, since framework automatically 49 * assigns a unique id for each new object. 50 * @param id New identity for object. 51 */ 52 virtual void SetInstanceId(InstanceId) = 0; 53 /** 54 * @brief Called by the framework when this object is about to be destroyed 55 */ 56 virtual void Destroy() = 0; 57 }; 58 59 META_END_NAMESPACE() 60 61 #endif 62