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_IATTACHMENT_H 17 #define META_INTERFACE_IATTACHMENT_H 18 19 #include <base/containers/vector.h> 20 21 #include <meta/base/bit_field.h> 22 #include <meta/base/namespace.h> 23 #include <meta/base/shared_ptr.h> 24 #include <meta/base/types.h> 25 #include <meta/interface/interface_macros.h> 26 #include <meta/interface/intf_attach.h> 27 #include <meta/interface/intf_object.h> 28 29 META_BEGIN_NAMESPACE() 30 31 META_REGISTER_INTERFACE(IAttachment, "1f661207-4478-4fbb-ac1b-8ee73365d2d8") 32 /** 33 * @brief The IAttachment interface defines a common interface for classes which can be attached 34 * to objects that implement the IAttach interface. 35 * 36 * meta/attachment.h defines a helper class for implementing an object which implements 37 * the IAttachment interface. 38 */ 39 class IAttachment : public CORE_NS::IInterface { 40 META_INTERFACE(CORE_NS::IInterface, IAttachment) 41 public: 42 /** 43 * @brief The current data context. 44 */ 45 META_READONLY_PROPERTY(IObject::WeakPtr, DataContext); 46 /** 47 * @brief The object this attachment is attached to. 48 */ 49 META_READONLY_PROPERTY(IAttach::WeakPtr, AttachedTo); 50 /** 51 * @brief Called by the framework when an the attachment is being attached to an IObject. If this 52 * function succeeds, the object is attached to the target. 53 * @param object The IObject instance the attachment is attached to. 54 * @param dataContext The data context for this attachment. 55 * @note The data context can be the same object as the object being attached to, or 56 * something else. It is up to the attachment to decide how to handle them. 57 * @return The implementation should return true if the attachment can be attached to target object. 58 * If the attachment cannot be added, the implementation should return false. 59 */ 60 virtual bool Attaching(const IAttach::Ptr& target, const IObject::Ptr& dataContext) = 0; 61 /** 62 * @brief Detach the attachment from an object. 63 * @param object The object to attach to. 64 * @return If the attachment can be detached from the target, the implementation should return true. 65 * If detaching is not possible, the implementation should return false. In such a case the 66 * target may choose to not remove the attachment. During for example object destruction, 67 * the target will ignore the return value. 68 */ 69 virtual bool Detaching(const IAttach::Ptr& target) = 0; 70 }; 71 72 META_END_NAMESPACE() 73 74 META_INTERFACE_TYPE(META_NS::IAttachment); 75 76 #endif 77