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()24 META_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_CACHED_INTERFACE(Observer)->SetContainer(container);
40         return *this;
41     }
42     /**
43      * @brief See IContainerObserver::OnDescendantAdded.
44      */
45     template<class Callback>
46     auto& OnDescendantAdded(Callback&& callback)
47     {
48         META_API_CACHED_INTERFACE(Observer)->OnDescendantAdded()->AddHandler(
49             META_NS::MakeCallback<META_NS::IOnChildChanged>(BASE_NS::forward<Callback>(callback)));
50         return *this;
51     }
52     /**
53      * @brief See IContainerObserver::OnDescendantRemoved.
54      */
55     template<class Callback>
56     auto& OnDescendantRemoved(Callback&& callback)
57     {
58         META_API_CACHED_INTERFACE(Observer)->OnDescendantRemoved()->AddHandler(
59             META_NS::MakeCallback<META_NS::IOnChildChanged>(BASE_NS::forward<Callback>(callback)));
60         return *this;
61     }
62     /**
63      * @brief See IContainerObserver::OnDescendantMoved.
64      */
65     template<class Callback>
66     auto& OnDescendantMoved(Callback&& callback)
67     {
68         META_API_CACHED_INTERFACE(Observer)->OnDescendantMoved()->AddHandler(
69             META_NS::MakeCallback<META_NS::IOnChildMoved>(BASE_NS::forward<Callback>(callback)));
70         return *this;
71     }
72 };
73 
74 META_END_NAMESPACE()
75 
76 #endif // META_API_CONTAINER_OBSERVER_H
77