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_INTERFACE_ICLASS_REGISTRY_H
17 #define META_INTERFACE_ICLASS_REGISTRY_H
18 
19 #include <base/containers/vector.h>
20 #include <base/util/uid.h>
21 #include <core/plugin/intf_interface.h>
22 #include <core/plugin/intf_plugin.h>
23 #include <core/plugin/intf_plugin_register.h>
24 
25 #include <meta/interface/interface_macros.h>
26 #include <meta/interface/intf_object_factory.h>
27 #include <meta/interface/simple_event.h>
28 
29 META_BEGIN_NAMESPACE()
30 
31 META_REGISTER_INTERFACE(IOnClassRegistrationChanged, "3a91e751-551d-44a8-b68d-7c5638173efe")
32 META_REGISTER_INTERFACE(IOnClassRegistrationChangedCallable, "3285cc3e-f417-42d8-888d-3ed25faabfd1")
33 
34 struct IOnClassRegistrationChangedInfo {
35     constexpr static BASE_NS::Uid UID { META_NS::InterfaceId::IOnClassRegistrationChanged };
36     constexpr static char const* NAME { "OnClassRegistrationChanged" };
37 };
38 
39 /**
40  * @brief The ClassRegistrationInfo struct defines the parameters for an event which is invoked when
41  *        an object is registered to or unregistered from the class registry.
42  */
43 struct ClassRegistrationInfo {
44     /** ClassInfo of the class whose registration status changed */
45     IClassInfo::ConstPtr classInfo;
46 };
47 
48 using IOnClassRegistrationChanged =
49     META_NS::SimpleEvent<IOnClassRegistrationChangedInfo, void(const ClassRegistrationInfo&)>;
50 
51 /**
52  * @brief The IClassRegistry interface provides the functionality for class management via the object registry.
53  */
54 class IClassRegistry : public CORE_NS::IInterface {
55     META_INTERFACE(CORE_NS::IInterface, IClassRegistry, "cde99105-ea78-451d-a52d-06056ba13fd0")
56 public:
57     /**
58      * @brief Returns a list of all classes which implement the given interface requirements.
59      * @param interfaceUids List of interfaces a qualifying class shall implement.
60      * @param strict If true, the class must implement all listed interfaces. If false, it is enough if
61      *               the class implements any of the given interfaces.
62      */
63     virtual BASE_NS::vector<IClassInfo::ConstPtr> GetAllTypes(
64         const BASE_NS::vector<BASE_NS::Uid>& interfaceUids, bool strict, bool excludeDeprecated) const = 0;
65     /**
66      * @brief A helper for GetAllTypes(interfaceUids, strict) which always defines strict=true.
67      */
GetAllTypes(const BASE_NS::vector<BASE_NS::Uid> & interfaceUids)68     BASE_NS::vector<IClassInfo::ConstPtr> GetAllTypes(const BASE_NS::vector<BASE_NS::Uid>& interfaceUids) const
69     {
70         return GetAllTypes(interfaceUids, true, true);
71     }
72     /**
73      * @brief Invoked when a class is registered.
74      */
75     META_EVENT(IOnClassRegistrationChanged, OnClassRegistered)
76     /**
77      * @brief Invoked when a class is unregistered.
78      */
79     META_EVENT(IOnClassRegistrationChanged, OnClassUnregistered)
80 };
81 
82 META_END_NAMESPACE()
83 
84 META_TYPE(META_NS::ClassRegistrationInfo)
85 
86 #endif
87