• 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 "platform_ohos.h"
17 
18 #include <core/io/intf_file_manager.h>
19 #include <core/log.h>
20 #include <core/namespace.h>
21 
22 #include "os/ohos/ohos_filesystem.h"
23 #include "os/platform.h"
24 
CORE_BEGIN_NAMESPACE()25 CORE_BEGIN_NAMESPACE()
26 PlatformOHOS::PlatformOHOS(PlatformCreateInfo const& createInfo)
27 {
28     plat_.coreRootPath = createInfo.coreRootPath;
29     if (createInfo.corePluginPath.empty()) {
30         plat_.corePluginPath = plat_.coreRootPath;
31     } else {
32         plat_.corePluginPath = createInfo.corePluginPath;
33     }
34     plat_.appRootPath = createInfo.appRootPath;
35     plat_.appPluginPath = createInfo.appPluginPath;
36     plat_.hapPath = createInfo.hapPath;
37     plat_.bundleName = createInfo.bundleName;
38     plat_.moduleName = createInfo.moduleName;
39     plat_.resourceManager = createInfo.resourceManager;
40 }
41 
RegisterDefaultPaths(IFileManager & fileManager) const42 BASE_NS::string PlatformOHOS::RegisterDefaultPaths(IFileManager& fileManager) const
43 {
44     // register HapFilesystem
45     const BASE_NS::string hapPath = plat_.hapPath;
46     const BASE_NS::string bundleName = plat_.bundleName;
47     const BASE_NS::string moduleName = plat_.moduleName;
48     auto resManager = plat_.resourceManager;
49     fileManager.RegisterFilesystem(
50         "OhosRawFile", IFilesystem::Ptr { new Core::OhosFilesystem(hapPath, bundleName, moduleName, resManager) });
51     CORE_LOG_I("Registered hapFilesystem by Platform: 'hapPath:%s bundleName:%s moduleName:%s'", hapPath.c_str(),
52         bundleName.c_str(), moduleName.c_str());
53     const BASE_NS::string coreDirectory = "file://" + plat_.coreRootPath;
54     return coreDirectory;
55 }
56 
~PlatformOHOS()57 PlatformOHOS::~PlatformOHOS() {}
58 
RegisterPluginLocations(IPluginRegister & registry)59 void PlatformOHOS::RegisterPluginLocations(IPluginRegister& registry)
60 {
61     constexpr BASE_NS::string_view fileproto("file://");
62     if (!plat_.corePluginPath.empty()) {
63         registry.RegisterPluginPath(fileproto + plat_.corePluginPath);
64     }
65     if (!plat_.appPluginPath.empty()) {
66         if (plat_.appPluginPath != plat_.corePluginPath) {
67             registry.RegisterPluginPath(fileproto + plat_.appPluginPath);
68         }
69     }
70 }
71 
GetPlatformData() const72 const PlatformData& PlatformOHOS::GetPlatformData() const
73 {
74     return plat_;
75 }
76 
Create(PlatformCreateInfo const & createInfo)77 CORE_NS::IPlatform::Ptr Platform::Create(PlatformCreateInfo const& createInfo)
78 {
79     return CORE_NS::IPlatform::Ptr(new PlatformOHOS(createInfo));
80 }
81 
Extensions(PlatformCreateInfo const & createInfo)82 const CORE_NS::PlatformCreateExtensionInfo* Platform::Extensions(PlatformCreateInfo const& createInfo)
83 {
84     return createInfo.extensions;
85 }
86 CORE_END_NAMESPACE()
87