diff --git a/en/application-dev/reference/apis/js-apis-rpc.md b/en/application-dev/reference/apis/js-apis-rpc.md
index 8fc776d5508dccfd04155a3952936743de8e711c..511e268d6f795357c94b13935df7874c0f8aeccd 100644
--- a/en/application-dev/reference/apis/js-apis-rpc.md
+++ b/en/application-dev/reference/apis/js-apis-rpc.md
@@ -1,13 +1,12 @@
# @ohos.rpc (RPC)
-The **rpc** module implements communication between processes, including inter-process communication (IPC) on a single device and remote procedure call (RPC) between processes on difference devices. IPC is implemented based on the Binder driver, and RPC is based on the DSoftBus driver.
+The **RPC** module implements communication between processes, including inter-process communication (IPC) on a single device and remote procedure call (RPC) between processes on difference devices. IPC is implemented based on the Binder driver, and RPC is based on the DSoftBus driver.
> **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.
+> - 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.
>
-> This module supports return of error codes since API version 9.
-
+> - This module supports return of error codes since API version 9.
## Modules to Import
@@ -15,38 +14,39 @@ The **rpc** module implements communication between processes, including inter-p
import rpc from '@ohos.rpc';
```
-
## ErrorCode9+
The APIs of this module return exceptions since API version 9. The following table lists the error codes.
**System capability**: SystemCapability.Communication.IPC.Core
- | Name | Value | Description |
- | ------------------------------------- | ------- | --------------------------------------------- |
- | CHECK_PARAM_ERROR | 401 | Parameter check failed. |
- | OS_MMAP_ERROR | 1900001 | Failed to call mmap. |
- | OS_IOCTL_ERROR | 1900002 | Failed to call **ioctl** with the shared memory file descriptor.|
- | WRITE_TO_ASHMEM_ERROR | 1900003 | Failed to write data to the shared memory. |
- | READ_FROM_ASHMEM_ERROR | 1900004 | Failed to read data from the shared memory. |
- | ONLY_PROXY_OBJECT_PERMITTED_ERROR | 1900005 | This operation is allowed only on the proxy object. |
- | ONLY_REMOTE_OBJECT_PERMITTED_ERROR | 1900006 | This operation is allowed only on the remote object. |
- | COMMUNICATION_ERROR | 1900007 | Failed to communicate with the remote object over IPC. |
- | PROXY_OR_REMOTE_OBJECT_INVALID_ERROR | 1900008 | Invalid proxy or remote object. |
- | WRITE_DATA_TO_MESSAGE_SEQUENCE_ERROR | 1900009 | Failed to write data to MessageSequence. |
- | READ_DATA_FROM_MESSAGE_SEQUENCE_ERROR | 1900010 | Failed to read data from MessageSequence. |
- | PARCEL_MEMORY_ALLOC_ERROR | 1900011 | Failed to allocate memory during serialization. |
- | CALL_JS_METHOD_ERROR | 1900012 | Failed to invoke the JS callback. |
- | OS_DUP_ERROR | 1900013 | Failed to call dup. |
+| Name | Value | Description |
+| ------------------------------------- | ------- | --------------------------------------------- |
+| CHECK_PARAM_ERROR | 401 | Parameter check failed. |
+| OS_MMAP_ERROR | 1900001 | Failed to call mmap. |
+| OS_IOCTL_ERROR | 1900002 | Failed to call **ioctl** with the shared memory file descriptor.|
+| WRITE_TO_ASHMEM_ERROR | 1900003 | Failed to write data to the shared memory. |
+| READ_FROM_ASHMEM_ERROR | 1900004 | Failed to read data from the shared memory. |
+| ONLY_PROXY_OBJECT_PERMITTED_ERROR | 1900005 | This operation is allowed only on the proxy object. |
+| ONLY_REMOTE_OBJECT_PERMITTED_ERROR | 1900006 | This operation is allowed only on the remote object. |
+| COMMUNICATION_ERROR | 1900007 | Failed to communicate with the remote object over IPC. |
+| PROXY_OR_REMOTE_OBJECT_INVALID_ERROR | 1900008 | Invalid proxy or remote object. |
+| WRITE_DATA_TO_MESSAGE_SEQUENCE_ERROR | 1900009 | Failed to write data to MessageSequence. |
+| READ_DATA_FROM_MESSAGE_SEQUENCE_ERROR | 1900010 | Failed to read data from MessageSequence. |
+| PARCEL_MEMORY_ALLOC_ERROR | 1900011 | Failed to allocate memory during serialization. |
+| CALL_JS_METHOD_ERROR | 1900012 | Failed to invoke the JS callback. |
+| OS_DUP_ERROR | 1900013 | Failed to call dup. |
## MessageSequence9+
- Provides APIs for reading and writing data in specific format. During RPC, the sender can use the **write()** method provided by **MessageSequence** to write data in specific format to a **MessageSequence** object. The receiver can use the **read()** method provided by **MessageSequence** to read data in specific format from a **MessageSequence** object. The data formats include basic data types and arrays, IPC objects, interface tokens, and custom sequenceable objects.
+Provides APIs for reading and writing data in specific format.
+
+During RPC or IPC, the sender can use the **write()** method provided by **MessageSequence** to write data in specific format to a **MessageSequence** object. The receiver can use the **read()** method provided by **MessageSequence** to read data in specific format from a **MessageSequence** object. The data formats include basic data types and arrays, IPC objects, interface tokens, and custom sequenceable objects.
### create
- create(): MessageSequence
+ static create(): MessageSequence
Creates a **MessageSequence** object. This API is a static method.
@@ -54,13 +54,13 @@ The APIs of this module return exceptions since API version 9. The following tab
**Return value**
- | Type | Description |
- | --------------- | ------------------------------- |
- | MessageSequence | **MessageSequence** object created.|
+| Type | Description |
+| --------------- | ------------------------------- |
+| MessageSequence | **MessageSequence** object created.|
**Example**
- ```
+ ```ts
let data = rpc.MessageSequence.create();
console.log("RpcClient: data is " + data);
```
@@ -75,7 +75,7 @@ Reclaims the **MessageSequence** object that is no longer used.
**Example**
- ```
+ ```ts
let reply = rpc.MessageSequence.create();
reply.reclaim();
```
@@ -90,22 +90,22 @@ Serializes a remote object and writes it to this **MessageSequence** object.
**Parameters**
- | Name| Type | Mandatory| Description |
- | ------ | ------------------------------- | ---- | ----------------------------------------- |
- | object | [IRemoteObject](#iremoteobject) | Yes | Remote object to serialize and write to the **MessageSequence** object.|
+| Name| Type | Mandatory| Description |
+| ------ | ------------------------------- | ---- | ----------------------------------------- |
+| object | [IRemoteObject](#iremoteobject) | Yes | Remote object to serialize and write to the **MessageSequence** object.|
**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | -------- | ------- |
- | 1900008 | proxy or remote object is invalid |
- | 1900009 | write data to message sequence failed |
+| ID| Error Message|
+| -------- | ------- |
+| 1900008 | proxy or remote object is invalid |
+| 1900009 | write data to message sequence failed |
**Example**
- ```
+ ```ts
class TestRemoteObject extends rpc.RemoteObject {
constructor(descriptor) {
super(descriptor);
@@ -131,22 +131,22 @@ Reads the remote object from **MessageSequence**. You can use this API to deseri
**Return value**
- | Type | Description |
- | ------------------------------- | ------------------ |
- | [IRemoteObject](#iremoteobject) | Remote object obtained.|
+| Type | Description |
+| ------------------------------- | ------------------ |
+| [IRemoteObject](#iremoteobject) | Remote object obtained.|
**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | ------- | -------- |
- | 1900008 | proxy or remote object is invalid |
- | 1900010 | read data from message sequence failed |
+| ID| Error Message|
+| ------- | -------- |
+| 1900008 | proxy or remote object is invalid |
+| 1900010 | read data from message sequence failed |
**Example**
- ```
+ ```ts
class TestRemoteObject extends rpc.RemoteObject {
constructor(descriptor) {
super(descriptor);
@@ -173,21 +173,21 @@ Writes an interface token to this **MessageSequence** object. The remote object
**Parameters**
- | Name| Type | Mandatory| Description |
- | ------ | ------ | ---- | ------------------ |
- | token | string | Yes | Interface token to write.|
+| Name| Type | Mandatory| Description |
+| ------ | ------ | ---- | ------------------ |
+| token | string | Yes | Interface token to write.|
**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | ------- | -------- |
- | 1900009 | write data to message sequence failed |
+| ID| Error Message|
+| ------- | -------- |
+| 1900009 | write data to message sequence failed |
**Example**
- ```
+ ```ts
let data = rpc.MessageSequence.create();
try {
data.writeInterfaceToken("aaa");
@@ -207,35 +207,34 @@ Reads the interface token from this **MessageSequence** object. The interface to
**Return value**
- | Type | Description |
- | ------ | ------------------------ |
- | string | Interface token obtained.|
+| Type | Description |
+| ------ | ------------------------ |
+| string | Interface token obtained.|
**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | ------- | ----- |
- | 1900010 | read data from message sequence failed |
-
-
-**Example**
-
- ```
- class Stub extends rpc.RemoteObject {
- onRemoteRequest(code, data, reply, option) {
- try {
- let interfaceToken = data.readInterfaceToken();
- console.log("RpcServer: interfaceToken is " + interfaceToken);
- } catch(error) {
- console.info("RpcServer: read interfaceToken failed, errorCode " + error.code);
- console.info("RpcServer: read interfaceToken failed, errorMessage " + error.message);
- }
- return true;
- }
- }
- ```
+| ID| Error Message|
+| ------- | ----- |
+| 1900010 | read data from message sequence failed |
+
+**Example**
+
+```ts
+class Stub extends rpc.RemoteObject {
+ onRemoteRequest(code, data, reply, option) {
+ try {
+ let interfaceToken = data.readInterfaceToken();
+ console.log("RpcServer: interfaceToken is " + interfaceToken);
+ } catch(error) {
+ console.info("RpcServer: read interfaceToken failed, errorCode " + error.code);
+ console.info("RpcServer: read interfaceToken failed, errorMessage " + error.message);
+ }
+ return true;
+ }
+}
+```
### getSize
@@ -247,13 +246,13 @@ Obtains the data size of this **MessageSequence** object.
**Return value**
- | Type | Description |
- | ------ | ----------------------------------------------- |
- | number | Size of the **MessageSequence** object obtained, in bytes.|
+| Type | Description |
+| ------ | ----------------------------------------------- |
+| number | Size of the **MessageSequence** object obtained, in bytes.|
**Example**
- ```
+ ```ts
let data = rpc.MessageSequence.create();
let size = data.getSize();
console.log("RpcClient: size is " + size);
@@ -269,13 +268,13 @@ Obtains the capacity of this **MessageSequence** object.
**Return value**
- | Type | Description|
- | ------ | ----- |
- | number | **MessageSequence** capacity obtained, in bytes.|
+| Type | Description|
+| ------ | ----- |
+| number | **MessageSequence** capacity obtained, in bytes.|
**Example**
- ```
+ ```ts
let data = rpc.MessageSequence.create();
let result = data.getCapacity();
console.log("RpcClient: capacity is " + result);
@@ -285,19 +284,19 @@ Obtains the capacity of this **MessageSequence** object.
setSize(size: number): void
-Sets the size of data contained in this **MessageSequence** object.
+Sets the size of the data contained in this **MessageSequence** object.
**System capability**: SystemCapability.Communication.IPC.Core
**Parameters**
- | Name| Type | Mandatory| Description|
- | ------ | ------ | ---- | ------ |
- | size | number | Yes| Data size to set, in bytes.|
+| Name| Type | Mandatory| Description|
+| ------ | ------ | ---- | ------ |
+| size | number | Yes | Data size to set, in bytes.|
**Example**
- ```
+ ```ts
let data = rpc.MessageSequence.create();
try {
data.setSize(16);
@@ -318,21 +317,21 @@ Sets the storage capacity of this **MessageSequence** object.
**Parameters**
- | Name| Type | Mandatory| Description |
- | ------ | ------ | ---- | --------------------------------------------- |
- | size | number | Yes | Storage capacity of the **MessageSequence** object to set, in bytes.|
+| Name| Type | Mandatory| Description |
+| ------ | ------ | ---- | --------------------------------------------- |
+| size | number | Yes | Storage capacity of the **MessageSequence** object to set, in bytes.|
**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | -------- | ------ |
- | 1900011 | parcel memory alloc failed |
+| ID| Error Message|
+| -------- | ------ |
+| 1900011 | parcel memory alloc failed |
**Example**
- ```
+ ```ts
let data = rpc.MessageSequence.create();
try {
data.setCapacity(100);
@@ -347,27 +346,27 @@ For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode
getWritableBytes(): number
-Obtains the writable capacity of this **MessageSequence** object.
+Obtains the writable capacity (in bytes) of this **MessageSequence** object.
**System capability**: SystemCapability.Communication.IPC.Core
**Return value**
- | Type| Description|
- | ------ | ------ |
- | number | **MessageSequence** writable capacity obtained, in bytes.|
+| Type| Description|
+| ------ | ------ |
+| number | Writable capacity of the **MessageSequence** instance, in bytes.|
**Example**
- ```
- class Stub extends rpc.RemoteObject {
- onRemoteRequest(code, data, reply, option) {
- let getWritableBytes = data.getWritableBytes();
- console.log("RpcServer: getWritableBytes is " + getWritableBytes);
- return true;
- }
- }
- ```
+```ts
+class Stub extends rpc.RemoteObject {
+ onRemoteRequest(code, data, reply, option) {
+ let getWritableBytes = data.getWritableBytes();
+ console.log("RpcServer: getWritableBytes is " + getWritableBytes);
+ return true;
+ }
+}
+```
### getReadableBytes
@@ -379,20 +378,20 @@ Obtains the readable capacity of this **MessageSequence** object.
**Return value**
- | Type| Description|
- | ------ | ------- |
- | number | **MessageSequence** readable capacity obtained, in bytes.|
+| Type| Description|
+| ------ | ------- |
+| number | Readable capacity of the **MessageSequence** instance, in bytes.|
**Example**
- ```
- class Stub extends rpc.RemoteObject {
- onRemoteRequest(code, data, reply, option) {
- let result = data.getReadableBytes();
- console.log("RpcServer: getReadableBytes is " + result);
- return true;
- }
- }
+ ```ts
+class Stub extends rpc.RemoteObject {
+ onRemoteRequest(code, data, reply, option) {
+ let result = data.getReadableBytes();
+ console.log("RpcServer: getReadableBytes is " + result);
+ return true;
+ }
+}
```
### getReadPosition
@@ -405,13 +404,13 @@ Obtains the read position of this **MessageSequence** object.
**Return value**
- | Type| Description|
- | ------ | ------ |
- | number | Read position obtained.|
+| Type| Description|
+| ------ | ------ |
+| number | Read position obtained.|
**Example**
- ```
+ ```ts
let data = rpc.MessageSequence.create();
let readPos = data.getReadPosition();
console.log("RpcClient: readPos is " + readPos);
@@ -427,13 +426,13 @@ Obtains the write position of this **MessageSequence** object.
**Return value**
- | Type| Description|
- | ------ | ----- |
- | number | Write position obtained.|
+| Type| Description|
+| ------ | ----- |
+| number | Write position obtained.|
**Example**
- ```
+ ```ts
let data = rpc.MessageSequence.create();
data.writeInt(10);
let bwPos = data.getWritePosition();
@@ -450,13 +449,13 @@ Moves the read pointer to the specified position.
**Parameters**
- | Name| Type| Mandatory| Description|
- | ------ | ------ | ---- | ------- |
- | pos | number | Yes | Position from which data is to read.|
+| Name| Type| Mandatory| Description|
+| ------ | ------ | ---- | ------- |
+| pos | number | Yes | Position from which data is to read.|
**Example**
- ```
+ ```ts
let data = rpc.MessageSequence.create();
data.writeInt(12);
data.writeString("sequence");
@@ -482,13 +481,13 @@ Moves the write pointer to the specified position.
**Parameters**
- | Name| Type| Mandatory| Description|
- | ------ | ------ | ---- | ----- |
- | pos | number | Yes | Position from which data is to write.|
+| Name| Type| Mandatory| Description|
+| ------ | ------ | ---- | ----- |
+| pos | number | Yes | Position from which data is to write.|
**Example**
- ```
+ ```ts
let data = rpc.MessageSequence.create();
data.writeInt(4);
try {
@@ -512,21 +511,21 @@ Writes a byte value to this **MessageSequence** object.
**Parameters**
- | Name| Type | Mandatory| Description|
- | ----- | ------ | ---- | ----- |
- | val | number | Yes| Byte value to write.|
+| Name| Type | Mandatory| Description|
+| ----- | ------ | ---- | ----- |
+| val | number | Yes| Byte value to write.|
**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | -------- | ------- |
- | 1900009 | write data to message sequence failed |
+| ID| Error Message|
+| -------- | ------- |
+| 1900009 | write data to message sequence failed |
**Example**
- ```
+ ```ts
let data = rpc.MessageSequence.create();
try {
data.writeByte(2);
@@ -546,21 +545,21 @@ Reads the byte value from this **MessageSequence** object.
**Return value**
- | Type | Description|
- | ------ | ----- |
- | number | Byte value read.|
+| Type | Description|
+| ------ | ----- |
+| number | Byte value read.|
**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | ------- | -------- |
- | 1900010 | read data from message sequence failed |
+| ID| Error Message|
+| ------- | -------- |
+| 1900010 | read data from message sequence failed |
**Example**
- ```
+ ```ts
let data = rpc.MessageSequence.create();
try {
data.writeByte(2);
@@ -587,21 +586,21 @@ Writes a short integer to this **MessageSequence** object.
**Parameters**
- | Name| Type | Mandatory| Description|
- | ------ | ------ | --- | --- |
- | val | number | Yes| Short integer to write.|
+| Name| Type | Mandatory| Description|
+| ------ | ------ | --- | --- |
+| val | number | Yes| Short integer to write.|
**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | ------- | ------ |
- | 1900009 | write data to message sequence failed |
+| ID| Error Message|
+| ------- | ------ |
+| 1900009 | write data to message sequence failed |
**Example**
- ```
+ ```ts
let data = rpc.MessageSequence.create();
try {
data.writeShort(8);
@@ -621,21 +620,21 @@ Reads the short integer from this **MessageSequence** object.
**Return value**
- | Type | Description |
- | ------ | -------------- |
- | number | Short integer read.|
+| Type | Description |
+| ------ | -------------- |
+| number | Short integer read.|
**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | ------- | -------- |
- | 1900010 | read data from message sequence failed |
+| ID| Error Message|
+| ------- | -------- |
+| 1900010 | read data from message sequence failed |
**Example**
- ```
+ ```ts
let data = rpc.MessageSequence.create();
try {
data.writeShort(8);
@@ -644,12 +643,12 @@ For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode
console.info("rpc write short fail, errorMessage" + error.message);
}
try {
- let ret = data.readShort(8);
+ let ret = data.readShort();
+ console.log("RpcClient: readByte is: " + ret);
} catch(error) {
console.info("rpc read short fail, errorCode " + error.code);
console.info("rpc read short fail, errorMessage" + error.message);
}
- console.log("RpcClient: readByte is: " + ret);
```
### writeInt
@@ -662,21 +661,21 @@ Writes an integer to this **MessageSequence** object.
**Parameters**
- | Name| Type | Mandatory| Description |
- | ------ | ------ | ---- | ---------------- |
- | val | number | Yes | Integer to write.|
+| Name| Type | Mandatory| Description |
+| ------ | ------ | ---- | ---------------- |
+| val | number | Yes | Integer to write.|
**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | -------- | ------- |
- | 1900009 | write data to message sequence failed |
+| ID| Error Message|
+| -------- | ------- |
+| 1900009 | write data to message sequence failed |
**Example**
- ```
+ ```ts
let data = rpc.MessageSequence.create();
try {
data.writeInt(10);
@@ -696,21 +695,21 @@ Reads the integer from this **MessageSequence** object.
**Return value**
- | Type | Description |
- | ------ | ------------ |
- | number | Integer read.|
+| Type | Description |
+| ------ | ------------ |
+| number | Integer read.|
**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | ------- | ------- |
- | 1900010 | read data from message sequence failed |
+| ID| Error Message|
+| ------- | ------- |
+| 1900010 | read data from message sequence failed |
**Example**
- ```
+ ```ts
let data = rpc.MessageSequence.create();
try {
data.writeInt(10);
@@ -737,21 +736,21 @@ Writes a long integer to this **MessageSequence** object.
**Parameters**
- | Name| Type | Mandatory| Description |
- | ------ | ------ | ---- | ---------------- |
- | val | number | Yes | Long integer to write.|
+| Name| Type | Mandatory| Description |
+| ------ | ------ | ---- | ---------------- |
+| val | number | Yes | Long integer to write.|
**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | ------- | ------- |
- | 1900009 | write data to message sequence failed |
+| ID| Error Message|
+| ------- | ------- |
+| 1900009 | write data to message sequence failed |
**Example**
- ```
+ ```ts
let data = rpc.MessageSequence.create();
try {
data.writeLong(10000);
@@ -771,21 +770,21 @@ Reads the long integer from this **MessageSequence** object.
**Return value**
- | Type | Description |
- | ------ | -------------- |
- | number | Long integer read.|
+| Type | Description |
+| ------ | -------------- |
+| number | Long integer read.|
**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | ------- | -------- |
- | 1900010 | read data from message sequence failed |
+| ID| Error Message|
+| ------- | -------- |
+| 1900010 | read data from message sequence failed |
**Example**
- ```
+ ```ts
let data = rpc.MessageSequence.create();
try {
data.writeLong(10000);
@@ -812,21 +811,21 @@ Writes a floating-point number to this **MessageSequence** object.
**Parameters**
- | Name| Type| Mandatory| Description|
- | ----- | ---- | ---- | ----- |
- | val | number | Yes| Floating-point number to write.|
+| Name| Type| Mandatory| Description|
+| ----- | ---- | ---- | ----- |
+| val | number | Yes| Floating-point number to write.|
**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | ------- | ------- |
- | 1900009 | write data to message sequence failed |
+| ID| Error Message|
+| ------- | ------- |
+| 1900009 | write data to message sequence failed |
**Example**
- ```
+ ```ts
let data = rpc.MessageSequence.create();
try {
data.writeFloat(1.2);
@@ -846,21 +845,21 @@ Reads the floating-pointer number from this **MessageSequence** object.
**Return value**
- | Type | Description |
- | ------ | ------------ |
- | number | Floating-point number read.|
+| Type | Description |
+| ------ | ------------ |
+| number | Floating-point number read.|
**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | ------- | -------- |
- | 1900010 | read data from message sequence failed |
+| ID| Error Message|
+| ------- | -------- |
+| 1900010 | read data from message sequence failed |
**Example**
- ```
+ ```ts
let data = rpc.MessageSequence.create();
try {
data.writeFloat(1.2);
@@ -887,21 +886,21 @@ Writes a double-precision floating-point number to this **MessageSequence** obje
**Parameters**
- | Name| Type| Mandatory| Description|
- | ------ | ------ | ---- | ------ |
- | val number | Yes| Double-precision floating-point number to write.|
+| Name| Type | Mandatory| Description |
+| ------ | ------ | ---- | ---------------------- |
+| val | number | Yes | Double-precision floating-point number to write.|
**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | ------- | -------- |
- | 1900009 | write data to message sequence failed |
+| ID| Error Message|
+| ------- | -------- |
+| 1900009 | write data to message sequence failed |
**Example**
- ```
+ ```ts
let data = rpc.MessageSequence.create();
try {
data.writeDouble(10.2);
@@ -921,21 +920,21 @@ Reads the double-precision floating-point number from this **MessageSequence** o
**Return value**
- | Type | Description |
- | ------ | ------------------ |
- | number | Double-precision floating-point number read.|
+| Type | Description |
+| ------ | ------------------ |
+| number | Double-precision floating-point number read.|
**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | ------- | -------- |
- | 1900010 | read data from message sequence failed |
+| ID| Error Message|
+| ------- | -------- |
+| 1900010 | read data from message sequence failed |
**Example**
- ```
+ ```ts
let data = rpc.MessageSequence.create();
try {
data.writeDouble(10.2);
@@ -962,21 +961,21 @@ Writes a Boolean value to this **MessageSequence** object.
**Parameters**
- | Name| Type | Mandatory| Description |
- | ------ | ------- | ---- | ---------------- |
- | val | boolean | Yes | Boolean value to write.|
+| Name| Type | Mandatory| Description |
+| ------ | ------- | ---- | ---------------- |
+| val | boolean | Yes | Boolean value to write.|
**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | ------- | ------- |
- | 1900009 | write data to message sequence failed |
+| ID| Error Message|
+| ------- | ------- |
+| 1900009 | write data to message sequence failed |
**Example**
- ```
+ ```ts
let data = rpc.MessageSequence.create();
try {
data.writeBoolean(false);
@@ -996,21 +995,21 @@ Reads the Boolean value from this **MessageSequence** object.
**Return value**
- | Type | Description |
- | ------- | -------------------- |
- | boolean | Boolean value read.|
+| Type | Description |
+| ------- | -------------------- |
+| boolean | Boolean value read.|
**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | -------- | ------- |
- | 1900010 | read data from message sequence failed |
+| ID| Error Message|
+| -------- | ------- |
+| 1900010 | read data from message sequence failed |
**Example**
- ```
+ ```ts
let data = rpc.MessageSequence.create();
try {
data.writeBoolean(false);
@@ -1037,21 +1036,21 @@ Writes a character to this **MessageSequence** object.
**Parameters**
- | Name| Type | Mandatory| Description |
- | ------ | ------ | ---- | -------------------- |
- | val | number | Yes | Single character to write.|
+| Name| Type | Mandatory| Description |
+| ------ | ------ | ---- | -------------------- |
+| val | number | Yes | Single character to write.|
**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | ------- | -------- |
- | 1900009 | write data to message sequence failed |
+| ID| Error Message|
+| ------- | -------- |
+| 1900009 | write data to message sequence failed |
**Example**
- ```
+ ```ts
let data = rpc.MessageSequence.create();
try {
data.writeChar(97);
@@ -1071,21 +1070,21 @@ Reads the character from this **MessageSequence** object.
**Return value**
- | Type | Description|
- | ------ | ---- |
- | number | Character read.|
+| Type | Description|
+| ------ | ---- |
+| number | Character read.|
**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | ------ | --------- |
- | 1900010 | read data from message sequence failed |
+| ID| Error Message|
+| ------ | --------- |
+| 1900010 | read data from message sequence failed |
**Example**
- ```
+ ```ts
let data = rpc.MessageSequence.create();
try {
data.writeChar(97);
@@ -1112,21 +1111,21 @@ Writes a string to this **MessageSequence** object.
**Parameters**
- | Name| Type | Mandatory| Description |
- | ------ | ------ | ---- | ----------------------------------------- |
- | val | string | Yes | String to write. The length of the string must be less than 40960 bytes.|
+| Name| Type | Mandatory| Description |
+| ------ | ------ | ---- | ----------------------------------------- |
+| val | string | Yes | String to write. The length of the string must be less than 40960 bytes.|
**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | ------- | -------- |
- | 1900009 | write data to message sequence failed |
+| ID| Error Message|
+| ------- | -------- |
+| 1900009 | write data to message sequence failed |
**Example**
- ```
+ ```ts
let data = rpc.MessageSequence.create();
try {
data.writeString('abc');
@@ -1146,21 +1145,21 @@ Reads the string from this **MessageSequence** object.
**Return value**
- | Type | Description |
- | ------ | -------------- |
- | string | String read.|
+| Type | Description |
+| ------ | -------------- |
+| string | String read.|
**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | ------- | -------- |
- | 1900010 | read data from message sequence failed |
+| ID| Error Message|
+| ------- | -------- |
+| 1900010 | read data from message sequence failed |
**Example**
- ```
+ ```ts
let data = rpc.MessageSequence.create();
try {
data.writeString('abc');
@@ -1187,21 +1186,21 @@ Writes a **Parcelable** object to this **MessageSequence** object.
**Parameters**
- | Name| Type| Mandatory| Description|
- | ------ | --------- | ---- | ------ |
- | val | Parcelable | Yes | **Parcelable** object to write.|
+| Name| Type| Mandatory| Description|
+| ------ | --------- | ---- | ------ |
+| val | Parcelable | Yes | **Parcelable** object to write.|
**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | ------- | -------- |
- | 1900009 | write data to message sequence failed |
+| ID| Error Message|
+| ------- | -------- |
+| 1900009 | write data to message sequence failed |
**Example**
- ```
+ ```ts
class MySequenceable {
num: number;
str: string;
@@ -1240,22 +1239,22 @@ Reads a **Parcelable** object from this **MessageSequence** object to the specif
**Parameters**
- | Name| Type | Mandatory| Description |
- | ------ | ------------------------- | ---- | ----------------------------------------- |
- | dataIn | Parcelable | Yes | **Parcelable** object to read.|
+| Name| Type | Mandatory| Description |
+| ------ | ------------------------- | ---- | ----------------------------------------- |
+| dataIn | Parcelable | Yes | **Parcelable** object to read.|
**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | -------- | ------- |
- | 1900010 | read data from message sequence failed |
- | 1900012 | call js callback function failed |
+| ID| Error Message|
+| -------- | ------- |
+| 1900010 | read data from message sequence failed |
+| 1900012 | call js callback function failed |
**Example**
- ```
+ ```ts
class MySequenceable {
num: number;
str: string;
@@ -1296,21 +1295,21 @@ Writes a byte array to this **MessageSequence** object.
**Parameters**
- | Name | Type | Mandatory| Description |
- | --------- | -------- | ---- | ------------------ |
- | byteArray | number[] | Yes | Byte array to write.|
+| Name | Type | Mandatory| Description |
+| --------- | -------- | ---- | ------------------ |
+| byteArray | number[] | Yes | Byte array to write.|
**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | ------- | -------- |
- | 1900009 | write data to message sequence failed |
+| ID| Error Message|
+| ------- | -------- |
+| 1900009 | write data to message sequence failed |
**Example**
- ```
+ ```ts
let data = rpc.MessageSequence.create();
let ByteArrayVar = [1, 2, 3, 4, 5];
try {
@@ -1331,21 +1330,21 @@ Reads a byte array from this **MessageSequence** object.
**Parameters**
- | Name| Type | Mandatory| Description |
- | ------ | -------- | ---- | ------------------ |
- | dataIn | number[] | Yes | Byte array to read.|
+| Name| Type | Mandatory| Description |
+| ------ | -------- | ---- | ------------------ |
+| dataIn | number[] | Yes | Byte array to read.|
**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | ------- | -------- |
- | 1900010 | read data from message sequence failed |
+| ID| Error Message|
+| ------- | -------- |
+| 1900010 | read data from message sequence failed |
**Example**
- ```
+ ```ts
let data = rpc.MessageSequence.create();
let ByteArrayVar = [1, 2, 3, 4, 5];
try {
@@ -1373,21 +1372,21 @@ Reads the byte array from this **MessageSequence** object.
**Return value**
- | Type | Description |
- | -------- | -------------- |
- | number[] | Byte array read.|
+| Type | Description |
+| -------- | -------------- |
+| number[] | Byte array read.|
**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | -------- | ------- |
- | 1900010 | read data from message sequence failed |
+| ID| Error Message|
+| -------- | ------- |
+| 1900010 | read data from message sequence failed |
**Example**
- ```
+ ```ts
let data = rpc.MessageSequence.create();
let byteArrayVar = [1, 2, 3, 4, 5];
try {
@@ -1415,21 +1414,21 @@ Writes a short array to this **MessageSequence** object.
**Parameters**
- | Name | Type | Mandatory| Description |
- | ---------- | -------- | ---- | -------------------- |
- | shortArray | number[] | Yes | Short array to write.|
+| Name | Type | Mandatory| Description |
+| ---------- | -------- | ---- | -------------------- |
+| shortArray | number[] | Yes | Short array to write.|
**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | ----- | ----- |
- | 1900009 | write data to message sequence failed |
+| ID| Error Message|
+| ----- | ----- |
+| 1900009 | write data to message sequence failed |
**Example**
- ```
+ ```ts
let data = rpc.MessageSequence.create();
try {
data.writeShortArray([11, 12, 13]);
@@ -1449,21 +1448,21 @@ Reads a short array from this **MessageSequence** object.
**Parameters**
- | Name| Type | Mandatory| Description |
- | ------ | -------- | ---- | -------------------- |
- | dataIn | number[] | Yes | Short array to read.|
+| Name| Type | Mandatory| Description |
+| ------ | -------- | ---- | -------------------- |
+| dataIn | number[] | Yes | Short array to read.|
**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | ------ | ------- |
- | 1900010 | read data from message sequence failed |
+| ID| Error Message|
+| ------ | ------- |
+| 1900010 | read data from message sequence failed |
**Example**
- ```
+ ```ts
let data = rpc.MessageSequence.create();
try {
data.writeShortArray([11, 12, 13]);
@@ -1490,21 +1489,21 @@ Reads the short array from this **MessageSequence** object.
**Return value**
- | Type | Description |
- | -------- | ---------------- |
- | number[] | Short array read.|
+| Type | Description |
+| -------- | ---------------- |
+| number[] | Short array read.|
**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | -------- | ------- |
- | 1900010 | read data from message sequence failed |
+| ID| Error Message|
+| -------- | ------- |
+| 1900010 | read data from message sequence failed |
**Example**
- ```
+ ```ts
let data = rpc.MessageSequence.create();
try {
data.writeShortArray([11, 12, 13]);
@@ -1531,21 +1530,21 @@ Writes an integer array to this **MessageSequence** object.
**Parameters**
- | Name | Type | Mandatory| Description |
- | -------- | -------- | ---- | ------------------ |
- | intArray | number[] | Yes | Integer array to write.|
+| Name | Type | Mandatory| Description |
+| -------- | -------- | ---- | ------------------ |
+| intArray | number[] | Yes | Integer array to write.|
**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | ----- | --------- |
- | 1900009 | write data to message sequence failed |
+| ID| Error Message|
+| ----- | --------- |
+| 1900009 | write data to message sequence failed |
**Example**
- ```
+ ```ts
let data = rpc.MessageSequence.create();
try {
data.writeIntArray([100, 111, 112]);
@@ -1565,21 +1564,21 @@ Reads an integer array from this **MessageSequence** object.
**Parameters**
- | Name| Type | Mandatory| Description |
- | ------ | -------- | ---- | ------------------ |
- | dataIn | number[] | Yes | Integer array to read.|
+| Name| Type | Mandatory| Description |
+| ------ | -------- | ---- | ------------------ |
+| dataIn | number[] | Yes | Integer array to read.|
**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | ------- | -------- |
- | 1900010 | read data from message sequence failed |
+| ID| Error Message|
+| ------- | -------- |
+| 1900010 | read data from message sequence failed |
**Example**
- ```
+ ```ts
let data = rpc.MessageSequence.create();
try {
data.writeIntArray([100, 111, 112]);
@@ -1606,21 +1605,21 @@ Reads the integer array from this **MessageSequence** object.
**Return value**
- | Type | Description |
- | -------- | -------------- |
- | number[] | Integer array read.|
+| Type | Description |
+| -------- | -------------- |
+| number[] | Integer array read.|
**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | ----- | ------- |
- | 1900010 | read data from message sequence failed |
+| ID| Error Message|
+| ----- | ------- |
+| 1900010 | read data from message sequence failed |
**Example**
- ```
+ ```ts
let data = rpc.MessageSequence.create();
try {
data.writeIntArray([100, 111, 112]);
@@ -1647,21 +1646,21 @@ Writes a long array to this **MessageSequence** object.
**Parameters**
- | Name | Type | Mandatory| Description |
- | --------- | -------- | ---- | -------------------- |
- | longArray | number[] | Yes | Long array to write.|
+| Name | Type | Mandatory| Description |
+| --------- | -------- | ---- | -------------------- |
+| longArray | number[] | Yes | Long array to write.|
**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | ------- | ----- |
- | 1900009 | write data to message sequence failed |
+| ID| Error Message|
+| ------- | ----- |
+| 1900009 | write data to message sequence failed |
**Example**
- ```
+ ```ts
let data = rpc.MessageSequence.create();
try {
data.writeLongArray([1111, 1112, 1113]);
@@ -1681,21 +1680,21 @@ Reads a long array from this **MessageSequence** object.
**Parameters**
- | Name| Type | Mandatory| Description |
- | ------ | -------- | ---- | -------------------- |
- | dataIn | number[] | Yes | Long array to read.|
+| Name| Type | Mandatory| Description |
+| ------ | -------- | ---- | -------------------- |
+| dataIn | number[] | Yes | Long array to read.|
**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | ------- | ------ |
- | 1900010 | read data from message sequence failed |
+| ID| Error Message|
+| ------- | ------ |
+| 1900010 | read data from message sequence failed |
**Example**
- ```
+ ```ts
let data = rpc.MessageSequence.create();
try {
data.writeLongArray([1111, 1112, 1113]);
@@ -1722,21 +1721,21 @@ Reads the long array from this **MessageSequence** object.
**Return value**
- | Type | Description |
- | -------- | ---------------- |
- | number[] | Long array read.|
+| Type | Description |
+| -------- | ---------------- |
+| number[] | Long array read.|
**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | ------- | -------- |
- | 1900010 | read data from message sequence failed |
+| ID| Error Message|
+| ------- | -------- |
+| 1900010 | read data from message sequence failed |
**Example**
- ```
+ ```ts
let data = rpc.MessageSequence.create();
try {
data.writeLongArray([1111, 1112, 1113]);
@@ -1763,21 +1762,21 @@ Writes a floating-point array to this **MessageSequence** object.
**Parameters**
- | Name | Type | Mandatory| Description |
- | ---------- | -------- | ---- | ----------------------------------------------------------------------------------------------------------------------- |
- | floatArray | number[] | Yes | Floating-point array to write. The system processes Float data as that of the Double type. Therefore, the total number of bytes occupied by a FloatArray must be calculated as the Double type.|
+| Name | Type | Mandatory| Description |
+| ---------- | -------- | ---- | ----------------------------------------------------------------------------------------------------------------------- |
+| floatArray | number[] | Yes | Floating-point array to write. The system processes Float data as that of the Double type. Therefore, the total number of bytes occupied by a FloatArray must be calculated as the Double type.|
**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | ------- | -------- |
- | 1900009 | write data to message sequence failed |
+| ID| Error Message|
+| ------- | -------- |
+| 1900009 | write data to message sequence failed |
**Example**
- ```
+ ```ts
let data = rpc.MessageSequence.create();
try {
data.writeFloatArray([1.2, 1.3, 1.4]);
@@ -1797,21 +1796,21 @@ Reads a floating-point array from this **MessageSequence** object.
**Parameters**
- | Name| Type | Mandatory| Description |
- | ------ | -------- | ---- | ----------------------------------------------------------------------------------------------------------------------- |
- | dataIn | number[] | Yes | Floating-point array to read. The system processes Float data as that of the Double type. Therefore, the total number of bytes occupied by a FloatArray must be calculated as the Double type.|
+| Name| Type | Mandatory| Description |
+| ------ | -------- | ---- | ----------------------------------------------------------------------------------------------------------------------- |
+| dataIn | number[] | Yes | Floating-point array to read. The system processes Float data as that of the Double type. Therefore, the total number of bytes occupied by a FloatArray must be calculated as the Double type.|
**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | ------- | -------- |
- | 1900010 | read data from message sequence failed |
+| ID| Error Message|
+| ------- | -------- |
+| 1900010 | read data from message sequence failed |
**Example**
- ```
+ ```ts
let data = rpc.MessageSequence.create();
try {
data.writeFloatArray([1.2, 1.3, 1.4]);
@@ -1838,21 +1837,21 @@ Reads the floating-point array from this **MessageSequence** object.
**Return value**
- | Type | Description |
- | -------- | -------------- |
- | number[] | Floating-point array read.|
+| Type | Description |
+| -------- | -------------- |
+| number[] | Floating-point array read.|
**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | ------- | -------- |
- | 1900010 | read data from message sequence failed |
+| ID| Error Message|
+| ------- | -------- |
+| 1900010 | read data from message sequence failed |
**Example**
- ```
+ ```ts
let data = rpc.MessageSequence.create();
try {
data.writeFloatArray([1.2, 1.3, 1.4]);
@@ -1879,21 +1878,21 @@ Writes a double-precision floating-point array to this **MessageSequence** objec
**Parameters**
- | Name | Type | Mandatory| Description |
- | ----------- | -------- | ---- | ------------------------ |
- | doubleArray | number[] | Yes | Double-precision floating-point array to write.|
+| Name | Type | Mandatory| Description |
+| ----------- | -------- | ---- | ------------------------ |
+| doubleArray | number[] | Yes | Double-precision floating-point array to write.|
**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | ------- | -------- |
- | 1900009 | write data to message sequence failed |
+| ID| Error Message|
+| ------- | -------- |
+| 1900009 | write data to message sequence failed |
**Example**
- ```
+ ```ts
let data = rpc.MessageSequence.create();
try {
data.writeDoubleArray([11.1, 12.2, 13.3]);
@@ -1913,21 +1912,21 @@ Reads a double-precision floating-point array from this **MessageSequence** obje
**Parameters**
- | Name| Type | Mandatory| Description |
- | ------ | -------- | ---- | ------------------------ |
- | dataIn | number[] | Yes | Double-precision floating-point array to read.|
+| Name| Type | Mandatory| Description |
+| ------ | -------- | ---- | ------------------------ |
+| dataIn | number[] | Yes | Double-precision floating-point array to read.|
**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | ------- | -------- |
- | 1900010 | read data from message sequence failed |
+| ID| Error Message|
+| ------- | -------- |
+| 1900010 | read data from message sequence failed |
**Example**
- ```
+ ```ts
let data = rpc.MessageSequence.create();
try {
data.writeDoubleArray([11.1, 12.2, 13.3]);
@@ -1954,21 +1953,21 @@ Reads the double-precision floating-point array from this **MessageSequence** ob
**Return value**
- | Type | Description |
- | -------- | -------------------- |
- | number[] | Double-precision floating-point array read.|
+| Type | Description |
+| -------- | -------------------- |
+| number[] | Double-precision floating-point array read.|
**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | ------- | -------- |
- | 1900010 | read data from message sequence failed |
+| ID| Error Message|
+| ------- | -------- |
+| 1900010 | read data from message sequence failed |
**Example**
- ```
+ ```ts
let data = rpc.MessageSequence.create();
try {
data.writeDoubleArray([11.1, 12.2, 13.3]);
@@ -1995,21 +1994,21 @@ Writes a Boolean array to this **MessageSequence** object.
**Parameters**
- | Name | Type | Mandatory| Description |
- | ------------ | --------- | ---- | ------------------ |
- | booleanArray | boolean[] | Yes | Boolean array to write.|
+| Name | Type | Mandatory| Description |
+| ------------ | --------- | ---- | ------------------ |
+| booleanArray | boolean[] | Yes | Boolean array to write.|
**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | ------- | -------- |
- | 1900009 | write data to message sequence failed |
+| ID| Error Message|
+| ------- | -------- |
+| 1900009 | write data to message sequence failed |
**Example**
- ```
+ ```ts
let data = rpc.MessageSequence.create();
try {
data.writeBooleanArray([false, true, false]);
@@ -2029,21 +2028,21 @@ Reads a Boolean array from this **MessageSequence** object.
**Parameters**
- | Name| Type | Mandatory| Description |
- | ------ | --------- | ---- | ------------------ |
- | dataIn | boolean[] | Yes | Boolean array to read.|
+| Name| Type | Mandatory| Description |
+| ------ | --------- | ---- | ------------------ |
+| dataIn | boolean[] | Yes | Boolean array to read.|
**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | ------- | -------- |
- | 1900010 | read data from message sequence failed |
+| ID| Error Message|
+| ------- | -------- |
+| 1900010 | read data from message sequence failed |
**Example**
- ```
+ ```ts
let data = rpc.MessageSequence.create();
try {
data.writeBooleanArray([false, true, false]);
@@ -2070,21 +2069,21 @@ Reads the Boolean array from this **MessageSequence** object.
**Return value**
- | Type | Description |
- | --------- | -------------- |
- | boolean[] | Boolean array read.|
+| Type | Description |
+| --------- | -------------- |
+| boolean[] | Boolean array read.|
**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | ------- | -------- |
- | 1900010 | read data from message sequence failed |
+| ID| Error Message|
+| ------- | -------- |
+| 1900010 | read data from message sequence failed |
**Example**
- ```
+ ```ts
let data = rpc.MessageSequence.create();
try {
data.writeBooleanArray([false, true, false]);
@@ -2111,21 +2110,21 @@ Writes a character array to this **MessageSequence** object.
**Parameters**
- | Name | Type | Mandatory| Description |
- | --------- | -------- | ---- | ---------------------- |
- | charArray | number[] | Yes | Character array to write.|
+| Name | Type | Mandatory| Description |
+| --------- | -------- | ---- | ---------------------- |
+| charArray | number[] | Yes | Character array to write.|
**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | -------- | ------ |
- | 1900009 | write data to message sequence failed |
+| ID| Error Message|
+| -------- | ------ |
+| 1900009 | write data to message sequence failed |
**Example**
- ```
+ ```ts
let data = rpc.MessageSequence.create();
try {
data.writeCharArray([97, 98, 88]);
@@ -2145,21 +2144,21 @@ Reads a character array from this **MessageSequence** object.
**Parameters**
- | Name| Type | Mandatory| Description |
- | ------ | -------- | ---- | ---------------------- |
- | dataIn | number[] | Yes | Character array to read.|
+| Name| Type | Mandatory| Description |
+| ------ | -------- | ---- | ---------------------- |
+| dataIn | number[] | Yes | Character array to read.|
**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | ------- | -------- |
- | 1900010 | read data from message sequence failed |
+| ID| Error Message|
+| ------- | -------- |
+| 1900010 | read data from message sequence failed |
**Example**
- ```
+ ```ts
let data = rpc.MessageSequence.create();
try {
data.writeCharArray([97, 98, 88]);
@@ -2186,21 +2185,21 @@ Reads the character array from this **MessageSequence** object.
**Return value**
- | Type | Description |
- | -------- | ------------------ |
- | number[] | Character array read.|
+| Type | Description |
+| -------- | ------------------ |
+| number[] | Character array read.|
**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | ------- | -------- |
- | 1900010 | read data from message sequence failed |
+| ID| Error Message|
+| ------- | -------- |
+| 1900010 | read data from message sequence failed |
**Example**
- ```
+ ```ts
let data = rpc.MessageSequence.create();
try {
data.writeCharArray([97, 98, 88]);
@@ -2228,21 +2227,21 @@ Writes a string array to this **MessageSequence** object.
**Parameters**
- | Name | Type | Mandatory| Description |
- | ----------- | -------- | ---- | ------------------------------------------------------- |
- | stringArray | string[] | Yes | String array to write. The length of a single element in the array must be less than 40960 bytes.|
+| Name | Type | Mandatory| Description |
+| ----------- | -------- | ---- | ------------------------------------------------------- |
+| stringArray | string[] | Yes | String array to write. The length of a single element in the array must be less than 40960 bytes.|
**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | ------- | -------- |
- | 1900009 | write data to message sequence failed |
+| ID| Error Message|
+| ------- | -------- |
+| 1900009 | write data to message sequence failed |
**Example**
- ```
+ ```ts
let data = rpc.MessageSequence.create();
try {
data.writeStringArray(["abc", "def"]);
@@ -2262,21 +2261,21 @@ Reads a string array from this **MessageSequence** object.
**Parameters**
- | Name| Type | Mandatory| Description |
- | ------ | -------- | ---- | -------------------- |
- | dataIn | string[] | Yes | String array to read.|
+| Name| Type | Mandatory| Description |
+| ------ | -------- | ---- | -------------------- |
+| dataIn | string[] | Yes | String array to read.|
**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | ------- | -------- |
- | 1900010 | read data from message sequence failed |
+| ID| Error Message|
+| ------- | -------- |
+| 1900010 | read data from message sequence failed |
**Example**
- ```
+ ```ts
let data = rpc.MessageSequence.create();
try {
data.writeStringArray(["abc", "def"]);
@@ -2303,21 +2302,21 @@ Reads the string array from this **MessageSequence** object.
**Return value**
- | Type | Description |
- | -------- | ---------------- |
- | string[] | String array read.|
+| Type | Description |
+| -------- | ---------------- |
+| string[] | String array read.|
**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | ------- | -------- |
- | 1900010 | read data from message sequence failed |
+| ID| Error Message|
+| ------- | -------- |
+| 1900010 | read data from message sequence failed |
**Example**
- ```
+ ```ts
let data = rpc.MessageSequence.create();
try {
data.writeStringArray(["abc", "def"]);
@@ -2346,13 +2345,13 @@ Writes information to this **MessageSequence** object indicating that no excepti
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | ------- | -------- |
- | 1900009 | write data to message sequence failed |
+| ID| Error Message|
+| ------- | -------- |
+| 1900009 | write data to message sequence failed |
**Example**
- ```
+ ```ts
class TestRemoteObject extends rpc.RemoteObject {
constructor(descriptor) {
super(descriptor);
@@ -2388,13 +2387,15 @@ Reads the exception information from this **MessageSequence** object.
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | ------- | -------- |
- | 1900010 | read data from message sequence failed |
+| ID| Error Message|
+| ------- | -------- |
+| 1900010 | read data from message sequence failed |
**Example**
- ```
+ Obtain the service.
+
+ ```ts
import FA from "@ohos.ability.featureAbility";
let proxy;
let connect = {
@@ -2414,6 +2415,11 @@ For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode
"abilityName": "com.ohos.server.MainAbility",
};
FA.connectAbility(want, connect);
+ ```
+
+The proxy object in the **onConnect** callback can be assigned a value only after the ability is connected asynchronously. Then, **sendMessageRequest()** of the proxy object is called to send a message.
+
+ ```ts
let option = new rpc.MessageOption();
let data = rpc.MessageSequence.create();
let reply = rpc.MessageSequence.create();
@@ -2453,21 +2459,21 @@ Writes a **Parcelable** array to this **MessageSequence** object.
**Parameters**
- | Name | Type | Mandatory| Description |
- | --------------- | ------------ | ---- | -------------------------- |
- | parcelableArray | Parcelable[] | Yes | **Parcelable** array to write.|
+| Name | Type | Mandatory| Description |
+| --------------- | ------------ | ---- | -------------------------- |
+| parcelableArray | Parcelable[] | Yes | **Parcelable** array to write.|
**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | ------- | -------- |
- | 1900009 | write data to message sequence failed |
+| ID| Error Message|
+| ------- | -------- |
+| 1900009 | write data to message sequence failed |
**Example**
- ```
+ ```ts
class MyParcelable {
num: number;
str: string;
@@ -2509,22 +2515,22 @@ Reads a **Parcelable** array from this **MessageSequence** object.
**Parameters**
- | Name | Type | Mandatory| Description |
- | --------------- | ------------ | ---- | -------------------------- |
- | parcelableArray | Parcelable[] | Yes | **Parcelable** array to read.|
+| Name | Type | Mandatory| Description |
+| --------------- | ------------ | ---- | -------------------------- |
+| parcelableArray | Parcelable[] | Yes | **Parcelable** array to read.|
**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | ------- | -------- |
- | 1900010 | read data from message sequence failed |
- | 1900012 | call js callback function failed |
+| ID| Error Message|
+| ------- | -------- |
+| 1900010 | read data from message sequence failed |
+| 1900012 | call js callback function failed |
**Example**
- ```
+ ```ts
class MyParcelable {
num: number;
str: string;
@@ -2570,21 +2576,21 @@ Writes an array of **IRemoteObject** objects to this **MessageSequence** object.
**Parameters**
- | Name | Type | Mandatory| Description |
- | ----------- | --------------- | ---- | ---------------------------------------------- |
- | objectArray | IRemoteObject[] | Yes | Array of **IRemoteObject** objects to write.|
+| Name | Type | Mandatory| Description |
+| ----------- | --------------- | ---- | ---------------------------------------------- |
+| objectArray | IRemoteObject[] | Yes | Array of **IRemoteObject** objects to write.|
**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | ------- | ------- |
- | 1900009 | write data to message sequence failed |
+| ID| Error Message|
+| ------- | ------- |
+| 1900009 | write data to message sequence failed |
**Example**
- ```
+ ```ts
class TestRemoteObject extends rpc.RemoteObject {
constructor(descriptor) {
super(descriptor);
@@ -2617,21 +2623,21 @@ Reads an array of **IRemoteObject** objects from this **MessageSequence** object
**Parameters**
- | Name | Type | Mandatory| Description |
- | ------- | --------------- | ---- | ---------------------------------------------- |
- | objects | IRemoteObject[] | Yes | **IRemoteObject** array to read.|
+| Name | Type | Mandatory| Description |
+| ------- | --------------- | ---- | ---------------------------------------------- |
+| objects | IRemoteObject[] | Yes | **IRemoteObject** array to read.|
**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | ------- | -------- |
- | 1900010 | read data from message sequence failed |
+| ID| Error Message|
+| ------- | -------- |
+| 1900010 | read data from message sequence failed |
**Example**
- ```
+ ```ts
class MyDeathRecipient {
onRemoteDied() {
console.log("server died");
@@ -2670,21 +2676,21 @@ Reads the **IRemoteObject** object array from this **MessageSequence** object.
**Return value**
- | Type | Description |
- | --------------- | --------------------------- |
- | IRemoteObject[] | **IRemoteObject** object array read.|
+| Type | Description |
+| --------------- | --------------------------- |
+| IRemoteObject[] | **IRemoteObject** object array read.|
**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | ------- | -------- |
- | 1900010 | read data from message sequence failed |
+| ID| Error Message|
+| ------- | -------- |
+| 1900010 | read data from message sequence failed |
**Example**
- ```
+ ```ts
class TestRemoteObject extends rpc.RemoteObject {
constructor(descriptor) {
super(descriptor);
@@ -2712,19 +2718,19 @@ For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode
static closeFileDescriptor(fd: number): void
-Closes a file descriptor.
+Closes a file descriptor. This API is a static method.
**System capability**: SystemCapability.Communication.IPC.Core
**Parameters**
- | Name| Type | Mandatory| Description |
- | ------ | ------ | ---- | -------------------- |
- | fd | number | Yes | File descriptor to close.|
+| Name| Type | Mandatory| Description |
+| ------ | ------ | ---- | -------------------- |
+| fd | number | Yes | File descriptor to close.|
**Example**
- ```
+ ```ts
import fileio from '@ohos.fileio';
let filePath = "path/to/file";
let fd = fileio.openSync(filePath, 0o2| 0o100, 0o666);
@@ -2740,33 +2746,33 @@ Closes a file descriptor.
static dupFileDescriptor(fd: number) :number
-Duplicates a file descriptor.
+Duplicates a file descriptor. This API is a static method.
**System capability**: SystemCapability.Communication.IPC.Core
**Parameters**
- | Name| Type | Mandatory| Description |
- | ------ | ------ | ---- | ------------------------ |
- | fd | number | Yes | File descriptor to duplicate.|
+| Name| Type | Mandatory| Description |
+| ------ | ------ | ---- | ------------------------ |
+| fd | number | Yes | File descriptor to duplicate.|
**Return value**
- | Type | Description |
- | ------ | -------------------- |
- | number | New file descriptor.|
+| Type | Description |
+| ------ | -------------------- |
+| number | New file descriptor.|
**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | ------- | ------- |
- | 1900013 | call os dup function failed |
+| ID| Error Message|
+| ------- | ------- |
+| 1900013 | call os dup function failed |
**Example**
- ```
+ ```ts
import fileio from '@ohos.fileio';
let filePath = "path/to/file";
let fd = fileio.openSync(filePath, 0o2| 0o100, 0o666);
@@ -2788,14 +2794,14 @@ Checks whether this **MessageSequence** object contains file descriptors.
**Return value**
- | Type | Description |
- | ------- | -------------------------------------------------------------------- |
- | boolean | Returns **true** if the **MessageSequence** object contains file descriptors; returns **false** otherwise.|
+| Type | Description |
+| ------- | -------------------------------------------------------------------- |
+| boolean | Returns **true** if the **MessageSequence** object contains file descriptors; returns **false** otherwise.|
**Example**
- ```
+ ```ts
import fileio from '@ohos.fileio';
let sequence = new rpc.MessageSequence();
let filePath = "path/to/file";
@@ -2826,21 +2832,21 @@ Writes a file descriptor to this **MessageSequence** object.
**Parameters**
- | Name| Type | Mandatory| Description |
- | ------ | ------ | ---- | ------------ |
- | fd | number | Yes | File descriptor to write.|
+| Name| Type | Mandatory| Description |
+| ------ | ------ | ---- | ------------ |
+| fd | number | Yes | File descriptor to write.|
**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | -------- | ------ |
- | 1900009 | write data to message sequence failed |
+| ID| Error Message|
+| -------- | ------ |
+| 1900009 | write data to message sequence failed |
**Example**
- ```
+ ```ts
import fileio from '@ohos.fileio';
let sequence = new rpc.MessageSequence();
let filePath = "path/to/file";
@@ -2853,7 +2859,6 @@ For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode
}
```
-
### readFileDescriptor
readFileDescriptor(): number
@@ -2864,21 +2869,21 @@ Reads the file descriptor from this **MessageSequence** object.
**Return value**
- | Type | Description |
- | ------ | ---------------- |
- | number | File descriptor read.|
+| Type | Description |
+| ------ | ---------------- |
+| number | File descriptor read.|
**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | ------- | -------- |
- | 1900010 | read data from message sequence failed |
+| ID| Error Message|
+| ------- | -------- |
+| 1900010 | read data from message sequence failed |
**Example**
- ```
+ ```ts
import fileio from '@ohos.fileio';
let sequence = new rpc.MessageSequence();
let filePath = "path/to/file";
@@ -2897,7 +2902,6 @@ For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode
}
```
-
### writeAshmem
writeAshmem(ashmem: Ashmem): void
@@ -2908,21 +2912,21 @@ Writes an anonymous shared object to this **MessageSequence** object.
**Parameters**
- | Name| Type | Mandatory| Description |
- | ------ | ------ | ---- | ------------------------------------- |
- | ashmem | Ashmem | Yes | Anonymous shared object to write.|
+| Name| Type | Mandatory| Description |
+| ------ | ------ | ---- | ------------------------------------- |
+| ashmem | Ashmem | Yes | Anonymous shared object to write.|
**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | ------- | ------- |
- | 1900003 | write to ashmem failed |
+| ID| Error Message|
+| ------- | ------- |
+| 1900003 | write to ashmem failed |
**Example**
- ```
+ ```ts
let sequence = new rpc.MessageSequence();
let ashmem;
try {
@@ -2950,21 +2954,21 @@ Reads the anonymous shared object from this **MessageSequence** object.
**Return value**
- | Type | Description |
- | ------ | ------------------ |
- | Ashmem | Anonymous share object read.|
+| Type | Description |
+| ------ | ------------------ |
+| Ashmem | Anonymous share object read.|
**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | ------- | -------- |
- | 1900004 | read from ashmem failed |
+| ID| Error Message|
+| ------- | -------- |
+| 1900004 | read from ashmem failed |
**Example**
- ```
+ ```ts
let sequence = new rpc.MessageSequence();
let ashmem;
try {
@@ -2988,7 +2992,6 @@ For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode
}
```
-
### getRawDataCapacity
getRawDataCapacity(): number
@@ -2999,19 +3002,18 @@ Obtains the maximum amount of raw data that can be held by this **MessageSequenc
**Return value**
- | Type | Description |
- | ------ | ------------------------------------------------------------ |
- | number | 128 MB, which is the maximum amount of raw data that can be held by this **MessageSequence** object.|
+| Type | Description |
+| ------ | ------------------------------------------------------------ |
+| number | 128 MB, which is the maximum amount of raw data that can be held by this **MessageSequence** object.|
**Example**
- ```
+ ```ts
let sequence = new rpc.MessageSequence();
let result = sequence.getRawDataCapacity();
console.log("RpcTest: sequence get RawDataCapacity result is : " + result);
```
-
### writeRawData
writeRawData(rawData: number[], size: number): void
@@ -3022,22 +3024,22 @@ Writes raw data to this **MessageSequence** object.
**Parameters**
- | Name | Type | Mandatory| Description |
- | ------- | -------- | ---- | ---------------------------------- |
- | rawData | number[] | Yes | Raw data to write. |
- | size | number | Yes | Size of the raw data, in bytes.|
+| Name | Type | Mandatory| Description |
+| ------- | -------- | ---- | ---------------------------------- |
+| rawData | number[] | Yes | Raw data to write. |
+| size | number | Yes | Size of the raw data, in bytes.|
**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | ------- | ------ |
- | 1900009 | write data to message sequence failed |
+| ID| Error Message|
+| ------- | ------ |
+| 1900009 | write data to message sequence failed |
**Example**
- ```
+ ```ts
let sequence = new rpc.MessageSequence();
let arr = [1, 2, 3, 4, 5];
try {
@@ -3048,7 +3050,6 @@ For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode
}
```
-
### readRawData
readRawData(size: number): number[]
@@ -3059,27 +3060,27 @@ Reads raw data from this **MessageSequence** object.
**Parameters**
- | Name| Type | Mandatory| Description |
- | ------ | ------ | ---- | ------------------------ |
- | size | number | Yes | Size of the raw data to read.|
+| Name| Type | Mandatory| Description |
+| ------ | ------ | ---- | ------------------------ |
+| size | number | Yes | Size of the raw data to read.|
**Return value**
- | Type | Description |
- | -------- | ------------------------------ |
- | number[] | Raw data read, in bytes.|
+| Type | Description |
+| -------- | ------------------------------ |
+| number[] | Raw data read, in bytes.|
**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | ------- | -------- |
- | 1900010 | read data from message sequence failed |
+| ID| Error Message|
+| ------- | -------- |
+| 1900010 | read data from message sequence failed |
**Example**
- ```
+ ```ts
let sequence = new rpc.MessageSequence();
let arr = [1, 2, 3, 4, 5];
try {
@@ -3101,11 +3102,13 @@ For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode
>This class is no longer maintained since API version 9. You are advised to use [MessageSequence](#messagesequence9).
-Provides APIs for reading and writing data in specific format. During RPC, the sender can use the **write()** method provided by **MessageParcel** to write data in specific format to a **MessageParcel** object. The receiver can use the **read()** method provided by **MessageParcel** to read data in specific format from a **MessageParcel** object. The data formats include basic data types and arrays, IPC objects, interface tokens, and custom sequenceable objects.
+Provides APIs for reading and writing data in specific format.
+
+During RPC, the sender can use the **write()** method provided by **MessageParcel** to write data in specific format to a **MessageParcel** object. The receiver can use the **read()** method provided by **MessageParcel** to read data in specific format from a **MessageParcel** object. The data formats include basic data types and arrays, IPC objects, interface tokens, and custom sequenceable objects.
### create
-create(): MessageParcel
+static create(): MessageParcel
Creates a **MessageParcel** object. This method is a static method.
@@ -3113,13 +3116,13 @@ Creates a **MessageParcel** object. This method is a static method.
**Return value**
- | Type | Description |
- | ------------- | ----------------------------- |
- | MessageParcel | **MessageParcel** object created.|
+| Type | Description |
+| ------------- | ----------------------------- |
+| MessageParcel | **MessageParcel** object created.|
**Example**
- ```
+ ```ts
let data = rpc.MessageParcel.create();
console.log("RpcClient: data is " + data);
```
@@ -3134,7 +3137,7 @@ Reclaims the **MessageParcel** object that is no longer used.
**Example**
- ```
+ ```ts
let reply = rpc.MessageParcel.create();
reply.reclaim();
```
@@ -3149,19 +3152,19 @@ Serializes a remote object and writes it to this **MessageParcel** object.
**Parameters**
- | Name| Type | Mandatory| Description |
- | ------ | ------------------------------- | ---- | --------------------------------------- |
- | object | [IRemoteObject](#iremoteobject) | Yes | Remote object to serialize and write to the **MessageParcel** object.|
+| Name| Type | Mandatory| Description |
+| ------ | ------------------------------- | ---- | --------------------------------------- |
+| object | [IRemoteObject](#iremoteobject) | Yes | Remote object to serialize and write to the **MessageParcel** object.|
**Return value**
- | Type | Description |
- | ------- | ----------------------------------------- |
- | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
+| Type | Description |
+| ------- | ----------------------------------------- |
+| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Example**
- ```
+ ```ts
class MyDeathRecipient {
onRemoteDied() {
console.log("server died");
@@ -3196,13 +3199,13 @@ Reads the remote object from this **MessageParcel** object. You can use this met
**Return value**
- | Type | Description |
- | ------------------------------- | ------------------ |
- | [IRemoteObject](#iremoteobject) | Remote object obtained.|
+| Type | Description |
+| ------------------------------- | ------------------ |
+| [IRemoteObject](#iremoteobject) | Remote object obtained.|
**Example**
- ```
+ ```ts
class MyDeathRecipient {
onRemoteDied() {
console.log("server died");
@@ -3238,19 +3241,19 @@ Writes an interface token to this **MessageParcel** object. The remote object ca
**Parameters**
- | Name| Type | Mandatory| Description |
- | ------ | ------ | ---- | ------------------ |
- | token | string | Yes | Interface token to write.|
+| Name| Type | Mandatory| Description |
+| ------ | ------ | ---- | ------------------ |
+| token | string | Yes | Interface token to write.|
**Return value**
- | Type | Description |
- | ------- | ----------------------------------------- |
- | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
+| Type | Description |
+| ------- | ----------------------------------------- |
+| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Example**
- ```
+ ```ts
let data = rpc.MessageParcel.create();
let result = data.writeInterfaceToken("aaa");
console.log("RpcServer: writeInterfaceToken is " + result);
@@ -3267,13 +3270,13 @@ Reads the interface token from this **MessageParcel** object. The interface toke
**Return value**
- | Type | Description |
- | ------ | ------------------------ |
- | string | Interface token obtained.|
+| Type | Description |
+| ------ | ------------------------ |
+| string | Interface token obtained.|
**Example**
- ```
+ ```ts
class Stub extends rpc.RemoteObject {
onRemoteMessageRequest(code, data, reply, option) {
let interfaceToken = data.readInterfaceToken();
@@ -3283,7 +3286,6 @@ Reads the interface token from this **MessageParcel** object. The interface toke
}
```
-
### getSize
getSize(): number
@@ -3294,19 +3296,18 @@ Obtains the data size of this **MessageParcel** object.
**Return value**
- | Type | Description |
- | ------ | --------------------------------------------- |
- | number | Size of the **MessageParcel** object obtained, in bytes.|
+| Type | Description |
+| ------ | --------------------------------------------- |
+| number | Size of the **MessageParcel** object obtained, in bytes.|
**Example**
- ```
+ ```ts
let data = rpc.MessageParcel.create();
let size = data.getSize();
console.log("RpcClient: size is " + size);
```
-
### getCapacity
getCapacity(): number
@@ -3317,19 +3318,18 @@ Obtains the capacity of this **MessageParcel** object.
**Return value**
- | Type | Description |
- | ------ | --------------------------------------------- |
- | number | **MessageParcel** capacity obtained, in bytes.|
+| Type | Description |
+| ------ | --------------------------------------------- |
+| number | **MessageParcel** capacity obtained, in bytes.|
**Example**
- ```
+ ```ts
let data = rpc.MessageParcel.create();
let result = data.getCapacity();
console.log("RpcClient: capacity is " + result);
```
-
### setSize
setSize(size: number): boolean
@@ -3340,25 +3340,24 @@ Sets the size of data contained in this **MessageParcel** object.
**Parameters**
- | Name| Type | Mandatory| Description |
- | ------ | ------ | ---- | ------------------------------------------- |
- | size | number | Yes | Data size to set, in bytes.|
+| Name| Type | Mandatory| Description |
+| ------ | ------ | ---- | ------------------------------------------- |
+| size | number | Yes | Data size to set, in bytes.|
**Return value**
- | Type | Description |
- | ------- | --------------------------------- |
- | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
+| Type | Description |
+| ------- | --------------------------------- |
+| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Example**
- ```
+ ```ts
let data = rpc.MessageParcel.create();
let setSize = data.setSize(16);
console.log("RpcClient: setSize is " + setSize);
```
-
### setCapacity
setCapacity(size: number): boolean
@@ -3369,25 +3368,24 @@ Sets the storage capacity of this **MessageParcel** object.
**Parameters**
- | Name| Type | Mandatory| Description |
- | ------ | ------ | ---- | ------------------------------------------- |
- | size | number | Yes | Storage capacity to set, in bytes.|
+| Name| Type | Mandatory| Description |
+| ------ | ------ | ---- | ------------------------------------------- |
+| size | number | Yes | Storage capacity to set, in bytes.|
**Return value**
- | Type | Description |
- | ------- | --------------------------------- |
- | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
+| Type | Description |
+| ------- | --------------------------------- |
+| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Example**
- ```
+ ```ts
let data = rpc.MessageParcel.create();
let result = data.setCapacity(100);
console.log("RpcClient: setCapacity is " + result);
```
-
### getWritableBytes
getWritableBytes(): number
@@ -3398,13 +3396,13 @@ Obtains the writable capacity of this **MessageParcel** object.
**Return value**
- | Type | Description |
- | ------ | --------------------------------------------------- |
- | number | **MessageParcel** writable capacity obtained, in bytes.|
+| Type | Description |
+| ------ | --------------------------------------------------- |
+| number | **MessageParcel** writable capacity obtained, in bytes.|
**Example**
- ```
+ ```ts
class Stub extends rpc.RemoteObject {
onRemoteMessageRequest(code, data, reply, option) {
let getWritableBytes = data.getWritableBytes();
@@ -3414,7 +3412,6 @@ Obtains the writable capacity of this **MessageParcel** object.
}
```
-
### getReadableBytes
getReadableBytes(): number
@@ -3425,13 +3422,13 @@ Obtains the readable capacity of this **MessageParcel** object.
**Return value**
- | Type | Description |
- | ------ | --------------------------------------------------- |
- | number | **MessageParcel** object readable capacity, in bytes.|
+| Type | Description |
+| ------ | --------------------------------------------------- |
+| number | **MessageParcel** object readable capacity, in bytes.|
**Example**
- ```
+ ```ts
class Stub extends rpc.RemoteObject {
onRemoteRequest(code, data, reply, option) {
let result = data.getReadableBytes();
@@ -3441,7 +3438,6 @@ Obtains the readable capacity of this **MessageParcel** object.
}
```
-
### getReadPosition
getReadPosition(): number
@@ -3452,19 +3448,18 @@ Obtains the read position of this **MessageParcel** object.
**Return value**
- | Type | Description |
- | ------ | --------------------------------------- |
- | number | Current read position of the **MessageParcel** object.|
+| Type | Description |
+| ------ | --------------------------------------- |
+| number | Current read position of the **MessageParcel** object.|
**Example**
- ```
+ ```ts
let data = rpc.MessageParcel.create();
let readPos = data.getReadPosition();
console.log("RpcClient: readPos is " + readPos);
```
-
### getWritePosition
getWritePosition(): number
@@ -3475,20 +3470,19 @@ Obtains the write position of this **MessageParcel** object.
**Return value**
- | Type | Description |
- | ------ | --------------------------------------- |
- | number | Current write position of the **MessageParcel** object.|
+| Type | Description |
+| ------ | --------------------------------------- |
+| number | Current write position of the **MessageParcel** object.|
**Example**
- ```
+ ```ts
let data = rpc.MessageParcel.create();
data.writeInt(10);
let bwPos = data.getWritePosition();
console.log("RpcClient: bwPos is " + bwPos);
```
-
### rewindRead
rewindRead(pos: number): boolean
@@ -3499,19 +3493,19 @@ Moves the read pointer to the specified position.
**Parameters**
- | Name| Type | Mandatory| Description |
- | ------ | ------ | ---- | ------------------------ |
- | pos | number | Yes | Position from which data is to read.|
+| Name| Type | Mandatory| Description |
+| ------ | ------ | ---- | ------------------------ |
+| pos | number | Yes | Position from which data is to read.|
**Return value**
- | Type | Description |
- | ------- | ------------------------------------------------- |
- | boolean | Returns **true** if the read position changes; returns **false** otherwise.|
+| Type | Description |
+| ------- | ------------------------------------------------- |
+| boolean | Returns **true** if the read position changes; returns **false** otherwise.|
**Example**
- ```
+ ```ts
let data = rpc.MessageParcel.create();
data.writeInt(12);
data.writeString("parcel");
@@ -3522,7 +3516,6 @@ Moves the read pointer to the specified position.
console.log("RpcClient: rewindRead is " + number2);
```
-
### rewindWrite
rewindWrite(pos: number): boolean
@@ -3533,19 +3526,19 @@ Moves the write pointer to the specified position.
**Parameters**
- | Name| Type | Mandatory| Description |
- | ------ | ------ | ---- | ------------------------ |
- | pos | number | Yes | Position from which data is to write.|
+| Name| Type | Mandatory| Description |
+| ------ | ------ | ---- | ------------------------ |
+| pos | number | Yes | Position from which data is to write.|
**Return value**
- | Type | Description |
- | ------- | --------------------------------------------- |
- | boolean | Returns **true** if the write position changes; returns **false** otherwise.|
+| Type | Description |
+| ------- | --------------------------------------------- |
+| boolean | Returns **true** if the write position changes; returns **false** otherwise.|
**Example**
- ```
+ ```ts
let data = rpc.MessageParcel.create();
data.writeInt(4);
data.rewindWrite(0);
@@ -3554,7 +3547,6 @@ Moves the write pointer to the specified position.
console.log("RpcClient: rewindWrite is: " + number);
```
-
### writeByte
writeByte(val: number): boolean
@@ -3565,25 +3557,24 @@ Writes a Byte value to this **MessageParcel** object.
**Parameters**
- | Name| Type | Mandatory| Description |
- | ------ | ------ | ---- | ---------------- |
- | val | number | Yes | Byte value to write.|
+| Name| Type | Mandatory| Description |
+| ------ | ------ | ---- | ---------------- |
+| val | number | Yes | Byte value to write.|
**Return value**
- | Type | Description |
- | ------- | ----------------------------- |
- | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
+| Type | Description |
+| ------- | ----------------------------- |
+| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Example**
- ```
+ ```ts
let data = rpc.MessageParcel.create();
let result = data.writeByte(2);
console.log("RpcClient: writeByte is: " + result);
```
-
### readByte
readByte(): number
@@ -3594,13 +3585,13 @@ Reads the Byte value from this **MessageParcel** object.
**Return value**
- | Type | Description |
- | ------ | ------------ |
- | number | Byte value read.|
+| Type | Description |
+| ------ | ------------ |
+| number | Byte value read.|
**Example**
- ```
+ ```ts
let data = rpc.MessageParcel.create();
let result = data.writeByte(2);
console.log("RpcClient: writeByte is: " + result);
@@ -3608,7 +3599,6 @@ Reads the Byte value from this **MessageParcel** object.
console.log("RpcClient: readByte is: " + ret);
```
-
### writeShort
writeShort(val: number): boolean
@@ -3619,25 +3609,24 @@ Writes a Short int value to this **MessageParcel** object.
**Parameters**
- | Name| Type | Mandatory| Description |
- | ------ | ------ | ---- | ------------------ |
- | val | number | Yes | Short int value to write.|
+| Name| Type | Mandatory| Description |
+| ------ | ------ | ---- | ------------------ |
+| val | number | Yes | Short int value to write.|
**Return value**
- | Type | Description |
- | ------- | ----------------------------- |
- | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
+| Type | Description |
+| ------- | ----------------------------- |
+| boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
**Example**
- ```
+ ```ts
let data = rpc.MessageParcel.create();
let result = data.writeShort(8);
console.log("RpcClient: writeShort is: " + result);
```
-
### readShort
readShort(): number
@@ -3648,13 +3637,13 @@ Reads the Short int value from this **MessageParcel** object.
**Return value**
- | Type | Description |
- | ------ | -------------- |
- | number | Short int value read.|
+| Type | Description |
+| ------ | -------------- |
+| number | Short int value read.|
**Example**
- ```
+ ```ts
let data = rpc.MessageParcel.create();
let result = data.writeShort(8);
console.log("RpcClient: writeShort is: " + result);
@@ -3662,7 +3651,6 @@ Reads the Short int value from this **MessageParcel** object.
console.log("RpcClient: readShort is: " + ret);
```
-
### writeInt
writeInt(val: number): boolean
@@ -3673,25 +3661,24 @@ Writes an Int value to this **MessageParcel** object.
**Parameters**
- | Name| Type | Mandatory| Description |
- | ------ | ------ | ---- | ---------------- |
- | val | number | Yes | Int value to write.|
+| Name| Type | Mandatory| Description |
+| ------ | ------ | ---- | ---------------- |
+| val | number | Yes | Int value to write.|
**Return value**
- | Type | Description |
- | ------- | ----------------------------- |
- | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
+| Type | Description |
+| ------- | ----------------------------- |
+| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Example**
- ```
+ ```ts
let data = rpc.MessageParcel.create();
let result = data.writeInt(10);
console.log("RpcClient: writeInt is " + result);
```
-
### readInt
readInt(): number
@@ -3702,13 +3689,13 @@ Reads the Int value from this **MessageParcel** object.
**Return value**
- | Type | Description |
- | ------ | ------------ |
- | number | Int value read.|
+| Type | Description |
+| ------ | ------------ |
+| number | Int value read.|
**Example**
- ```
+ ```ts
let data = rpc.MessageParcel.create();
let result = data.writeInt(10);
console.log("RpcClient: writeInt is " + result);
@@ -3716,7 +3703,6 @@ Reads the Int value from this **MessageParcel** object.
console.log("RpcClient: readInt is " + ret);
```
-
### writeLong
writeLong(val: number): boolean
@@ -3727,25 +3713,24 @@ Writes a Long int value to this **MessageParcel** object.
**Parameters**
- | Name| Type | Mandatory| Description |
- | ------ | ------ | ---- | ---------------- |
- | val | number | Yes | Long int value to write.|
+| Name| Type | Mandatory| Description |
+| ------ | ------ | ---- | ---------------- |
+| val | number | Yes | Long int value to write.|
**Return value**
- | Type | Description |
- | ------- | --------------------------------- |
- | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
+| Type | Description |
+| ------- | --------------------------------- |
+| boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
**Example**
- ```
+ ```ts
let data = rpc.MessageParcel.create();
let result = data.writeLong(10000);
console.log("RpcClient: writeLong is " + result);
```
-
### readLong
readLong(): number
@@ -3756,13 +3741,13 @@ Reads the Long int value from this **MessageParcel** object.
**Return value**
- | Type | Description |
- | ------ | -------------- |
- | number | Long int value read.|
+| Type | Description |
+| ------ | -------------- |
+| number | Long int value read.|
**Example**
- ```
+ ```ts
let data = rpc.MessageParcel.create();
let result = data.writeLong(10000);
console.log("RpcClient: writeLong is " + result);
@@ -3770,7 +3755,6 @@ Reads the Long int value from this **MessageParcel** object.
console.log("RpcClient: readLong is " + ret);
```
-
### writeFloat
writeFloat(val: number): boolean
@@ -3781,25 +3765,24 @@ Writes a Float value to this **MessageParcel** object.
**Parameters**
- | Name| Type | Mandatory| Description |
- | ------ | ------ | ---- | ---------------- |
- | val | number | Yes | Float value to write.|
+| Name| Type | Mandatory| Description |
+| ------ | ------ | ---- | ---------------- |
+| val | number | Yes | Float value to write.|
**Return value**
- | Type | Description |
- | ------- | --------------------------------- |
- | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
+| Type | Description |
+| ------- | --------------------------------- |
+| boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
**Example**
- ```
+ ```ts
let data = rpc.MessageParcel.create();
let result = data.writeFloat(1.2);
console.log("RpcClient: writeFloat is " + result);
```
-
### readFloat
readFloat(): number
@@ -3810,13 +3793,13 @@ Reads the Float value from this **MessageParcel** object.
**Return value**
- | Type | Description |
- | ------ | ------------ |
- | number | Float value read.|
+| Type | Description |
+| ------ | ------------ |
+| number | Float value read.|
**Example**
- ```
+ ```ts
let data = rpc.MessageParcel.create();
let result = data.writeFloat(1.2);
console.log("RpcClient: writeFloat is " + result);
@@ -3824,7 +3807,6 @@ Reads the Float value from this **MessageParcel** object.
console.log("RpcClient: readFloat is " + ret);
```
-
### writeDouble
writeDouble(val: number): boolean
@@ -3835,25 +3817,24 @@ Writes a Double value to this **MessageParcel** object.
**Parameters**
- | Name| Type | Mandatory| Description |
- | ------ | ------ | ---- | ---------------------- |
- | val | number | Yes | Double value to write.|
+| Name| Type | Mandatory| Description |
+| ------ | ------ | ---- | ---------------------- |
+| val | number | Yes | Double value to write.|
**Return value**
- | Type | Description |
- | ------- | --------------------------------- |
- | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
+| Type | Description |
+| ------- | --------------------------------- |
+| boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
**Example**
- ```
+ ```ts
let data = rpc.MessageParcel.create();
let result = data.writeDouble(10.2);
console.log("RpcClient: writeDouble is " + result);
```
-
### readDouble
readDouble(): number
@@ -3864,13 +3845,13 @@ Reads the Double value from this **MessageParcel** object.
**Return value**
- | Type | Description |
- | ------ | ------------------ |
- | number | Double value read.|
+| Type | Description |
+| ------ | ------------------ |
+| number | Double value read.|
**Example**
- ```
+ ```ts
let data = rpc.MessageParcel.create();
let result = data.writeDouble(10.2);
console.log("RpcClient: writeDouble is " + result);
@@ -3888,25 +3869,24 @@ Writes a Boolean value to this **MessageParcel** object.
**Parameters**
- | Name| Type | Mandatory| Description |
- | ------ | ------- | ---- | ---------------- |
- | val | boolean | Yes | Boolean value to write.|
+| Name| Type | Mandatory| Description |
+| ------ | ------- | ---- | ---------------- |
+| val | boolean | Yes | Boolean value to write.|
**Return value**
- | Type | Description |
- | ------- | --------------------------------- |
- | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
+| Type | Description |
+| ------- | --------------------------------- |
+| boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
**Example**
- ```
+ ```ts
let data = rpc.MessageParcel.create();
let result = data.writeBoolean(false);
console.log("RpcClient: writeBoolean is " + result);
```
-
### readBoolean
readBoolean(): boolean
@@ -3917,13 +3897,13 @@ Reads the Boolean value from this **MessageParcel** object.
**Return value**
- | Type | Description |
- | ------- | -------------------- |
- | boolean | Boolean value read.|
+| Type | Description |
+| ------- | -------------------- |
+| boolean | Boolean value read.|
**Example**
- ```
+ ```ts
let data = rpc.MessageParcel.create();
let result = data.writeBoolean(false);
console.log("RpcClient: writeBoolean is " + result);
@@ -3931,7 +3911,6 @@ Reads the Boolean value from this **MessageParcel** object.
console.log("RpcClient: readBoolean is " + ret);
```
-
### writeChar
writeChar(val: number): boolean
@@ -3942,25 +3921,24 @@ Writes a Char value to this **MessageParcel** object.
**Parameters**
- | Name| Type | Mandatory| Description |
- | ------ | ------ | ---- | -------------------- |
- | val | number | Yes | Char value to write.|
+| Name| Type | Mandatory| Description |
+| ------ | ------ | ---- | -------------------- |
+| val | number | Yes | Char value to write.|
**Return value**
- | Type | Description |
- | ------- | ----------------------------- |
- | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
+| Type | Description |
+| ------- | ----------------------------- |
+| boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
**Example**
- ```
+ ```ts
let data = rpc.MessageParcel.create();
let result = data.writeChar(97);
console.log("RpcClient: writeChar is " + result);
```
-
### readChar
readChar(): number
@@ -3971,13 +3949,13 @@ Reads the Char value from this **MessageParcel** object.
**Return value**
- | Type | Description |
- | ------ | ---------------- |
- | number | Char value read.|
+| Type | Description |
+| ------ | ---------------- |
+| number | Char value read.|
**Example**
- ```
+ ```ts
let data = rpc.MessageParcel.create();
let result = data.writeChar(97);
console.log("RpcClient: writeChar is " + result);
@@ -3985,7 +3963,6 @@ Reads the Char value from this **MessageParcel** object.
console.log("RpcClient: readChar is " + ret);
```
-
### writeString
writeString(val: string): boolean
@@ -3996,25 +3973,24 @@ Writes a string to this **MessageParcel** object.
**Parameters**
- | Name| Type | Mandatory| Description |
- | ------ | ------ | ---- | ----------------------------------------- |
- | val | string | Yes | String to write. The length of the string must be less than 40960 bytes.|
+| Name| Type | Mandatory| Description |
+| ------ | ------ | ---- | ----------------------------------------- |
+| val | string | Yes | String to write. The length of the string must be less than 40960 bytes.|
**Return value**
- | Type | Description |
- | ------- | --------------------------------- |
- | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
+| Type | Description |
+| ------- | --------------------------------- |
+| boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
**Example**
- ```
+ ```ts
let data = rpc.MessageParcel.create();
let result = data.writeString('abc');
console.log("RpcClient: writeString is " + result);
```
-
### readString
readString(): string
@@ -4025,13 +4001,13 @@ Reads the string from this **MessageParcel** object.
**Return value**
- | Type | Description |
- | ------ | -------------- |
- | string | String read.|
+| Type | Description |
+| ------ | -------------- |
+| string | String read.|
**Example**
- ```
+ ```ts
let data = rpc.MessageParcel.create();
let result = data.writeString('abc');
console.log("RpcClient: writeString is " + result);
@@ -4039,7 +4015,6 @@ Reads the string from this **MessageParcel** object.
console.log("RpcClient: readString is " + ret);
```
-
### writeSequenceable
writeSequenceable(val: Sequenceable): boolean
@@ -4050,19 +4025,19 @@ Writes a sequenceable object to this **MessageParcel** object.
**Parameters**
- | Name| Type | Mandatory| Description |
- | ------ | ----------------------------- | ---- | -------------------- |
- | val | [Sequenceable](#sequenceable) | Yes | Sequenceable object to write.|
+| Name| Type | Mandatory| Description |
+| ------ | ----------------------------- | ---- | -------------------- |
+| val | [Sequenceable](#sequenceable) | Yes | Sequenceable object to write.|
**Return value**
- | Type | Description |
- | ------- | --------------------------------- |
- | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
+| Type | Description |
+| ------- | --------------------------------- |
+| boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
**Example**
- ```
+ ```ts
class MySequenceable {
num: number;
str: string;
@@ -4087,7 +4062,6 @@ Writes a sequenceable object to this **MessageParcel** object.
console.log("RpcClient: writeSequenceable is " + result);
```
-
### readSequenceable
readSequenceable(dataIn: Sequenceable): boolean
@@ -4098,19 +4072,19 @@ Reads member variables from this **MessageParcel** object.
**Parameters**
- | Name| Type | Mandatory| Description |
- | ------ | ----------------------------- | ---- | --------------------------------------- |
- | dataIn | [Sequenceable](#sequenceabledeprecated) | Yes | Object that reads member variables from the **MessageParcel** object.|
+| Name| Type | Mandatory| Description |
+| ------ | ----------------------------- | ---- | --------------------------------------- |
+| dataIn | [Sequenceable](#sequenceabledeprecated) | Yes | Object that reads member variables from the **MessageParcel** object.|
**Return value**
- | Type | Description |
- | ------- | ------------------------------------------- |
- | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
+| Type | Description |
+| ------- | ------------------------------------------- |
+| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Example**
- ```
+ ```ts
class MySequenceable {
num: number;
str: string;
@@ -4138,7 +4112,6 @@ Reads member variables from this **MessageParcel** object.
console.log("RpcClient: writeSequenceable is " + result2);
```
-
### writeByteArray
writeByteArray(byteArray: number[]): boolean
@@ -4149,26 +4122,25 @@ Writes a byte array to this **MessageParcel** object.
**Parameters**
- | Name | Type | Mandatory| Description |
- | --------- | -------- | ---- | ------------------ |
- | byteArray | number[] | Yes | Byte array to write.|
+| Name | Type | Mandatory| Description |
+| --------- | -------- | ---- | ------------------ |
+| byteArray | number[] | Yes | Byte array to write.|
**Return value**
- | Type | Description |
- | ------- | --------------------------------- |
- | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
+| Type | Description |
+| ------- | --------------------------------- |
+| boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
**Example**
- ```
+ ```ts
let data = rpc.MessageParcel.create();
let ByteArrayVar = [1, 2, 3, 4, 5];
let result = data.writeByteArray(ByteArrayVar);
console.log("RpcClient: writeByteArray is " + result);
```
-
### readByteArray
readByteArray(dataIn: number[]): void
@@ -4179,13 +4151,13 @@ Reads a byte array from this **MessageParcel** object.
**Parameters**
- | Name| Type | Mandatory| Description |
- | ------ | -------- | ---- | ------------------ |
- | dataIn | number[] | Yes | Byte array to read.|
+| Name| Type | Mandatory| Description |
+| ------ | -------- | ---- | ------------------ |
+| dataIn | number[] | Yes | Byte array to read.|
**Example**
- ```
+ ```ts
let data = rpc.MessageParcel.create();
let ByteArrayVar = [1, 2, 3, 4, 5];
let result = data.writeByteArray(ByteArrayVar);
@@ -4194,7 +4166,6 @@ Reads a byte array from this **MessageParcel** object.
data.readByteArray(array);
```
-
### readByteArray
readByteArray(): number[]
@@ -4205,13 +4176,13 @@ Reads the byte array from this **MessageParcel** object.
**Return value**
- | Type | Description |
- | -------- | -------------- |
- | number[] | Byte array read.|
+| Type | Description |
+| -------- | -------------- |
+| number[] | Byte array read.|
**Example**
- ```
+ ```ts
let data = rpc.MessageParcel.create();
let ByteArrayVar = [1, 2, 3, 4, 5];
let result = data.writeByteArray(ByteArrayVar);
@@ -4220,7 +4191,6 @@ Reads the byte array from this **MessageParcel** object.
console.log("RpcClient: readByteArray is " + array);
```
-
### writeShortArray
writeShortArray(shortArray: number[]): boolean
@@ -4231,25 +4201,24 @@ Writes a short array to this **MessageParcel** object.
**Parameters**
- | Name | Type | Mandatory| Description |
- | ---------- | -------- | ---- | -------------------- |
- | shortArray | number[] | Yes | Short array to write.|
+| Name | Type | Mandatory| Description |
+| ---------- | -------- | ---- | -------------------- |
+| shortArray | number[] | Yes | Short array to write.|
**Return value**
- | Type | Description |
- | ------- | ----------------------------- |
- | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
+| Type | Description |
+| ------- | ----------------------------- |
+| boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
**Example**
- ```
+ ```ts
let data = rpc.MessageParcel.create();
let result = data.writeShortArray([11, 12, 13]);
console.log("RpcClient: writeShortArray is " + result);
```
-
### readShortArray
readShortArray(dataIn: number[]): void
@@ -4260,13 +4229,13 @@ Reads a short array from this **MessageParcel** object.
**Parameters**
- | Name| Type | Mandatory| Description |
- | ------ | -------- | ---- | -------------------- |
- | dataIn | number[] | Yes | Short array to read.|
+| Name| Type | Mandatory| Description |
+| ------ | -------- | ---- | -------------------- |
+| dataIn | number[] | Yes | Short array to read.|
**Example**
- ```
+ ```ts
let data = rpc.MessageParcel.create();
let result = data.writeShortArray([11, 12, 13]);
console.log("RpcClient: writeShortArray is " + result);
@@ -4274,7 +4243,6 @@ Reads a short array from this **MessageParcel** object.
data.readShortArray(array);
```
-
### readShortArray
readShortArray(): number[]
@@ -4285,13 +4253,13 @@ Reads the short array from this **MessageParcel** object.
**Return value**
- | Type | Description |
- | -------- | ---------------- |
- | number[] | Short array read.|
+| Type | Description |
+| -------- | ---------------- |
+| number[] | Short array read.|
**Example**
- ```
+ ```ts
let data = rpc.MessageParcel.create();
let result = data.writeShortArray([11, 12, 13]);
console.log("RpcClient: writeShortArray is " + result);
@@ -4299,7 +4267,6 @@ Reads the short array from this **MessageParcel** object.
console.log("RpcClient: readShortArray is " + array);
```
-
### writeIntArray
writeIntArray(intArray: number[]): boolean
@@ -4310,25 +4277,24 @@ Writes an integer array to this **MessageParcel** object.
**Parameters**
- | Name | Type | Mandatory| Description |
- | -------- | -------- | ---- | ------------------ |
- | intArray | number[] | Yes | Integer array to write.|
+| Name | Type | Mandatory| Description |
+| -------- | -------- | ---- | ------------------ |
+| intArray | number[] | Yes | Integer array to write.|
**Return value**
- | Type | Description |
- | ------- | ----------------------------- |
- | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
+| Type | Description |
+| ------- | ----------------------------- |
+| boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
**Example**
- ```
+ ```ts
let data = rpc.MessageParcel.create();
let result = data.writeIntArray([100, 111, 112]);
console.log("RpcClient: writeIntArray is " + result);
```
-
### readIntArray
readIntArray(dataIn: number[]): void
@@ -4339,13 +4305,13 @@ Reads an integer array from this **MessageParcel** object.
**Parameters**
- | Name| Type | Mandatory| Description |
- | ------ | -------- | ---- | ------------------ |
- | dataIn | number[] | Yes | Integer array to read.|
+| Name| Type | Mandatory| Description |
+| ------ | -------- | ---- | ------------------ |
+| dataIn | number[] | Yes | Integer array to read.|
**Example**
- ```
+ ```ts
let data = rpc.MessageParcel.create();
let result = data.writeIntArray([100, 111, 112]);
console.log("RpcClient: writeIntArray is " + result);
@@ -4353,7 +4319,6 @@ Reads an integer array from this **MessageParcel** object.
data.readIntArray(array);
```
-
### readIntArray
readIntArray(): number[]
@@ -4364,13 +4329,13 @@ Reads the integer array from this **MessageParcel** object.
**Return value**
- | Type | Description |
- | -------- | -------------- |
- | number[] | Integer array read.|
+| Type | Description |
+| -------- | -------------- |
+| number[] | Integer array read.|
**Example**
- ```
+ ```ts
let data = rpc.MessageParcel.create();
let result = data.writeIntArray([100, 111, 112]);
console.log("RpcClient: writeIntArray is " + result);
@@ -4378,7 +4343,6 @@ Reads the integer array from this **MessageParcel** object.
console.log("RpcClient: readIntArray is " + array);
```
-
### writeLongArray
writeLongArray(longArray: number[]): boolean
@@ -4389,25 +4353,24 @@ Writes a long array to this **MessageParcel** object.
**Parameters**
- | Name | Type | Mandatory| Description |
- | --------- | -------- | ---- | -------------------- |
- | longArray | number[] | Yes | Long array to write.|
+| Name | Type | Mandatory| Description |
+| --------- | -------- | ---- | -------------------- |
+| longArray | number[] | Yes | Long array to write.|
**Return value**
- | Type | Description |
- | ------- | ----------------------------- |
- | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
+| Type | Description |
+| ------- | ----------------------------- |
+| boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
**Example**
- ```
+ ```ts
let data = rpc.MessageParcel.create();
let result = data.writeLongArray([1111, 1112, 1113]);
console.log("RpcClient: writeLongArray is " + result);
```
-
### readLongArray
readLongArray(dataIn: number[]): void
@@ -4418,13 +4381,13 @@ Reads a long array from this **MessageParcel** object.
**Parameters**
- | Name| Type | Mandatory| Description |
- | ------ | -------- | ---- | -------------------- |
- | dataIn | number[] | Yes | Long array to read.|
+| Name| Type | Mandatory| Description |
+| ------ | -------- | ---- | -------------------- |
+| dataIn | number[] | Yes | Long array to read.|
**Example**
- ```
+ ```ts
let data = rpc.MessageParcel.create();
let result = data.writeLongArray([1111, 1112, 1113]);
console.log("RpcClient: writeLongArray is " + result);
@@ -4432,7 +4395,6 @@ Reads a long array from this **MessageParcel** object.
data.readLongArray(array);
```
-
### readLongArray
readLongArray(): number[]
@@ -4443,13 +4405,13 @@ Reads the long array from this **MessageParcel** object.
**Return value**
- | Type | Description |
- | -------- | ---------------- |
- | number[] | Long array read.|
+| Type | Description |
+| -------- | ---------------- |
+| number[] | Long array read.|
**Example**
- ```
+ ```ts
let data = rpc.MessageParcel.create();
let result = data.writeLongArray([1111, 1112, 1113]);
console.log("RpcClient: writeLongArray is " + result);
@@ -4457,7 +4419,6 @@ Reads the long array from this **MessageParcel** object.
console.log("RpcClient: readLongArray is " + array);
```
-
### writeFloatArray
writeFloatArray(floatArray: number[]): boolean
@@ -4468,25 +4429,24 @@ Writes a FloatArray to this **MessageParcel** object.
**Parameters**
- | Name| Type| Mandatory| Description|
- | ---------- | -------- | ---- | --- |
- | floatArray | number[] | Yes | Floating-point array to write. The system processes Float data as that of the Double type. Therefore, the total number of bytes occupied by a FloatArray must be calculated as the Double type.|
+| Name| Type| Mandatory| Description|
+| ---------- | -------- | ---- | --- |
+| floatArray | number[] | Yes | Floating-point array to write. The system processes Float data as that of the Double type. Therefore, the total number of bytes occupied by a FloatArray must be calculated as the Double type.|
**Return value**
- | Type | Description |
- | ------- | ----------------------------- |
- | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
+| Type | Description |
+| ------- | ----------------------------- |
+| boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
**Example**
- ```
+ ```ts
let data = rpc.MessageParcel.create();
let result = data.writeFloatArray([1.2, 1.3, 1.4]);
console.log("RpcClient: writeFloatArray is " + result);
```
-
### readFloatArray
readFloatArray(dataIn: number[]): void
@@ -4497,13 +4457,13 @@ Reads a FloatArray from this **MessageParcel** object.
**Parameters**
- | Name| Type| Mandatory| Description|
- | ------ | -------- | ---- | ------ |
- | dataIn | number[] | Yes | Floating-point array to read. The system processes Float data as that of the Double type. Therefore, the total number of bytes occupied by a FloatArray must be calculated as the Double type.|
+| Name| Type| Mandatory| Description|
+| ------ | -------- | ---- | ------ |
+| dataIn | number[] | Yes | Floating-point array to read. The system processes Float data as that of the Double type. Therefore, the total number of bytes occupied by a FloatArray must be calculated as the Double type.|
**Example**
- ```
+ ```ts
let data = rpc.MessageParcel.create();
let result = data.writeFloatArray([1.2, 1.3, 1.4]);
console.log("RpcClient: writeFloatArray is " + result);
@@ -4511,7 +4471,6 @@ Reads a FloatArray from this **MessageParcel** object.
data.readFloatArray(array);
```
-
### readFloatArray
readFloatArray(): number[]
@@ -4522,13 +4481,13 @@ Reads the FloatArray from this **MessageParcel** object.
**Return value**
- | Type | Description |
- | -------- | -------------- |
- | number[] | FloatArray read.|
+| Type | Description |
+| -------- | -------------- |
+| number[] | FloatArray read.|
**Example**
- ```
+ ```ts
let data = rpc.MessageParcel.create();
let result = data.writeFloatArray([1.2, 1.3, 1.4]);
console.log("RpcClient: writeFloatArray is " + result);
@@ -4536,7 +4495,6 @@ Reads the FloatArray from this **MessageParcel** object.
console.log("RpcClient: readFloatArray is " + array);
```
-
### writeDoubleArray
writeDoubleArray(doubleArray: number[]): boolean
@@ -4547,25 +4505,24 @@ Writes a DoubleArray to this **MessageParcel** object.
**Parameters**
- | Name | Type | Mandatory| Description |
- | ----------- | -------- | ---- | ------------------------ |
- | doubleArray | number[] | Yes | DoubleArray to write.|
+| Name | Type | Mandatory| Description |
+| ----------- | -------- | ---- | ------------------------ |
+| doubleArray | number[] | Yes | DoubleArray to write.|
**Return value**
- | Type | Description |
- | ------- | ----------------------------- |
- | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
+| Type | Description |
+| ------- | ----------------------------- |
+| boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
**Example**
- ```
+ ```ts
let data = rpc.MessageParcel.create();
let result = data.writeDoubleArray([11.1, 12.2, 13.3]);
console.log("RpcClient: writeDoubleArray is " + result);
```
-
### readDoubleArray
readDoubleArray(dataIn: number[]): void
@@ -4576,13 +4533,13 @@ Reads a DoubleArray from this **MessageParcel** object.
**Parameters**
- | Name| Type | Mandatory| Description |
- | ------ | -------- | ---- | ------------------------ |
- | dataIn | number[] | Yes | DoubleArray to read.|
+| Name| Type | Mandatory| Description |
+| ------ | -------- | ---- | ------------------------ |
+| dataIn | number[] | Yes | DoubleArray to read.|
**Example**
- ```
+ ```ts
let data = rpc.MessageParcel.create();
let result = data.writeDoubleArray([11.1, 12.2, 13.3]);
console.log("RpcClient: writeDoubleArray is " + result);
@@ -4590,7 +4547,6 @@ Reads a DoubleArray from this **MessageParcel** object.
data.readDoubleArray(array);
```
-
### readDoubleArray
readDoubleArray(): number[]
@@ -4601,13 +4557,13 @@ Reads the DoubleArray from this **MessageParcel** object.
**Return value**
- | Type | Description |
- | -------- | -------------------- |
- | number[] | DoubleArray read.|
+| Type | Description |
+| -------- | -------------------- |
+| number[] | DoubleArray read.|
**Example**
- ```
+ ```ts
let data = rpc.MessageParcel.create();
let result = data.writeDoubleArray([11.1, 12.2, 13.3]);
console.log("RpcClient: writeDoubleArray is " + result);
@@ -4615,7 +4571,6 @@ Reads the DoubleArray from this **MessageParcel** object.
console.log("RpcClient: readDoubleArray is " + array);
```
-
### writeBooleanArray
writeBooleanArray(booleanArray: boolean[]): boolean
@@ -4626,25 +4581,24 @@ Writes a Boolean array to this **MessageParcel** object.
**Parameters**
- | Name | Type | Mandatory| Description |
- | ------------ | --------- | ---- | ------------------ |
- | booleanArray | boolean[] | Yes | Boolean array to write.|
+| Name | Type | Mandatory| Description |
+| ------------ | --------- | ---- | ------------------ |
+| booleanArray | boolean[] | Yes | Boolean array to write.|
**Return value**
- | Type | Description |
- | ------- | --------------------------------- |
- | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
+| Type | Description |
+| ------- | --------------------------------- |
+| boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
**Example**
- ```
+ ```ts
let data = rpc.MessageParcel.create();
let result = data.writeBooleanArray([false, true, false]);
console.log("RpcClient: writeBooleanArray is " + result);
```
-
### readBooleanArray
readBooleanArray(dataIn: boolean[]): void
@@ -4655,13 +4609,13 @@ Reads a Boolean array from this **MessageParcel** object.
**Parameters**
- | Name| Type | Mandatory| Description |
- | ------ | --------- | ---- | ------------------ |
- | dataIn | boolean[] | Yes | Boolean array to read.|
+| Name| Type | Mandatory| Description |
+| ------ | --------- | ---- | ------------------ |
+| dataIn | boolean[] | Yes | Boolean array to read.|
**Example**
- ```
+ ```ts
let data = rpc.MessageParcel.create();
let result = data.writeBooleanArray([false, true, false]);
console.log("RpcClient: writeBooleanArray is " + result);
@@ -4669,7 +4623,6 @@ Reads a Boolean array from this **MessageParcel** object.
data.readBooleanArray(array);
```
-
### readBooleanArray
readBooleanArray(): boolean[]
@@ -4680,13 +4633,13 @@ Reads the Boolean array from this **MessageParcel** object.
**Return value**
- | Type | Description |
- | --------- | -------------- |
- | boolean[] | Boolean array read.|
+| Type | Description |
+| --------- | -------------- |
+| boolean[] | Boolean array read.|
**Example**
- ```
+ ```ts
let data = rpc.MessageParcel.create();
let result = data.writeBooleanArray([false, true, false]);
console.log("RpcClient: writeBooleanArray is " + result);
@@ -4694,7 +4647,6 @@ Reads the Boolean array from this **MessageParcel** object.
console.log("RpcClient: readBooleanArray is " + array);
```
-
### writeCharArray
writeCharArray(charArray: number[]): boolean
@@ -4705,25 +4657,24 @@ Writes a character array to this **MessageParcel** object.
**Parameters**
- | Name | Type | Mandatory| Description |
- | --------- | -------- | ---- | ---------------------- |
- | charArray | number[] | Yes | Character array to write.|
+| Name | Type | Mandatory| Description |
+| --------- | -------- | ---- | ---------------------- |
+| charArray | number[] | Yes | Character array to write.|
**Return value**
- | Type | Description |
- | ------- | --------------------------------- |
- | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
+| Type | Description |
+| ------- | --------------------------------- |
+| boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
**Example**
- ```
+ ```ts
let data = rpc.MessageParcel.create();
let result = data.writeCharArray([97, 98, 88]);
console.log("RpcClient: writeCharArray is " + result);
```
-
### readCharArray
readCharArray(dataIn: number[]): void
@@ -4734,13 +4685,13 @@ Reads a character array from this **MessageParcel** object.
**Parameters**
- | Name| Type | Mandatory| Description |
- | ------ | -------- | ---- | ---------------------- |
- | dataIn | number[] | Yes | Character array to read.|
+| Name| Type | Mandatory| Description |
+| ------ | -------- | ---- | ---------------------- |
+| dataIn | number[] | Yes | Character array to read.|
**Example**
- ```
+ ```ts
let data = rpc.MessageParcel.create();
let result = data.writeCharArray([97, 98, 99]);
console.log("RpcClient: writeCharArray is " + result);
@@ -4748,7 +4699,6 @@ Reads a character array from this **MessageParcel** object.
data.readCharArray(array);
```
-
### readCharArray
readCharArray(): number[]
@@ -4759,13 +4709,13 @@ Reads the character array from this **MessageParcel** object.
**Return value**
- | Type | Description |
- | -------- | ------------------ |
- | number[] | Character array read.|
+| Type | Description |
+| -------- | ------------------ |
+| number[] | Character array read.|
**Example**
- ```
+ ```ts
let data = rpc.MessageParcel.create();
let result = data.writeCharArray([97, 98, 99]);
console.log("RpcClient: writeCharArray is " + result);
@@ -4773,7 +4723,6 @@ Reads the character array from this **MessageParcel** object.
console.log("RpcClient: readCharArray is " + array);
```
-
### writeStringArray
writeStringArray(stringArray: string[]): boolean
@@ -4784,25 +4733,24 @@ Writes a string array to this **MessageParcel** object.
**Parameters**
- | Name | Type | Mandatory| Description|
- | ----------- | -------- | ---- | ---------------- |
- | stringArray | string[] | Yes | String array to write. The length of a single element in the array must be less than 40960 bytes.|
+| Name | Type | Mandatory| Description|
+| ----------- | -------- | ---- | ---------------- |
+| stringArray | string[] | Yes | String array to write. The length of a single element in the array must be less than 40960 bytes.|
**Return value**
- | Type | Description|
- | ------- | --------------------------------- |
- | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
+| Type | Description|
+| ------- | --------------------------------- |
+| boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
**Example**
- ```
+ ```ts
let data = rpc.MessageParcel.create();
let result = data.writeStringArray(["abc", "def"]);
console.log("RpcClient: writeStringArray is " + result);
```
-
### readStringArray
readStringArray(dataIn: string[]): void
@@ -4813,13 +4761,13 @@ Reads a string array from this **MessageParcel** object.
**Parameters**
- | Name| Type | Mandatory| Description |
- | ------ | -------- | ---- | -------------------- |
- | dataIn | string[] | Yes | String array to read.|
+| Name| Type | Mandatory| Description |
+| ------ | -------- | ---- | -------------------- |
+| dataIn | string[] | Yes | String array to read.|
**Example**
- ```
+ ```ts
let data = rpc.MessageParcel.create();
let result = data.writeStringArray(["abc", "def"]);
console.log("RpcClient: writeStringArray is " + result);
@@ -4827,7 +4775,6 @@ Reads a string array from this **MessageParcel** object.
data.readStringArray(array);
```
-
### readStringArray
readStringArray(): string[]
@@ -4838,13 +4785,13 @@ Reads the string array from this **MessageParcel** object.
**Return value**
- | Type | Description |
- | -------- | ---------------- |
- | string[] | String array read.|
+| Type | Description |
+| -------- | ---------------- |
+| string[] | String array read.|
**Example**
- ```
+ ```ts
let data = rpc.MessageParcel.create();
let result = data.writeStringArray(["abc", "def"]);
console.log("RpcClient: writeStringArray is " + result);
@@ -4852,7 +4799,6 @@ Reads the string array from this **MessageParcel** object.
console.log("RpcClient: readStringArray is " + array);
```
-
### writeNoException8+
writeNoException(): void
@@ -4863,7 +4809,7 @@ Writes information to this **MessageParcel** object indicating that no exception
**Example**
- ```
+ ```ts
class MyDeathRecipient {
onRemoteDied() {
console.log("server died");
@@ -4905,7 +4851,9 @@ Reads the exception information from this **MessageParcel** object.
**Example**
- ```
+ Obtain the service.
+
+ ```ts
import FA from "@ohos.ability.featureAbility";
let proxy;
let connect = {
@@ -4925,6 +4873,11 @@ Reads the exception information from this **MessageParcel** object.
"abilityName": "com.ohos.server.MainAbility",
};
FA.connectAbility(want, connect);
+ ```
+
+The proxy object in the **onConnect** callback can be assigned a value only after the ability is connected asynchronously. Then, **sendMessageRequest()** of the proxy object is called to send a message.
+
+ ```ts
let option = new rpc.MessageOption();
let data = rpc.MessageParcel.create();
let reply = rpc.MessageParcel.create();
@@ -4959,19 +4912,19 @@ Writes a sequenceable array to this **MessageParcel** object.
**Parameters**
- | Name | Type | Mandatory| Description |
- | ----------------- | -------------- | ---- | -------------------------- |
- | sequenceableArray | Sequenceable[] | Yes | Sequenceable array to write.|
+| Name | Type | Mandatory| Description |
+| ----------------- | -------------- | ---- | -------------------------- |
+| sequenceableArray | Sequenceable[] | Yes | Sequenceable array to write.|
**Return value**
- | Type | Description |
- | ------- | --------------------------------- |
- | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
+| Type | Description |
+| ------- | --------------------------------- |
+| boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
**Example**
- ```
+ ```ts
class MySequenceable {
num: number;
str: string;
@@ -4999,7 +4952,6 @@ Writes a sequenceable array to this **MessageParcel** object.
console.log("RpcClient: writeSequenceableArray is " + result);
```
-
### readSequenceableArray8+
readSequenceableArray(sequenceableArray: Sequenceable[]): void
@@ -5010,13 +4962,13 @@ Reads a sequenceable array from this **MessageParcel** object.
**Parameters**
- | Name | Type | Mandatory| Description |
- | ----------------- | -------------- | ---- | -------------------------- |
- | sequenceableArray | Sequenceable[] | Yes | Sequenceable array to read.|
+| Name | Type | Mandatory| Description |
+| ----------------- | -------------- | ---- | -------------------------- |
+| sequenceableArray | Sequenceable[] | Yes | Sequenceable array to read.|
**Example**
- ```
+ ```ts
class MySequenceable {
num: number;
str: string;
@@ -5046,7 +4998,6 @@ Reads a sequenceable array from this **MessageParcel** object.
data.readSequenceableArray(b);
```
-
### writeRemoteObjectArray8+
writeRemoteObjectArray(objectArray: IRemoteObject[]): boolean
@@ -5057,19 +5008,19 @@ Writes an array of **IRemoteObject** objects to this **MessageParcel** object.
**Parameters**
- | Name | Type | Mandatory| Description|
- | ----------- | --------------- | ---- | ----- |
- | objectArray | IRemoteObject[] | Yes | Array of **IRemoteObject** objects to write.|
+| Name | Type | Mandatory| Description|
+| ----------- | --------------- | ---- | ----- |
+| objectArray | IRemoteObject[] | Yes | Array of **IRemoteObject** objects to write.|
**Return value**
- | Type | Description |
- | ------- | -------------------------------------------------------------------------------------------------------------------- |
- | boolean | Returns **true** if the operation is successful; returns **false** if the operation fails or if the **IRemoteObject** array is null.|
+| Type | Description |
+| ------- | -------------------------------------------------------------------------------------------------------------------- |
+| boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
**Example**
- ```
+ ```ts
class MyDeathRecipient {
onRemoteDied() {
console.log("server died");
@@ -5099,7 +5050,6 @@ Writes an array of **IRemoteObject** objects to this **MessageParcel** object.
console.log("RpcClient: writeRemoteObjectArray is " + result);
```
-
### readRemoteObjectArray8+
readRemoteObjectArray(objects: IRemoteObject[]): void
@@ -5110,13 +5060,13 @@ Reads an **IRemoteObject** array from this **MessageParcel** object.
**Parameters**
- | Name | Type | Mandatory| Description|
- | ------- | --------------- | ---- | --------- |
- | objects | IRemoteObject[] | Yes | **IRemoteObject** array to read.|
+| Name | Type | Mandatory| Description|
+| ------- | --------------- | ---- | --------- |
+| objects | IRemoteObject[] | Yes | **IRemoteObject** array to read.|
**Example**
- ```
+ ```ts
class MyDeathRecipient {
onRemoteDied() {
console.log("server died");
@@ -5147,7 +5097,6 @@ Reads an **IRemoteObject** array from this **MessageParcel** object.
data.readRemoteObjectArray(b);
```
-
### readRemoteObjectArray8+
readRemoteObjectArray(): IRemoteObject[]
@@ -5158,13 +5107,13 @@ Reads the **IRemoteObject** array from this **MessageParcel** object.
**Return value**
- | Type| Description|
- | --------------- | -------- |
- | IRemoteObject[] | **IRemoteObject** object array obtained.|
+| Type| Description|
+| --------------- | -------- |
+| IRemoteObject[] | **IRemoteObject** object array obtained.|
**Example**
- ```
+ ```ts
class MyDeathRecipient {
onRemoteDied() {
console.log("server died");
@@ -5196,78 +5145,75 @@ Reads the **IRemoteObject** array from this **MessageParcel** object.
console.log("RpcClient: readRemoteObjectArray is " + b);
```
-
### closeFileDescriptor8+
static closeFileDescriptor(fd: number): void
-Closes a file descriptor.
+Closes a file descriptor. This API is a static method.
**System capability**: SystemCapability.Communication.IPC.Core
**Parameters**
- | Name| Type | Mandatory| Description |
- | ------ | ------ | ---- | -------------------- |
- | fd | number | Yes | File descriptor to close.|
+| Name| Type | Mandatory| Description |
+| ------ | ------ | ---- | -------------------- |
+| fd | number | Yes | File descriptor to close.|
**Example**
- ```
+ ```ts
import fileio from '@ohos.fileio';
let filePath = "path/to/file";
let fd = fileio.openSync(filePath, 0o2| 0o100, 0o666);
rpc.MessageParcel.closeFileDescriptor(fd);
```
-
### dupFileDescriptor8+
static dupFileDescriptor(fd: number) :number
-Duplicates a file descriptor.
+Duplicates a file descriptor. This API is a static method.
**System capability**: SystemCapability.Communication.IPC.Core
**Parameters**
- | Name| Type | Mandatory| Description |
- | ------ | ------ | ---- | ------------------------ |
- | fd | number | Yes | File descriptor to duplicate.|
+| Name| Type | Mandatory| Description |
+| ------ | ------ | ---- | ------------------------ |
+| fd | number | Yes | File descriptor to duplicate.|
**Return value**
- | Type | Description |
- | ------ | -------------------- |
- | number | New file descriptor.|
+| Type | Description |
+| ------ | -------------------- |
+| number | New file descriptor.|
**Example**
- ```
+ ```ts
import fileio from '@ohos.fileio';
let filePath = "path/to/file";
let fd = fileio.openSync(filePath, 0o2| 0o100, 0o666);
let newFd = rpc.MessageParcel.dupFileDescriptor(fd);
```
-
### containFileDescriptors8+
containFileDescriptors(): boolean
-Checks whether this **MessageParcel** object contains a file descriptor.
+Checks whether this **MessageParcel** object contains file descriptors.
**System capability**: SystemCapability.Communication.IPC.Core
**Return value**
- | Type | Description |
- | ------- | ------------------------------------------------------------------ |
- | boolean | Returns **true** if the **MessageParcel** object contains a file descriptor; returns **false** otherwise.|
+| Type | Description |
+| ------- | ------------------------------------------------------------------ |
+| boolean |Returns **true** if the **MessageParcel** object contains file descriptors; returns **false** otherwise.|
**Example**
- ```
+ ```ts
import fileio from '@ohos.fileio';
let parcel = new rpc.MessageParcel();
let filePath = "path/to/file";
@@ -5279,7 +5225,6 @@ Checks whether this **MessageParcel** object contains a file descriptor.
console.log("RpcTest: parcel after write fd containFd result is : " + containFD);
```
-
### writeFileDescriptor8+
writeFileDescriptor(fd: number): boolean
@@ -5290,19 +5235,19 @@ Writes a file descriptor to this **MessageParcel** object.
**Parameters**
- | Name| Type | Mandatory| Description |
- | ------ | ------ | ---- | ------------ |
- | fd | number | Yes | File descriptor to write.|
+| Name| Type | Mandatory| Description |
+| ------ | ------ | ---- | ------------ |
+| fd | number | Yes | File descriptor to write.|
**Return value**
- | Type | Description |
- | ------- | ----------------------------------------- |
- | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
+| Type | Description |
+| ------- | ----------------------------------------- |
+| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Example**
- ```
+ ```ts
import fileio from '@ohos.fileio';
let parcel = new rpc.MessageParcel();
let filePath = "path/to/file";
@@ -5311,7 +5256,6 @@ Writes a file descriptor to this **MessageParcel** object.
console.log("RpcTest: parcel writeFd result is : " + writeResult);
```
-
### readFileDescriptor8+
readFileDescriptor(): number
@@ -5322,13 +5266,13 @@ Reads the file descriptor from this **MessageParcel** object.
**Return value**
- | Type | Description |
- | ------ | ---------------- |
- | number | File descriptor read.|
+| Type | Description |
+| ------ | ---------------- |
+| number | File descriptor read.|
**Example**
- ```
+ ```ts
import fileio from '@ohos.fileio';
let parcel = new rpc.MessageParcel();
let filePath = "path/to/file";
@@ -5338,7 +5282,6 @@ Reads the file descriptor from this **MessageParcel** object.
console.log("RpcTest: parcel read fd is : " + readFD);
```
-
### writeAshmem8+
writeAshmem(ashmem: Ashmem): boolean
@@ -5349,26 +5292,25 @@ Writes an anonymous shared object to this **MessageParcel** object.
**Parameters**
- | Name| Type | Mandatory| Description |
- | ------ | ------ | ---- | ----------------------------------- |
- | ashmem | Ashmem | Yes | Anonymous shared object to write.|
+| Name| Type | Mandatory| Description |
+| ------ | ------ | ---- | ----------------------------------- |
+| ashmem | Ashmem | Yes | Anonymous shared object to write.|
**Return value**
- | Type | Description |
- | ------- | -------------------------------------------------------------------- |
- | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
+| Type | Description |
+| ------- | -------------------------------------------------------------------- |
+| boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
**Example**
- ```
+ ```ts
let parcel = new rpc.MessageParcel();
let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024);
let isWriteSuccess = parcel.writeAshmem(ashmem);
console.log("RpcTest: write ashmem to result is : " + isWriteSuccess);
```
-
### readAshmem8+
readAshmem(): Ashmem
@@ -5379,13 +5321,13 @@ Reads the anonymous shared object from this **MessageParcel** object.
**Return value**
- | Type | Description |
- | ------ | ------------------ |
- | Ashmem | Anonymous share object obtained.|
+| Type | Description |
+| ------ | ------------------ |
+| Ashmem | Anonymous share object obtained.|
**Example**
- ```
+ ```ts
let parcel = new rpc.MessageParcel();
let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024);
let isWriteSuccess = parcel.writeAshmem(ashmem);
@@ -5394,7 +5336,6 @@ Reads the anonymous shared object from this **MessageParcel** object.
console.log("RpcTest: read ashmem to result is : " + readAshmem);
```
-
### getRawDataCapacity8+
getRawDataCapacity(): number
@@ -5405,19 +5346,18 @@ Obtains the maximum amount of raw data that can be held by this **MessageParcel*
**Return value**
- | Type | Description |
- | ------ | ---------------------------------------------------------- |
- | number | 128 MB, which is the maximum amount of raw data that can be held by this **MessageParcel** object.|
+| Type | Description |
+| ------ | ---------------------------------------------------------- |
+| number | 128 MB, which is the maximum amount of raw data that can be held by this **MessageParcel** object.|
**Example**
- ```
+ ```ts
let parcel = new rpc.MessageParcel();
let result = parcel.getRawDataCapacity();
console.log("RpcTest: parcel get RawDataCapacity result is : " + result);
```
-
### writeRawData8+
writeRawData(rawData: number[], size: number): boolean
@@ -5428,27 +5368,26 @@ Writes raw data to this **MessageParcel** object.
**Parameters**
- | Name | Type | Mandatory| Description |
- | ------- | -------- | ---- | ---------------------------------- |
- | rawData | number[] | Yes | Raw data to write. |
- | size | number | Yes | Size of the raw data, in bytes.|
+| Name | Type | Mandatory| Description |
+| ------- | -------- | ---- | ---------------------------------- |
+| rawData | number[] | Yes | Raw data to write. |
+| size | number | Yes | Size of the raw data, in bytes.|
**Return value**
- | Type | Description |
- | ------- | ----------------------------------------- |
- | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
+| Type | Description |
+| ------- | ----------------------------------------- |
+| boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
**Example**
- ```
+ ```ts
let parcel = new rpc.MessageParcel();
let arr = [1, 2, 3, 4, 5];
let isWriteSuccess = parcel.writeRawData(arr, arr.length);
console.log("RpcTest: parcel write raw data result is : " + isWriteSuccess);
```
-
### readRawData8+
readRawData(size: number): number[]
@@ -5459,19 +5398,19 @@ Reads raw data from this **MessageParcel** object.
**Parameters**
- | Name| Type | Mandatory| Description |
- | ------ | ------ | ---- | ------------------------ |
- | size | number | Yes | Size of the raw data to read.|
+| Name| Type | Mandatory| Description |
+| ------ | ------ | ---- | ------------------------ |
+| size | number | Yes | Size of the raw data to read.|
**Return value**
- | Type | Description |
- | -------- | ------------------------------ |
- | number[] | Raw data obtained, in bytes.|
+| Type | Description |
+| -------- | ------------------------------ |
+| number[] | Raw data obtained, in bytes.|
**Example**
- ```
+ ```ts
let parcel = new rpc.MessageParcel();
let arr = [1, 2, 3, 4, 5];
let isWriteSuccess = parcel.writeRawData(arr, arr.length);
@@ -5480,7 +5419,6 @@ Reads raw data from this **MessageParcel** object.
console.log("RpcTest: parcel read raw data result is : " + result);
```
-
## Parcelable9+
Writes an object to a **MessageSequence** and reads it from the **MessageSequence** during IPC.
@@ -5495,19 +5433,18 @@ Marshals this **Parcelable** object into a **MessageSequence** object.
**Parameters**
- | Name | Type | Mandatory| Description |
- | ------- | --------------- | ---- | ------------------------------------------- |
- | dataOut | MessageSequence | Yes | **MessageSequence** object to which the **Parcelable** object is to be marshaled.|
+| Name | Type | Mandatory| Description |
+| ------- | --------------- | ---- | ------------------------------------------- |
+| dataOut | MessageSequence | Yes | **MessageSequence** object to which the **Parcelable** object is to be marshaled.|
**Return value**
- | Type | Description |
- | ------- | ----------------------------------------- |
- | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
-
+| Type | Description |
+| ------- | ----------------------------------------- |
+| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Example**
- ```
+ ```ts
class MyParcelable {
num: number;
str: string;
@@ -5535,7 +5472,6 @@ Marshals this **Parcelable** object into a **MessageSequence** object.
console.log("RpcClient: readParcelable is " + result2);
```
-
### unmarshalling
unmarshalling(dataIn: MessageSequence): boolean
@@ -5546,19 +5482,19 @@ Unmarshals this **Parcelable** object from a **MessageSequence** object.
**Parameters**
- | Name| Type | Mandatory| Description |
- | ------ | --------------- | ---- | ----------------------------------------------- |
- | dataIn | MessageSequence | Yes | **MessageSequence** object from which the **Parcelable** object is to be unmarshaled.|
+| Name| Type | Mandatory| Description |
+| ------ | --------------- | ---- | ----------------------------------------------- |
+| dataIn | MessageSequence | Yes | **MessageSequence** object from which the **Parcelable** object is to be unmarshaled.|
**Return value**
- | Type | Description |
- | ------- | --------------------------------------------- |
- | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
+| Type | Description |
+| ------- | --------------------------------------------- |
+| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Example**
- ```
+ ```ts
class MyParcelable {
num: number;
str: string;
@@ -5586,7 +5522,6 @@ Unmarshals this **Parcelable** object from a **MessageSequence** object.
console.log("RpcClient: readParcelable is " + result2);
```
-
## Sequenceable(deprecated)
>This class is no longer maintained since API version 9. You are advised to use the [Parcelable](#parcelable9).
@@ -5603,19 +5538,18 @@ Marshals the sequenceable object into a **MessageParcel** object.
**Parameters**
- | Name | Type | Mandatory| Description |
- | ------- | ------------------------------- | ---- | ----------------------------------------- |
- | dataOut | [MessageParcel](#messageparceldeprecated) | Yes | **MessageParcel** object to which the sequenceable object is to be marshaled.|
+| Name | Type | Mandatory| Description |
+| ------- | ------------------------------- | ---- | ----------------------------------------- |
+| dataOut | [MessageParcel](#messageparceldeprecated) | Yes | **MessageParcel** object to which the sequenceable object is to be marshaled.|
**Return value**
- | Type | Description |
- | ------- | ----------------------------------------- |
- | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
-
+| Type | Description |
+| ------- | ----------------------------------------- |
+| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Example**
- ```
+ ```ts
class MySequenceable {
num: number;
str: string;
@@ -5643,7 +5577,6 @@ Marshals the sequenceable object into a **MessageParcel** object.
console.log("RpcClient: readSequenceable is " + result2);
```
-
### unmarshalling
unmarshalling(dataIn: MessageParcel): boolean
@@ -5654,19 +5587,19 @@ Unmarshals this sequenceable object from a **MessageParcel** object.
**Parameters**
- | Name| Type | Mandatory| Description |
- | ------ | ------------------------------- | ---- | --------------------------------------------- |
- | dataIn | [MessageParcel](#messageparceldeprecated) | Yes | **MessageParcel** object in which the sequenceable object is to be unmarshaled.|
+| Name| Type | Mandatory| Description |
+| ------ | ------------------------------- | ---- | --------------------------------------------- |
+| dataIn | [MessageParcel](#messageparceldeprecated) | Yes | **MessageParcel** object in which the sequenceable object is to be unmarshaled.|
**Return value**
- | Type | Description |
- | ------- | --------------------------------------------- |
- | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
+| Type | Description |
+| ------- | --------------------------------------------- |
+| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Example**
- ```
+ ```ts
class MySequenceable {
num: number;
str: string;
@@ -5694,7 +5627,6 @@ Unmarshals this sequenceable object from a **MessageParcel** object.
console.log("RpcClient: readSequenceable is " + result2);
```
-
## IRemoteBroker
Provides the holder of a remote proxy object.
@@ -5709,23 +5641,50 @@ Obtains a proxy or remote object. This API must be implemented by its derived cl
**Return value**
- | Type | Description|
- | ---- | ----- |
- | [IRemoteObject](#iremoteobject) | Returns the **RemoteObject** if it is the caller; returns the [IRemoteObject](#iremoteobject), the holder of this **RemoteProxy** object, if the caller is a [RemoteProxy](#remoteproxy) object.|
+| Type | Description|
+| ---- | ----- |
+| [IRemoteObject](#iremoteobject) | Returns the **RemoteObject** if it is the caller; returns the [IRemoteObject](#iremoteobject), the holder of this **RemoteProxy** object, if the caller is a [RemoteProxy](#remoteproxy) object.|
**Example**
- ```
+ ```ts
class TestAbility extends rpc.RemoteObject {
asObject() {
return this;
}
}
+ let remoteObject = new TestAbility().asObject();
```
**Example**
+ Obtain the service.
+
+ ```ts
+ import FA from "@ohos.ability.featureAbility";
+ let proxy;
+ let connect = {
+ onConnect: function (elementName, remoteProxy) {
+ console.log("RpcClient: js onConnect called.");
+ proxy = remoteProxy;
+ },
+ onDisconnect: function (elementName) {
+ console.log("RpcClient: onDisconnect");
+ },
+ onFailed: function () {
+ console.log("RpcClient: onFailed");
+ }
+ };
+ let want = {
+ "bundleName": "com.ohos.server",
+ "abilityName": "com.ohos.server.MainAbility",
+ };
+ FA.connectAbility(want, connect);
```
+
+The proxy object in the **onConnect** callback can be assigned a value only after the ability is connected asynchronously. Then, **asObject()** of the proxy object is called to obtain the proxy or remote object.
+
+ ```ts
class TestProxy {
remote: rpc.RemoteObject;
constructor(remote) {
@@ -5735,6 +5694,8 @@ Obtains a proxy or remote object. This API must be implemented by its derived cl
return this.remote;
}
}
+ let iRemoteObject = new TestProxy(proxy).asObject();
+
```
## DeathRecipient
@@ -5751,7 +5712,7 @@ Called to perform subsequent operations when a death notification of the remote
**Example**
- ```
+ ```ts
class MyDeathRecipient {
onRemoteDied() {
console.log("server died");
@@ -5765,12 +5726,12 @@ Defines the response to the request.
**System capability**: SystemCapability.Communication.IPC.Core
- | Name | Type | Readable| Writable| Description |
- | ------- | --------------- | ---- | ---- |-------------------------------------- |
- | errCode | number | Yes | No | Error Code |
- | code | number | Yes | No | Message code. |
- | data | MessageSequence | Yes | No | **MessageSequence** object sent to the remote process.|
- | reply | MessageSequence | Yes | No | **MessageSequence** object returned by the remote process. |
+| Name | Type | Readable| Writable| Description |
+| ------- | --------------- | ---- | ---- |-------------------------------------- |
+| errCode | number | Yes | No | Error Code |
+| code | number | Yes | No | Message code. |
+| data | MessageSequence | Yes | No | **MessageSequence** object sent to the remote process.|
+| reply | MessageSequence | Yes | No | **MessageSequence** object returned by the remote process. |
## SendRequestResult8+(deprecated)
@@ -5780,12 +5741,12 @@ Defines the response to the request.
**System capability**: SystemCapability.Communication.IPC.Core
- | Name | Type | Readable| Writable| Description |
- | ------- | ------------- | ---- | ---- | ----------------------------------- |
- | errCode | number | Yes | No | Error Code |
- | code | number | Yes | No | Message code. |
- | data | MessageParcel | Yes | No | **MessageParcel** object sent to the remote process.|
- | reply | MessageParcel | Yes | No | **MessageParcel** object returned by the remote process. |
+| Name | Type | Readable| Writable| Description |
+| ------- | ------------- | ---- | ---- | ----------------------------------- |
+| errCode | number | Yes | No | Error Code |
+| code | number | Yes | No | Message code. |
+| data | MessageParcel | Yes | No | **MessageParcel** object sent to the remote process.|
+| reply | MessageParcel | Yes | No | **MessageParcel** object returned by the remote process. |
## IRemoteObject
@@ -5795,21 +5756,21 @@ Provides methods to query of obtain interface descriptors, add or delete death n
getLocalInterface(descriptor: string): IRemoteBroker
-Obtains the interface.
+Obtains the interface descriptor.
**System capability**: SystemCapability.Communication.IPC.Core
**Parameters**
- | Name | Type | Mandatory| Description |
- | ---------- | ------ | ---- | -------------------- |
- | descriptor | string | Yes | Interface descriptor.|
+| Name | Type | Mandatory| Description |
+| ---------- | ------ | ---- | -------------------- |
+| descriptor | string | Yes | Interface descriptor.|
**Return value**
- | Type | Description |
- | ------------- | --------------------------------------------- |
- | IRemoteBroker | **IRemoteBroker** object bound to the specified interface token.|
+| Type | Description |
+| ------------- | --------------------------------------------- |
+| IRemoteBroker | **IRemoteBroker** object bound to the specified interface token.|
### queryLocalInterface(deprecated)
@@ -5817,22 +5778,21 @@ Obtains the interface.
queryLocalInterface(descriptor: string): IRemoteBroker
-Obtains the interface.
+Queries the interface descriptor.
**System capability**: SystemCapability.Communication.IPC.Core
**Parameters**
- | Name | Type | Mandatory| Description |
- | ---------- | ------ | ---- | -------------------- |
- | descriptor | string | Yes | Interface descriptor.|
+| Name | Type | Mandatory| Description |
+| ---------- | ------ | ---- | -------------------- |
+| descriptor | string | Yes | Interface descriptor.|
**Return value**
- | Type | Description |
- | ------------- | --------------------------------------------- |
- | IRemoteBroker | **IRemoteBroker** object bound to the specified interface token.|
-
+| Type | Description |
+| ------------- | --------------------------------------------- |
+| IRemoteBroker | **IRemoteBroker** object bound to the specified interface token.|
### sendRequest(deprecated)
@@ -5840,24 +5800,24 @@ Obtains the interface.
sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption): boolean
-Sends a **MessageParcel** message to the remote process in synchronous or asynchronous mode. If **options** is the asynchronous mode, a promise will be fulfilled immediately and the reply message does not contain any content. If **options** is the synchronous mode, a promise will be fulfilled when the response to **sendRequest** is returned, and the reply message contains the returned information.
+Sends a **MessageParcel** message to the remote process in synchronous or asynchronous mode. If asynchronous mode is set in **options**, a promise will be fulfilled immediately and the reply message does not contain any content. If synchronous mode is set in **options** , a promise will be fulfilled when the response to **sendRequest** is returned, and the reply message contains the returned information.
**System capability**: SystemCapability.Communication.IPC.Core
**Parameters**
- | Name | Type| Mandatory| Description |
- | ------- | ------------------------------- | ---- | ---- |
- | code | number | Yes | Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
- | data | [MessageParcel](#messageparceldeprecated) | Yes | **MessageParcel** object holding the data to send. |
- | reply | [MessageParcel](#messageparceldeprecated) | Yes | **MessageParcel** object that receives the response. |
- | options | [MessageOption](#messageoption) | Yes | Request sending mode, which can be synchronous (default) or asynchronous. |
+| Name | Type| Mandatory| Description |
+| ------- | ------------------------------- | ---- | ---- |
+| code | number | Yes | Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
+| data | [MessageParcel](#messageparceldeprecated) | Yes | **MessageParcel** object holding the data to send. |
+| reply | [MessageParcel](#messageparceldeprecated) | Yes | **MessageParcel** object that receives the response. |
+| options | [MessageOption](#messageoption) | Yes | Request sending mode, which can be synchronous (default) or asynchronous. |
**Return value**
- | Type | Description |
- | ------- | --------------------------------------------- |
- | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
+| Type | Description |
+| ------- | --------------------------------------------- |
+| boolean | Returns **true** if the message is sent successfully; returns **false** otherwise.|
### sendRequest8+(deprecated)
@@ -5866,68 +5826,67 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch
sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption): Promise<SendRequestResult>
-Sends a **MessageParcel** message to the remote process in synchronous or asynchronous mode. If **options** is the asynchronous mode, a promise will be fulfilled immediately and the reply message does not contain any content. If **options** is the synchronous mode, a promise will be fulfilled when the response to **sendRequest** is returned, and the reply message contains the returned information.
+Sends a **MessageParcel** message to the remote process in synchronous or asynchronous mode. If asynchronous mode is set in **options**, a promise will be fulfilled immediately and the reply message is empty. The specific reply needs to be obtained from the callback on the service side. If synchronous mode is set in **options**, a promise will be fulfilled when the response to **sendRequest** is returned, and the reply message contains the returned information.
**System capability**: SystemCapability.Communication.IPC.Core
**Parameters**
- | Name | Type | Mandatory| Description |
- | ------- | ------------------------------- | ---- | -------------------------------------------------------------------------------------- |
- | code | number | Yes | Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
- | data | [MessageParcel](#messageparceldeprecated) | Yes | **MessageParcel** object holding the data to send. |
- | reply | [MessageParcel](#messageparceldeprecated) | Yes | **MessageParcel** object that receives the response. |
- | options | [MessageOption](#messageoption) | Yes | Request sending mode, which can be synchronous (default) or asynchronous. |
+| Name | Type | Mandatory| Description |
+| ------- | ------------------------------- | ---- | -------------------------------------------------------------------------------------- |
+| code | number | Yes | Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
+| data | [MessageParcel](#messageparceldeprecated) | Yes | **MessageParcel** object holding the data to send. |
+| reply | [MessageParcel](#messageparceldeprecated) | Yes | **MessageParcel** object that receives the response. |
+| options | [MessageOption](#messageoption) | Yes | Request sending mode, which can be synchronous (default) or asynchronous. |
**Return value**
- | Type | Description |
- | -------------------------------- | --------------------------------------------- |
- | Promise<SendRequestResult> | Promise used to return the **sendRequestResult** object.|
+| Type | Description |
+| -------------------------------- | --------------------------------------------- |
+| Promise<SendRequestResult> | Promise used to return the **sendRequestResult** object.|
### sendMessageRequest9+
sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence, options: MessageOption): Promise<RequestResult>
-Sends a **MessageSequence** message to the remote process in synchronous or asynchronous mode. If **options** is the asynchronous mode, a promise will be fulfilled immediately and the reply message does not contain any content. If **options** is the synchronous mode, a promise will be fulfilled when the response to **sendMessageRequest** is returned, and the reply message contains the returned information.
+Sends a **MessageSequence** message to the remote process in synchronous or asynchronous mode. If asynchronous mode is set in **options**, a promise will be fulfilled immediately and the reply message is empty. The specific reply needs to be obtained from the callback on the service side. If synchronous mode is set in **options**, a promise will be fulfilled when the response to **sendMessageRequest** is returned, and the reply message contains the returned information.
**System capability**: SystemCapability.Communication.IPC.Core
**Parameters**
- | Name | Type | Mandatory| Description |
- | ------- | ------------------------------- | ---- | -------------------------------------------------------------------------------------- |
- | code | number | Yes | Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
- | data | [MessageSequence](#messagesequence9) | Yes | **MessageSequence** object holding the data to send. |
- | reply | [MessageSequence](#messagesequence9) | Yes | **MessageSequence** object that receives the response. |
- | options | [MessageOption](#messageoption) | Yes | Request sending mode, which can be synchronous (default) or asynchronous. |
+| Name | Type | Mandatory| Description |
+| ------- | ------------------------------- | ---- | -------------------------------------------------------------------------------------- |
+| code | number | Yes | Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
+| data | [MessageSequence](#messagesequence9) | Yes | **MessageSequence** object holding the data to send. |
+| reply | [MessageSequence](#messagesequence9) | Yes | **MessageSequence** object that receives the response. |
+| options | [MessageOption](#messageoption) | Yes | Request sending mode, which can be synchronous (default) or asynchronous. |
**Return value**
- | Type | Description |
- | ---------------------------- | ----------------------------------------- |
- | Promise<RequestResult> | Promise used to return the **requestResult** object.|
+| Type | Description |
+| ---------------------------- | ----------------------------------------- |
+| Promise<RequestResult> | Promise used to return the **requestResult** object.|
### sendMessageRequest9+
sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence, options: MessageOption, callback: AsyncCallback<RequestResult>): void
-Sends a **MessageSequence** message to the remote process in synchronous or asynchronous mode. If **options** is the asynchronous mode, a callback will be invoked immediately and the reply message does not contain any content. If **options** is the synchronous mode, a callback will be invoked when the response to sendRequest is returned, and the reply message contains the returned information.
+Sends a **MessageSequence** message to the remote process in synchronous or asynchronous mode. If asynchronous mode is set in **options**, a callback will be called immediately, and the reply message is empty. The specific reply needs to be obtained from the callback on the service side. If synchronous mode is set in **options**, a callback will be invoked when the response to sendRequest is returned, and the reply message contains the returned information.
**System capability**: SystemCapability.Communication.IPC.Core
**Parameters**
- | Name | Type | Mandatory| Description |
- | -------- | ---------------------------------- | ---- | -------------------------------------------------------------------------------------- |
- | code | number | Yes | Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
- | data | [MessageSequence](#messagesequence9) | Yes | **MessageSequence** object holding the data to send. |
- | reply | [MessageSequence](#messagesequence9) | Yes | **MessageSequence** object that receives the response. |
- | options | [MessageOption](#messageoption) | Yes | Request sending mode, which can be synchronous (default) or asynchronous. |
- | callback | AsyncCallback<RequestResult> | Yes | Callback for receiving the sending result. |
-
+| Name | Type | Mandatory| Description |
+| -------- | ---------------------------------- | ---- | -------------------------------------------------------------------------------------- |
+| code | number | Yes | Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
+| data | [MessageSequence](#messagesequence9) | Yes | **MessageSequence** object holding the data to send. |
+| reply | [MessageSequence](#messagesequence9) | Yes | **MessageSequence** object that receives the response. |
+| options | [MessageOption](#messageoption) | Yes | Request sending mode, which can be synchronous (default) or asynchronous. |
+| callback | AsyncCallback<RequestResult> | Yes | Callback for receiving the sending result. |
### sendRequest8+(deprecated)
@@ -5935,44 +5894,42 @@ Sends a **MessageSequence** message to the remote process in synchronous or asyn
sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption, callback: AsyncCallback<SendRequestResult>): void
-Sends a **MessageParcel** message to the remote process in synchronous or asynchronous mode. If **options** is the asynchronous mode, a callback will be invoked immediately and the reply message does not contain any content. If **options** is the synchronous mode, a callback will be invoked when the response to sendRequest is returned, and the reply message contains the returned information.
+Sends a **MessageParcel** message to the remote process in synchronous or asynchronous mode. If asynchronous mode is set in **options**, a callback will be called immediately, and the reply message is empty. The specific reply needs to be obtained from the callback on the service side. If synchronous mode is set in **options**, a callback will be invoked when the response to sendRequest is returned, and the reply message contains the returned information.
**System capability**: SystemCapability.Communication.IPC.Core
**Parameters**
- | Name | Type | Mandatory| Description |
- | -------- | -------------------------------------- | ---- | -------------------------------------------------------------------------------------- |
- | code | number | Yes | Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
- | data | [MessageParcel](#messageparceldeprecated) | Yes | **MessageParcel** object holding the data to send. |
- | reply | [MessageParcel](#messageparceldeprecated) | Yes | **MessageParcel** object that receives the response. |
- | options | [MessageOption](#messageoption) | Yes | Request sending mode, which can be synchronous (default) or asynchronous. |
- | callback | AsyncCallback<SendRequestResult> | Yes | Callback for receiving the sending result. |
-
+| Name | Type | Mandatory| Description |
+| -------- | -------------------------------------- | ---- | -------------------------------------------------------------------------------------- |
+| code | number | Yes | Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
+| data | [MessageParcel](#messageparceldeprecated) | Yes | **MessageParcel** object holding the data to send. |
+| reply | [MessageParcel](#messageparceldeprecated) | Yes | **MessageParcel** object that receives the response. |
+| options | [MessageOption](#messageoption) | Yes | Request sending mode, which can be synchronous (default) or asynchronous. |
+| callback | AsyncCallback<SendRequestResult> | Yes | Callback for receiving the sending result. |
### registerDeathRecipient9+
registerDeathRecipient(recipient: DeathRecipient, flags: number): void
-Adds a callback for receiving death notifications of the remote object. This method is called if the remote object process matching the **RemoteProxy** object is killed.
+Registers a callback for receiving death notifications of the remote object. The callback will be called if the remote object process matching the **RemoteProxy** object is killed.
**System capability**: SystemCapability.Communication.IPC.Core
**Parameters**
- | Name | Type | Mandatory| Description |
- | --------- | --------------------------------- | ---- | -------------- |
- | recipient | [DeathRecipient](#deathrecipient) | Yes | Callback to add.|
- | flags | number | Yes | Flag of the death notification.|
+| Name | Type | Mandatory| Description |
+| --------- | --------------------------------- | ---- | -------------- |
+| recipient | [DeathRecipient](#deathrecipient) | Yes | Callback to register.|
+| flags | number | Yes | Flag of the death notification.|
-**Error Code**
+**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | ------- | -------- |
- | 1900008 | proxy or remote object is invalid |
-
+| ID| Error Message|
+| ------- | -------- |
+| 1900008 | proxy or remote object is invalid |
### addDeathrecipient(deprecated)
@@ -5986,41 +5943,40 @@ Adds a callback for receiving death notifications of the remote object. This met
**Parameters**
- | Name | Type | Mandatory| Description |
- | --------- | --------------------------------- | ---- | -------------- |
- | recipient | [DeathRecipient](#deathrecipient) | Yes | Callback to add.|
- | flags | number | Yes | Flag of the death notification.|
+| Name | Type | Mandatory| Description |
+| --------- | --------------------------------- | ---- | -------------- |
+| recipient | [DeathRecipient](#deathrecipient) | Yes | Callback to add.|
+| flags | number | Yes | Flag of the death notification.|
**Return value**
- | Type | Description |
- | ------- | --------------------------------------------- |
- | boolean | Returns **true** if the callback is added successfully; returns **false** otherwise.|
+| Type | Description |
+| ------- | --------------------------------------------- |
+| boolean | Returns **true** if the callback is added successfully; returns **false** otherwise.|
### unregisterDeathRecipient9+
unregisterDeathRecipient(recipient: DeathRecipient, flags: number): void
-Removes the callback used to receive death notifications of the remote object.
+Unregisters the callback used to receive death notifications of the remote object.
**System capability**: SystemCapability.Communication.IPC.Core
**Parameters**
- | Name | Type | Mandatory| Description |
- | --------- | --------------------------------- | ---- | -------------- |
- | recipient | [DeathRecipient](#deathrecipient) | Yes | Callback to remove.|
- | flags | number | Yes | Flag of the death notification.|
+| Name | Type | Mandatory| Description |
+| --------- | --------------------------------- | ---- | -------------- |
+| recipient | [DeathRecipient](#deathrecipient) | Yes | Callback to unregister.|
+| flags | number | Yes | Flag of the death notification.|
-**Error Code**
+**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | ------- | -------- |
- | 1900008 | proxy or remote object is invalid |
-
+| ID| Error Message|
+| ------- | -------- |
+| 1900008 | proxy or remote object is invalid |
### removeDeathRecipient(deprecated)
@@ -6034,39 +5990,38 @@ Removes the callback used to receive death notifications of the remote object.
**Parameters**
- | Name | Type | Mandatory| Description |
- | --------- | --------------------------------- | ---- | -------------- |
- | recipient | [DeathRecipient](#deathrecipient) | Yes | Callback to remove.|
- | flags | number | Yes | Flag of the death notification.|
+| Name | Type | Mandatory| Description |
+| --------- | --------------------------------- | ---- | -------------- |
+| recipient | [DeathRecipient](#deathrecipient) | Yes | Callback to remove.|
+| flags | number | Yes | Flag of the death notification.|
**Return value**
- | Type | Description |
- | ------- | --------------------------------------------- |
- | boolean | Returns **true** if the callback is removed successfully; returns **false** otherwise.|
-
+| Type | Description |
+| ------- | --------------------------------------------- |
+| boolean | Returns **true** if the callback is removed; returns **false** otherwise.|
### getDescriptor9+
getDescriptor(): string
-Obtains the interface descriptor of this object. The interface descriptor is a string.
+Obtains the interface descriptor (which is a string) of this object.
**System capability**: SystemCapability.Communication.IPC.Core
**Return value**
- | Type | Description |
- | ------ | ---------------- |
- | string | Interface descriptor obtained.|
+| Type | Description |
+| ------ | ---------------- |
+| string | Interface descriptor obtained.|
-**Error Code**
+**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | ------- | -------- |
- | 1900008 | proxy or remote object is invalid |
+| ID| Error Message|
+| ------- | -------- |
+| 1900008 | proxy or remote object is invalid |
### getInterfaceDescriptor(deprecated)
@@ -6075,15 +6030,15 @@ For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode
getInterfaceDescriptor(): string
-Obtains the interface descriptor of this object. The interface descriptor is a string.
+Obtains the interface descriptor (which is a string) of this object.
**System capability**: SystemCapability.Communication.IPC.Core
**Return value**
- | Type | Description |
- | ------ | ---------------- |
- | string | Interface descriptor obtained.|
+| Type | Description |
+| ------ | ---------------- |
+| string | Interface descriptor obtained.|
### isObjectDead
@@ -6096,9 +6051,9 @@ Checks whether this object is dead.
**Return value**
- | Type | Description |
- | ------- | ------------------------------------------- |
- | boolean | Returns **true** if the object is dead; returns **false** otherwise.|
+| Type | Description |
+| ------- | ------------------------------------------- |
+| boolean | Returns **true** if the object is dead; returns **false** otherwise.|
## RemoteProxy
@@ -6115,35 +6070,36 @@ Provides APIs to implement **IRemoteObject**.
| MIN_TRANSACTION_ID | 1 (0x00000001) | Minimum valid instruction code. |
| MAX_TRANSACTION_ID | 16777215 (0x00FFFFFF) | Maximum valid instruction code. |
-
### sendRequest(deprecated)
>This API is no longer maintained since API version 9. You are advised to use [sendMessageRequest](#sendmessagerequest9).
sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption): boolean
-Sends a **MessageParcel** message to the remote process in synchronous or asynchronous mode. If **options** is the asynchronous mode, a promise will be fulfilled immediately and the reply message does not contain any content. If **options** is the synchronous mode, a promise will be fulfilled when the response to **sendRequest** is returned, and the reply message contains the returned information.
+Sends a **MessageParcel** message to the remote process in synchronous or asynchronous mode. If asynchronous mode is set in **options**, a promise will be fulfilled immediately and the reply message is empty. The specific reply needs to be obtained from the callback on the service side. If synchronous mode is set in **options**, a promise will be fulfilled when the response to **sendRequest** is returned, and the reply message contains the returned information.
**System capability**: SystemCapability.Communication.IPC.Core
**Parameters**
- | Name | Type | Mandatory| Description |
- | ------- | ------------------------------- | ---- | -------------------------------------------------------------------------------------- |
- | code | number | Yes | Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
- | data | [MessageParcel](#messageparceldeprecated) | Yes | **MessageParcel** object holding the data to send. |
- | reply | [MessageParcel](#messageparceldeprecated) | Yes | **MessageParcel** object that receives the response. |
- | options | [MessageOption](#messageoption) | Yes | Request sending mode, which can be synchronous (default) or asynchronous. |
+| Name | Type | Mandatory| Description |
+| ------- | ------------------------------- | ---- | -------------------------------------------------------------------------------------- |
+| code | number | Yes | Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
+| data | [MessageParcel](#messageparceldeprecated) | Yes | **MessageParcel** object holding the data to send. |
+| reply | [MessageParcel](#messageparceldeprecated) | Yes | **MessageParcel** object that receives the response. |
+| options | [MessageOption](#messageoption) | Yes | Request sending mode, which can be synchronous (default) or asynchronous. |
**Return value**
- | Type | Description |
- | ------- | --------------------------------------------- |
- | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
+| Type | Description |
+| ------- | --------------------------------------------- |
+| boolean | Returns **true** if the message is sent successfully; returns **false** otherwise.|
**Example**
- ```
+ Obtain the service.
+
+ ```ts
import FA from "@ohos.ability.featureAbility";
let proxy;
let connect = {
@@ -6163,6 +6119,11 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch
"abilityName": "com.ohos.server.MainAbility",
};
FA.connectAbility(want, connect);
+ ```
+
+The proxy object in the **onConnect** callback can be assigned a value only after the ability is connected asynchronously. Then, **sendMessageRequest()** of the proxy object is called to send a message.
+
+ ```ts
let option = new rpc.MessageOption();
let data = rpc.MessageParcel.create();
let reply = rpc.MessageParcel.create();
@@ -6181,33 +6142,34 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch
reply.reclaim();
```
-
### sendMessageRequest9+
sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence, options: MessageOption): Promise<RequestResult>
-Sends a **MessageSequence** message to the remote process in synchronous or asynchronous mode. If **options** is the asynchronous mode, a promise will be fulfilled immediately and the reply message does not contain any content. If **options** is the synchronous mode, a promise will be fulfilled when the response to **sendMessageRequest** is returned, and the reply message contains the returned information.
+Sends a **MessageSequence** message to the remote process in synchronous or asynchronous mode. If asynchronous mode is set in **options**, a promise will be fulfilled immediately and the reply message is empty. The specific reply needs to be obtained from the callback on the service side. If synchronous mode is set in **options**, a promise will be fulfilled when the response to **sendMessageRequest** is returned, and the reply message contains the returned information.
**System capability**: SystemCapability.Communication.IPC.Core
**Parameters**
- | Name | Type | Mandatory| Description |
- | ------- | ------------------------------- | ---- | -------------------------------------------------------------------------------------- |
- | code | number | Yes | Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
- | data | [MessageSequence](#messagesequence9) | Yes | **MessageSequence** object holding the data to send. |
- | reply | [MessageSequence](#messagesequence9) | Yes | **MessageSequence** object that receives the response. |
- | options | [MessageOption](#messageoption) | Yes | Request sending mode, which can be synchronous (default) or asynchronous. |
+| Name | Type | Mandatory| Description |
+| ------- | ------------------------------- | ---- | -------------------------------------------------------------------------------------- |
+| code | number | Yes | Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
+| data | [MessageSequence](#messagesequence9) | Yes | **MessageSequence** object holding the data to send. |
+| reply | [MessageSequence](#messagesequence9) | Yes | **MessageSequence** object that receives the response. |
+| options | [MessageOption](#messageoption) | Yes | Request sending mode, which can be synchronous (default) or asynchronous. |
**Return value**
- | Type | Description |
- | ---------------------------- | ----------------------------------------- |
- | Promise<RequestResult> | Promise used to return the **requestResult** object.|
+| Type | Description |
+| ---------------------------- | ----------------------------------------- |
+| Promise<RequestResult> | Promise used to return the **requestResult** object.|
**Example**
- ```
+ Obtain the service.
+
+ ```ts
import FA from "@ohos.ability.featureAbility";
let proxy;
let connect = {
@@ -6227,6 +6189,11 @@ Sends a **MessageSequence** message to the remote process in synchronous or asyn
"abilityName": "com.ohos.server.MainAbility",
};
FA.connectAbility(want, connect);
+ ```
+
+The proxy object in the **onConnect** callback can be assigned a value only after the ability is connected asynchronously. Then, **sendMessageRequest()** of the proxy object is called to send a message.
+
+ ```ts
let option = new rpc.MessageOption();
let data = rpc.MessageSequence.create();
let reply = rpc.MessageSequence.create();
@@ -6251,35 +6218,36 @@ Sends a **MessageSequence** message to the remote process in synchronous or asyn
});
```
-
### sendRequest8+(deprecated)
>This API is no longer maintained since API version 9. You are advised to use [sendMessageRequest](#sendmessagerequest9).
sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption): Promise<SendRequestResult>
-Sends a **MessageParcel** message to the remote process in synchronous or asynchronous mode. If **options** is the asynchronous mode, a promise will be fulfilled immediately and the reply message does not contain any content. If **options** is the synchronous mode, a promise will be fulfilled when the response to **sendRequest** is returned, and the reply message contains the returned information.
+Sends a **MessageParcel** message to the remote process in synchronous or asynchronous mode. If asynchronous mode is set in **options**, a promise will be fulfilled immediately and the reply message is empty. The specific reply needs to be obtained from the callback on the service side. If synchronous mode is set in **options**, a promise will be fulfilled when the response to **sendRequest** is returned, and the reply message contains the returned information.
**System capability**: SystemCapability.Communication.IPC.Core
**Parameters**
- | Name | Type | Mandatory| Description |
- | ------- | ------------------------------- | ---- | -------------------------------------------------------------------------------------- |
- | code | number | Yes | Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
- | data | [MessageParcel](#messageparceldeprecated) | Yes | **MessageParcel** object holding the data to send. |
- | reply | [MessageParcel](#messageparceldeprecated) | Yes | **MessageParcel** object that receives the response. |
- | options | [MessageOption](#messageoption) | Yes | Request sending mode, which can be synchronous (default) or asynchronous. |
+| Name | Type | Mandatory| Description |
+| ------- | ------------------------------- | ---- | -------------------------------------------------------------------------------------- |
+| code | number | Yes | Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
+| data | [MessageParcel](#messageparceldeprecated) | Yes | **MessageParcel** object holding the data to send. |
+| reply | [MessageParcel](#messageparceldeprecated) | Yes | **MessageParcel** object that receives the response. |
+| options | [MessageOption](#messageoption) | Yes | Request sending mode, which can be synchronous (default) or asynchronous. |
**Return value**
- | Type | Description |
- | -------------------------------- | --------------------------------------------- |
- | Promise<SendRequestResult> | Promise used to return the **sendRequestResult** object.|
+| Type | Description |
+| -------------------------------- | --------------------------------------------- |
+| Promise<SendRequestResult> | Promise used to return the **sendRequestResult** object.|
**Example**
- ```
+ Obtain the service.
+
+ ```ts
import FA from "@ohos.ability.featureAbility";
let proxy;
let connect = {
@@ -6299,6 +6267,11 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch
"abilityName": "com.ohos.server.MainAbility",
};
FA.connectAbility(want, connect);
+ ```
+
+The proxy object in the **onConnect** callback can be assigned a value only after the ability is connected asynchronously. Then, **sendMessageRequest()** of the proxy object is called to send a message.
+
+ ```ts
let option = new rpc.MessageOption();
let data = rpc.MessageParcel.create();
let reply = rpc.MessageParcel.create();
@@ -6327,24 +6300,25 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch
sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence, options: MessageOption, callback: AsyncCallback<RequestResult>): void
-Sends a **MessageSequence** message to the remote process in synchronous or asynchronous mode. If **options** is the asynchronous mode, a callback will be invoked immediately and the reply message does not contain any content. If **options** is the synchronous mode, a callback will be invoked at certain time after the response to **sendMessageRequest** is returned, and the reply contains the returned information.
+Sends a **MessageSequence** message to the remote process in synchronous or asynchronous mode. If asynchronous mode is set in **options**, a callback will be called immediately, and the reply message is empty. The specific reply needs to be obtained from the callback on the service side. If **options** is the synchronous mode, a callback will be invoked at certain time after the response to **sendMessageRequest** is returned, and the reply contains the returned information.
**System capability**: SystemCapability.Communication.IPC.Core
**Parameters**
- | Name | Type | Mandatory| Description |
- | -------- | ---------------------------------- | ---- | -------------------------------------------------------------------------------------- |
- | code | number | Yes | Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
- | data | [MessageSequence](#messagesequence9) | Yes | **MessageSequence** object holding the data to send. |
- | reply | [MessageSequence](#messagesequence9) | Yes | **MessageSequence** object that receives the response. |
- | options | [MessageOption](#messageoption) | Yes | Request sending mode, which can be synchronous (default) or asynchronous. |
- | callback | AsyncCallback<RequestResult> | Yes | Callback for receiving the sending result. |
-
+| Name | Type | Mandatory| Description |
+| -------- | ---------------------------------- | ---- | -------------------------------------------------------------------------------------- |
+| code | number | Yes | Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
+| data | [MessageSequence](#messagesequence9) | Yes | **MessageSequence** object holding the data to send. |
+| reply | [MessageSequence](#messagesequence9) | Yes | **MessageSequence** object that receives the response. |
+| options | [MessageOption](#messageoption) | Yes | Request sending mode, which can be synchronous (default) or asynchronous. |
+| callback | AsyncCallback<RequestResult> | Yes | Callback for receiving the sending result. |
**Example**
- ```
+ Obtain the service.
+
+ ```ts
import FA from "@ohos.ability.featureAbility";
let proxy;
let connect = {
@@ -6377,6 +6351,11 @@ Sends a **MessageSequence** message to the remote process in synchronous or asyn
result.reply.reclaim();
}
FA.connectAbility(want, connect);
+ ```
+
+The proxy object in the **onConnect** callback can be assigned a value only after the ability is connected asynchronously. Then, **sendMessageRequest()** of the proxy object is called to send a message.
+
+ ```ts
let option = new rpc.MessageOption();
let data = rpc.MessageSequence.create();
let reply = rpc.MessageSequence.create();
@@ -6390,30 +6369,31 @@ Sends a **MessageSequence** message to the remote process in synchronous or asyn
}
```
-
### sendRequest8+(deprecated)
>This API is no longer maintained since API version 9. You are advised to use [sendMessageRequest](#sendmessagerequest9).
sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption, callback: AsyncCallback<SendRequestResult>): void
-Sends a **MessageParcel** message to the remote process in synchronous or asynchronous mode. If **options** is the asynchronous mode, a callback will be invoked immediately and the reply message does not contain any content. If **options** is the synchronous mode, a callback will be invoked when the response to sendRequest is returned, and the reply message contains the returned information.
+Sends a **MessageParcel** message to the remote process in synchronous or asynchronous mode. If asynchronous mode is set in **options**, a callback will be called immediately, and the reply message is empty. The specific reply needs to be obtained from the callback on the service side. If synchronous mode is set in **options**, a callback will be invoked when the response to sendRequest is returned, and the reply message contains the returned information.
**System capability**: SystemCapability.Communication.IPC.Core
**Parameters**
- | Name | Type | Mandatory| Description |
- | -------- | -------------------------------------- | ---- | -------------------------------------------------------------------------------------- |
- | code | number | Yes | Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
- | data | [MessageParcel](#messageparceldeprecated) | Yes | **MessageParcel** object holding the data to send. |
- | reply | [MessageParcel](#messageparceldeprecated) | Yes | **MessageParcel** object that receives the response. |
- | options | [MessageOption](#messageoption) | Yes | Request sending mode, which can be synchronous (default) or asynchronous. |
- | callback | AsyncCallback<SendRequestResult> | Yes | Callback for receiving the sending result. |
+| Name | Type | Mandatory| Description |
+| -------- | -------------------------------------- | ---- | -------------------------------------------------------------------------------------- |
+| code | number | Yes | Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
+| data | [MessageParcel](#messageparceldeprecated) | Yes | **MessageParcel** object holding the data to send. |
+| reply | [MessageParcel](#messageparceldeprecated) | Yes | **MessageParcel** object that receives the response. |
+| options | [MessageOption](#messageoption) | Yes | Request sending mode, which can be synchronous (default) or asynchronous. |
+| callback | AsyncCallback<SendRequestResult> | Yes | Callback for receiving the sending result. |
**Example**
- ```
+ Obtain the service.
+
+ ```ts
import FA from "@ohos.ability.featureAbility";
let proxy;
let connect = {
@@ -6446,6 +6426,11 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch
result.reply.reclaim();
}
FA.connectAbility(want, connect);
+ ```
+
+The proxy object in the **onConnect** callback can be assigned a value only after the ability is connected asynchronously. Then, **sendMessageRequest()** of the proxy object is called to send a message.
+
+ ```ts
let option = new rpc.MessageOption();
let data = rpc.MessageParcel.create();
let reply = rpc.MessageParcel.create();
@@ -6454,7 +6439,6 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch
proxy.sendRequest(1, data, reply, option, sendRequestCallback);
```
-
### getLocalInterface9+
getLocalInterface(interface: string): IRemoteBroker
@@ -6465,27 +6449,29 @@ Obtains the **LocalInterface** object of an interface token.
**Parameters**
- | Name | Type | Mandatory| Description |
- | --------- | ------ | ---- | ---------------------- |
- | interface | string | Yes | Interface descriptor.|
+| Name | Type | Mandatory| Description |
+| --------- | ------ | ---- | ---------------------- |
+| interface | string | Yes | Interface descriptor.|
**Return value**
- | Type | Description |
- | ------------- | ------------------------------------------ |
- | IRemoteBroker | Returns **Null** by default, which indicates a proxy interface.|
+| Type | Description |
+| ------------- | ------------------------------------------ |
+| IRemoteBroker | Returns **Null** by default, which indicates a proxy interface.|
-**Error Code**
+**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | ------- | -------- |
- | 1900006 | only remote object permitted |
+| ID| Error Message|
+| ------- | -------- |
+| 1900006 | only remote object permitted |
**Example**
- ```
+ Obtain the service.
+
+ ```ts
import FA from "@ohos.ability.featureAbility";
let proxy;
let connect = {
@@ -6502,9 +6488,14 @@ For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode
};
let want = {
"bundleName":"com.ohos.server",
- "abilityName":"com.ohos.server.MainAbility",
+ "abilityName":"com.ohos.server.EntryAbility",
};
FA.connectAbility(want, connect);
+ ```
+
+The proxy object in the **onConnect** callback can be assigned a value only after the ability is connected asynchronously. Then, **getLocalInterface()** of the proxy object is called to obtain the interface descriptor.
+
+ ```ts
try {
let broker = proxy.getLocalInterface("testObject");
console.log("RpcClient: getLocalInterface is " + broker);
@@ -6514,7 +6505,6 @@ For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode
}
```
-
### queryLocalInterface(deprecated)
>This API is no longer maintained since API version 9. You are advised to use [getLocalInterface](#getlocalinterface9).
@@ -6527,19 +6517,21 @@ Obtains the **LocalInterface** object of an interface token.
**Parameters**
- | Name | Type | Mandatory| Description |
- | --------- | ------ | ---- | ---------------------- |
- | interface | string | Yes | Interface descriptor.|
+| Name | Type | Mandatory| Description |
+| --------- | ------ | ---- | ---------------------- |
+| interface | string | Yes | Interface descriptor.|
**Return value**
- | Type | Description |
- | ------------- | ------------------------------------------ |
- | IRemoteBroker | Returns **Null** by default, which indicates a proxy interface.|
+| Type | Description |
+| ------------- | ------------------------------------------ |
+| IRemoteBroker | Returns **Null** by default, which indicates a proxy interface.|
**Example**
- ```
+ Obtain the service.
+
+ ```ts
import FA from "@ohos.ability.featureAbility";
let proxy;
let connect = {
@@ -6556,40 +6548,46 @@ Obtains the **LocalInterface** object of an interface token.
};
let want = {
"bundleName":"com.ohos.server",
- "abilityName":"com.ohos.server.MainAbility",
+ "abilityName":"com.ohos.server.EntryAbility",
};
FA.connectAbility(want, connect);
+ ```
+
+The proxy object in the **onConnect** callback can be assigned a value only after the ability is connected asynchronously. Then, **queryLocalInterface()** of the proxy object is called to obtain the interface descriptor.
+
+ ```ts
let broker = proxy.queryLocalInterface("testObject");
console.log("RpcClient: queryLocalInterface is " + broker);
```
-
### registerDeathRecipient9+
registerDeathRecipient(recipient: DeathRecipient, flags: number): void
-Adds a callback for receiving death notifications of the remote object. This method is called if the remote object process matching the **RemoteProxy** object is killed.
+Registers a callback for receiving death notifications of the remote object. The callback will be invoked when the remote object process matching the **RemoteProxy** object is killed.
**System capability**: SystemCapability.Communication.IPC.Core
**Parameters**
- | Name | Type | Mandatory| Description |
- | --------- | --------------------------------- | ---- | -------------- |
- | recipient | [DeathRecipient](#deathrecipient) | Yes | Callback to add.|
- | flags | number | Yes | Flag of the death notification.|
+| Name | Type | Mandatory| Description |
+| --------- | --------------------------------- | ---- | -------------- |
+| recipient | [DeathRecipient](#deathrecipient) | Yes | Callback to register.|
+| flags | number | Yes | Flag of the death notification.|
-**Error Code**
+**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | ------- | -------- |
- | 1900008 | proxy or remote object is invalid |
+| ID| Error Message|
+| ------- | -------- |
+| 1900008 | proxy or remote object is invalid |
**Example**
- ```
+ Obtain the service.
+
+ ```ts
import FA from "@ohos.ability.featureAbility";
let proxy;
let connect = {
@@ -6609,6 +6607,11 @@ For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode
"abilityName": "com.ohos.server.MainAbility",
};
FA.connectAbility(want, connect);
+ ```
+
+The proxy object in the **onConnect** callback can be assigned a value only after the ability is connected asynchronously. Then, **registerDeathRecipient()** of the proxy object is called to register a callback for receiving the death notification of the remote object.
+
+ ```ts
class MyDeathRecipient {
onRemoteDied() {
console.log("server died");
@@ -6616,14 +6619,13 @@ For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode
}
let deathRecipient = new MyDeathRecipient();
try {
- proxy.registerDeathRecippient(deathRecipient, 0);
+ proxy.registerDeathRecipient(deathRecipient, 0);
} catch(error) {
console.info("proxy register deathRecipient fail, errorCode " + error.code);
console.info("proxy register deathRecipient fail, errorMessage " + error.message);
}
```
-
### addDeathRecippient(deprecated)
>This API is no longer maintained since API version 9. You are advised to use [registerDeathRecipient](#registerdeathrecipient9).
@@ -6636,20 +6638,22 @@ Adds a callback for receiving the death notifications of the remote object, incl
**Parameters**
- | Name | Type | Mandatory| Description |
- | --------- | --------------------------------- | ---- | --------------------------------- |
- | recipient | [DeathRecipient](#deathrecipient) | Yes | Callback to add. |
- | flags | number | Yes | Flag of the death notification. This parameter is reserved. It is set to **0**.|
+| Name | Type | Mandatory| Description |
+| --------- | --------------------------------- | ---- | --------------------------------- |
+| recipient | [DeathRecipient](#deathrecipient) | Yes | Callback to add. |
+| flags | number | Yes | Flag of the death notification. This parameter is reserved. It is set to **0**.|
**Return value**
- | Type | Description |
- | ------- | --------------------------------------------- |
- | boolean | Returns **true** if the callback is added successfully; returns **false** otherwise.|
+| Type | Description |
+| ------- | --------------------------------------------- |
+| boolean | Returns **true** if the callback is added successfully; returns **false** otherwise.|
**Example**
- ```
+ Obtain the service.
+
+ ```ts
import FA from "@ohos.ability.featureAbility";
let proxy;
let connect = {
@@ -6669,41 +6673,48 @@ Adds a callback for receiving the death notifications of the remote object, incl
"abilityName": "com.ohos.server.MainAbility",
};
FA.connectAbility(want, connect);
+ ```
+
+The proxy object in the **onConnect** callback can be assigned a value only after the ability is connected asynchronously. Then, **addDeathRecippient()** of the proxy object is called to add a callback for receiving the death notification of the remove object.
+
+ ```ts
class MyDeathRecipient {
onRemoteDied() {
console.log("server died");
}
}
let deathRecipient = new MyDeathRecipient();
- proxy.addDeathRecippient(deathRecipient, 0);
+ proxy.addDeathRecipient(deathRecipient, 0);
```
### unregisterDeathRecipient9+
-unregisterDeathRecipient(recipient: DeathRecipient, flags: number): boolean
+unregisterDeathRecipient(recipient: DeathRecipient, flags: number): void
-Removes the callback used to receive death notifications of the remote object.
+Unregisters the callback used to receive death notifications of the remote object.
**System capability**: SystemCapability.Communication.IPC.Core
**Parameters**
- | Name | Type | Mandatory| Description |
- | --------- | --------------------------------- | ---- | -------------- |
- | recipient | [DeathRecipient](#deathrecipient) | Yes | Callback to remove.|
- | flags | number | Yes | Flag of the death notification.|
+| Name | Type | Mandatory| Description |
+| --------- | --------------------------------- | ---- | -------------- |
+| recipient | [DeathRecipient](#deathrecipient) | Yes | Callback to unregister.|
+| flags | number | Yes | Flag of the death notification.|
-**Error Code**
+**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | ------- | -------- |
- | 1900008 | proxy or remote object is invalid |
+| ID| Error Message|
+| ------- | -------- |
+| 1900008 | proxy or remote object is invalid |
**Example**
- ```
+ Obtain the service.
+
+ ```ts
import FA from "@ohos.ability.featureAbility";
let proxy;
let connect = {
@@ -6723,6 +6734,11 @@ For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode
"abilityName": "com.ohos.server.MainAbility",
};
FA.connectAbility(want, connect);
+ ```
+
+The proxy object in the **onConnect** callback can be assigned a value only after the ability is connected asynchronously. Then, **unregisterDeathRecipient()** of the proxy object is called to unregister the callback for receiving the death notification of the remote object.
+
+ ```ts
class MyDeathRecipient {
onRemoteDied() {
console.log("server died");
@@ -6738,7 +6754,6 @@ For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode
}
```
-
### removeDeathRecipient(deprecated)
>This API is no longer maintained since API version 9. You are advised to use [unregisterDeathRecipient](#unregisterdeathrecipient9).
@@ -6751,20 +6766,22 @@ Removes the callback used to receive death notifications of the remote object.
**Parameters**
- | Name | Type | Mandatory| Description |
- | --------- | --------------------------------- | ---- | --------------------------------- |
- | recipient | [DeathRecipient](#deathrecipient) | Yes | Callback to remove. |
- | flags | number | Yes | Flag of the death notification. This parameter is reserved. It is set to **0**.|
+| Name | Type | Mandatory| Description |
+| --------- | --------------------------------- | ---- | --------------------------------- |
+| recipient | [DeathRecipient](#deathrecipient) | Yes | Callback to remove. |
+| flags | number | Yes | Flag of the death notification. This parameter is reserved. It is set to **0**.|
**Return value**
- | Type | Description |
- | ------- | --------------------------------------------- |
- | boolean | Returns **true** if the callback is removed successfully; returns **false** otherwise.|
+| Type | Description |
+| ------- | --------------------------------------------- |
+| boolean | Returns **true** if the callback is removed; returns **false** otherwise.|
**Example**
- ```
+ Obtain the service.
+
+ ```ts
import FA from "@ohos.ability.featureAbility";
let proxy;
let connect = {
@@ -6784,6 +6801,11 @@ Removes the callback used to receive death notifications of the remote object.
"abilityName": "com.ohos.server.MainAbility",
};
FA.connectAbility(want, connect);
+ ```
+
+The proxy object in the **onConnect** callback can be assigned a value only after the ability is connected asynchronously. Then, **removeDeathRecipient()** of the proxy object is called to remove the callback used to receive the death notification of the remote object.
+
+ ```ts
class MyDeathRecipient {
onRemoteDied() {
console.log("server died");
@@ -6794,33 +6816,34 @@ Removes the callback used to receive death notifications of the remote object.
proxy.removeDeathRecipient(deathRecipient, 0);
```
-
### getDescriptor9+
getDescriptor(): string
-Obtains the interface descriptor of this object. The interface descriptor is a string.
+Obtains the interface descriptor (which is a string) of this proxy object.
**System capability**: SystemCapability.Communication.IPC.Core
**Return value**
- | Type | Description |
- | ------ | ---------------- |
- | string | Interface descriptor obtained.|
+| Type | Description |
+| ------ | ---------------- |
+| string | Interface descriptor obtained.|
-**Error Code**
+**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | -------- | ------- |
- | 1900008 | proxy or remote object is invalid |
- | 1900007 | communication failed |
+| ID| Error Message|
+| -------- | ------- |
+| 1900008 | proxy or remote object is invalid |
+| 1900007 | communication failed |
**Example**
- ```
+ Obtain the service.
+
+ ```ts
import FA from "@ohos.ability.featureAbility";
let proxy;
let connect = {
@@ -6840,6 +6863,10 @@ For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode
"abilityName": "com.ohos.server.MainAbility",
};
FA.connectAbility(want, connect);
+ ```
+The proxy object in the **onConnect** callback can be assigned a value only after the ability is connected asynchronously. Then, **getDescriptor()** of the proxy object is called to obtain the interface descriptor of the object.
+
+ ```ts
try {
let descriptor = proxy.getDescriptor();
console.log("RpcClient: descriptor is " + descriptor);
@@ -6849,7 +6876,6 @@ For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode
}
```
-
### getInterfaceDescriptor(deprecated)
>This API is no longer maintained since API version 9. You are advised to use [getDescriptor](#getdescriptor9).
@@ -6862,13 +6888,15 @@ Obtains the interface descriptor of this proxy object.
**Return value**
- | Type | Description |
- | ------ | ------------------ |
- | string | Interface descriptor obtained.|
+| Type | Description |
+| ------ | ------------------ |
+| string | Interface descriptor obtained.|
**Example**
- ```
+ Obtain the service.
+
+ ```ts
import FA from "@ohos.ability.featureAbility";
let proxy;
let connect = {
@@ -6888,11 +6916,15 @@ Obtains the interface descriptor of this proxy object.
"abilityName": "com.ohos.server.MainAbility",
};
FA.connectAbility(want, connect);
+ ```
+
+The proxy object in the **onConnect** callback can be assigned a value only after the ability is connected asynchronously. Then, **getInterfaceDescriptor()** of the proxy object is called to obtain the interface descriptor of the current proxy object.
+
+ ```ts
let descriptor = proxy.getInterfaceDescriptor();
console.log("RpcClient: descriptor is " + descriptor);
```
-
### isObjectDead
isObjectDead(): boolean
@@ -6903,13 +6935,15 @@ Checks whether the **RemoteObject** is dead.
**Return value**
- | Type | Description |
- | ------- | --------------------------------------------------------- |
- | boolean | Returns **true** if the **RemoteObject** is dead; returns **false** otherwise.|
+| Type | Description |
+| ------- | --------------------------------------------------------- |
+| boolean | Returns **true** if the **RemoteObject** is dead; returns **false** otherwise.|
**Example**
- ```
+ Obtain the service.
+
+ ```ts
import FA from "@ohos.ability.featureAbility";
let proxy;
let connect = {
@@ -6929,23 +6963,27 @@ Checks whether the **RemoteObject** is dead.
"abilityName": "com.ohos.server.MainAbility",
};
FA.connectAbility(want, connect);
+ ```
+
+The proxy object in the **onConnect** callback can be assigned a value only after the ability is connected asynchronously. Then, **isObjectDead()** of the proxy object is called to check whether this object is dead.
+
+ ```ts
let isDead = proxy.isObjectDead();
console.log("RpcClient: isObjectDead is " + isDead);
```
-
## MessageOption
Provides common message options (flag and wait time). Use the specified flag to construct the **MessageOption** object.
**System capability**: SystemCapability.Communication.IPC.Core
- | Name | Value | Description |
- | ------------- | ---- | ----------------------------------------------------------- |
- | TF_SYNC | 0 | Synchronous call. |
- | TF_ASYNC | 1 | Asynchronous call. |
- | TF_ACCEPT_FDS | 0x10 | Indication to **sendMessageRequest9+** for returning the file descriptor.|
- | TF_WAIT_TIME | 8 | Default waiting time, in seconds. |
+| Name | Value | Description |
+| ------------- | ---- | ----------------------------------------------------------- |
+| TF_SYNC | 0 | Synchronous call. |
+| TF_ASYNC | 1 | Asynchronous call. |
+| TF_ACCEPT_FDS | 0x10 | Indication to **sendMessageRequest9+** for returning the file descriptor.|
+| TF_WAIT_TIME | 8 | Default waiting time, in seconds. |
### constructor9+
@@ -6958,10 +6996,20 @@ A constructor used to create a **MessageOption** object.
**Parameters**
- | Name | Type | Mandatory| Description |
- | --------- | ------ | ---- | -------------------------------------- |
- | syncFlags | number | No | Call flag, which can be synchronous or asynchronous. The default value is **synchronous**.|
+| Name | Type | Mandatory| Description |
+| --------- | ------ | ---- | -------------------------------------- |
+| syncFlags | number | No | Call flag, which can be synchronous or asynchronous. The default value is **synchronous**.|
+
+**Example**
+
+ ```ts
+ class TestRemoteObject extends rpc.MessageOption {
+ constructor(async) {
+ super(async);
+ }
+ }
+ ```
### constructor
@@ -6973,12 +7021,20 @@ A constructor used to create a **MessageOption** object.
**Parameters**
- | Name | Type | Mandatory| Description |
- | --------- | ------ | ---- | --------------------------------------------- |
- | syncFlags | number | No | Call flag, which can be synchronous or asynchronous. The default value is **synchronous**. |
- | waitTime | number | No | Maximum wait time for an RPC call. The default value is **TF_WAIT_TIME**.|
+| Name | Type | Mandatory| Description |
+| --------- | ------ | ---- | --------------------------------------------- |
+| syncFlags | number | No | Call flag, which can be synchronous or asynchronous. The default value is **synchronous**. |
+| waitTime | number | No | Maximum wait time for an RPC call. The default value is **TF_WAIT_TIME**.|
+**Example**
+ ```ts
+ class TestRemoteObject extends rpc.MessageOption {
+ constructor(syncFlags,waitTime) {
+ super(syncFlags,waitTime);
+ }
+ }
+ ```
### isAsync9+
isAsync(): boolean;
@@ -6989,10 +7045,16 @@ Checks whether **SendMessageRequest** is called synchronously or asynchronously.
**Return value**
- | Type | Description |
- | ------- | ------------------------------------ |
- | boolean | Call mode obtained.|
+| Type | Description |
+| ------- | ------------------------------------ |
+| boolean | Returns **true** if **SendMessageRequest** is called synchronously; returns **false** if **SendMessageRequest** is called asynchronously.|
+**Example**
+
+ ```ts
+ let option = new rpc.MessageOption();
+ let isAsync = option.isAsync();
+ ```
### setAsync9+
@@ -7002,6 +7064,13 @@ Sets whether **SendMessageRequest** is called synchronously or asynchronously.
**System capability**: SystemCapability.Communication.IPC.Core
+**Example**
+
+ ```ts
+ let option = new rpc.MessageOption();
+ let setAsync = option.setAsync(true);
+ console.log("Set synchronization flag");
+ ```
### getFlags
@@ -7013,10 +7082,26 @@ Obtains the call flag, which can be synchronous or asynchronous.
**Return value**
- | Type | Description |
- | ------ | ------------------------------------ |
- | number | Call mode obtained.|
+| Type | Description |
+| ------ | ------------------------------------ |
+| number | Call mode obtained.|
+**Example**
+
+ ```ts
+ try {
+ let option = new rpc.MessageOption();
+ console.info("create object successfully.");
+ let flog = option.getFlags();
+ console.info("run getFlags success, flog is " + flog);
+ option.setFlags(1)
+ console.info("run setFlags success");
+ let flog2 = option.getFlags();
+ console.info("run getFlags success, flog2 is " + flog2);
+ } catch (error) {
+ console.info("error " + error);
+ }
+ ```
### setFlags
@@ -7028,10 +7113,23 @@ Sets the call flag, which can be synchronous or asynchronous.
**Parameters**
- | Name| Type | Mandatory| Description |
- | ------ | ------ | ---- | ------------------------ |
- | flags | number | Yes | Call flag to set.|
+| Name| Type | Mandatory| Description |
+| ------ | ------ | ---- | ------------------------ |
+| flags | number | Yes | Call flag to set.|
+**Example**
+
+ ```ts
+ try {
+ let option = new rpc.MessageOption();
+ option.setFlags(1)
+ console.info("run setFlags success");
+ let flog = option.getFlags();
+ console.info("run getFlags success, flog is " + flog);
+ } catch (error) {
+ console.info("error " + error);
+ }
+ ```
### getWaitTime
@@ -7043,10 +7141,24 @@ Obtains the maximum wait time for this RPC call.
**Return value**
- | Type | Description |
- | ------ | ----------------- |
- | number | Maximum wait time obtained.|
+| Type | Description |
+| ------ | ----------------- |
+| number | Maximum wait time obtained.|
+**Example**
+
+ ```ts
+ try {
+ let option = new rpc.MessageOption();
+ let time = option.getWaitTime();
+ console.info("run getWaitTime success");
+ option.setWaitTime(16);
+ let time2 = option.getWaitTime();
+ console.info("run getWaitTime success, time is " + time);
+ } catch (error) {
+ console.info("error " + error);
+ }
+ ```
### setWaitTime
@@ -7058,10 +7170,22 @@ Sets the maximum wait time for this RPC call.
**Parameters**
- | Name | Type | Mandatory| Description |
- | -------- | ------ | ---- | --------------------- |
- | waitTime | number | Yes | Maximum wait time to set.|
+| Name | Type | Mandatory| Description |
+| -------- | ------ | ---- | --------------------- |
+| waitTime | number | Yes | Maximum wait time to set.|
+
+**Example**
+ ```ts
+ try {
+ let option = new rpc.MessageOption();
+ option.setWaitTime(16);
+ let time = option.getWaitTime();
+ console.info("run getWaitTime success, time is " + time);
+ } catch (error) {
+ console.info("error " + error);
+ }
+ ```
## IPCSkeleton
@@ -7071,41 +7195,40 @@ Obtains IPC context information, including the UID and PID, local and remote dev
static getContextObject(): IRemoteObject
-Obtains the system capability manager.
+Obtains the system capability manager. This API is a static method.
**System capability**: SystemCapability.Communication.IPC.Core
**Return value**
- | Type | Description |
- | ------------------------------- | -------------------- |
- | [IRemoteObject](#iremoteobject) | System capability manager obtained.|
+| Type | Description |
+| ------------------------------- | -------------------- |
+| [IRemoteObject](#iremoteobject) | System capability manager obtained.|
**Example**
- ```
+ ```ts
let samgr = rpc.IPCSkeleton.getContextObject();
console.log("RpcServer: getContextObject result: " + samgr);
```
-
### getCallingPid
static getCallingPid(): number
-Obtains the PID of the caller. This method is invoked by the **RemoteObject** object in the **onRemoteRequest** method. If this method is not invoked in the IPC context (**onRemoteRequest**), the PID of the process will be returned.
+Obtains the PID of the caller. This API is a static method, which is invoked by the **RemoteObject** object in the **onRemoteRequest** method. If this method is not invoked in the IPC context (**onRemoteRequest**), the PID of the process will be returned.
**System capability**: SystemCapability.Communication.IPC.Core
**Return value**
- | Type | Description |
- | ------ | ----------------- |
- | number | PID of the caller.|
+| Type | Description |
+| ------ | ----------------- |
+| number | PID of the caller.|
**Example**
- ```
+ ```ts
class Stub extends rpc.RemoteObject {
onRemoteMessageRequest(code, data, reply, option) {
let callerPid = rpc.IPCSkeleton.getCallingPid();
@@ -7115,24 +7238,23 @@ Obtains the PID of the caller. This method is invoked by the **RemoteObject** ob
}
```
-
### getCallingUid
static getCallingUid(): number
-Obtains the UID of the caller. This method is invoked by the **RemoteObject** object in the **onRemoteRequest** method. If this method is not invoked in the IPC context (**onRemoteRequest**), the UID of the process will be returned.
+Obtains the UID of the caller. This API is a static method, which is invoked by the **RemoteObject** object in the **onRemoteRequest** method. If this method is not invoked in the IPC context (**onRemoteRequest**), the UID of the process will be returned.
**System capability**: SystemCapability.Communication.IPC.Core
**Return value**
- | Type | Description |
- | ------ | ----------------- |
- | number | UID of the caller.|
+| Type | Description |
+| ------ | ----------------- |
+| number | UID of the caller.|
**Example**
- ```
+ ```ts
class Stub extends rpc.RemoteObject {
onRemoteMessageRequest(code, data, reply, option) {
let callerUid = rpc.IPCSkeleton.getCallingUid();
@@ -7142,7 +7264,6 @@ Obtains the UID of the caller. This method is invoked by the **RemoteObject** ob
}
```
-
### getCallingTokenId8+
static getCallingTokenId(): number;
@@ -7151,16 +7272,15 @@ Obtains the caller's token ID, which is used to verify the caller identity.
**System capability**: SystemCapability.Communication.IPC.Core
-
**Return value**
-
- | Type | Description |
- | ------ | --------------------- |
- | number | Token ID of the caller obtained.|
-
+
+| Type | Description |
+| ------ | --------------------- |
+| number | Token ID of the caller obtained.|
+
**Example**
- ```
+ ```ts
class Stub extends rpc.RemoteObject {
onRemoteMessageRequest(code, data, reply, option) {
let callerTokenId = rpc.IPCSkeleton.getCallingTokenId();
@@ -7175,19 +7295,19 @@ Obtains the caller's token ID, which is used to verify the caller identity.
static getCallingDeviceID(): string
-Obtains the ID of the device hosting the caller's process.
+Obtains the ID of the device hosting the caller's process. This API is a static method.
**System capability**: SystemCapability.Communication.IPC.Core
**Return value**
- | Type | Description |
- | ------ | ---------------------------- |
- | string | Device ID obtained.|
+| Type | Description |
+| ------ | ---------------------------- |
+| string | Device ID obtained.|
**Example**
- ```
+ ```ts
class Stub extends rpc.RemoteObject {
onRemoteMessageRequest(code, data, reply, option) {
let callerDeviceID = rpc.IPCSkeleton.getCallingDeviceID();
@@ -7197,24 +7317,23 @@ Obtains the ID of the device hosting the caller's process.
}
```
-
### getLocalDeviceID
static getLocalDeviceID(): string
-Obtains the local device ID.
+Obtains the local device ID. This API is a static method.
**System capability**: SystemCapability.Communication.IPC.Core
**Return value**
- | Type | Description |
- | ------ | ------------------ |
- | string | Local device ID obtained.|
+| Type | Description |
+| ------ | ------------------ |
+| string | Local device ID obtained.|
**Example**
- ```
+ ```ts
class Stub extends rpc.RemoteObject {
onRemoteMessageRequest(code, data, reply, option) {
let localDeviceID = rpc.IPCSkeleton.getLocalDeviceID();
@@ -7224,24 +7343,23 @@ Obtains the local device ID.
}
```
-
### isLocalCalling
static isLocalCalling(): boolean
-Checks whether the remote process is a process of the local device.
+Checks whether the remote process is a process of the local device. This API is a static method.
**System capability**: SystemCapability.Communication.IPC.Core
**Return value**
- | Type | Description |
- | ------- | --------------------------------------------------------- |
- | boolean | Returns **true** if the local and remote processes are on the same device; returns **false** otherwise.|
+| Type | Description |
+| ------- | --------------------------------------------------------- |
+| boolean | Returns **true** if the local and remote processes are on the same device; returns **false** otherwise.|
**Example**
- ```
+ ```ts
class Stub extends rpc.RemoteObject {
onRemoteMessageRequest(code, data, reply, option) {
let isLocalCalling = rpc.IPCSkeleton.isLocalCalling();
@@ -7251,25 +7369,24 @@ Checks whether the remote process is a process of the local device.
}
```
-
### flushCmdBuffer9+
static flushCmdBuffer(object: IRemoteObject): void
-Flushes all suspended commands from the specified **RemoteProxy** to the corresponding **RemoteObject**. It is recommended that this method be called before any time-sensitive operation is performed.
+Flushes all suspended commands from the specified **RemoteProxy** to the corresponding **RemoteObject**. This API is a static method. It is recommended that this method be called before any time-sensitive operation is performed.
**System capability**: SystemCapability.Communication.IPC.Core
**Parameters**
- | Name| Type | Mandatory| Description |
- | ------ | ------------------------------- | ---- | ------------------- |
- | object | [IRemoteObject](#iremoteobject) | Yes | **RemoteProxy** specified. |
+| Name| Type | Mandatory| Description |
+| ------ | ------------------------------- | ---- | ------------------- |
+| object | [IRemoteObject](#iremoteobject) | Yes | **RemoteProxy** specified. |
**Example**
- ```
+ ```ts
class TestRemoteObject extends rpc.RemoteObject {
constructor(descriptor) {
super(descriptor);
@@ -7284,32 +7401,31 @@ Flushes all suspended commands from the specified **RemoteProxy** to the corresp
}
```
-
### flushCommands(deprecated)
>This API is no longer maintained since API version 9. You are advised to use [flushCmdBuffer](#flushcmdbuffer9).
static flushCommands(object: IRemoteObject): number
-Flushes all suspended commands from the specified **RemoteProxy** to the corresponding **RemoteObject**. It is recommended that this method be called before any time-sensitive operation is performed.
+Flushes all suspended commands from the specified **RemoteProxy** to the corresponding **RemoteObject**. This API is a static method. It is recommended that this method be called before any time-sensitive operation is performed.
**System capability**: SystemCapability.Communication.IPC.Core
**Parameters**
- | Name| Type | Mandatory| Description |
- | ------ | ------------------------------- | ---- | ------------------- |
- | object | [IRemoteObject](#iremoteobject) | Yes | **RemoteProxy** specified. |
+| Name| Type | Mandatory| Description |
+| ------ | ------------------------------- | ---- | ------------------- |
+| object | [IRemoteObject](#iremoteobject) | Yes | **RemoteProxy** specified. |
**Return value**
- | Type | Description |
- | ------ | --------------------------------------------------------------------------------- |
- | number | Returns **0** if the operation is successful; returns an error code if the input object is null or a **RemoteObject**, or if the operation fails.|
+| Type | Description |
+| ------ | --------------------------------------------------------------------------------- |
+| number | Returns **0** if the operation is successful; returns an error code if the input object is null or a **RemoteObject**, or if the operation fails.|
**Example**
- ```
+ ```ts
class MyDeathRecipient {
onRemoteDied() {
console.log("server died");
@@ -7338,19 +7454,19 @@ Flushes all suspended commands from the specified **RemoteProxy** to the corresp
static resetCallingIdentity(): string
-Changes the UID and PID of the remote user to the UID and PID of the local user. This method is used in scenarios such as identity authentication.
+Changes the UID and PID of the remote user to the UID and PID of the local user. This API is a static method. You can use it in scenarios such as identity authentication.
**System capability**: SystemCapability.Communication.IPC.Core
**Return value**
- | Type | Description |
- | ------ | ------------------------------------ |
- | string | String containing the UID and PID of the remote user.|
+| Type | Description |
+| ------ | ------------------------------------ |
+| string | String containing the UID and PID of the remote user.|
**Example**
- ```
+ ```ts
class Stub extends rpc.RemoteObject {
onRemoteMessageRequest(code, data, reply, option) {
let callingIdentity = rpc.IPCSkeleton.resetCallingIdentity();
@@ -7365,19 +7481,19 @@ Changes the UID and PID of the remote user to the UID and PID of the local user.
static restoreCallingIdentity(identity: string): void
-Changes the UID and PID of the remote user to the UID and PID of the local user. This method is used in scenarios such as identity authentication.
+Changes the UID and PID of the remote user to the UID and PID of the local user. This API is a static method. You can use it in scenarios such as identity authentication.
**System capability**: SystemCapability.Communication.IPC.Core
**Parameters**
- | Name | Type | Mandatory| Description |
- | -------- | ------ | ---- | ------------------------------------------------------------------ |
- | identity | string | Yes | String containing the remote user UID and PID, which are returned by **resetCallingIdentity**.|
+| Name | Type | Mandatory| Description |
+| -------- | ------ | ---- | ------------------------------------------------------------------ |
+| identity | string | Yes | String containing the remote user UID and PID, which are returned by **resetCallingIdentity**.|
**Example**
- ```
+ ```ts
class Stub extends rpc.RemoteObject {
onRemoteMessageRequest(code, data, reply, option) {
let callingIdentity = null;
@@ -7392,32 +7508,31 @@ Changes the UID and PID of the remote user to the UID and PID of the local user.
}
```
-
### setCallingIdentity(deprecated)
>This API is no longer maintained since API version 9. You are advised to use [restoreCallingIdentity](#restorecallingidentity9).
static setCallingIdentity(identity: string): boolean
-Restores the UID and PID of the remote user. It is usually called when the UID and PID of the remote user are required. The UID and PID of the remote user are returned by **resetCallingIdentity**.
+Sets the UID and PID of the remote user. This API is a static method. It is usually called when the UID and PID of the remote user are required. The UID and PID of the remote user are returned by **resetCallingIdentity**.
**System capability**: SystemCapability.Communication.IPC.Core
**Parameters**
- | Name | Type | Mandatory| Description |
- | -------- | ------ | ---- | ------------------------------------------------------------------ |
- | identity | string | Yes | String containing the remote user UID and PID, which are returned by **resetCallingIdentity**.|
+| Name | Type | Mandatory| Description |
+| -------- | ------ | ---- | ------------------------------------------------------------------ |
+| identity | string | Yes | String containing the remote user UID and PID, which are returned by **resetCallingIdentity**.|
**Return value**
- | Type | Description |
- | ------- | ----------------------------------------- |
- | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
+| Type | Description |
+| ------- | ----------------------------------------- |
+| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Example**
- ```
+ ```ts
class Stub extends rpc.RemoteObject {
onRemoteMessageRequest(code, data, reply, option) {
let callingIdentity = null;
@@ -7433,7 +7548,6 @@ Restores the UID and PID of the remote user. It is usually called when the UID a
}
```
-
## RemoteObject
Provides methods to implement **RemoteObject**. The service provider must inherit from this class.
@@ -7448,9 +7562,9 @@ A constructor used to create a **RemoteObject** object.
**Parameters**
- | Name | Type | Mandatory| Description |
- | ---------- | ------ | ---- | ------------ |
- | descriptor | string | Yes | Interface descriptor.|
+| Name | Type | Mandatory| Description |
+| ---------- | ------ | ---- | ------------ |
+| descriptor | string | Yes | Interface descriptor.|
### sendRequest(deprecated)
@@ -7459,28 +7573,28 @@ A constructor used to create a **RemoteObject** object.
sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption): boolean
-Sends a **MessageParcel** message to the remote process in synchronous or asynchronous mode. If **options** is the asynchronous mode, a promise will be fulfilled immediately and the reply message does not contain any content. If **options** is the synchronous mode, a promise will be fulfilled when the response to **sendRequest** is returned, and the reply message contains the returned information.
+Sends a **MessageParcel** message to the remote process in synchronous or asynchronous mode. If asynchronous mode is set in **options**, a promise will be fulfilled immediately and the reply message is empty. The specific reply needs to be obtained from the callback on the service side. If synchronous mode is set in **options**, a promise will be fulfilled when the response to **sendRequest** is returned, and the reply message contains the returned information.
**System capability**: SystemCapability.Communication.IPC.Core
**Parameters**
- | Name | Type | Mandatory| Description |
- | ------- | ------------------------------- | ---- | -------------------------------------------------------------------------------------- |
- | code | number | Yes | Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
- | data | [MessageParcel](#messageparceldeprecated) | Yes | **MessageParcel** object holding the data to send. |
- | reply | [MessageParcel](#messageparceldeprecated) | Yes | **MessageParcel** object that receives the response. |
- | options | [MessageOption](#messageoption) | Yes | Request sending mode, which can be synchronous (default) or asynchronous. |
+| Name | Type | Mandatory| Description |
+| ------- | ------------------------------- | ---- | -------------------------------------------------------------------------------------- |
+| code | number | Yes | Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
+| data | [MessageParcel](#messageparceldeprecated) | Yes | **MessageParcel** object holding the data to send. |
+| reply | [MessageParcel](#messageparceldeprecated) | Yes | **MessageParcel** object that receives the response. |
+| options | [MessageOption](#messageoption) | Yes | Request sending mode, which can be synchronous (default) or asynchronous. |
**Return value**
- | Type | Description |
- | ------- | --------------------------------------------- |
- | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
+| Type | Description |
+| ------- | --------------------------------------------- |
+| boolean | Returns **true** if the message is sent successfully; returns **false** otherwise.|
**Example**
- ```
+ ```ts
class MyDeathRecipient {
onRemoteDied() {
console.log("server died");
@@ -7519,35 +7633,34 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch
reply.reclaim();
```
-
### sendRequest8+(deprecated)
>This API is no longer maintained since API version 9. You are advised to use [sendMessageRequest](#sendmessagerequest9).
sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption): Promise<SendRequestResult>
-Sends a **MessageParcel** message to the remote process in synchronous or asynchronous mode. If **options** is the asynchronous mode, a promise will be fulfilled immediately and the reply message does not contain any content. If **options** is the synchronous mode, a promise will be fulfilled when the response to **sendRequest** is returned, and the reply message contains the returned information.
+Sends a **MessageParcel** message to the remote process in synchronous or asynchronous mode. If asynchronous mode is set in **options**, a promise will be fulfilled immediately and the reply message is empty. The specific reply needs to be obtained from the callback on the service side. If synchronous mode is set in **options**, a promise will be fulfilled when the response to **sendRequest** is returned, and the reply message contains the returned information.
**System capability**: SystemCapability.Communication.IPC.Core
**Parameters**
- | Name | Type | Mandatory| Description |
- | ------- | ------------------------------- | ---- | -------------------------------------------------------------------------------------- |
- | code | number | Yes | Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
- | data | [MessageParcel](#messageparceldeprecated) | Yes | **MessageParcel** object holding the data to send. |
- | reply | [MessageParcel](#messageparceldeprecated) | Yes | **MessageParcel** object that receives the response. |
- | options | [MessageOption](#messageoption) | Yes | Request sending mode, which can be synchronous (default) or asynchronous. |
+| Name | Type | Mandatory| Description |
+| ------- | ------------------------------- | ---- | -------------------------------------------------------------------------------------- |
+| code | number | Yes | Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
+| data | [MessageParcel](#messageparceldeprecated) | Yes | **MessageParcel** object holding the data to send. |
+| reply | [MessageParcel](#messageparceldeprecated) | Yes | **MessageParcel** object that receives the response. |
+| options | [MessageOption](#messageoption) | Yes | Request sending mode, which can be synchronous (default) or asynchronous. |
**Return value**
- | Type | Description |
- | -------------------------------- | --------------------------------------------- |
- | Promise<SendRequestResult> | Promise used to return the **sendRequestResult** object.|
+| Type | Description |
+| -------------------------------- | --------------------------------------------- |
+| Promise<SendRequestResult> | Promise used to return the **sendRequestResult** object.|
**Example**
- ```
+ ```ts
class MyDeathRecipient {
onRemoteDied() {
console.log("server died");
@@ -7596,28 +7709,28 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch
sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence, options: MessageOption): Promise<RequestResult>
-Sends a **MessageSequence** message to the remote process in synchronous or asynchronous mode. If **options** is the asynchronous mode, a promise will be fulfilled immediately and the reply message does not contain any content. If **options** is the synchronous mode, a promise will be fulfilled when the response to **sendMessageRequest** is returned, and the reply message contains the returned information.
+Sends a **MessageSequence** message to the remote process in synchronous or asynchronous mode. If asynchronous mode is set in **options**, a promise will be fulfilled immediately and the reply message is empty. The specific reply needs to be obtained from the callback on the service side. If synchronous mode is set in **options**, a promise will be fulfilled when the response to **sendMessageRequest** is returned, and the reply message contains the returned information.
**System capability**: SystemCapability.Communication.IPC.Core
**Parameters**
- | Name | Type | Mandatory| Description |
- | ------- | ------------------------------- | ---- | -------------------------------------------------------------------------------------- |
- | code | number | Yes | Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
- | data | [MessageSequence](#messagesequence9) | Yes | **MessageSequence** object holding the data to send. |
- | reply | [MessageSequence](#messagesequence9) | Yes | **MessageSequence** object that receives the response. |
- | options | [MessageOption](#messageoption) | Yes | Request sending mode, which can be synchronous (default) or asynchronous. |
+| Name | Type | Mandatory| Description |
+| ------- | ------------------------------- | ---- | -------------------------------------------------------------------------------------- |
+| code | number | Yes | Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
+| data | [MessageSequence](#messagesequence9) | Yes | **MessageSequence** object holding the data to send. |
+| reply | [MessageSequence](#messagesequence9) | Yes | **MessageSequence** object that receives the response. |
+| options | [MessageOption](#messageoption) | Yes | Request sending mode, which can be synchronous (default) or asynchronous. |
**Return value**
- | Type | Description |
- | ---------------------------- | --------------------------------------------- |
- | Promise<RequestResult> | Promise used to return the **sendRequestResult** object.|
+| Type | Description |
+| ---------------------------- | --------------------------------------------- |
+| Promise<RequestResult> | Promise used to return the **sendRequestResult** object.|
**Example**
- ```
+ ```ts
class TestRemoteObject extends rpc.RemoteObject {
constructor(descriptor) {
super(descriptor);
@@ -7648,28 +7761,27 @@ Sends a **MessageSequence** message to the remote process in synchronous or asyn
});
```
-
### sendMessageRequest9+
sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence, options: MessageOption, callback: AsyncCallback<RequestResult>): void
-Sends a **MessageSequence** message to the remote process in synchronous or asynchronous mode. If **options** is the asynchronous mode, a callback will be invoked immediately and the reply message does not contain any content. If **options** is the synchronous mode, a callback will be invoked when the response to **sendMessageRequest** is returned, and the reply message contains the returned information.
+Sends a **MessageSequence** message to the remote process in synchronous or asynchronous mode. If asynchronous mode is set in **options**, a callback will be called immediately, and the reply message is empty. The specific reply needs to be obtained from the callback on the service side. If synchronous mode is set in **options**, a callback will be invoked when the response to **sendMessageRequest** is returned, and the reply message contains the returned information.
**System capability**: SystemCapability.Communication.IPC.Core
**Parameters**
- | Name | Type | Mandatory| Description |
- | ------------- | ---------------------------------- | ---- | -------------------------------------------------------------------------------------- |
- | code | number | Yes | Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
- | data | [MessageSequence](#messagesequence9) | Yes | **MessageSequence** object holding the data to send. |
- | reply | [MessageSequence](#messagesequence9) | Yes | **MessageSequence** object that receives the response. |
- | options | [MessageOption](#messageoption) | Yes | Request sending mode, which can be synchronous (default) or asynchronous. |
- | AsyncCallback | AsyncCallback<RequestResult> | Yes | Callback for receiving the sending result. |
+| Name | Type | Mandatory| Description |
+| ------------- | ---------------------------------- | ---- | -------------------------------------------------------------------------------------- |
+| code | number | Yes | Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
+| data | [MessageSequence](#messagesequence9) | Yes | **MessageSequence** object holding the data to send. |
+| reply | [MessageSequence](#messagesequence9) | Yes | **MessageSequence** object that receives the response. |
+| options | [MessageOption](#messageoption) | Yes | Request sending mode, which can be synchronous (default) or asynchronous. |
+| AsyncCallback | AsyncCallback<RequestResult> | Yes | Callback for receiving the sending result. |
**Example**
- ```
+ ```ts
class TestRemoteObject extends rpc.RemoteObject {
constructor(descriptor) {
super(descriptor);
@@ -7697,30 +7809,29 @@ Sends a **MessageSequence** message to the remote process in synchronous or asyn
testRemoteObject.sendMessageRequest(1, data, reply, option, sendRequestCallback);
```
-
### sendRequest8+(deprecated)
>This API is no longer maintained since API version 9. You are advised to use [sendMessageRequest](#sendmessagerequest9).
sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption, callback: AsyncCallback<SendRequestResult>): void
-Sends a **MessageParcel** message to the remote process in synchronous or asynchronous mode. If **options** is the asynchronous mode, a callback will be invoked immediately and the reply message does not contain any content. If **options** is the synchronous mode, a callback will be invoked when the response to sendRequest is returned, and the reply message contains the returned information.
+Sends a **MessageParcel** message to the remote process in synchronous or asynchronous mode. If asynchronous mode is set in **options**, a callback will be called immediately, and the reply message is empty. The specific reply needs to be obtained from the callback on the service side. If synchronous mode is set in **options**, a callback will be invoked when the response to sendRequest is returned, and the reply message contains the returned information.
**System capability**: SystemCapability.Communication.IPC.Core
**Parameters**
- | Name | Type | Mandatory| Description |
- | ------------- | -------------------------------------- | ---- | -------------------------------------------------------------------------------------- |
- | code | number | Yes | Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
- | data | [MessageParcel](#messageparceldeprecated) | Yes | **MessageParcel** object holding the data to send. |
- | reply | [MessageParcel](#messageparceldeprecated) | Yes | **MessageParcel** object that receives the response. |
- | options | [MessageOption](#messageoption) | Yes | Request sending mode, which can be synchronous (default) or asynchronous. |
- | AsyncCallback | AsyncCallback<SendRequestResult> | Yes | Callback for receiving the sending result. |
+| Name | Type | Mandatory| Description |
+| ------------- | -------------------------------------- | ---- | -------------------------------------------------------------------------------------- |
+| code | number | Yes | Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
+| data | [MessageParcel](#messageparceldeprecated) | Yes | **MessageParcel** object holding the data to send. |
+| reply | [MessageParcel](#messageparceldeprecated) | Yes | **MessageParcel** object that receives the response. |
+| options | [MessageOption](#messageoption) | Yes | Request sending mode, which can be synchronous (default) or asynchronous. |
+| AsyncCallback | AsyncCallback<SendRequestResult> | Yes | Callback for receiving the sending result. |
**Example**
- ```
+ ```ts
class MyDeathRecipient {
onRemoteDied() {
console.log("server died");
@@ -7762,7 +7873,6 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch
testRemoteObject.sendRequest(1, data, reply, option, sendRequestCallback);
```
-
### onRemoteRequest8+(deprecated)
>This API is no longer maintained since API version 9. You are advised to use [onRemoteMessageRequest](#onremotemessagerequest9).
@@ -7775,22 +7885,22 @@ Provides a response to **sendMessageRequest()**. The server processes the reques
**Parameters**
- | Name| Type | Mandatory| Description |
- | ------ | ------------------------------- | ---- | --------------------------------------- |
- | code | number | Yes | Service request code sent by the remote end. |
- | data | [MessageParcel](#messageparceldeprecated) | Yes | **MessageParcel** object that holds the parameters called by the client.|
- | reply | [MessageParcel](#messageparceldeprecated) | Yes | **MessageParcel** object carrying the result. |
- | option | [MessageOption](#messageoption) | Yes | Whether the operation is synchronous or asynchronous. |
+| Name| Type | Mandatory| Description |
+| ------ | ------------------------------- | ---- | --------------------------------------- |
+| code | number | Yes | Service request code sent by the remote end. |
+| data | [MessageParcel](#messageparceldeprecated) | Yes | **MessageParcel** object that holds the parameters called by the client.|
+| reply | [MessageParcel](#messageparceldeprecated) | Yes | **MessageParcel** object carrying the result. |
+| option | [MessageOption](#messageoption) | Yes | Whether the operation is synchronous or asynchronous. |
**Return value**
- | Type | Description |
- | ------- | ----------------------------------------- |
- | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
+| Type | Description |
+| ------- | ----------------------------------------- |
+| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Example**
- ```ets
+ ```ts
class MyDeathRecipient {
onRemoteDied() {
console.log("server died");
@@ -7836,23 +7946,23 @@ Provides a response to **sendMessageRequest()**. The server processes the reques
**Parameters**
- | Name| Type | Mandatory| Description |
- | ------ | ------------------------------- | ---- | ----------------------------------------- |
- | code | number | Yes | Service request code sent by the remote end. |
- | data | [MessageSequence](#messagesequence9) | Yes | **MessageSequence** object that holds the parameters called by the client.|
- | reply | [MessageSequence](#messagesequence9) | Yes | **MessageSequence** object to which the result is written. |
- | option | [MessageOption](#messageoption) | Yes | Whether the operation is synchronous or asynchronous. |
+| Name| Type | Mandatory| Description |
+| ------ | ------------------------------- | ---- | ----------------------------------------- |
+| code | number | Yes | Service request code sent by the remote end. |
+| data | [MessageSequence](#messagesequence9) | Yes | **MessageSequence** object that holds the parameters called by the client.|
+| reply | [MessageSequence](#messagesequence9) | Yes | **MessageSequence** object to which the result is written. |
+| option | [MessageOption](#messageoption) | Yes | Whether the operation is synchronous or asynchronous. |
**Return value**
- | Type | Description |
- | ----------------- | ---------------------------------------------------------------------------------------------- |
- | boolean | Returns a Boolean value if the request is processed synchronously in **onRemoteMessageRequest**. If the operation is successful, **true** is returned. Otherwise, **false** is returned.|
- | Promise\ | Returns a promise object if the request is processed asynchronously in **onRemoteMessageRequest**. |
+| Type | Description |
+| ----------------- | ---------------------------------------------------------------------------------------------- |
+| boolean | Returns a Boolean value if the request is processed synchronously in **onRemoteMessageRequest**. The value **true** means the operation is successful; the value **false** means the opposite.|
+| Promise\ | Returns a promise object if the request is processed asynchronously in **onRemoteMessageRequest**. |
**Example**: Overload **onRemoteMessageRequest** to process requests synchronously.
- ```ets
+ ```ts
class TestRemoteObject extends rpc.RemoteObject {
constructor(descriptor) {
super(descriptor);
@@ -7872,7 +7982,7 @@ Provides a response to **sendMessageRequest()**. The server processes the reques
**Example**: Overload **onRemoteMessageRequest** to process requests asynchronously.
- ```ets
+ ```ts
class TestRemoteObject extends rpc.RemoteObject {
constructor(descriptor) {
super(descriptor);
@@ -7895,7 +8005,7 @@ Provides a response to **sendMessageRequest()**. The server processes the reques
**Example**: Overload **onRemoteMessageRequest** and **onRemoteRequest** to process requests synchronously.
- ```ets
+ ```ts
class TestRemoteObject extends rpc.RemoteObject {
constructor(descriptor) {
super(descriptor);
@@ -7926,7 +8036,7 @@ Provides a response to **sendMessageRequest()**. The server processes the reques
**Example**: Overload **onRemoteMessageRequest** and **onRemoteRequest** to process requests asynchronously.
- ```ets
+ ```ts
class TestRemoteObject extends rpc.RemoteObject {
constructor(descriptor) {
super(descriptor);
@@ -7957,7 +8067,6 @@ Provides a response to **sendMessageRequest()**. The server processes the reques
}
```
-
### getCallingUid
getCallingUid(): number
@@ -7967,13 +8076,13 @@ Obtains the UID of the remote process.
**System capability**: SystemCapability.Communication.IPC.Core
**Return value**
- | Type | Description |
- | ------ | ----------------------- |
- | number | UID of the remote process obtained.|
+| Type | Description |
+| ------ | ----------------------- |
+| number | UID of the remote process obtained.|
**Example**
- ```
+ ```ts
class TestRemoteObject extends rpc.RemoteObject {
constructor(descriptor) {
super(descriptor);
@@ -7993,13 +8102,13 @@ Obtains the PID of the remote process.
**Return value**
- | Type | Description |
- | ------ | ----------------------- |
- | number | PID of the remote process obtained.|
+| Type | Description |
+| ------ | ----------------------- |
+| number | PID of the remote process obtained.|
**Example**
- ```
+ ```ts
class TestRemoteObject extends rpc.RemoteObject {
constructor(descriptor) {
super(descriptor);
@@ -8013,26 +8122,26 @@ Obtains the PID of the remote process.
getLocalInterface(descriptor: string): IRemoteBroker
-Obtains the interface.
+Obtains the interface descriptor.
**System capability**: SystemCapability.Communication.IPC.Core
**Parameters**
- | Name | Type | Mandatory| Description |
- | ---------- | ------ | ---- | -------------------- |
- | descriptor | string | Yes | Interface descriptor.|
+| Name | Type | Mandatory| Description |
+| ---------- | ------ | ---- | -------------------- |
+| descriptor | string | Yes | Interface descriptor.|
**Return value**
- | Type | Description |
- | ------------- | --------------------------------------------- |
- | IRemoteBroker | **IRemoteBroker** object bound to the specified interface token.|
+| Type | Description |
+| ------------- | --------------------------------------------- |
+| IRemoteBroker | **IRemoteBroker** object bound to the specified interface token.|
**Example**
- ```
+ ```ts
class MyDeathRecipient {
onRemoteDied() {
console.log("server died");
@@ -8042,8 +8151,12 @@ Obtains the interface.
constructor(descriptor) {
super(descriptor);
}
- registerDeathRecipient(recipient: MyDeathRecipient, flags: number);
- unregisterDeathRecipient(recipient: MyDeathRecipient, flags: number);
+ registerDeathRecipient(recipient: MyDeathRecipient, flags: number) {
+ // Implement the method logic based on service requirements.
+ }
+ unregisterDeathRecipient(recipient: MyDeathRecipient, flags: number) {
+ // Implement the method logic based on service requirements.
+ }
isObjectDead(): boolean {
return false;
}
@@ -8052,12 +8165,11 @@ Obtains the interface.
try {
let broker = testRemoteObject.getLocalInterface("testObject");
} catch(error) {
- console.info(rpc get local interface fail, errorCode " + error.code);
- console.info(rpc get local interface fail, errorMessage " + error.message);
+ console.info("rpc get local interface fail, errorCode " + error.code);
+ console.info("rpc get local interface fail, errorMessage " + error.message);
}
```
-
### queryLocalInterface(deprecated)
>This API is no longer maintained since API version 9. You are advised to use [getLocalInterface](#getlocalinterface9).
@@ -8070,19 +8182,19 @@ Checks whether the remote object corresponding to the specified interface token
**Parameters**
- | Name | Type | Mandatory| Description |
- | ---------- | ------ | ---- | ---------------------- |
- | descriptor | string | Yes | Interface descriptor.|
+| Name | Type | Mandatory| Description |
+| ---------- | ------ | ---- | ---------------------- |
+| descriptor | string | Yes | Interface descriptor.|
**Return value**
- | Type | Description |
- | ------------- | ------------------------------------------------------------------ |
- | IRemoteBroker | Returns the remote object if a match is found; returns **Null** otherwise.|
+| Type | Description |
+| ------------- | ------------------------------------------------------------------ |
+| IRemoteBroker | Returns the remote object if a match is found; returns **Null** otherwise.|
**Example**
- ```
+ ```ts
class MyDeathRecipient {
onRemoteDied() {
console.log("server died");
@@ -8106,7 +8218,6 @@ Checks whether the remote object corresponding to the specified interface token
let broker = testRemoteObject.queryLocalInterface("testObject");
```
-
### getDescriptor9+
getDescriptor(): string
@@ -8117,21 +8228,21 @@ Obtains the interface descriptor of this object. The interface descriptor is a s
**Return value**
- | Type | Description |
- | ------ | ---------------- |
- | string | Interface descriptor obtained.|
+| Type | Description |
+| ------ | ---------------- |
+| string | Interface descriptor obtained.|
-**Error Code**
+**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | ------- | -------- |
- | 1900008 | proxy or remote object is invalid |
+| ID| Error Message|
+| ------- | -------- |
+| 1900008 | proxy or remote object is invalid |
**Example**
- ```
+ ```ts
class MyDeathRecipient {
onRemoteDied() {
console.log("server died");
@@ -8141,8 +8252,12 @@ For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode
constructor(descriptor) {
super(descriptor);
}
- addDeathRecipient(recipient: MyDeathRecipient, flags: number);
- unregisterDeathRecipient(recipient: MyDeathRecipient, flags: number);
+ registerDeathRecipient(recipient: MyDeathRecipient, flags: number) {
+ // Implement the method logic based on service requirements.
+ }
+ unregisterDeathRecipient(recipient: MyDeathRecipient, flags: number) {
+ // Implement the method logic based on service requirements.
+ }
isObjectDead(): boolean {
return false;
}
@@ -8151,13 +8266,12 @@ For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode
try {
let descriptor = testRemoteObject.getDescriptor();
} catch(error) {
- console.info(rpc get local interface fail, errorCode " + error.code);
- console.info(rpc get local interface fail, errorMessage " + error.message);
+ console.info("rpc get local interface fail, errorCode " + error.code);
+ console.info("rpc get local interface fail, errorMessage " + error.message);
}
console.log("RpcServer: descriptor is: " + descriptor);
```
-
### getInterfaceDescriptor(deprecated)
>This API is no longer maintained since API version 9. You are advised to use [getDescriptor](#getdescriptor9).
@@ -8170,13 +8284,13 @@ Obtains the interface descriptor.
**Return value**
- | Type | Description |
- | ------ | ---------------- |
- | string | Interface descriptor obtained.|
+| Type | Description |
+| ------ | ---------------- |
+| string | Interface descriptor obtained.|
**Example**
- ```
+ ```ts
class MyDeathRecipient {
onRemoteDied() {
console.log("server died");
@@ -8201,7 +8315,6 @@ Obtains the interface descriptor.
console.log("RpcServer: descriptor is: " + descriptor);
```
-
### modifyLocalInterface9+
modifyLocalInterface(localInterface: IRemoteBroker, descriptor: string): void
@@ -8212,15 +8325,14 @@ Binds an interface descriptor to an **IRemoteBroker** object.
**Parameters**
- | Name | Type | Mandatory| Description |
- | -------------- | ------------- | ---- | ------------------------------------- |
- | localInterface | IRemoteBroker | Yes | **IRemoteBroker** object. |
- | descriptor | string | Yes | Interface descriptor.|
-
+| Name | Type | Mandatory| Description |
+| -------------- | ------------- | ---- | ------------------------------------- |
+| localInterface | IRemoteBroker | Yes | **IRemoteBroker** object. |
+| descriptor | string | Yes | Interface descriptor.|
**Example**
- ```
+ ```ts
class MyDeathRecipient {
onRemoteDied() {
console.log("server died");
@@ -8236,8 +8348,12 @@ Binds an interface descriptor to an **IRemoteBroker** object.
console.info(rpc attach local interface fail, errorMessage " + error.message);
}
}
- registerDeathRecipient(recipient: MyDeathRecipient, flags: number);
- unregisterDeathRecipient(recipient: MyDeathRecipient, flags: number);
+ registerDeathRecipient(recipient: MyDeathRecipient, flags: number) {
+ // Implement the method logic based on service requirements.
+ }
+ unregisterDeathRecipient(recipient: MyDeathRecipient, flags: number) {
+ // Implement the method logic based on service requirements.
+ }
isObjectDead(): boolean {
return false;
}
@@ -8260,14 +8376,14 @@ Binds an interface descriptor to an **IRemoteBroker** object.
**Parameters**
- | Name | Type | Mandatory| Description |
- | -------------- | ------------- | ---- | ------------------------------------- |
- | localInterface | IRemoteBroker | Yes | **IRemoteBroker** object. |
- | descriptor | string | Yes | Interface descriptor.|
+| Name | Type | Mandatory| Description |
+| -------------- | ------------- | ---- | ------------------------------------- |
+| localInterface | IRemoteBroker | Yes | **IRemoteBroker** object. |
+| descriptor | string | Yes | Interface descriptor.|
**Example**
- ```
+ ```ts
class MyDeathRecipient {
onRemoteDied() {
console.log("server died");
@@ -8294,48 +8410,45 @@ Binds an interface descriptor to an **IRemoteBroker** object.
let testRemoteObject = new TestRemoteObject("testObject");
```
-
## Ashmem8+
Provides methods related to anonymous shared memory objects, including creating, closing, mapping, and unmapping an **Ashmem** object, reading data from and writing data to an **Ashmem** object, obtaining the **Ashmem** size, and setting **Ashmem** protection.
-The table below describes the protection types of the mapped memory.
-
**System capability**: SystemCapability.Communication.IPC.Core
- | Name | Value | Description |
- | ---------- | --- | ------------------ |
- | PROT_EXEC | 4 | The mapped memory is executable. |
- | PROT_NONE | 0 | The mapped memory is inaccessible.|
- | PROT_READ | 1 | The mapped memory is readable. |
- | PROT_WRITE | 2 | The mapped memory is writeable. |
+The table below describes the protection types of the mapped memory.
+| Name | Value | Description |
+| ---------- | --- | ------------------ |
+| PROT_EXEC | 4 | The mapped memory is executable. |
+| PROT_NONE | 0 | The mapped memory is inaccessible.|
+| PROT_READ | 1 | The mapped memory is readable. |
+| PROT_WRITE | 2 | The mapped memory is writeable. |
### create9+
static create(name: string, size: number): Ashmem
-Creates an **Ashmem** object with the specified name and size.
+Creates an **Ashmem** object with the specified name and size. This API is a static method.
**System capability**: SystemCapability.Communication.IPC.Core
**Parameters**
- | Name| Type | Mandatory| Description |
- | ------ | ------ | ---- | ---------------------------- |
- | name | string | Yes | Name of the **Ashmem** object to create. |
- | size | number | Yes | Size (in bytes) of the **Ashmem** object to create.|
+| Name| Type | Mandatory| Description |
+| ------ | ------ | ---- | ---------------------------- |
+| name | string | Yes | Name of the **Ashmem** object to create. |
+| size | number | Yes | Size (in bytes) of the **Ashmem** object to create.|
**Return value**
- | Type | Description |
- | ------ | ---------------------------------------------- |
- | Ashmem | Returns the **Ashmem** object if it is created successfully; returns null otherwise.|
-
+| Type | Description |
+| ------ | ---------------------------------------------- |
+| Ashmem | Returns the **Ashmem** object if it is created successfully; returns null otherwise.|
**Example**
- ```
+ ```ts
let ashmem;
try {
ashmem = rpc.Ashmem.create("ashmem", 1024*1024);
@@ -8347,63 +8460,61 @@ Creates an **Ashmem** object with the specified name and size.
console.log("RpcTest: get ashemm by create : " + ashmem + " size is : " + size);
```
-
### createAshmem8+(deprecated)
>This API is no longer maintained since API version 9. You are advised to use [create](#create9).
static createAshmem(name: string, size: number): Ashmem
-Creates an **Ashmem** object with the specified name and size.
+Creates an **Ashmem** object with the specified name and size. This API is a static method.
**System capability**: SystemCapability.Communication.IPC.Core
**Parameters**
- | Name| Type | Mandatory| Description |
- | ------ | ------ | ---- | ---------------------------- |
- | name | string | Yes | Name of the **Ashmem** object to create. |
- | size | number | Yes | Size (in bytes) of the **Ashmem** object to create.|
+| Name| Type | Mandatory| Description |
+| ------ | ------ | ---- | ---------------------------- |
+| name | string | Yes | Name of the **Ashmem** object to create. |
+| size | number | Yes | Size (in bytes) of the **Ashmem** object to create.|
**Return value**
- | Type | Description |
- | ------ | ---------------------------------------------- |
- | Ashmem | Returns the **Ashmem** object if it is created successfully; returns null otherwise.|
+| Type | Description |
+| ------ | ---------------------------------------------- |
+| Ashmem | Returns the **Ashmem** object if it is created successfully; returns null otherwise.|
**Example**
- ```
+ ```ts
let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024);
let size = ashmem.getAshmemSize();
console.log("RpcTest: get ashemm by createAshmem : " + ashmem + " size is : " + size);
```
-
### create9+
static create(ashmem: Ashmem): Ashmem
-Creates an **Ashmem** object by copying the file descriptor (FD) of an existing Ashmem object. The two **Ashmem** objects point to the same shared memory region.
+Creates an **Ashmem** object by copying the file descriptor of an existing **Ashmem** object. The two **Ashmem** objects point to the same shared memory region.
**System capability**: SystemCapability.Communication.IPC.Core
**Parameters**
- | Name| Type | Mandatory| Description |
- | ------ | ------ | ---- | -------------------- |
- | ashmem | Ashmem | Yes | Existing **Ashmem** object.|
+| Name| Type | Mandatory| Description |
+| ------ | ------ | ---- | -------------------- |
+| ashmem | Ashmem | Yes | Existing **Ashmem** object.|
**Return value**
- | Type | Description |
- | ------ | ---------------------- |
- | Ashmem | **Ashmem** object created.|
+| Type | Description |
+| ------ | ---------------------- |
+| Ashmem | **Ashmem** object created.|
**Example**
- ```
+ ```ts
let ashmem2;
try {
let ashmem = rpc.Ashmem.create("ashmem", 1024*1024);
@@ -8416,39 +8527,37 @@ Creates an **Ashmem** object by copying the file descriptor (FD) of an existing
console.log("RpcTest: get ashemm by create : " + ashmem2 + " size is : " + size);
```
-
### createAshmemFromExisting8+(deprecated)
>This API is no longer maintained since API version 9. You are advised to use [create](#create9).
static createAshmemFromExisting(ashmem: Ashmem): Ashmem
-Creates an **Ashmem** object by copying the file descriptor (FD) of an existing Ashmem object. The two **Ashmem** objects point to the same shared memory region.
+Creates an **Ashmem** object by copying the file descriptor of an existing **Ashmem** object. The two **Ashmem** objects point to the same shared memory region.
**System capability**: SystemCapability.Communication.IPC.Core
**Parameters**
- | Name| Type | Mandatory| Description |
- | ------ | ------ | ---- | -------------------- |
- | ashmem | Ashmem | Yes | Existing **Ashmem** object.|
+| Name| Type | Mandatory| Description |
+| ------ | ------ | ---- | -------------------- |
+| ashmem | Ashmem | Yes | Existing **Ashmem** object.|
**Return value**
- | Type | Description |
- | ------ | ---------------------- |
- | Ashmem | **Ashmem** object created.|
+| Type | Description |
+| ------ | ---------------------- |
+| Ashmem | **Ashmem** object created.|
**Example**
- ```
+ ```ts
let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024);
let ashmem2 = rpc.Ashmem.createAshmemFromExisting(ashmem);
let size = ashmem2.getAshmemSize();
console.log("RpcTest: get ashemm by createAshmemFromExisting : " + ashmem2 + " size is : " + size);
```
-
### closeAshmem8+
closeAshmem(): void
@@ -8459,12 +8568,11 @@ Closes this **Ashmem** object.
**Example**
- ```
+ ```ts
let ashmem = rpc.Ashmem.create("ashmem", 1024*1024);
ashmem.closeAshmem();
```
-
### unmapAshmem8+
unmapAshmem(): void
@@ -8475,12 +8583,11 @@ Deletes the mappings for the specified address range of this **Ashmem** object.
**Example**
- ```
+ ```ts
let ashmem = rpc.Ashmem.create("ashmem", 1024*1024);
ashmem.unmapAshmem();
```
-
### getAshmemSize8+
getAshmemSize(): number
@@ -8491,19 +8598,18 @@ Obtains the memory size of this **Ashmem** object.
**Return value**
- | Type | Description |
- | ------ | -------------------------- |
- | number | **Ashmem** size obtained.|
+| Type | Description |
+| ------ | -------------------------- |
+| number | **Ashmem** size obtained.|
**Example**
- ```
+ ```ts
let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024);
let size = ashmem.getAshmemSize();
console.log("RpcTest: get ashmem is " + ashmem + " size is : " + size);
```
-
### mapTypedAshmem9+
mapTypedAshmem(mapType: number): void
@@ -8514,21 +8620,21 @@ Creates the shared file mapping on the virtual address space of this process. Th
**Parameters**
- | Name | Type | Mandatory| Description |
- | ------- | ------ | ---- | ------------------------------ |
- | mapType | number | Yes | Protection level of the memory region to which the shared file is mapped.|
+| Name | Type | Mandatory| Description |
+| ------- | ------ | ---- | ------------------------------ |
+| mapType | number | Yes | Protection level of the memory region to which the shared file is mapped.|
-**Error Code**
+**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | ------- | ------ |
- | 1900001 | call mmap function failed |
+| ID| Error Message|
+| ------- | ------ |
+| 1900001 | call mmap function failed |
**Example**
- ```
+ ```ts
let ashmem = rpc.Ashmem.create("ashmem", 1024*1024);
try {
ashmem.mapTypedAshmem(ashmem.PROT_READ | ashmem.PROT_WRITE);
@@ -8538,7 +8644,6 @@ For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode
}
```
-
### mapAshmem8+(deprecated)
>This API is no longer maintained since API version 9. You are advised to use [mapTypedAshmem](#maptypedashmem9).
@@ -8551,25 +8656,24 @@ Creates the shared file mapping on the virtual address space of this process. Th
**Parameters**
- | Name | Type | Mandatory| Description |
- | ------- | ------ | ---- | ------------------------------ |
- | mapType | number | Yes | Protection level of the memory region to which the shared file is mapped.|
+| Name | Type | Mandatory| Description |
+| ------- | ------ | ---- | ------------------------------ |
+| mapType | number | Yes | Protection level of the memory region to which the shared file is mapped.|
**Return value**
- | Type | Description |
- | ------- | ----------------------------------------- |
- | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
+| Type | Description |
+| ------- | ----------------------------------------- |
+| boolean | Returns **true** if the mapping is created; returns **false** otherwise.|
**Example**
- ```
+ ```ts
let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024);
let mapReadAndWrite = ashmem.mapAshmem(ashmem.PROT_READ | ashmem.PROT_WRITE);
console.log("RpcTest: map ashmem result is : " + mapReadAndWrite);
```
-
### mapReadWriteAshmem9+
mapReadWriteAshmem(): void
@@ -8578,17 +8682,17 @@ Maps the shared file to the readable and writable virtual address space of the p
**System capability**: SystemCapability.Communication.IPC.Core
-**Error Code**
+**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | ------- | -------- |
- | 1900001 | call mmap function failed |
+| ID| Error Message|
+| ------- | -------- |
+| 1900001 | call mmap function failed |
**Example**
- ```
+ ```ts
let ashmem = rpc.Ashmem.create("ashmem", 1024*1024);
try {
ashmem.mapReadWriteAshmem();
@@ -8598,7 +8702,6 @@ For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode
}
```
-
### mapReadAndWriteAshmem8+(deprecated)
>This API is no longer maintained since API version 9. You are advised to use [mapReadWriteAshmem](#mapreadwriteashmem9).
@@ -8611,19 +8714,18 @@ Maps the shared file to the readable and writable virtual address space of the p
**Return value**
- | Type | Description |
- | ------- | ----------------------------------------- |
- | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
+| Type | Description |
+| ------- | ----------------------------------------- |
+| boolean | Returns **true** if the mapping is created; returns **false** otherwise.|
**Example**
- ```
+ ```ts
let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024);
let mapResult = ashmem.mapReadAndWriteAshmem();
console.log("RpcTest: map ashmem result is : " + mapResult);
```
-
### mapReadonlyAshmem9+
mapReadonlyAshmem(): void
@@ -8632,17 +8734,17 @@ Maps the shared file to the read-only virtual address space of the process.
**System capability**: SystemCapability.Communication.IPC.Core
-**Error Code**
+**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | ------- | -------- |
- | 1900001 | call mmap function failed |
+| ID| Error Message|
+| ------- | -------- |
+| 1900001 | call mmap function failed |
**Example**
- ```
+ ```ts
let ashmem = rpc.Ashmem.create("ashmem", 1024*1024);
try {
ashmem.mapReadonlyAshmem();
@@ -8652,7 +8754,6 @@ For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode
}
```
-
### mapReadOnlyAshmem8+(deprecated)
>This API is no longer maintained since API version 9. You are advised to use [mapReadonlyAshmem](#mapreadonlyashmem9).
@@ -8665,19 +8766,18 @@ Maps the shared file to the read-only virtual address space of the process.
**Return value**
- | Type | Description |
- | ------- | ----------------------------------------- |
- | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
+| Type | Description |
+| ------- | ----------------------------------------- |
+| boolean | Returns **true** if the mapping is created; returns **false** otherwise.|
**Example**
- ```
+ ```ts
let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024);
let mapResult = ashmem.mapReadOnlyAshmem();
console.log("RpcTest: Ashmem mapReadOnlyAshmem result is : " + mapResult);
```
-
### setProtectionType9+
setProtectionType(protectionType: number): void
@@ -8688,21 +8788,21 @@ Sets the protection level of the memory region to which the shared file is mappe
**Parameters**
- | Name | Type | Mandatory| Description |
- | -------------- | ------ | ---- | ------------------ |
- | protectionType | number | Yes | Protection type to set.|
+| Name | Type | Mandatory| Description |
+| -------------- | ------ | ---- | ------------------ |
+| protectionType | number | Yes | Protection type to set.|
-**Error Code**
+**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | -------- | ------- |
- | 1900002 | call os ioctl function failed |
+| ID| Error Message|
+| -------- | ------- |
+| 1900002 | call os ioctl function failed |
**Example**
- ```
+ ```ts
let ashmem = rpc.Ashmem.create("ashmem", 1024*1024);
try {
ashmem.setProtection(ashmem.PROT_READ);
@@ -8712,7 +8812,6 @@ For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode
}
```
-
### setProtection8+(deprecated)
>This API is no longer maintained since API version 9. You are advised to use [setProtectionType](#setprotectiontype9).
@@ -8725,25 +8824,24 @@ Sets the protection level of the memory region to which the shared file is mappe
**Parameters**
- | Name | Type | Mandatory| Description |
- | -------------- | ------ | ---- | ------------------ |
- | protectionType | number | Yes | Protection type to set.|
+| Name | Type | Mandatory| Description |
+| -------------- | ------ | ---- | ------------------ |
+| protectionType | number | Yes | Protection type to set.|
**Return value**
- | Type | Description |
- | ------- | ----------------------------------------- |
- | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
+| Type | Description |
+| ------- | ----------------------------------------- |
+| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Example**
- ```
+ ```ts
let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024);
let result = ashmem.setProtection(ashmem.PROT_READ);
console.log("RpcTest: Ashmem setProtection result is : " + result);
```
-
### writeAshmem9+
writeAshmem(buf: number[], size: number, offset: number): void
@@ -8754,23 +8852,23 @@ Writes data to the shared file associated with this **Ashmem** object.
**Parameters**
- | Name| Type | Mandatory| Description |
- | ------ | -------- | ---- | -------------------------------------------------- |
- | buf | number[] | Yes | Data to write. |
- | size | number | Yes | Size of the data to write. |
- | offset | number | Yes | Start position of the data to write in the memory region associated with this **Ashmem** object.|
+| Name| Type | Mandatory| Description |
+| ------ | -------- | ---- | -------------------------------------------------- |
+| buf | number[] | Yes | Data to write. |
+| size | number | Yes | Size of the data to write. |
+| offset | number | Yes | Start position of the data to write in the memory region associated with this **Ashmem** object.|
-**Error Code**
+**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID| Error Message|
- | ------- | -------- |
- | 1900003 | write to ashmem failed |
+| ID| Error Message|
+| ------- | -------- |
+| 1900003 | write to ashmem failed |
**Example**
- ```
+ ```ts
let ashmem = rpc.Ashmem.create("ashmem", 1024*1024);
ashmem.mapReadWriteAshmem();
var ByteArrayVar = [1, 2, 3, 4, 5];
@@ -8782,7 +8880,6 @@ For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode
}
```
-
### writeToAshmem8+(deprecated)
>This API is no longer maintained since API version 9. You are advised to use [writeAshmem](#writeashmem9).
@@ -8795,21 +8892,21 @@ Writes data to the shared file associated with this **Ashmem** object.
**Parameters**
- | Name| Type | Mandatory| Description |
- | ------ | -------- | ---- | -------------------------------------------------- |
- | buf | number[] | Yes | Data to write. |
- | size | number | Yes | Size of the data to write. |
- | offset | number | Yes | Start position of the data to write in the memory region associated with this **Ashmem** object.|
+| Name| Type | Mandatory| Description |
+| ------ | -------- | ---- | -------------------------------------------------- |
+| buf | number[] | Yes | Data to write. |
+| size | number | Yes | Size of the data to write. |
+| offset | number | Yes | Start position of the data to write in the memory region associated with this **Ashmem** object.|
**Return value**
- | Type | Description |
- | ------- | ----------------------------------------------------------------------------------------- |
- | boolean | Returns **true** is the data is written successfully; returns **false** otherwise.|
+| Type | Description |
+| ------- | ----------------------------------------------------------------------------------------- |
+| boolean | Returns **true** if the data is written successfully; returns **false** otherwise.|
**Example**
- ```
+ ```ts
let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024);
let mapResult = ashmem.mapReadAndWriteAshmem();
console.info("RpcTest map ashmem result is " + mapResult);
@@ -8818,7 +8915,6 @@ Writes data to the shared file associated with this **Ashmem** object.
console.log("RpcTest: write to Ashmem result is : " + writeResult);
```
-
### readAshmem9+
readAshmem(size: number, offset: number): number[]
@@ -8829,28 +8925,28 @@ Reads data from the shared file associated with this **Ashmem** object.
**Parameters**
- | Name| Type | Mandatory| Description |
- | ------ | ------ | ---- | -------------------------------------------------- |
- | size | number | Yes | Size of the data to read. |
- | offset | number | Yes | Start position of the data to read in the memory region associated with this **Ashmem** object.|
+| Name| Type | Mandatory| Description |
+| ------ | ------ | ---- | -------------------------------------------------- |
+| size | number | Yes | Size of the data to read. |
+| offset | number | Yes | Start position of the data to read in the memory region associated with this **Ashmem** object.|
**Return value**
- | Type | Description |
- | -------- | ---------------- |
- | number[] | Data read.|
+| Type | Description |
+| -------- | ---------------- |
+| number[] | Data read.|
-**Error Code**
+**Error codes**
For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode-rpc.md).
- | ID | Error Message|
- | -------- | -------- |
- | 1900004 | read from ashmem failed |
+| ID | Error Message|
+| -------- | -------- |
+| 1900004 | read from ashmem failed |
**Example**
- ```
+ ```ts
let ashmem = rpc.Ashmem.create("ashmem", 1024*1024);
ashmem.mapReadWriteAshmem();
var ByteArrayVar = [1, 2, 3, 4, 5];
@@ -8864,7 +8960,6 @@ For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode
}
```
-
### readFromAshmem8+(deprecated)
>This API is no longer maintained since API version 9. You are advised to use [readAshmem](#readashmem9).
@@ -8877,20 +8972,20 @@ Reads data from the shared file associated with this **Ashmem** object.
**Parameters**
- | Name| Type | Mandatory| Description |
- | ------ | ------ | ---- | -------------------------------------------------- |
- | size | number | Yes | Size of the data to read. |
- | offset | number | Yes | Start position of the data to read in the memory region associated with this **Ashmem** object.|
+| Name| Type | Mandatory| Description |
+| ------ | ------ | ---- | -------------------------------------------------- |
+| size | number | Yes | Size of the data to read. |
+| offset | number | Yes | Start position of the data to read in the memory region associated with this **Ashmem** object.|
**Return value**
- | Type | Description |
- | -------- | ---------------- |
- | number[] | Data read.|
+| Type | Description |
+| -------- | ---------------- |
+| number[] | Data read.|
**Example**
- ```
+ ```ts
let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024);
let mapResult = ashmem.mapReadAndWriteAshmem();
console.info("RpcTest map ashmem result is " + mapResult);
@@ -8899,4 +8994,4 @@ Reads data from the shared file associated with this **Ashmem** object.
console.log("RpcTest: write to Ashmem result is : " + writeResult);
let readResult = ashmem.readFromAshmem(5, 0);
console.log("RpcTest: read to Ashmem result is : " + readResult);
- ```
+ ```