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_SRC_OBJECT_CONTEXT_H
17 #define META_SRC_OBJECT_CONTEXT_H
18
19 #include <meta/base/namespace.h>
20 #include <meta/ext/implementation_macros.h>
21 #include <meta/ext/object_fwd.h>
22 #include <meta/interface/builtin_objects.h>
23 #include <meta/interface/intf_object_context.h>
24 #include <meta/interface/intf_proxy_object.h>
25
26 #include "object.h"
27
META_BEGIN_NAMESPACE()28 META_BEGIN_NAMESPACE()
29
30 namespace Internal {
31
32 class ObjectContext final : public IntroduceInterfaces<ObjectFwd, IProxyObject, IObjectContext> {
33 META_OBJECT(ObjectContext, META_NS::ClassId::ObjectContext, IntroduceInterfaces, META_NS::ClassId::ProxyObject)
34
35 public:
36 ObjectContext() = default;
37 ~ObjectContext() override = default;
38
39 public: // ILifecycle
40 void SetSuperInstance(const META_NS::IObject::Ptr& aggr, const META_NS::IObject::Ptr& super) override;
41
42 public: // IProxyObject
43 META_FORWARD_PROPERTY(ProxyModeBitsValue, Mode, proxy_->Mode())
44 META_FORWARD_PROPERTY(bool, Dynamic, proxy_->Dynamic())
45 const IObject::Ptr GetTarget() const override;
46 bool SetTarget(const IObject::Ptr& target) override;
47 BASE_NS::vector<IProperty::ConstPtr> GetOverrides() const override;
48 IProperty::ConstPtr GetOverride(BASE_NS::string_view name) const override;
49 IProperty::Ptr SetPropertyTarget(const IProperty::Ptr& property) override;
50 IProperty::ConstPtr GetProxyProperty(BASE_NS::string_view name) const override;
51 void AddInternalProxy(BASE_NS::string_view propertyPropertyName, BASE_NS::string_view sourcePropertyName) override;
52
53 public: // IMetadata
54 using IMetadata::GetProperty;
55 IProperty::Ptr GetProperty(BASE_NS::string_view name, MetadataQuery) override;
56 IProperty::ConstPtr GetProperty(BASE_NS::string_view name, MetadataQuery) const override;
57
58 BASE_NS::vector<IProperty::Ptr> GetProperties() override;
59 BASE_NS::vector<IProperty::ConstPtr> GetProperties() const override;
60
61 public: // IObjectContext
62 IObjectRegistry& GetObjectRegistry() override;
63
64 private:
65 META_NS::IProxyObject* proxy_ { nullptr };
66 META_NS::IMetadata* metadata_ { nullptr };
67 IObject::WeakPtr target_;
68 };
69
70 } // namespace Internal
71
72 META_END_NAMESPACE()
73
74 #endif
75