• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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 /**
17  * @addtogroup rawfile
18  * @{
19  *
20  * @brief Provides native functions for the resource manager to operate raw file directories and their raw files.
21  *
22  * You can use the resource manager to traverse, open, seek, read, and close raw files.
23  *
24  * @since 8
25  * @version 1.0
26  */
27 
28 /**
29  * @file raw_file_manager.h
30  *
31  * @brief Declares native functions for the resource manager.
32  *
33  * You can use the resource manager to open raw files for subsequent operations, such as seeking and reading.
34  *
35  * @syscap SystemCapability.Global.ResourceManager
36  * @library librawfile.z.so
37  * @kit LocalizationKit
38  * @since 8
39  * @version 1.0
40  */
41 #ifndef GLOBAL_NATIVE_RESOURCE_MANAGER_H
42 #define GLOBAL_NATIVE_RESOURCE_MANAGER_H
43 
44 #include "napi/native_api.h"
45 #include "raw_dir.h"
46 #include "raw_file.h"
47 
48 #ifdef __cplusplus
49 extern "C" {
50 #endif
51 
52 struct NativeResourceManager;
53 
54 /**
55  * @brief Presents the resource manager.
56  *
57  * This class encapsulates the native implementation of the JavaScript resource manager. The pointer to a
58  * <b>ResourceManager</b> object can be obtained by calling {@link OH_ResourceManager_InitNativeResourceManager}.
59  *
60  * @since 8
61  * @version 1.0
62  */
63 typedef struct NativeResourceManager NativeResourceManager;
64 
65 /**
66  * @brief Obtains the native resource manager based on the JavaScipt resource manager.
67  *
68  * You need to obtain the resource manager to process raw files as required.
69  *
70  * @param env Indicates the pointer to the JavaScipt Native Interface (napi) environment.
71  * @param jsResMgr Indicates the JavaScipt resource manager.
72  * @return Returns the pointer to {@link NativeResourceManager}. If failed returns nullptr.
73  * @since 8
74  * @version 1.0
75  */
76 NativeResourceManager *OH_ResourceManager_InitNativeResourceManager(napi_env env, napi_value jsResMgr);
77 
78 /**
79  * @brief Releases the native resource manager.
80  *
81  *
82  *
83  * @param resMgr Indicates the pointer to {@link RawDir}.
84  * @since 8
85  * @version 1.0
86  */
87 void OH_ResourceManager_ReleaseNativeResourceManager(NativeResourceManager *resMgr);
88 
89 /**
90  * @brief Opens a raw file directory.
91  *
92  * After it is opened, you can traverse its raw files.
93  *
94  * @param mgr Indicates the pointer to {@link NativeResourceManager} obtained by calling
95  * {@link OH_ResourceManager_InitNativeResourceManager}.
96  * @param dirName Indicates the name of the raw file directory to open. You can pass an empty string to open the
97  * top-level raw file directory.
98  * @return Returns the pointer to {@link RawDir}. If failed or mgr is nullptr also returns nullptr.
99  *         After you finish using the pointer, call {@link OH_ResourceManager_CloseRawDir} to release it.
100  * @see OH_ResourceManager_InitNativeResourceManager
101  * @see OH_ResourceManager_CloseRawDir
102  * @since 8
103  * @version 1.0
104  */
105 RawDir *OH_ResourceManager_OpenRawDir(const NativeResourceManager *mgr, const char *dirName);
106 
107 /**
108  * @brief Opens a raw file.
109  *
110  * After it is opened, you can read its data.
111  *
112  * @param mgr Indicates the pointer to {@link NativeResourceManager} obtained by calling
113  * {@link OH_ResourceManager_InitNativeResourceManager}.
114  * @param fileName Indicates the file path relative to the top-level raw file directory.
115  * @return Returns the pointer to {@link RawFile}. If failed or mgr and fileName is nullptr also returns nullptr.
116  * After you finish using the pointer, call {@link OH_ResourceManager_CloseRawFile} to release it.
117  * @see OH_ResourceManager_InitNativeResourceManager
118  * @see OH_ResourceManager_CloseRawFile
119  * @since 8
120  * @version 1.0
121  */
122 RawFile *OH_ResourceManager_OpenRawFile(const NativeResourceManager *mgr, const char *fileName);
123 
124 /**
125  * @brief Opens a raw file.
126  *
127  * After it is opened, you can read its data.
128  *
129  * @param mgr Indicates the pointer to {@link NativeResourceManager} obtained by calling
130  * {@link OH_ResourceManager_InitNativeResourceManager}.
131  * @param fileName Indicates the file path relative to the top-level raw file directory.
132  * @return Returns the pointer to {@link RawFile64}. If failed or mgr and fileName is nullptr also returns nullptr.
133  * After you finish using the pointer, call {@link OH_ResourceManager_CloseRawFile64} to release it.
134  * @see OH_ResourceManager_InitNativeResourceManager
135  * @see OH_ResourceManager_CloseRawFile64
136  * @since 11
137  * @version 1.0
138  */
139 RawFile64 *OH_ResourceManager_OpenRawFile64(const NativeResourceManager *mgr, const char *fileName);
140 
141 /**
142  * @brief Whether the rawfile resource is a directory or not.
143  *
144  * @param mgr Indicates the pointer to {@link NativeResourceManager} obtained by calling
145  * {@link OH_ResourceManager_InitNativeResourceManager}.
146  * @param path Indicates the rawfile resource relative path.
147  * @return Returns true means the file path is directory, else false.
148  * @since 12
149  * @version 1.0
150  */
151 bool OH_ResourceManager_IsRawDir(const NativeResourceManager *mgr, const char *path);
152 
153 #ifdef __cplusplus
154 };
155 #endif
156 
157 /** @} */
158 #endif // GLOBAL_NATIVE_RESOURCE_MANAGER_H
159