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_SETTABLE_FUNCTION_H
17 #define META_SRC_SETTABLE_FUNCTION_H
18
19 #include <meta/interface/intf_function.h>
20 #include <meta/interface/serialization/intf_serializable.h>
21
22 #include "base_object.h"
23
META_BEGIN_NAMESPACE()24 META_BEGIN_NAMESPACE()
25
26 class SettableFunction
27 : public Internal::BaseObjectFwd<SettableFunction, ClassId::SettableFunction, ISettableFunction, ISerializable> {
28 public: // IFunction
29 BASE_NS::string GetName() const override;
30 IObject::ConstPtr GetDestination() const override;
31 void Invoke(const ICallContext::Ptr& context) const override;
32 ICallContext::Ptr CreateCallContext() const override;
33
34 bool SetTarget(const IObject::Ptr& obj, BASE_NS::string_view name) override;
35
36 private:
37 bool ResolveFunction(const IObject::Ptr& obj, BASE_NS::string_view name);
38
39 ReturnError Export(IExportContext&) const override;
40 ReturnError Import(IImportContext&) override;
41
42 private:
43 IFunction::ConstWeakPtr func_;
44 };
45
46 class PropertyFunction : public Internal::BaseObjectFwd<PropertyFunction, ClassId::PropertyFunction, IPropertyFunction,
47 ISerializable, IImportFinalize> {
48 public: // IFunction
49 BASE_NS::string GetName() const override;
50 IObject::ConstPtr GetDestination() const override;
51 void Invoke(const ICallContext::Ptr& context) const override;
52 ICallContext::Ptr CreateCallContext() const override;
53
54 bool SetTarget(const IProperty::ConstPtr& prop) override;
55
56 ReturnError Export(IExportContext&) const override;
57 ReturnError Import(IImportContext&) override;
58
59 ReturnError Finalize(IImportFunctions&) override;
60
61 private:
62 RefUri uri_;
63 IProperty::ConstWeakPtr prop_;
64 };
65
66 META_END_NAMESPACE()
67
68 #endif
69