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