提交 79ea467d 编写于 作者: S shawn_he

update doc

Signed-off-by: Nshawn_he <shawn.he@huawei.com>
上级 eb80f8e5
......@@ -3,7 +3,7 @@
## Basic Concepts
The inter-process communication (IPC) and remote procedure call (RPC) mechanisms are used to implement cross-process communication. The difference between them lies in that IPC uses the Binder driver to implement cross-process communication within a device, whereas RPC uses the DSoftBus driver to implement cross-process communication across devices. The reason why cross-process communication is needed is that each process has its own independent resources and memory space and one process is not allowed to access the resources and memory space of other processes.
Inter-process communication (IPC) and remote procedure call (RPC) are used to implement cross-process communication. IPC uses the Binder driver to implement cross-process communication within a device, whereas RPC uses the DSoftBus driver to implement cross-process communication across devices. Cross-process communication is required because each process has its own independent resources and memory space and one process is not allowed to access the resources and memory space of other processes.
> **NOTE**
> The applications in the stage model cannot use IPC or RPC directly, and must use the following capabilities to implement related service scenarios:
......
# @ohos.hilog (HiLog)
The **hilog** module allows your applications or services to output logs based on the specified type, level, and format string. Such logs help you learn the running status of applications and better debug programs.
The HiLog subsystem allows your applications or services to output logs based on the specified type, level, and format string. Such logs help you learn the running status of applications and better debug programs.
> **NOTE**<br>
> **NOTE**
>
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
......@@ -23,7 +24,7 @@ Checks whether logs are printable based on the specified service domain, log tag
| Name| Type | Mandatory| Description |
| ------ | --------------------- | ---- | ------------------------------------------------------------ |
| domain | number | Yes | Service domain of logs. The value ranges from **0x0** to **0xFFFF**. You can define the value within your application as required.|
| domain | number | Yes | Service domain of logs. The value ranges from **0x0** to **0xFFFF**.<br>You can define the value as required.|
| tag | string | Yes | Log tag in the string format. You are advised to use this parameter to identify a particular service behavior or the class holding the ongoing method.|
| level | [LogLevel](#loglevel) | Yes | Log level. |
......@@ -41,11 +42,11 @@ hilog.isLoggable(0x0001, "testTag", hilog.LogLevel.INFO);
## LogLevel
Enumerates the log levels.
Log level.
**System capability**: SystemCapability.HiviewDFX.HiLog
| Name | Value| Description |
| Name | Value | Description |
| ----- | ------ | ------------------------------------------------------------ |
| DEBUG | 3 | Log level used to record more detailed process information than INFO logs to help developers analyze service processes and locate faults.|
| INFO | 4 | Log level used to record key service process nodes and exceptions that occur during service running,<br>for example, no network signal or login failure.<br>These logs should be recorded by the dominant module in the service to avoid repeated logging conducted by multiple invoked modules or low-level functions.|
......@@ -67,9 +68,9 @@ DEBUG logs are not recorded in official versions by default. They are available
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| domain | number | Yes | Service domain of logs. The value ranges from **0x0** to **0xFFFF**. You can define the value within your application as required.|
| domain | number | Yes | Service domain of logs. The value ranges from **0x0** to **0xFFFF**.<br>You can define the value as required.|
| tag | string | Yes | Log tag in the string format. You are advised to use this parameter to identify a particular service behavior or the class holding the ongoing method.|
| format | string | Yes | Format string used to output logs in a specified format. It can contain several parameters, where the parameter type and privacy identifier are mandatory.<br>Parameters labeled **{public}** are public data and are displayed in plaintext; parameters labeled **{private}** (default value) are private data and are filtered by **\<private>**.|
| format | string | Yes | Format string used to output logs in a specified format. It can contain several elements, where the parameter type and privacy identifier are mandatory.<br>Parameters labeled **{public}** are public data and are displayed in plaintext; parameters labeled **{private}** (default value) are private data and are filtered by **\<private>**.|
| args | any[] | Yes | Variable-length parameter list corresponding to the format string. The number and type of parameters must map to the identifier in the format string.|
**Example**
......@@ -98,9 +99,9 @@ Prints INFO logs.
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| domain | number | Yes | Service domain of logs. The value ranges from **0x0** to **0xFFFF**. You can define the value within your application as required.|
| domain | number | Yes | Service domain of logs. The value ranges from **0x0** to **0xFFFF**.<br>You can define the value as required. |
| tag | string | Yes | Log tag in the string format. You are advised to use this parameter to identify a particular service behavior or the class holding the ongoing method.|
| format | string | Yes | Format string used to output logs in a specified format. It can contain several parameters, where the parameter type and privacy identifier are mandatory.<br>Parameters labeled **{public}** are public data and are displayed in plaintext; parameters labeled **{private}** (default value) are private data and are filtered by **\<private>**.|
| format | string | Yes | Format string used to output logs in a specified format. It can contain several elements, where the parameter type and privacy identifier are mandatory.<br>Parameters labeled **{public}** are public data and are displayed in plaintext; parameters labeled **{private}** (default value) are private data and are filtered by **\<private>**.|
| args | any[] | Yes | Variable-length parameter list corresponding to the format string. The number and type of parameters must map to the identifier in the format string.|
**Example**
......@@ -129,9 +130,9 @@ Prints WARN logs.
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| domain | number | Yes | Service domain of logs. The value ranges from **0x0** to **0xFFFF**. You can define the value within your application as required.|
| domain | number | Yes | Service domain of logs. The value ranges from **0x0** to **0xFFFF**.<br>You can define the value as required. |
| tag | string | Yes | Log tag in the string format. You are advised to use this parameter to identify a particular service behavior or the class holding the ongoing method.|
| format | string | Yes | Format string used to output logs in a specified format. It can contain several parameters, where the parameter type and privacy identifier are mandatory.<br>Parameters labeled **{public}** are public data and are displayed in plaintext; parameters labeled **{private}** (default value) are private data and are filtered by **\<private>**.|
| format | string | Yes | Format string used to output logs in a specified format. It can contain several elements, where the parameter type and privacy identifier are mandatory.<br>Parameters labeled **{public}** are public data and are displayed in plaintext; parameters labeled **{private}** (default value) are private data and are filtered by **\<private>**.|
| args | any[] | Yes | Variable-length parameter list corresponding to the format string. The number and type of parameters must map to the identifier in the format string.|
**Example**
......@@ -160,9 +161,9 @@ Prints ERROR logs.
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| domain | number | Yes | Service domain of logs. The value ranges from **0x0** to **0xFFFF**. You can define the value within your application as required.|
| domain | number | Yes | Service domain of logs. The value ranges from **0x0** to **0xFFFF**.<br>You can define the value as required. |
| tag | string | Yes | Log tag in the string format. You are advised to use this parameter to identify a particular service behavior or the class holding the ongoing method.|
| format | string | Yes | Format string used to output logs in a specified format. It can contain several parameters, where the parameter type and privacy identifier are mandatory.<br>Parameters labeled **{public}** are public data and are displayed in plaintext; parameters labeled **{private}** (default value) are private data and are filtered by **\<private>**.|
| format | string | Yes | Format string used to output logs in a specified format. It can contain several elements, where the parameter type and privacy identifier are mandatory.<br>Parameters labeled **{public}** are public data and are displayed in plaintext; parameters labeled **{private}** (default value) are private data and are filtered by **\<private>**.|
| args | any[] | Yes | Variable-length parameter list corresponding to the format string. The number and type of parameters must map to the identifier in the format string.|
**Example**
......@@ -191,9 +192,9 @@ Prints FATAL logs.
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| domain | number | Yes | Service domain of logs. The value ranges from **0x0** to **0xFFFF**. You can define the value within your application as required.|
| domain | number | Yes | Service domain of logs. The value ranges from **0x0** to **0xFFFF**.<br>You can define the value as required. |
| tag | string | Yes | Log tag in the string format. You are advised to use this parameter to identify a particular service behavior or the class holding the ongoing method.|
| format | string | Yes | Format string used to output logs in a specified format. It can contain several parameters, where the parameter type and privacy identifier are mandatory.<br>Parameters labeled **{public}** are public data and are displayed in plaintext; parameters labeled **{private}** (default value) are private data and are filtered by **\<private>**.|
| format | string | Yes | Format string used to output logs in a specified format. It can contain several elements, where the parameter type and privacy identifier are mandatory.<br>Parameters labeled **{public}** are public data and are displayed in plaintext; parameters labeled **{private}** (default value) are private data and are filtered by **\<private>**.|
| args | any[] | Yes | Variable-length parameter list corresponding to the format string. The number and type of parameters must map to the identifier in the format string.|
**Example**
......@@ -209,3 +210,43 @@ If `"hello"` is filled in `%{public}s` and `3` in `%{private}d`, the output log
```
08-05 12:21:47.579 2695-2703/com.example.myapplication F 00001/testTag: hello World <private>
```
## Parameter Format
Parameters in the log are printed in the following format:
%[private flag]specifier
| Privacy Flag| Description|
| ------------ | ---- |
| Unspecified | The default value is **private**, indicating that parameters in plaintext are not printed.|
| private | Prints private parameters.|
| public | Prints parameters in plaintext.|
| Specifier| Description| Example|
| ------------ | ---- | ---- |
| d/i | Prints logs of the **number** and **bigint** types.| 123 |
| s | Prints logs of the **string undefined bool** and **null** types.| "123" |
**Example**
```js
let obj2 = new Object({name:"Jack", age:22});
let isBol = true;
let bigNum = BigInt(1234567890123456789);
hilog.info(0x0001, "jsHilogTest", "print object: %{public}s", JSON.stringify(obj2));
hilog.info(0x0001, "jsHilogTest", "private flag: %{private}s %s, print null: %{public}s", "hello", "world", null);
hilog.info(0x0001, "jsHilogTest", "print undefined: %{public}s", undefined);
hilog.info(0x0001, "jsHilogTest", "print number: %{public}d %{public}i", 123, 456);
hilog.info(0x0001, "jsHilogTest", "print bigNum: %{public}d %{public}i", bigNum, bigNum);
hilog.info(0x0001, "jsHilogTest", "print boolean: %{public}s", isBol);
```
Log printing result:
```
08-09 13:26:29.094 2266 2266 I A00001/jsHilogTest: print object: {"name":"Jack","age":22}
08-09 13:26:29.094 2266 2266 I A00001/jsHilogTest: private flag: <private> <private>, print null: null
08-09 13:26:29.094 2266 2266 I A00001/jsHilogTest: print undefined: undefined
08-09 13:26:29.094 2266 2266 I A00001/jsHilogTest: print number: 123 456
08-09 13:26:29.095 2266 2266 I A00001/jsHilogTest: print bigNum: 1234567890123456768 1234567890123456768
08-09 13:26:29.095 2266 2266 I A00001/jsHilogTest: print boolean: true
```
# @ohos.multimodalInput.inputDevice (Input Device)
The **inputDevice** module implements listening for connection, disconnection, and update events of input devices and displays information about input devices. For example, it can be used to listen for mouse insertion and removal and obtain information such as the ID, name, and pointer speed of the mouse.
The **inputDevice** module allows you to listen for hot swap events of input devices and query information about input devices.
> **NOTE**<br>
> **NOTE**
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
......@@ -10,6 +11,7 @@ The **inputDevice** module implements listening for connection, disconnection, a
```js
import inputDevice from '@ohos.multimodalInput.inputDevice';
```
## inputDevice.getDeviceList<sup>9+</sup>
getDeviceList(callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void
......@@ -21,24 +23,22 @@ Obtains the IDs of all input devices. This API uses an asynchronous callback to
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------------------------- | ---- | ---------- |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| callback | AsyncCallback&lt;Array&lt;number&gt;&gt; | Yes | Callback used to return the result.|
**Example**
```js
try {
inputDevice.getDeviceIds((error, ids) => {
inputDevice.getDeviceList((error, ids) => {
if (error) {
console.log(`Failed to get device list.
error code=${JSON.stringify(err.code)} msg=${JSON.stringify(err.message)}`);
console.log(`Failed to get device id list, error: ${JSON.stringify(error, [`code`, `message`])}`);
return;
}
this.data = ids;
console.log("The device ID list is: " + ids);
console.log(`Device id list: ${JSON.stringify(ids)}`);
});
} catch (error) {
console.info("getDeviceList " + error.code + " " + error.message);
console.log(`Failed to get device id list, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
......@@ -52,19 +52,19 @@ Obtains the IDs of all input devices. This API uses a promise to return the resu
**Return value**
| Name | Description |
| ---------------------------------- | ------------------------------- |
| Parameters | Description |
| ---------------------------------- | ------------------------------------------- |
| Promise&lt;Array&lt;number&gt;&gt; | Promise used to return the result.|
**Example**
```js
try {
inputDevice.getDeviceIds().then((ids) => {
console.log("The device ID list is: " + ids);
inputDevice.getDeviceList().then((ids) => {
console.log(`Device id list: ${JSON.stringify(ids)}`);
});
} catch (error) {
console.info("getDeviceList " + error.code + " " + error.message);
console.log(`Failed to get device id list, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
......@@ -88,16 +88,15 @@ Obtains information about an input device. This API uses an asynchronous callbac
```js
// Obtain the name of the device whose ID is 1.
try {
inputDevice.getDeviceInfo(1, (error, inputDevice) => {
inputDevice.getDeviceInfo(1, (error, deviceData) => {
if (error) {
console.log(`Failed to get device information.
error code=${JSON.stringify(err.code)} msg=${JSON.stringify(err.message)}`);
console.log(`Failed to get device info, error: ${JSON.stringify(error, [`code`, `message`])}`);
return;
}
console.log("The device name is: " + inputDevice.name);
console.log(`Device info: ${JSON.stringify(deviceData)}`);
});
} catch (error) {
console.info("getDeviceInfo " + error.code + " " + error.message);
console.log(`Failed to get device info, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
......@@ -117,7 +116,7 @@ Obtains information about an input device. This API uses a promise to return the
**Return value**
| Name | Description |
| Parameters | Description |
| -------------------------------------------------- | ------------------------------- |
| Promise&lt;[InputDeviceData](#inputdevicedata)&gt; | Promise used to return the result.|
......@@ -126,20 +125,19 @@ Obtains information about an input device. This API uses a promise to return the
```js
// Obtain the name of the device whose ID is 1.
try {
inputDevice.getDeviceInfo(id).then((inputDevice) => {
console.log("The device name is: " + inputDevice.name);
inputDevice.getDeviceInfo(1).then((deviceData) => {
console.log(`Device info: ${JSON.stringify(deviceData)}`);
});
} catch (error) {
console.info("getDeviceInfo " + error.code + " " + error.message);
console.log(`Failed to get device info, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
## inputDevice.on<sup>9+</sup>
on(type: "change", listener: Callback&lt;DeviceListener&gt;): void
Enables listening for hot swap events of an input device.
Enables listening for device hot swap events.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice
......@@ -156,13 +154,13 @@ Enables listening for hot swap events of an input device.
let isPhysicalKeyboardExist = true;
try {
inputDevice.on("change", (data) => {
console.log("type: " + data.type + ", deviceId: " + data.deviceId);
inputDevice.getKeyboardType(data.deviceId, (err, ret) => {
console.log("The keyboard type of the device is: " + ret);
if (ret == inputDevice.KeyboardType.ALPHABETIC_KEYBOARD && data.type == 'add') {
console.log(`Device event info: ${JSON.stringify(data)}`);
inputDevice.getKeyboardType(data.deviceId, (err, type) => {
console.log("The keyboard type is: " + type);
if (type == inputDevice.KeyboardType.ALPHABETIC_KEYBOARD && data.type == 'add') {
// The physical keyboard is connected.
isPhysicalKeyboardExist = true;
} else if (ret == inputDevice.KeyboardType.ALPHABETIC_KEYBOARD && data.type == 'remove') {
} else if (type == inputDevice.KeyboardType.ALPHABETIC_KEYBOARD && data.type == 'remove') {
// The physical keyboard is disconnected.
isPhysicalKeyboardExist = false;
}
......@@ -170,7 +168,7 @@ try {
});
// Check whether the soft keyboard is open based on the value of isPhysicalKeyboardExist.
} catch (error) {
console.info("oninputdevcie " + error.code + " " + error.message);
console.log(`Get device info failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
......@@ -178,7 +176,7 @@ try {
off(type: "change", listener?: Callback&lt;DeviceListener&gt;): void
Disables listening for hot swap events of an input device.
Disables listening for device hot swap events. This API is called before the application exits.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice
......@@ -192,33 +190,29 @@ Disables listening for hot swap events of an input device.
**Example**
```js
callback: function(data) {
console.log("type: " + data.type + ", deviceId: " + data.deviceId);
}
function callback(data) {
console.log(`Report device event info: ${JSON.stringify(data, [`type`, `deviceId`])}`);
};
try {
inputDevice.on("change", this.callback);
inputDevice.on("change", callback);
} catch (error) {
console.info("oninputdevcie " + error.code + " " + error.message)
console.log(`Listen device event failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
// Enable listening for hot swap events of an input device.
inputDevice.on("change", listener);
// Disable this listener.
try {
inputDevice.off("change", this.callback);
inputDevice.off("change", callback);
} catch (error) {
console.info("offinputdevcie " + error.code + " " + error.message)
console.log(`Cancel listening device event failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
// Disable all listeners.
try {
inputDevice.off("change");
} catch (error) {
console.info("offinputdevcie " + error.code + " " + error.message);
console.log(`Cancel all listening device event failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
// By default, the soft keyboard is closed when listening is disabled.
```
## inputDevice.getDeviceIds<sup>(deprecated)</sup>
......@@ -233,8 +227,8 @@ This API is deprecated since API version 9. You are advised to use [inputDevice.
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ----- |
| Name | Type | Mandatory| Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| callback | AsyncCallback&lt;Array&lt;number&gt;&gt; | Yes | Callback used to return the result.|
**Example**
......@@ -248,7 +242,6 @@ inputDevice.getDeviceIds((error, ids) => {
console.log(`Device id list: ${JSON.stringify(ids)}`);
});
```
```
## inputDevice.getDeviceIds<sup>(deprecated)</sup>
......@@ -262,8 +255,8 @@ This API is deprecated since API version 9. You are advised to use [inputDevice.
**Return value**
| Parameter | Description |
| ---------------------------------- | ------------------- |
| Parameters | Description |
| ---------------------------------- | ------------------------------------------- |
| Promise&lt;Array&lt;number&gt;&gt; | Promise used to return the result.|
**Example**
......@@ -286,8 +279,8 @@ This API is deprecated since API version 9. You are advised to use [inputDevice.
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | --------------------------- |
| Name | Type | Mandatory| Description |
| -------- | -------------------------------------------------------- | ---- | -------------------------------- |
| deviceId | number | Yes | ID of the input device. |
| callback | AsyncCallback&lt;[InputDeviceData](#inputdevicedata)&gt; | Yes | Callback used to return the result, which is an **InputDeviceData** object.|
......@@ -316,14 +309,14 @@ This API is deprecated since API version 9. You are advised to use [inputDevice.
**Parameters**
| Name | Type | Mandatory | Description |
| Name | Type | Mandatory| Description |
| -------- | ------ | ---- | ------------ |
| deviceId | number | Yes | ID of the input device.|
**Return value**
| Parameter | Description |
| ---------------------------------------- | ------------------- |
| Parameters | Description |
| -------------------------------------------------- | ----------------------------------- |
| Promise&lt;[InputDeviceData](#inputdevicedata)&gt; | Promise used to return the result.|
**Example**
......@@ -345,8 +338,8 @@ Obtains the key codes supported by the input device. This API uses an asynchrono
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------------------------------------ | ---- | --------------------------------- |
| Name | Type | Mandatory| Description |
| -------- | ----------------------------------------- | ---- | ------------------------------------------------------ |
| deviceId | number | Yes | Unique ID of the input device. If the same physical device is repeatedly inserted and removed, its ID changes.|
| keys | Array&lt;KeyCode&gt; | Yes | Key codes to be queried. A maximum of five key codes can be specified. |
| callback | AsyncCallback&lt;Array&lt;boolean&gt;&gt; | Yes | Callback used to return the result. |
......@@ -356,11 +349,11 @@ Obtains the key codes supported by the input device. This API uses an asynchrono
```js
// Check whether the input device whose ID is 1 supports key codes 17, 22, and 2055.
try {
inputDevice.supportKeys(1, [17, 22, 2055], (error, ret) => {
console.log("The query result is as follows: " + ret);
inputDevice.supportKeys(1, [17, 22, 2055], (error, supportResult) => {
console.log(`Query result: ${JSON.stringify(supportResult)}`);
});
} catch (error) {
console.info("supportKeys " + error.code + " " + error.message);
console.log(`Query failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
......@@ -374,15 +367,15 @@ Obtains the key codes supported by the input device. This API uses a promise to
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | -------------------- | ---- | --------------------------------- |
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ------------------------------------------------------ |
| deviceId | number | Yes | Unique ID of the input device. If the same physical device is repeatedly inserted and removed, its ID changes.|
| keys | Array&lt;KeyCode&gt; | Yes | Key codes to be queried. A maximum of five key codes can be specified. |
**Return value**
| Parameter | Description |
| ----------------------------------- | ------------------- |
| Parameters | Description |
| ----------------------------------- | ------------------------------- |
| Promise&lt;Array&lt;boolean&gt;&gt; | Promise used to return the result.|
**Example**
......@@ -390,11 +383,11 @@ Obtains the key codes supported by the input device. This API uses a promise to
```js
// Check whether the input device whose ID is 1 supports key codes 17, 22, and 2055.
try {
inputDevice.supportKeys(1, [17, 22, 2055]).then((ret) => {
console.log("The query result is as follows: " + ret);
inputDevice.supportKeys(1, [17, 22, 2055]).then((supportResult) => {
console.log(`Query result: ${JSON.stringify(supportResult)}`);
});
} catch (error) {
console.info("supportKeys " + error.code + " " + error.message);
console.log(`Query failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
......@@ -408,8 +401,8 @@ Obtains the keyboard type of an input device. This API uses an asynchronous call
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | --------------------------------- |
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------------------- | ---- | ------------------------------------------------------------ |
| deviceId | number | Yes | Unique ID of the input device. If the same physical device is repeatedly inserted and removed, its ID changes.|
| callback | AsyncCallback&lt;[KeyboardType](#keyboardtype9)&gt; | Yes | Callback used to return the result. |
......@@ -418,31 +411,36 @@ Obtains the keyboard type of an input device. This API uses an asynchronous call
```js
// Query the keyboard type of the input device whose ID is 1.
try {
inputDevice.getKeyboardType(1, (error, number) => {
inputDevice.getKeyboardType(1, (error, type) => {
if (error) {
console.log(`Failed to get keyboardtype.
error code=${JSON.stringify(err.code)} msg=${JSON.stringify(err.message)}`);
console.log(`Failed to get keyboard type, error: ${JSON.stringify(error, [`code`, `message`])}`);
return;
}
console.log("The keyboard type of the device is: " + number);
console.log(`Keyboard type: ${JSON.stringify(type)}`);
});
} catch (error) {
console.info("getKeyboardType " + error.code + " " + error.message);
console.log(`Failed to get keyboard type, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
## inputDevice.getKeyboardType<sup>9+</sup>
getKeyboardType(deviceId: number,): Promise&lt;KeyboardType&gt;
getKeyboardType(deviceId: number): Promise&lt;KeyboardType&gt;
Obtains the keyboard type of an input device. This API uses a promise to return the result.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------ | ---- | ------------------------------------------------------------ |
| deviceId | number | Yes | Unique ID of the input device. If the same physical device is repeatedly inserted and removed, its ID changes.|
**Return value**
| Parameter | Description |
| ---------------------------------------- | ------------------- |
| Parameters | Description |
| --------------------------------------------- | ------------------------------- |
| Promise&lt;[KeyboardType](#keyboardtype9)&gt; | Promise used to return the result.|
**Example**
......@@ -450,11 +448,11 @@ Obtains the keyboard type of an input device. This API uses a promise to return
```js
// Query the keyboard type of the input device whose ID is 1.
try {
inputDevice.getKeyboardType(1).then((number) => {
console.log("The keyboard type of the device is: " + number);
inputDevice.getKeyboardType(1).then((type) => {
console.log(`Keyboard type: ${JSON.stringify(type)}`);
});
} catch (error) {
console.info("getKeyboardType " + error.code + " " + error.message);
console.log(`Failed to get keyboard type, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
......@@ -524,7 +522,7 @@ Defines the axis range of an input device.
## SourceType<sup>9+</sup>
Enumerates the input source types. For example, if a mouse reports an x-axis event, the source of the x-axis is the mouse.
Input source type of the axis. For example, if a mouse reports an x-axis event, the input source of the x-axis is the mouse.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice
......
......@@ -1750,7 +1750,7 @@ promise.then(() => {
setExtraOptions(options: TCPExtraOptions, callback: AsyncCallback\<void\>): void
Sets other properties of the TCPSocket connection after successful binding of the local IP address and port number of the TLSSocket connection. This API uses an asynchronous callback to return the result.
Sets other properties of the TCPSocket connection after successful binding of the local IP address and port number of the connection. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetStack
......@@ -1802,7 +1802,7 @@ tls.setExtraOptions({
setExtraOptions(options: TCPExtraOptions): Promise\<void\>
Sets other properties of the TCPSocket connection after successful binding of the local IP address and port number of the TLSSocket connection. This API uses a promise to return the result.
Sets other properties of the TCPSocket connection after successful binding of the local IP address and port number of the connection. This API uses a promise to return the result.
**System capability**: SystemCapability.Communication.NetStack
......
......@@ -152,7 +152,7 @@ Checks whether the user, for example, the application or system, has the device
**Example**
```js
let devicesName="1-1";
let devicesName = "1-1";
let bool = usb.hasRight(devicesName);
console.log(`${bool}`);
```
......@@ -180,7 +180,7 @@ Requests the temporary permission for the application to access a USB device. Th
**Example**
```js
let devicesName="1-1";
let devicesName = "1-1";
usb.requestRight(devicesName).then((ret) => {
console.log(`requestRight = ${ret}`);
});
......@@ -209,7 +209,7 @@ Removes the permission for the application to access a USB device.
**Example**
```js
let devicesName="1-1";
let devicesName = "1-1";
if (usb.removeRight(devicesName)) {
console.log(`Succeed in removing right`);
}
......@@ -277,6 +277,16 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi
**Example**
```js
let devicesList = usb.getDevices();
if (devicesList.length == 0) {
console.log(`device list is empty`);
return;
}
let device = devicesList[0];
usb.requestRight(device.name);
let devicepipe = usb.connectDevice(device);
let interfaces = device.configs[0].interfaces[0];
let ret = usb.claimInterface(devicepipe, interfaces);
console.log(`claimInterface = ${ret}`);
```
......@@ -307,7 +317,18 @@ Before you do this, ensure that you have claimed the interface by calling [usb.c
**Example**
```js
let ret = usb.releaseInterface(devicepipe, interfaces);
let devicesList = usb.getDevices();
if (devicesList.length == 0) {
console.log(`device list is empty`);
return;
}
let device = devicesList[0];
usb.requestRight(device.name);
let devicepipe = usb.connectDevice(device);
let interfaces = device.configs[0].interfaces[0];
let ret = usb.claimInterface(devicepipe, interfaces);
ret = usb.releaseInterface(devicepipe, interfaces);
console.log(`releaseInterface = ${ret}`);
```
......@@ -337,6 +358,16 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi
**Example**
```js
let devicesList = usb.getDevices();
if (devicesList.length == 0) {
console.log(`device list is empty`);
return;
}
let device = devicesList[0];
usb.requestRight(device.name);
let devicepipe = usb.connectDevice(device);
let config = device.configs[0];
let ret = usb.setConfiguration(devicepipe, config);
console.log(`setConfiguration = ${ret}`);
```
......@@ -367,7 +398,18 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi
**Example**
```js
let ret = usb.setInterface(devicepipe, interfaces);
let devicesList = usb.getDevices();
if (devicesList.length == 0) {
console.log(`device list is empty`);
return;
}
let device = devicesList[0];
usb.requestRight(device.name);
let devicepipe = usb.connectDevice(device);
let interfaces = device.configs[0].interfaces[0];
let ret = usb.claimInterface(devicepipe, interfaces);
ret = usb.setInterface(devicepipe, interfaces);
console.log(`setInterface = ${ret}`);
```
......@@ -396,6 +438,14 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi
**Example**
```js
let devicesList = usb.getDevices();
if (devicesList.length == 0) {
console.log(`device list is empty`);
return;
}
usb.requestRight(devicesList[0].name);
let devicepipe = usb.connectDevice(devicesList[0]);
let ret = usb.getRawDescriptor(devicepipe);
```
......@@ -424,6 +474,14 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi
**Example**
```js
let devicesList = usb.getDevices();
if (devicesList.length == 0) {
console.log(`device list is empty`);
return;
}
usb.requestRight(devicesList[0].name);
let devicepipe = usb.connectDevice(devicesList[0]);
let ret = usb.getFileDescriptor(devicepipe);
```
......@@ -462,6 +520,15 @@ let param = {
index: 0,
data: null
};
let devicesList = usb.getDevices();
if (devicesList.length == 0) {
console.log(`device list is empty`);
return;
}
usb.requestRight(devicesList[0].name);
let devicepipe = usb.connectDevice(devicesList[0]);
usb.controlTransfer(devicepipe, param).then((ret) => {
console.log(`controlTransfer = ${ret}`);
})
......@@ -498,6 +565,20 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi
// Call usb.getDevices to obtain a data set. Then, obtain a USB device and its access permission.
// Pass the obtained USB device as a parameter to usb.connectDevice. Then, call usb.connectDevice to connect the USB device.
// Call usb.claimInterface to claim the USB interface. After that, call usb.bulkTransfer to start bulk transfer.
let devicesList = usb.getDevices();
if (devicesList.length == 0) {
console.log(`device list is empty`);
return;
}
let device = devicesList[0];
usb.requestRight(device.name);
let devicepipe = usb.connectDevice(device);
let interfaces = device.configs[0].interfaces[0];
let endpoint = device.configs[0].interfaces[0].endpoints[0];
let ret = usb.claimInterface(devicepipe, interfaces);
let buffer = new Uint8Array(128);
usb.bulkTransfer(devicepipe, endpoint, buffer).then((ret) => {
console.log(`bulkTransfer = ${ret}`);
});
......@@ -528,6 +609,14 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi
**Example**
```js
let devicesList = usb.getDevices();
if (devicesList.length == 0) {
console.log(`device list is empty`);
return;
}
usb.requestRight(devicesList[0].name);
let devicepipe = usb.connectDevice(devicesList[0]);
let ret = usb.closePipe(devicepipe);
console.log(`closePipe = ${ret}`);
```
......
......@@ -182,11 +182,11 @@ This error code is reported if an error occurs while writing received data to th
**Cause**
The application does not have the data write permission.
The application does not have the permission to write files or the file to be downloaded exceeds 5 MB.
**Solution**
Check the permissions granted to the application.
Check the application permission and the size of the file to be downloaded.
## 2300025 Failed to Upload Data
......
......@@ -5,10 +5,11 @@
Provides **Context** APIs for configuring runtime information.
**Since:**
**Since**
9
**Related Modules:**
**Related Modules**
[MindSpore](_mind_spore.md)
......@@ -18,35 +19,35 @@ Provides **Context** APIs for configuring runtime information.
### Types
| Name | Description |
| Name| Description|
| -------- | -------- |
| [OH_AI_ContextHandle](_mind_spore.md#oh_ai_contexthandle) | Defines the pointer to the MindSpore context. |
| [OH_AI_DeviceInfoHandle](_mind_spore.md#oh_ai_deviceinfohandle) | Defines the pointer to the MindSpore device information. |
| [OH_AI_DeviceInfoHandle](_mind_spore.md#oh_ai_deviceinfohandle) | Defines the pointer to the MindSpore device information.|
### Functions
| Name | Description |
| Name| Description|
| -------- | -------- |
| [OH_AI_ContextCreate](_mind_spore.md#oh_ai_contextcreate) () | Creates a context object. |
| [OH_AI_ContextDestroy](_mind_spore.md#oh_ai_contextdestroy) ([OH_AI_ContextHandle](_mind_spore.md#oh_ai_contexthandle) \*context) | Destroys a context object. |
| [OH_AI_ContextSetThreadNum](_mind_spore.md#oh_ai_contextsetthreadnum) ([OH_AI_ContextHandle](_mind_spore.md#oh_ai_contexthandle) context, int32_t thread_num) | Sets the number of runtime threads. |
| [OH_AI_ContextGetThreadNum](_mind_spore.md#oh_ai_contextgetthreadnum) (const [OH_AI_ContextHandle](_mind_spore.md#oh_ai_contexthandle) context) | Obtains the number of threads. |
| [OH_AI_ContextSetThreadAffinityMode](_mind_spore.md#oh_ai_contextsetthreadaffinitymode) ([OH_AI_ContextHandle](_mind_spore.md#oh_ai_contexthandle) context, int mode) | Sets the affinity mode for binding runtime threads to CPU cores, which are categorized into little cores and big cores depending on the CPU frequency. |
| [OH_AI_ContextGetThreadAffinityMode](_mind_spore.md#oh_ai_contextgetthreadaffinitymode) (const [OH_AI_ContextHandle](_mind_spore.md#oh_ai_contexthandle) context) | Obtains the affinity mode for binding runtime threads to CPU cores. |
| [OH_AI_ContextSetThreadAffinityCoreList](_mind_spore.md#oh_ai_contextsetthreadaffinitycorelist) ([OH_AI_ContextHandle](_mind_spore.md#oh_ai_contexthandle) context, const int32_t \*core_list, size_t core_num) | Sets the list of CPU cores bound to a runtime thread. |
| [OH_AI_ContextGetThreadAffinityCoreList](_mind_spore.md#oh_ai_contextgetthreadaffinitycorelist) (const [OH_AI_ContextHandle](_mind_spore.md#oh_ai_contexthandle) context, size_t \*core_num) | Obtains the list of bound CPU cores. |
| [OH_AI_ContextSetEnableParallel](_mind_spore.md#oh_ai_contextsetenableparallel) ([OH_AI_ContextHandle](_mind_spore.md#oh_ai_contexthandle) context, bool is_parallel) | Sets whether to enable parallelism between operators. |
| [OH_AI_ContextGetEnableParallel](_mind_spore.md#oh_ai_contextgetenableparallel) (const [OH_AI_ContextHandle](_mind_spore.md#oh_ai_contexthandle) context) | Checks whether parallelism between operators is supported. |
| [OH_AI_ContextAddDeviceInfo](_mind_spore.md#oh_ai_contextadddeviceinfo) ([OH_AI_ContextHandle](_mind_spore.md#oh_ai_contexthandle) context, [OH_AI_DeviceInfoHandle](_mind_spore.md#oh_ai_deviceinfohandle) device_info) | Adds information about a running device. |
| [OH_AI_DeviceInfoCreate](_mind_spore.md#oh_ai_deviceinfocreate) ([OH_AI_DeviceType](_mind_spore.md#oh_ai_devicetype) device_type) | Creates a device information object. |
| [OH_AI_DeviceInfoDestroy](_mind_spore.md#oh_ai_deviceinfodestroy) ([OH_AI_DeviceInfoHandle](_mind_spore.md#oh_ai_deviceinfohandle) \*device_info) | Destroys a device information instance. |
| [OH_AI_DeviceInfoSetProvider](_mind_spore.md#oh_ai_deviceinfosetprovider) ([OH_AI_DeviceInfoHandle](_mind_spore.md#oh_ai_deviceinfohandle) device_info, const char \*provider) | Sets the name of a provider. |
| [OH_AI_DeviceInfoGetProvider](_mind_spore.md#oh_ai_deviceinfogetprovider) (const [OH_AI_DeviceInfoHandle](_mind_spore.md#oh_ai_deviceinfohandle) device_info) | Obtains the provider name. |
| [OH_AI_DeviceInfoSetProviderDevice](_mind_spore.md#oh_ai_deviceinfosetproviderdevice) ([OH_AI_DeviceInfoHandle](_mind_spore.md#oh_ai_deviceinfohandle) device_info, const char \*device) | Sets the name of a provider device. |
| [OH_AI_DeviceInfoGetProviderDevice](_mind_spore.md#oh_ai_deviceinfogetproviderdevice) (const [OH_AI_DeviceInfoHandle](_mind_spore.md#oh_ai_deviceinfohandle) device_info) | Obtains the name of a provider device. |
| [OH_AI_DeviceInfoGetDeviceType](_mind_spore.md#oh_ai_deviceinfogetdevicetype) (const [OH_AI_DeviceInfoHandle](_mind_spore.md#oh_ai_deviceinfohandle) device_info) | Obtains the type of a provider device. |
| [OH_AI_DeviceInfoSetEnableFP16](_mind_spore.md#oh_ai_deviceinfosetenablefp16) ([OH_AI_DeviceInfoHandle](_mind_spore.md#oh_ai_deviceinfohandle) device_info, bool is_fp16) | Sets whether to enable float16 inference. This function is available only for CPU/GPU devices. |
| [OH_AI_DeviceInfoGetEnableFP16](_mind_spore.md#oh_ai_deviceinfogetenablefp16) (const [OH_AI_DeviceInfoHandle](_mind_spore.md#oh_ai_deviceinfohandle) device_info) | Checks whether float16 inference is enabled. This function is available only for CPU/GPU devices. |
| [OH_AI_DeviceInfoSetFrequency](_mind_spore.md#oh_ai_deviceinfosetfrequency) ([OH_AI_DeviceInfoHandle](_mind_spore.md#oh_ai_deviceinfohandle) device_info, int frequency) | Sets the NPU frequency type. This function is available only for NPU devices. |
| [OH_AI_DeviceInfoGetFrequency](_mind_spore.md#oh_ai_deviceinfogetfrequency) (const [OH_AI_DeviceInfoHandle](_mind_spore.md#oh_ai_deviceinfohandle) device_info) | Obtains the NPU frequency type. This function is available only for NPU devices. |
| [OH_AI_ContextCreate](_mind_spore.md#oh_ai_contextcreate) () | Creates a context object.|
| [OH_AI_ContextDestroy](_mind_spore.md#oh_ai_contextdestroy) (OH_AI_ContextHandle \*context) | Destroys a context object.|
| [OH_AI_ContextSetThreadNum](_mind_spore.md#oh_ai_contextsetthreadnum) (OH_AI_ContextHandle context, int32_t thread_num) | Sets the number of runtime threads.|
| [OH_AI_ContextGetThreadNum](_mind_spore.md#oh_ai_contextgetthreadnum) (const OH_AI_ContextHandle context) | Obtains the number of threads.|
| [OH_AI_ContextSetThreadAffinityMode](_mind_spore.md#oh_ai_contextsetthreadaffinitymode) (OH_AI_ContextHandle context, int mode) | Sets the affinity mode for binding runtime threads to CPU cores, which are classified into large, medium, and small cores based on the CPU frequency. You only need to bind the large or medium cores, but not small cores.|
| [OH_AI_ContextGetThreadAffinityMode](_mind_spore.md#oh_ai_contextgetthreadaffinitymode) (const OH_AI_ContextHandle context) | Obtains the affinity mode for binding runtime threads to CPU cores.|
| [OH_AI_ContextSetThreadAffinityCoreList](_mind_spore.md#oh_ai_contextsetthreadaffinitycorelist) (OH_AI_ContextHandle context, const int32_t \*core_list, size_t core_num) | Sets the list of CPU cores bound to a runtime thread.|
| [OH_AI_ContextGetThreadAffinityCoreList](_mind_spore.md#oh_ai_contextgetthreadaffinitycorelist) (const OH_AI_ContextHandle context, size_t \*core_num) | Obtains the list of bound CPU cores.|
| [OH_AI_ContextSetEnableParallel](_mind_spore.md#oh_ai_contextsetenableparallel) (OH_AI_ContextHandle context, bool is_parallel) | Sets whether to enable parallelism between operators. The setting is ineffective because the feature of this API is not yet available.|
| [OH_AI_ContextGetEnableParallel](_mind_spore.md#oh_ai_contextgetenableparallel) (const OH_AI_ContextHandle context) | Checks whether parallelism between operators is supported.|
| [OH_AI_ContextAddDeviceInfo](_mind_spore.md#oh_ai_contextadddeviceinfo) (OH_AI_ContextHandle context, OH_AI_DeviceInfoHandle device_info) | Attaches the custom device information to the inference context.|
| [OH_AI_DeviceInfoCreate](_mind_spore.md#oh_ai_deviceinfocreate) (OH_AI_DeviceType device_type) | Creates a device information object.|
| [OH_AI_DeviceInfoDestroy](_mind_spore.md#oh_ai_deviceinfodestroy) (OH_AI_DeviceInfoHandle \*device_info) | Destroys a device information object. Note: After the device information instance is added to the context, the caller does not need to destroy it manually.|
| [OH_AI_DeviceInfoSetProvider](_mind_spore.md#oh_ai_deviceinfosetprovider) (OH_AI_DeviceInfoHandle device_info, const char \*provider) | Sets the provider name.|
| [OH_AI_DeviceInfoGetProvider](_mind_spore.md#oh_ai_deviceinfogetprovider) (const OH_AI_DeviceInfoHandle device_info) | Obtains the provider name.|
| [OH_AI_DeviceInfoSetProviderDevice](_mind_spore.md#oh_ai_deviceinfosetproviderdevice) (OH_AI_DeviceInfoHandle device_info, const char \*device) | Sets the name of a provider device.|
| [OH_AI_DeviceInfoGetProviderDevice](_mind_spore.md#oh_ai_deviceinfogetproviderdevice) (const OH_AI_DeviceInfoHandle device_info) | Obtains the name of a provider device.|
| [OH_AI_DeviceInfoGetDeviceType](_mind_spore.md#oh_ai_deviceinfogetdevicetype) (const OH_AI_DeviceInfoHandle device_info) | Obtains the device type.|
| [OH_AI_DeviceInfoSetEnableFP16](_mind_spore.md#oh_ai_deviceinfosetenablefp16) (OH_AI_DeviceInfoHandle device_info, bool is_fp16) | Sets whether to enable float16 inference. This function is available only for CPU and GPU devices.|
| [OH_AI_DeviceInfoGetEnableFP16](_mind_spore.md#oh_ai_deviceinfogetenablefp16) (const OH_AI_DeviceInfoHandle device_info) | Checks whether float16 inference is enabled. This function is available only for CPU and GPU devices.|
| [OH_AI_DeviceInfoSetFrequency](_mind_spore.md#oh_ai_deviceinfosetfrequency) (OH_AI_DeviceInfoHandle device_info, int frequency) | Sets the NPU frequency type. This function is available only for NPU devices.|
| [OH_AI_DeviceInfoGetFrequency](_mind_spore.md#oh_ai_deviceinfogetfrequency) (const OH_AI_DeviceInfoHandle device_info) | Obtains the NPU frequency type. This function is available only for NPU devices.|
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册