• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 #include "loader/render_data_loader.h"
17 
18 #include <base/containers/string_view.h>
19 #include <core/io/intf_directory.h>
20 #include <core/io/intf_file_manager.h>
21 #include <core/namespace.h>
22 #include <render/datastore/intf_render_data_store_pod.h>
23 
24 #include "loader/render_data_configuration_loader.h"
25 #include "util/log.h"
26 
27 using namespace BASE_NS;
28 using namespace CORE_NS;
29 
RENDER_BEGIN_NAMESPACE()30 RENDER_BEGIN_NAMESPACE()
31 RenderDataLoader::RenderDataLoader(IFileManager& fileManager) : fileManager_(fileManager) {}
32 
Load(const BASE_NS::string_view pathPrefix,IRenderDataStorePod & renderDataStorePod)33 void RenderDataLoader::Load(const BASE_NS::string_view pathPrefix, IRenderDataStorePod& renderDataStorePod)
34 {
35     const string fullPath = pathPrefix + RENDER_CONFIG_PATH;
36     if (auto const path = fileManager_.OpenDirectory(fullPath); path) {
37         const string currentPath = fullPath + string_view(POST_PROCESS_PATH) + '/';
38         auto currentDirectory = fileManager_.OpenDirectory(currentPath);
39         if (currentDirectory) {
40             RecurseDirectory(currentPath, *currentDirectory, ConfigurationType::POST_PROCESS, renderDataStorePod);
41         } else {
42             PLUGIN_LOG_E("render configuration files path (%s) not found.", currentPath.c_str());
43         }
44     } else {
45         PLUGIN_LOG_E("render configuration files path (%s) not found.", fullPath.c_str());
46     }
47 }
48 
RecurseDirectory(const string_view currentPath,const IDirectory & directory,const ConfigurationType configurationType,IRenderDataStorePod & renderDataStorePod)49 void RenderDataLoader::RecurseDirectory(const string_view currentPath, const IDirectory& directory,
50     const ConfigurationType configurationType, IRenderDataStorePod& renderDataStorePod)
51 {
52     for (auto const& entry : directory.GetEntries()) {
53         switch (entry.type) {
54             default:
55             case IDirectory::Entry::Type::UNKNOWN:
56                 break;
57             case IDirectory::Entry::Type::FILE: {
58                 if (entry.name.ends_with(".json")) {
59                     auto const file = currentPath + entry.name;
60                     IRenderDataConfigurationLoader::LoadResult result;
61                     if (configurationType == ConfigurationType::POST_PROCESS) {
62                         const auto loadedPP = RenderDataConfigurationLoader::LoadPostProcess(fileManager_, file);
63                         if (loadedPP.loadResult.success) {
64                             renderDataStorePod.CreatePod(
65                                 "PostProcess", loadedPP.name, arrayviewU8(loadedPP.postProcessConfiguration));
66                         }
67                         result = loadedPP.loadResult;
68                     }
69 
70                     if (!result.success) {
71                         PLUGIN_LOG_E("unable to load renderer data configuration json %s : %s", file.c_str(),
72                             result.error.c_str());
73                     }
74                 }
75                 break;
76             }
77             case IDirectory::Entry::Type::DIRECTORY: {
78                 PLUGIN_LOG_I("recursive renderer configuration directories not supported");
79                 break;
80             }
81         }
82     }
83 }
84 RENDER_END_NAMESPACE()
85