• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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 "platform_ohos.h"
17 #include "os/platform.h"
18 
19 #include <core/log.h>
20 #include <core/namespace.h>
21 #include <core/io/intf_file_manager.h>
22 #include "io/ohos_filesystem.h"
23 
CORE_BEGIN_NAMESPACE()24 CORE_BEGIN_NAMESPACE()
25 
26 PlatformOHOS::PlatformOHOS(PlatformCreateInfo const& createInfo)
27 {
28     plat_.coreRootPath = createInfo.coreRootPath;
29     plat_.appRootPath = createInfo.appRootPath;
30     plat_.appPluginPath = createInfo.appPluginPath;
31     plat_.hapPath = createInfo.hapPath;
32     plat_.bundleName = createInfo.bundleName;
33     plat_.moduleName = createInfo.moduleName;
34 }
35 
~PlatformOHOS()36 PlatformOHOS::~PlatformOHOS()
37 {
38 }
39 
RegisterDefaultPaths(IFileManager & fileManager)40 BASE_NS::string PlatformOHOS::RegisterDefaultPaths(IFileManager& fileManager)
41 {
42     // register HapFilesystem
43     BASE_NS::string hapPath = plat_.hapPath;
44     BASE_NS::string bundleName = plat_.bundleName;
45     BASE_NS::string moduleName = plat_.moduleName;
46     fileManager.RegisterFilesystem("OhosRawFile",
47         IFilesystem::Ptr{new Core::OhosFilesystem(hapPath, bundleName, moduleName)});
48 
49     CORE_LOG_I("Registered hapFilesystem by Platform: 'hapPath:%s bundleName:%s moduleName:%s'",
50         hapPath.c_str(), bundleName.c_str(), moduleName.c_str());
51     // register path to system plugins (this does not actually do anything anymore, pluginregistry has it's one
52     // filemanager instance etc..) Root path is the location where system plugins , non-rofs assets etc could be held.
53     const BASE_NS::string coreDirectory = "file://" + plat_.coreRootPath;
54 
55     // Create plugins:// protocol that points to plugin files under coredirectory.
56     fileManager.RegisterPath("plugins", coreDirectory, false);
57 
58 #if (CORE_EMBEDDED_ASSETS_ENABLED == 0) || (CORE_DEV_ENABLED == 1)
59     const BASE_NS::string assetRoot = plat_.appRootPath + "assets/";
60 
61     // Create engine:// protocol that points to core asset files on the filesystem.
62     CORE_LOG_I("Registered core asset path: '%score/'", assetRoot.c_str());
63     fileManager.RegisterPath("engine", assetRoot + "core/", false);
64 #endif
65     return coreDirectory;
66 }
67 
RegisterPluginLocations(IPluginRegister & registry)68 void PlatformOHOS::RegisterPluginLocations(IPluginRegister& registry)
69 {
70     constexpr BASE_NS::string_view fileproto("file://");
71     registry.RegisterPluginPath(fileproto + GetPlatformData().coreRootPath);
72     if (!GetPlatformData().appPluginPath.empty()) {
73         registry.RegisterPluginPath(fileproto + GetPlatformData().appPluginPath);
74     }
75 }
76 
GetPlatformData() const77 const PlatformData& PlatformOHOS::GetPlatformData() const
78 {
79     return plat_;
80 }
81 
Create(PlatformCreateInfo const & createInfo)82 CORE_NS::IPlatform::Ptr Platform::Create(PlatformCreateInfo const& createInfo)
83 {
84     return CORE_NS::IPlatform::Ptr(new PlatformOHOS(createInfo));
85 }
86 
87 CORE_END_NAMESPACE()
88