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#ifndef META_SRC_META_OBJECT_H
168bf80f4bSopenharmony_ci#define META_SRC_META_OBJECT_H
178bf80f4bSopenharmony_ci
188bf80f4bSopenharmony_ci#include <base/containers/array_view.h>
198bf80f4bSopenharmony_ci#include <base/containers/vector.h>
208bf80f4bSopenharmony_ci
218bf80f4bSopenharmony_ci#include <meta/base/types.h>
228bf80f4bSopenharmony_ci#include <meta/ext/implementation_macros.h>
238bf80f4bSopenharmony_ci#include <meta/ext/metadata_helpers.h>
248bf80f4bSopenharmony_ci#include <meta/ext/object_factory.h>
258bf80f4bSopenharmony_ci#include <meta/interface/builtin_objects.h>
268bf80f4bSopenharmony_ci#include <meta/interface/interface_helpers.h>
278bf80f4bSopenharmony_ci#include <meta/interface/intf_attachment.h>
288bf80f4bSopenharmony_ci#include <meta/interface/intf_attachment_container.h>
298bf80f4bSopenharmony_ci#include <meta/interface/intf_metadata.h>
308bf80f4bSopenharmony_ci#include <meta/interface/intf_object_context.h>
318bf80f4bSopenharmony_ci
328bf80f4bSopenharmony_ci#include "base_object.h"
338bf80f4bSopenharmony_ci
348bf80f4bSopenharmony_ciMETA_BEGIN_NAMESPACE()
358bf80f4bSopenharmony_ci
368bf80f4bSopenharmony_cinamespace Internal {
378bf80f4bSopenharmony_ci
388bf80f4bSopenharmony_ciclass MetaObject : public BaseObjectFwd<MetaObject, META_NS::ClassId::MetaObject, IObjectContextProvider, IMetadata,
398bf80f4bSopenharmony_ci                       IMetadataInternal> {
408bf80f4bSopenharmony_ci    using Super = BaseObjectFwd;
418bf80f4bSopenharmony_ci
428bf80f4bSopenharmony_cipublic:
438bf80f4bSopenharmony_ci    static BASE_NS::vector<BASE_NS::Uid> GetInterfacesVector()
448bf80f4bSopenharmony_ci    {
458bf80f4bSopenharmony_ci        return Super::GetInterfacesVector();
468bf80f4bSopenharmony_ci    }
478bf80f4bSopenharmony_ci
488bf80f4bSopenharmony_ciprotected:
498bf80f4bSopenharmony_ci    // ILifecycle
508bf80f4bSopenharmony_ci    bool Build(const IMetadata::Ptr& data) override;
518bf80f4bSopenharmony_ci    void Destroy() override;
528bf80f4bSopenharmony_ci    IObjectRegistry& GetObjectRegistry() const override;
538bf80f4bSopenharmony_ci    IObject::Ptr Resolve(const RefUri& uri) const override;
548bf80f4bSopenharmony_ci
558bf80f4bSopenharmony_ci    // IObjectContextProvider
568bf80f4bSopenharmony_ci
578bf80f4bSopenharmony_ci    IProperty::Ptr PropertyObjectContext() override;
588bf80f4bSopenharmony_ci    IProperty::ConstPtr PropertyObjectContext() const override;
598bf80f4bSopenharmony_ci    void ResetObjectContext() override;
608bf80f4bSopenharmony_ci
618bf80f4bSopenharmony_ci    // IMetadata
628bf80f4bSopenharmony_ci    IMetadata::Ptr CloneMetadata() const override;
638bf80f4bSopenharmony_ci    IContainer::Ptr GetPropertyContainer() override;
648bf80f4bSopenharmony_ci    IContainer::ConstPtr GetPropertyContainer() const override;
658bf80f4bSopenharmony_ci
668bf80f4bSopenharmony_ci    void AddFunction(const IFunction::Ptr&) override;
678bf80f4bSopenharmony_ci    void RemoveFunction(const IFunction::Ptr&) override;
688bf80f4bSopenharmony_ci
698bf80f4bSopenharmony_ci    void AddProperty(const IProperty::Ptr&) override;
708bf80f4bSopenharmony_ci    void RemoveProperty(const IProperty::Ptr&) override;
718bf80f4bSopenharmony_ci
728bf80f4bSopenharmony_ci    void AddEvent(const IEvent::Ptr&) override;
738bf80f4bSopenharmony_ci    void RemoveEvent(const IEvent::Ptr&) override;
748bf80f4bSopenharmony_ci
758bf80f4bSopenharmony_ci    void SetProperties(const BASE_NS::vector<IProperty::Ptr>& vec) override;
768bf80f4bSopenharmony_ci    void Merge(const IMetadata::Ptr& data) override;
778bf80f4bSopenharmony_ci
788bf80f4bSopenharmony_ci    BASE_NS::vector<IProperty::Ptr> GetAllProperties() override;
798bf80f4bSopenharmony_ci    BASE_NS::vector<IProperty::ConstPtr> GetAllProperties() const override;
808bf80f4bSopenharmony_ci    BASE_NS::vector<IFunction::Ptr> GetAllFunctions() override;
818bf80f4bSopenharmony_ci    BASE_NS::vector<IFunction::ConstPtr> GetAllFunctions() const override;
828bf80f4bSopenharmony_ci    BASE_NS::vector<IEvent::Ptr> GetAllEvents() override;
838bf80f4bSopenharmony_ci    BASE_NS::vector<IEvent::ConstPtr> GetAllEvents() const override;
848bf80f4bSopenharmony_ci
858bf80f4bSopenharmony_ci    IProperty::Ptr GetPropertyByName(BASE_NS::string_view name) override;
868bf80f4bSopenharmony_ci    IProperty::ConstPtr GetPropertyByName(BASE_NS::string_view name) const override;
878bf80f4bSopenharmony_ci    IFunction::Ptr GetFunctionByName(BASE_NS::string_view name) override;
888bf80f4bSopenharmony_ci    IFunction::ConstPtr GetFunctionByName(BASE_NS::string_view name) const override;
898bf80f4bSopenharmony_ci    IEvent::ConstPtr GetEventByName(BASE_NS::string_view name) const override;
908bf80f4bSopenharmony_ci    IEvent::Ptr GetEventByName(BASE_NS::string_view name) override;
918bf80f4bSopenharmony_ci
928bf80f4bSopenharmony_ci    // IMetadataInternal
938bf80f4bSopenharmony_ci    IMetadata::Ptr GetMetadata() const override;
948bf80f4bSopenharmony_ci    void SetMetadata(const IMetadata::Ptr& meta) override;
958bf80f4bSopenharmony_ci    const StaticObjectMetadata& GetStaticMetadata() const override;
968bf80f4bSopenharmony_ci
978bf80f4bSopenharmony_ciprivate:
988bf80f4bSopenharmony_ci    Property<IObjectContext::Ptr> GetOrConstuctObjectContext() const;
998bf80f4bSopenharmony_ci
1008bf80f4bSopenharmony_ci    mutable Property<IObjectContext::Ptr> objectContext_;
1018bf80f4bSopenharmony_ci    IMetadata::Ptr meta_;
1028bf80f4bSopenharmony_ci};
1038bf80f4bSopenharmony_ci
1048bf80f4bSopenharmony_citemplate<class FinalClass, const META_NS::ClassInfo& ClassInfo, class... Interfaces>
1058bf80f4bSopenharmony_ciclass MetaObjectFwd : public ConcreteBaseFwd<FinalClass, ClassInfo, META_NS::Internal::MetaObject, Interfaces...> {
1068bf80f4bSopenharmony_ci    using Super = ConcreteBaseFwd<FinalClass, ClassInfo, META_NS::Internal::MetaObject, Interfaces...>;
1078bf80f4bSopenharmony_ci
1088bf80f4bSopenharmony_cipublic:
1098bf80f4bSopenharmony_ci    IObjectRegistry& GetObjectRegistry() const override
1108bf80f4bSopenharmony_ci    {
1118bf80f4bSopenharmony_ci        return MetaObject::GetObjectRegistry();
1128bf80f4bSopenharmony_ci    }
1138bf80f4bSopenharmony_ci
1148bf80f4bSopenharmony_ci    void SetMetadata(const META_NS::IMetadata::Ptr& meta) override
1158bf80f4bSopenharmony_ci    {
1168bf80f4bSopenharmony_ci        Super::SetMetadata(meta);
1178bf80f4bSopenharmony_ci        META_NS::ConstructPropertiesFromMetadata(this, this->GetStaticObjectMetadata(), meta);
1188bf80f4bSopenharmony_ci        META_NS::ConstructEventsFromMetadata(this, this->GetStaticObjectMetadata(), meta);
1198bf80f4bSopenharmony_ci        META_NS::ConstructFunctionsFromMetadata(this, this->GetStaticObjectMetadata(), meta);
1208bf80f4bSopenharmony_ci    }
1218bf80f4bSopenharmony_ci
1228bf80f4bSopenharmony_ciprotected:
1238bf80f4bSopenharmony_ci    MetaObjectFwd() = default;
1248bf80f4bSopenharmony_ci    ~MetaObjectFwd() override = default;
1258bf80f4bSopenharmony_ci};
1268bf80f4bSopenharmony_ci
1278bf80f4bSopenharmony_ci} // namespace Internal
1288bf80f4bSopenharmony_ci
1298bf80f4bSopenharmony_ciclass MetaObject : public Internal::MetaObjectFwd<MetaObject, ClassId::MetaObject> {};
1308bf80f4bSopenharmony_ci
1318bf80f4bSopenharmony_ciMETA_END_NAMESPACE()
1328bf80f4bSopenharmony_ci
1338bf80f4bSopenharmony_ci#endif
134