• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_PROPERTY_BIND_H
17 #define META_SRC_PROPERTY_BIND_H
18 
19 #include <meta/interface/property/intf_bind.h>
20 
21 #include "../base_object.h"
22 #include "stack_property.h"
23 
META_BEGIN_NAMESPACE()24 META_BEGIN_NAMESPACE()
25 namespace Internal {
26 
27 class Bind : public IntroduceInterfaces<BaseObject, IValue, IBind, INotifyOnChange, ISerializable, IImportFinalize> {
28     META_OBJECT(Bind, META_NS::ClassId::Bind, IntroduceInterfaces)
29 
30 public:
31     META_NO_COPY_MOVE(Bind)
32 
33     Bind() = default;
34     ~Bind() override;
35 
36     AnyReturnValue SetValue(const IAny& value) override;
37     const IAny& GetValue() const override;
38     bool IsCompatible(const TypeId& id) const override;
39 
40     bool SetTarget(const IProperty::ConstPtr& prop, bool getDeps, const IProperty* owner) override;
41     bool SetTarget(const IFunction::ConstPtr& func, bool getDeps, const IProperty* owner) override;
42     IFunction::ConstPtr GetTarget() const override;
43 
44     bool AddDependency(const INotifyOnChange::ConstPtr& dep) override;
45     bool RemoveDependency(const INotifyOnChange::ConstPtr& dep) override;
46     BASE_NS::vector<INotifyOnChange::ConstPtr> GetDependencies() const override;
47 
48     BASE_NS::shared_ptr<IEvent> EventOnChanged(MetadataQuery) const override;
49 
50 private:
51     ReturnError Export(IExportContext&) const override;
52     ReturnError Import(IImportContext&) override;
53     ReturnError Finalize(IImportFunctions&) override;
54 
55     bool CreateContext(bool eval, const IProperty* owner);
56 
57     void Reset();
58 
59 private:
60     BASE_NS::shared_ptr<EventImpl<IOnChanged>> event_ { new EventImpl<IOnChanged>("OnChanged") };
61     ICallContext::Ptr context_;
62     IFunction::ConstPtr func_;
63     BASE_NS::vector<INotifyOnChange::ConstWeakPtr> dependencies_;
64 };
65 
66 } // namespace Internal
67 META_END_NAMESPACE()
68 
69 #endif