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 Internal::BaseObjectFwd<Bind, META_NS::ClassId::Bind, IValue, IBind, INotifyOnChange, ISerializable,
27 IImportFinalize> {
28 using Super = Internal::BaseObjectFwd<Bind, META_NS::ClassId::Bind, IValue, IBind, INotifyOnChange, ISerializable,
29 IImportFinalize>;
30
31 public:
32 META_NO_COPY_MOVE(Bind)
33
34 Bind() = default;
35 ~Bind() override;
36
37 AnyReturnValue SetValue(const IAny& value) override;
38 const IAny& GetValue() const override;
39 bool IsCompatible(const TypeId& id) const override;
40
41 bool SetTarget(const IProperty::ConstPtr& prop, bool getDeps, const IProperty* owner) override;
42 bool SetTarget(const IFunction::ConstPtr& func, bool getDeps, const IProperty* owner) override;
43 IFunction::ConstPtr GetTarget() const override;
44
45 bool AddDependency(const INotifyOnChange::ConstPtr& dep) override;
46 bool RemoveDependency(const INotifyOnChange::ConstPtr& dep) override;
47 BASE_NS::vector<INotifyOnChange::ConstPtr> GetDependencies() const override;
48
49 BASE_NS::shared_ptr<IEvent> EventOnChanged() const override;
50
51 private:
52 ReturnError Export(IExportContext&) const override;
53 ReturnError Import(IImportContext&) override;
54 ReturnError Finalize(IImportFunctions&) override;
55
56 bool CreateContext(bool eval, const IProperty* owner);
57
58 void Reset();
59
60 private:
61 BASE_NS::shared_ptr<EventImpl<IOnChanged>> event_ { new EventImpl<IOnChanged>("OnChanged") };
62 ICallContext::Ptr context_;
63 IFunction::ConstPtr func_;
64 BASE_NS::vector<INotifyOnChange::ConstWeakPtr> dependencies_;
65 };
66
67 } // namespace Internal
68 META_END_NAMESPACE()
69
70 #endif