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