18bf80f4bSopenharmony_ci/* 28bf80f4bSopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 38bf80f4bSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 48bf80f4bSopenharmony_ci * you may not use this file except in compliance with the License. 58bf80f4bSopenharmony_ci * You may obtain a copy of the License at 68bf80f4bSopenharmony_ci * 78bf80f4bSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 88bf80f4bSopenharmony_ci * 98bf80f4bSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 108bf80f4bSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 118bf80f4bSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 128bf80f4bSopenharmony_ci * See the License for the specific language governing permissions and 138bf80f4bSopenharmony_ci * limitations under the License. 148bf80f4bSopenharmony_ci */ 158bf80f4bSopenharmony_ci#ifndef META_SRC_ENGINE_ENGINE_VALUE_H 168bf80f4bSopenharmony_ci#define META_SRC_ENGINE_ENGINE_VALUE_H 178bf80f4bSopenharmony_ci 188bf80f4bSopenharmony_ci#include <shared_mutex> 198bf80f4bSopenharmony_ci 208bf80f4bSopenharmony_ci#include <meta/ext/event_impl.h> 218bf80f4bSopenharmony_ci#include <meta/ext/minimal_object.h> 228bf80f4bSopenharmony_ci#include <meta/interface/engine/intf_engine_value.h> 238bf80f4bSopenharmony_ci#include <meta/interface/interface_helpers.h> 248bf80f4bSopenharmony_ci#include <meta/interface/intf_lockable.h> 258bf80f4bSopenharmony_ci#include <meta/interface/intf_notify_on_change.h> 268bf80f4bSopenharmony_ci#include <meta/interface/property/intf_stack_resetable.h> 278bf80f4bSopenharmony_ci 288bf80f4bSopenharmony_ciMETA_BEGIN_NAMESPACE() 298bf80f4bSopenharmony_ci 308bf80f4bSopenharmony_cinamespace Internal { 318bf80f4bSopenharmony_ci 328bf80f4bSopenharmony_ciclass IEngineValueInternal : public CORE_NS::IInterface { 338bf80f4bSopenharmony_ci META_INTERFACE(CORE_NS::IInterface, IEngineValueInternal, "86afd68c-7924-46b8-8bb8-aeace0029945") 348bf80f4bSopenharmony_cipublic: 358bf80f4bSopenharmony_ci virtual IEngineInternalValueAccess::ConstPtr GetInternalAccess() const = 0; 368bf80f4bSopenharmony_ci virtual EnginePropertyParams GetPropertyParams() const = 0; 378bf80f4bSopenharmony_ci virtual bool SetPropertyParams(const EnginePropertyParams& p) = 0; 388bf80f4bSopenharmony_ci}; 398bf80f4bSopenharmony_ci 408bf80f4bSopenharmony_ciMETA_REGISTER_CLASS(EngineValue, "a8a9c80f-3501-48da-b552-f1f323ee399b", ObjectCategoryBits::NO_CATEGORY) 418bf80f4bSopenharmony_ci 428bf80f4bSopenharmony_ciclass EngineValue : public MinimalObject<ClassId::EngineValue, IEngineValue, INotifyOnChange, ILockable, 438bf80f4bSopenharmony_ci IStackResetable, IEngineValueInternal> { 448bf80f4bSopenharmony_cipublic: 458bf80f4bSopenharmony_ci EngineValue(BASE_NS::string name, IEngineInternalValueAccess::ConstPtr access, const EnginePropertyParams& p); 468bf80f4bSopenharmony_ci 478bf80f4bSopenharmony_ci AnyReturnValue Sync(EngineSyncDirection) override; 488bf80f4bSopenharmony_ci 498bf80f4bSopenharmony_ci AnyReturnValue SetValue(const IAny& value) override; 508bf80f4bSopenharmony_ci const IAny& GetValue() const override; 518bf80f4bSopenharmony_ci bool IsCompatible(const TypeId& id) const override; 528bf80f4bSopenharmony_ci 538bf80f4bSopenharmony_ci BASE_NS::string GetName() const override; 548bf80f4bSopenharmony_ci 558bf80f4bSopenharmony_ci void Lock() const override; 568bf80f4bSopenharmony_ci void Unlock() const override; 578bf80f4bSopenharmony_ci void LockShared() const override; 588bf80f4bSopenharmony_ci void UnlockShared() const override; 598bf80f4bSopenharmony_ci 608bf80f4bSopenharmony_ci ResetResult ProcessOnReset(const IAny& defaultValue) override; 618bf80f4bSopenharmony_ci 628bf80f4bSopenharmony_ci BASE_NS::shared_ptr<IEvent> EventOnChanged() const override; 638bf80f4bSopenharmony_ci 648bf80f4bSopenharmony_ciprivate: 658bf80f4bSopenharmony_ci IEngineInternalValueAccess::ConstPtr GetInternalAccess() const override 668bf80f4bSopenharmony_ci { 678bf80f4bSopenharmony_ci return access_; 688bf80f4bSopenharmony_ci } 698bf80f4bSopenharmony_ci EnginePropertyParams GetPropertyParams() const override; 708bf80f4bSopenharmony_ci bool SetPropertyParams(const EnginePropertyParams& p) override; 718bf80f4bSopenharmony_ci 728bf80f4bSopenharmony_ciprivate: 738bf80f4bSopenharmony_ci mutable std::shared_mutex mutex_; 748bf80f4bSopenharmony_ci EnginePropertyParams params_; 758bf80f4bSopenharmony_ci IEngineInternalValueAccess::ConstPtr access_; 768bf80f4bSopenharmony_ci bool valueChanged_ {}; 778bf80f4bSopenharmony_ci const BASE_NS::string name_; 788bf80f4bSopenharmony_ci IAny::Ptr value_; 798bf80f4bSopenharmony_ci BASE_NS::shared_ptr<EventImpl<IOnChanged>> event_ { new EventImpl<IOnChanged>("OnChanged") }; 808bf80f4bSopenharmony_ci}; 818bf80f4bSopenharmony_ci 828bf80f4bSopenharmony_ci} // namespace Internal 838bf80f4bSopenharmony_ci 848bf80f4bSopenharmony_ciMETA_END_NAMESPACE() 858bf80f4bSopenharmony_ci 868bf80f4bSopenharmony_ci#endif