diff --git a/zh-cn/native_sdk/resmgr/raw_dir.h b/zh-cn/native_sdk/resmgr/raw_dir.h new file mode 100644 index 0000000000000000000000000000000000000000..333b9e78dcaa16fcd5ebc6e868ddc3afca10d691 --- /dev/null +++ b/zh-cn/native_sdk/resmgr/raw_dir.h @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @addtogroup rawfile + * @{ + * + * @brief 提供操作rawfile目录和rawfile文件的功能 + * + * 功能包括遍历、打开、搜索、读取和关闭rawfile + * + * @since 8 + * @version 1.0 + */ + +/** + * @file raw_dir.h + * + * @brief 提供rawfile目录相关功能 + * + * 功能包括遍历和关闭rawfile目录 + * + * @since 8 + * @version 1.0 + */ +#ifndef GLOBAL_RAW_DIR_H +#define GLOBAL_RAW_DIR_H + +#ifdef __cplusplus +extern "C" { +#endif + +struct RawDir; + +/** + * @brief 提供对rawfile目录的访问 + * + * + * + * @since 8 + * @version 1.0 + */ +typedef struct RawDir RawDir; + +/** + * @brief 通过索引获取rawfile文件名称 + * + * 可以使用此方法遍历rawfile目录 + * + * @param rawDir 表示指向{@link RawDir}的指针 + * @param index 表示文件在{@link RawDir}中的索引位置 + * @return 通过索引返回文件名称,此返回值可以作为{@link OH_ResourceManager_OpenRawFile}的输入参数, + * 如果遍历完所有文件仍未找到,则返回NULL + * @see OH_ResourceManager_OpenRawFile + * @since 8 + * @version 1.0 + */ +const char *OH_ResourceManager_GetRawFileName(RawDir *rawDir, int index); + +/** + * @brief 获取{@link RawDir}中的rawfile数量 + * + * 通过此方法可以获取{@link OH_ResourceManager_GetRawFileName}中可用的索引 + * + * @param rawDir 表示指向{@link RawDir}的指针 + * @see OH_ResourceManager_GetRawFileName + * @since 8 + * @version 1.0 + */ +int OH_ResourceManager_GetRawFileCount(RawDir *rawDir); + +/** + * @brief 关闭已打开的{@link RawDir}并释放所有相关联资源 + * + * + * + * @param rawDir 表示指向{@link RawDir}的指针 + * @see OH_ResourceManager_OpenRawDir + * @since 8 + * @version 1.0 + */ +void OH_ResourceManager_CloseRawDir(RawDir *rawDir); + +#ifdef __cplusplus +}; +#endif + +/** @} */ +#endif // GLOBAL_RAW_DIR_H diff --git a/zh-cn/native_sdk/resmgr/raw_file.h b/zh-cn/native_sdk/resmgr/raw_file.h new file mode 100644 index 0000000000000000000000000000000000000000..4d7bdf90aec98f4065ffedd9a062d0e7379a2b04 --- /dev/null +++ b/zh-cn/native_sdk/resmgr/raw_file.h @@ -0,0 +1,172 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @addtogroup rawfile + * @{ + * + * @brief 提供操作rawfile目录和rawfile文件功能 + * + * 功能包括遍历、打开、搜索、读取和关闭rawfile + * + * @since 8 + * @version 1.0 + */ + +/** + * @file raw_file.h + * + * @brief 提供rawfile文件相关功能 + * + * 功能包括搜索、读取和关闭rawfile文件 + * + * @since 8 + * @version 1.0 + */ +#ifndef GLOBAL_RAW_FILE_H +#define GLOBAL_RAW_FILE_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct RawFile; + +/** + * @brief 提供对rawfile的访问功能 + * + * + * + * @since 8 + * @version 1.0 + */ +typedef struct RawFile RawFile; + +/** + * @brief 提供rawfile文件描述符信息 + * + * RawFileDescriptor是{@link OH_ResourceManager_GetRawFileDescriptor}的输出参数, + * 涵盖了rawfile文件的文件描述符以及在HAP包中的起始位置和长度。 + * + * @since 8 + * @version 1.0 + */ +typedef struct { + /** rawfile文件描述符 */ + int fd; + + /** rawfile在HAP包中的起始位置 */ + long start; + + /** rawfile在HAP包中的长度 */ + long length; +} RawFileDescriptor; + +/** + * @brief 读取rawfile + * + * 从当前位置读取指定长度的数据 + * + * @param rawFile 表示指向{@link RawFile}的指针 + * @param buf 用于接收读取数据的缓冲区指针 + * @param length 读取数据的字节长度 + * @return 返回读取的字节数,如果读取长度超过文件末尾长度,则返回0 + * @since 8 + * @version 1.0 + */ +int OH_ResourceManager_ReadRawFile(const RawFile *rawFile, void *buf, int length); + +/** + * @brief 基于指定的offset,在rawfile文件内搜索读写数据的位置 + * + * @param rawFile 表示指向{@link RawFile}的指针 + * @param offset 表示指定的offset + * @param whence 读写位置,有以下场景: \n + * 0: 读写位置为offset \n + * 1: 读写位置为当前位置加上offset \n + * 2: 读写位置为文件末尾(EOF)加上offset + * @return 如果搜索成功返回新的读写位置,如果发生错误返回 (long) -1 + * @since 8 + * @version 1.0 + */ +int OH_ResourceManager_SeekRawFile(const RawFile *rawFile, long offset, int whence); + +/** + * @brief 获取rawfile长度,单位为int32_t + * + * @param rawFile 表示指向{@link RawFile}的指针 + * @return Returns rawfile整体长度 + * @since 8 + * @version 1.0 + */ +long OH_ResourceManager_GetRawFileSize(RawFile *rawFile); + +/** + * @brief 关闭已打开的{@link RawFile} 以及释放所有相关联资源 + * + * + * + * @param rawFile 表示指向{@link RawFile}的指针 + * @see OH_ResourceManager_OpenRawFile + * @since 8 + * @version 1.0 + */ +void OH_ResourceManager_CloseRawFile(RawFile *rawFile); + +/** + * @brief 获取rawfile当前的offset,单位为int32_t + * + * rawfile当前的offset + * + * @param rawFile 表示指向{@link RawFile}的指针 + * @return 返回rawfile当前的offset + * @since 8 + * @version 1.0 + */ +long OH_ResourceManager_GetRawFileOffset(const RawFile *rawFile); + +/** + * @brief 基于offset(单位为int32_t)和文件长度打开rawfile,并获取rawfile文件描述符 + * + * 打开的文件描述符被用于读取rawfile + * + * @param rawFile 表示指向{@link RawFile}的指针 + * @param descriptor 显示rawfile文件描述符,以及在HAP包中的起始位置和长度 + * @return 返回true表示打开rawfile文件描述符成功,返回false表示rawfile不允许被访问 + * @since 8 + * @version 1.0 + */ +bool OH_ResourceManager_GetRawFileDescriptor(const RawFile *rawFile, RawFileDescriptor &descriptor); + +/** + * @brief 关闭rawfile文件描述符 + * + * 已打开的文件描述符在使用完以后必须释放,防止文件描述符泄露 + * + * @param descriptor 包含rawfile文件描述符,以及在HAP包中的起始位置和长度 + * @return 返回true表示关闭文件描述符成功,返回false表示关闭文件描述符失败 + * @since 8 + * @version 1.0 + */ +bool OH_ResourceManager_ReleaseRawFileDescriptor(const RawFileDescriptor &descriptor); + +#ifdef __cplusplus +}; +#endif + +/** @} */ +#endif // GLOBAL_RAW_FILE_H diff --git a/zh-cn/native_sdk/resmgr/raw_file_manager.h b/zh-cn/native_sdk/resmgr/raw_file_manager.h new file mode 100644 index 0000000000000000000000000000000000000000..0f8d5c97815c7a76fff81a8ea77f37b2049f2ec2 --- /dev/null +++ b/zh-cn/native_sdk/resmgr/raw_file_manager.h @@ -0,0 +1,123 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @addtogroup rawfile + * @{ + * + * @brief 提供操作rawfile目录和rawfile文件功能 + * + * 功能包括遍历、打开、搜索、读取和关闭rawfile + * + * @since 8 + * @version 1.0 + */ + +/** + * @file resource_manager.h + * + * @brief 提供资源管理rawfile相关功能 + * + * 可以使用resource manager打开rawfile来进行后续相关操作,像搜索和读取等 + * + * @since 8 + * @version 1.0 + */ +#ifndef GLOBAL_NATIVE_RESOURCE_MANAGER_H +#define GLOBAL_NATIVE_RESOURCE_MANAGER_H + +#include "napi/native_api.h" +#include "raw_dir.h" +#include "raw_file.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct NativeResourceManager; + +/** + * @brief 代表resource manager + * + * 此类封装了JavaScript resource manager的native实现 + * ResourceManager指针可以通过调用{@link OH_ResourceManager_InitNativeResourceManager}方法获取 + * + * @since 8 + * @version 1.0 + */ +typedef struct NativeResourceManager NativeResourceManager; + +/** + * @brief 基于JavaScipt resource manager获取native resource manager + * + * 通过获取resource manager来完成rawfile相关功能 + * + * @param env 表示JavaScipt Native Interface (napi)环境指针 + * @param jsResMgr 表示JavaScipt resource manager + * @return 返回{@link NativeResourceManager}指针 + * @since 8 + * @version 1.0 + */ +NativeResourceManager *OH_ResourceManager_InitNativeResourceManager(napi_env env, napi_value jsResMgr); + +/** + * @brief 释放native resource manager + * + * + * + * @param resMgr 表示{@link NativeResourceManager}指针 + * @since 8 + * @version 1.0 + */ +void OH_ResourceManager_ReleaseNativeResourceManager(NativeResourceManager *resMgr); + +/** + * @brief 打开rawfile目录 + * + * 打开rawfile目录后,可以遍历对应目录下的rawfile文件 + * + * @param mgr 表示指向{@link NativeResourceManager}的指针,此指针是通过调用 + * {@link OH_ResourceManager_InitNativeResourceManager}方法获取的 + * @param dirName 表示要打开的rawfile目录名称,当传递一个空字符串时表示打开rawfile根目录 + * @return 返回{@link RawDir}指针。使用完此指针后,调用{@link OH_ResourceManager_CloseRawDir}释放。 + * @see OH_ResourceManager_InitNativeResourceManager + * @see OH_ResourceManager_CloseRawDir + * @since 8 + * @version 1.0 + */ +RawDir *OH_ResourceManager_OpenRawDir(const NativeResourceManager *mgr, const char *dirName); + +/** + * @brief 打开rawfile文件 + * + * 当打开rawfile以后,可以读取它的数据 + * + * @param mgr 表示指向{@link NativeResourceManager}的指针,此指针是通过调用 + * {@link OH_ResourceManager_InitNativeResourceManager}方法获取的 + * @param fileName 表示基于rawfile根目录的相对路径下的文件名称 + * @return 返回{@link RawFile}指针。当使用完此指针,调用{@link OH_ResourceManager_CloseRawFile}释放。 + * @see OH_ResourceManager_InitNativeResourceManager + * @see OH_ResourceManager_CloseRawFile + * @since 8 + * @version 1.0 + */ +RawFile *OH_ResourceManager_OpenRawFile(const NativeResourceManager *mgr, const char *fileName); + +#ifdef __cplusplus +}; +#endif + +/** @} */ +#endif // GLOBAL_NATIVE_RESOURCE_MANAGER_H diff --git a/zh-cn/native_sdk/resource_mgt/.gitignore b/zh-cn/native_sdk/resource_mgt/.gitignore deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000