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 #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 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
RegisterDefaultPaths(IFileManager & fileManager)36 BASE_NS::string PlatformOHOS::RegisterDefaultPaths(IFileManager& fileManager)
37 {
38 // register HapFilesystem
39 BASE_NS::string hapPath = plat_.hapPath;
40 BASE_NS::string bundleName = plat_.bundleName;
41 BASE_NS::string moduleName = plat_.moduleName;
42 fileManager.RegisterFilesystem("OhosRawFile",
43 IFilesystem::Ptr{new Core::OhosFilesystem(hapPath, bundleName, moduleName)});
44 CORE_LOG_I("Registered hapFilesystem by Platform: 'hapPath:%s bundleName:%s moduleName:%s'",
45 hapPath.c_str(), bundleName.c_str(), moduleName.c_str());
46 const BASE_NS::string coreDirectory = "file://" + plat_.coreRootPath;
47 fileManager.RegisterPath("plugins", coreDirectory, false);
48 return coreDirectory;
49 }
50
~PlatformOHOS()51 PlatformOHOS::~PlatformOHOS() {}
52
RegisterPluginLocations(IPluginRegister & registry)53 void PlatformOHOS::RegisterPluginLocations(IPluginRegister& registry)
54 {
55 constexpr BASE_NS::string_view fileproto("file://");
56 registry.RegisterPluginPath(fileproto + GetPlatformData().coreRootPath);
57 if (!GetPlatformData().appPluginPath.empty()) {
58 registry.RegisterPluginPath(fileproto + GetPlatformData().appPluginPath);
59 }
60 }
61
GetPlatformData() const62 const PlatformData& PlatformOHOS::GetPlatformData() const
63 {
64 return plat_;
65 }
66
Create(PlatformCreateInfo const & createInfo)67 CORE_NS::IPlatform::Ptr Platform::Create(PlatformCreateInfo const& createInfo)
68 {
69 return CORE_NS::IPlatform::Ptr(new PlatformOHOS(createInfo));
70 }
71 CORE_END_NAMESPACE()
72