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_H 17 #define META_ENGINE_INTERFACE_ENGINE_VALUE_H 18 19 #include <core/property/intf_property_handle.h> 20 21 #include <meta/interface/intf_value.h> 22 23 META_BEGIN_NAMESPACE() 24 25 enum class EngineSyncDirection { 26 AUTO, /// Synchronise cached value to engine if changed, otherwise sync engine to cached value 27 TO_ENGINE, /// Synchronise cached value to engine 28 FROM_ENGINE /// Synchronise from engine to cached value 29 }; 30 31 META_REGISTER_INTERFACE(IEngineValue, "2edaea8a-936d-4bc5-a5eb-ecfdbb50574d") 32 33 class IEngineValue : public IValue { 34 META_INTERFACE(IValue, IEngineValue) 35 public: 36 virtual BASE_NS::string GetName() const = 0; 37 virtual AnyReturnValue Sync(EngineSyncDirection) = 0; 38 }; 39 40 META_REGISTER_INTERFACE(IEngineInternalValueAccess, "f11f1272-e936-4804-9202-3b93606c25ea") 41 42 struct EnginePropertyParams { 43 CORE_NS::IPropertyHandle* handle {}; 44 CORE_NS::Property property {}; 45 // offset to the parent property data, this is needed for member properties 46 // calculate baseOffset + property.offset to access the data, 47 // baseOffset is zero if not a member property 48 uintptr_t baseOffset {}; 49 OffsetEnginePropertyParams50 uintptr_t Offset() const 51 { 52 return baseOffset + property.offset; 53 } 54 55 // to support some old code, we allow to push the value directly to the engine property 56 // if this is set, the values can only be set in the engine task queue thread 57 bool pushValueToEngineDirectly {}; 58 }; 59 60 class IEngineInternalValueAccess : public CORE_NS::IInterface { 61 META_INTERFACE(CORE_NS::IInterface, IEngineInternalValueAccess) 62 public: 63 virtual IAny::Ptr CreateAny() const = 0; 64 virtual bool IsCompatible(const CORE_NS::PropertyTypeDecl& type) const = 0; 65 virtual AnyReturnValue SyncToEngine(const IAny& value, const EnginePropertyParams& params) const = 0; 66 virtual AnyReturnValue SyncFromEngine(const EnginePropertyParams& params, IAny& out) const = 0; 67 }; 68 69 META_INTERFACE_TYPE(IEngineValue); 70 META_END_NAMESPACE() 71 72 #endif 73