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 #include "container_data_model.h"
17
18 #include <meta/api/make_callback.h>
19
META_BEGIN_NAMESPACE()20 META_BEGIN_NAMESPACE()
21
22 bool ContainerDataModel::Build(const IMetadata::Ptr&)
23 {
24 SetRequiredInterfaces({ IMetadata::UID });
25 OnContainerChanged()->AddHandler(MakeCallback<IOnChildChanged>([this](const ChildChangedInfo& info) {
26 if (info.type == ContainerChangeType::ADDED) {
27 Invoke<IOnDataAdded>(META_ACCESS_EVENT(OnDataAdded), DataModelIndex(info.to), 1);
28 } else if (info.type == ContainerChangeType::REMOVED) {
29 Invoke<IOnDataRemoved>(META_ACCESS_EVENT(OnDataRemoved), DataModelIndex(info.from), 1);
30 } else if (info.type == ContainerChangeType::MOVED) {
31 Invoke<IOnDataMoved>(META_ACCESS_EVENT(OnDataMoved), DataModelIndex(info.from), 1, DataModelIndex(info.to));
32 }
33 }));
34 return true;
35 }
36
GetModelData(const DataModelIndex & index) const37 IMetadata::ConstPtr ContainerDataModel::GetModelData(const DataModelIndex& index) const
38 {
39 return GetAt<IMetadata>(index.Index());
40 }
41
GetModelData(const DataModelIndex & index)42 IMetadata::Ptr ContainerDataModel::GetModelData(const DataModelIndex& index)
43 {
44 return GetAt<IMetadata>(index.Index());
45 }
46
GetSize(const DataModelIndex & index) const47 size_t ContainerDataModel::GetSize(const DataModelIndex& index) const
48 {
49 return CommonObjectContainerFwd::GetSize();
50 }
51
52 META_END_NAMESPACE()
53