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