• 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 #ifndef META_SRC_ENGINE_ENGINE_VALUE_MANAGER_H
16 #define META_SRC_ENGINE_ENGINE_VALUE_MANAGER_H
17 
18 #include <base/containers/unordered_map.h>
19 
20 #include <meta/base/interface_macros.h>
21 #include <meta/base/namespace.h>
22 #include <meta/interface/engine/intf_engine_value_manager.h>
23 #include <meta/interface/intf_task_queue.h>
24 
25 #include "object.h"
26 #include "engine_value.h"
27 
META_BEGIN_NAMESPACE()28 META_BEGIN_NAMESPACE()
29 
30 namespace Internal {
31 
32 class EngineValueManager : public IntroduceInterfaces<BaseObject, IEngineValueManager> {
33     META_OBJECT(EngineValueManager, META_NS::ClassId::EngineValueManager, IntroduceInterfaces)
34 public:
35     META_NO_COPY_MOVE(EngineValueManager)
36     EngineValueManager() = default;
37     ~EngineValueManager() override;
38 
39     void SetNotificationQueue(const ITaskQueue::WeakPtr&) override;
40     bool ConstructValues(EnginePropertyHandle handle, EngineValueOptions) override;
41     bool ConstructValues(IValue::Ptr value, EngineValueOptions) override;
42     bool ConstructValue(EnginePropertyParams property, EngineValueOptions) override;
43     bool ConstructValue(EnginePropertyHandle handle, BASE_NS::string_view path, EngineValueOptions) override;
44 
45     bool RemoveValue(BASE_NS::string_view name) override;
46     void RemoveAll() override;
47 
48     IProperty::Ptr ConstructProperty(BASE_NS::string_view name) const override;
49     IEngineValue::Ptr GetEngineValue(BASE_NS::string_view name) const override;
50 
51     BASE_NS::vector<IProperty::Ptr> ConstructAllProperties() const override;
52     BASE_NS::vector<IEngineValue::Ptr> GetAllEngineValues() const override;
53 
54     bool Sync(EngineSyncDirection) override;
55 
56 private:
57     void NotifySyncs();
58     IEngineValue::Ptr AddValue(EnginePropertyParams p, EngineValueOptions options);
59     IEngineValue::Ptr ConstructValueImplAdd(
60         EnginePropertyParams params, BASE_NS::string pathTaken, EngineValueOptions options);
61     bool ConstructValueImpl(
62         EnginePropertyHandle handle, BASE_NS::string pathTaken, BASE_NS::string_view path, EngineValueOptions options);
63     bool ConstructValueImpl(
64         EnginePropertyParams params, BASE_NS::string pathTaken, BASE_NS::string_view path, EngineValueOptions options);
65     bool ConstructValueImplArraySubs(
66         EnginePropertyParams params, BASE_NS::string pathTaken, BASE_NS::string_view path, EngineValueOptions options);
67 
68 private:
69     mutable std::shared_mutex mutex_;
70     ITaskQueue::WeakPtr queue_;
71     struct ValueInfo {
72         IEngineValue::Ptr value;
73     };
74     BASE_NS::unordered_map<BASE_NS::string, ValueInfo> values_;
75     ITaskQueue::Token task_token_ {};
76 };
77 
78 } // namespace Internal
79 
80 META_END_NAMESPACE()
81 
82 #endif