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