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 #include "container_data_model.h" 16 17 #include <meta/api/make_callback.h> 18 META_BEGIN_NAMESPACE()19META_BEGIN_NAMESPACE() 20 21 bool ContainerDataModel::Build(const IMetadata::Ptr&) 22 { 23 SetRequiredInterfaces({ IMetadata::UID }); 24 OnAdded()->AddHandler(MakeCallback<IOnChildChanged>([this](const ChildChangedInfo& info) { 25 META_ACCESS_EVENT(OnDataAdded)->Invoke(DataModelIndex(info.index), 1); 26 })); 27 OnRemoved()->AddHandler(MakeCallback<IOnChildChanged>([this](const ChildChangedInfo& info) { 28 META_ACCESS_EVENT(OnDataRemoved)->Invoke(DataModelIndex(info.index), 1); 29 })); 30 OnMoved()->AddHandler(MakeCallback<IOnChildMoved>([this](const ChildMovedInfo& info) { 31 META_ACCESS_EVENT(OnDataMoved)->Invoke(DataModelIndex(info.from), 1, DataModelIndex(info.to)); 32 })); 33 return true; 34 } 35 GetModelData(const DataModelIndex & index) const36IMetadata::ConstPtr ContainerDataModel::GetModelData(const DataModelIndex& index) const 37 { 38 return GetAt<IMetadata>(index.Index()); 39 } 40 GetModelData(const DataModelIndex & index)41IMetadata::Ptr ContainerDataModel::GetModelData(const DataModelIndex& index) 42 { 43 return GetAt<IMetadata>(index.Index()); 44 } 45 GetSize(const DataModelIndex & index) const46size_t ContainerDataModel::GetSize(const DataModelIndex& index) const 47 { 48 return ObjectContainerFwd::GetSize(); 49 } 50 51 META_END_NAMESPACE() 52