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_API_CONTAINER_OBSERVER_H 17 #define META_API_CONTAINER_OBSERVER_H 18 19 #include <meta/api/internal/object_api.h> 20 #include <meta/api/make_callback.h> 21 #include <meta/interface/builtin_objects.h> 22 #include <meta/interface/intf_container_observer.h> 23 META_BEGIN_NAMESPACE()24META_BEGIN_NAMESPACE() 25 26 /** 27 * @brief The ContainerObserver class provides a wrapper for META_NS::ClassId::ContainerObserver. 28 */ 29 class ContainerObserver final 30 : public Internal::ObjectInterfaceAPI<ContainerObserver, META_NS::ClassId::ContainerObserver> { 31 META_API(ContainerObserver) 32 META_API_CACHE_INTERFACE(META_NS::IContainerObserver, Observer) 33 public: 34 /** 35 * @brief See IContainerObserver::SetContainer. 36 */ 37 auto& Container(const IContainer::Ptr& container) 38 { 39 META_API_CALL_INTERFACE(Observer, SetContainer(container)); 40 return *this; 41 } 42 /** 43 * @brief See IContainerObserver::OnDescendantAdded. 44 */ 45 template<class Callback> 46 auto& OnDescendantChanged(Callback&& callback) 47 { 48 if (auto p = META_API_CALL_INTERFACE(Observer, OnDescendantChanged())) { 49 p->AddHandler(META_NS::MakeCallback<META_NS::IOnChildChanged>(BASE_NS::forward<Callback>(callback))); 50 } 51 return *this; 52 } 53 }; 54 55 META_END_NAMESPACE() 56 57 #endif // META_API_CONTAINER_OBSERVER_H 58