18bf80f4bSopenharmony_ci/*
28bf80f4bSopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd.
38bf80f4bSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
48bf80f4bSopenharmony_ci * you may not use this file except in compliance with the License.
58bf80f4bSopenharmony_ci * You may obtain a copy of the License at
68bf80f4bSopenharmony_ci *
78bf80f4bSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
88bf80f4bSopenharmony_ci *
98bf80f4bSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
108bf80f4bSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
118bf80f4bSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
128bf80f4bSopenharmony_ci * See the License for the specific language governing permissions and
138bf80f4bSopenharmony_ci * limitations under the License.
148bf80f4bSopenharmony_ci */
158bf80f4bSopenharmony_ci
168bf80f4bSopenharmony_ci#ifndef META_EXT_OBJECT_H
178bf80f4bSopenharmony_ci#define META_EXT_OBJECT_H
188bf80f4bSopenharmony_ci
198bf80f4bSopenharmony_ci#include <base/util/uid_util.h>
208bf80f4bSopenharmony_ci
218bf80f4bSopenharmony_ci#include <meta/base/interface_macros.h>
228bf80f4bSopenharmony_ci#include <meta/base/namespace.h>
238bf80f4bSopenharmony_ci#include <meta/base/types.h>
248bf80f4bSopenharmony_ci#include <meta/ext/implementation_macros.h>
258bf80f4bSopenharmony_ci#include <meta/ext/metadata_helpers.h>
268bf80f4bSopenharmony_ci#include <meta/ext/object_factory.h>
278bf80f4bSopenharmony_ci#include <meta/interface/interface_helpers.h>
288bf80f4bSopenharmony_ci#include <meta/interface/intf_attachment.h>
298bf80f4bSopenharmony_ci#include <meta/interface/intf_container_query.h>
308bf80f4bSopenharmony_ci#include <meta/interface/intf_derived.h>
318bf80f4bSopenharmony_ci#include <meta/interface/intf_lifecycle.h>
328bf80f4bSopenharmony_ci#include <meta/interface/intf_metadata.h>
338bf80f4bSopenharmony_ci#include <meta/interface/intf_object.h>
348bf80f4bSopenharmony_ci#include <meta/interface/intf_object_context.h>
358bf80f4bSopenharmony_ci#include <meta/interface/intf_object_flags.h>
368bf80f4bSopenharmony_ci#include <meta/interface/intf_object_registry.h>
378bf80f4bSopenharmony_ci#include <meta/interface/property/intf_property.h>
388bf80f4bSopenharmony_ci#include <meta/interface/static_object_metadata.h>
398bf80f4bSopenharmony_ci
408bf80f4bSopenharmony_ci#include "object_factory.h"
418bf80f4bSopenharmony_ci
428bf80f4bSopenharmony_ciMETA_BEGIN_NAMESPACE()
438bf80f4bSopenharmony_cinamespace Internal {
448bf80f4bSopenharmony_ci// dummy pure virtual to shutup compiler warnings
458bf80f4bSopenharmony_ciclass DummyGetObjectRegistry {
468bf80f4bSopenharmony_ci    virtual META_NS::IObjectRegistry& GetObjectRegistry() = 0;
478bf80f4bSopenharmony_ci};
488bf80f4bSopenharmony_ci} // namespace Internal
498bf80f4bSopenharmony_ci
508bf80f4bSopenharmony_ci/**
518bf80f4bSopenharmony_ci * @brief A helper template class for implementing a class which implements a basic set of object interfaces.
528bf80f4bSopenharmony_ci * @note Usually when inheriting from this template directly SuperClassInfo should be META_NS::ClassId::BaseObject.
538bf80f4bSopenharmony_ci */
548bf80f4bSopenharmony_citemplate<class FinalClass, const META_NS::ClassInfo& ClassInfo, const META_NS::ClassInfo& SuperClassInfo,
558bf80f4bSopenharmony_ci    class... Interfaces>
568bf80f4bSopenharmony_ciclass BaseObjectFwd : public IntroduceInterfaces<IObjectInstance, IObjectFlags, IDerived, ILifecycle, Interfaces...>,
578bf80f4bSopenharmony_ci                      private Internal::DummyGetObjectRegistry {
588bf80f4bSopenharmony_ci    using Fwd = BaseObjectFwd;
598bf80f4bSopenharmony_ci    using Super = IntroduceInterfaces<IObjectInstance, IObjectFlags, IDerived, ILifecycle, Interfaces...>;
608bf80f4bSopenharmony_ci
618bf80f4bSopenharmony_cipublic:
628bf80f4bSopenharmony_ci    // using declaration doesn't work with vc, still thinks the function access is protected
638bf80f4bSopenharmony_ci    CORE_NS::IInterface* GetInterface(const BASE_NS::Uid& uid) override
648bf80f4bSopenharmony_ci    {
658bf80f4bSopenharmony_ci        return Super::GetInterface(uid);
668bf80f4bSopenharmony_ci    }
678bf80f4bSopenharmony_ci    const CORE_NS::IInterface* GetInterface(const BASE_NS::Uid& uid) const override
688bf80f4bSopenharmony_ci    {
698bf80f4bSopenharmony_ci        return Super::GetInterface(uid);
708bf80f4bSopenharmony_ci    }
718bf80f4bSopenharmony_ci    template<typename Type>
728bf80f4bSopenharmony_ci    constexpr Type* GetInterface() noexcept
738bf80f4bSopenharmony_ci    {
748bf80f4bSopenharmony_ci        return static_cast<Type*>(Super::StaticGetInterface(Type::UID));
758bf80f4bSopenharmony_ci    }
768bf80f4bSopenharmony_ci    template<typename Type>
778bf80f4bSopenharmony_ci    constexpr const Type* GetInterface() const noexcept
788bf80f4bSopenharmony_ci    {
798bf80f4bSopenharmony_ci        auto* me = const_cast<BaseObjectFwd*>(this);
808bf80f4bSopenharmony_ci        return static_cast<const Type*>(me->StaticGetInterface(Type::UID));
818bf80f4bSopenharmony_ci    }
828bf80f4bSopenharmony_ci
838bf80f4bSopenharmony_cipublic:
848bf80f4bSopenharmony_ci    META_DEFINE_OBJECT_TYPE_INFO(FinalClass, ClassInfo)
858bf80f4bSopenharmony_ci
868bf80f4bSopenharmony_cipublic:
878bf80f4bSopenharmony_ci    META_NS::IObjectRegistry& GetObjectRegistry() override
888bf80f4bSopenharmony_ci    {
898bf80f4bSopenharmony_ci        return META_NS::GetObjectRegistry();
908bf80f4bSopenharmony_ci    }
918bf80f4bSopenharmony_ci
928bf80f4bSopenharmony_ci    static const StaticObjectMetadata& GetStaticObjectMetadata()
938bf80f4bSopenharmony_ci    {
948bf80f4bSopenharmony_ci        return StaticObjectMeta();
958bf80f4bSopenharmony_ci    }
968bf80f4bSopenharmony_ci
978bf80f4bSopenharmony_cipublic: // IObject
988bf80f4bSopenharmony_ci    BASE_NS::string_view GetClassName() const override
998bf80f4bSopenharmony_ci    {
1008bf80f4bSopenharmony_ci        return ClassInfo.Name();
1018bf80f4bSopenharmony_ci    }
1028bf80f4bSopenharmony_ci    InstanceId GetInstanceId() const override
1038bf80f4bSopenharmony_ci    {
1048bf80f4bSopenharmony_ci        return object_->GetInstanceId();
1058bf80f4bSopenharmony_ci    }
1068bf80f4bSopenharmony_ci    ObjectId GetClassId() const override
1078bf80f4bSopenharmony_ci    {
1088bf80f4bSopenharmony_ci        return ClassInfo.Id();
1098bf80f4bSopenharmony_ci    }
1108bf80f4bSopenharmony_ci    BASE_NS::string GetName() const override
1118bf80f4bSopenharmony_ci    {
1128bf80f4bSopenharmony_ci        return object_->GetName();
1138bf80f4bSopenharmony_ci    }
1148bf80f4bSopenharmony_ci    IObject::Ptr Resolve(const RefUri& uri) const override
1158bf80f4bSopenharmony_ci    {
1168bf80f4bSopenharmony_ci        return object_->Resolve(uri);
1178bf80f4bSopenharmony_ci    }
1188bf80f4bSopenharmony_ci    template<typename Interface>
1198bf80f4bSopenharmony_ci    typename Interface::Ptr Resolve(const RefUri& uri) const
1208bf80f4bSopenharmony_ci    {
1218bf80f4bSopenharmony_ci        return interface_pointer_cast<Interface>(object_->Resolve(uri));
1228bf80f4bSopenharmony_ci    }
1238bf80f4bSopenharmony_ci    IObject::Ptr GetSelf() const override
1248bf80f4bSopenharmony_ci    {
1258bf80f4bSopenharmony_ci        return object_ ? object_->GetSelf() : nullptr;
1268bf80f4bSopenharmony_ci    }
1278bf80f4bSopenharmony_ci    template<typename Interface>
1288bf80f4bSopenharmony_ci    typename Interface::Ptr GetSelf() const
1298bf80f4bSopenharmony_ci    {
1308bf80f4bSopenharmony_ci        return interface_pointer_cast<Interface>(GetSelf());
1318bf80f4bSopenharmony_ci    }
1328bf80f4bSopenharmony_ci    BASE_NS::vector<BASE_NS::Uid> GetInterfaces() const override
1338bf80f4bSopenharmony_ci    {
1348bf80f4bSopenharmony_ci        return GetStaticInterfaces();
1358bf80f4bSopenharmony_ci    }
1368bf80f4bSopenharmony_ci
1378bf80f4bSopenharmony_ci    static BASE_NS::vector<BASE_NS::Uid> GetStaticInterfaces()
1388bf80f4bSopenharmony_ci    {
1398bf80f4bSopenharmony_ci        return Super::GetInterfacesVector();
1408bf80f4bSopenharmony_ci    }
1418bf80f4bSopenharmony_ci
1428bf80f4bSopenharmony_cipublic: // IObjectFlags
1438bf80f4bSopenharmony_ci    ObjectFlagBitsValue GetObjectFlags() const override
1448bf80f4bSopenharmony_ci    {
1458bf80f4bSopenharmony_ci        if (auto flags = interface_cast<IObjectFlags>(object_)) {
1468bf80f4bSopenharmony_ci            return flags->GetObjectFlags();
1478bf80f4bSopenharmony_ci        }
1488bf80f4bSopenharmony_ci        return {};
1498bf80f4bSopenharmony_ci    }
1508bf80f4bSopenharmony_ci    void SetObjectFlags(const ObjectFlagBitsValue& value) override
1518bf80f4bSopenharmony_ci    {
1528bf80f4bSopenharmony_ci        if (auto flags = interface_cast<IObjectFlags>(object_)) {
1538bf80f4bSopenharmony_ci            flags->SetObjectFlags(value);
1548bf80f4bSopenharmony_ci        }
1558bf80f4bSopenharmony_ci    }
1568bf80f4bSopenharmony_ci    ObjectFlagBitsValue GetObjectDefaultFlags() const override
1578bf80f4bSopenharmony_ci    {
1588bf80f4bSopenharmony_ci        if (auto flags = interface_cast<IObjectFlags>(object_)) {
1598bf80f4bSopenharmony_ci            return flags->GetObjectDefaultFlags();
1608bf80f4bSopenharmony_ci        }
1618bf80f4bSopenharmony_ci        return {};
1628bf80f4bSopenharmony_ci    }
1638bf80f4bSopenharmony_ci
1648bf80f4bSopenharmony_ciprotected: // ILifecycle
1658bf80f4bSopenharmony_ci    bool Build(const IMetadata::Ptr& data) override
1668bf80f4bSopenharmony_ci    {
1678bf80f4bSopenharmony_ci#ifdef _DEBUG
1688bf80f4bSopenharmony_ci        // Object registry calls this
1698bf80f4bSopenharmony_ci        if (buildCalled_) {
1708bf80f4bSopenharmony_ci            CORE_LOG_E("Do not call Build explicitly from derived class!");
1718bf80f4bSopenharmony_ci        }
1728bf80f4bSopenharmony_ci        buildCalled_ = true;
1738bf80f4bSopenharmony_ci#endif
1748bf80f4bSopenharmony_ci        return true;
1758bf80f4bSopenharmony_ci    }
1768bf80f4bSopenharmony_ci
1778bf80f4bSopenharmony_ci    void SetInstanceId(InstanceId uid) override
1788bf80f4bSopenharmony_ci    {
1798bf80f4bSopenharmony_ci        // Object registry does this
1808bf80f4bSopenharmony_ci    }
1818bf80f4bSopenharmony_ci    void Destroy() override
1828bf80f4bSopenharmony_ci    {
1838bf80f4bSopenharmony_ci        if (auto builder = interface_cast<META_NS::ILifecycle>(object_)) {
1848bf80f4bSopenharmony_ci            builder->Destroy();
1858bf80f4bSopenharmony_ci        }
1868bf80f4bSopenharmony_ci    }
1878bf80f4bSopenharmony_ci
1888bf80f4bSopenharmony_ciprotected: // IDerived
1898bf80f4bSopenharmony_ci    void SetSuperInstance(const META_NS::IObject::Ptr& /*aggr*/, const META_NS::IObject::Ptr& super) override
1908bf80f4bSopenharmony_ci    {
1918bf80f4bSopenharmony_ci#ifdef _DEBUG
1928bf80f4bSopenharmony_ci        // Object registry calls this
1938bf80f4bSopenharmony_ci        if (object_) {
1948bf80f4bSopenharmony_ci            CORE_LOG_E("Do not call SetSuperInstance explicitly from derived class!");
1958bf80f4bSopenharmony_ci        }
1968bf80f4bSopenharmony_ci#endif
1978bf80f4bSopenharmony_ci        if (IsFirstInit()) {
1988bf80f4bSopenharmony_ci            if (auto i = interface_cast<IMetadataInternal>(super)) {
1998bf80f4bSopenharmony_ci                StaticObjectMeta().baseclass = &i->GetStaticMetadata();
2008bf80f4bSopenharmony_ci            }
2018bf80f4bSopenharmony_ci        }
2028bf80f4bSopenharmony_ci
2038bf80f4bSopenharmony_ci        object_ = interface_pointer_cast<IObjectInstance>(super); // Save the strong reference to super.
2048bf80f4bSopenharmony_ci    }
2058bf80f4bSopenharmony_ci    BASE_NS::Uid GetSuperClassUid() const override
2068bf80f4bSopenharmony_ci    {
2078bf80f4bSopenharmony_ci        return SuperClassInfo.Id().ToUid();
2088bf80f4bSopenharmony_ci    }
2098bf80f4bSopenharmony_ci
2108bf80f4bSopenharmony_ciprotected:
2118bf80f4bSopenharmony_ci    bool IsFirstInit()
2128bf80f4bSopenharmony_ci    {
2138bf80f4bSopenharmony_ci        static bool init = (isFirstInit_ = true);
2148bf80f4bSopenharmony_ci        return isFirstInit_;
2158bf80f4bSopenharmony_ci    }
2168bf80f4bSopenharmony_ci
2178bf80f4bSopenharmony_ci    template<typename Type>
2188bf80f4bSopenharmony_ci    nullptr_t RegisterStaticPropertyMetadata(const META_NS::InterfaceInfo& intf, BASE_NS::string_view name,
2198bf80f4bSopenharmony_ci        ObjectFlagBitsValue flags, Internal::PCtor* ctor, Internal::PMemberInit* init)
2208bf80f4bSopenharmony_ci    {
2218bf80f4bSopenharmony_ci        if (IsFirstInit()) {
2228bf80f4bSopenharmony_ci            StaticObjectMeta().properties.push_back(
2238bf80f4bSopenharmony_ci                PropertyMetadata { name, intf, flags, UidFromType<Type>(), ctor, init });
2248bf80f4bSopenharmony_ci        }
2258bf80f4bSopenharmony_ci        return nullptr;
2268bf80f4bSopenharmony_ci    }
2278bf80f4bSopenharmony_ci
2288bf80f4bSopenharmony_ci    template<typename Type>
2298bf80f4bSopenharmony_ci    nullptr_t RegisterStaticEventMetadata(const META_NS::InterfaceInfo& intf, BASE_NS::string_view name,
2308bf80f4bSopenharmony_ci        Internal::ECtor* ctor, Internal::EMemberInit* init)
2318bf80f4bSopenharmony_ci    {
2328bf80f4bSopenharmony_ci        if (IsFirstInit()) {
2338bf80f4bSopenharmony_ci            StaticObjectMeta().events.push_back(EventMetadata { name, intf, Type::UID, ctor, init });
2348bf80f4bSopenharmony_ci        }
2358bf80f4bSopenharmony_ci        return nullptr;
2368bf80f4bSopenharmony_ci    }
2378bf80f4bSopenharmony_ci
2388bf80f4bSopenharmony_ci    nullptr_t RegisterStaticFunctionMetadata(const META_NS::InterfaceInfo& intf, BASE_NS::string_view name,
2398bf80f4bSopenharmony_ci        Internal::FCtor* ctor, Internal::FContext* context)
2408bf80f4bSopenharmony_ci    {
2418bf80f4bSopenharmony_ci        if (IsFirstInit()) {
2428bf80f4bSopenharmony_ci            StaticObjectMeta().functions.push_back(FunctionMetadata { name, intf, ctor, context });
2438bf80f4bSopenharmony_ci        }
2448bf80f4bSopenharmony_ci        return nullptr;
2458bf80f4bSopenharmony_ci    }
2468bf80f4bSopenharmony_ci
2478bf80f4bSopenharmony_ciprotected:
2488bf80f4bSopenharmony_ci    static StaticObjectMetadata& StaticObjectMeta()
2498bf80f4bSopenharmony_ci    {
2508bf80f4bSopenharmony_ci        static StaticObjectMetadata meta { ClassInfo, nullptr };
2518bf80f4bSopenharmony_ci        return meta;
2528bf80f4bSopenharmony_ci    }
2538bf80f4bSopenharmony_ci
2548bf80f4bSopenharmony_ci    IObject::Ptr GetBase() const noexcept
2558bf80f4bSopenharmony_ci    {
2568bf80f4bSopenharmony_ci        return object_;
2578bf80f4bSopenharmony_ci    }
2588bf80f4bSopenharmony_ci
2598bf80f4bSopenharmony_ci    template<typename Type>
2608bf80f4bSopenharmony_ci    constexpr Type* GetBaseAs()
2618bf80f4bSopenharmony_ci    {
2628bf80f4bSopenharmony_ci        auto* t = object_->GetInterface<Type>();
2638bf80f4bSopenharmony_ci        CORE_ASSERT_MSG(t, "Invalid interface %s for base", BASE_NS::to_string(Type::UID).c_str());
2648bf80f4bSopenharmony_ci        return t;
2658bf80f4bSopenharmony_ci    }
2668bf80f4bSopenharmony_ci    template<typename Type>
2678bf80f4bSopenharmony_ci    constexpr const Type* GetBaseAs() const
2688bf80f4bSopenharmony_ci    {
2698bf80f4bSopenharmony_ci        return const_cast<BaseObjectFwd*>(this)->GetBaseAs<Type>();
2708bf80f4bSopenharmony_ci    }
2718bf80f4bSopenharmony_ci
2728bf80f4bSopenharmony_ciprotected:
2738bf80f4bSopenharmony_ci    BaseObjectFwd() = default;
2748bf80f4bSopenharmony_ci    ~BaseObjectFwd() override = default;
2758bf80f4bSopenharmony_ci    META_NO_COPY_MOVE(BaseObjectFwd)
2768bf80f4bSopenharmony_ci
2778bf80f4bSopenharmony_ciprivate:
2788bf80f4bSopenharmony_ci    bool isFirstInit_ {};
2798bf80f4bSopenharmony_ci    IObjectInstance::Ptr object_;
2808bf80f4bSopenharmony_ci#ifdef _DEBUG
2818bf80f4bSopenharmony_ci    bool buildCalled_ {};
2828bf80f4bSopenharmony_ci#endif
2838bf80f4bSopenharmony_ci};
2848bf80f4bSopenharmony_ci
2858bf80f4bSopenharmony_ci/**
2868bf80f4bSopenharmony_ci * @brief A helper macro for classes deriving from BaseObjectFwd. Makes a forwarder for an interface
2878bf80f4bSopenharmony_ci *        property implemented by the super class.
2888bf80f4bSopenharmony_ci */
2898bf80f4bSopenharmony_ci#define META_EXT_BASE_READONLY_PROPERTY(Interface, Type, Name) \
2908bf80f4bSopenharmony_ci    META_FORWARD_READONLY_PROPERTY(Type, Name, Super::template GetBaseAs<Interface>()->Name())
2918bf80f4bSopenharmony_ci
2928bf80f4bSopenharmony_ci/**
2938bf80f4bSopenharmony_ci * @brief A helper macro for classes deriving from BaseObjectFwd. Makes a forwarder for an interface
2948bf80f4bSopenharmony_ci *        property defined by the super class.
2958bf80f4bSopenharmony_ci */
2968bf80f4bSopenharmony_ci#define META_EXT_BASE_PROPERTY(Interface, Type, Name) \
2978bf80f4bSopenharmony_ci    META_FORWARD_PROPERTY(Type, Name, Super::template GetBaseAs<Interface>()->Name())
2988bf80f4bSopenharmony_ci
2998bf80f4bSopenharmony_ci/**
3008bf80f4bSopenharmony_ci * @brief A helper macro for classes deriving from BaseObjectFwd. Calls a method through an interface defined
3018bf80f4bSopenharmony_ci *        by the super class.
3028bf80f4bSopenharmony_ci */
3038bf80f4bSopenharmony_ci#define META_EXT_CALL_BASE(Interface, Function) Super::template GetBaseAs<Interface>()->Function
3048bf80f4bSopenharmony_ci
3058bf80f4bSopenharmony_ci/**
3068bf80f4bSopenharmony_ci * @brief A helper template class for implementing a class which implements a basic set of object interfaces with
3078bf80f4bSopenharmony_ci *        the addition of Metadata related interfaces.
3088bf80f4bSopenharmony_ci * @note Usually when inheriting from this template directly SuperClassInfo should be META_NS::ClassId::MetaObject.
3098bf80f4bSopenharmony_ci */
3108bf80f4bSopenharmony_citemplate<class FinalClass, const META_NS::ClassInfo& ClassInfo, const META_NS::ClassInfo& SuperClassInfo,
3118bf80f4bSopenharmony_ci    class... Interfaces>
3128bf80f4bSopenharmony_ciclass MetaObjectFwd : public BaseObjectFwd<FinalClass, ClassInfo, SuperClassInfo, IMetadata, IMetadataInternal,
3138bf80f4bSopenharmony_ci                          IObjectContextProvider, Interfaces...> {
3148bf80f4bSopenharmony_ci    using Super = BaseObjectFwd<FinalClass, ClassInfo, SuperClassInfo, IMetadata, IMetadataInternal,
3158bf80f4bSopenharmony_ci        IObjectContextProvider, Interfaces...>;
3168bf80f4bSopenharmony_ci
3178bf80f4bSopenharmony_ciprotected: // IMetadata
3188bf80f4bSopenharmony_ci    IContainer::Ptr GetPropertyContainer() override
3198bf80f4bSopenharmony_ci    {
3208bf80f4bSopenharmony_ci        return meta_->GetPropertyContainer();
3218bf80f4bSopenharmony_ci    }
3228bf80f4bSopenharmony_ci
3238bf80f4bSopenharmony_ci    IContainer::ConstPtr GetPropertyContainer() const override
3248bf80f4bSopenharmony_ci    {
3258bf80f4bSopenharmony_ci        return meta_->GetPropertyContainer();
3268bf80f4bSopenharmony_ci    }
3278bf80f4bSopenharmony_ci
3288bf80f4bSopenharmony_ciprotected:
3298bf80f4bSopenharmony_ci    IMetadata::Ptr CloneMetadata() const override
3308bf80f4bSopenharmony_ci    {
3318bf80f4bSopenharmony_ci        return meta_->CloneMetadata();
3328bf80f4bSopenharmony_ci    }
3338bf80f4bSopenharmony_ci    void AddProperty(const IProperty::Ptr& p) override
3348bf80f4bSopenharmony_ci    {
3358bf80f4bSopenharmony_ci        auto self = Super::GetSelf();
3368bf80f4bSopenharmony_ci        if (self) {
3378bf80f4bSopenharmony_ci            if (auto pp = interface_pointer_cast<IPropertyInternal>(p)) {
3388bf80f4bSopenharmony_ci                pp->SetOwner(self);
3398bf80f4bSopenharmony_ci            }
3408bf80f4bSopenharmony_ci        }
3418bf80f4bSopenharmony_ci        meta_->AddProperty(p);
3428bf80f4bSopenharmony_ci    }
3438bf80f4bSopenharmony_ci    void RemoveProperty(const IProperty::Ptr& p) override
3448bf80f4bSopenharmony_ci    {
3458bf80f4bSopenharmony_ci        meta_->RemoveProperty(p);
3468bf80f4bSopenharmony_ci    }
3478bf80f4bSopenharmony_ci    void AddFunction(const IFunction::Ptr& p) override
3488bf80f4bSopenharmony_ci    {
3498bf80f4bSopenharmony_ci        meta_->AddFunction(p);
3508bf80f4bSopenharmony_ci    }
3518bf80f4bSopenharmony_ci    void RemoveFunction(const IFunction::Ptr& p) override
3528bf80f4bSopenharmony_ci    {
3538bf80f4bSopenharmony_ci        meta_->RemoveFunction(p);
3548bf80f4bSopenharmony_ci    }
3558bf80f4bSopenharmony_ci    void AddEvent(const IEvent::Ptr& p) override
3568bf80f4bSopenharmony_ci    {
3578bf80f4bSopenharmony_ci        meta_->AddEvent(p);
3588bf80f4bSopenharmony_ci    }
3598bf80f4bSopenharmony_ci    void RemoveEvent(const IEvent::Ptr& p) override
3608bf80f4bSopenharmony_ci    {
3618bf80f4bSopenharmony_ci        meta_->RemoveEvent(p);
3628bf80f4bSopenharmony_ci    }
3638bf80f4bSopenharmony_ci    void SetProperties(const BASE_NS::vector<IProperty::Ptr>& vec) override
3648bf80f4bSopenharmony_ci    {
3658bf80f4bSopenharmony_ci        meta_->SetProperties(vec);
3668bf80f4bSopenharmony_ci    }
3678bf80f4bSopenharmony_ci    void Merge(const IMetadata::Ptr& data) override
3688bf80f4bSopenharmony_ci    {
3698bf80f4bSopenharmony_ci        meta_->Merge(data);
3708bf80f4bSopenharmony_ci    }
3718bf80f4bSopenharmony_ci    BASE_NS::vector<META_NS::IProperty::Ptr> GetAllProperties() override
3728bf80f4bSopenharmony_ci    {
3738bf80f4bSopenharmony_ci        return meta_->GetAllProperties();
3748bf80f4bSopenharmony_ci    }
3758bf80f4bSopenharmony_ci    BASE_NS::vector<META_NS::IProperty::ConstPtr> GetAllProperties() const override
3768bf80f4bSopenharmony_ci    {
3778bf80f4bSopenharmony_ci        return static_cast<const IMetadata*>(meta_.get())->GetAllProperties();
3788bf80f4bSopenharmony_ci    }
3798bf80f4bSopenharmony_ci    BASE_NS::vector<IFunction::Ptr> GetAllFunctions() override
3808bf80f4bSopenharmony_ci    {
3818bf80f4bSopenharmony_ci        return meta_->GetAllFunctions();
3828bf80f4bSopenharmony_ci    }
3838bf80f4bSopenharmony_ci    BASE_NS::vector<IFunction::ConstPtr> GetAllFunctions() const override
3848bf80f4bSopenharmony_ci    {
3858bf80f4bSopenharmony_ci        return static_cast<const IMetadata*>(meta_.get())->GetAllFunctions();
3868bf80f4bSopenharmony_ci    }
3878bf80f4bSopenharmony_ci    BASE_NS::vector<IEvent::Ptr> GetAllEvents() override
3888bf80f4bSopenharmony_ci    {
3898bf80f4bSopenharmony_ci        return meta_->GetAllEvents();
3908bf80f4bSopenharmony_ci    }
3918bf80f4bSopenharmony_ci    BASE_NS::vector<IEvent::ConstPtr> GetAllEvents() const override
3928bf80f4bSopenharmony_ci    {
3938bf80f4bSopenharmony_ci        return static_cast<const IMetadata*>(meta_.get())->GetAllEvents();
3948bf80f4bSopenharmony_ci    }
3958bf80f4bSopenharmony_ci
3968bf80f4bSopenharmony_ci    IProperty::Ptr GetPropertyByName(BASE_NS::string_view name) override
3978bf80f4bSopenharmony_ci    {
3988bf80f4bSopenharmony_ci        return meta_->GetPropertyByName(name);
3998bf80f4bSopenharmony_ci    }
4008bf80f4bSopenharmony_ci    IProperty::ConstPtr GetPropertyByName(BASE_NS::string_view name) const override
4018bf80f4bSopenharmony_ci    {
4028bf80f4bSopenharmony_ci        return meta_->GetPropertyByName(name);
4038bf80f4bSopenharmony_ci    }
4048bf80f4bSopenharmony_ci
4058bf80f4bSopenharmony_ci    IFunction::ConstPtr GetFunctionByName(BASE_NS::string_view name) const override
4068bf80f4bSopenharmony_ci    {
4078bf80f4bSopenharmony_ci        return meta_->GetFunctionByName(name);
4088bf80f4bSopenharmony_ci    }
4098bf80f4bSopenharmony_ci    IFunction::Ptr GetFunctionByName(BASE_NS::string_view name) override
4108bf80f4bSopenharmony_ci    {
4118bf80f4bSopenharmony_ci        return meta_->GetFunctionByName(name);
4128bf80f4bSopenharmony_ci    }
4138bf80f4bSopenharmony_ci    IEvent::ConstPtr GetEventByName(BASE_NS::string_view name) const override
4148bf80f4bSopenharmony_ci    {
4158bf80f4bSopenharmony_ci        return meta_->GetEventByName(name);
4168bf80f4bSopenharmony_ci    }
4178bf80f4bSopenharmony_ci    IEvent::Ptr GetEventByName(BASE_NS::string_view name) override
4188bf80f4bSopenharmony_ci    {
4198bf80f4bSopenharmony_ci        return meta_->GetEventByName(name);
4208bf80f4bSopenharmony_ci    }
4218bf80f4bSopenharmony_ci
4228bf80f4bSopenharmony_ciprotected: // IMetadataInternal
4238bf80f4bSopenharmony_ci    void SetMetadata(const IMetadata::Ptr& meta) override
4248bf80f4bSopenharmony_ci    {
4258bf80f4bSopenharmony_ci        meta_ = meta;
4268bf80f4bSopenharmony_ci        ConstructPropertiesFromMetadata(this, FinalClass::StaticObjectMeta(), meta);
4278bf80f4bSopenharmony_ci        ConstructEventsFromMetadata(this, FinalClass::StaticObjectMeta(), meta);
4288bf80f4bSopenharmony_ci        ConstructFunctionsFromMetadata(this, FinalClass::StaticObjectMeta(), meta);
4298bf80f4bSopenharmony_ci    }
4308bf80f4bSopenharmony_ci
4318bf80f4bSopenharmony_ci    IMetadata::Ptr GetMetadata() const override
4328bf80f4bSopenharmony_ci    {
4338bf80f4bSopenharmony_ci        return meta_;
4348bf80f4bSopenharmony_ci    }
4358bf80f4bSopenharmony_ci
4368bf80f4bSopenharmony_ci    const StaticObjectMetadata& GetStaticMetadata() const override
4378bf80f4bSopenharmony_ci    {
4388bf80f4bSopenharmony_ci        return FinalClass::GetStaticObjectMetadata();
4398bf80f4bSopenharmony_ci    }
4408bf80f4bSopenharmony_ci
4418bf80f4bSopenharmony_ciprotected: // IObjectContextProvider
4428bf80f4bSopenharmony_ci    META_EXT_BASE_PROPERTY(IObjectContextProvider, IObjectContext::Ptr, ObjectContext)
4438bf80f4bSopenharmony_ci    void ResetObjectContext() override
4448bf80f4bSopenharmony_ci    {
4458bf80f4bSopenharmony_ci        META_EXT_CALL_BASE(IObjectContextProvider, ResetObjectContext());
4468bf80f4bSopenharmony_ci    }
4478bf80f4bSopenharmony_ci
4488bf80f4bSopenharmony_ciprotected:
4498bf80f4bSopenharmony_ci    MetaObjectFwd() = default;
4508bf80f4bSopenharmony_ci    ~MetaObjectFwd() override = default;
4518bf80f4bSopenharmony_ci    META_NO_COPY_MOVE(MetaObjectFwd)
4528bf80f4bSopenharmony_ci
4538bf80f4bSopenharmony_ciprivate:
4548bf80f4bSopenharmony_ci    IMetadata::Ptr meta_;
4558bf80f4bSopenharmony_ci};
4568bf80f4bSopenharmony_ci
4578bf80f4bSopenharmony_ci/**
4588bf80f4bSopenharmony_ci * @brief A helper template class for implementing a class which implements the full set of object interfaces.
4598bf80f4bSopenharmony_ci * @note Usually this template should be used as the base class, unless SuperClassInfo is
4608bf80f4bSopenharmony_ci *       META_NS::ClassId::BaseObject or META_NS::ClassId::MetaObject.
4618bf80f4bSopenharmony_ci */
4628bf80f4bSopenharmony_citemplate<class FinalClass, const META_NS::ClassInfo& ClassInfo, const META_NS::ClassInfo& SuperClassInfo,
4638bf80f4bSopenharmony_ci    class... Interfaces>
4648bf80f4bSopenharmony_ciclass ObjectFwd : public MetaObjectFwd<FinalClass, ClassInfo, SuperClassInfo, IAttach, IContainerQuery, Interfaces...> {
4658bf80f4bSopenharmony_ci    using Super = MetaObjectFwd<FinalClass, ClassInfo, SuperClassInfo, IAttach, IContainerQuery, Interfaces...>;
4668bf80f4bSopenharmony_ci
4678bf80f4bSopenharmony_cipublic:
4688bf80f4bSopenharmony_ci    META_NS::IObjectRegistry& GetObjectRegistry() override
4698bf80f4bSopenharmony_ci    {
4708bf80f4bSopenharmony_ci        if (auto context = Super::ObjectContext()->GetValue()) {
4718bf80f4bSopenharmony_ci            return context->GetObjectRegistry();
4728bf80f4bSopenharmony_ci        }
4738bf80f4bSopenharmony_ci        return Super::GetObjectRegistry();
4748bf80f4bSopenharmony_ci    }
4758bf80f4bSopenharmony_ci
4768bf80f4bSopenharmony_ciprotected: // IAttach
4778bf80f4bSopenharmony_ci    bool Attach(const IObject::Ptr& attachment, const IObject::Ptr& dataContext) override
4788bf80f4bSopenharmony_ci    {
4798bf80f4bSopenharmony_ci        return META_EXT_CALL_BASE(IAttach, Attach(attachment, dataContext));
4808bf80f4bSopenharmony_ci    }
4818bf80f4bSopenharmony_ci
4828bf80f4bSopenharmony_ci    bool Detach(const IObject::Ptr& attachment) override
4838bf80f4bSopenharmony_ci    {
4848bf80f4bSopenharmony_ci        return META_EXT_CALL_BASE(IAttach, Detach(attachment));
4858bf80f4bSopenharmony_ci    }
4868bf80f4bSopenharmony_ci    BASE_NS::vector<IObject::Ptr> GetAttachments(const BASE_NS::vector<TypeId>& uids, bool strict) const override
4878bf80f4bSopenharmony_ci    {
4888bf80f4bSopenharmony_ci        return META_EXT_CALL_BASE(IAttach, GetAttachments(uids, strict));
4898bf80f4bSopenharmony_ci    }
4908bf80f4bSopenharmony_ci    bool HasAttachments() const override
4918bf80f4bSopenharmony_ci    {
4928bf80f4bSopenharmony_ci        return META_EXT_CALL_BASE(IAttach, HasAttachments());
4938bf80f4bSopenharmony_ci    }
4948bf80f4bSopenharmony_ci    IContainer::Ptr GetAttachmentContainer(bool initializeAlways) const override
4958bf80f4bSopenharmony_ci    {
4968bf80f4bSopenharmony_ci        return META_EXT_CALL_BASE(IAttach, GetAttachmentContainer(initializeAlways));
4978bf80f4bSopenharmony_ci    }
4988bf80f4bSopenharmony_ci
4998bf80f4bSopenharmony_ciprotected: // IContainerQuery
5008bf80f4bSopenharmony_ci    BASE_NS::vector<IContainer::Ptr> FindAllContainers(
5018bf80f4bSopenharmony_ci        const IContainerQuery::ContainerFindOptions& options) const override
5028bf80f4bSopenharmony_ci    {
5038bf80f4bSopenharmony_ci        return META_EXT_CALL_BASE(IContainerQuery, FindAllContainers(options));
5048bf80f4bSopenharmony_ci    }
5058bf80f4bSopenharmony_ci
5068bf80f4bSopenharmony_ciprotected:
5078bf80f4bSopenharmony_ci    ObjectFwd() = default;
5088bf80f4bSopenharmony_ci    ~ObjectFwd() override = default;
5098bf80f4bSopenharmony_ci    META_NO_COPY_MOVE(ObjectFwd)
5108bf80f4bSopenharmony_ci};
5118bf80f4bSopenharmony_ci
5128bf80f4bSopenharmony_ciMETA_END_NAMESPACE()
5138bf80f4bSopenharmony_ci
5148bf80f4bSopenharmony_ci#endif
515