mirror of
https://gitee.com/openharmony/distributeddatamgr_data_share
synced 2024-11-27 00:51:17 +00:00
appdatamgr分仓data_share
Signed-off-by: PaDaBoo <xuejianwu@huawei.com>
This commit is contained in:
parent
73cd586e66
commit
29c237f047
66
OAT.xml
66
OAT.xml
@ -1,66 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- Copyright (c) 2021 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.
|
||||
|
||||
Notes:
|
||||
This is project config file for OpenHarmony OSS Audit Tool, if you have any questions or concerns, please email chenyaxun.
|
||||
-->
|
||||
|
||||
<!-- OAT(OSS Audit Tool) configuration guide:
|
||||
basedir: Root dir, the basedir + project path is the real source file location.
|
||||
licensefile:
|
||||
1.If the project don't have "LICENSE" in root dir, please define all the license files in this project in , OAT will check license files according to this rule.
|
||||
|
||||
tasklist(only for batch mode):
|
||||
1. task: Define oat check thread, each task will start a new thread.
|
||||
2. task name: Only an name, no practical effect.
|
||||
3. task policy: Default policy for projects under this task, this field is required and the specified policy must defined in policylist.
|
||||
4. task filter: Default filefilter for projects under this task, this field is required and the specified filefilter must defined in filefilterlist.
|
||||
5. task project: Projects to be checked, the path field define the source root dir of the project.
|
||||
|
||||
|
||||
policyList:
|
||||
1. policy: All policyitems will be merged to default OAT.xml rules, the name of policy doesn't affect OAT check process.
|
||||
2. policyitem: The fields type, name, path, desc is required, and the fields rule, group, filefilter is optional,the default value is:
|
||||
<policyitem type="" name="" path="" desc="" rule="may" group="defaultGroup" filefilter="defaultPolicyFilter"/>
|
||||
3. policyitem type:
|
||||
"compatibility" is used to check license compatibility in the specified path;
|
||||
"license" is used to check source license header in the specified path;
|
||||
"copyright" is used to check source copyright header in the specified path;
|
||||
"import" is used to check source dependency in the specified path, such as import ... ,include ...
|
||||
"filetype" is used to check file type in the specified path, supported file types: archive, binary
|
||||
"filename" is used to check whether the specified file exists in the specified path(support projectroot in default OAT.xml), supported file names: LICENSE, README, README.OpenSource
|
||||
|
||||
4. policyitem name: This field is used for define the license, copyright, "*" means match all, the "!" prefix means could not match this value. For example, "!GPL" means can not use GPL license.
|
||||
5. policyitem path: This field is used for define the source file scope to apply this policyitem, the "!" prefix means exclude the files. For example, "!.*/lib/.*" means files in lib dir will be exclude while process this policyitem.
|
||||
6. policyitem rule and group: These two fields are used together to merge policy results. "may" policyitems in the same group means any one in this group passed, the result will be passed.
|
||||
7. policyitem filefilter: Used to bind filefilter which define filter rules.
|
||||
8. filefilter: Filter rules, the type filename is used to filter file name, the type filepath is used to filter file path.
|
||||
|
||||
Note:If the text contains special characters, please escape them according to the following rules:
|
||||
" == >
|
||||
& == >
|
||||
' == >
|
||||
< == >
|
||||
> == >
|
||||
-->
|
||||
<configuration>
|
||||
<oatconfig>
|
||||
<filefilterlist>
|
||||
<filefilter name="binaryFileTypePolicyFilter" desc="Filters for binary file policies" >
|
||||
<filteritem type="filepath" name=".*.db" desc="Database data file used for test case execution."/>
|
||||
</filefilter>
|
||||
</filefilterlist>
|
||||
</oatconfig>
|
||||
</configuration>
|
110
README.md
110
README.md
@ -1,110 +0,0 @@
|
||||
# distributeddatamgr\_appdatamgr<a name="EN-US_TOPIC_0000001124534865"></a>
|
||||
|
||||
- [Introduction](#section11660541593)
|
||||
- [RDB](#section1589234172717)
|
||||
- [Preferences Database](#section1287582752719)
|
||||
|
||||
- [Directory Structure](#section161941989596)
|
||||
- [Relational Database](#section101010894114)
|
||||
- [Constraints](#section18387142613414)
|
||||
|
||||
- [Preferences Database](#section762641474720)
|
||||
- [Constraints](#section1944481420489)
|
||||
|
||||
- [Repositories Involved](#section1371113476307)
|
||||
|
||||
## Introduction<a name="section11660541593"></a>
|
||||
|
||||
The **relational database \(RDB\)** manages data based on relational models. With the underlying SQLite database, the OpenHarmony RDB provides a complete mechanism for managing local databases.
|
||||
|
||||
The **preferences database** provides lightweight key-value operations for local applications to store a small amount of data. As the stored data is already loaded in the memory, the faster data access speed achieves a higher work efficiency. The preferences database is non-relational, and therefore it is not suitable for storing a large amount of data. Instead, the preferences database is usually used to operate data in key-value pairs.
|
||||
|
||||
### RDB<a name="section1589234172717"></a>
|
||||
|
||||
With the SQLite database as the persistence engine, the OpenHarmony RDB supports all features of the SQLite database , including but not limited to transactions, indices, views, triggers, foreign keys, parameterized queries, and prepared SQL statements.
|
||||
|
||||
**Figure 1** How RDB works<a name="fig3330103712254"></a>
|
||||
|
||||
|
||||
![](figures/en-us_How_RDB_works.png)
|
||||
|
||||
### Preferences Database<a name="section1287582752719"></a>
|
||||
|
||||
1. The preferences database provides operation classes for applications to operate the database.
|
||||
2. With the **PreferencesHelper**, an app can load the content of a specified file to the **Preferences** instance. Each file has only one **Preferences** instance. The system stores the instance in the memory through a static container until the app removes the instance from the memory or deletes the file.
|
||||
3. After obtaining the **Preferences** instance, the app can use the functions in **Preferences** to read data from or write data to the **Preferences** instance, and use **flush\(\)** or **flushSync\(\)** to save the modification to the file that stores the preference data.
|
||||
|
||||
**Figure 2** How the preferences database works<a name="fig833053712258"></a>
|
||||
|
||||
|
||||
![](figures/en-us_How_the_preferences_database_works.png)
|
||||
|
||||
## Directory Structure<a name="section161941989596"></a>
|
||||
|
||||
```
|
||||
//foundation/distributeddatamgr/appdatamgr
|
||||
├── frameworks # Framework code
|
||||
│ └── js # JS API implementation
|
||||
│ │ └── napi # napi implementation
|
||||
│ └── native # Internal API implementation
|
||||
└── interfaces # APIs
|
||||
└── inner_api # Internal APIs
|
||||
└── native # C/C++ APIs
|
||||
```
|
||||
|
||||
## Relational Database<a name="section101010894114"></a>
|
||||
|
||||
Some basic concepts are as follows:
|
||||
|
||||
- **Relational database \(RDB\)**
|
||||
|
||||
A database created on the basis of relational models. The RDB stores data in rows and columns.
|
||||
|
||||
- **Result set**
|
||||
|
||||
A set of query results used to access the data. You can access the required data in a result set in flexible modes.
|
||||
|
||||
- **SQLite database**
|
||||
|
||||
A lightweight RDB in compliance with the atomicity, consistency, isolation, and durability \(ACID\) properties. It is an open-source database.
|
||||
|
||||
|
||||
### Constraints<a name="section18387142613414"></a>
|
||||
|
||||
The RDB can use a maximum of four connection pools to manage read and write operations.
|
||||
|
||||
To ensure data accuracy, the RDB supports only one writ operation at a time.
|
||||
|
||||
## Preferences Database<a name="section762641474720"></a>
|
||||
|
||||
Some basic concepts are as follows:
|
||||
|
||||
- **Key-value database**
|
||||
|
||||
A database that stores data in key-value pairs. The **key** indicates keyword, and **value** indicates the corresponding value.
|
||||
|
||||
- **Non-relational database**
|
||||
|
||||
A database not in compliance with the atomicity, consistency, isolation, and durability \(ACID\) database management properties of relational data transactions. Instead, the data in a non-relational database is independent and scalable.
|
||||
|
||||
- **Preference** **data**
|
||||
|
||||
A type of data that is frequently accessed and used.
|
||||
|
||||
|
||||
### Constraints<a name="section1944481420489"></a>
|
||||
|
||||
A key should be a string with a maximum of 80 characters and cannot be an empty string.
|
||||
|
||||
A value in the format of string can have a maximum of 8192 characters. A value can be an empty string.
|
||||
|
||||
To avoid a high memory cost, it is recommended that the preferences database store no more than ten thousand data entries.
|
||||
|
||||
## Repositories Involved<a name="section1371113476307"></a>
|
||||
|
||||
- [Distributed Data Management subsystem](https://gitee.com/openharmony/docs/blob/master/en/readme/distributed-data-management.md)
|
||||
|
||||
- **distributeddatamgr\_appdatamgr**
|
||||
|
||||
- [third\_party\_sqlite](https://gitee.com/openharmony/third_party_sqlite)
|
||||
|
57
README_zh.md
57
README_zh.md
@ -1,29 +1,52 @@
|
||||
# 本地数据管理组件
|
||||
# 数据共享
|
||||
|
||||
## 简介
|
||||
### [关系型数据库(Relational Database,RDB)](relational_store/README_zh.md)
|
||||
|
||||
是一种基于关系模型来管理数据的数据库。OpenHarmony关系型数据库基于SQLite组件提供了一套完整的对本地数据库进行管理的机制。
|
||||
### [首选项(Preferences)](preferences/README_zh.md)
|
||||
**数据共享(Data Share)** 提供了向其他应用共享以及管理其数据的方法,支持同个设备上不同应用之间的数据共享。
|
||||
|
||||
主要提供轻量级Key-Value操作,支持本地应用存储少量数据,数据存储在本地文件中,同时也加载在内存中,所以访问速度更快,效率更高。首选项提供非关系型数据存储,不宜存储大量数据,经常用于操作键值对形式数据的场景。
|
||||
### [数据共享(DataShare)](data_share/README_zh.md)
|
||||
**图 1** 逻辑架构图
|
||||
|
||||
主要用于应用管理其自身数据,同时支持同个设备上不同应用间的数据共享。
|
||||
### [轻量系统KV数据库(Lightweight KV store)](kv_store/README_zh.md)
|
||||
![](figures/zh-cn_dataShare.png)
|
||||
|
||||
- DataShareExtAbility模块为数据提供方,实现跨应用数据共享的相关业务。
|
||||
- DataShareHelper模块为数据访问方,提供各种访问数据的接口,包括增删改查等。
|
||||
- 数据访问方与提供方通过IPC进行通信,数据提供方可以通过数据库实现,也可以通过其他数据存储方式实现。
|
||||
- ResultSet模块通过共享内存实现,用于存储查询数据得到的结果集,并提供了遍历结果集的方法。
|
||||
|
||||
依托当前公共基础库提供的KV存储能力开发,为轻量系统设备应用提供键值对数据管理能力。在有进程的平台上,KV存储提供的参数管理,供单进程访问不能被其他进程使用。在此类平台上,KV存储作为基础库加载在应用进程,以保障不被其他进程访问。
|
||||
## 目录
|
||||
|
||||
```
|
||||
//foundation/distributeddatamgr/appdatamgr
|
||||
├── data_share # 数据共享(DataShare)
|
||||
├── kv_store # 轻量系统KV数据库(Lightweight KV store)
|
||||
├── preferences # 首选项(Preferences)
|
||||
└── relational_store # 关系型数据库(RDB)
|
||||
/foundation/distributeddatamgr/data_share
|
||||
├── frameworks # 框架代码
|
||||
│ ├── js
|
||||
│ │ └── napi # NAPI代码存放目录
|
||||
│ │ ├── common # 公用NAPI代码存放目录
|
||||
│ │ ├── dataShare # 客户端NAPI代码存放目录
|
||||
│ │ ├── datashare_ext_ability # DataShareExtentionAbility模块JS代码存放目录
|
||||
│ │ └── datashare_ext_ability_context # DataShareExtentionAbilityContext模块JS代码存放目录
|
||||
│ └── native
|
||||
│ ├── common
|
||||
│ ├── consumer
|
||||
│ └── provider
|
||||
└── interfaces # 对外接口存放目录
|
||||
└── inner_api # 对内部子系统暴露的头文件存放目录
|
||||
├── common # 公用对内部子系统暴露的头文件存放目录
|
||||
├── consumer # 客户端对内部子系统暴露的头文件存放目录
|
||||
└── provider # 服务端对内部子系统暴露的头文件存放目录
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
## 约束
|
||||
|
||||
- DataShare受到数据提供方所使用数据库的一些限制。例如支持的数据模型、Key的长度、Value的长度、每个应用程序支持同时打开数据库的最大数量等,都会受到使用的数据库的限制。
|
||||
- 因DataShare内部实现依赖于IPC通信,所以数据集、谓词、结果集等的载荷受到IPC通信的约束与限制。
|
||||
|
||||
## 相关仓
|
||||
- [分布式数据管理子系统](https://gitee.com/openharmony/docs/blob/master/zh-cn/readme/%E5%88%86%E5%B8%83%E5%BC%8F%E6%95%B0%E6%8D%AE%E7%AE%A1%E7%90%86%E5%AD%90%E7%B3%BB%E7%BB%9F.md)
|
||||
|
||||
- [**distributeddatamgr\_appdatamgr**](https://gitee.com/openharmony/distributeddatamgr_appdatamgr/blob/master/README_zh.md)
|
||||
[分布式数据管理子系统](https://gitee.com/openharmony/distributeddatamgr_data_share/blob/master/README_zh.md)
|
||||
|
||||
- [third\_party\_sqlite](https://gitee.com/openharmony/third_party_sqlite)
|
||||
[distributeddatamgr_datamgr](https://gitee.com/openharmony/distributeddatamgr_datamgr/blob/master/README_zh.md)
|
||||
|
||||
[**distributeddatamgr_data_share**](https://gitee.com/openharmony/distributeddatamgr_data_share/blob/master/README_zh.md)
|
@ -1,16 +0,0 @@
|
||||
# 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.
|
||||
|
||||
declare_args() {
|
||||
relational_store_rdb_support_icu = true
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
# 数据共享
|
||||
|
||||
## 简介
|
||||
|
||||
**数据共享(Data Share)** 提供了向其他应用共享以及管理其数据的方法,支持同个设备上不同应用之间的数据共享。
|
||||
|
||||
**图 1** 逻辑架构图
|
||||
|
||||
![](figures/zh-cn_dataShare.png)
|
||||
|
||||
- DataShareExtAbility模块为数据提供方,实现跨应用数据共享的相关业务。
|
||||
- DataShareHelper模块为数据访问方,提供各种访问数据的接口,包括增删改查等。
|
||||
- 数据访问方与提供方通过IPC进行通信,数据提供方可以通过数据库实现,也可以通过其他数据存储方式实现。
|
||||
- ResultSet模块通过共享内存实现,用于存储查询数据得到的结果集,并提供了遍历结果集的方法。
|
||||
|
||||
## 目录
|
||||
|
||||
```
|
||||
/foundation/distributeddatamgr/data_share
|
||||
├── frameworks # 框架代码
|
||||
│ ├── js
|
||||
│ │ └── napi # NAPI代码存放目录
|
||||
│ │ ├── common # 公用NAPI代码存放目录
|
||||
│ │ ├── dataShare # 客户端NAPI代码存放目录
|
||||
│ │ ├── datashare_ext_ability # DataShareExtentionAbility模块JS代码存放目录
|
||||
│ │ └── datashare_ext_ability_context # DataShareExtentionAbilityContext模块JS代码存放目录
|
||||
│ └── native
|
||||
│ ├── common
|
||||
│ ├── consumer
|
||||
│ └── provider
|
||||
└── interfaces # 对外接口存放目录
|
||||
└── inner_api # 对内部子系统暴露的头文件存放目录
|
||||
├── common # 公用对内部子系统暴露的头文件存放目录
|
||||
├── consumer # 客户端对内部子系统暴露的头文件存放目录
|
||||
└── provider # 服务端对内部子系统暴露的头文件存放目录
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
## 约束
|
||||
|
||||
- DataShare受到数据提供方所使用数据库的一些限制。例如支持的数据模型、Key的长度、Value的长度、每个应用程序支持同时打开数据库的最大数量等,都会受到使用的数据库的限制。
|
||||
- 因DataShare内部实现依赖于IPC通信,所以数据集、谓词、结果集等的载荷受到IPC通信的约束与限制。
|
||||
|
||||
## 相关仓
|
||||
|
||||
[分布式数据管理子系统](https://gitee.com/openharmony/distributeddatamgr_data_share/blob/master/README_zh.md)
|
||||
|
||||
[distributeddatamgr_datamgr](https://gitee.com/openharmony/distributeddatamgr_datamgr/blob/master/README_zh.md)
|
||||
|
||||
[**distributeddatamgr_data_share**](https://gitee.com/openharmony/distributeddatamgr_data_share/blob/master/README_zh.md)
|
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 32 KiB |
@ -1,39 +0,0 @@
|
||||
# 轻量系统KV数据库(Lightweight KV store)
|
||||
|
||||
## 简介
|
||||
|
||||
**轻量系统KV数据库(Lightweight KV store)** 依托当前公共基础库提供的KV存储能力开发,为轻量系统设备应用提供键值对数据管理能力。在有进程的平台上,KV存储提供的参数管理,供单进程访问不能被其他进程使用。在此类平台上,KV存储作为基础库加载在应用进程,以保障不被其他进程访问。
|
||||
|
||||
1. 当前先支持轻量键值(KV)本地数据存储能力,后续会逐步支持其他更丰富的数据类型。
|
||||
2. 轻量键值(KV)数据:数据有结构,文件轻量,具有简易事务性,单独提供一套专用的键值对接口
|
||||
|
||||
**目前,在轻量系统上默认关闭该特性,需要使用时请用户修改vendor_hisilicon仓配置以开启。**
|
||||
|
||||
## 目录
|
||||
|
||||
```
|
||||
//foundation/distributeddatamgr/kv_store
|
||||
├── frameworks # 框架层代码
|
||||
│ └── js # JS API的实现
|
||||
│ │ └── napi # napi代码实现
|
||||
│ └── native # 内部接口实现
|
||||
├── interfaces # 接口代码
|
||||
└── inner_api # 内部接口声明
|
||||
```
|
||||
## 约束
|
||||
|
||||
- KV大小及可存储条目数在平台可承受内可修改配置,轻量系统默认为小于Key(32byte),Value(512byte),通过修改编译宏修改;
|
||||
|
||||
- 依赖平台具有正常的文件创建、读写删除修改、锁等能力,针对不同平台(如LiteOS-M内核、LiteOS-A内核等)尽可能表现接口语义功能的不变;
|
||||
|
||||
- 由于平台能力差异数据库能力需要做相应裁剪,其中不同平台内部实现可能不同;
|
||||
|
||||
- 对于指定路径仅支持创建数据库单例,不支持同一路径创建多数据库实例对象。
|
||||
|
||||
## 相关仓
|
||||
|
||||
- [分布式数据管理子系统](https://gitee.com/openharmony/docs/blob/master/zh-cn/readme/%E5%88%86%E5%B8%83%E5%BC%8F%E6%95%B0%E6%8D%AE%E7%AE%A1%E7%90%86%E5%AD%90%E7%B3%BB%E7%BB%9F.md)
|
||||
|
||||
- [**distributeddatamgr\_kv_store**](https://gitee.com/openharmony/distributeddatamgr_kv_store/blob/master/README_zh.md)
|
||||
|
||||
- [third\_party\_sqlite](https://gitee.com/openharmony/third_party_sqlite)
|
@ -1,36 +0,0 @@
|
||||
{
|
||||
"name": "@openharmony/kv_store",
|
||||
"version": "3.1.0",
|
||||
"license": "Apache License 2.0",
|
||||
"description": "",
|
||||
"publishAs": "code-segment",
|
||||
"segment": {
|
||||
"destPath": "foundation/distributeddatamgr/kv_store/interfaces/inner_api/kv_store"
|
||||
},
|
||||
"dirs": {},
|
||||
"scripts": {},
|
||||
"component": {
|
||||
"name": "kv_store",
|
||||
"subsystem": "distributeddatamgr",
|
||||
"features": [],
|
||||
"adapted_system_type": [
|
||||
"mini",
|
||||
"small"
|
||||
],
|
||||
"rom": "13KB",
|
||||
"ram": "80KB",
|
||||
"deps": {
|
||||
"thrid_party": [ "bounds_checking_function" ],
|
||||
"kernel_special": {},
|
||||
"board_special": {},
|
||||
"components": [
|
||||
"utils_lite"
|
||||
]
|
||||
},
|
||||
"build": {
|
||||
"sub_component": [ "//foundation/distributeddatamgr/kv_store/interfaces/inner_api/kv_store" ],
|
||||
"inner_kits": [],
|
||||
"test": []
|
||||
}
|
||||
}
|
||||
}
|
@ -1,74 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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.
|
||||
*/
|
||||
#ifndef DBM_DEF_H
|
||||
#define DBM_DEF_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/* default max len of KV */
|
||||
#define MAX_KEY_LEN 32 // the suffix is 7 bytes
|
||||
#ifndef MAX_VALUE_LEN
|
||||
#define MAX_VALUE_LEN 512
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Defintion of macro using in KVStore.
|
||||
*/
|
||||
|
||||
#define DBM_SW_VERSION "1.0"
|
||||
#define DBM_SW_VERSION_NUM 0x10
|
||||
|
||||
#define DBM_CTRL_SET_LOCK 0x0 /* set lock function control command */
|
||||
#define DBM_CTRL_SET_UNLOCK 0x1 /* set unlock function control command */
|
||||
|
||||
/* log function: default DBM_PRINT macro is printf */
|
||||
#ifndef DBM_PRINT
|
||||
#define DBM_PRINT(...) printf(__VA_ARGS__)
|
||||
#endif
|
||||
#define DBM_LOG_PREFIX1() DBM_PRINT("[DataMgrKVDB]"DBM_LOG_TAG)
|
||||
#define DBM_LOG_PREFIX2() DBM_PRINT(" ")
|
||||
#define DBM_LOG_PREFIX() DBM_LOG_PREFIX1();DBM_LOG_PREFIX2()
|
||||
#ifdef DBM_DEBUG_ENABLE
|
||||
#define DBM_DEBUG(...) DBM_LOG_PREFIX();DBM_PRINT(__VA_ARGS__);DBM_PRINT("\n")
|
||||
#else
|
||||
#define DBM_DEBUG(...)
|
||||
#endif
|
||||
|
||||
#ifdef DBM_RUNTIME_LOG_ENABLE
|
||||
/* routine print function. Must be implement by user. */
|
||||
#define DBM_INFO(...) DBM_LOG_PREFIX();DBM_PRINT(__VA_ARGS__);DBM_PRINT("\n")
|
||||
#else
|
||||
#define DBM_INFO(...)
|
||||
#endif
|
||||
|
||||
/* assert for developer */
|
||||
#define DBM_ASSERT(EXPR) \
|
||||
if (!(EXPR)) \
|
||||
{ \
|
||||
DBM_DEBUG("%s has assert failed at %s.", #EXPR, __FUNCTION__); \
|
||||
while (1); \
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* DBM_DEF_H */
|
File diff suppressed because it is too large
Load Diff
@ -1,54 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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.
|
||||
*/
|
||||
|
||||
/* This function is not open for user now */
|
||||
#include "dbm_kv_store.h"
|
||||
|
||||
#include "dbm_errno.h"
|
||||
|
||||
#ifdef DBM_DEBUG_ENABLE
|
||||
#define DBM_LOG_TAG "[low_posix][kv]"
|
||||
#endif
|
||||
|
||||
int DBM_GetKVStore(const char* storeFullPath, KVStoreHandle* db)
|
||||
{
|
||||
return DBM_NOT_SUPPORT;
|
||||
}
|
||||
|
||||
int DBM_Get(KVStoreHandle db, const char* key, void* value, unsigned int count, unsigned int* realValueLen)
|
||||
{
|
||||
return DBM_NOT_SUPPORT;
|
||||
}
|
||||
int DBM_Put(KVStoreHandle db, const char* key, const void* value, unsigned int len)
|
||||
{
|
||||
return DBM_NOT_SUPPORT;
|
||||
}
|
||||
int DBM_Delete(KVStoreHandle db, const char* key)
|
||||
{
|
||||
return DBM_NOT_SUPPORT;
|
||||
}
|
||||
|
||||
int DBM_CloseKVStore(KVStoreHandle db)
|
||||
{
|
||||
return DBM_NOT_SUPPORT;
|
||||
}
|
||||
int DBM_DeleteKVStore(const char* storeFullPath)
|
||||
{
|
||||
return DBM_NOT_SUPPORT;
|
||||
}
|
||||
|
||||
void DBM_KVStoreControl(KVStoreHandle db, int cmd, void* arg)
|
||||
{
|
||||
}
|
@ -1,198 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
|
||||
#include "kvstore_common.h"
|
||||
#include <ctype.h>
|
||||
#include <securec.h>
|
||||
#include <stdlib.h>
|
||||
#include "ohos_errno.h"
|
||||
|
||||
#ifdef FEATURE_KV_CACHE
|
||||
static KvItem* g_itemHeader = NULL;
|
||||
static KvItem* g_itemTail = NULL;
|
||||
static int g_sum = 0;
|
||||
#endif
|
||||
|
||||
boolean IsValidChar(const char ch)
|
||||
{
|
||||
if (islower(ch) || isdigit(ch) || (ch == '_') || (ch == '.')) {
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
boolean IsValidValue(const char* value, unsigned int len)
|
||||
{
|
||||
if (value == NULL) {
|
||||
return FALSE;
|
||||
}
|
||||
size_t valueLen = strnlen(value, MAX_VALUE_LEN);
|
||||
if ((valueLen == 0) || (valueLen >= MAX_VALUE_LEN) || (valueLen >= len)) {
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
boolean IsValidKey(const char* key)
|
||||
{
|
||||
if (!IsValidValue(key, MAX_KEY_LEN)) {
|
||||
return FALSE;
|
||||
}
|
||||
size_t keyLen = strnlen(key, MAX_KEY_LEN);
|
||||
for (size_t i = 0; i < keyLen; i++) {
|
||||
if (!IsValidChar(key[i])) {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
#ifdef FEATURE_KV_CACHE
|
||||
static void FreeItem(KvItem* item)
|
||||
{
|
||||
if (item == NULL) {
|
||||
return;
|
||||
}
|
||||
if (item->key != NULL) {
|
||||
free(item->key);
|
||||
}
|
||||
if (item->value != NULL) {
|
||||
free(item->value);
|
||||
}
|
||||
free(item);
|
||||
}
|
||||
|
||||
void DeleteKVCache(const char* key)
|
||||
{
|
||||
if (key == NULL || g_itemHeader == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
KvItem* item = g_itemHeader;
|
||||
while (strcmp(key, item->key) != 0) {
|
||||
item = item->next;
|
||||
if (item == NULL) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
g_sum--;
|
||||
if (g_sum == 0) {
|
||||
g_itemHeader = NULL;
|
||||
g_itemTail = NULL;
|
||||
} else if (item == g_itemHeader) {
|
||||
g_itemHeader = item->next;
|
||||
g_itemHeader->prev = NULL;
|
||||
} else if (item == g_itemTail) {
|
||||
g_itemTail = item->prev;
|
||||
g_itemTail->next = NULL;
|
||||
} else {
|
||||
item->prev->next = item->next;
|
||||
item->next->prev = item->prev;
|
||||
}
|
||||
FreeItem(item);
|
||||
}
|
||||
|
||||
void AddKVCache(const char* key, const char* value, boolean isNew)
|
||||
{
|
||||
if (key == NULL || value == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
size_t keyLen = strnlen(key, MAX_KEY_LEN);
|
||||
size_t valueLen = strnlen(value, MAX_VALUE_LEN);
|
||||
if ((keyLen >= MAX_KEY_LEN) || (valueLen >= MAX_VALUE_LEN)) {
|
||||
return;
|
||||
}
|
||||
if (isNew) {
|
||||
DeleteKVCache(key);
|
||||
}
|
||||
KvItem* item = (KvItem *)malloc(sizeof(KvItem));
|
||||
if (item == NULL) {
|
||||
return;
|
||||
}
|
||||
(void)memset_s(item, sizeof(KvItem), 0, sizeof(KvItem));
|
||||
item->key = (char *)malloc(keyLen + 1);
|
||||
item->value = (char *)malloc(valueLen + 1);
|
||||
if ((item->key == NULL) || (item->value == NULL)) {
|
||||
FreeItem(item);
|
||||
return;
|
||||
}
|
||||
if ((strcpy_s(item->key, keyLen + 1, key) != EOK) ||
|
||||
(strcpy_s(item->value, valueLen + 1, value) != EOK)) {
|
||||
FreeItem(item);
|
||||
return;
|
||||
}
|
||||
item->prev = NULL;
|
||||
item->next = NULL;
|
||||
if (g_itemHeader == NULL) {
|
||||
g_itemHeader = item;
|
||||
g_itemTail = item;
|
||||
g_sum++;
|
||||
return;
|
||||
}
|
||||
item->next = g_itemHeader;
|
||||
g_itemHeader->prev = item;
|
||||
g_itemHeader = item;
|
||||
g_sum++;
|
||||
while (g_sum > MAX_CACHE_SIZE) {
|
||||
KvItem* needDel = g_itemTail;
|
||||
g_itemTail = g_itemTail->prev;
|
||||
FreeItem(needDel);
|
||||
g_itemTail->next = NULL;
|
||||
g_sum--;
|
||||
}
|
||||
}
|
||||
|
||||
int GetValueByCache(const char* key, char* value, unsigned int maxLen)
|
||||
{
|
||||
if (key == NULL || value == NULL || g_itemHeader == NULL) {
|
||||
return EC_FAILURE;
|
||||
}
|
||||
|
||||
KvItem* item = g_itemHeader;
|
||||
while (strcmp(key, item->key) != 0) {
|
||||
item = item->next;
|
||||
if (item == NULL) {
|
||||
return EC_FAILURE;
|
||||
}
|
||||
}
|
||||
size_t valueLen = strnlen(item->value, MAX_VALUE_LEN);
|
||||
if (valueLen >= MAX_VALUE_LEN) {
|
||||
return EC_FAILURE;
|
||||
}
|
||||
if ((valueLen >= maxLen) || (strcpy_s(value, maxLen, item->value) != EOK)) {
|
||||
return EC_FAILURE;
|
||||
}
|
||||
return EC_SUCCESS;
|
||||
}
|
||||
|
||||
int ClearKVCacheInner(void)
|
||||
{
|
||||
if (g_itemHeader == NULL) {
|
||||
return EC_SUCCESS;
|
||||
}
|
||||
KvItem* item = g_itemHeader;
|
||||
while (item != NULL) {
|
||||
KvItem* temp = item;
|
||||
item = item->next;
|
||||
FreeItem(temp);
|
||||
g_sum--;
|
||||
}
|
||||
g_itemHeader = NULL;
|
||||
g_itemTail = NULL;
|
||||
|
||||
return (g_sum != 0) ? EC_FAILURE : EC_SUCCESS;
|
||||
}
|
||||
#endif
|
@ -1,43 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
|
||||
#ifndef KV_STORE_COMMON_H
|
||||
#define KV_STORE_COMMON_H
|
||||
|
||||
#include "ohos_types.h"
|
||||
#include "utils_config.h"
|
||||
|
||||
#define MAX_KEY_LEN 32
|
||||
#define MAX_VALUE_LEN 128
|
||||
|
||||
boolean IsValidChar(const char ch);
|
||||
boolean IsValidValue(const char* value, unsigned int len);
|
||||
boolean IsValidKey(const char* key);
|
||||
|
||||
#ifdef FEATURE_KV_CACHE
|
||||
typedef struct KvItem_ {
|
||||
char* key;
|
||||
char* value;
|
||||
struct KvItem_* next;
|
||||
struct KvItem_* prev;
|
||||
} KvItem;
|
||||
|
||||
void DeleteKVCache(const char* key);
|
||||
void AddKVCache(const char* key, const char* value, boolean isNew);
|
||||
int GetValueByCache(const char* key, char* value, unsigned int maxLen);
|
||||
int ClearKVCacheInner(void);
|
||||
#endif
|
||||
|
||||
#endif // KV_STORE_COMMON_H
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user