• 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_LOADERS_JSON_CONTENT_LOADER_H
17 #define META_SRC_LOADERS_JSON_CONTENT_LOADER_H
18 
19 #include <meta/api/property/property_event_handler.h>
20 #include <meta/base/namespace.h>
21 #include <meta/ext/implementation_macros.h>
22 #include <meta/ext/object_fwd.h>
23 #include <meta/interface/builtin_objects.h>
24 #include <meta/interface/loaders/intf_file_content_loader.h>
25 #include <meta/interface/serialization/intf_ser_node.h>
26 
META_BEGIN_NAMESPACE()27 META_BEGIN_NAMESPACE()
28 
29 class JsonContentLoader final : public IntroduceInterfaces<ObjectFwd, IFileContentLoader> {
30     META_OBJECT(JsonContentLoader, ClassId::JsonContentLoader, IntroduceInterfaces)
31 public:
32     bool Build(const IMetadata::Ptr& data) override;
33 
34     META_BEGIN_STATIC_DATA()
35     META_STATIC_PROPERTY_DATA(IFileContentLoader, bool, Cached)
36     META_STATIC_EVENT_DATA(IDynamicContentLoader, IOnChanged, ContentChanged)
37     META_END_STATIC_DATA()
38     META_IMPLEMENT_PROPERTY(bool, Cached)
39     META_IMPLEMENT_EVENT(IOnChanged, ContentChanged)
40 public: // IDynamicContentLoader
41     void Reload() override;
42 
43 public: // IFileContentLoader
44     bool SetFile(CORE_NS::IFile::Ptr file) override;
45     IObject::Ptr Create(const IObject::Ptr& params) override;
46 
47 private:
48     IObject::Ptr LoadCached();
49     bool UpdateTree();
50 
51 private:
52     CORE_NS::IFile::Ptr file_;
53     PropertyChangedEventHandler cachedChangedHandler_;
54     ISerNode::Ptr tree_;
55 };
56 
57 META_END_NAMESPACE()
58 
59 #endif
60