• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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(IAttachable, "99570418-e6b0-4221-bb7e-e86a77a17cfb")
32 META_REGISTER_INTERFACE(IAttachment, "1f661207-4478-4fbb-ac1b-8ee73365d2d8")
33 
34 class IAttachable : public CORE_NS::IInterface {
35     META_INTERFACE(CORE_NS::IInterface, IAttachable)
36 public:
37     /**
38      * @brief Called by the framework when an the attachment is being attached to an IObject. If this
39      *        function succeeds, the object is attached to the target.
40      * @param object The IObject instance the attachment is attached to.
41      * @param dataContext The data context for this attachment.
42      * @note The data context can be the same object as the object being attached to, or
43      *       something else. It is up to the attachment to decide how to handle them.
44      * @return The implementation should return true if the attachment can be attached to target object.
45      *         If the attachment cannot be added, the implementation should return false.
46      */
47     virtual bool Attaching(const IAttach::Ptr& target, const IObject::Ptr& dataContext) = 0;
48     /**
49      * @brief Detach the attachment from an object.
50      * @param object The object to attach to.
51      * @return If the attachment can be detached from the target, the implementation should return true.
52      *         If detaching is not possible, the implementation should return false. In such a case the
53      *         target may choose to not remove the attachment. During for example object destruction,
54      *         the target will ignore the return value.
55      */
56     virtual bool Detaching(const IAttach::Ptr& target) = 0;
57 };
58 
59 /**
60  * @brief The IAttachment interface defines a common interface for classes which can be attached
61  *        to objects that implement the IAttach interface.
62  *
63  *        meta/attachment.h defines a helper class for implementing an object which implements
64  *        the IAttachment interface.
65  */
66 class IAttachment : public IAttachable {
67     META_INTERFACE(IAttachable, IAttachment)
68 public:
69     /**
70      * @brief The current data context.
71      */
72     META_READONLY_PROPERTY(IObject::WeakPtr, DataContext);
73     /**
74      * @brief The object this attachment is attached to.
75      */
76     META_READONLY_PROPERTY(IAttach::WeakPtr, AttachedTo);
77 };
78 
79 META_END_NAMESPACE()
80 
81 META_INTERFACE_TYPE(META_NS::IAttachable)
82 META_INTERFACE_TYPE(META_NS::IAttachment)
83 
84 #endif
85