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_MODEL_IOBJECT_PROVIDER_H
17 #define META_INTERFACE_MODEL_IOBJECT_PROVIDER_H
18
19 #include <meta/base/namespace.h>
20 #include <meta/base/types.h>
21 #include <meta/interface/loaders/intf_content_loader.h>
22 #include <meta/interface/model/intf_data_model.h>
23
META_BEGIN_NAMESPACE()24 META_BEGIN_NAMESPACE()
25
26 /**
27 * @brief Generic object provider, creates objects based on model data,
28 */
29 class IObjectProvider : public CORE_NS::IInterface {
30 META_INTERFACE(CORE_NS::IInterface, IObjectProvider, "11a75ee4-c661-4a25-816a-b8fbfc4c4497")
31 public:
32 /**
33 * @brief Create object from model data at give location or null if not possible,
34 */
35 virtual IObject::Ptr CreateObject(const DataModelIndex& index) = 0;
36 /**
37 * @brief Dispose object that was created with CreateObject,
38 * Note: This allows the implementation to break bindings and/or recycle objects.
39 * @return true if the object is being reused.
40 */
41 virtual bool DisposeObject(const IObject::Ptr& item) = 0;
42
43 /**
44 * @brief Get count of objects in given dimension at given index.
45 */
46 virtual size_t GetObjectCount(const DataModelIndex& index) const = 0;
47
48 /**
49 * @brief Get count of objects in first dimension.
50 */
51 size_t GetObjectCount() const
52 {
53 return GetObjectCount(DataModelIndex {});
54 }
55
56 /**
57 * @brief Event when data is added to the underlying model.
58 */
59 META_EVENT(IOnDataAdded, OnDataAdded)
60 /**
61 * @brief Event when data is removed from the underlying model.
62 */
63 META_EVENT(IOnDataRemoved, OnDataRemoved)
64 /**
65 * @brief Event when data is moved in the underlying model.
66 */
67 META_EVENT(IOnDataMoved, OnDataMoved)
68 /**
69 * @brief Tell a hint to the implementation how many objects it should cache for reuse.
70 */
71 META_PROPERTY(size_t, CacheHint);
72 };
73
74 /**
75 * @brief Interface to set data model which is used for objects.
76 */
77 class IModelObjectProvider : public IObjectProvider {
78 META_INTERFACE(IObjectProvider, IModelObjectProvider, "e68b0f51-e66d-4f33-a7a2-b9b6dcf2bfe8")
79 public:
80 /**
81 * @brief Set data model from where the data is queried for created object.
82 * @return true on success.
83 */
84 virtual bool SetDataModel(const IDataModel::Ptr& model) = 0;
85 /**
86 * @brief Get previously set data model.
87 */
88 virtual IDataModel::Ptr GetDataModel() const = 0;
89 };
90
91 /**
92 * @brief Interface to set object's class uid which the IObjectProvider's CreateObject creates.
93 * Uses ObjectRegistry to instantiate the given type when needed.
94 */
95 class IInstantiatingObjectProvider : public CORE_NS::IInterface {
96 META_INTERFACE(CORE_NS::IInterface, IInstantiatingObjectProvider, "d6996e21-0f4d-4207-9c71-d7a3f141f566")
97 public:
98 /**
99 * @brief Set object's class uid which the IObjectProvider's CreateObject creates.
100 * @return true on success.
101 */
102 virtual bool SetObjectClassId(const ObjectId& id) = 0;
103 };
104
105 /**
106 * @brief Interface to set content loader which the IObjectProvider's CreateObject uses.
107 */
108 class IContentLoaderObjectProvider : public CORE_NS::IInterface {
109 META_INTERFACE(CORE_NS::IInterface, IContentLoaderObjectProvider, "d5f6507d-c823-436c-b45c-8e30ea9217e9")
110 public:
111 /**
112 * @brief Set content loader which the IObjectProvider's CreateObject uses.
113 * @return true on success.
114 */
115 virtual bool SetContentLoader(const IContentLoader::Ptr& loader) = 0;
116 };
117
118 META_END_NAMESPACE()
119
120 #endif
121