• 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_ENGINE_ENGINE_VALUE_H
17 #define META_SRC_ENGINE_ENGINE_VALUE_H
18 
19 #include <shared_mutex>
20 
21 #include <meta/ext/event_impl.h>
22 #include <meta/ext/implementation_macros.h>
23 #include <meta/ext/minimal_object.h>
24 #include <meta/interface/engine/intf_engine_value.h>
25 #include <meta/interface/interface_helpers.h>
26 #include <meta/interface/intf_lockable.h>
27 #include <meta/interface/intf_notify_on_change.h>
28 #include <meta/interface/property/intf_stack_resetable.h>
29 
META_BEGIN_NAMESPACE()30 META_BEGIN_NAMESPACE()
31 
32 namespace Internal {
33 
34 META_REGISTER_CLASS(EngineValue, "a8a9c80f-3501-48da-b552-f1f323ee399b", ObjectCategoryBits::NO_CATEGORY)
35 
36 class EngineValue : public IntroduceInterfaces<MinimalObject, IEngineValue, INotifyOnChange, ILockable, IStackResetable,
37                         IEngineValueInternal> {
38     META_IMPLEMENT_OBJECT_TYPE_INTERFACE(ClassId::EngineValue)
39 public:
40     EngineValue(BASE_NS::string name, IEngineInternalValueAccess::ConstPtr access, const EnginePropertyParams& p);
41 
42     AnyReturnValue Sync(EngineSyncDirection) override;
43     bool ResetPendingNotify() override;
44 
45     AnyReturnValue SetValue(const IAny& value) override;
46     const IAny& GetValue() const override;
47     bool IsCompatible(const TypeId& id) const override;
48 
49     BASE_NS::string GetName() const override;
50 
51     void Lock() const override;
52     void Unlock() const override;
53     void LockShared() const override;
54     void UnlockShared() const override;
55 
56     ResetResult ProcessOnReset(const IAny& defaultValue) override;
57 
58     BASE_NS::shared_ptr<IEvent> EventOnChanged(MetadataQuery) const override;
59 
60 private:
61     IEngineInternalValueAccess::ConstPtr GetInternalAccess() const override
62     {
63         return access_;
64     }
65     EnginePropertyParams GetPropertyParams() const override;
66     bool SetPropertyParams(const EnginePropertyParams& p) override;
67     IAny::Ptr CreateAny() const override;
68 
69 private:
70     mutable std::shared_mutex mutex_;
71     EnginePropertyParams params_;
72     IEngineInternalValueAccess::ConstPtr access_;
73     bool valueChanged_ {};
74     bool pendingNotify_ {};
75     const BASE_NS::string name_;
76     IAny::Ptr value_;
77     BASE_NS::shared_ptr<EventImpl<IOnChanged>> event_ { new EventImpl<IOnChanged>("OnChanged") };
78 };
79 
80 } // namespace Internal
81 
82 META_END_NAMESPACE()
83 
84 #endif