未验证 提交 75cb2865 编写于 作者: O openharmony_ci 提交者: Gitee

!13775 翻译完成 12918+12864+13215+12858

Merge pull request !13775 from ester.zhou/TR-12918
# @ohos.events.emitter
# @ohos.events.emitter (Emitter)
The **Emitter** module provides APIs for sending and processing in-process events, including the APIs for processing events that are subscribed to in persistent or one-shot manner, unsubscribing from events, and emitting events to the event queue.
The **Emitter** module provides the capabilities of sending and processing inter- or intra-thread events in a process. You can use the APIs of this module to subscribe to an event in persistent or one-shot manner, unsubscribe from an event, or emit an event to the event queue.
> **NOTE**
>
> The initial APIs of this module are supported since API version 7.
> 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.
>
> The APIs of this module can be used in the FA model or stage model.
## Modules to Import
......@@ -20,16 +22,16 @@ None
on(event: [InnerEvent](#innerevent), callback: Callback\<[EventData](#eventdata)\>): void
Subscribes to an event in persistent manner. This API uses a callback to return the event.
Subscribes to an event in persistent manner and executes a callback after the event is received.
**System capability**: SystemCapability.Notification.Emitter
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------------------- | ---- | --------------------------------------- |
| event | [InnerEvent](#innerevent) | Yes | Event to subscribe to in persistent manner. The **EventPriority** settings do not take effect.|
| callback | Callback\<[EventData](#eventdata)\> | Yes | Callback used to return the event. |
| Name | Type | Mandatory| Description |
| -------- | ----------------------------------- | ---- | ------------------------------------------------------ |
| event | [InnerEvent](#innerevent) | Yes | Event to subscribe to in persistent manner. The [EventPriority](#eventpriority) settings do not take effect.|
| callback | Callback\<[EventData](#eventdata)\> | Yes | Callback to execute after the event is received. |
**Example**
......@@ -37,26 +39,28 @@ Subscribes to an event in persistent manner. This API uses a callback to return
let innerEvent = {
eventId: 1
};
function EmitterCallback(eventData) {
// Execute the callback after receiving the event whose eventId is 1.
function emitterCallback() {
console.info('callback');
}
emitter.on(innerEvent, EmitterCallback);
emitter.on(innerEvent, emitterCallback);
```
## emitter.once
once(event: [InnerEvent](#innerevent), callback: Callback\<[EventData](#eventdata)\>): void
Subscribes to an event in one-shot manner and unsubscribes from it after the event callback is received.
Subscribes to an event in one-shot manner and unsubscribes from it after the event callback is executed.
**System capability**: SystemCapability.Notification.Emitter
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------------------- | ---- | --------------------------------------- |
| event | [InnerEvent](#innerevent) | Yes | Event to subscribe to in one-shot manner. The **EventPriority** settings do not take effect.|
| callback | Callback\<[EventData](#eventdata)\> | Yes | Callback used to return the event. |
| Name | Type | Mandatory| Description |
| -------- | ----------------------------------- | ---- | ------------------------------------------------------------------------------ |
| event | [InnerEvent](#innerevent) | Yes | Event to subscribe to in one-shot manner. The [EventPriority](#eventpriority) settings do not take effect.|
| callback | Callback\<[EventData](#eventdata)\> | Yes | Callback to execute after the event is received. |
**Example**
......@@ -64,10 +68,12 @@ Subscribes to an event in one-shot manner and unsubscribes from it after the eve
let innerEvent = {
eventId: 1
};
function EmitterCallback(eventData) {
// Execute the callback after receiving the event whose eventId is 1.
function emitterCallback() {
console.info('once callback');
};
emitter.once(innerEvent, EmitterCallback);
emitter.once(innerEvent, emitterCallback);
```
## emitter.off
......@@ -92,17 +98,17 @@ emitter.off(1);
## emitter.emit
emit(event: InnerEvent, data?: EventData): void
emit(event: [InnerEvent](#innerevent), data?: [EventData](#eventdata)): void
Emits an event to the event queue.
Emits an event.
**System capability**: SystemCapability.Notification.Emitter
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------------------------- | ---- | -------------- |
| event | [InnerEvent](#innerevent) | Yes | Event to emit. |
| ------ | ------------------------- | ---- | ------------- |
| event | [InnerEvent](#innerevent) | Yes | Event to emit, where [EventPriority](#eventpriority) specifies the emit priority of the event.|
| data | [EventData](#eventdata) | No | Data carried by the event.|
**Example**
......@@ -112,11 +118,14 @@ let eventData = {
data: {
"content": "c",
"id": 1,
}};
}
};
let innerEvent = {
eventId: 1,
priority: emitter.EventPriority.HIGH
};
emitter.emit(innerEvent, eventData);
```
......@@ -126,23 +135,23 @@ Enumerates the event emit priority levels.
**System capability**: SystemCapability.Notification.Emitter
| Name | Value | Description |
| Name | Value | Description |
| --------- | ---- | --------------------------------------------------- |
| IMMEDIATE | 0 | The event will be emitted immediately. |
| HIGH | 1 | The event will be emitted before low-priority events. |
| LOW | 2 | The event will be emitted before idle-priority events. By default, an event is in LOW priority.|
| IDLE | 3 | The event will be emitted after all the other events. |
| IMMEDIATE | 0 | The event will be emitted immediately. |
| HIGH | 1 | The event will be emitted before low-priority events. |
| LOW | 2 | The event will be emitted before idle-priority events. By default, an event is in LOW priority. |
| IDLE | 3 | The event will be emitted after all the other events. |
## InnerEvent
Describes an in-process event.
Describes an event to subscribe to or emit. The **EventPriority** settings do not take effect under event subscription.
**System capability**: SystemCapability.Notification.Emitter
| Name | Type | Readable| Writable| Description |
| -------- | ------------------------------- | ---- | ---- | ---------------------------------- |
| Name | Type | Readable| Writable| Description |
| -------- | ------------------------------- | ---- | ---- | ------------------------------ |
| eventId | number | Yes | Yes | Event ID.|
| priority | [EventPriority](#eventpriority) | Yes | Yes | Emit priority of the event. |
| priority | [EventPriority](#eventpriority) | Yes | Yes | Emit priority of the event. |
## EventData
......
......@@ -3,125 +3,160 @@
## 1500001 Want Action Is Null
**Error Message**
Want action is null
**Description**
This error code is reported when the **Action** attribute in the **want** is null for the event to send.
This error code is reported when the **Action** attribute in the **want** object is null for the event to send.
**Possible Causes**
The **Action** attribute in the **want** is null for the event to send.
The **Action** attribute in the **want** object is null for the event to send.
**Solution**
Make sure the **Action** attribute in the **want** is not null.
Make sure the **Action** attribute in the **want** object is not null.
## 1500002 Failed to Send Common Events from a Sandbox Application
**Error Message**
sandbox application can not send common event
**Description**
This error code is reported when an attempt is made to send a common event from a sandbox application.
**Possible Causes**
Common events from a sandbox application are blocked.
**Solution**
Check whether the application used to send a common event is a sandbox application. If so, switch to another application.
## 1500003 Event Sending Frequency Is Too High
**Error Message**
common event send frequency too high
**Description**
This error code is reported when the application sends common events too frequently.
**Possible Causes**
The number of common events sent by the application in a given time frame has reached the maximum.
**Solution**
Do not send common events too frequently.
## 1500004 Failed to Send System Common Events
**Error Message**
not System services or System app
**Description**
This error code is reported when the application cannot send system common events.
**Possible Causes**
The application is not a system application or system service.
**Solution**
Make sure the application to send system common events is a system application or system service.
## 1500005 Subscriber Not Found
**Error Message**
subscriber can not found
**Description**
This error code is reported when the subscriber cannot be found.
**Possible Causes**
The subscriber is deleted.
**Solution**
Check whether the subscription has already been canceled. If the subscription has been canceled, the subscriber is deleted.
## 1500006 Invalid User ID
**Error Message**
usreId is invalid
userId is invalid
**Description**
This error code is reported when the user ID is invalid.
**Possible Causes**
The user ID is different from the system user ID, or the application is not a system application or subsystem process.
**Solution**
Check whether the current user ID is the same as the system user ID. If they are different, check whether the application is a system application or subsystem process
The user ID is different from the system user ID, or the application is not a system application or system service.
**Solution**
1. Make sure the current user ID is the same as the system user ID.
2. Make sure the application is a system application or system service.
## 1500007 Failed to Send a Request Through IPC
**Error Message**
message send error
**Description**
This error code is reported when the attempt to send a request through IPC fails.
**Possible Causes**
The connection object fails to be created.
**Solution**
Do not set up connections frequently. Try again later.
## 1500008 Failed to Read Data
**Error Message**
CEMS error
**Description**
This error code is reported when an error occurs on the server.
**Possible Causes**
A service exception occurs when the server processes data.
**Solution**
Try again later.
## 1500009 System Error
**Error Message**
system error
**Description**
This error code is reported when an exception occurs in the system during service processing, for example, when the current system time fails to be obtained.
**Possible Causes**
A system fault occurs.
**Solution**
Try again later.
Try again later.
\ No newline at end of file
......@@ -8,11 +8,11 @@ Internal Error.
**Description**
This error code is reported when an internal processing error occurs, such as a memory allocation or multi-thread processing error.
This error code is reported when an internal error occurs, such as a memory allocation or multi-thread processing error.
**Possible Causes**
1. Common kernel errors such as memory allocation and multi-thread processing errors occur.
A common kernel error, such as a memory allocation or multi-thread processing error, occurs.
**Solution**
......@@ -36,8 +36,9 @@ This error code is reported when a serialization or deserialization error occurs
**Solution**
1. Make sure the input parameter value is within the valid range.
2. Make sure the notification subsystem is not being started.
1. Make sure the input parameter value length is within the valid range.
2. Make sure the input parameter value is valid.
3. Make sure the notification subsystem has been started.
## 1600003 Failed to Connect to the Service
......@@ -47,7 +48,7 @@ Failed to connect to service.
**Description**
This error code is reported when the notification subsystem is abnormal due to a service connection failure.
This error code is reported when the connection with the notification subsystem fails.
**Possible Causes**
......@@ -66,15 +67,15 @@ Notification is not enabled.
**Description**
This error code is reported when the notification function is disabled.
This error code is reported when the notification feature is disabled.
**Possible Causes**
The notification function is set to its default state (default) or manually disabled.
The notification feature is not enabled manually. By default, this feature is disabled.
**Solution**
Enable the notification function.
Enable the notification feature.
## 1600005 Notification Slot Is Disabled
......@@ -102,16 +103,16 @@ Notification is not allowed to remove.
**Description**
This error code is reported when **isUnremoveable** is set to **true** and an attempt is made to remove all notifications or when **isRemoveAllowed** is set to **false** and an attempt is made to remove a specific notification.
This error code is reported when the notification removal does not comply with the permission settings.
**Possible Causes**
1. When **isUnremoveable** is set to **true**, notifications can only be removed on a one-by-one basis.
2. When **isRemoveAllowed** is set to **false**, no notification can be deleted.
1. When **isUnremovable** is set to **true**, notifications can only be removed on a one-by-one basis.
2. When **isRemoveAllowed** is set to **false**, no notification can be removed.
**Solution**
1. Check whether **unremovable** is set to **true**.
1. Check whether **isUnremovable** is set to **true**
2. Check whether **isRemoveAllowed** is set to **false**.
## 1600007 Notification Not Found
......@@ -131,7 +132,7 @@ This error code is reported when the target notification is not found.
**Solution**
Make sure the notification exists.
1. Make sure the notification exists.
## 1600008 User Not Found
......@@ -208,7 +209,7 @@ This error code is reported when the template configuration file fails to be rea
**Solution**
1. Check for the **/system/etc/notification_template/external.json** file.
2. Update the version to 3.2 or later.
2. Update the system version to 3.2 or later.
## 17700001 Bundle Name Not Found
......@@ -228,4 +229,5 @@ This error code is reported when the specified bund name is not found.
**Solution**
1. Verify the bundle name.
2. Make sure the application has been installed.
2. Make sure the application has been installed.
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册