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_INTERFACE_FUNCTION_H 17 #define META_INTERFACE_FUNCTION_H 18 19 #include <core/plugin/intf_interface.h> 20 21 #include <meta/base/namespace.h> 22 #include <meta/base/types.h> 23 #include <meta/interface/intf_any.h> 24 #include <meta/interface/intf_call_context.h> 25 #include <meta/interface/intf_callable.h> 26 #include <meta/interface/intf_object.h> 27 #include <meta/interface/property/intf_property.h> 28 29 META_BEGIN_NAMESPACE() 30 31 META_REGISTER_INTERFACE(IFunction, "a25fc0e3-4d2c-4005-bd5b-13ed647114ca") 32 33 /** 34 * @brief Interface for named functions 35 */ 36 class IFunction : public ICallable { 37 META_INTERFACE(ICallable, IFunction) 38 public: 39 /** 40 * @brief Name of this callable entity 41 * @return Name of this entity. 42 */ 43 virtual BASE_NS::string GetName() const = 0; 44 45 /** 46 * @brief Destination object for which this function is called for. 47 * @return Destination object if any (and alive). 48 */ 49 virtual IObject::ConstPtr GetDestination() const = 0; 50 51 /** 52 * @brief Invoke the function 53 * @param context Needs to contain arguments for the call and the return value will be stored here. 54 */ 55 virtual void Invoke(const ICallContext::Ptr& context) const = 0; 56 57 /** 58 * @brief Create default call context for this function, which contains the parameter names and types. 59 * @return Call context. 60 */ 61 virtual ICallContext::Ptr CreateCallContext() const = 0; 62 }; 63 64 /** 65 * @brief IFunction for which the target object and function-name can be set manually. 66 */ 67 class ISettableFunction : public IFunction { 68 META_INTERFACE(IFunction, ISettableFunction, "4437e8d2-e41f-48a0-8880-b2636c926b21") 69 public: 70 /** 71 * @brief Set the target object and function name. 72 */ 73 virtual bool SetTarget(const IObject::Ptr& obj, BASE_NS::string_view name) = 0; 74 }; 75 76 /** 77 * @brief IFunction which returns the value of given property. 78 */ 79 class IPropertyFunction : public IFunction { 80 META_INTERFACE(IFunction, IPropertyFunction, "2f5491bf-881e-449e-8aab-78b137dee0d3") 81 public: 82 /** 83 * @brief Set the target property. 84 */ 85 virtual bool SetTarget(const IProperty::ConstPtr& prop) = 0; 86 }; 87 88 META_END_NAMESPACE() 89 90 META_INTERFACE_TYPE(META_NS::IFunction) 91 92 #endif 93