未验证 提交 3fa1dde9 编写于 作者: O openharmony_ci 提交者: Gitee

!17086 翻译已完成16581+16237+16415+16422+16391+16529+16567+16477+16598+16573+16554+16662+16828

Merge pull request !17086 from shawn_he/16581-d
......@@ -30,7 +30,7 @@ The following table provides only a simple description of the related APIs. For
| on\('dataProgress'\)<sup>10+</sup> | Registers an observer for events indicating progress of receiving HTTP streaming responses. |
| off\('dataProgress'\)<sup>10+</sup> | Unregisters the observer for events indicating progress of receiving HTTP streaming responses.|
## How to Develop
## How to Develop request APIs
1. Import the **http** namespace from **@ohos.net.http.d.ts**.
2. Call **createHttp()** to create an **HttpRequest** object.
......@@ -89,3 +89,80 @@ httpRequest.request(
}
);
```
## How to Develop request2 APIs
1. Import the **http** namespace from **@ohos.net.http.d.ts**.
2. Call **createHttp()** to create an **HttpRequest** object.
3. Depending on your need, call **on()** of the **HttpRequest** object to subscribe to HTTP response header events as well as events indicating receiving of HTTP streaming responses, progress of receiving HTTP streaming responses, and completion of receiving HTTP streaming responses.
4. Call **request2()** to initiate a network request. You need to pass in the URL and optional parameters of the HTTP request.
5. Parse the returned response code as needed.
6. Call **off()** of the **HttpRequest** object to unsubscribe from the related events.
7. Call **httpRequest.destroy()** to release resources after the request is processed.
```js
// Import the http namespace.
import http from '@ohos.net.http'
// Each httpRequest corresponds to an HTTP request task and cannot be reused.
let httpRequest = http.createHttp();
// Subscribe to HTTP response header events.
httpRequest.on('headersReceive', (header) => {
console.info('header: ' + JSON.stringify(header));
});
// Subscribe to events indicating receiving of HTTP streaming responses.
let res = '';
httpRequest.on('dataReceive', (data) => {
res += data;
console.info('res: ' + res);
});
// Subscribe to events indicating completion of receiving HTTP streaming responses.
httpRequest.on('dataEnd', () => {
console.info('No more data in response, data receive end');
});
// Subscribe to events indicating progress of receiving HTTP streaming responses.
httpRequest.on('dataProgress', (data) => {
console.log("dataProgress receiveSize:" + data.receiveSize+ ", totalSize:" + data.totalSize);
});
httpRequest.request2(
// Customize EXAMPLE_URL in extraData on your own. It is up to you whether to add parameters to the URL.
"EXAMPLE_URL",
{
method: http.RequestMethod.POST, // Optional. The default value is http.RequestMethod.GET.
// You can add header fields based on service requirements.
header: {
'Content-Type': 'application/json'
},
// This field is used to transfer data when the POST request is used.
extraData: {
"data": "data to send",
},
expectDataType: http.HttpDataType.STRING, // Optional. This field specifies the type of the return data.
usingCache: true, // Optional. The default value is true.
priority: 1, // Optional. The default value is 1.
connectTimeout: 60000 // Optional. The default value is 60000, in ms.
readTimeout: 60000, // Optional. The default value is 60000, in ms. If a large amount of data needs to be transmitted, you are advised to set this parameter to a larger value to ensure normal data transmission.
usingProtocol: http.HttpProtocol.HTTP1_1, // Optional. The default protocol type is automatically specified by the system.
}, (err, data) => {
console.info('error:' + JSON.stringify(err));
console.info('ResponseCode :' + JSON.stringify(data));
// Unsubscribe from HTTP Response Header events.
httpRequest.off('headersReceive');
// Unregister the observer for events indicating receiving of HTTP streaming responses.
httpRequest.off('dataReceive');
// Unregister the observer for events indicating progress of receiving HTTP streaming responses.
httpRequest.off('dataProgress');
// Unregister the observer for events indicating completion of receiving HTTP streaming responses.
httpRequest.off('dataEnd');
// Call the destroy() method to release resources after HttpRequest is complete.
httpRequest.destroy();
}
);
```
## Samples
The following sample is provided to help you better understand how to develop the HTTP data request feature:
- [HTTP Data Request (ArkTS) (API9)](https://gitee.com/openharmony/applications_app_samples/tree/master/code/BasicFeature/Connectivity/Http)
- [HTTP Communication (ArkTS) (API9)](https://gitee.com/openharmony/codelabs/tree/master/NetworkManagement/SmartChatEtsOH)
......@@ -18,5 +18,4 @@
- [Native API Usage](faqs-native.md)
- [Usage of Third- and Fourth-Party Libraries](faqs-third-party-library.md)
- [IDE Usage](faqs-ide.md)
- [hdc_std Command Usage](faqs-hdc-std.md)
- [Development Board](faqs-development-board.md)
\ No newline at end of file
# hdc_std Command Usage
## Common Log Commands
Applicable to: OpenHarmony SDK 3.2.2.5
Clearing logs: hdc_std shell hilog -r
Increasing the buffer size to 20 MB: hdc_std shell hilog -G 20M
Capturing logs: hdc_std shell hilog &gt; log.txt
## What should I do to avoid log flow control?
Applicable to: OpenHarmony SDK 3.2.5.3, stage model of API version 9
- Disabling log flow control: hdc_std shell hilog -Q pidoff
- Disabling the privacy flag: hdc_std shell hilog -p off
- Increasing the log buffer to 200 MB: hdc_std shell hilog -G 200M
- Enabling the log function of the specific domain (that is, disabling the global log function): hdc_std shell hilog –b D –D 0xd0xxxxx
After performing the preceding operations, restart the DevEco Studio.
## What should I do if the HAP installed on the development board through the IDE cannot be opened?
Applicable to: OpenHarmony SDK 3.2.5.3, stage model of API version 9
Check whether the SDK version is consistent with the system version on the development board. You are advised to use the SDK version and system version that are released on the same day.
## How do I upload files using the hdc command?
Applicable to: OpenHarmony SDK 3.2.2.5
Run the **hdc_std file send** command.
## How do I prevent the screen of the RK3568 development board from turning off?
Applicable to: OpenHarmony SDK 3.2.5.3, stage model of API version 9
Run the **hdc_std shell "power-shell setmode 602"** command.
## How do I start an ability using the hdc command?
Applicable to: OpenHarmony SDK 3.2.5.3, stage model of API version 9
Run the **hdc\_std shell aa start -a AbilityName -b bundleName -m moduleName** command.
## How do I change the read and write permissions on a file directory on the development board?
Applicable to: OpenHarmony SDK 3.2.5.6, stage model of API version 9
Run the **hdc\_std shell mount -o remount,rw /** command.
## What should I do if the error message "Unknown file option -r" is displayed when hdc_std file recv is run?
Applicable to: OpenHarmony SDK 3.2.5.6, stage model of API version 9
1. Use the the hdc tool in the device image or SDK of the same version.
2. Remove any Chinese characters or spaces from the directory specified for the hdc tool.
## How do I uninstall an application using the hdc command?
Applicable to: OpenHarmony SDK 3.2.2.5
Run the **hdc\_std uninstall [-k] [package_name]** command.
## How do I check whether the system is 32-bit or 64-bit?
Applicable to: OpenHarmony SDK 3.2.5.5
Run the **hdc\_std shell getconf LONG_BIT** command.
If **64** is returned, the system is a 64-bit one. Otherwise, the system is a 32-bit one.
## How do I view the component tree structure?
Applicable to: OpenHarmony SDK 3.2.5.5
1. Run the **hdc\_std shell** command to launch the CLI.
2. Run the **aa dump -a** command to find **abilityID**.
3. Run the **aa dump -i [abilityID] -c -render** command to view the component tree.
......@@ -265,6 +265,7 @@
- [@ohos.net.socket (Socket Connection)](js-apis-socket.md)
- [@ohos.net.webSocket (WebSocket Connection)](js-apis-webSocket.md)
- [@ohos.request (Upload and Download)](js-apis-request.md)
- [@ohos.net.mdns (mDNS Management)](js-apis-net-mdns.md)
- Connectivity
- [@ohos.bluetooth (Bluetooth)(To Be Deprecated Soon)](js-apis-bluetooth.md)
......
# @ohos.contact (Contacts)
The **contact** module provides contact management functions, such as adding, deleting, and updating contacts.
>**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.
......@@ -7,7 +9,7 @@
## Modules to Import
```js
```
import contact from '@ohos.contact';
```
......@@ -183,7 +185,7 @@ Updates a contact based on the specified contact information. This API uses an a
updateContact(contact: Contact, attrs: ContactAttributes, callback: AsyncCallback&lt;void&gt;): void
Updates a contact based on the specified contact information and attributes. This API uses an asynchronous callback to return the result.
Updates a contact based on the specified contact information. This API uses an asynchronous callback to return the result.
**Permission required**: ohos.permission.WRITE_CONTACTS
......@@ -234,7 +236,6 @@ Updates a contact based on the specified contact information and attributes. Thi
| attrs | [ContactAttributes](#contactattributes) | No | List of contact attributes.|
**Return Value**
| Type | Description |
| ------------------- | ------------------------------------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
......@@ -418,7 +419,7 @@ Queries my card. This API uses an asynchronous callback to return the result.
queryMyCard(attrs: ContactAttributes, callback: AsyncCallback&lt;Contact&gt;): void
Queries my card based on the specified contact attributes. This API uses an asynchronous callback to return the result.
Queries my card. This API uses an asynchronous callback to return the result.
**Permission required**: ohos.permission.READ_CONTACTS
......@@ -463,7 +464,6 @@ Queries my card based on the specified contact attributes. This API uses a promi
| attrs | [ContactAttributes](#contactattributes) | No | List of contact attributes.|
**Return Value**
| Type | Description |
| ---------------------------------- | ------------------------------------------- |
| Promise&lt;[Contact](#contact)&gt; | Promise used to return the result.|
......@@ -488,8 +488,6 @@ selectContact(callback: AsyncCallback&lt;Array&lt;Contact&gt;&gt;): void
Selects a contact. This API uses an asynchronous callback to return the result.
**Permission required**: ohos.permission.READ_CONTACTS
**System capability**: SystemCapability.Applications.Contacts
**Parameters**
......@@ -517,8 +515,6 @@ selectContact(): Promise&lt;Array&lt;Contact&gt;&gt;
Selects a contact. This API uses a promise to return the result.
**Permission required**: ohos.permission.READ_CONTACTS
**System capability**: SystemCapability.Applications.Contacts
**Return Value**
......@@ -573,7 +569,7 @@ Queries a contact based on the specified key. This API uses an asynchronous call
queryContact(key: string, holder: Holder, callback: AsyncCallback&lt;Contact&gt;): void
Queries contacts based on the specified key and application. This API uses an asynchronous callback to return the result.
Queries a contact based on the specified key. This API uses an asynchronous callback to return the result.
**Permission required**: ohos.permission.READ_CONTACTS
......@@ -608,7 +604,7 @@ Queries contacts based on the specified key and application. This API uses an as
queryContact(key: string, attrs: ContactAttributes, callback: AsyncCallback&lt;Contact&gt;): void
Queries contacts based on the specified key and attributes. This API uses an asynchronous callback to return the result.
Queries a contact based on the specified key. This API uses an asynchronous callback to return the result.
**Permission required**: ohos.permission.READ_CONTACTS
......@@ -641,7 +637,7 @@ Queries contacts based on the specified key and attributes. This API uses an asy
queryContact(key: string, holder: Holder, attrs: ContactAttributes, callback: AsyncCallback&lt;Contact&gt;): void
Queries contacts based on the specified key, application, and attributes. This API uses an asynchronous callback to return the result.
Queries a contact based on the specified key. This API uses an asynchronous callback to return the result.
**Permission required**: ohos.permission.READ_CONTACTS
......@@ -660,7 +656,6 @@ Queries contacts based on the specified key, application, and attributes. This A
```js
contact.queryContact('xxx', {
holderId: 0
holderId: 0,
bundleName: "",
displayName: ""
......@@ -695,7 +690,6 @@ Queries contacts based on the specified key, application, and attributes. This A
| attrs | [ContactAttributes](#contactattributes) | No | List of contact attributes. |
**Return Value**
| Type | Description |
| ---------------------------------- | ----------------------------------------------- |
| Promise&lt;[Contact](#contact)&gt; | Promise used to return the result.|
......@@ -704,7 +698,6 @@ Queries contacts based on the specified key, application, and attributes. This A
```js
let promise = contact.queryContact('xxx', {
holderId: 0
holderId: 0,
bundleName: "",
displayName: ""
......@@ -752,7 +745,7 @@ Queries all contacts. This API uses an asynchronous callback to return the resul
queryContacts(holder: Holder, callback: AsyncCallback&lt;Array&lt;Contact&gt;&gt;): void
Queries all contacts based on the specified application. This API uses an asynchronous callback to return the result.
Queries all contacts. This API uses an asynchronous callback to return the result.
**Permission required**: ohos.permission.READ_CONTACTS
......@@ -786,7 +779,7 @@ Queries all contacts based on the specified application. This API uses an asynch
queryContacts(attrs: ContactAttributes, callback: AsyncCallback&lt;Array&lt;Contact&gt;&gt;): void
Queries all contacts based on the specified attributes. This API uses an asynchronous callback to return the result.
Queries all contacts. This API uses an asynchronous callback to return the result.
**Permission required**: ohos.permission.READ_CONTACTS
......@@ -818,7 +811,7 @@ Queries all contacts based on the specified attributes. This API uses an asynchr
queryContacts(holder: Holder, attrs: ContactAttributes, callback: AsyncCallback&lt;Array&lt;Contact&gt;&gt;): void
Queries all contacts based on the specified application and attributes. This API uses an asynchronous callback to return the result.
Queries all contacts. This API uses an asynchronous callback to return the result.
**Permission required**: ohos.permission.READ_CONTACTS
......@@ -869,7 +862,6 @@ Queries all contacts based on the specified application and attributes. This API
| attrs | [ContactAttributes](#contactattributes) | No | List of contact attributes. |
**Return Value**
| Type | Description |
| ----------------------------------------------- | --------------------------------------------------- |
| Promise&lt;Array&lt;[Contact](#contact)&gt;&gt; | Promise used to return the result.|
......@@ -926,7 +918,7 @@ Queries contacts based on the specified phone number. This API uses an asynchron
queryContactsByPhoneNumber(phoneNumber: string, holder: Holder, callback: AsyncCallback&lt;Array&lt;Contact&gt;&gt;): void
Queries contacts based on the specified phone number and application. This API uses an asynchronous callback to return the result.
Queries contacts based on the specified phone number. This API uses an asynchronous callback to return the result.
**Permission required**: ohos.permission.READ_CONTACTS
......@@ -961,7 +953,7 @@ Queries contacts based on the specified phone number and application. This API u
queryContactsByPhoneNumber(phoneNumber: string, attrs: ContactAttributes, callback: AsyncCallback&lt;Array&lt;Contact&gt;&gt;): void
Queries contacts based on the specified phone number and attributes. This API uses an asynchronous callback to return the result.
Queries contacts based on the specified phone number. This API uses an asynchronous callback to return the result.
**Permission required**: ohos.permission.READ_CONTACTS
......@@ -994,7 +986,7 @@ Queries contacts based on the specified phone number and attributes. This API us
queryContactsByPhoneNumber(phoneNumber: string, holder: Holder, attrs: ContactAttributes, callback: AsyncCallback&lt;Array&lt;Contact&gt;&gt;): void
Queries contacts based on the specified phone number, application, and attributes. This API uses an asynchronous callback to return the result.
Queries contacts based on the specified phone number. This API uses an asynchronous callback to return the result.
**Permission required**: ohos.permission.READ_CONTACTS
......@@ -1104,7 +1096,7 @@ Queries contacts based on the specified email address. This API uses an asynchro
queryContactsByEmail(email: string, holder: Holder, callback: AsyncCallback&lt;Array&lt;Contact&gt;&gt;): void
Queries contacts based on the specified email address and application. This API uses an asynchronous callback to return the result.
Queries contacts based on the specified email address. This API uses an asynchronous callback to return the result.
**Permission required**: ohos.permission.READ_CONTACTS
......@@ -1122,7 +1114,7 @@ Queries contacts based on the specified email address and application. This API
```js
contact.queryContactsByEmail('xxx@email.com', {
holderId: 0,
holderId: 0,
bundleName: "",
displayName: ""
}, (err, data) => {
......@@ -1139,7 +1131,7 @@ Queries contacts based on the specified email address and application. This API
queryContactsByEmail(email: string, attrs: ContactAttributes, callback: AsyncCallback&lt;Array&lt;Contact&gt;&gt;): void
Queries contacts based on the specified email address and attributes. This API uses an asynchronous callback to return the result.
Queries contacts based on the specified email address. This API uses an asynchronous callback to return the result.
**Permission required**: ohos.permission.READ_CONTACTS
......@@ -1172,7 +1164,7 @@ Queries contacts based on the specified email address and attributes. This API u
queryContactsByEmail(email: string, holder: Holder, attrs: ContactAttributes, callback: AsyncCallback&lt;Array&lt;Contact&gt;&gt;): void
Queries contacts based on the specified email address, application, and attributes. This API uses an asynchronous callback to return the result.
Queries contacts based on the specified email address. This API uses an asynchronous callback to return the result.
**Permission required**: ohos.permission.READ_CONTACTS
......@@ -1281,7 +1273,7 @@ Queries all groups of this contact. This API uses an asynchronous callback to re
queryGroups(holder: Holder, callback: AsyncCallback&lt;Array&lt;Group&gt;&gt;): void
Queries all groups of this contact based on the specified application. This API uses an asynchronous callback to return the result.
Queries all groups of this contact. This API uses an asynchronous callback to return the result.
**Permission required**: ohos.permission.READ_CONTACTS
......@@ -1440,7 +1432,7 @@ Queries the key of a contact based on the specified contact ID. This API uses an
queryKey(id: number, holder: Holder, callback: AsyncCallback&lt;string&gt;): void
Queries the key of a contact based on the specified contact ID and application. This API uses an asynchronous callback to return the result.
Queries the key of a contact based on the specified contact ID. This API uses an asynchronous callback to return the result.
**Permission required**: ohos.permission.READ_CONTACTS
......@@ -1525,7 +1517,7 @@ Defines a contact.
### Attributes
| Name | Type | Readable| Writable| Description |
| Name | Type | Readable| Writable| Description |
| ----------------- | --------------------------------------- | ---- | ---- | -------------------------------------- |
| id | number | Yes | No | Contact ID. |
| key | string | Yes | No | Contact key. |
......@@ -1587,7 +1579,7 @@ If **null** is passed, all attributes are queried by default.
**System capability**: SystemCapability.Applications.ContactsData
| Name | Type | Readable| Writable| Description |
| Name | Type | Readable| Writable| Description |
| ---------- | ------------------------- | ---- | ---- | ---------------- |
| attributes | [Attribute](#attribute)[] | Yes | Yes | List of contact attributes.|
......@@ -1668,7 +1660,7 @@ Defines a contact's email.
### Attributes
| Name | Type| Readable| Writable| Description |
| Name | Type | Readable| Writable| Description |
| ----------- | -------- | ---- | ---- | ---------------- |
| email | string | Yes | Yes | Email addresses |
| labelName | string | Yes | Yes | Name of the mailbox type.|
......@@ -1702,11 +1694,11 @@ Defines an application that creates the contact.
**System capability**: SystemCapability.Applications.ContactsData
| Name | Type| Readable| Writable| Description |
| ----------- | -------- | ---- | ---- | ---------- |
| bundleName | string | Yes | No | Bundle name. |
| displayName | string | Yes | No | Application name.|
| holderId | number | Yes | Yes | Application ID. |
| Name | Type | Readable| Writable| Description |
| ----------- | ------ | ---- | ---- | ------------ |
| bundleName | string | Yes | No | Bundle name.|
| displayName | string | Yes | No | Application name. |
| holderId | number | Yes | Yes | Application ID. |
**Example**
......@@ -1746,7 +1738,7 @@ Defines a contact's event.
### Attributes
| Name | Type| Readable| Writable| Description |
| Name | Type | Readable| Writable| Description |
| --------- | -------- | ---- | ---- | -------------- |
| eventDate | string | Yes | Yes | Event date. |
| labelName | string | Yes | Yes | Event type.|
......@@ -1777,7 +1769,7 @@ Defines a contact group.
**System capability**: SystemCapability.Applications.ContactsData
| Name | Type| Readable| Writable| Description |
| Name | Type | Readable| Writable| Description |
| ------- | -------- | ---- | ---- | ------------------ |
| groupId | number | Yes | Yes | ID of a contact group. |
| title | string | Yes | Yes | Name of a contact group.|
......@@ -1825,7 +1817,7 @@ Enumerates IM addresses.
### Attributes
| Name | Type| Readable| Writable| Description |
| Name | Type | Readable| Writable| Description |
| --------- | -------- | ---- | ---- | ------------------ |
| imAddress | string | Yes | Yes | IM address. |
| labelName | string | Yes | Yes | IM name.|
......@@ -1858,7 +1850,7 @@ Defines a contact's name.
**System capability**: SystemCapability.Applications.ContactsData
| Name | Type| Readable| Writable| Description |
| Name | Type | Readable| Writable| Description |
| ------------------ | -------- | ---- | ---- | --------------------------- |
| familyName | string | Yes | Yes | Family name. |
| familyNamePhonetic | string | Yes | Yes | Family name in pinyin. |
......@@ -1897,7 +1889,7 @@ Defines a contact's nickname.
**System capability**: SystemCapability.Applications.ContactsData
| Name | Type| Readable| Writable| Description |
| Name | Type | Readable| Writable| Description |
| -------- | -------- | ---- | ---- | -------------- |
| nickName | string | Yes | Yes | Contact nickname.|
......@@ -1926,7 +1918,7 @@ Defines a contact's note.
**System capability**: SystemCapability.Applications.ContactsData
| Name | Type| Readable| Writable| Description |
| Name | Type | Readable| Writable| Description |
| ----------- | -------- | ---- | ---- | ------------------ |
| noteContent | string | Yes | Yes | Notes of the contact.|
......@@ -1955,7 +1947,7 @@ Defines a contact's organization.
**System capability**: SystemCapability.Applications.ContactsData
| Name | Type| Readable| Writable| Description |
| Name | Type | Readable| Writable| Description |
| ----- | -------- | ---- | ---- | ---------- |
| name | string | Yes | Yes | Organization name.|
| title | string | Yes | Yes | Organization title.|
......@@ -2017,7 +2009,7 @@ Defines a contact's phone number.
### Attributes
| Name | Type| Readable| Writable| Description |
| Name | Type | Readable| Writable| Description |
| ----------- | -------- | ---- | ---- | ------------------ |
| labelName | string | Yes | Yes | Phone number type.|
| phoneNumber | string | Yes | Yes | Phone number. |
......@@ -2049,7 +2041,7 @@ Defines a contact's portrait.
**System capability**: SystemCapability.Applications.ContactsData
| Name| Type| Readable| Writable| Description |
| Name| Type | Readable| Writable| Description |
| ---- | -------- | ---- | ---- | -------------- |
| uri | string | Yes | Yes | Contact portrait.|
......@@ -2091,7 +2083,7 @@ Defines a contact's postal address.
### Attributes
| Name | Type| Readable| Writable| Description |
| Name | Type | Readable| Writable| Description |
| ------------- | -------- | ---- | ---- | -------------------------- |
| city | string | Yes | Yes | City where the contact is located. |
| country | string | Yes | Yes | Country/Region where the contact is located. |
......@@ -2153,7 +2145,7 @@ Defines a contact's relationship.
### Attributes
| Name | Type| Readable| Writable| Description |
| Name | Type | Readable| Writable| Description |
| ------------ | -------- | ---- | ---- | -------------- |
| labelName | string | Yes | Yes | Relationship type.|
| relationName | string | Yes | Yes | Relationship name. |
......@@ -2199,13 +2191,12 @@ Defines a contact's SIP address.
### Attributes
| Name | Type| Readable| Writable| Description |
| Name | Type | Readable| Writable| Description |
| ---------- | -------- | ---- | ---- | --------------------------------- |
| labelName | string | Yes | Yes | SIP address type.|
| sipAddress | string | Yes | Yes | SIP address. |
| labelId | number | Yes | Yes | SIP address ID. |
**Example**
Create contact data in JSON format:
......@@ -2230,7 +2221,7 @@ Defines a contact's website.
**System capability**: SystemCapability.Applications.ContactsData
| Name | Type| Readable| Writable| Description |
| Name | Type | Readable| Writable| Description |
| ------- | -------- | ---- | ---- | ------------------ |
| website | string | Yes | Yes | Website of the contact.|
......@@ -2250,4 +2241,4 @@ let website = {
```js
let website = new contact.Website();
website.website = "website";
```
\ No newline at end of file
```
......@@ -16,7 +16,7 @@ import http from '@ohos.net.http';
## Examples
```js
// Import the HTTP namespace.
// Import the http namespace.
import http from '@ohos.net.http';
// Each httpRequest corresponds to an HTTP request task and cannot be reused.
......@@ -112,7 +112,7 @@ Initiates an HTTP request to a given URL. This API uses an asynchronous callback
**Error codes**
| ID | Error Message |
| Code | Error Message |
|---------|-------------------------------------------------------|
| 401 | Parameter error. |
| 201 | Permission denied. |
......@@ -164,7 +164,7 @@ Initiates an HTTP request containing specified options to a given URL. This API
**Error codes**
| ID | Error Message |
| Code | Error Message |
|---------|-------------------------------------------------------|
| 401 | Parameter error. |
| 201 | Permission denied. |
......@@ -255,7 +255,7 @@ Initiates an HTTP request containing specified options to a given URL. This API
**Error codes**
| ID | Error Message |
| Code | Error Message |
|---------|-------------------------------------------------------|
| 401 | Parameter error. |
| 201 | Permission denied. |
......@@ -349,7 +349,7 @@ Initiates an HTTP request to a given URL. This API uses an asynchronous callback
**Error codes**
| ID | Error Message |
| Code | Error Message |
|---------|-------------------------------------------------------|
| 401 | Parameter error. |
| 201 | Permission denied. |
......@@ -395,7 +395,7 @@ Initiates an HTTP request to a given URL. This API uses an asynchronous callback
**Error codes**
| ID | Error Message |
| Code | Error Message |
|---------|-------------------------------------------------------|
| 401 | Parameter error. |
| 201 | Permission denied. |
......@@ -477,7 +477,7 @@ Initiates an HTTP request containing specified options to a given URL. This API
**Error codes**
| ID | Error Message |
| Code | Error Message |
|---------|-------------------------------------------------------|
| 401 | Parameter error. |
| 201 | Permission denied. |
......@@ -513,7 +513,7 @@ Initiates an HTTP request containing specified options to a given URL. This API
>**NOTE**
> For details about the error codes, see [HTTP Error Codes](../errorcodes/errorcode-net-http.md).
> The HTTP error code mapping is in the format of 2300000 + Curl error code. For more common error codes, see:
> The HTTP error code mapping is in the format of 2300000 + Curl error code. For more common error codes, see [Curl Error Codes](https://curl.se/libcurl/c/libcurl-errors.html).
**Example**
......@@ -540,7 +540,7 @@ on(type: 'headerReceive', callback: AsyncCallback\<Object\>): void
Registers an observer for HTTP Response Header events.
>**NOTE**
>This API has been deprecated. You are advised to use [on('headersReceive')<sup>8+</sup>](#onheadersreceive8) instead.
>This API has been deprecated. You are advised to use [on('headersReceive')<sup>8+</sup>](#onheadersreceive8).
**System capability**: SystemCapability.Communication.NetStack
......@@ -567,7 +567,7 @@ Unregisters the observer for HTTP Response Header events.
>**NOTE**
>
>1. This API has been deprecated. You are advised to use [off('headersReceive')<sup>8+</sup>](#offheadersreceive8) instead.
>1. This API has been deprecated. You are advised to use [off('headersReceive')<sup>8+</sup>](#offheadersreceive8).
>
>2. You can pass the callback of the **on** function if you want to cancel listening for a certain type of event. If you do not pass the callback, you will cancel listening for all events.
......@@ -839,7 +839,7 @@ Enumerates the response codes for an HTTP request.
| Name | Value | Description |
| ----------------- | ---- | ------------------------------------------------------------ |
| OK | 200 | "OK." The request has been processed successfully. This return code is generally used for GET and POST requests. |
| OK | 200 | The request is successful. The request has been processed successfully. This return code is generally used for GET and POST requests. |
| CREATED | 201 | "Created." The request has been successfully sent and a new resource is created. |
| ACCEPTED | 202 | "Accepted." The request has been accepted, but the processing has not been completed. |
| NOT_AUTHORITATIVE | 203 | "Non-Authoritative Information." The request is successful. |
......
......@@ -2112,6 +2112,75 @@ Obtains the sequence of the year, month, and day in the specified locale.
```
## Normalizer<sup>10+</sup>
### getInstance<sup>10+</sup>
static getInstance(mode: NormalizerMode): Normalizer
Obtains a **Normalizer** object for text normalization.
**System capability**: SystemCapability.Global.I18n
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | ------------------------- |
| mode | [NormalizerMode](#normalizermode10) | Yes | Text normalization mode.|
**Return value**
| Type | Description |
| ------ | ------------------- |
| [Normalizer](#normalizer10) | **Normalizer** object for text normalization.|
**Example**
```js
let normalizer = I18n.Normalizer.getInstance(I18n.NormalizerMode.NFC);
```
### normalize<sup>10+</sup>
normalize(text: string): string
Normalizes text strings.
**System capability**: SystemCapability.Global.I18n
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | ------------------------- |
| text | string | Yes | Text strings to be normalized.|
**Return value**
| Type | Description |
| ------ | ------------------- |
| string | Normalized text strings.|
**Example**
```js
let normalizer = I18n.Normalizer.getInstance(I18n.NormalizerMode.NFC);
let normalizedText = normalizer.normalize('\u1E9B\u0323'); // normalizedText = \u1E9B\u0323
```
## NormalizerMode<sup>10+</sup>
Enumerates text normalization modes.
**System capability**: SystemCapability.Global.I18n
| Name| Value| Description|
| -------- | -------- | -------- |
| NFC | 1 | NFC.|
| NFD | 2 | NFD.|
| NFKC | 3 | NFKC.|
| NFKD | 4 | NFKD.|
## I18n.getDisplayCountry<sup>(deprecated)</sup>
getDisplayCountry(country: string, locale: string, sentenceCase?: boolean): string
......
此差异已折叠。
# @ohos.power (System Power Management)
# @ohos.power (Power Manager)
The **power** module provides APIs for rebooting and shutting down the system, as well as querying the screen status.
> **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
......@@ -33,7 +34,7 @@ Shuts down the system.
For details about the error codes, see [Power Manager Error Codes](../errorcodes/errorcode-power.md).
| Code | Error Message |
| ID | Error Message |
|---------|---------|
| 4900101 | Operation failed. Cannot connect to service.|
......@@ -69,7 +70,7 @@ Reboots the system.
For details about the error codes, see [Power Manager Error Codes](../errorcodes/errorcode-power.md).
| Code | Error Message |
| ID | Error Message |
|---------|---------|
| 4900101 | Operation failed. Cannot connect to service.|
......@@ -95,7 +96,7 @@ Checks whether the current device is active. In the active state, the screen is
For details about the error codes, see [Power Manager Error Codes](../errorcodes/errorcode-power.md).
| Code | Error Message |
| ID | Error Message |
|---------|---------|
| 4900101 | Operation failed. Cannot connect to service.|
......@@ -130,7 +131,7 @@ Wakes up a device.
For details about the error codes, see [Power Manager Error Codes](../errorcodes/errorcode-power.md).
| Code | Error Message |
| ID | Error Message |
|---------|---------|
| 4900101 | Operation failed. Cannot connect to service.|
......@@ -158,7 +159,7 @@ Hibernates a device.
For details about the error codes, see [Power Manager Error Codes](../errorcodes/errorcode-power.md).
| Code | Error Message |
| ID | Error Message |
|---------|---------|
| 4900101 | Operation failed. Cannot connect to service.|
......@@ -190,7 +191,7 @@ Obtains the power mode of this device.
For details about the error codes, see [Power Manager Error Codes](../errorcodes/errorcode-power.md).
| Code | Error Message |
| ID | Error Message |
|---------|---------|
| 4900101 | Operation failed. Cannot connect to service.|
......@@ -228,7 +229,7 @@ Sets the power mode of this device. This API uses an asynchronous callback to re
For details about the error codes, see [Power Manager Error Codes](../errorcodes/errorcode-power.md).
| Code | Error Message |
| ID | Error Message |
|---------|---------|
| 4900101 | Operation failed. Cannot connect to service.|
......@@ -272,7 +273,7 @@ Sets the power mode of this device. This API uses a promise to return the result
For details about the error codes, see [Power Manager Error Codes](../errorcodes/errorcode-power.md).
| Code | Error Message |
| ID | Error Message |
|---------|---------|
| 4900101 | Operation failed. Cannot connect to service.|
......@@ -292,8 +293,7 @@ power.setPowerMode(power.DevicePowerMode.MODE_PERFORMANCE)
rebootDevice(reason: string): void
> NOTE<br>
> This API is deprecated since API version 9. You are advised to use [power.reboot](#powerreboot9) instead.
> **NOTE**<br>This API is supported since API version 7 and is deprecated since API version 9. You are advised to use [power.reboot](#powerreboot9). The substitute API is available only for system applications.
Reboots the system.
......@@ -317,8 +317,7 @@ power.rebootDevice('reboot_test');
isScreenOn(callback: AsyncCallback&lt;boolean&gt;): void
> NOTE<br>
> This API is deprecated since API version 9. You are advised to use [power.isActive](#powerisactive9) instead.
> **NOTE**<br>This API is deprecated since API version 9. You are advised to use [power.isActive](#powerisactive9).
Checks the screen status of the current device. This API uses an asynchronous callback to return the result.
......@@ -328,7 +327,7 @@ Checks the screen status of the current device. This API uses an asynchronous ca
| Name | Type | Mandatory| Description |
| -------- | ---------------------------- | ---- | ------------------------------------------------------------ |
| callback | AsyncCallback&lt;boolean&gt; | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the screen status obtained, where the value **true** indicates on and the value **false** indicates the opposite. Otherwise, **err** is an error object.|
| callback | AsyncCallback&lt;boolean&gt; | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the screen status obtained, where the value **true** indicates on and the value **false** indicates off. Otherwise, **err** is an error object.|
**Example**
......@@ -346,8 +345,7 @@ power.isScreenOn((err, data) => {
isScreenOn(): Promise&lt;boolean&gt;
> NOTE<br>
> This API is deprecated since API version 9. You are advised to use [power.isActive](#powerisactive9) instead.
> **NOTE**<br>This API is deprecated since API version 9. You are advised to use [power.isActive](#powerisactive9).
Checks the screen status of the current device. This API uses a promise to return the result.
......
......@@ -3,7 +3,8 @@
The **brightness** module provides APIs for querying and adjusting the screen brightness and mode.
> **NOTE**
> - The APIs of this module are no longer maintained since API version 7. It is recommended that you use [`@ohos.brightness`](js-apis-brightness.md) instead.
>
> - The APIs of this module are no longer maintained since API version 7. You are advised to use APIs of [`@ohos.brightness`](js-apis-brightness.md). The substitute APIs are available only for system applications.
> - The initial APIs of this module are supported since API version 3. Newly added APIs will be marked with a superscript to indicate their earliest API version.
......
# @ohos.telephony.data (Cellular Data)
The cellular data module provides basic mobile data management functions. You can obtain and set the default slot of the SIM card used for mobile data, and obtain the uplink and downlink connection status of cellular data services and connection status of the packet switched (PS) domain. Besides, you can check whether cellular data services and data roaming are enabled.
The **data** module provides basic mobile data management functions. You can obtain and set the default slot of the SIM card used for mobile data, and obtain the uplink and downlink connection status of cellular data services and connection status of the packet switched (PS) domain. Besides, you can check whether cellular data services and data roaming are enabled.
>**NOTE**
>
......@@ -24,7 +24,7 @@ Obtains the default slot of the SIM card used for mobile data. This API uses an
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | ------------------------------------------ |
| callback | AsyncCallback\<number\> | Yes | Callback used to return the result.<br>**0**: card slot 1<br>**1**: card slot 2|
| callback | AsyncCallback\<number\> | Yes | Callback used to return the result.<br>**0**: card slot 1.<br>**1**: card slot 2.|
**Example**
......@@ -46,7 +46,7 @@ Obtains the default slot of the SIM card used for mobile data. This API uses a p
| Type | Description |
| ----------------- | ------------------------------------------------------------ |
| Promise\<number\> | Promise used to return the result.<br>**0**: card slot 1<br>**1**: card slot 2|
| Promise\<number\> | Promise used to return the result.<br>**0**: card slot 1.<br>**1**: card slot 2.|
**Example**
......@@ -71,7 +71,7 @@ Obtains the default SIM card used for mobile data synchronously.
| Type | Description |
| ------ | -------------------------------------------------- |
| number | Card slot ID.<br>**0**: card slot 1<br>**1**: card slot 2|
| number | Card slot ID.<br>**0**: card slot 1.<br>**1**: card slot 2.|
**Example**
......@@ -87,7 +87,7 @@ Sets the default slot of the SIM card used for mobile data. This API uses an asy
**System API**: This is a system API.
**Required permission**: ohos.permission.SET_TELEPHONY_STATE
**Required permissions**: ohos.permission.SET_TELEPHONY_STATE
**System capability**: SystemCapability.Telephony.CellularData
......@@ -95,7 +95,7 @@ Sets the default slot of the SIM card used for mobile data. This API uses an asy
| Name | Type | Mandatory| Description |
| -------- | --------------------- | ---- | ------------------------------------------------------------ |
| slotId | number | Yes | SIM card slot ID. <br>**0**: card slot 1<br>**1**: card slot 2<br>**-1**: Clears the default configuration.|
| slotId | number | Yes | SIM card slot ID. <br>**0**: card slot 1.<br>**1**: card slot 2.<br>**-1**: Clears the default configuration.|
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. |
**Error codes**
......@@ -129,7 +129,7 @@ Sets the default slot of the SIM card used for mobile data. This API uses a prom
**System API**: This is a system API.
**Required permission**: ohos.permission.SET_TELEPHONY_STATE
**Required permissions**: ohos.permission.SET_TELEPHONY_STATE
**System capability**: SystemCapability.Telephony.CellularData
......@@ -137,7 +137,7 @@ Sets the default slot of the SIM card used for mobile data. This API uses a prom
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| slotId | number | Yes | SIM card slot ID. <br>**0**: card slot 1<br>**1**: card slot 2<br>**-1**: Clears the default configuration.|
| slotId | number | Yes | SIM card slot ID. <br>**0**: card slot 1.<br>**1**: card slot 2.<br>**-1**: Clears the default configuration.|
**Return value**
......@@ -356,7 +356,7 @@ Checks whether roaming is enabled for the cellular data service. This API uses a
| Name | Type | Mandatory| Description |
| -------- | ------------------------ | ---- | ------------------------------------------------------------ |
| slotId | number | Yes | Card slot ID.<br>**0**: card slot 1<br>**1**: card slot 2 |
| slotId | number | Yes | Card slot ID.<br>**0**: card slot 1.<br>**1**: card slot 2. |
| callback | AsyncCallback\<boolean\> | Yes | Callback used to return the result.<br>**true**: Roaming is enabled for the cellular data service.<br>**false**: Roaming is disabled for the cellular data service.|
**Error codes**
......@@ -394,7 +394,7 @@ Checks whether roaming is enabled for the cellular data service. This API uses a
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ---------------------------------------- |
| slotId | number | Yes | Card slot ID.<br>**0**: card slot 1<br>**1**: card slot 2|
| slotId | number | Yes | Card slot ID.<br>**0**: card slot 1.<br>**1**: card slot 2.|
**Return value**
......@@ -434,7 +434,7 @@ Enables the cellular data service. This API uses an asynchronous callback to ret
**System API**: This is a system API.
**Required permission**: ohos.permission.SET_TELEPHONY_STATE
**Required permissions**: ohos.permission.SET_TELEPHONY_STATE
**System capability**: SystemCapability.Telephony.CellularData
......@@ -473,7 +473,7 @@ Enables the cellular data service. This API uses a promise to return the result.
**System API**: This is a system API.
**Required permission**: ohos.permission.SET_TELEPHONY_STATE
**Required permissions**: ohos.permission.SET_TELEPHONY_STATE
**System capability**: SystemCapability.Telephony.CellularData
......@@ -515,7 +515,7 @@ Disables the cellular data service. This API uses an asynchronous callback to re
**System API**: This is a system API.
**Required permission**: ohos.permission.SET_TELEPHONY_STATE
**Required permissions**: ohos.permission.SET_TELEPHONY_STATE
**System capability**: SystemCapability.Telephony.CellularData
......@@ -554,7 +554,7 @@ Disables the cellular data service. This API uses a promise to return the result
**System API**: This is a system API.
**Required permission**: ohos.permission.SET_TELEPHONY_STATE
**Required permissions**: ohos.permission.SET_TELEPHONY_STATE
**System capability**: SystemCapability.Telephony.CellularData
......@@ -596,7 +596,7 @@ Enables the cellular data roaming service. This API uses an asynchronous callbac
**System API**: This is a system API.
**Required permission**: ohos.permission.SET_TELEPHONY_STATE
**Required permissions**: ohos.permission.SET_TELEPHONY_STATE
**System capability**: SystemCapability.Telephony.CellularData
......@@ -604,7 +604,7 @@ Enables the cellular data roaming service. This API uses an asynchronous callbac
| Name | Type | Mandatory| Description |
| -------- | --------------------- | ---- | ---------------------------------------- |
| slotId | number | Yes | Card slot ID.<br>**0**: card slot 1<br>**1**: card slot 2|
| slotId | number | Yes | Card slot ID.<br>**0**: card slot 1.<br>**1**: card slot 2.|
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. |
**Error codes**
......@@ -636,7 +636,7 @@ Enables the cellular data roaming service. This API uses a promise to return the
**System API**: This is a system API.
**Required permission**: ohos.permission.SET_TELEPHONY_STATE
**Required permissions**: ohos.permission.SET_TELEPHONY_STATE
**System capability**: SystemCapability.Telephony.CellularData
......@@ -644,7 +644,7 @@ Enables the cellular data roaming service. This API uses a promise to return the
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ---------------------------------------- |
| slotId | number | Yes | Card slot ID.<br>**0**: card slot 1<br>**1**: card slot 2|
| slotId | number | Yes | Card slot ID.<br>**0**: card slot 1.<br>**1**: card slot 2.|
**Return value**
......@@ -684,7 +684,7 @@ Disables the cellular data roaming service. This API uses an asynchronous callba
**System API**: This is a system API.
**Required permission**: ohos.permission.SET_TELEPHONY_STATE
**Required permissions**: ohos.permission.SET_TELEPHONY_STATE
**System capability**: SystemCapability.Telephony.CellularData
......@@ -692,7 +692,7 @@ Disables the cellular data roaming service. This API uses an asynchronous callba
| Name | Type | Mandatory| Description |
| -------- | --------------------- | ---- | ---------------------------------------- |
| slotId | number | Yes | Card slot ID.<br>**0**: card slot 1<br>**1**: card slot 2|
| slotId | number | Yes | Card slot ID.<br>**0**: card slot 1.<br>**1**: card slot 2.|
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. |
**Error codes**
......@@ -724,7 +724,7 @@ Disables the cellular data roaming service. This API uses a promise to return th
**System API**: This is a system API.
**Required permission**: ohos.permission.SET_TELEPHONY_STATE
**Required permissions**: ohos.permission.SET_TELEPHONY_STATE
**System capability**: SystemCapability.Telephony.CellularData
......@@ -732,7 +732,7 @@ Disables the cellular data roaming service. This API uses a promise to return th
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ---------------------------------------- |
| slotId | number | Yes | Card slot ID.<br>**0**: card slot 1<br>**1**: card slot 2|
| slotId | number | Yes | Card slot ID.<br>**0**: card slot 1.<br>**1**: card slot 2.|
**Return value**
......
......@@ -56,6 +56,7 @@
- [Ethernet Connection Error Codes](errorcode-net-ethernet.md)
- [Network Sharing Error Codes](errorcode-net-sharing.md)
- [Policy Management Error Codes](errorcode-net-policy.md)
- [mDNS Error Codes](errorcode-net-mdns.md)
- Connectivity
- [Bluetooth Error Codes](errorcode-bluetoothManager.md)
- [Wi-Fi Error Codes](errorcode-wifi.md)
......
# mDNS Error Codes
> **NOTE**
>
> This topic describes only module-specific error codes. For details about universal error codes, see [Universal Error Codes](errorcode-universal.md).
## 2100002 Service Connection Failure
**Error Message**
Operation failed. Cannot connect to service.
**Description**
This error code is reported if a service connection failure occurs.
**Possible Causes**
The service is abnormal.
**Procedure**
Check whether system services are running properly.
## 2100003 System Internal Error
**Error Message**
System internal error.
**Description**
This error code is reported if a system internal error occurs.
**Possible Causes**
1. The memory is abnormal.
2. A null pointer is present.
**Procedure**
1. Check whether the memory space is sufficient. If not, clear the memory and try again.
2. Check whether the system is normal. If not, try again later or restart the device.
## 2204003 Repeated Registration
**Error Message**
Callback duplicated.
**Description**
The callback already exists.
**Possible Causes**
An mDNS service with the same name and type is repeatedly registered.
**Procedure**
Check whether the mDNS service to be registered already exists.
## 2204008 Service Deletion Failure
**Error Message**
Service instance duplicated.
**Description**
The service to be removed does not exist.
**Possible Causes**
The service has been deleted.
**Procedure**
Check whether the mDNS service to be deleted exists.
## 2204010 Message Sending Failure
**Error Message**
Send packet failed.
**Description**
Messages fail to be sent through an mDNS service.
**Possible Causes**
The mDNS service does not exist on the LAN.
**Procedure**
Check whether the target mDNS service exists on the LAN.
## 2204006 Service Resolution Timeout
**Error Message**
Request timeout.
**Description**
mDNS services of the specified type fail to be resolved.
**Possible Causes**
mDNS services of the specified type do not exist on the LAN.
**Procedure**
Check whether mDNS services of the specified type exist on the LAN.
......@@ -90,14 +90,13 @@
- [HiTraceChain Development](subsys-dfx-hitracechain.md)
- [HiTraceMeter Development](subsys-dfx-hitracemeter.md)
- [HiCollie Development](subsys-dfx-hicollie.md)
- HiSysEvent Development
- HiSysEvent
- [HiSysEvent Overview](subsys-dfx-hisysevent-overview.md)
- [HiSysEvent Logging Configuration](subsys-dfx-hisysevent-logging-config.md)
- [HiSysEvent Logging](subsys-dfx-hisysevent-logging.md)
- [HiSysEvent Listening](subsys-dfx-hisysevent-listening.md)
- [HiSysEvent Query](subsys-dfx-hisysevent-query.md)
- [HiSysEvent Tool Usage](subsys-dfx-hisysevent-tool.md)
- [HiDumper Development](subsys-dfx-hidumper.md)
- [HiChecker Development](subsys-dfx-hichecker.md)
- [FaultLogger Development](subsys-dfx-faultlogger.md)
- [Hiview Development](subsys-dfx-hiview.md)
......@@ -105,6 +104,7 @@
- [bytrace](subsys-toolchain-bytrace-guide.md)
- [hdc](subsys-toolchain-hdc-guide.md)
- [hiperf](subsys-toolchain-hiperf.md)
- [HiDumper](subsys-dfx-hidumper.md)
- Power Management
- Display Management
- [System Brightness Customization](subsys-power-brightness-customization.md)
# NNRt Development
## Overview
### Function Introduction
Neural Network Runtime (NNRt) functions as a bridge to connect the upper-layer AI inference framework and bottom-layer acceleration chips, implementing cross-chip inference computing of AI models.
With the open APIs provided by NNRt, chip vendors can connect their dedicated acceleration chips to NNRt to access the OpenHarmony ecosystem.
### Basic Concepts
Before you get started, it would be helpful for you to have a basic understanding of the following concepts:
- Hardware Device Interface (HDI): defines APIs for cross-process communication between services in OpenHarmony.
- Interface Description Language (IDL): defines the HDI language format.
### Constraints
- System version: OpenHarmony trunk version.
- Development environment: Ubuntu 18.04 or later.
- Access device: a chip with AI computing capabilities.
### Working Principles
NNRt connects to device chips through HDIs, which implement cross-process communication between services.
**Figure 1** NNRt architecture
![NNRt architecture](./figures/nnrt_arch_diagram.png)
The NNRt architecture consists of three layers: AI applications at the application layer, AI inference framework and NNRt at the system layer, and device services at the chip layer. To use a dedicated acceleration chip model for inference, an AI application needs to call the dedicated acceleration chip at the bottom layer through the AI inference framework and NNRt. NNRt is responsible for adapting to various dedicated acceleration chips at the bottom layer. It opens standard and unified HDIs for various chips to access the OpenHarmony ecosystem.
During program running, the AI application, AI inference framework, and NNRt reside in the user process, and the underlying device services reside in the service process. NNRt implements the HDI client and the service side implements HDI Service to fulfill cross-process communication.
## How to Develop
### Application Scenario
Suppose you are connecting an AI acceleration chip, for example, RK3568, to NNRt. The following describes how to connect the RK3568 chip to NNRt through the HDI to implement AI model inference.
> **NOTE**<br>In this application scenario, the connection of the RK3568 chip to NNRt is implemented by utilizing the CPU operator of MindSpore Lite, instead of writing the CPU driver. This is the reason why the following development procedure depends on the dynamic library and header file of MindSpore Lite. In practice, the development does not depend on any library or header file of MindSpore Lite.
### Development Flowchart
The following figure shows the process of connecting a dedicated acceleration chip to NNRt.
**Figure 2** NNRt development flowchart
![NNRt development flowchart](./figures/nnrt_dev_flow.png)
### Development Procedure
To connect the acceleration chip to NNRt, perform the development procedure below.
#### Generating the HDI Header File
Download the OpenHarmony source code from the open source community, build the `drivers_interface` component, and generate the HDI header file.
1. [Download the source code](../get-code/sourcecode-acquire.md).
2. Build the IDL file of the HDI.
```shell
./build.sh --product-name productname –ccache --build-target drivers_interface_nnrt
```
> **NOTE**<br>**productname** indicates the product name. In this example, the product name is **RK3568**.
When the build is complete, the HDI header file is generated in `out/rk3568/gen/drivers/interface/nnrt`. The default programming language is C++. To generate a header file for the C programming language, run the following command to set the `language` field in the `drivers/interface/nnrt/v1_0/BUILD.gn` file before starting the build:
```shell
language = "c"
```
The directory of the generated header file is as follows:
```text
out/rk3568/gen/drivers/interface/nnrt
└── v1_0
├── drivers_interface_nnrt__libnnrt_proxy_1.0_external_deps_temp.json
├── drivers_interface_nnrt__libnnrt_stub_1.0_external_deps_temp.json
├── innrt_device.h # Header file of the HDI
├── iprepared_model.h # Header file of the AI model
├── libnnrt_proxy_1.0__notice.d
├── libnnrt_stub_1.0__notice.d
├── model_types.cpp # Implementation file for AI model structure definition
├── model_types.h # Header file for AI model structure definition
├── nnrt_device_driver.cpp # Device driver implementation example
├── nnrt_device_proxy.cpp
├── nnrt_device_proxy.h
├── nnrt_device_service.cpp # Implementation file for device services
├── nnrt_device_service.h # Header file for device services
├── nnrt_device_stub.cpp
├── nnrt_device_stub.h
├── nnrt_types.cpp # Implementation file for data type definition
├── nnrt_types.h # Header file for data type definition
├── node_attr_types.cpp # Implementation file for AI model operator attribute definition
├── node_attr_types.h # Header file for AI model operator attribute definition
├── prepared_model_proxy.cpp
├── prepared_model_proxy.h
├── prepared_model_service.cpp # Implementation file for AI model services
├── prepared_model_service.h # Header file for AI model services
├── prepared_model_stub.cpp
└── prepared_model_stub.h
```
#### Implementing the HDI Service
1. Create a development directory in `drivers/peripheral`. The structure of the development directory is as follows:
```text
drivers/peripheral/nnrt
├── BUILD.gn # Code build script
├── bundle.json
└── hdi_cpu_service # Customized directory
├── BUILD.gn # Code build script
├── include
│ ├── nnrt_device_service.h # Header file for device services
│ ├── node_functions.h # Optional, depending on the actual implementation
│ ├── node_registry.h # Optional, depending on the actual implementation
│ └── prepared_model_service.h # Header file for AI model services
└── src
├── nnrt_device_driver.cpp # Implementation file for the device driver
├── nnrt_device_service.cpp # Implementation file for device services
├── nnrt_device_stub.cpp # Optional, depending on the actual implementation
├── node_attr_types.cpp # Optional, depending on the actual implementation
├── node_functions.cpp # Optional, depending on the actual implementation
├── node_registry.cpp # Optional, depending on the actual implementation
└── prepared_model_service.cpp # Implementation file for AI model services
```
2. Implement the device driver. Unless otherwise required, you can directly use the `nnrt_device_driver.cpp` file generated in step 1.
3. Implement service APIs. For details, see the `nnrt_device_service.cpp` and `prepared_model_service.cpp` implementation files. For details about the API definition, see [NNRt HDI Definitions](https://gitee.com/openharmony/drivers_interface/tree/master/nnrt).
4. Build the implementation files for device drivers and services as shared libraries.
Create the `BUILD.gn` file with the following content in `drivers/peripheral/nnrt/hdi_cpu_service/`. For details about how to set related parameters, see [Compilation and Building](https://gitee.com/openharmony/build).
```shell
import("//build/ohos.gni")
import("//drivers/hdf_core/adapter/uhdf2/uhdf.gni")
ohos_shared_library("libnnrt_service_1.0") {
include_dirs = []
sources = [
"src/nnrt_device_service.cpp",
"src/prepared_model_service.cpp",
"src/node_registry.cpp",
"src/node_functions.cpp",
"src/node_attr_types.cpp"
]
public_deps = [ "//drivers/interface/nnrt/v1_0:nnrt_idl_headers" ]
external_deps = [
"hdf_core:libhdf_utils",
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_single",
"c_utils:utils",
]
install_images = [ chipset_base_dir ]
subsystem_name = "hdf"
part_name = "drivers_peripheral_nnrt"
}
ohos_shared_library("libnnrt_driver") {
include_dirs = []
sources = [ "src/nnr_device_driver.cpp" ]
deps = [ "//drivers/peripheral/nnrt/hdi_cpu_service:libnnrt_service_1.0" ]
external_deps = [
"hdf_core:libhdf_host",
"hdf_core:libhdf_ipc_adapter",
"hdf_core:libhdf_utils",
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_single",
"c_utils:utils",
]
install_images = [ chipset_base_dir ]
subsystem_name = "hdf"
part_name = "drivers_peripheral_nnrt"
}
group("hdf_nnrt_service") {
deps = [
":libnnrt_driver",
":libnnrt_service_1.0",
]
}
```
Add `group("hdf_nnrt_service")` to the `drivers/peripheral/nnrt/BUILD.gn` file so that it can be referenced at a higher directory level.
```shell
if (defined(ohos_lite)) {
group("nnrt_entry") {
deps = [ ]
}
} else {
group("nnrt_entry") {
deps = [
"./hdi_cpu_service:hdf_nnrt_service",
]
}
}
```
Create the `drivers/peripheral/nnrt/bundle.json` file to define the new `drivers_peripheral_nnrt` component.
```json
{
"name": "drivers_peripheral_nnrt",
"description": "Neural network runtime device driver",
"version": "3.2",
"license": "Apache License 2.0",
"component": {
"name": "drivers_peripheral_nnrt",
"subsystem": "hdf",
"syscap": [""],
"adapter_system_type": ["standard"],
"rom": "1024KB",
"ram": "2048KB",
"deps": {
"components": [
"ipc",
"hdf_core",
"hiviewdfx_hilog_native",
"c_utils"
],
"third_part": [
"bounds_checking_function"
]
},
"build": {
"sub_component": [
"//drivers/peripheral/nnrt:nnrt_entry"
],
"test": [
],
"inner_kits": [
]
}
}
}
```
#### Declaring the HDI Service
In the uhdf directory, declare the user-mode driver and services in the **.hcs** file of the corresponding product. For example, for the RK3568 chip, add the following configuration to the `vendor/hihope/rk3568/hdf_config/uhdf/device_info.hcs` file:
```text
nnrt :: host {
hostName = "nnrt_host";
priority = 50;
uid = "";
gid = "";
caps = ["DAC_OVERRIDE", "DAC_READ_SEARCH"];
nnrt_device :: device {
device0 :: deviceNode {
policy = 2;
priority = 100;
moduleName = "libnnrt_driver.z.so";
serviceName = "nnrt_device_service";
}
}
}
```
> **NOTE**<BR>After modifying the `.hcs` file, you need to delete the `out` directory and build the file again for the modification to take effect.
#### Configuring the User ID and Group ID of the Host Process
In the scenario of creating an nnrt_host process, you need to configure the user ID and group ID of the corresponding process. The user ID is configured in the `base/startup/init/services/etc/passwd` file, and the group ID is configured in the `base/startup/init/services/etc/group` file.
```text
# Add the user ID in base/startup/init/services/etc/passwd.
nnrt_host:x:3311:3311:::/bin/false
# Add the group ID in base/startup/init/services/etc/group.
nnrt_host:x:3311:
```
#### Configuring SELinux
The SELinux feature has been enabled for the OpenHarmony. You need to configure SELinux rules for the new processes and services so that they can run the host process to access certain resources and release HDI services.
1. Configure the security context of the **nnrt_host** process in the `base/security/selinux/sepolicy/ohos_policy/drivers/adapter/vendor/type.te` file.
```text
# Add the security context configuration.
type nnrt_host, hdfdomain, domain;
```
> **NOTE**<br>In the preceding command, **nnrt_host** indicates the process name previously configured.
2. Configure access permissions because SELinux uses the trustlist access permission mechanism. Upon service startup, run the `dmesg` command to view the AVC alarm,
which provides a list of missing permissions. For details about the SELinux configuration, see [security_selinux] (https://gitee.com/openharmony/security_selinux/blob/master/README-en.md).
```shell
hdc_std shell
dmesg | grep nnrt
```
3. Create the `nnrt_host.te` file.
```shell
# Create the nnrt folder.
mkdir base/security/selinux/sepolicy/ohos_policy/drivers/peripheral/nnrt
# Create the vendor folder.
mkdir base/security/selinux/sepolicy/ohos_policy/drivers/peripheral/nnrt/vendor
# Create the nnrt_host.te file.
touch base/security/selinux/sepolicy/ohos_policy/drivers/peripheral/nnrt/vendor/nnrt_host.te
```
4. Add the required permissions to the `nnrt_host.te` file. For example:
```text
allow nnrt_host dev_hdf_kevent:chr_file { ioctl };
allow nnrt_host hilog_param:file { read };
allow nnrt_host sh:binder { transfer };
allow nnrt_host dev_ashmem_file:chr_file { open };
allow sh nnrt_host:fd { use };
```
#### Configuring the Component Build Entry
Access the `chipset_common.json` file.
```shell
vim //productdefine/common/inherit/chipset_common.json
```
Add the following to `"subsystems"`, `"subsystem":"hdf"`, `"components"`:
```shell
{
"component": "drivers_peripheral_foo",
"features": []
}
```
#### Deleting the out Directory and Building the Entire System
```shell
# Delete the out directory.
rm -rf ./out
# Build the entire system.
./build.sh --product-name rk3568 –ccache --jobs=4
```
### Commissioning and Verification
On completion of service development, you can use XTS to verify its basic functions and compatibility.
1. Build the **hats** test cases of NNRt in the `test/xts/hats/hdf/nnrt` directory.
```shell
# Go to the hats directory.
cd test/xts/hats
# Build the hats test cases.
./build.sh suite=hats system_size=standard --product-name rk3568
# Return to the root directory.
cd -
```
The hats test cases are exported to `out/rk3568/suites/hats/testcases/HatsHdfNnrtFunctionTest` in the relative code root directory.
2. Push the test cases to the device.
```shell
# Push the executable file of test cases to the device. In this example, the executable file is HatsHdfNnrtFunctionTest.
hdc_std file send out/rk3568/suites/hats/testcases/HartsHdfNnrtFunctionTest /data/local/tmp/
# Grant required permissions to the executable file of test cases.
hdc_std shell "chmod +x /data/local/tmp/HatsHdfNnrtFunctionTest"
```
3. Execute the test cases and view the result.
```shell
# Execute the test cases.
hdc_std shell "/data/local/tmp/HatsHdfNnrtFunctionTest"
```
The test report below shows that all 47 test cases are successful, indicating that the service has passed the compatibility test.
```text
...
[----------] Global test environment tear-down
Gtest xml output finished
[==========] 47 tests from 3 test suites ran. (515 ms total)
[ PASSED ] 47 tests.
```
### Development Example
For the complete demo code, see [NNRt Service Implementation Example](https://gitee.com/openharmony/ai_neural_network_runtime/tree/master/example/drivers).
1. Copy the `example/driver/nnrt` directory to `drivers/peripheral`.
```shell
cp -r example/driver/nnrt drivers/peripheral
```
2. Add the `bundle.json` file to `drivers/peripheral/nnrt`. For details about the `bundle.json` file, see [Development Procedure](#development-procedure).
3. Add the dependency files of MindSpore Lite because the demo depends on the CPU operator of MindSpore Lite.
- Download the header file of [MindSpore Lite 1.5.0](https://ms-release.obs.cn-north-4.myhuaweicloud.com/1.5.0/MindSpore/lite/release/linux/mindspore-lite-1.5.0-linux-x64.tar.gz).
1. Create the `mindspore` directory in `drivers/peripheral/nnrt`.
```shell
mkdir drivers/peripheral/nnrt/mindspore
```
2. Decompress the `mindspore-lite-1.5.0-linux-x64.tar.gz` file, and copy the `runtime/include` directory to `drivers/peripheral/nnrt/mindspore`.
3. Create and copy the `schema` file of MindSpore Lite.
```shell
# Create the mindspore_schema directory.
mkdir drivers/peripheral/nnrt/hdi_cpu_service/include/mindspore_schema
# Copy the schema file of MindSpore Lite.
cp third_party/mindspore/mindspore/lite/schema/* drivers/peripheral/nnrt/hdi_cpu_service/include/mindspore_schema/
```
4. Build the dynamic library of MindSpore Lite, and put the dynamic library in the `mindspore`directory.
```shell
# Build the dynamic library of MindSpore Lite.
./build.sh --product-name rk3568 -ccaache --jobs 4 --build-target mindspore_lib
# Create the mindspore subdirectory.
mkdir drivers/peripheral/nnrt/mindspore/mindspore
# Copy the dynamic library to drivers/peripheral/nnrt/mindspore/mindspore.
cp out/rk3568/package/phone/system/lib/libmindspore-lite.huawei.so drivers/peripheral/nnrt/mindspore/mindspore/
```
4. Follow the [development procedure](#development-procedure) to complete other configurations.
# HiCollie Development<a name="EN-US_TOPIC_0000001231255509"></a>
# HiCollie Development
## Overview<a name="section3432134085116"></a>
HiCollie provides the software watchdog function. It provides a unified framework for fault detection and fault log generation to help you locate software timeout faults resulting from system service deadlock, application main thread blocking, and service process timeout.
## Available APIs<a name="section139261151145116"></a>
**Table 1** Description of C++ APIs
<a name="table19452225011"></a>
<table><thead align="left"><tr id="row1517803543518"><th class="cellrowborder" valign="top" width="19.698030196980305%" id="mcps1.2.4.1.1"><p id="p484763319529"><a name="p484763319529"></a><a name="p484763319529"></a>Class</p>
</th>
<th class="cellrowborder" valign="top" width="35.82641735826417%" id="mcps1.2.4.1.2"><p id="p1684719339523"><a name="p1684719339523"></a><a name="p1684719339523"></a>API</p>
</th>
<th class="cellrowborder" valign="top" width="44.47555244475552%" id="mcps1.2.4.1.3"><p id="p284773315220"><a name="p284773315220"></a><a name="p284773315220"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row1361184632117"><td class="cellrowborder" valign="top" width="19.698030196980305%" headers="mcps1.2.4.1.1 "><p id="p6700155032113"><a name="p6700155032113"></a><a name="p6700155032113"></a>XCollieChecker</p>
</td>
<td class="cellrowborder" valign="top" width="35.82641735826417%" headers="mcps1.2.4.1.2 "><p id="p18699115019217"><a name="p18699115019217"></a><a name="p18699115019217"></a>virtual void CheckBlock()</p>
</td>
<td class="cellrowborder" valign="top" width="44.47555244475552%" headers="mcps1.2.4.1.3 "><p id="p18700175062115"><a name="p18700175062115"></a><a name="p18700175062115"></a>Provides the callback of the suspension detection result.</p>
<p id="p13700125012216"><a name="p13700125012216"></a><a name="p13700125012216"></a>Input arguments: none</p>
<p id="p13700650162114"><a name="p13700650162114"></a><a name="p13700650162114"></a>Output arguments: none</p>
<p id="p3700850192115"><a name="p3700850192115"></a><a name="p3700850192115"></a>Return value: none</p>
</td>
</tr>
<tr id="row8945182185017"><td class="cellrowborder" valign="top" width="19.698030196980305%" headers="mcps1.2.4.1.1 "><p id="p79451227506"><a name="p79451227506"></a><a name="p79451227506"></a>XCollieChecker</p>
</td>
<td class="cellrowborder" valign="top" width="35.82641735826417%" headers="mcps1.2.4.1.2 "><p id="p647534064612"><a name="p647534064612"></a><a name="p647534064612"></a>virtual void CheckThreadBlock()</p>
</td>
<td class="cellrowborder" valign="top" width="44.47555244475552%" headers="mcps1.2.4.1.3 "><p id="p127630177475"><a name="p127630177475"></a><a name="p127630177475"></a>Provides the callback of the thread suspension detection result.</p>
<p id="p18763111794719"><a name="p18763111794719"></a><a name="p18763111794719"></a>Input arguments: none</p>
<p id="p87631176478"><a name="p87631176478"></a><a name="p87631176478"></a>Output arguments: none</p>
<p id="p3764111718473"><a name="p3764111718473"></a><a name="p3764111718473"></a>Return value: none</p>
</td>
</tr>
<tr id="row149924222486"><td class="cellrowborder" valign="top" width="19.698030196980305%" headers="mcps1.2.4.1.1 "><p id="p11643173114810"><a name="p11643173114810"></a><a name="p11643173114810"></a>XCollie</p>
</td>
<td class="cellrowborder" valign="top" width="35.82641735826417%" headers="mcps1.2.4.1.2 "><p id="p16289114074812"><a name="p16289114074812"></a><a name="p16289114074812"></a>void RegisterXCollieChecker(const sptr&lt;XCollieChecker&gt; &amp;checker, unsigned int type)</p>
</td>
<td class="cellrowborder" valign="top" width="44.47555244475552%" headers="mcps1.2.4.1.3 "><p id="p186437319482"><a name="p186437319482"></a><a name="p186437319482"></a>Registers the callback of the thread suspension detection result.</p>
<p id="p112011591133"><a name="p112011591133"></a><a name="p112011591133"></a>Input arguments:</p>
<a name="ul7783192181413"></a><a name="ul7783192181413"></a><ul id="ul7783192181413"><li><strong id="b64637561712"><a name="b64637561712"></a><a name="b64637561712"></a>checker</strong>: Indicates the pointer to the XCollieChecker instance.</li><li><strong id="b1947711661711"><a name="b1947711661711"></a><a name="b1947711661711"></a>type</strong>: Indicates the suspension detection type. Set it to <strong id="b259214119717"><a name="b259214119717"></a><a name="b259214119717"></a>XCOLLIE_THREAD</strong>.</li></ul>
<p id="p166439314482"><a name="p166439314482"></a><a name="p166439314482"></a>Output arguments: none</p>
<p id="p564393112485"><a name="p564393112485"></a><a name="p564393112485"></a>Return value: none</p>
</td>
</tr>
<tr id="row594519275012"><td class="cellrowborder" valign="top" width="19.698030196980305%" headers="mcps1.2.4.1.1 "><p id="p294512211505"><a name="p294512211505"></a><a name="p294512211505"></a>XCollie</p>
</td>
<td class="cellrowborder" valign="top" width="35.82641735826417%" headers="mcps1.2.4.1.2 "><p id="p81561310145215"><a name="p81561310145215"></a><a name="p81561310145215"></a>int SetTimer(const std::string &amp;name, unsigned int timeout, std::function&lt;void (void *)&gt; func, void *arg, unsigned int flag)</p>
</td>
<td class="cellrowborder" valign="top" width="44.47555244475552%" headers="mcps1.2.4.1.3 "><p id="p174279246538"><a name="p174279246538"></a><a name="p174279246538"></a>Adds timers.</p>
<p id="p1998141221410"><a name="p1998141221410"></a><a name="p1998141221410"></a>Input arguments:</p>
<a name="ul845512153147"></a><a name="ul845512153147"></a><ul id="ul845512153147"><li><strong id="b44651010141715"><a name="b44651010141715"></a><a name="b44651010141715"></a>name</strong>: Indicates the timer name.</li><li><strong id="b266981221717"><a name="b266981221717"></a><a name="b266981221717"></a>timeout</strong>: Indicates the timeout duration, in seconds.</li><li><strong id="b17158171421710"><a name="b17158171421710"></a><a name="b17158171421710"></a>func</strong>: Indicates the timeout callback.</li><li><strong id="b1950162581810"><a name="b1950162581810"></a><a name="b1950162581810"></a>arg</strong>: Indicates the pointer to the timeout callback.</li><li><strong id="b4949151521714"><a name="b4949151521714"></a><a name="b4949151521714"></a>flag</strong>: Indicates the timer operation type.<p id="p1242762435310"><a name="p1242762435310"></a><a name="p1242762435310"></a>XCOLLIE_FLAG_DEFAULT // Indicates the default flag, which is the combination of the other three options.</p>
<p id="p1542712435312"><a name="p1542712435312"></a><a name="p1542712435312"></a>XCOLLIE_FLAG_NOOP // Calls only the timeout callback.</p>
<p id="p15427112416531"><a name="p15427112416531"></a><a name="p15427112416531"></a>XCOLLIE_FLAG_LOG // Generates a timeout fault log.</p>
<p id="p242762455314"><a name="p242762455314"></a><a name="p242762455314"></a>XCOLLIE_FLAG_RECOVERY // Exits the process.</p>
</li></ul>
<p id="p15427102445311"><a name="p15427102445311"></a><a name="p15427102445311"></a>Output arguments: none</p>
<p id="p144271424155316"><a name="p144271424155316"></a><a name="p144271424155316"></a>Return value: Returns the timer ID if the operation is successful; returns <strong id="b2229713291"><a name="b2229713291"></a><a name="b2229713291"></a>-1</strong> otherwise.</p>
</td>
</tr>
<tr id="row1294692165010"><td class="cellrowborder" valign="top" width="19.698030196980305%" headers="mcps1.2.4.1.1 "><p id="p19461929506"><a name="p19461929506"></a><a name="p19461929506"></a>XCollie</p>
</td>
<td class="cellrowborder" valign="top" width="35.82641735826417%" headers="mcps1.2.4.1.2 "><p id="p119467215012"><a name="p119467215012"></a><a name="p119467215012"></a>bool UpdateTimer(int id, unsigned int timeout)</p>
</td>
<td class="cellrowborder" valign="top" width="44.47555244475552%" headers="mcps1.2.4.1.3 "><p id="p3831253185713"><a name="p3831253185713"></a><a name="p3831253185713"></a>Updates timers.</p>
<p id="p10649172815148"><a name="p10649172815148"></a><a name="p10649172815148"></a>Input arguments:</p>
<a name="ul1628783221411"></a><a name="ul1628783221411"></a><ul id="ul1628783221411"><li><strong id="b61651021161710"><a name="b61651021161710"></a><a name="b61651021161710"></a>id</strong>: Indicates the timer ID.</li><li><strong id="b24661423141717"><a name="b24661423141717"></a><a name="b24661423141717"></a>timeout</strong>: Indicates the timeout duration, in seconds.</li></ul>
<p id="p11831115375719"><a name="p11831115375719"></a><a name="p11831115375719"></a>Output arguments: none</p>
<p id="p38311853105716"><a name="p38311853105716"></a><a name="p38311853105716"></a>Return value: Returns <strong id="b95701352192819"><a name="b95701352192819"></a><a name="b95701352192819"></a>true</strong> if the operation is successful; returns <strong id="b175761652152814"><a name="b175761652152814"></a><a name="b175761652152814"></a>false</strong> otherwise.</p>
</td>
</tr>
<tr id="row594682175013"><td class="cellrowborder" valign="top" width="19.698030196980305%" headers="mcps1.2.4.1.1 "><p id="p194614212504"><a name="p194614212504"></a><a name="p194614212504"></a>XCollie</p>
</td>
<td class="cellrowborder" valign="top" width="35.82641735826417%" headers="mcps1.2.4.1.2 "><p id="p1435552713588"><a name="p1435552713588"></a><a name="p1435552713588"></a>void CancelTimer(int id)</p>
</td>
<td class="cellrowborder" valign="top" width="44.47555244475552%" headers="mcps1.2.4.1.3 "><p id="p06791131580"><a name="p06791131580"></a><a name="p06791131580"></a>Cancels timers.</p>
<p id="p868013165815"><a name="p868013165815"></a><a name="p868013165815"></a>Input arguments:</p>
<p id="p9311488283"><a name="p9311488283"></a><a name="p9311488283"></a><strong id="b9666749171816"><a name="b9666749171816"></a><a name="b9666749171816"></a>id</strong>: Indicates the timer ID.</p>
<p id="p12680537587"><a name="p12680537587"></a><a name="p12680537587"></a>Output arguments: none</p>
<p id="p768015317586"><a name="p768015317586"></a><a name="p768015317586"></a>Return value: none</p>
</td>
</tr>
</tbody>
</table>
## Example<a name="section1589120102458"></a>
Print logs.
```
timeout: TimeoutTimer start at 1611040305 to check 1s ago
----------StacktraceCatcher CurrentTime:2021-01-19 15:11:45 Unexecuted(-1)(LogType:Stacktrace Pid:27689 Process:XCollieTimeoutModuleTest)----------
----- pid 27689 at 2021-01-19 15:11:45 -----
Cmd line: ./XCollieTimeoutModuleTest
ABI: 'arm64'
"XCollieTimeoutM" sysTid=27689
#01 pc 00000000000174cc /data/test/XCollieTimeoutModuleTest
```
## How to Develop<a name="section13905646534"></a>
### C++<a name="section9797199145316"></a>
### Thread Suspension Monitoring<a name="section1734221332"></a>
This function requires you to implement two callback functions: **CheckBlock** and **CheckThreadBlock** of the **XCollieChecker** class. After the callbacks are implemented, you need to use the **RegisterXCollieChecker** function of the **XCollie** class to register their instances. The suspension monitoring thread periodically executes all successfully registered callbacks, checks the thread logic completion flag, and determines whether the service logic of any registered thread is suspended.
1. Develop the source code.
Include the **xcollie** header file in the source file.
```
#include "xcollie.h"
```
Add the following code to the service code:
```
void MyXCollieChecker::CheckLock()
{
/* time consuming job */
}
void MyXCollieChecker::CheckThreadBlock()
{
/* time consuming job */
}
sptr<XCollieChecker> checker = new MyXCollieChecker("MyXCollieChecker");
XCollie::GetInstance().RegisterXCollieChecker(checker,
(XCOLLIE_LOCK | XCOLLIE_THREAD));
...
```
2. Configure compilation information. Specifically, add the subsystem SDK dependency to **BUILD.gn**.
```
external_deps = [ "hiviewdfx:libxcollie" ]
```
### Timeout Monitoring<a name="section2186947140"></a>
You can add a maximum of 128 timers for a single process by using the **SetTimer** function. Adding timers will fail if the number of timers has reached the upper limit.
1. Develop the source code.
Include the **xcollie** header file in the source file.
```
#include "xcollie.h"
```
Add the code to add, update, and cancel timers.
```
std::function<void(void *)> callback = [](void *args)
{
/* dump helpful information */
};
int id = XCollie::GetInstance().SetTimer("MyXCollieTimer", 10, callback ,nullptr, XCOLLIE_FLAG_LOG);
/* time consuming job */
XCollie::GetInstance().UpdateTimer(id, 5);
/* time consuming job */
XCollie::GetInstance().CancelTimer(id);
...
```
## Overview
2. Configure compilation information. Specifically, add the subsystem SDK dependency to **BUILD.gn**.
```
external_deps = [ "hiviewdfx:libxcollie" ]
```
HiCollie provides the software watchdog function. It provides a unified framework for fault detection and fault log generation to help you locate software timeout faults resulting from system service deadlock, application main thread blocking, and service process timeout.
## Available APIs
**Table 1** Description of XCollieChecker APIs
| API| Description|
| -------- | -------- |
| virtual void CheckBlock() | Provides the callback of the suspension detection result.<br>Input arguments: none<br>Output arguments: none<br>Return value: none|
| virtual void CheckThreadBlock() | Provides the callback of the thread suspension detection result.<br>Input arguments: none<br>Output arguments: none<br>Return value: none|
**Table 2** Description of XCollie APIs
| API| Description|
| -------- | -------- |
| void RegisterXCollieChecker(const sptr&lt;XCollieChecker&gt; &amp;checker, unsigned int type) | Registers the callback of the thread suspension detection result.<br>Input arguments:<br>- **checker**: pointer to the XCollieChecker instance.<br>- **type**: suspension detection type. Set it to **XCOLLIE_THREAD**.<br>Output arguments: none<br>Return value: none|
| int SetTimer(const std::string &amp;name, unsigned int timeout, std::function&lt;void(void*)&gt; func, void *arg, unsigned int flag) | Adds timers.<br>Input arguments:<br>- **name**: timer name.<br>- **timeout**: timeout duration, in seconds.<br>- **func**: timeout callback.<br>- **arg**: pointer to the timeout callback.<br>- **flag**: timer operation type.<br> - **XCOLLIE_FLAG_DEFAULT**: default flag, which is the combination of the other three options.<br> - **XCOLLIE_FLAG_NOOP**: Calls only the timeout callback.<br> - **XCOLLIE_FLAG_LOG**: Generates a timeout fault log.<br> - **XCOLLIE_FLAG_RECOVERY**: Exits the process.<br>Output arguments: none<br>Return value: timer ID if the operation is successful; **-1** otherwise.|
| bool UpdateTimer(int id, unsigned int timeout) | Updates timers.<br>Input arguments:<br>- **id**: timer ID.<br>- **timeout**: timeout duration, in seconds.<br>Output arguments: none<br>Return value: **true** if the operation is successful; **false** otherwise.|
| void CancelTimer(int id) | Cancels a timer.<br>Input arguments:<br>- **id**: timer ID.<br>Output arguments: none<br>Return value: none|
## How to Develop
### Thread Suspension Monitoring
This function requires you to implement two callback functions: **CheckBlock** and **CheckThreadBlock** of the **XCollieChecker** class. After the callbacks are implemented, you need to use the **RegisterXCollieChecker** function of the **XCollie** class to register their instances. The suspension monitoring thread periodically executes all successfully registered callbacks, checks the thread logic completion flag, and determines whether the service logic of any registered thread is suspended.
1. Develop the source code.
Include the **xcollie** header file in the source file.
```
#include "xcollie.h"
```
Add the following code to the service code:
```
void MyXCollieChecker::CheckLock()
{
/* time consuming job */
}
void MyXCollieChecker::CheckThreadBlock()
{
/* time consuming job */
}
sptr<XCollieChecker> checker = new MyXCollieChecker("MyXCollieChecker");
XCollie::GetInstance().RegisterXCollieChecker(checker,
(XCOLLIE_LOCK | XCOLLIE_THREAD));
......
```
2. Configure compilation information. Specifically, add the subsystem SDK dependency to **BUILD.gn**.
```
external_deps = [ "hiviewdfx:libxcollie" ]
```
### Timeout Monitoring
You can add a maximum of 128 timers for a single process by using the **SetTimer** function. Adding timers will fail if the number of timers has reached the upper limit.
1. Develop the source code.
Include the **xcollie** header file in the source file.
```
#include "xcollie.h"
```
Add the code to add, update, and cancel timers.
```
std::function<void(void *)> callback = [](void *args)
{
/* dump helpful information */
};
int id = XCollie::GetInstance().SetTimer("MyXCollieTimer", 10, callback ,nullptr, XCOLLIE_FLAG_LOG);
/* time consuming job */
XCollie::GetInstance().UpdateTimer(id, 5);
/* time consuming job */
XCollie::GetInstance().CancelTimer(id);
......
```
2. Configure compilation information. Specifically, add the subsystem SDK dependency to **BUILD.gn**.
```
external_deps = [ "hiviewdfx:libxcollie" ]
```
# HiDumper Development
# HiDumper
## Overview
### Introduction
HiDumper is a tool provided by OpenHarmony for developers, testers, and IDE tool engineers to obtain system information necessary for analyzing and locating faults. This section applies only to the standard system.
### Source Code Directories
## Source Code Directories
```
/base/hiviewdfx/hidumper
├── frameworks # Framework code
│ ├── native # Core function code
│ │ │── include # Header files
│ │ │── include # Header files
│ │ │── src # Source files
│ │ │── common # Common function code
│ │ │── executor # Process executor code
......@@ -34,14 +31,14 @@ HiDumper is a tool provided by OpenHarmony for developers, testers, and IDE tool
```
## Usage
# Usage
### Command-Line Options
## Command-Line Options
**Table 1** HiDumper command-line options
| Option| Description|
| Option| **Description**|
| -------- | -------- |
| -h | Shows the help Information.|
| -t&nbsp;[timeout] | Specifies the timeout period, in seconds. The default value is **30**. Value **0** indicates no timeout limit.|
......@@ -56,14 +53,14 @@ HiDumper is a tool provided by OpenHarmony for developers, testers, and IDE tool
| --net | Exports network information.|
| --storage | Exports storage information.|
| -p | Exports the process list and all process information.|
| -p&nbsp;[pid] | Exports all information about a specified process.|
| --cpuusage&nbsp;[pid] | Exports the CPU usage information based on **pid**.|
| -p&nbsp;[pid] | Exports all information about the specified process.|
| --cpuusage&nbsp;[pid] | Exports the CPU usage information. If **pid** is specified, the CPU usage of the corresponding process is exported.|
| --cpufreq | Exports the actual CPU frequency.|
| --mem&nbsp;[pid] | Exports the memory usage information based on **pid**.|
| --mem&nbsp;[pid] | Export memory usage information. If **pid** is specified, the memory usage of the corresponding process is exported.|
| --zip | Compresses the exported information to a specified folder.|
### Development Example
## Development Example
HiDumper helps you export basic system information to locate and analyze faults. Complex parameters passed to sub-services and abilities must be enclosed in double quotation marks.
......@@ -118,7 +115,7 @@ The procedure is as follows:
hidumper -s 3008
```
9. Run the **hidumper -e** command to obtain the crash information generated by the FaultLogger module.
9. Run the **hidumper -e** command to obtain the crash information generated by the FaultLoger module.
```
hidumper -e
......@@ -148,7 +145,7 @@ The procedure is as follows:
hidumper -p 1024
```
14. Run the **hidumper --cpuusage [pid]** command to obtain the CPU usage information of the process whose PID has been specified.
14. Run the **hidumper --cpuusage [pid]** command to obtain the CPU usage information. If the PID of a process is specified, only the CPU usage of the process is returned.
```
hidumper --cpuusage
......@@ -161,7 +158,7 @@ The procedure is as follows:
hidumper --cpufreq
```
16. Run the **hidumper --mem [pid]** command to obtain all memory usage information of the process whose PID has been specified.
16. Run the **hidumper --mem [pid]** command to obtain all memory usage information. If the PID of a process is specified, only the memory usage of the process is returned.
```
hidumper --mem [pid]
......
......@@ -146,9 +146,7 @@ Some built-in communication mechanisms (such as ZIDL) of OpenHarmony already sup
The following figure shows the process of transferring **traceid** in synchronous call. The process of transferring **traceid** in asynchronous call is similar.
Extended communication mechanisms can also follow this implementation.
**Figure 5** Call chain trace in synchronous communication
![](figures/call-chain-trace-in-synchronous-communication.png "call-chain-trace-in-synchronous-communication")
The process is as follows:
......
# HiTraceMeter
# HiTraceMeter Development
## Introduction
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册