提交 53bd195d 编写于 作者: Z zengyawen 提交者: Gitee

Merge branch 'master' of gitee.com:openharmony/docs into master

Signed-off-by: Nzengyawen <zengyawen1@huawei.com>
......@@ -88,7 +88,7 @@ The permission usage record includes the application identity (token ID) of the
| permissionName | Permissions | Yes | Name of the permission.|
| successCount | number | Yes | Number of successful accesses.|
| failCount | number | Yes | Number of failed accesses.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. If a usage record is added successfully, **err** is **undefined**. Otherwise, **err** is an error object.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
**Error codes**
......@@ -196,7 +196,7 @@ Obtains historical permission usage records. This API uses an asynchronous callb
| Name | Type | Mandatory| Description |
| -------- | ------------------- | ---- | ------------------------------------------ |
| request | [PermissionUsedRequest](#permissionusedrequest) | Yes| Request for querying permission usage records.|
| callback | AsyncCallback<[PermissionUsedResponse](#permissionusedresponse)> | Yes| Callback invoked to return the result. If the query is successful, **err** is **undefined** and **data** is the permission usage record. Otherwise, **err** is an error object.|
| callback | AsyncCallback<[PermissionUsedResponse](#permissionusedresponse)> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **undefined** and **data** is the permission usage record obtained. Otherwise, **err** is an error object.|
**Error codes**
......@@ -307,7 +307,7 @@ Starts to use a permission and flushes the permission usage record. This API is
| -------------- | --------------------- | ---- | ------------------------------------ |
| tokenID | number | Yes | Application token ID of the invoker. The value can be obtained from [ApplicationInfo](js-apis-bundle-ApplicationInfo.md).|
| permissionName | Permissions | Yes | Permission to use. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. If the permission is successfully used, **err** is **undefined**. Otherwise, **err** is an error object.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
**Error codes**
......
......@@ -2,35 +2,31 @@
## Introduction
Node-API (NAPI) provides APIs to encapsulate JavaScript capabilities as a native plug-in. It is independent of the underlying JavaScript and is maintained as part of Node.js.
Node-API (NAPI) provides APIs to encapsulate JavaScript (JS) capabilities as a native plug-in. It is independent of the underlying JS and is maintained as part of Node.js.
## Supported Capabilities
NAPI eliminates the differences between underlying JavaScript engines and provides a set of stable interfaces.
NAPI eliminates the differences between underlying JS engines and provides a set of stable interfaces.
The OpenHarmony Native API component optimizes the NAPI interface implementation and provides connection to underlying engines such as ArkJS. Currently, some APIs in the [Node-API](https://nodejs.org/docs/v14.9.0/api/n-api.html) standard library are supported.
The OpenHarmony N-API component optimizes the Node-API interface implementation and provides connection to underlying engines such as ArkJS. Currently, some APIs in the [Node-API](https://nodejs.org/docs/v14.9.0/api/n-api.html) standard library are supported.
## Symbols Extended by the OpenHarmony API Component
## Extended Symbols of the N-API Component
|Type|Symbol|Description|
| --- | --- | --- |
|FUNC|napi_run_script_path|Runs a JavaScript file.|
** Symbols Exported from the NAPI Library**
**Symbols Exported from the NAPI Library**
|Type|Symbol|Description|
| --- | --- | --- |
|FUNC|napi_module_register|Registers the NAPI native module.|
|FUNC|napi_get_last_error_info|Obtains the **napi_extended_error_info** structure, which contains the latest error information.|
|FUNC|napi_throw|Throws a JavaScript value.|
|FUNC|napi_throw_error|Throws a JavaScript **Error** with text information.|
|FUNC|napi_throw_type_error|Throws a JavaScript **TypeError** with text information.|
|FUNC|napi_throw_range_error|Throws a JavaScript **RangeError** with text information.|
|FUNC|napi_throw|Throws a JS value.|
|FUNC|napi_throw_error|Throws a JS **Error** with text information.|
|FUNC|napi_throw_type_error|Throws a JS **TypeError** with text information.|
|FUNC|napi_throw_range_error|Throws a JS **RangeError** with text information.|
|FUNC|napi_is_error|Checks whether **napi_value** indicates an error object.|
|FUNC|napi_create_error|Creates and obtains a JavaScript **Error** with text information.|
|FUNC|napi_create_type_error|Creates and obtains a JavaScript **TypeError** with text information.|
|FUNC|napi_create_range_error|Creates and obtains a JavaScript **RangeError** with text information.|
|FUNC|napi_create_error|Creates and obtains a JS **Error** with text information.|
|FUNC|napi_create_type_error|Creates and obtains a JS **TypeError** with text information.|
|FUNC|napi_create_range_error|Creates and obtains a JS **RangeError** with text information.|
|FUNC|napi_get_and_clear_last_exception|Obtains and clears the latest exception.|
|FUNC|napi_is_exception_pending|Checks whether an exception occurs.|
|FUNC|napi_fatal_error|Raises a fatal error to terminate the process immediately.|
......@@ -38,56 +34,58 @@ The OpenHarmony Native API component optimizes the NAPI interface implementation
|FUNC|napi_close_handle_scope|Closes the context environment. After the context environment is closed, all references declared in it are closed.|
|FUNC|napi_open_escapable_handle_scope|Creates an escapable handle scope from which the declared values can be returned to the parent scope.|
|FUNC|napi_close_escapable_handle_scope|Closes the escapable handle scope passed in.|
|FUNC|napi_escape_handle|Promotes the handle to the input JavaScript object so that it is valid for the lifespan of its parent scope.|
|FUNC|napi_escape_handle|Promotes the handle to the input JS object so that it is valid for the lifespan of its parent scope.|
|FUNC|napi_create_reference|Creates a reference for an **Object** to extend its lifespan. The caller needs to manage the reference lifespan.|
|FUNC|napi_delete_reference|Deletes the reference passed in.|
|FUNC|napi_reference_ref|Increments the reference count for the reference passed in and returns the count.|
|FUNC|napi_reference_unref|Decrements the reference count for the reference passed in and returns the count.|
|FUNC|napi_get_reference_value|Obtains the JavaScript **Object** associated with the reference.|
|FUNC|napi_create_array|Creates and obtains a JavaScript **Array**.|
|FUNC|napi_create_array_with_length|Creates and obtains a JavaScript **Array** of the specified length.|
|FUNC|napi_create_arraybuffer|Creates and obtains a JavaScript **ArrayBuffer** of the specified size.|
|FUNC|napi_create_external|Allocates a JavaScript value with external data.|
|FUNC|napi_create_external_arraybuffer|Allocates a JavaScript **ArrayBuffer** with external data.|
|FUNC|napi_create_object|Creates a default JavaScript **Object**.|
|FUNC|napi_create_symbol|Create a JavaScript **Symbol**.|
|FUNC|napi_create_typedarray|Creates a JavaScript **TypeArray** from an existing **ArrayBuffer**.|
|FUNC|napi_create_dataview|Creates a JavaScript **DataView** from an existing **ArrayBuffer**.|
|FUNC|napi_create_int32|Creates a JavaScript **Number** from C **int32_t** data.|
|FUNC|napi_create_uint32|Creates a JavaScript **Number** from C **uint32_t** data.|
|FUNC|napi_create_int64|Creates a JavaScript **Number** from C **int64_t** data.|
|FUNC|napi_create_double|Creates a JavaScript **Number** from C **double** data.|
|FUNC|napi_create_string_latin1|Creates a JavaScript **String** from an ISO-8859-1-encoded C string.|
|FUNC|napi_create_string_utf8|Creates a JavaScript **String** from a UTF8-encoded C string.|
|FUNC|napi_get_reference_value|Obtains the JS **Object** associated with the reference.|
|FUNC|napi_create_array|Creates and obtains a JS **Array**.|
|FUNC|napi_create_array_with_length|Creates and obtains a JS **Array** of the specified length.|
|FUNC|napi_create_arraybuffer|Creates and obtains a JS **ArrayBuffer** of the specified size.|
|FUNC|napi_create_external|Allocates a JS value with external data.|
|FUNC|napi_create_external_arraybuffer|Allocates a JS **ArrayBuffer** with external data.|
|FUNC|napi_create_object|Creates a default JS **Object**.|
|FUNC|napi_create_symbol|Create a JS **Symbol**.|
|FUNC|napi_create_typedarray|Creates a JS **TypeArray** from an existing **ArrayBuffer**.|
|FUNC|napi_create_dataview|Creates a JS **DataView** from an existing **ArrayBuffer**.|
|FUNC|napi_create_int32|Creates a JS **Number** from C **int32_t** data.|
|FUNC|napi_create_uint32|Creates a JS **Number** from C **uint32_t** data.|
|FUNC|napi_create_int64|Creates a JS **Number** from C **int64_t** data.|
|FUNC|napi_create_double|Creates a JS **Number** from C **double** data.|
|FUNC|napi_create_string_latin1|Creates a JS **String** from an ISO-8859-1-encoded C string.|
|FUNC|napi_create_string_utf8|Creates a JS **String** from a UTF8-encoded C string.|
|FUNC|napi_create_string_utf16|Creates a JS **String** from a UTF16-encoded C string.|
|FUNC|napi_get_array_length|Obtains the length of an array.|
|FUNC|napi_get_arraybuffer_info|Obtains the underlying data buffer of the **ArrayBuffer** and its length.|
|FUNC|napi_get_prototype|Obtains the prototype of the specified JavaScript **Object**.|
|FUNC|napi_get_prototype|Obtains the prototype of the specified JS **Object**.|
|FUNC|napi_get_typedarray_info|Obtains properties of the specified **TypedArray**.|
|FUNC|napi_get_dataview_info|Obtains properties of the specified **DataView**.|
|FUNC|napi_get_value_bool|Obtains the C Boolean equivalent of the given JavaScript **Boolean**.|
|FUNC|napi_get_value_double|Obtains the C double equivalent of the given JavaScript **Number**.|
|FUNC|napi_get_value_bool|Obtains the C Boolean equivalent of the given JS **Boolean**.|
|FUNC|napi_get_value_double|Obtains the C double equivalent of the given JS **Number**.|
|FUNC|napi_get_value_external|Obtains the external data pointer previously passed through **napi_create_external()**.|
|FUNC|napi_get_value_int32|Obtains the C int32 equivalent of the given JavaScript **Number**.|
|FUNC|napi_get_value_int64|Obtains the C int64 equivalent of the given JavaScript **Number**.|
|FUNC|napi_get_value_string_latin1|Obtains the ISO-8859-1-encoded string corresponding to the given JavaScript value.|
|FUNC|napi_get_value_string_utf8|Obtains the UTF8-encoded string corresponding to the given JavaScript value.|
|FUNC|napi_get_value_uint32|Obtains the C uint32 equivalent of the given JavaScript **Number**.|
|FUNC|napi_get_boolean|Obtains the JavaScript Boolean object based on the given C Boolean value.|
|FUNC|napi_get_value_int32|Obtains the C int32 equivalent of the given JS **Number**.|
|FUNC|napi_get_value_int64|Obtains the C int64 equivalent of the given JS **Number**.|
|FUNC|napi_get_value_string_latin1|Obtains the ISO-8859-1-encoded string corresponding to the given JS value.|
|FUNC|napi_get_value_string_utf8|Obtains the UTF8-encoded string corresponding to the given JS value.|
|FUNC|napi_get_value_string_utf16|Obtains the UTF16-encoded string corresponding to the given JS value.|
|FUNC|napi_get_value_uint32|Obtains the C uint32 equivalent of the given JS **Number**.|
|FUNC|napi_get_boolean|Obtains the JS Boolean object based on the given C Boolean value.|
|FUNC|napi_get_global|Obtains the **global** object.|
|FUNC|napi_get_null|Obtains the **null** object.|
|FUNC|napi_get_undefined|Obtains the **undefined** object.|
|FUNC|napi_coerce_to_bool|Forcibly converts the given JavaScript value to a JavaScript Boolean value.|
|FUNC|napi_coerce_to_number|Forcibly converts the given JavaScript value to a JavaScript number.|
|FUNC|napi_coerce_to_object|Forcibly converts the given JavaScript value to a JavaScript object.|
|FUNC|napi_coerce_to_string|Forcibly converts the given JavaScript value to a JavaScript string.|
|FUNC|napi_typeof|Obtains the JavaScript type of the given JavaScript value.|
|FUNC|napi_coerce_to_bool|Forcibly converts the given JS value to a JS Boolean value.|
|FUNC|napi_coerce_to_number|Forcibly converts the given JS value to a JS number.|
|FUNC|napi_coerce_to_object|Forcibly converts the given JS value to a JS object.|
|FUNC|napi_coerce_to_string|Forcibly converts the given JS value to a JS string.|
|FUNC|napi_typeof|Obtains the JS type of the given JS value.|
|FUNC|napi_instanceof|Checks whether the given object is an instance of the specified constructor.|
|FUNC|napi_is_array|Checks whether the given JavaScript value is an array.|
|FUNC|napi_is_arraybuffer|Checks whether the given JavaScript value is a `ArrayBuffer`.|
|FUNC|napi_is_typedarray|Checks whether the given JavaScript value is a **TypedArray**.|
|FUNC|napi_is_dataview|Checks whether the given JavaScript value is a **DataView**.|
|FUNC|napi_is_date|Checks whether the given JavaScript value is a JavaScript **Date** object.|
|FUNC|napi_strict_equals|Checks whether two JavaScript values are strictly equal.|
|FUNC|napi_is_array|Checks whether the given JS value is an array.|
|FUNC|napi_is_arraybuffer|Checks whether the given JS value is a **ArrayBuffer**.|
|FUNC|napi_is_typedarray|Checks whether the given JS value is a **TypedArray**.|
|FUNC|napi_is_dataview|Checks whether the given JS value is a **DataView**.|
|FUNC|napi_is_date|Checks whether the given JS value is a JS **Date** object.|
|FUNC|napi_strict_equals|Checks whether two JS values are strictly equal.|
|FUNC|napi_get_property_names|Obtains the names of the enumerable properties of **Object** in an array of strings.|
|FUNC|napi_set_property|Sets a property for the given **Object**.|
|FUNC|napi_get_property|Obtains the requested property of the given **Object**.|
......@@ -102,24 +100,40 @@ The OpenHarmony Native API component optimizes the NAPI interface implementation
|FUNC|napi_has_element|Obtains the element if the given **Object** has an element at the specified index.|
|FUNC|napi_delete_element|Deletes the element at the specified index of the given **Object**.|
|FUNC|napi_define_properties|Defines multiple properties for the given **Object**.|
|FUNC|napi_call_function|Calls a JavaScript function in a native method, that is, native call JavaScript.|
|FUNC|napi_create_function|Creates a native method for JavaScript to call.|
|FUNC|napi_type_tag_object|Associates the value of the tag pointer with **Object**.|
|FUNC|napi_check_object_type_tag|Checks whether a tag pointer is associated with the JS **Object**.|
|FUNC|napi_call_function|Calls a JS function in a native method, that is, native call JS.|
|FUNC|napi_create_function|Creates a native method for JS to call.|
|FUNC|napi_get_cb_info|Obtains detailed information about the call, such as the parameters and **this** pointer, from the given callback info.|
|FUNC|napi_get_new_target|Obtains the **new.target** of the constructor call.|
|FUNC|napi_new_instance|Creates an instance based on the given constructor.|
|FUNC|napi_define_class|Defines a JavaScript class corresponding to the C++ class.|
|FUNC|napi_wrap|Wraps a native instance in a JavaScript object.|
|FUNC|napi_unwrap|Obtains the native instance that was previously wrapped in a JavaScript object.|
|FUNC|napi_remove_wrap|Obtains the native instance that was previously wrapped in a JavaScript object and removes the wrapping.|
|FUNC|napi_define_class|Defines a JS class corresponding to the C++ class.|
|FUNC|napi_wrap|Wraps a native instance in a JS object.|
|FUNC|napi_unwrap|Obtains the native instance that was previously wrapped in a JS object.|
|FUNC|napi_remove_wrap|Obtains the native instance that was previously wrapped in a JS object and removes the wrapping.|
|FUNC|napi_create_async_work|Creates a work object that executes logic asynchronously.|
|FUNC|napi_delete_async_work|Releases an asynchronous work object.|
|FUNC|napi_queue_async_work|Adds an asynchronous work object to the queue so that it can be scheduled for execution.|
|FUNC|napi_cancel_async_work|Cancels the queued asynchronous work if it has not been started.|
|FUNC|napi_get_node_version|Obtains the current Node-API version.|
|FUNC|napi_get_version|Obtains the latest Node-API version supported when the Node.js runtime.|
|FUNC|napi_create_promise|Creates a deferred object and a JavaScript promise.|
|FUNC|napi_resolve_deferred|Resolves a deferred object that is associated with a JavaScript promise.|
|FUNC|napi_reject_deferred|Rejects a deferred object that is associated with a JavaScript promise.|
|FUNC|napi_is_promise|Checks whether the given JavaScript value is a promise object.|
|FUNC|napi_run_script|Executes a string of JavaScript code.|
|FUNC|napi_create_promise|Creates a deferred object and a JS promise.|
|FUNC|napi_resolve_deferred|Resolves a deferred object that is associated with a JS promise.|
|FUNC|napi_reject_deferred|Rejects a deferred object that is associated with a JS promise.|
|FUNC|napi_is_promise|Checks whether the given JS value is a promise object.|
|FUNC|napi_get_uv_event_loop|Obtains the current libuv loop instance.|
|FUNC|napi_create_threadsafe_function|Creates a thread-safe function.|
|FUNC|napi_get_threadsafe_function_context|Obtains the context of a thread-safe function.|
|FUNC|napi_call_threadsafe_function|Calls a thread-safe function.|
|FUNC|napi_acquire_threadsafe_function|Indicates that a thread starts to use a thread-safe function.|
|FUNC|napi_release_threadsafe_function|Indicates that a thread releases a thread-safe function.|
|FUNC|napi_ref_threadsafe_function|Indicates that the event loop running on the main thread should not exit until the thread-safe function is destroyed.|
|FUNC|napi_unref_threadsafe_function|Indicates that the event loop running on the main thread may exit before the thread-safe function is destroyed.|
|FUNC|napi_create_date|Creates a JS **Date** from C **double** data.|
|FUNC|napi_get_date_value|Obtains the C double equivalent of the given JS **Date**.|
|FUNC|napi_create_bigint_int64|Creates a JS **BigInt** from C **int64** data.|
|FUNC|napi_create_bigint_uint64|Creates a JS **BigInt** from C **uint64** data.|
|FUNC|napi_create_bigint_words|Creates a single JS **BigInt** from a C **uint64** array.|
|FUNC|napi_get_value_bigint_int64|Obtains the C **int64** equivalent of the given JS **BigInt**.|
|FUNC|napi_get_value_bigint_uint64|Obtains the C **uint64** equivalent of the given JS **BigInt**.|
|FUNC|napi_get_value_bigint_words|Obtains information from the given JS **BigInt**, including the sign bit, 64-bit little-endian array, and number of elements in the array.|
......@@ -225,13 +225,22 @@
```js
let predicates = new relationalStore.RdbPredicates('EMPLOYEE');
predicates.equalTo('NAME', 'Rose');
store.query(predicates, ['ID', 'NAME', 'AGE', 'SALARY', 'CODES'], (err, resultSet) => {
store.query(predicates, ['ID', 'NAME', 'AGE', 'SALARY'], (err, resultSet) => {
if (err) {
console.error(`Failed to query data. Code:${err.code}, message:${err.message}`);
return;
}
console.info(`ResultSet column names: ${resultSet.columnNames}`);
console.info(`ResultSet column count: ${resultSet.columnCount}`);
console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
// resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
while (resultSet.goToNextRow()) {
const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
}
// 释放数据集的内存
resultSet.close();
})
```
......
......@@ -4,6 +4,7 @@
- [性能打点跟踪开发指导](hitracemeter-guidelines.md)
- [分布式跟踪开发指导](hitracechain-guidelines.md)
- [HiLog开发指导(Native)](hilog-guidelines.md)
- [HitraceMeter开发指导(Native)](hitracemeter-native-guidelines.md)
- 错误管理
- [错误管理开发指导](errormanager-guidelines.md)
- [应用恢复开发指导](apprecovery-guidelines.md)
......
# 性能打点跟踪开发指导(Native)
## 概述
hiTraceMeter为开发者提供系统性能打点接口。开发者通过在自己的业务逻辑中的关键代码位置调用HiTraceMeter接口提供的API接口,能够有效跟踪进程轨迹、查看系统性能。
> **说明:**
> - 仅当开发者使用Native API开发应用时,可参考本开发指导。
> - 如需使用ArkTS API开发应用,请参考对应的[开发指导](hitracemeter-guidelines.md)和[API参考](../reference/apis/js-apis-hitracemeter.md)。
## 接口说明
| 方法 | 接口描述 |
| -------- | -------- |
| void OH_HiTrace_StartTrace(const char* name) | 开启一个同步时间片跟踪事件 |
| void OH_HiTrace_FinishTrace() | 结束一个同步时间片跟踪事件 |
| void OH_HiTrace_StartAsyncTrace(const char* name, int32_t taskId) | 开启一个异步时间片跟踪事件 |
| void OH_HiTrace_FinishAsyncTrace(const char* name, int32_t taskId) | 结束一个异步时间片跟踪事件 |
| void OH_HiTrace_CountTrace(const char* name, int64_t count) | 整数跟踪事件 |
**参数解析**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| name | string | 否 | 要跟踪的数值变量名称。 |
| taskId | number | 否 | 用来表示关联的ID,如果有多个name相同的任务是并行执行的,则每次调用startTrace的taskId不同。 |
| count | number | 否 | 变量的值。 |
## 开发示例
1. 在CMakeLists.txt中新增libhitrace_ndk.z.so链接。
```
target_link_libraries(entry PUBLIC libhitrace_ndk.z.so)
```
2. 在源文件中引用hitrace头文件。
```c++
#include "hitrace/trace.h"
```
3. 打开hdc shell,使能trace,命令是:hitrace --trace_begin app。
```shell
capturing trace...
```
4. 进行性能打点,以异步打点为例。
```c++
OH_HiTrace_StartAsyncTrace("hitraceTest", 123);
OH_HiTrace_FinishAsyncTrace("hitraceTest", 123);
```
5. dump trace查看结果,命令是:hitrace --trace_dump | grep hitraceTest。
```shell
<...>-2477 (-------) [001] .... 396.427165: tracing_mark_write: S|2477|H:hitraceTest 123
<...>-2477 (-------) [001] .... 396.427196: tracing_mark_write: F|2477|H:hitraceTest 123
```
\ No newline at end of file
......@@ -2076,8 +2076,17 @@ store.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"], function (err,
console.error(`Query failed, code is ${err.code},message is ${err.message}`);
return;
}
console.info(`ResultSet column names: ${resultSet.columnNames}`);
console.info(`ResultSet column count: ${resultSet.columnCount}`);
console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
// resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
while(resultSet.goToNextRow()) {
const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
}
// 释放数据集的内存
resultSet.close();
})
```
......@@ -2117,8 +2126,17 @@ let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.equalTo("NAME", "Rose");
let promise = store.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
promise.then((resultSet) => {
console.info(`ResultSet column names: ${resultSet.columnNames}`);
console.info(`ResultSet column count: ${resultSet.columnCount}`);
console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
// resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
while(resultSet.goToNextRow()) {
const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
}
// 释放数据集的内存
resultSet.close();
}).catch((err) => {
console.error(`Query failed, code is ${err.code},message is ${err.message}`);
})
......@@ -2164,8 +2182,17 @@ store.query("EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"], fu
console.error(`Query failed, code is ${err.code},message is ${err.message}`);
return;
}
console.info(`ResultSet column names: ${resultSet.columnNames}`);
console.info(`ResultSet column count: ${resultSet.columnCount}`);
console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
// resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
while(resultSet.goToNextRow()) {
const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
}
// 释放数据集的内存
resultSet.close();
})
```
......@@ -2211,8 +2238,17 @@ let predicates = new dataSharePredicates.DataSharePredicates();
predicates.equalTo("NAME", "Rose");
let promise = store.query("EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
promise.then((resultSet) => {
console.info(`ResultSet column names: ${resultSet.columnNames}`);
console.info(`ResultSet column count: ${resultSet.columnCount}`);
console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
// resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
while(resultSet.goToNextRow()) {
const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
}
// 释放数据集的内存
resultSet.close();
}).catch((err) => {
console.error(`Query failed, code is ${err.code},message is ${err.message}`);
})
......@@ -2273,8 +2309,17 @@ store.remoteQuery(deviceId, "EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALAR
console.error(`Failed to remoteQuery, code is ${err.code},message is ${err.message}`);
return;
}
console.info(`ResultSet column names: ${resultSet.columnNames}`);
console.info(`ResultSet column count: ${resultSet.columnCount}`);
console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
// resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
while(resultSet.goToNextRow()) {
const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
}
// 释放数据集的内存
resultSet.close();
}
)
```
......@@ -2335,8 +2380,17 @@ let predicates = new relationalStore.RdbPredicates('EMPLOYEE');
predicates.greaterThan("id", 0);
let promise = store.remoteQuery(deviceId, "EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
promise.then((resultSet) => {
console.info(`ResultSet column names: ${resultSet.columnNames}`);
console.info(`ResultSet column count: ${resultSet.columnCount}`);
console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
// resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
while(resultSet.goToNextRow()) {
const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
}
// 释放数据集的内存
resultSet.close();
}).catch((err) => {
console.error(`Failed to remoteQuery, code is ${err.code},message is ${err.message}`);
})
......@@ -2374,8 +2428,17 @@ store.querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = ?", ['s
console.error(`Query failed, code is ${err.code},message is ${err.message}`);
return;
}
console.info(`ResultSet column names: ${resultSet.columnNames}`);
console.info(`ResultSet column count: ${resultSet.columnCount}`);
console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
// resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
while(resultSet.goToNextRow()) {
const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
}
// 释放数据集的内存
resultSet.close();
})
```
......@@ -2413,8 +2476,17 @@ querySql(sql: string, bindArgs?: Array&lt;ValueType&gt;):Promise&lt;ResultSet&gt
```js
let promise = store.querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = 'sanguo'");
promise.then((resultSet) => {
console.info(`ResultSet column names: ${resultSet.columnNames}`);
console.info(`ResultSet column count: ${resultSet.columnCount}`);
console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
// resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
while(resultSet.goToNextRow()) {
const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
}
// 释放数据集的内存
resultSet.close();
}).catch((err) => {
console.error(`Query failed, code is ${err.code},message is ${err.message}`);
})
......
......@@ -58,8 +58,8 @@ TextPicker(options?: {range: string[] | string[][] | Resource | TextPickerRangeC
| 名称 | 描述 |
| -------- | -------- |
| onAccept(callback: (value: string, index: number) => void) | 点击弹窗中的“确定”按钮时触发该回调。<br/><br/>-&nbsp;value:&nbsp;当前选中项的文本。<br/>-&nbsp;index:&nbsp;当前选中项的索引值。<br/>**说明:** <br/>该事件仅在[文本滑动选择器弹窗](ts-methods-textpicker-dialog.md)中生效。 |
| onCancel(callback: () => void) | 点击弹窗中的“取消”按钮时触发该回调<br/>**说明:** <br/>该事件仅在[文本滑动选择器弹窗](ts-methods-textpicker-dialog.md)中生效。 |
| onAccept(callback: (value: string, index: number) => void)<sup>(deprecated) </sup> | 点击弹窗中的“确定”按钮时触发该回调。<br/>-&nbsp;value:&nbsp;当前选中项的文本。<br/>-&nbsp;index:&nbsp;当前选中项的索引值。<br/> 从API version 10开始废弃。 <br/>**说明:** <br/>该事件仅在[文本滑动选择器弹窗](ts-methods-textpicker-dialog.md)中生效。|
| onCancel(callback: () => void)<sup>(deprecated) </sup> | 点击弹窗中的“取消”按钮时触发该回调。<br/> 从API version 10开始废弃<br/>**说明:** <br/>该事件仅在[文本滑动选择器弹窗](ts-methods-textpicker-dialog.md)中生效。 |
| onChange(callback:&nbsp;(value:&nbsp;string&nbsp;\|&nbsp;string[]<sup>10+</sup>,&nbsp;index:&nbsp;number&nbsp;\|&nbsp;number[]<sup>10+</sup>)&nbsp;=&gt;&nbsp;void) | 滑动选中TextPicker文本内容后,触发该回调。<br/>-&nbsp;value:&nbsp;当前选中项的文本。(多列的情况,value为数组类型。)<br/>-&nbsp;index:&nbsp;当前选中项的索引值。(多列的情况,index为数组类型。)<br/>**说明**:当显示文本或图片加文本列表时,value值为选中项中的文本值,当显示图片列表时,value值为空。 |
......
......@@ -4287,6 +4287,7 @@ onSslErrorEventReceive接口返回的SSL错误的具体原因。
| 名称 | 描述 | 备注 |
| --------- | ------------- | -------------------------- |
| MidiSysex | MIDI SYSEX资源。 | 目前仅支持权限事件上报,MIDI设备的使用还未支持。 |
| VIDEO_CAPTURE<sup>10+</sup> | 视频捕获资源,例如相机。 | |
## WebDarkMode<sup>9+</sup>枚举说明
| 名称 | 描述 |
......
# UsbConfigDescriptor
## 概述
标准配置描述符,对应USB协议中Standard Configuration Descriptor。
**起始版本:**
10
**相关模块:**
[UsbDdk](_usb_ddk.md)
## 汇总
### 成员变量
| 名称 | 描述 |
| -------- | -------- |
| [bLength](#blength) | 该描述符的大小,单位为字节。 |
| [bDescriptorType](#bdescriptortype) | 描述符类型。 |
| [wTotalLength](#wtotallength) | 该配置描述符的总长度,包含配置、接口、端点和特定于类或供应商的描述符。 |
| [bNumInterfaces](#bnuminterfaces) | 该配置所支持的接口数量。 |
| [bConfigurationValue](#bconfigurationvalue) | 设置配置所需要的参数,用来选择当前配置。 |
| [iConfiguration](#iconfiguration) | 描述该配置的字符串描述符的索引。 |
| [bmAttributes](#bmattributes) | 配置属性,包含供电模式、远程唤醒等配置。 |
| [bMaxPower](#bmaxpower) | 总线供电的USB设备的最大功耗,以2mA为单位。 |
## 结构体成员变量说明
### bConfigurationValue
```
uint8_t UsbConfigDescriptor::bConfigurationValue
```
**描述:**
设置配置所需要的参数,用来选择当前配置。
### bDescriptorType
```
uint8_t UsbConfigDescriptor::bDescriptorType
```
**描述:**
描述符类型。
### bLength
```
uint8_t UsbConfigDescriptor::bLength
```
**描述:**
该描述符的大小,单位为字节。
### bmAttributes
```
uint8_t UsbConfigDescriptor::bmAttributes
```
**描述:**
配置属性,包含供电模式、远程唤醒等配置。
### bMaxPower
```
uint8_t UsbConfigDescriptor::bMaxPower
```
**描述:**
总线供电的USB设备的最大功耗,以2mA为单位。
### bNumInterfaces
```
uint8_t UsbConfigDescriptor::bNumInterfaces
```
**描述:**
该配置所支持的接口数量。
### iConfiguration
```
uint8_t UsbConfigDescriptor::iConfiguration
```
**描述:**
描述该配置的字符串描述符的索引。
### wTotalLength
```
uint16_t UsbConfigDescriptor::wTotalLength
```
**描述:**
该配置描述符的总长度,包含配置、接口、端点和特定于类或供应商的描述符。
# UsbControlRequestSetup
## 概述
控制传输setup包,对应USB协议中的Setup Data。
**起始版本:**
10
**相关模块:**
[UsbDdk](_usb_ddk.md)
## 汇总
### 成员变量
| 名称 | 描述 |
| -------- | -------- |
| [bmRequestType](#bmrequesttype) | 请求类型。 |
| [bRequest](#brequest) | 具体的请求,其代表的含义不一样。 |
| [wValue](#wvalue) | 具体的请求不同。 |
| [wIndex](#windex) | 具体的请求不同,其代表的含义不一样,通常用来传递索引或者偏移量。 |
| [wLength](#wlength) | 如果有数据阶段的传输,其代表传输的字节个数。 |
## 结构体成员变量说明
### wIndex
```
uint16_t UsbControlRequestSetup::wIndex
```
**描述:**
具体的请求不同,其代表的含义不一样,通常用来传递索引或者偏移量。
### wLength
```
uint16_t UsbControlRequestSetup::wLength
```
**描述:**
如果有数据阶段的传输,其代表传输的字节个数。
### bRequest
```
uint8_t UsbControlRequestSetup::bRequest
```
**描述:**
具体的请求。
### bmRequestType
```
uint8_t UsbControlRequestSetup::bmRequestType
```
**描述:**
请求类型。
### wValue
```
uint16_t UsbControlRequestSetup::wValue
```
**描述:**
具体的请求不同,其代表的含义不一样。
# UsbDdk
## 概述
提供USB DDK接口,包括主机侧打开和关闭接口、管道同步异步读写通信、控制传输、中断传输等。
\@syscap SystemCapability.Driver.USB.Extension
**起始版本:**
10
## 汇总
### 文件
| 名称 | 描述 |
| -------- | -------- |
| [usb_ddk_api.h](usb__ddk__api_8h.md) | 声明用于主机侧访问设备的USB&nbsp;DDK接口。<br/>引用文件:&lt;usb/usb_ddk_api.h&gt; |
| [usb_ddk_types.h](usb__ddk__types_8h.md) | 提供USB&nbsp;DDK中的枚举变量、结构体定义与宏定义。<br/>引用文件:&lt;usb/usb_ddk_types.h&gt; |
### 结构体
| 名称 | 描述 |
| -------- | -------- |
| [UsbControlRequestSetup](_usb_control_request_setup.md) | 控制传输setup包,对应USB协议中的Setup&nbsp;Data。 |
| [UsbDeviceDescriptor](_usb_device_descriptor.md) | 标准设备描述符,对应USB协议中Standard&nbsp;Device&nbsp;Descriptor。 |
| [UsbConfigDescriptor](_usb_config_descriptor.md) | 标准配置描述符,对应USB协议中Standard&nbsp;Configuration&nbsp;Descriptor。 |
| [UsbInterfaceDescriptor](_usb_interface_descriptor.md) | 标准接口描述符,对应USB协议中Standard&nbsp;Interface&nbsp;Descriptor。 |
| [UsbEndpointDescriptor](_usb_endpoint_descriptor.md) | 标准端点描述符,对应USB协议中Standard&nbsp;Endpoint&nbsp;Descriptor。 |
| [UsbDdkEndpointDescriptor](_usb_ddk_endpoint_descriptor.md) | 端点描述符。 |
| [UsbDdkInterfaceDescriptor](_usb_ddk_interface_descriptor.md) | 接口描述符。 |
| [UsbDdkInterface](_usb_ddk_interface.md) | USB接口,是特定接口下备用设置的集合。 |
| [UsbDdkConfigDescriptor](_usb_ddk_config_descriptor.md) | 配置描述符。 |
| [UsbRequestPipe](_usb_request_pipe.md) | 请求管道。 |
| [UsbDeviceMemMap](_usb_device_mem_map.md) | 设备内存映射,通过[OH_Usb_CreateDeviceMemMap()](#oh_usb_createdevicememmap)创建设备内存映射,使用内存映射后的缓冲区,获得更好的性能。 |
### 类型定义
| 名称 | 描述 |
| -------- | -------- |
| [UsbDdkEndpointDescriptor](#usbddkendpointdescriptor) | 端点描述符。 |
| [UsbDdkInterfaceDescriptor](#usbddkinterfacedescriptor) | 接口描述符。 |
| [UsbDdkInterface](#usbddkinterface) | USB接口,是特定接口下备用设置的集合。 |
| [UsbDdkConfigDescriptor](#usbddkconfigdescriptor) | 配置描述符。 |
| [UsbDeviceMemMap](#usbdevicememmap) | 设备内存映射,通过[OH_Usb_CreateDeviceMemMap()](#oh_usb_createdevicememmap)创建设备内存映射,使用内存映射后的缓冲区,获得更好的性能。 |
### 枚举
| 名称 | 描述 |
| -------- | -------- |
| [UsbDdkErrCode](#usbddkerrcode)&nbsp;{<br/>USB_DDK_SUCCESS&nbsp;=&nbsp;0,&nbsp;USB_DDK_FAILED&nbsp;=&nbsp;-1,&nbsp;USB_DDK_INVALID_PARAMETER&nbsp;=&nbsp;-2,&nbsp;USB_DDK_MEMORY_ERROR&nbsp;=&nbsp;-3,<br/>USB_DDK_INVALID_OPERATION&nbsp;=&nbsp;-4,&nbsp;USB_DDK_NULL_PTR&nbsp;=&nbsp;-5,&nbsp;USB_DDK_DEVICE_BUSY&nbsp;=&nbsp;-6,&nbsp;USB_DDK_TIMEOUT&nbsp;=&nbsp;-7<br/>} | USB&nbsp;DDK&nbsp;错误码定义。 |
### 函数
| 名称 | 描述 |
| -------- | -------- |
| [OH_Usb_Init](#oh_usb_init)&nbsp;(void) | 初始化DDK。 |
| [OH_Usb_Release](#oh_usb_release)&nbsp;(void) | 释放DDK。 |
| [OH_Usb_GetDeviceDescriptor](#oh_usb_getdevicedescriptor)&nbsp;(uint64_t&nbsp;deviceId,&nbsp;struct&nbsp;[UsbDeviceDescriptor](_usb_device_descriptor.md)&nbsp;\*desc) | 获取设备描述符。 |
| [OH_Usb_GetConfigDescriptor](#oh_usb_getconfigdescriptor)&nbsp;(uint64_t&nbsp;deviceId,&nbsp;uint8_t&nbsp;configIndex,&nbsp;struct&nbsp;[UsbDdkConfigDescriptor](_usb_ddk_config_descriptor.md)&nbsp;\*\*const&nbsp;config) | 获取配置描述符。请在描述符使用完后使用[OH_Usb_FreeConfigDescriptor()](#oh_usb_freeconfigdescriptor)释放描述符,否则会造成内存泄露。 |
| [OH_Usb_FreeConfigDescriptor](#oh_usb_freeconfigdescriptor)&nbsp;(const&nbsp;struct&nbsp;[UsbDdkConfigDescriptor](_usb_ddk_config_descriptor.md)&nbsp;\*const&nbsp;config) | 释放配置描述符,请在描述符使用完后释放描述符,否则会造成内存泄露。 |
| [OH_Usb_ClaimInterface](#oh_usb_claiminterface)&nbsp;(uint64_t&nbsp;deviceId,&nbsp;uint8_t&nbsp;interfaceIndex,&nbsp;uint64_t&nbsp;\*[interfaceHandle](usb__ddk__types_8h.md#interfacehandle)) | 声明接口。 |
| [OH_Usb_ReleaseInterface](#oh_usb_releaseinterface)&nbsp;(uint64_t&nbsp;[interfaceHandle](usb__ddk__types_8h.md#interfacehandle)) | 释放接口。 |
| [OH_Usb_SelectInterfaceSetting](#oh_usb_selectinterfacesetting)&nbsp;(uint64_t&nbsp;[interfaceHandle](usb__ddk__types_8h.md#interfacehandle),&nbsp;uint8_t&nbsp;settingIndex) | 激活接口的备用设置。 |
| [OH_Usb_GetCurrentInterfaceSetting](#oh_usb_getcurrentinterfacesetting)&nbsp;(uint64_t&nbsp;[interfaceHandle](usb__ddk__types_8h.md#interfacehandle),&nbsp;uint8_t&nbsp;\*settingIndex) | 获取接口当前激活的备用设置。 |
| [OH_Usb_SendControlReadRequest](#oh_usb_sendcontrolreadrequest)&nbsp;(uint64_t&nbsp;[interfaceHandle](usb__ddk__types_8h.md#interfacehandle),&nbsp;const&nbsp;struct&nbsp;[UsbControlRequestSetup](_usb_control_request_setup.md)&nbsp;\*setup,&nbsp;uint32_t&nbsp;[timeout](usb__ddk__types_8h.md#timeout),&nbsp;uint8_t&nbsp;\*data,&nbsp;uint32_t&nbsp;\*dataLen) | 发送控制读请求,该接口为同步接口。 |
| [OH_Usb_SendControlWriteRequest](#oh_usb_sendcontrolwriterequest)&nbsp;(uint64_t&nbsp;[interfaceHandle](usb__ddk__types_8h.md#interfacehandle),&nbsp;const&nbsp;struct&nbsp;[UsbControlRequestSetup](_usb_control_request_setup.md)&nbsp;\*setup,&nbsp;uint32_t&nbsp;[timeout](usb__ddk__types_8h.md#timeout),&nbsp;const&nbsp;uint8_t&nbsp;\*data,&nbsp;uint32_t&nbsp;dataLen) | 发送控制写请求,该接口为同步接口。 |
| [OH_Usb_SendPipeRequest](#oh_usb_sendpiperequest)&nbsp;(const&nbsp;struct&nbsp;[UsbRequestPipe](_usb_request_pipe.md)&nbsp;\*pipe,&nbsp;[UsbDeviceMemMap](_usb_device_mem_map.md)&nbsp;\*devMmap) | 发送管道请求,该接口为同步接口。中断传输和批量传输都使用该接口发送请求。 |
| [OH_Usb_CreateDeviceMemMap](#oh_usb_createdevicememmap)&nbsp;(uint64_t&nbsp;deviceId,&nbsp;size_t&nbsp;size,&nbsp;[UsbDeviceMemMap](_usb_device_mem_map.md)&nbsp;\*\*devMmap) | 创建缓冲区。请在缓冲区使用完后,调用[OH_Usb_CreateDeviceMemMap()](#oh_usb_createdevicememmap)销毁缓冲区,否则会造成资源泄露。 |
| [OH_Usb_DestroyDeviceMemMap](#oh_usb_destroydevicememmap)&nbsp;([UsbDeviceMemMap](_usb_device_mem_map.md)&nbsp;\*devMmap) | 销毁缓冲区。请在缓冲区使用完后及时销毁缓冲区,否则会造成资源泄露。 |
## 类型定义说明
### UsbDdkConfigDescriptor
```
typedef struct UsbDdkConfigDescriptor UsbDdkConfigDescriptor
```
**描述:**
配置描述符。
### UsbDdkEndpointDescriptor
```
typedef struct UsbDdkEndpointDescriptor UsbDdkEndpointDescriptor
```
**描述:**
端点描述符。
### UsbDdkInterface
```
typedef struct UsbDdkInterface UsbDdkInterface
```
**描述:**
USB接口,是特定接口下备用设置的集合。
### UsbDdkInterfaceDescriptor
```
typedef struct UsbDdkInterfaceDescriptor UsbDdkInterfaceDescriptor
```
**描述:**
接口描述符。
### UsbDeviceMemMap
```
typedef struct UsbDeviceMemMap UsbDeviceMemMap
```
**描述:**
设备内存映射,通过[OH_Usb_CreateDeviceMemMap()](#oh_usb_createdevicememmap)创建设备内存映射,使用内存映射后的缓冲区,获得更好的性能。
## 枚举类型说明
### UsbDdkErrCode
```
enum UsbDdkErrCode
```
**描述:**
USB DDK 错误码定义。
| 枚举值 | 描述 |
| -------- | -------- |
| USB_DDK_SUCCESS | 操作成功。 |
| USB_DDK_FAILED | 操作失败。 |
| USB_DDK_INVALID_PARAMETER | 非法参数。 |
| USB_DDK_MEMORY_ERROR | 内存相关的错误,包括:内存不足、内存数据拷贝失败、内存申请失败等。 |
| USB_DDK_INVALID_OPERATION | 非法操作。 |
| USB_DDK_NULL_PTR | 空指针异常。 |
| USB_DDK_DEVICE_BUSY | 设备忙。 |
| USB_DDK_TIMEOUT | 传输超时。 |
## 函数说明
### OH_Usb_ClaimInterface()
```
int32_t OH_Usb_ClaimInterface (uint64_t deviceId, uint8_t interfaceIndex, uint64_t * interfaceHandle )
```
**描述:**
声明接口。
**参数:**
| 名称 | 描述 |
| -------- | -------- |
| deviceId | 设备ID,代表要操作的设备。 |
| interfaceIndex | 接口索引,对应USB协议中的[bInterfaceNumber](_usb_interface_descriptor.md#binterfacenumber)。 |
| interfaceHandle | 接口操作句柄,接口声明成功后,该参数将会被赋值。 |
**返回:**
成功返回0,否则返回负数。
### OH_Usb_CreateDeviceMemMap()
```
int32_t OH_Usb_CreateDeviceMemMap (uint64_t deviceId, size_t size, UsbDeviceMemMap ** devMmap )
```
**描述:**
创建缓冲区。请在缓冲区使用完后,调用[OH_Usb_DestroyDeviceMemMap()](#oh_usb_destroydevicememmap)销毁缓冲区,否则会造成资源泄露。
**参数:**
| 名称 | 描述 |
| -------- | -------- |
| deviceId | 设备ID,代表要创建缓冲区的设备。 |
| size | 缓冲区的大小。 |
| devMmap | 创建的缓冲区通过该参数返回给调用者。 |
**返回:**
成功返回0,否则返回负数。
### OH_Usb_DestroyDeviceMemMap()
```
void OH_Usb_DestroyDeviceMemMap (UsbDeviceMemMap * devMmap)
```
**描述:**
销毁缓冲区。请在缓冲区使用完后及时销毁缓冲区,否则会造成资源泄露。
**参数:**
| 名称 | 描述 |
| -------- | -------- |
| devMmap | 销毁由[OH_Usb_CreateDeviceMemMap()](#oh_usb_createdevicememmap)创建的缓冲区。 |
### OH_Usb_FreeConfigDescriptor()
```
void OH_Usb_FreeConfigDescriptor (const struct UsbDdkConfigDescriptor *const config)
```
**描述:**
释放配置描述符,请在描述符使用完后释放描述符,否则会造成内存泄露。
**参数:**
| 名称 | 描述 |
| -------- | -------- |
| config | 配置描述符,通过[OH_Usb_GetConfigDescriptor()](#oh_usb_getconfigdescriptor)获得的配置描述符。 |
### OH_Usb_GetConfigDescriptor()
```
int32_t OH_Usb_GetConfigDescriptor (uint64_t deviceId, uint8_t configIndex, struct UsbDdkConfigDescriptor **const config )
```
**描述:**
获取配置描述符。请在描述符使用完后使用[OH_Usb_FreeConfigDescriptor()](#oh_usb_freeconfigdescriptor)释放描述符,否则会造成内存泄露。
**参数:**
| 名称 | 描述 |
| -------- | -------- |
| deviceId | 设备ID,代表要获取配置描述符的设备。 |
| configIndex | 配置id,对应USB协议中的[bConfigurationValue](_usb_config_descriptor.md#bconfigurationvalue)。 |
| config | 配置描述符,包含USB协议中定义的标准配置描述符,以及与其关联的接口描述符和端点描述符。 |
**返回:**
成功返回0,否则返回负数。
### OH_Usb_GetCurrentInterfaceSetting()
```
int32_t OH_Usb_GetCurrentInterfaceSetting (uint64_t interfaceHandle, uint8_t * settingIndex )
```
**描述:**
获取接口当前激活的备用设置。
**参数:**
| 名称 | 描述 |
| -------- | -------- |
| interfaceHandle | 接口操作句柄,代表要操作的接口。 |
| settingIndex | 备用设置索引,对应USB协议中的[bAlternateSetting](_usb_interface_descriptor.md#balternatesetting)。 |
**返回:**
成功返回0,否则返回负数。
### OH_Usb_GetDeviceDescriptor()
```
int32_t OH_Usb_GetDeviceDescriptor (uint64_t deviceId, struct UsbDeviceDescriptor * desc )
```
**描述:**
获取设备描述符。
**参数:**
| 名称 | 描述 |
| -------- | -------- |
| deviceId | 设备ID,代表要获取描述符的设备。 |
| desc | 设备描述符,详细定义请参考[UsbDeviceDescriptor](_usb_device_descriptor.md)。 |
**返回:**
成功返回0,否则返回负数。
### OH_Usb_Init()
```
int32_t OH_Usb_Init (void )
```
**描述:**
初始化DDK。
**返回:**
成功返回0,否则返回负数。
### OH_Usb_Release()
```
void OH_Usb_Release (void )
```
**描述:**
释放DDK。
### OH_Usb_ReleaseInterface()
```
int32_t OH_Usb_ReleaseInterface (uint64_t interfaceHandle)
```
**描述:**
释放接口。
**参数:**
| 名称 | 描述 |
| -------- | -------- |
| interfaceHandle | 接口操作句柄,代表要释放的接口。 |
**返回:**
成功返回0,否则返回负数。
### OH_Usb_SelectInterfaceSetting()
```
int32_t OH_Usb_SelectInterfaceSetting (uint64_t interfaceHandle, uint8_t settingIndex )
```
**描述:**
激活接口的备用设置。
**参数:**
| 名称 | 描述 |
| -------- | -------- |
| interfaceHandle | 接口操作句柄,代表要操作的接口。 |
| settingIndex | 备用设置索引,对应USB协议中的[bAlternateSetting](_usb_interface_descriptor.md#balternatesetting)。 |
**返回:**
成功返回0,否则返回负数。
### OH_Usb_SendControlReadRequest()
```
int32_t OH_Usb_SendControlReadRequest (uint64_t interfaceHandle, const struct UsbControlRequestSetup * setup, uint32_t timeout, uint8_t * data, uint32_t * dataLen )
```
**描述:**
发送控制读请求,该接口为同步接口。
**参数:**
| 名称 | 描述 |
| -------- | -------- |
| interfaceHandle | 接口操作句柄,代表要操作的接口。 |
| setup | 请求相关的参数,详细定义请参考&nbsp;[UsbControlRequestSetup](_usb_control_request_setup.md)。 |
| timeout | 超时时间,单位为毫秒。 |
| data | 要传输的数据。 |
| dataLen | 表示data的数据长度,在函数返回后,表示实际读取到的数据的长度。 |
**返回:**
成功返回0,否则返回负数。
### OH_Usb_SendControlWriteRequest()
```
int32_t OH_Usb_SendControlWriteRequest (uint64_t interfaceHandle, const struct UsbControlRequestSetup * setup, uint32_t timeout, const uint8_t * data, uint32_t dataLen )
```
**描述:**
发送控制写请求,该接口为同步接口。
**参数:**
| 名称 | 描述 |
| -------- | -------- |
| interfaceHandle | 接口操作句柄,代表要操作的接口。 |
| setup | 请求相关的参数,详细定义请参考&nbsp;[UsbControlRequestSetup](_usb_control_request_setup.md)。 |
| timeout | 超时时间,单位为毫秒。 |
| data | 要传输的数据。 |
| dataLen | 表示data的数据长度。 |
**返回:**
成功返回0,否则返回负数。
### OH_Usb_SendPipeRequest()
```
int32_t OH_Usb_SendPipeRequest (const struct UsbRequestPipe * pipe, UsbDeviceMemMap * devMmap )
```
**描述:**
发送管道请求,该接口为同步接口。中断传输和批量传输都使用该接口发送请求。
**参数:**
| 名称 | 描述 |
| -------- | -------- |
| pipe | 要传输数据的管道信息。 |
| devMmap | 数据缓冲区,可以通过[OH_Usb_CreateDeviceMemMap()](#oh_usb_createdevicememmap)获得。 |
**返回:**
成功返回0,否则返回负数。
# UsbDdkConfigDescriptor
## 概述
配置描述符。
**起始版本:**
10
**相关模块:**
[UsbDdk](_usb_ddk.md)
## 汇总
### 成员变量
| 名称 | 描述 |
| -------- | -------- |
| [configDescriptor](#configdescriptor) | 标准配置描述符。 |
| [interface](#interface) | 该配置所包含的接口。 |
| [extra](#extra) | 未做解析的描述符,包含特定于类或供应商的描述符。 |
| [extraLength](#extralength) | 未做解析的描述符长度。 |
## 结构体成员变量说明
### configDescriptor
```
struct UsbConfigDescriptor UsbDdkConfigDescriptor::configDescriptor
```
**描述:**
标准配置描述符。
### extra
```
uint8_t* UsbDdkConfigDescriptor::extra
```
**描述:**
未做解析的描述符,包含特定于类或供应商的描述符。
### extraLength
```
uint32_t UsbDdkConfigDescriptor::extraLength
```
**描述:**
未做解析的描述符长度。
### interface
```
struct UsbDdkInterface* UsbDdkConfigDescriptor::interface
```
**描述:**
该配置所包含的接口。
# UsbDdkEndpointDescriptor
## 概述
端点描述符。
**起始版本:**
10
**相关模块:**
[UsbDdk](_usb_ddk.md)
## 汇总
### 成员变量
| 名称 | 描述 |
| -------- | -------- |
| [endpointDescriptor](#endpointdescriptor) | 标准端点描述符。 |
| [extra](#extra) | 未做解析的描述符,包含特定于类或供应商的描述符。 |
| [extraLength](#extralength) | 未做解析的描述符长度。 |
## 结构体成员变量说明
### endpointDescriptor
```
struct UsbEndpointDescriptor UsbDdkEndpointDescriptor::endpointDescriptor
```
**描述:**
标准端点描述符。
### extra
```
uint8_t* UsbDdkEndpointDescriptor::extra
```
**描述:**
未做解析的描述符,包含特定于类或供应商的描述符。
### extraLength
```
uint32_t UsbDdkEndpointDescriptor::extraLength
```
**描述:**
未做解析的描述符长度。
# UsbDdkInterface
## 概述
USB接口,是特定接口下备用设置的集合。
**起始版本:**
10
**相关模块:**
[UsbDdk](_usb_ddk.md)
## 汇总
### 成员变量
| 名称 | 描述 |
| -------- | -------- |
| [numAltsetting](#numaltsetting) | 接口的备用设置数量。 |
| [altsetting](#altsetting) | 接口的备用设置。 |
## 结构体成员变量说明
### altsetting
```
struct UsbDdkInterfaceDescriptor* UsbDdkInterface::altsetting
```
**描述:**
接口的备用设置。
### numAltsetting
```
uint8_t UsbDdkInterface::numAltsetting
```
**描述:**
接口的备用设置数量。
# UsbDdkInterfaceDescriptor
## 概述
接口描述符。
**起始版本:**
10
**相关模块:**
[UsbDdk](_usb_ddk.md)
## 汇总
### 成员变量
| 名称 | 描述 |
| -------- | -------- |
| [interfaceDescriptor](#interfacedescriptor) | 标准接口描述符。 |
| [endPoint](#endpoint) | 该接口所包含的端点描述符。 |
| [extra](#extra) | 未做解析的描述符,包含特定于类或供应商的描述符。 |
| [extraLength](#extralength) | 未做解析的描述符长度。 |
## 结构体成员变量说明
### endPoint
```
struct UsbDdkEndpointDescriptor* UsbDdkInterfaceDescriptor::endPoint
```
**描述:**
该接口所包含的端点描述符。
### extra
```
uint8_t* UsbDdkInterfaceDescriptor::extra
```
**描述:**
未做解析的描述符,包含特定于类或供应商的描述符。
### extraLength
```
uint32_t UsbDdkInterfaceDescriptor::extraLength
```
**描述:**
未做解析的描述符长度。
### interfaceDescriptor
```
struct UsbInterfaceDescriptor UsbDdkInterfaceDescriptor::interfaceDescriptor
```
**描述:**
标准接口描述符。
# UsbDeviceDescriptor
## 概述
标准设备描述符,对应USB协议中Standard Device Descriptor。
**起始版本:**
10
**相关模块:**
[UsbDdk](_usb_ddk.md)
## 汇总
### 成员变量
| 名称 | 描述 |
| -------- | -------- |
| [bLength](#blength) | 该描述符的大小,单位为字节。 |
| [bDescriptorType](#bdescriptortype) | 描述符类型。 |
| [bcdUSB](#bcdusb) | USB协议发布号。 |
| [bDeviceClass](#bdeviceclass) | 由USB标准化组织(USB-IF)分配的设备类代码。 |
| [bDeviceSubClass](#bdevicesubclass) | 由USB标准化组织(USB-IF)分配的子类代码,其值由[bDeviceClass](#bdeviceclass)的值限定。 |
| [bDeviceProtocol](#bdeviceprotocol) | 由USB标准化组织(USB-IF)分配的协议代码,其值由[bDeviceClass](#bdeviceclass)[bDeviceSubClass](#bdevicesubclass)的值限定。 |
| [bMaxPacketSize0](#bmaxpacketsize0) | 端点零的最大包大小,只有8,16,32,64是合法的。 |
| [idVendor](#idvendor) | 由USB标准化组织(USB-IF)分配的厂商编号。 |
| [idProduct](#idproduct) | 由厂商分配的产品编号。 |
| [bcdDevice](#bcddevice) | 设备发布编号。 |
| [iManufacturer](#imanufacturer) | 描述厂商的字符串描述符的索引。 |
| [iProduct](#iproduct) | 描述产品的字符串描述符的索引。 |
| [iSerialNumber](#iserialnumber) | 描述设备序列号的字符串描述符的索引。 |
| [bNumConfigurations](#bnumconfigurations) | 配置数量。 |
## 结构体成员变量说明
### bcdDevice
```
uint16_t UsbDeviceDescriptor::bcdDevice
```
**描述:**
设备发布编号。
### bcdUSB
```
uint16_t UsbDeviceDescriptor::bcdUSB
```
**描述:**
USB协议发布号。
### bDescriptorType
```
uint8_t UsbDeviceDescriptor::bDescriptorType
```
**描述:**
描述符类型。
### bDeviceClass
```
uint8_t UsbDeviceDescriptor::bDeviceClass
```
**描述:**
由USB标准化组织(USB-IF)分配的设备类代码。
### bDeviceProtocol
```
uint8_t UsbDeviceDescriptor::bDeviceProtocol
```
**描述:**
由USB标准化组织(USB-IF)分配的协议代码,其值由[bDeviceClass](#bdeviceclass)[bDeviceSubClass](#bdevicesubclass)的值限定。
### bDeviceSubClass
```
uint8_t UsbDeviceDescriptor::bDeviceSubClass
```
**描述:**
由USB标准化组织(USB-IF)分配的子类代码,其值由[bDeviceClass](#bdeviceclass)的值限定。
### bLength
```
uint8_t UsbDeviceDescriptor::bLength
```
**描述:**
该描述符的大小,单位为字节。
### bMaxPacketSize0
```
uint8_t UsbDeviceDescriptor::bMaxPacketSize0
```
**描述:**
端点零的最大包大小,只有8、16、32、64是合法的。
### bNumConfigurations
```
uint8_t UsbDeviceDescriptor::bNumConfigurations
```
**描述:**
配置数量。
### idProduct
```
uint16_t UsbDeviceDescriptor::idProduct
```
**描述:**
由厂商分配的产品编号。
### idVendor
```
uint16_t UsbDeviceDescriptor::idVendor
```
**描述:**
由USB标准化组织(USB-IF)分配的厂商编号。
### iManufacturer
```
uint8_t UsbDeviceDescriptor::iManufacturer
```
**描述:**
描述厂商的字符串描述符的索引。
### iProduct
```
uint8_t UsbDeviceDescriptor::iProduct
```
**描述:**
描述产品的字符串描述符的索引。
### iSerialNumber
```
uint8_t UsbDeviceDescriptor::iSerialNumber
```
**描述:**
描述设备序列号的字符串描述符的索引。
# UsbDeviceMemMap
## 概述
设备内存映射,通过[OH_Usb_CreateDeviceMemMap()](_usb_ddk.md#oh_usb_createdevicememmap)创建设备内存映射,使用内存映射后的缓冲区,获得更好的性能。
**起始版本:**
10
**相关模块:**
[UsbDdk](_usb_ddk.md)
## 汇总
### 成员变量
| 名称 | 描述 |
| -------- | -------- |
| [address](#address) | 映射后的缓冲区地址。 |
| [size](#size) | 缓冲区大小。 |
| [offset](#offset) | 所使用的的缓冲区的偏移量,默认为0,表示没有偏移,从address开始。 |
| [bufferLength](#bufferlength) | 所使用的缓冲区的长度,默认等于size,表示使用全部的缓冲区。 |
| [transferedLength](#transferedlength) | 实际传输的数据的长度。 |
## 结构体成员变量说明
### address
```
uint8_t* const UsbDeviceMemMap::address
```
**描述:**
映射后的缓冲区地址。
### bufferLength
```
uint32_t UsbDeviceMemMap::bufferLength
```
**描述:**
所使用的缓冲区的长度,默认等于size,表示使用全部的缓冲区。
### offset
```
uint32_t UsbDeviceMemMap::offset
```
**描述:**
所使用的的缓冲区的偏移量,默认为0,表示没有偏移,从address开始。
### size
```
const size_t UsbDeviceMemMap::size
```
**描述:**
缓冲区大小。
### transferedLength
```
uint32_t UsbDeviceMemMap::transferedLength
```
**描述:**
实际传输的数据的长度。
# UsbEndpointDescriptor
## 概述
标准端点描述符,对应USB协议中Standard Endpoint Descriptor。
**起始版本:**
10
**相关模块:**
[UsbDdk](_usb_ddk.md)
## 汇总
### 成员变量
| 名称 | 描述 |
| -------- | -------- |
| [bLength](#blength) | 该描述符的大小,单位为字节。 |
| [bDescriptorType](#bdescriptortype) | 描述符类型。 |
| [bEndpointAddress](#bendpointaddress) | 端点地址,包含端点编号以及端点方向。 |
| [bmAttributes](#bmattributes) | 端点属性,包括传输类型、同步类型、使用类型。 |
| [wMaxPacketSize](#wmaxpacketsize) | 该端点所能承载的最大包的大小。 |
| [bInterval](#binterval) | 数据传输轮询端点的时间间隔。 |
| [bRefresh](#brefresh) | 用于音频类设备,同步反馈的速率。 |
| [bSynchAddress](#bsynchaddress) | 用于音频类设备,同步端点的地址。 |
## 结构体成员变量说明
### bDescriptorType
```
uint8_t UsbEndpointDescriptor::bDescriptorType
```
**描述:**
描述符类型。
### bEndpointAddress
```
uint8_t UsbEndpointDescriptor::bEndpointAddress
```
**描述:**
端点地址,包含端点编号以及端点方向。
### bInterval
```
uint8_t UsbEndpointDescriptor::bInterval
```
**描述:**
数据传输轮询端点的时间间隔。
### bLength
```
uint8_t UsbEndpointDescriptor::bLength
```
**描述:**
该描述符的大小,单位为字节。
### bmAttributes
```
uint8_t UsbEndpointDescriptor::bmAttributes
```
**描述:**
端点属性,包括传输类型、同步类型、使用类型。
### bRefresh
```
uint8_t UsbEndpointDescriptor::bRefresh
```
**描述:**
用于音频类设备,同步反馈的速率。
### bSynchAddress
```
uint8_t UsbEndpointDescriptor::bSynchAddress
```
**描述:**
用于音频类设备,同步端点的地址。
### wMaxPacketSize
```
uint16_t UsbEndpointDescriptor::wMaxPacketSize
```
**描述:**
该端点所能承载的最大包的大小。
# UsbInterfaceDescriptor
## 概述
标准接口描述符,对应USB协议中Standard Interface Descriptor。
**起始版本:**
10
**相关模块:**
[UsbDdk](_usb_ddk.md)
## 汇总
### 成员变量
| 名称 | 描述 |
| -------- | -------- |
| [bLength](#blength) | 该描述符的大小,单位为字节。 |
| [bDescriptorType](#bdescriptortype) | 描述符类型。 |
| [bInterfaceNumber](#binterfacenumber) | 接口编号。 |
| [bAlternateSetting](#balternatesetting) | 用来选择该接口的备用配置的值。 |
| [bNumEndpoints](#bnumendpoints) | 该接口所使用的端点数量(不包括端点零)。 |
| [bInterfaceClass](#binterfaceclass) | 由USB标准化组织(USB-IF)分配的设备类代码。 |
| [bInterfaceSubClass](#binterfacesubclass) | 由USB标准化组织(USB-IF)分配的子类代码,其值由[bInterfaceClass](#binterfaceclass)的值限定。 |
| [bInterfaceProtocol](#binterfaceprotocol) | 由USB标准化组织(USB-IF)分配的协议代码,其值由[bInterfaceClass](#binterfaceclass)[bInterfaceSubClass](#binterfacesubclass)的值限定。 |
| [iInterface](#iinterface) | 描述该接口的字符串描述符的索引。 |
## 结构体成员变量说明
### bAlternateSetting
```
uint8_t UsbInterfaceDescriptor::bAlternateSetting
```
**描述:**
用来选择该接口的备用配置的值。
### bDescriptorType
```
uint8_t UsbInterfaceDescriptor::bDescriptorType
```
**描述:**
描述符类型。
### bInterfaceClass
```
uint8_t UsbInterfaceDescriptor::bInterfaceClass
```
**描述:**
由USB标准化组织(USB-IF)分配的设备类代码。
### bInterfaceNumber
```
uint8_t UsbInterfaceDescriptor::bInterfaceNumber
```
**描述:**
接口编号。
### bInterfaceProtocol
```
uint8_t UsbInterfaceDescriptor::bInterfaceProtocol
```
**描述:**
由USB标准化组织(USB-IF)分配的协议代码,其值由[bInterfaceClass](#binterfaceclass)[bInterfaceSubClass](#binterfacesubclass)的值限定。
### bInterfaceSubClass
```
uint8_t UsbInterfaceDescriptor::bInterfaceSubClass
```
**描述:**
由USB标准化组织(USB-IF)分配的子类代码,其值由[bInterfaceClass](#binterfaceclass)的值限定。
### bLength
```
uint8_t UsbInterfaceDescriptor::bLength
```
**描述:**
该描述符的大小,单位为字节。
### bNumEndpoints
```
uint8_t UsbInterfaceDescriptor::bNumEndpoints
```
**描述:**
该接口所使用的端点数量(不包括端点零)。
### iInterface
```
uint8_t UsbInterfaceDescriptor::iInterface
```
**描述:**
描述该接口的字符串描述符的索引。
# UsbRequestPipe
## 概述
请求管道。
**起始版本:**
10
**相关模块:**
[UsbDdk](_usb_ddk.md)
## 汇总
### 成员变量
| 名称 | 描述 |
| -------- | -------- |
| [interfaceHandle](#interfacehandle) | 接口操作句柄。 |
| [endpoint](#endpoint) | 要通信的端点的地址。 |
| [timeout](#timeout) | 超时时间,单位是毫秒。 |
## 结构体成员变量说明
### endpoint
```
uint8_t UsbRequestPipe::endpoint
```
**描述:**
要通信的端点的地址。
### interfaceHandle
```
uint64_t UsbRequestPipe::interfaceHandle
```
**描述:**
接口操作句柄。
### timeout
```
uint32_t UsbRequestPipe::timeout
```
**描述:**
超时时间,单位是毫秒。
# usb_ddk_api.h
## 概述
声明用于主机侧访问设备的USB DDK接口。
**起始版本:**
10
**相关模块:**
[UsbDdk](_usb_ddk.md)
## 汇总
### 函数
| 名称 | 描述 |
| -------- | -------- |
| [OH_Usb_Init](_usb_ddk.md#oh_usb_init)&nbsp;(void) | 初始化DDK。 |
| [OH_Usb_Release](_usb_ddk.md#oh_usb_release)&nbsp;(void) | 释放DDK |
| [OH_Usb_GetDeviceDescriptor](_usb_ddk.md#oh_usb_getdevicedescriptor)&nbsp;(uint64_t&nbsp;deviceId,&nbsp;struct&nbsp;[UsbDeviceDescriptor](_usb_device_descriptor.md)&nbsp;\*desc) | 获取设备描述符。 |
| [OH_Usb_GetConfigDescriptor](_usb_ddk.md#oh_usb_getconfigdescriptor)&nbsp;(uint64_t&nbsp;deviceId,&nbsp;uint8_t&nbsp;configIndex,&nbsp;struct&nbsp;[UsbDdkConfigDescriptor](_usb_ddk_config_descriptor.md)&nbsp;\*\*const&nbsp;config) | 获取配置描述符。请在描述符使用完后使用[OH_Usb_FreeConfigDescriptor()](_usb_ddk.md#oh_usb_freeconfigdescriptor)释放描述符,否则会造成内存泄露。 |
| [OH_Usb_FreeConfigDescriptor](_usb_ddk.md#oh_usb_freeconfigdescriptor)&nbsp;(const&nbsp;struct&nbsp;[UsbDdkConfigDescriptor](_usb_ddk_config_descriptor.md)&nbsp;\*const&nbsp;config) | 释放配置描述符,请在描述符使用完后释放描述符,否则会造成内存泄露。 |
| [OH_Usb_ClaimInterface](_usb_ddk.md#oh_usb_claiminterface)&nbsp;(uint64_t&nbsp;deviceId,&nbsp;uint8_t&nbsp;interfaceIndex,&nbsp;uint64_t&nbsp;\*[interfaceHandle](usb__ddk__types_8h.md#interfacehandle)) | 声明接口。 |
| [OH_Usb_ReleaseInterface](_usb_ddk.md#oh_usb_releaseinterface)&nbsp;(uint64_t&nbsp;[interfaceHandle](usb__ddk__types_8h.md#interfacehandle)) | 释放接口。 |
| [OH_Usb_SelectInterfaceSetting](_usb_ddk.md#oh_usb_selectinterfacesetting)&nbsp;(uint64_t&nbsp;[interfaceHandle](usb__ddk__types_8h.md#interfacehandle),&nbsp;uint8_t&nbsp;settingIndex) | 激活接口的备用设置。 |
| [OH_Usb_GetCurrentInterfaceSetting](_usb_ddk.md#oh_usb_getcurrentinterfacesetting)&nbsp;(uint64_t&nbsp;[interfaceHandle](usb__ddk__types_8h.md#interfacehandle),&nbsp;uint8_t&nbsp;\*settingIndex) | 获取接口当前激活的备用设置。 |
| [OH_Usb_SendControlReadRequest](_usb_ddk.md#oh_usb_sendcontrolreadrequest)&nbsp;(uint64_t&nbsp;[interfaceHandle](usb__ddk__types_8h.md#interfacehandle),&nbsp;const&nbsp;struct&nbsp;[UsbControlRequestSetup](_usb_control_request_setup.md)&nbsp;\*setup,&nbsp;uint32_t&nbsp;[timeout](usb__ddk__types_8h.md#timeout),&nbsp;uint8_t&nbsp;\*data,&nbsp;uint32_t&nbsp;\*dataLen) | 发送控制读请求,该接口为同步接口。 |
| [OH_Usb_SendControlWriteRequest](_usb_ddk.md#oh_usb_sendcontrolwriterequest)&nbsp;(uint64_t&nbsp;[interfaceHandle](usb__ddk__types_8h.md#interfacehandle),&nbsp;const&nbsp;struct&nbsp;[UsbControlRequestSetup](_usb_control_request_setup.md)&nbsp;\*setup,&nbsp;uint32_t&nbsp;[timeout](usb__ddk__types_8h.md#timeout),&nbsp;const&nbsp;uint8_t&nbsp;\*data,&nbsp;uint32_t&nbsp;dataLen) | 发送控制写请求,该接口为同步接口。 |
| [OH_Usb_SendPipeRequest](_usb_ddk.md#oh_usb_sendpiperequest)&nbsp;(const&nbsp;struct&nbsp;[UsbRequestPipe](_usb_request_pipe.md)&nbsp;\*pipe,&nbsp;[UsbDeviceMemMap](_usb_device_mem_map.md)&nbsp;\*devMmap) | 发送管道请求,该接口为同步接口。中断传输和批量传输都使用该接口发送请求。 |
| [OH_Usb_CreateDeviceMemMap](_usb_ddk.md#oh_usb_createdevicememmap)&nbsp;(uint64_t&nbsp;deviceId,&nbsp;size_t&nbsp;size,&nbsp;[UsbDeviceMemMap](_usb_device_mem_map.md)&nbsp;\*\*devMmap) | 创建缓冲区。请在缓冲区使用完后,调用[OH_Usb_DestroyDeviceMemMap()](_usb_ddk.md#oh_usb_destroydevicememmap)销毁缓冲区,否则会造成资源泄露。 |
| [OH_Usb_DestroyDeviceMemMap](_usb_ddk.md#oh_usb_destroydevicememmap)&nbsp;([UsbDeviceMemMap](_usb_device_mem_map.md)&nbsp;\*devMmap) | 销毁缓冲区。请在缓冲区使用完后及时销毁缓冲区,否则会造成资源泄露。 |
# usb_ddk_types.h
## 概述
提供USB DDK中的枚举变量、结构体定义与宏定义。
**起始版本:**
10
**相关模块:**
[UsbDdk](_usb_ddk.md)
## 汇总
### 结构体
| 名称 | 描述 |
| -------- | -------- |
| [UsbControlRequestSetup](_usb_control_request_setup.md) | 控制传输setup包,对应USB协议中的Setup&nbsp;Data。 |
| [UsbDeviceDescriptor](_usb_device_descriptor.md) | 标准设备描述符,对应USB协议中Standard&nbsp;Device&nbsp;Descriptor。 |
| [UsbConfigDescriptor](_usb_config_descriptor.md) | 标准配置描述符,对应USB协议中Standard&nbsp;Configuration&nbsp;Descriptor。 |
| [UsbInterfaceDescriptor](_usb_interface_descriptor.md) | 标准接口描述符,对应USB协议中Standard&nbsp;Interface&nbsp;Descriptor。 |
| [UsbEndpointDescriptor](_usb_endpoint_descriptor.md) | 标准端点描述符,对应USB协议中Standard&nbsp;Endpoint&nbsp;Descriptor。 |
| [UsbDdkEndpointDescriptor](_usb_ddk_endpoint_descriptor.md) | 端点描述符。 |
| [UsbDdkInterfaceDescriptor](_usb_ddk_interface_descriptor.md) | 接口描述符。 |
| [UsbDdkInterface](_usb_ddk_interface.md) | USB接口,是特定接口下备用设置的集合。 |
| [UsbDdkConfigDescriptor](_usb_ddk_config_descriptor.md) | 配置描述符。 |
| [UsbRequestPipe](_usb_request_pipe.md) | 请求管道。 |
| [UsbDeviceMemMap](_usb_device_mem_map.md) | 设备内存映射,通过[OH_Usb_CreateDeviceMemMap()](_usb_ddk.md#oh_usb_createdevicememmap)创建设备内存映射,使用内存映射后的缓冲区,获得更好的性能。 |
### 类型定义
| 名称 | 描述 |
| -------- | -------- |
| [UsbDdkEndpointDescriptor](_usb_ddk.md#usbddkendpointdescriptor) | 端点描述符。 |
| [UsbDdkInterfaceDescriptor](_usb_ddk.md#usbddkinterfacedescriptor) | 接口描述符。 |
| [UsbDdkInterface](_usb_ddk.md#usbddkinterface) | USB接口。 |
| [UsbDdkConfigDescriptor](_usb_ddk.md#usbddkconfigdescriptor) | 配置描述符。 |
| [UsbDeviceMemMap](_usb_ddk.md#usbdevicememmap) | 设备内存映射,通过[OH_Usb_CreateDeviceMemMap()](_usb_ddk.md#oh_usb_createdevicememmap)创建设备内存映射,使用内存映射后的缓冲区,获得更好的性能。 |
### 枚举
| 名称 | 描述 |
| -------- | -------- |
| [UsbDdkErrCode](_usb_ddk.md#usbddkerrcode)&nbsp;{<br/>USB_DDK_SUCCESS&nbsp;=&nbsp;0,&nbsp;USB_DDK_FAILED&nbsp;=&nbsp;-1,&nbsp;USB_DDK_INVALID_PARAMETER&nbsp;=&nbsp;-2,&nbsp;USB_DDK_MEMORY_ERROR&nbsp;=&nbsp;-3,<br/>USB_DDK_INVALID_OPERATION&nbsp;=&nbsp;-4,&nbsp;USB_DDK_NULL_PTR&nbsp;=&nbsp;-5,&nbsp;USB_DDK_DEVICE_BUSY&nbsp;=&nbsp;-6,&nbsp;USB_DDK_TIMEOUT&nbsp;=&nbsp;-7<br/>} | USB&nbsp;DDK&nbsp;错误码定义。 |
### 变量
| 名称 | 描述 |
| -------- | -------- |
| [bmRequestType](#bmrequesttype) | 请求类型。 |
| [bRequest](#brequest) | 具体的请求。 |
| [wValue](#wvalue) | 具体的请求不同,其代表的含义不一样。 |
| [wIndex](#windex) | 具体的请求不同,其代表的含义不一样,通常用来传递索引或者偏移量。 |
| [wLength](#wlength) | 如果有数据阶段的传输,其代表传输的字节个数。 |
| [bLength](#blength) | 该描述符的大小,单位为字节。 |
| [bDescriptorType](#bdescriptortype) | 描述符类型。 |
| [bcdUSB](#bcdusb) | USB协议发布号。 |
| [bDeviceClass](#bdeviceclass) | 由USB标准化组织(USB-IF)分配的设备类代码。 |
| [bDeviceSubClass](#bdevicesubclass) | 由USB标准化组织(USB-IF)分配的子类代码,其值由[bDeviceClass](#bdeviceclass)的值限定。 |
| [bDeviceProtocol](#bdeviceprotocol) | 由USB标准化组织(USB-IF)分配的协议代码,其值由[bDeviceClass](#bdeviceclass)[bDeviceSubClass](#bdevicesubclass)的值限定。 |
| [bMaxPacketSize0](#bmaxpacketsize0) | 端点零的最大包大小,只有8、16、32、64是合法的。 |
| [idVendor](#idvendor) | 由USB标准化组织(USB-IF)分配的厂商编号。 |
| [idProduct](#idproduct) | 由厂商分配的产品编号。 |
| [bcdDevice](#bcddevice) | 设备发布编号。 |
| [iManufacturer](#imanufacturer) | 描述厂商的字符串描述符的索引。 |
| [iProduct](#iproduct) | 描述产品的字符串描述符的索引。 |
| [iSerialNumber](#iserialnumber) | 描述设备序列号的字符串描述符的索引。 |
| [bNumConfigurations](#bnumconfigurations) | 配置数量。 |
| [wTotalLength](#wtotallength) | 该配置描述符的总长度,包含配置、接口、端点和特定于类或供应商的描述符。 |
| [bNumInterfaces](#bnuminterfaces) | 该配置所支持的接口数量。 |
| [bConfigurationValue](#bconfigurationvalue) | 设置配置所需要的参数,用来选择当前配置。 |
| [iConfiguration](#iconfiguration) | 描述该配置的字符串描述符的索引。 |
| [bmAttributes](#bmattributes) | 配置属性,包含供电模式、远程唤醒等配置。 |
| [bMaxPower](#bmaxpower) | 总线供电的USB设备的最大功耗,以2mA为单位。 |
| [bInterfaceNumber](#binterfacenumber) | 接口编号。 |
| [bAlternateSetting](#balternatesetting) | 用来选择该接口的备用配置的值。 |
| [bNumEndpoints](#bnumendpoints) | 该接口所使用的端点数量(不包括端点零)。 |
| [bInterfaceClass](#binterfaceclass) | 由USB标准化组织(USB-IF)分配的设备类代码。 |
| [bInterfaceSubClass](#binterfacesubclass) | 由USB标准化组织(USB-IF)分配的子类代码,其值由[bInterfaceClass](#binterfaceclass)的值限定。 |
| [bInterfaceProtocol](#binterfaceprotocol) | 由USB标准化组织(USB-IF)分配的协议代码,其值由[bInterfaceClass](#binterfaceclass)[bInterfaceSubClass](#binterfacesubclass)的值限定。 |
| [iInterface](#iinterface) | 描述该接口的字符串描述符的索引。 |
| [bEndpointAddress](#bendpointaddress) | 端点地址,包含端点编号以及端点方向。 |
| [bmAttributes](#bmattributes) | 端点属性,包括传输类型、同步类型、使用类型。 |
| [wMaxPacketSize](#wmaxpacketsize) | 该端点所能承载的最大包的大小。 |
| [bInterval](#binterval) | 数据传输轮询端点的时间间隔。 |
| [bRefresh](#brefresh) | 用于音频类设备,同步反馈的速率。 |
| [bSynchAddress](#bsynchaddress) | 用于音频类设备,同步端点的地址。 |
| [interfaceHandle](#interfacehandle) | 接口操作句柄。 |
| [endpoint](#endpoint) | 要通信的端点的地址。 |
| [timeout](#timeout) | 超时时间,单位是毫秒。 |
## 变量说明
### bAlternateSetting
```
uint8_t bAlternateSetting
```
**描述:**
用来选择该接口的备用配置的值。
### bcdDevice
```
uint16_t bcdDevice
```
**描述:**
设备发布编号。
### bcdUSB
```
uint16_t bcdUSB
```
**描述:**
USB协议发布号。
### bConfigurationValue
```
uint8_t bConfigurationValue
```
**描述:**
设置配置所需要的参数,用来选择当前配置。
### bDescriptorType
```
uint8_t bDescriptorType
```
**描述:**
描述符类型。
### bDeviceClass
```
uint8_t bDeviceClass
```
**描述:**
由USB标准化组织(USB-IF)分配的设备类代码。
### bDeviceProtocol
```
uint8_t bDeviceProtocol
```
**描述:**
由USB标准化组织(USB-IF)分配的协议代码,其值由[bDeviceClass](#bdeviceclass)[bDeviceSubClass](#bdevicesubclass)的值限定。
### bDeviceSubClass
```
uint8_t bDeviceSubClass
```
**描述:**
由USB标准化组织(USB-IF)分配的子类代码,其值由[bDeviceClass](#bdeviceclass)的值限定。
### bEndpointAddress
```
uint8_t bEndpointAddress
```
**描述:**
端点地址,包含端点编号以及端点方向。
### bmAttributes
```
uint8_t bmAttributes
```
**描述:**
端点属性,包括传输类型、同步类型、使用类型。
### bInterfaceClass
```
uint8_t bInterfaceClass
```
**描述:**
由USB标准化组织(USB-IF)分配的设备类代码。
### bInterfaceNumber
```
uint8_t bInterfaceNumber
```
**描述:**
接口编号。
### bInterfaceProtocol
```
uint8_t bInterfaceProtocol
```
**描述:**
由USB标准化组织(USB-IF)分配的协议代码,其值由[bInterfaceClass](#binterfaceclass)[bInterfaceSubClass](#binterfacesubclass)的值限定。
### bInterfaceSubClass
```
uint8_t bInterfaceSubClass
```
**描述:**
由USB标准化组织(USB-IF)分配的子类代码,其值由[bInterfaceClass](#binterfaceclass)的值限定。
### bInterval
```
uint8_t bInterval
```
**描述:**
数据传输轮询端点的时间间隔。
### bLength
```
uint8_t bLength
```
**描述:**
该描述符的大小,单位为字节。
### bmAttributes
```
uint8_t bmAttributes
```
**描述:**
配置属性,包含供电模式、远程唤醒等配置。
### bMaxPacketSize0
```
uint8_t bMaxPacketSize0
```
**描述:**
端点零的最大包大小,只有8、16、32、64是合法的。
### bMaxPower
```
uint8_t bMaxPower
```
**描述:**
总线供电的USB设备的最大功耗,以2mA为单位。
### bNumConfigurations
```
uint8_t bNumConfigurations
```
**描述:**
配置数量。
### bNumEndpoints
```
uint8_t bNumEndpoints
```
**描述:**
该接口所使用的端点数量(不包括端点零)。
### bNumInterfaces
```
uint8_t bNumInterfaces
```
**描述:**
该配置所支持的接口数量。
### bRefresh
```
uint8_t bRefresh
```
**描述:**
用于音频类设备,同步反馈的速率。
### bSynchAddress
```
uint8_t bSynchAddress
```
**描述:**
用于音频类设备,同步端点的地址。
### endpoint
```
uint8_t endpoint
```
**描述:**
要通信的端点的地址。
### iConfiguration
```
uint8_t iConfiguration
```
**描述:**
描述该配置的字符串描述符的索引。
### idProduct
```
uint16_t idProduct
```
**描述:**
由厂商分配的产品编号。
### idVendor
```
uint16_t idVendor
```
**描述:**
由USB标准化组织(USB-IF)分配的厂商编号。
### iInterface
```
uint8_t iInterface
```
**描述:**
描述该接口的字符串描述符的索引。
### iManufacturer
```
uint8_t iManufacturer
```
**描述:**
描述厂商的字符串描述符的索引。
### wIndex
```
uint16_t wIndex
```
**描述:**
具体的请求不同,其代表的含义不一样,通常用来传递索引或者偏移量。
### interfaceHandle
```
uint64_t interfaceHandle
```
**描述:**
接口操作句柄。
### iProduct
```
uint8_t iProduct
```
**描述:**
描述产品的字符串描述符的索引。
### iSerialNumber
```
uint8_t iSerialNumber
```
**描述:**
描述设备序列号的字符串描述符的索引。
### wLength
```
uint16_t wLength
```
**描述:**
如果有数据阶段的传输,其代表传输的字节个数。
### bRequest
```
uint8_t bRequest
```
**描述:**
具体的请求。
### bmRequestType
```
uint8_t bmRequestType
```
**描述:**
请求类型。
### timeout
```
uint32_t timeout
```
**描述:**
超时时间,单位是毫秒。
### wValue
```
uint16_t wValue
```
**描述:**
具体的请求不同,其代表的含义不一样。
### wMaxPacketSize
```
uint16_t wMaxPacketSize
```
**描述:**
该端点所能承载的最大包的大小。
### wTotalLength
```
uint16_t wTotalLength
```
**描述:**
该配置描述符的总长度,包含配置、接口、端点和特定于类或供应商的描述符。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册