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_ENGINE_INTERFACE_ENGINE_VALUE_MANAGER_H 17 #define META_ENGINE_INTERFACE_ENGINE_VALUE_MANAGER_H 18 19 #include <meta/interface/engine/intf_engine_value.h> 20 #include <meta/interface/intf_task_queue.h> 21 #include <meta/interface/property/array_property.h> 22 #include <meta/interface/property/property.h> 23 24 META_BEGIN_NAMESPACE() 25 26 META_REGISTER_INTERFACE(IEngineValueManager, "542b7e13-21bd-4c9c-8d3f-a9527732216c") 27 28 /** 29 * @brief Options for constructing engine values 30 */ 31 struct EngineValueOptions { 32 /// prefix that is added before the name (plus '.') 33 BASE_NS::string namePrefix; 34 /// optional output vector to put all matching values 35 BASE_NS::vector<IEngineValue::Ptr>* values {}; 36 /** 37 * @brief Push value directly to engine when set, if this is enabled, 38 * the values can only be set in the engine task queue thread 39 **/ 40 bool pushValuesDirectlyToEngine {}; 41 /** 42 * @brief If true, also recursively handle known struct types. E.g. Vec4 would be expanded into x, y, z, and w 43 * properties. 44 */ 45 bool recurseKnownStructs {}; 46 }; 47 48 /** 49 * @brief Manager that contains engine values, handles their synchronisation and notification of changes 50 */ 51 class IEngineValueManager : public CORE_NS::IInterface { 52 META_INTERFACE(CORE_NS::IInterface, IEngineValueManager) 53 public: 54 /** 55 * @brief Set task queue where the engine value change notifications are posted to. 56 * This must be set to be able to get notifications. 57 */ 58 virtual void SetNotificationQueue(const ITaskQueue::WeakPtr&) = 0; 59 60 /** 61 * @brief Synchronise engine values with core engine 62 * Allows to specify direction to synchronise to. 63 * @note This must be called in correct thread because it touches the core engine 64 */ 65 virtual bool Sync(EngineSyncDirection) = 0; 66 67 /// Add engine values from the handle 68 virtual bool ConstructValues(EnginePropertyHandle handle, EngineValueOptions) = 0; 69 // Add engine values from value (e.g. member properties or follow EnginePropertyHandle) 70 virtual bool ConstructValues(IValue::Ptr value, EngineValueOptions) = 0; 71 // Add single engine value from EnginePropertyParams 72 virtual bool ConstructValue(EnginePropertyParams property, EngineValueOptions) = 0; 73 /// Add single engine value starting from handle and following path 74 virtual bool ConstructValue(EnginePropertyHandle handle, BASE_NS::string_view path, EngineValueOptions) = 0; 75 76 /// Remove engine value with given name 77 virtual bool RemoveValue(BASE_NS::string_view name) = 0; 78 /// Remove all engine values 79 virtual void RemoveAll() = 0; 80 81 /// Construct property from engine value with given name 82 virtual IProperty::Ptr ConstructProperty(BASE_NS::string_view name) const = 0; 83 /// Get engine value of given name 84 virtual IEngineValue::Ptr GetEngineValue(BASE_NS::string_view name) const = 0; 85 /// Construct property from all contained engine values 86 virtual BASE_NS::vector<IProperty::Ptr> ConstructAllProperties() const = 0; 87 /// Get all engine values 88 virtual BASE_NS::vector<IEngineValue::Ptr> GetAllEngineValues() const = 0; 89 /// Construct property from engine value with given name 90 template<typename Type> ConstructProperty(BASE_NS::string_view name)91 Property<Type> ConstructProperty(BASE_NS::string_view name) 92 { 93 return Property<Type>(ConstructProperty(name)); 94 } 95 /// Construct array property from engine value with given name 96 template<typename Type> ConstructArrayProperty(BASE_NS::string_view name)97 ArrayProperty<Type> ConstructArrayProperty(BASE_NS::string_view name) 98 { 99 return ArrayProperty<Type>(ConstructProperty(name)); 100 } 101 /// Add engine values from the handle with default options ConstructValues(EnginePropertyHandle handle)102 bool ConstructValues(EnginePropertyHandle handle) 103 { 104 return ConstructValues(handle, {}); 105 } 106 }; 107 108 META_INTERFACE_TYPE(META_NS::IEngineValueManager) 109 META_END_NAMESPACE() 110 111 #endif 112