提交 7a173d89 编写于 作者: A Annie_wang

update docs

Signed-off-by: NAnnie_wang <annie.wangli@huawei.com>
上级 809833a6
# RPC # RPC
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/> > **NOTE**<br>
> 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.
...@@ -26,12 +26,12 @@ Creates a **MessageParcel** object. This method is a static method. ...@@ -26,12 +26,12 @@ Creates a **MessageParcel** object. This method is a static method.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| MessageParcel | **MessageParcel** object created.| | MessageParcel | **MessageParcel** object created.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -47,7 +47,7 @@ Reclaims the **MessageParcel** object that is no longer used. ...@@ -47,7 +47,7 @@ Reclaims the **MessageParcel** object that is no longer used.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Example **Example**
``` ```
let reply = rpc.MessageParcel.create(); let reply = rpc.MessageParcel.create();
...@@ -63,23 +63,37 @@ writeRemoteObject(object: [IRemoteObject](#iremoteobject)): boolean ...@@ -63,23 +63,37 @@ writeRemoteObject(object: [IRemoteObject](#iremoteobject)): boolean
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| object | [IRemoteObject](#iremoteobject) | Yes| Remote object to serialize and write to the **MessageParcel** object.| | object | [IRemoteObject](#iremoteobject) | Yes| Remote object to serialize and write to the **MessageParcel** object.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
class MyDeathRecipient {
onRemoteDied() {
console.log("server died");
}
}
class TestRemoteObject extends rpc.RemoteObject { class TestRemoteObject extends rpc.RemoteObject {
constructor(descriptor) { constructor(descriptor) {
super(descriptor); super(descriptor);
} }
addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
return true;
}
removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
return true;
}
isObjectDead(): boolean {
return false;
}
} }
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
let testRemoteObject = new TestRemoteObject("testObject"); let testRemoteObject = new TestRemoteObject("testObject");
...@@ -95,18 +109,32 @@ Reads the remote object from this **MessageParcel** object. You can use this met ...@@ -95,18 +109,32 @@ Reads the remote object from this **MessageParcel** object. You can use this met
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| [IRemoteObject](#iremoteobject) | Remote object obtained.| | [IRemoteObject](#iremoteobject) | Remote object obtained.|
- Example **Example**
``` ```
class MyDeathRecipient {
onRemoteDied() {
console.log("server died");
}
}
class TestRemoteObject extends rpc.RemoteObject { class TestRemoteObject extends rpc.RemoteObject {
constructor(descriptor) { constructor(descriptor) {
super(descriptor); super(descriptor);
} }
addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
return true;
}
removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
return true;
}
isObjectDead(): boolean {
return false;
}
} }
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
let testRemoteObject = new TestRemoteObject("testObject"); let testRemoteObject = new TestRemoteObject("testObject");
...@@ -123,17 +151,17 @@ Writes an interface token to this **MessageParcel** object. ...@@ -123,17 +151,17 @@ Writes an interface token to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| token | string | Yes| Interface token to write.| | token | string | Yes| Interface token to write.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -150,12 +178,12 @@ Reads the interface token from this **MessageParcel** object. The interface toke ...@@ -150,12 +178,12 @@ Reads the interface token from this **MessageParcel** object. The interface toke
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| string | Interface token obtained.| | string | Interface token obtained.|
- Example **Example**
``` ```
class Stub extends rpc.RemoteObject { class Stub extends rpc.RemoteObject {
...@@ -176,12 +204,12 @@ Obtains the data size of this **MessageParcel** object. ...@@ -176,12 +204,12 @@ Obtains the data size of this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number | Size of the **MessageParcel** object obtained, in bytes.| | number | Size of the **MessageParcel** object obtained, in bytes.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -198,12 +226,12 @@ Obtains the capacity of this **MessageParcel** object. ...@@ -198,12 +226,12 @@ Obtains the capacity of this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number | **MessageParcel** capacity obtained, in bytes.| | number | **MessageParcel** capacity obtained, in bytes.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -220,17 +248,17 @@ Sets the size of data contained in this **MessageParcel** object. ...@@ -220,17 +248,17 @@ Sets the size of data contained in this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| size | number | Yes| Data size to set, in bytes.| | size | number | Yes| Data size to set, in bytes.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -247,17 +275,17 @@ Sets the storage capacity of this **MessageParcel** object. ...@@ -247,17 +275,17 @@ Sets the storage capacity of this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| size | number | Yes| Storage capacity to set, in bytes.| | size | number | Yes| Storage capacity to set, in bytes.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -274,12 +302,12 @@ Obtains the writable capacity of this **MessageParcel** object. ...@@ -274,12 +302,12 @@ Obtains the writable capacity of this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number | **MessageParcel** writable capacity obtained, in bytes.| | number | **MessageParcel** writable capacity obtained, in bytes.|
- Example **Example**
``` ```
class Stub extends rpc.RemoteObject { class Stub extends rpc.RemoteObject {
...@@ -300,12 +328,12 @@ Obtains the readable capacity of this **MessageParcel** object. ...@@ -300,12 +328,12 @@ Obtains the readable capacity of this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number | **MessageParcel** object readable capacity, in bytes.| | number | **MessageParcel** object readable capacity, in bytes.|
- Example **Example**
``` ```
class Stub extends rpc.RemoteObject { class Stub extends rpc.RemoteObject {
...@@ -326,12 +354,12 @@ Obtains the read position of this **MessageParcel** object. ...@@ -326,12 +354,12 @@ Obtains the read position of this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number | Current read position of the **MessageParcel** object.| | number | Current read position of the **MessageParcel** object.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -348,12 +376,12 @@ Obtains the write position of this **MessageParcel** object. ...@@ -348,12 +376,12 @@ Obtains the write position of this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number | Current write position of the **MessageParcel** object.| | number | Current write position of the **MessageParcel** object.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -371,17 +399,17 @@ Moves the read pointer to the specified position. ...@@ -371,17 +399,17 @@ Moves the read pointer to the specified position.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| pos | number | Yes| Position from which data is to read.| | pos | number | Yes| Position from which data is to read.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the read position changes; returns **false** otherwise.| | boolean | Returns **true** if the read position changes; returns **false** otherwise.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -403,17 +431,17 @@ Moves the write pointer to the specified position. ...@@ -403,17 +431,17 @@ Moves the write pointer to the specified position.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| pos | number | Yes| Position from which data is to write.| | pos | number | Yes| Position from which data is to write.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the write position changes; returns **false** otherwise.| | boolean | Returns **true** if the write position changes; returns **false** otherwise.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -433,17 +461,17 @@ Writes a Byte value to this **MessageParcel** object. ...@@ -433,17 +461,17 @@ Writes a Byte value to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| val | number | Yes| Byte value to write.| | val | number | Yes| Byte value to write.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -460,12 +488,12 @@ Reads the Byte value from this **MessageParcel** object. ...@@ -460,12 +488,12 @@ Reads the Byte value from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number | Byte value read.| | number | Byte value read.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -484,17 +512,17 @@ Writes a Short int value to this **MessageParcel** object. ...@@ -484,17 +512,17 @@ Writes a Short int value to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| val | number | Yes| Short int value to write.| | val | number | Yes| Short int value to write.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -511,12 +539,12 @@ Reads the Short int value from this **MessageParcel** object. ...@@ -511,12 +539,12 @@ Reads the Short int value from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number | Short int value read.| | number | Short int value read.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -535,17 +563,17 @@ Writes an Int value to this **MessageParcel** object. ...@@ -535,17 +563,17 @@ Writes an Int value to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| val | number | Yes| Int value to write.| | val | number | Yes| Int value to write.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -562,12 +590,12 @@ Reads the Int value from this **MessageParcel** object. ...@@ -562,12 +590,12 @@ Reads the Int value from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number | Int value read.| | number | Int value read.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -586,17 +614,17 @@ Writes a Long int value to this **MessageParcel** object. ...@@ -586,17 +614,17 @@ Writes a Long int value to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| val | number | Yes| Long int value to write.| | val | number | Yes| Long int value to write.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -613,18 +641,18 @@ Reads the Long int value from this **MessageParcel** object. ...@@ -613,18 +641,18 @@ Reads the Long int value from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number | Long int value read.| | number | Long int value read.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
let result = data.writeLong(10000); let result = data.writeLong(10000);
console.log("RpcClient: writeLong is " + result); console.log("RpcClient: writeLong is " + result);
let ret = data.readlong(); let ret = data.readLong();
console.log("RpcClient: readLong is " + ret); console.log("RpcClient: readLong is " + ret);
``` ```
...@@ -637,17 +665,17 @@ Writes a Float value to this **MessageParcel** object. ...@@ -637,17 +665,17 @@ Writes a Float value to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| val | number | Yes| Float value to write.| | val | number | Yes| Float value to write.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -664,12 +692,12 @@ Reads the Float value from this **MessageParcel** object. ...@@ -664,12 +692,12 @@ Reads the Float value from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number | Float value read.| | number | Float value read.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -688,17 +716,17 @@ Writes a Double value to this **MessageParcel** object. ...@@ -688,17 +716,17 @@ Writes a Double value to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| val | number | Yes| Double value to write.| | val | number | Yes| Double value to write.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -715,12 +743,12 @@ Reads the Double value from this **MessageParcel** object. ...@@ -715,12 +743,12 @@ Reads the Double value from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number | Double value read.| | number | Double value read.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -739,17 +767,17 @@ Writes a Boolean value to this **MessageParcel** object. ...@@ -739,17 +767,17 @@ Writes a Boolean value to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| val | boolean | Yes| Boolean value to write.| | val | boolean | Yes| Boolean value to write.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -766,12 +794,12 @@ Reads the Boolean value from this **MessageParcel** object. ...@@ -766,12 +794,12 @@ Reads the Boolean value from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Boolean value read.| | boolean | Boolean value read.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -790,21 +818,21 @@ Writes a Char value to this **MessageParcel** object. ...@@ -790,21 +818,21 @@ Writes a Char value to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| val | number | Yes| Char value to write.| | val | number | Yes| Char value to write.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
let result = data.writeChar('a'); let result = data.writeChar(97);
console.log("RpcClient: writeChar is " + result); console.log("RpcClient: writeChar is " + result);
``` ```
...@@ -817,16 +845,16 @@ Reads the Char value from this **MessageParcel** object. ...@@ -817,16 +845,16 @@ Reads the Char value from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number | Char value read.| | number | Char value read.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
let result = data.writeChar('a'); let result = data.writeChar(97);
console.log("RpcClient: writeChar is " + result); console.log("RpcClient: writeChar is " + result);
let ret = data.readChar(); let ret = data.readChar();
console.log("RpcClient: readChar is " + ret); console.log("RpcClient: readChar is " + ret);
...@@ -841,17 +869,17 @@ Writes a String value to this **MessageParcel** object. ...@@ -841,17 +869,17 @@ Writes a String value to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| val | string | Yes| String value to write.| | val | string | Yes| String value to write.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -868,12 +896,12 @@ Reads the String value from this **MessageParcel** object. ...@@ -868,12 +896,12 @@ Reads the String value from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| string | String value read.| | string | String value read.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -892,23 +920,25 @@ Writes a sequenceable object to this **MessageParcel** object. ...@@ -892,23 +920,25 @@ Writes a sequenceable object to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| val | [Sequenceable](#sequenceable) | Yes| Sequenceable object to write.| | val | [Sequenceable](#sequenceable) | Yes| Sequenceable object to write.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
class MySequenceable { class MySequenceable {
constructor(num, string) { num: number;
str: string;
constructor(num, str) {
this.num = num; this.num = num;
this.str = string; this.str = str;
} }
marshalling(messageParcel) { marshalling(messageParcel) {
messageParcel.writeInt(this.num); messageParcel.writeInt(this.num);
...@@ -936,23 +966,25 @@ Reads member variables from this **MessageParcel** object. ...@@ -936,23 +966,25 @@ Reads member variables from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| dataIn | [Sequenceable](#sequenceable) | Yes| Object that reads member variables from the **MessageParcel** object.| | dataIn | [Sequenceable](#sequenceable) | Yes| Object that reads member variables from the **MessageParcel** object.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
class MySequenceable { class MySequenceable {
constructor(num, string) { num: number;
str: string;
constructor(num, str) {
this.num = num; this.num = num;
this.str = string; this.str = str;
} }
marshalling(messageParcel) { marshalling(messageParcel) {
messageParcel.writeInt(this.num); messageParcel.writeInt(this.num);
...@@ -983,21 +1015,21 @@ Writes a ByteArray to this **MessageParcel** object. ...@@ -983,21 +1015,21 @@ Writes a ByteArray to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| byteArray | number[] | Yes| ByteArray to write.| | byteArray | number[] | Yes| ByteArray to write.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
let ByteArrayVar = new Int8Array([1, 2, 3, 4, 5]); let ByteArrayVar = [1, 2, 3, 4, 5];
let result = data.writeByteArray(ByteArrayVar); let result = data.writeByteArray(ByteArrayVar);
console.log("RpcClient: writeByteArray is " + result); console.log("RpcClient: writeByteArray is " + result);
``` ```
...@@ -1011,16 +1043,16 @@ Reads the ByteArray from this **MessageParcel** object. ...@@ -1011,16 +1043,16 @@ Reads the ByteArray from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| dataIn | number[] | Yes| ByteArray to read.| | dataIn | number[] | Yes| ByteArray to read.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
let ByteArrayVar = new Int8Array([1, 2, 3, 4, 5]); let ByteArrayVar = [1, 2, 3, 4, 5];
let result = data.writeByteArray(ByteArrayVar); let result = data.writeByteArray(ByteArrayVar);
console.log("RpcClient: writeByteArray is " + result); console.log("RpcClient: writeByteArray is " + result);
let array = new Array(5); let array = new Array(5);
...@@ -1036,16 +1068,16 @@ Reads the ByteArray from this **MessageParcel** object. ...@@ -1036,16 +1068,16 @@ Reads the ByteArray from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number[] | ByteArray read.| | number[] | ByteArray read.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
let ByteArrayVar = new Int8Array([1, 2, 3, 4, 5]); let ByteArrayVar = [1, 2, 3, 4, 5];
let result = data.writeByteArray(ByteArrayVar); let result = data.writeByteArray(ByteArrayVar);
console.log("RpcClient: writeByteArray is " + result); console.log("RpcClient: writeByteArray is " + result);
let array = data.readByteArray(); let array = data.readByteArray();
...@@ -1061,17 +1093,17 @@ Writes a ShortArray to this **MessageParcel** object. ...@@ -1061,17 +1093,17 @@ Writes a ShortArray to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| shortArray | number[] | Yes| ShortArray to write.| | shortArray | number[] | Yes| ShortArray to write.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -1088,12 +1120,12 @@ Reads a ShortArray from this **MessageParcel** object. ...@@ -1088,12 +1120,12 @@ Reads a ShortArray from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| dataIn | number[] | Yes| ShortArray to read.| | dataIn | number[] | Yes| ShortArray to read.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -1112,12 +1144,12 @@ Reads the ShortArray from this **MessageParcel** object. ...@@ -1112,12 +1144,12 @@ Reads the ShortArray from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number[] | ShortArray read.| | number[] | ShortArray read.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -1136,17 +1168,17 @@ Writes an IntArray to this **MessageParcel** object. ...@@ -1136,17 +1168,17 @@ Writes an IntArray to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| intArray | number[] | Yes| IntArray to write.| | intArray | number[] | Yes| IntArray to write.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -1163,12 +1195,12 @@ Reads an IntArray from this **MessageParcel** object. ...@@ -1163,12 +1195,12 @@ Reads an IntArray from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| dataIn | number[] | Yes| IntArray to read.| | dataIn | number[] | Yes| IntArray to read.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -1187,12 +1219,12 @@ Reads the IntArray from this **MessageParcel** object. ...@@ -1187,12 +1219,12 @@ Reads the IntArray from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number[] | IntArray read.| | number[] | IntArray read.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -1211,17 +1243,17 @@ Writes a LongArray to this **MessageParcel** object. ...@@ -1211,17 +1243,17 @@ Writes a LongArray to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| longArray | number[] | Yes| LongArray to write.| | longArray | number[] | Yes| LongArray to write.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -1238,12 +1270,12 @@ Reads a LongArray from this **MessageParcel** object. ...@@ -1238,12 +1270,12 @@ Reads a LongArray from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| dataIn | number[] | Yes| LongArray to read.| | dataIn | number[] | Yes| LongArray to read.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -1262,12 +1294,12 @@ Reads the LongArray from this **MessageParcel** object. ...@@ -1262,12 +1294,12 @@ Reads the LongArray from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number[] | LongArray read.| | number[] | LongArray read.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -1286,17 +1318,17 @@ Writes a FloatArray to this **MessageParcel** object. ...@@ -1286,17 +1318,17 @@ Writes a FloatArray to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| floatArray | number[] | Yes| FloatArray to write.| | floatArray | number[] | Yes| FloatArray to write.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -1313,13 +1345,13 @@ Reads a FloatArray from this **MessageParcel** object. ...@@ -1313,13 +1345,13 @@ Reads a FloatArray from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| dataIn | number[] | Yes| FloatArray to read.| | dataIn | number[] | Yes| FloatArray to read.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -1338,12 +1370,12 @@ Reads the FloatArray from this **MessageParcel** object. ...@@ -1338,12 +1370,12 @@ Reads the FloatArray from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number[] | FloatArray read.| | number[] | FloatArray read.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -1362,17 +1394,17 @@ Writes a DoubleArray to this **MessageParcel** object. ...@@ -1362,17 +1394,17 @@ Writes a DoubleArray to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| doubleArray | number[] | Yes| DoubleArray to write.| | doubleArray | number[] | Yes| DoubleArray to write.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -1389,12 +1421,12 @@ Reads a DoubleArray from this **MessageParcel** object. ...@@ -1389,12 +1421,12 @@ Reads a DoubleArray from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| dataIn | number[] | Yes| DoubleArray to read.| | dataIn | number[] | Yes| DoubleArray to read.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -1413,12 +1445,12 @@ Reads the DoubleArray from this **MessageParcel** object. ...@@ -1413,12 +1445,12 @@ Reads the DoubleArray from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number[] | DoubleArray read.| | number[] | DoubleArray read.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -1437,17 +1469,17 @@ Writes a BooleanArray to this **MessageParcel** object. ...@@ -1437,17 +1469,17 @@ Writes a BooleanArray to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| booleanArray | boolean[] | Yes| BooleanArray to write.| | booleanArray | boolean[] | Yes| BooleanArray to write.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -1464,12 +1496,12 @@ Reads a BooleanArray from this **MessageParcel** object. ...@@ -1464,12 +1496,12 @@ Reads a BooleanArray from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| dataIn | boolean[] | Yes| BooleanArray to read.| | dataIn | boolean[] | Yes| BooleanArray to read.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -1488,7 +1520,7 @@ Reads the BooleanArray from this **MessageParcel** object. ...@@ -1488,7 +1520,7 @@ Reads the BooleanArray from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean[] | BooleanArray read.| | boolean[] | BooleanArray read.|
...@@ -1511,21 +1543,21 @@ Writes a CharArray to this **MessageParcel** object. ...@@ -1511,21 +1543,21 @@ Writes a CharArray to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| charArray | number[] | Yes| CharArray to write.| | charArray | number[] | Yes| CharArray to write.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
let result = data.writeCharArray(['a', 'b', 'c']); let result = data.writeCharArray([97, 98, 88]);
console.log("RpcClient: writeCharArray is " + result); console.log("RpcClient: writeCharArray is " + result);
``` ```
...@@ -1538,16 +1570,16 @@ Reads a CharArray from this **MessageParcel** object. ...@@ -1538,16 +1570,16 @@ Reads a CharArray from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| dataIn | number[] | Yes| CharArray to read.| | dataIn | number[] | Yes| CharArray to read.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
let result = data.writeCharArray(['a', 'b', 'c']); let result = data.writeCharArray([97, 98, 99]);
console.log("RpcClient: writeCharArray is " + result); console.log("RpcClient: writeCharArray is " + result);
let array = new Array(3); let array = new Array(3);
data.readCharArray(array); data.readCharArray(array);
...@@ -1562,16 +1594,16 @@ Reads the CharArray from this **MessageParcel** object. ...@@ -1562,16 +1594,16 @@ Reads the CharArray from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number[] | CharArray read.| | number[] | CharArray read.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
let result = data.writeCharArray(['a', 'b', 'c']); let result = data.writeCharArray([97, 98, 99]);
console.log("RpcClient: writeCharArray is " + result); console.log("RpcClient: writeCharArray is " + result);
let array = data.readCharArray(); let array = data.readCharArray();
console.log("RpcClient: readCharArray is " + array); console.log("RpcClient: readCharArray is " + array);
...@@ -1586,17 +1618,17 @@ Writes a StringArray to this **MessageParcel** object. ...@@ -1586,17 +1618,17 @@ Writes a StringArray to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| stringArray | string[] | Yes| StringArray to write.| | stringArray | string[] | Yes| StringArray to write.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -1613,12 +1645,12 @@ Reads a StringArray from this **MessageParcel** object. ...@@ -1613,12 +1645,12 @@ Reads a StringArray from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| dataIn | string[] | Yes| StringArray to read.| | dataIn | string[] | Yes| StringArray to read.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -1637,12 +1669,12 @@ Reads the StringArray from this **MessageParcel** object. ...@@ -1637,12 +1669,12 @@ Reads the StringArray from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| string[] | StringArray read.| | string[] | StringArray read.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -1661,13 +1693,27 @@ Writes information to this **MessageParcel** object indicating that no exception ...@@ -1661,13 +1693,27 @@ Writes information to this **MessageParcel** object indicating that no exception
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Example **Example**
``` ```
class MyDeathRecipient {
onRemoteDied() {
console.log("server died");
}
}
class TestRemoteObject extends rpc.RemoteObject { class TestRemoteObject extends rpc.RemoteObject {
constructor(descriptor) { constructor(descriptor) {
super(descriptor); super(descriptor);
} }
addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
return true;
}
removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
return true;
}
isObjectDead(): boolean {
return false;
}
onRemoteRequest(code, data, reply, option) { onRemoteRequest(code, data, reply, option) {
if (code === 1) { if (code === 1) {
console.log("RpcServer: onRemoteRequest called"); console.log("RpcServer: onRemoteRequest called");
...@@ -1690,7 +1736,7 @@ Reads the exception information from this **MessageParcel** object. ...@@ -1690,7 +1736,7 @@ Reads the exception information from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Example **Example**
``` ```
import FA from "@ohos.ability.featureAbility"; import FA from "@ohos.ability.featureAbility";
...@@ -1745,23 +1791,25 @@ Writes a SequenceableArray to this **MessageParcel** object. ...@@ -1745,23 +1791,25 @@ Writes a SequenceableArray to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| sequenceableArray | Sequenceable[] | Yes| SequenceableArray to write.| | sequenceableArray | Sequenceable[] | Yes| SequenceableArray to write.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
class MySequenceable { class MySequenceable {
constructor(num, string) { num: number;
str: string;
constructor(num, str) {
this.num = num; this.num = num;
this.str = string; this.str = str;
} }
marshalling(messageParcel) { marshalling(messageParcel) {
messageParcel.writeInt(this.num); messageParcel.writeInt(this.num);
...@@ -1792,18 +1840,20 @@ Reads a SequenceableArray from this **MessageParcel** object. ...@@ -1792,18 +1840,20 @@ Reads a SequenceableArray from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| sequenceableArray | Sequenceable[] | Yes| SequenceableArray to read.| | sequenceableArray | Sequenceable[] | Yes| SequenceableArray to read.|
- Example **Example**
``` ```
class MySequenceable { class MySequenceable {
constructor(num, string) { num: number;
str: string;
constructor(num, str) {
this.num = num; this.num = num;
this.str = string; this.str = str;
} }
marshalling(messageParcel) { marshalling(messageParcel) {
messageParcel.writeInt(this.num); messageParcel.writeInt(this.num);
...@@ -1836,24 +1886,41 @@ Writes an array of **IRemoteObject** objects to this **MessageParcel** object. ...@@ -1836,24 +1886,41 @@ Writes an array of **IRemoteObject** objects to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| objectArray | IRemoteObject[] | Yes| Array of **IRemoteObject** objects to write.| | objectArray | IRemoteObject[] | Yes| Array of **IRemoteObject** objects to write.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** if the operation fails or if the **IRemoteObject** array is null.| | boolean | Returns **true** if the operation is successful; returns **false** if the operation fails or if the **IRemoteObject** array is null.|
- Example **Example**
``` ```
class MyDeathRecipient {
onRemoteDied() {
console.log("server died");
}
}
class TestRemoteObject extends rpc.RemoteObject { class TestRemoteObject extends rpc.RemoteObject {
constructor(descriptor) { constructor(descriptor) {
super(descriptor); super(descriptor);
this.attachLocalInterface(this, descriptor); this.attachLocalInterface(this, descriptor);
} }
addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
return true;
}
removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
return true;
}
isObjectDead(): boolean {
return false;
}
asObject(): rpc.IRemoteObject {
return this;
}
} }
let a = [new TestRemoteObject("testObject1"), new TestRemoteObject("testObject2"), new TestRemoteObject("testObject3")]; let a = [new TestRemoteObject("testObject1"), new TestRemoteObject("testObject2"), new TestRemoteObject("testObject3")];
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -1870,19 +1937,36 @@ Reads an **IRemoteObject** array from this **MessageParcel** object. ...@@ -1870,19 +1937,36 @@ Reads an **IRemoteObject** array from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| objects | IRemoteObject[] | Yes| **IRemoteObject** array to read.| | objects | IRemoteObject[] | Yes| **IRemoteObject** array to read.|
- Example **Example**
``` ```
class MyDeathRecipient {
onRemoteDied() {
console.log("server died");
}
}
class TestRemoteObject extends rpc.RemoteObject { class TestRemoteObject extends rpc.RemoteObject {
constructor(descriptor) { constructor(descriptor) {
super(descriptor); super(descriptor);
this.attachLocalInterface(this, descriptor); this.attachLocalInterface(this, descriptor);
} }
addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
return true;
}
removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
return true;
}
isObjectDead(): boolean {
return false;
}
asObject(): rpc.IRemoteObject {
return this;
}
} }
let a = [new TestRemoteObject("testObject1"), new TestRemoteObject("testObject2"), new TestRemoteObject("testObject3")]; let a = [new TestRemoteObject("testObject1"), new TestRemoteObject("testObject2"), new TestRemoteObject("testObject3")];
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -1900,19 +1984,36 @@ Reads the **IRemoteObject** array from this **MessageParcel** object. ...@@ -1900,19 +1984,36 @@ Reads the **IRemoteObject** array from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| IRemoteObject[] | **IRemoteObject** object array obtained.| | IRemoteObject[] | **IRemoteObject** object array obtained.|
- Example **Example**
``` ```
class MyDeathRecipient {
onRemoteDied() {
console.log("server died");
}
}
class TestRemoteObject extends rpc.RemoteObject { class TestRemoteObject extends rpc.RemoteObject {
constructor(descriptor) { constructor(descriptor) {
super(descriptor); super(descriptor);
this.attachLocalInterface(this, descriptor); this.attachLocalInterface(this, descriptor);
} }
addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
return true;
}
removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
return true;
}
isObjectDead(): boolean {
return false;
}
asObject(): rpc.IRemoteObject {
return this;
}
} }
let a = [new TestRemoteObject("testObject1"), new TestRemoteObject("testObject2"), new TestRemoteObject("testObject3")]; let a = [new TestRemoteObject("testObject1"), new TestRemoteObject("testObject2"), new TestRemoteObject("testObject3")];
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -1931,12 +2032,12 @@ Closes a file descriptor. ...@@ -1931,12 +2032,12 @@ Closes a file descriptor.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| fd | number | Yes| File descriptor to close.| | fd | number | Yes| File descriptor to close.|
- Example **Example**
``` ```
import fileio from '@ohos.fileio'; import fileio from '@ohos.fileio';
...@@ -1954,17 +2055,17 @@ Duplicates a file descriptor. ...@@ -1954,17 +2055,17 @@ Duplicates a file descriptor.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| fd | number | Yes| File descriptor to duplicate.| | fd | number | Yes| File descriptor to duplicate.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number | New file descriptor.| | number | New file descriptor.|
- Example **Example**
``` ```
import fileio from '@ohos.fileio'; import fileio from '@ohos.fileio';
...@@ -1982,12 +2083,12 @@ Checks whether this **MessageParcel** object contains a file descriptor. ...@@ -1982,12 +2083,12 @@ Checks whether this **MessageParcel** object contains a file descriptor.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the **MessageParcel** object contains a file descriptor; returns **false** otherwise.| | boolean | Returns **true** if the **MessageParcel** object contains a file descriptor; returns **false** otherwise.|
- Example **Example**
``` ```
import fileio from '@ohos.fileio'; import fileio from '@ohos.fileio';
...@@ -2010,17 +2111,17 @@ Writes a file descriptor to this **MessageParcel** object. ...@@ -2010,17 +2111,17 @@ Writes a file descriptor to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| fd | number | Yes| File descriptor to write.| | fd | number | Yes| File descriptor to write.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
import fileio from '@ohos.fileio'; import fileio from '@ohos.fileio';
...@@ -2040,12 +2141,12 @@ Reads the file descriptor from this **MessageParcel** object. ...@@ -2040,12 +2141,12 @@ Reads the file descriptor from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number | File descriptor read.| | number | File descriptor read.|
- Example **Example**
``` ```
import fileio from '@ohos.fileio'; import fileio from '@ohos.fileio';
...@@ -2066,17 +2167,17 @@ Writes an anonymous shared object to this **MessageParcel** object. ...@@ -2066,17 +2167,17 @@ Writes an anonymous shared object to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| ashmem | Ashmem | Yes| Anonymous shared object to write.| | ashmem | Ashmem | Yes| Anonymous shared object to write.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
let parcel = new rpc.MessageParcel(); let parcel = new rpc.MessageParcel();
...@@ -2094,12 +2195,12 @@ Reads the anonymous shared object from this **MessageParcel** object. ...@@ -2094,12 +2195,12 @@ Reads the anonymous shared object from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Ashmem | Anonymous share object obtained.| | Ashmem | Anonymous share object obtained.|
- Example **Example**
``` ```
let parcel = new rpc.MessageParcel(); let parcel = new rpc.MessageParcel();
...@@ -2119,12 +2220,12 @@ Obtains the maximum amount of raw data that can be held by this **MessageParcel* ...@@ -2119,12 +2220,12 @@ Obtains the maximum amount of raw data that can be held by this **MessageParcel*
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number | 128 MB, which is the maximum amount of raw data that can be held by this **MessageParcel** object.| | number | 128 MB, which is the maximum amount of raw data that can be held by this **MessageParcel** object.|
- Example **Example**
``` ```
let parcel = new rpc.MessageParcel(); let parcel = new rpc.MessageParcel();
...@@ -2141,22 +2242,22 @@ Writes raw data to this **MessageParcel** object. ...@@ -2141,22 +2242,22 @@ Writes raw data to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| rawData | number[] | Yes| Raw data to write.| | rawData | number[] | Yes| Raw data to write.|
| size | number | Yes| Size of the raw data, in bytes.| | size | number | Yes| Size of the raw data, in bytes.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
let parcel = new rpc.MessageParcel(); let parcel = new rpc.MessageParcel();
let arr = new Int8Array([1, 2, 3, 4, 5]); let arr = [1, 2, 3, 4, 5];
let isWriteSuccess = parcel.writeRawData(arr, arr.length); let isWriteSuccess = parcel.writeRawData(arr, arr.length);
console.log("RpcTest: parcel write raw data result is : " + isWriteSuccess); console.log("RpcTest: parcel write raw data result is : " + isWriteSuccess);
``` ```
...@@ -2170,21 +2271,21 @@ Reads raw data from this **MessageParcel** object. ...@@ -2170,21 +2271,21 @@ Reads raw data from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| size | number | Yes| Size of the raw data to read.| | size | number | Yes| Size of the raw data to read.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number[] | Raw data obtained, in bytes.| | number[] | Raw data obtained, in bytes.|
- Example **Example**
``` ```
let parcel = new rpc.MessageParcel(); let parcel = new rpc.MessageParcel();
let arr = new Int8Array([1, 2, 3, 4, 5]); let arr = [1, 2, 3, 4, 5];
let isWriteSuccess = parcel.writeRawData(arr, arr.length); let isWriteSuccess = parcel.writeRawData(arr, arr.length);
console.log("RpcTest: parcel write raw data result is : " + isWriteSuccess); console.log("RpcTest: parcel write raw data result is : " + isWriteSuccess);
let result = parcel.readRawData(5); let result = parcel.readRawData(5);
...@@ -2204,23 +2305,25 @@ Marshals the sequenceable object into a **MessageParcel** object. ...@@ -2204,23 +2305,25 @@ Marshals the sequenceable object into a **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| dataOut | [MessageParcel](#messageparcel) | Yes| **MessageParcel** object to which the sequenceable object is to be marshaled.| | dataOut | [MessageParcel](#messageparcel) | Yes| **MessageParcel** object to which the sequenceable object is to be marshaled.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
class MySequenceable { class MySequenceable {
constructor(num, string) { num: number;
str: string;
constructor(num, str) {
this.num = num; this.num = num;
this.str = string; this.str = str;
} }
marshalling(messageParcel) { marshalling(messageParcel) {
messageParcel.writeInt(this.num); messageParcel.writeInt(this.num);
...@@ -2251,23 +2354,25 @@ Unmarshals this sequenceable object from a **MessageParcel** object. ...@@ -2251,23 +2354,25 @@ Unmarshals this sequenceable object from a **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| dataIn | [MessageParcel](#messageparcel) | Yes| **MessageParcel** object in which the sequenceable object is to be unmarshaled.| | dataIn | [MessageParcel](#messageparcel) | Yes| **MessageParcel** object in which the sequenceable object is to be unmarshaled.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
class MySequenceable { class MySequenceable {
constructor(num, string) { num: number;
str: string;
constructor(num, str) {
this.num = num; this.num = num;
this.str = string; this.str = str;
} }
marshalling(messageParcel) { marshalling(messageParcel) {
messageParcel.writeInt(this.num); messageParcel.writeInt(this.num);
...@@ -2303,12 +2408,12 @@ Obtains a proxy or remote object. This method must be implemented by its derived ...@@ -2303,12 +2408,12 @@ Obtains a proxy or remote object. This method must be implemented by its derived
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| [IRemoteObject](#iremoteobject) | Returns the [RemoteObject](#ashmem8) if it is the caller; returns the [IRemoteObject](#iremoteobject), the holder of this **RemoteProxy** object, if the caller is a [RemoteProxy](#remoteproxy) object.| | [IRemoteObject](#iremoteobject) | Returns the [RemoteObject](#ashmem8) if it is the caller; returns the [IRemoteObject](#iremoteobject), the holder of this **RemoteProxy** object, if the caller is a [RemoteProxy](#remoteproxy) object.|
- Example **Example**
``` ```
class TestAbility extends rpc.RemoteObject { class TestAbility extends rpc.RemoteObject {
...@@ -2318,10 +2423,11 @@ Obtains a proxy or remote object. This method must be implemented by its derived ...@@ -2318,10 +2423,11 @@ Obtains a proxy or remote object. This method must be implemented by its derived
} }
``` ```
- Example **Example**
``` ```
class TestProxy { class TestProxy {
remote: rpc.RemoteObject;
constructor(remote) { constructor(remote) {
this.remote = remote; this.remote = remote;
} }
...@@ -2345,12 +2451,12 @@ Called to perform subsequent operations when a death notification of the remote ...@@ -2345,12 +2451,12 @@ Called to perform subsequent operations when a death notification of the remote
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Example **Example**
``` ```
class MyDeathRecipient { class MyDeathRecipient {
onRemoteDied() { onRemoteDied() {
console.log("server is died"); console.log("server died");
} }
} }
``` ```
...@@ -2383,28 +2489,29 @@ Obtains the interface. ...@@ -2383,28 +2489,29 @@ Obtains the interface.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| descriptor | string | Yes| Interface descriptor.| | descriptor | string | Yes| Interface descriptor.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| IRemoteBroker | **IRemoteBroker** object bound to the specified interface descriptor.| | IRemoteBroker | **IRemoteBroker** object bound to the specified interface descriptor.|
### sendRequest ### sendRequest<sup>(deprecated)</sup>
sendRequest(code : number, data : MessageParcel, reply : MessageParcel, options : MessageOption): boolean;<sup>7</sup> > **NOTE**<br/>
> This API is deprecated since API Version 8. You are advised to use [sendRequest<sup>8+</sup> ](#sendrequest8).
sendRequest(code : number, data : MessageParcel, reply : MessageParcel, options : MessageOption): Promise&lt;SendRequestResult&gt;<sup>8+</sup> 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 **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.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | 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.| | 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.|
...@@ -2412,21 +2519,42 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch ...@@ -2412,21 +2519,42 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch
| reply | [MessageParcel](#messageparcel) | Yes| **MessageParcel** object that receives the response.| | reply | [MessageParcel](#messageparcel) | Yes| **MessageParcel** object that receives the response.|
| options | [MessageOption](#messageoption) | Yes| Request sending mode, which can be synchronous (default) or asynchronous.| | options | [MessageOption](#messageoption) | Yes| Request sending mode, which can be synchronous (default) or asynchronous.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;number&gt;<sup>7</sup><br>Promise&lt;SendRequestResult&gt;<sup>8+</sup> | Promise used to return the result. The value **0** will be returned if the request is sent successfully. Otherwise, an error code will be returned.<sup>7</sup><br>Promise used to return the **sendRequestResult** object.<sup>8+</sup> | | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
### sendRequest<sup>8+</sup> ### sendRequest<sup>8+</sup>
sendRequest(code : number, data : MessageParcel, reply : MessageParcel, options : MessageOption): Promise&lt;SendRequestResult&gt;
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.
**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](#messageparcel) | Yes| **MessageParcel** object holding the data to send.|
| reply | [MessageParcel](#messageparcel) | 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&lt;SendRequestResult&gt; | Promise used to return the **sendRequestResult** object.|
### sendRequest<sup>8+</sup>
sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption, callback: AsyncCallback&lt;SendRequestResult&gt;): void sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption, callback: AsyncCallback&lt;SendRequestResult&gt;): 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 **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.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | 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.| | 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.|
...@@ -2444,13 +2572,13 @@ Adds a callback for receiving death notifications of the remote object. This met ...@@ -2444,13 +2572,13 @@ Adds a callback for receiving death notifications of the remote object. This met
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| recipient | [DeathRecipient](#deathrecipient) | Yes| Callback to add.| | recipient | [DeathRecipient](#deathrecipient) | Yes| Callback to add.|
| flags | number | Yes| Flag of the death notification.| | flags | number | Yes| Flag of the death notification.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the callback is added successfully; returns **false** otherwise.| | boolean | Returns **true** if the callback is added successfully; returns **false** otherwise.|
...@@ -2464,13 +2592,13 @@ Removes the callback used to receive death notifications of the remote object. ...@@ -2464,13 +2592,13 @@ Removes the callback used to receive death notifications of the remote object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| recipient | [DeathRecipient](#deathrecipient) | Yes| Callback to remove.| | recipient | [DeathRecipient](#deathrecipient) | Yes| Callback to remove.|
| flags | number | Yes| Flag of the death notification.| | flags | number | Yes| Flag of the death notification.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the callback is removed successfully; returns **false** otherwise.| | boolean | Returns **true** if the callback is removed successfully; returns **false** otherwise.|
...@@ -2484,7 +2612,7 @@ Obtains the interface descriptor of this object. The interface descriptor is a s ...@@ -2484,7 +2612,7 @@ Obtains the interface descriptor of this object. The interface descriptor is a s
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| string | Interface descriptor obtained.| | string | Interface descriptor obtained.|
...@@ -2498,7 +2626,7 @@ Checks whether this object is dead. ...@@ -2498,7 +2626,7 @@ Checks whether this object is dead.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the object is dead; returns **false** otherwise.| | boolean | Returns **true** if the object is dead; returns **false** otherwise.|
...@@ -2521,18 +2649,18 @@ Provides methods to implement **IRemoteObject**. ...@@ -2521,18 +2649,18 @@ Provides methods to implement **IRemoteObject**.
### sendRequest ### sendRequest<sup>(deprecated)</sup>
sendRequest(code : number, data : MessageParcel, reply : MessageParcel, options : MessageOption): boolean;<sup>7</sup> > **NOTE**<br/>
> This API is deprecated since API Version 8. You are advised to use [sendRequest<sup>8+</sup> ](#sendrequest8-2).
sendRequest(code : number, data : MessageParcel, reply : MessageParcel, options : MessageOption): Promise&lt;SendRequestResult&gt;<sup>8+</sup> 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 **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.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
**Parameters**
- Parameters
| Name| Type| Mandatory| Description| | 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.| | 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.|
...@@ -2540,12 +2668,13 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch ...@@ -2540,12 +2668,13 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch
| reply | [MessageParcel](#messageparcel) | Yes| **MessageParcel** object that receives the response.| | reply | [MessageParcel](#messageparcel) | Yes| **MessageParcel** object that receives the response.|
| options | [MessageOption](#messageoption) | Yes| Request sending mode, which can be synchronous (default) or asynchronous.| | options | [MessageOption](#messageoption) | Yes| Request sending mode, which can be synchronous (default) or asynchronous.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;number&gt;<sup>7</sup><br>Promise&lt;SendRequestResult&gt;<sup>8+</sup> | Promise used to return the result. The value **0** will be returned if the request is sent successfully. Otherwise, an error code will be returned.<sup>7</sup><br>Promise used to return the **sendRequestResult** object.<sup>8+</sup> | | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example:<sup>7</sup>
**Example**
``` ```
import FA from "@ohos.ability.featureAbility"; import FA from "@ohos.ability.featureAbility";
...@@ -2572,25 +2701,41 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch ...@@ -2572,25 +2701,41 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch
let reply = rpc.MessageParcel.create(); let reply = rpc.MessageParcel.create();
data.writeInt(1); data.writeInt(1);
data.writeString("hello"); data.writeString("hello");
proxy.sendRequest(1, data, reply, option) let ret: boolean = proxy.sendRequest(1, data, reply, option);
.then(function(errCode) { if (ret) {
if (errCode === 0) {
console.log("sendRequest got result"); console.log("sendRequest got result");
let msg = reply.readString(); let msg = reply.readString();
console.log("RPCTest: reply msg: " + msg); console.log("RPCTest: reply msg: " + msg);
} else { } else {
console.log("RPCTest: sendRequest failed, errCode: " + errCode); console.log("RPCTest: sendRequest failed");
} }
}).catch(function(e) {
console.log("RPCTest: sendRequest got exception: " + e.message);
}).finally (() => {
console.log("RPCTest: sendRequest ends, reclaim parcel"); console.log("RPCTest: sendRequest ends, reclaim parcel");
data.reclaim(); data.reclaim();
reply.reclaim(); reply.reclaim();
});
``` ```
- Example:<sup>8+</sup> ### sendRequest<sup>8+</sup>
sendRequest(code : number, data : MessageParcel, reply : MessageParcel, options : MessageOption): Promise&lt;SendRequestResult&gt;
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.
**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](#messageparcel) | Yes| **MessageParcel** object holding the data to send.|
| reply | [MessageParcel](#messageparcel) | 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&lt;SendRequestResult&gt; | Promise used to return the **sendRequestResult** object.|
**Example**
``` ```
import FA from "@ohos.ability.featureAbility"; import FA from "@ohos.ability.featureAbility";
...@@ -2645,7 +2790,7 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch ...@@ -2645,7 +2790,7 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | 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.| | 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.|
...@@ -2654,7 +2799,7 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch ...@@ -2654,7 +2799,7 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch
| options | [MessageOption](#messageoption) | Yes| Request sending mode, which can be synchronous (default) or asynchronous.| | options | [MessageOption](#messageoption) | Yes| Request sending mode, which can be synchronous (default) or asynchronous.|
| callback | AsyncCallback&lt;SendRequestResult&gt; | Yes| Callback for receiving the sending result.| | callback | AsyncCallback&lt;SendRequestResult&gt; | Yes| Callback for receiving the sending result.|
- Example **Example**
``` ```
import FA from "@ohos.ability.featureAbility"; import FA from "@ohos.ability.featureAbility";
...@@ -2706,17 +2851,17 @@ Obtains the **LocalInterface** object of an interface descriptor. ...@@ -2706,17 +2851,17 @@ Obtains the **LocalInterface** object of an interface descriptor.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| interface | string | Yes| Interface descriptor.| | interface | string | Yes| Interface descriptor.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| IRemoteBroker | Returns **Null** by default, which indicates a proxy interface.| | IRemoteBroker | Returns **Null** by default, which indicates a proxy interface.|
- Example **Example**
``` ```
import FA from "@ohos.ability.featureAbility"; import FA from "@ohos.ability.featureAbility";
...@@ -2751,18 +2896,18 @@ Adds a callback for receiving the death notifications of the remote object, incl ...@@ -2751,18 +2896,18 @@ Adds a callback for receiving the death notifications of the remote object, incl
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| recipient | [DeathRecipient](#deathrecipient) | Yes| Callback to add.| | recipient | [DeathRecipient](#deathrecipient) | Yes| Callback to add.|
| flags | number | Yes| Flag of the death notification. This parameter is reserved. It is set to **0**.| | flags | number | Yes| Flag of the death notification. This parameter is reserved. It is set to **0**.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the callback is added successfully; returns **false** otherwise.| | boolean | Returns **true** if the callback is added successfully; returns **false** otherwise.|
- Example **Example**
``` ```
import FA from "@ohos.ability.featureAbility"; import FA from "@ohos.ability.featureAbility";
...@@ -2786,7 +2931,7 @@ Adds a callback for receiving the death notifications of the remote object, incl ...@@ -2786,7 +2931,7 @@ Adds a callback for receiving the death notifications of the remote object, incl
FA.connectAbility(want, connect); FA.connectAbility(want, connect);
class MyDeathRecipient { class MyDeathRecipient {
onRemoteDied() { onRemoteDied() {
console.log("server is died"); console.log("server died");
} }
} }
let deathRecipient = new MyDeathRecipient(); let deathRecipient = new MyDeathRecipient();
...@@ -2802,18 +2947,18 @@ Removes the callback used to receive death notifications of the remote object. ...@@ -2802,18 +2947,18 @@ Removes the callback used to receive death notifications of the remote object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| recipient | [DeathRecipient](#deathrecipient) | Yes| Callback to remove.| | recipient | [DeathRecipient](#deathrecipient) | Yes| Callback to remove.|
| flags | number | Yes| Flag of the death notification. This parameter is reserved. It is set to **0**.| | flags | number | Yes| Flag of the death notification. This parameter is reserved. It is set to **0**.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the callback is removed successfully; returns **false** otherwise.| | boolean | Returns **true** if the callback is removed successfully; returns **false** otherwise.|
- Example **Example**
``` ```
import FA from "@ohos.ability.featureAbility"; import FA from "@ohos.ability.featureAbility";
...@@ -2837,7 +2982,7 @@ Removes the callback used to receive death notifications of the remote object. ...@@ -2837,7 +2982,7 @@ Removes the callback used to receive death notifications of the remote object.
FA.connectAbility(want, connect); FA.connectAbility(want, connect);
class MyDeathRecipient { class MyDeathRecipient {
onRemoteDied() { onRemoteDied() {
console.log("server is died"); console.log("server died");
} }
} }
let deathRecipient = new MyDeathRecipient(); let deathRecipient = new MyDeathRecipient();
...@@ -2854,12 +2999,12 @@ Obtains the interface descriptor of this proxy object. ...@@ -2854,12 +2999,12 @@ Obtains the interface descriptor of this proxy object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| string | Interface descriptor obtained.| | string | Interface descriptor obtained.|
- Example **Example**
``` ```
import FA from "@ohos.ability.featureAbility"; import FA from "@ohos.ability.featureAbility";
...@@ -2894,12 +3039,12 @@ Checks whether the **RemoteObject** is dead. ...@@ -2894,12 +3039,12 @@ Checks whether the **RemoteObject** is dead.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the **RemoteObject** is dead; returns **false** otherwise.| | boolean | Returns **true** if the **RemoteObject** is dead; returns **false** otherwise.|
- Example **Example**
``` ```
import FA from "@ohos.ability.featureAbility"; import FA from "@ohos.ability.featureAbility";
...@@ -2948,7 +3093,7 @@ A constructor used to create a **MessageOption** object. ...@@ -2948,7 +3093,7 @@ A constructor used to create a **MessageOption** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| syncFlags | number | No| Call flag, which can be synchronous or asynchronous. The default value is **synchronous**.| | syncFlags | number | No| Call flag, which can be synchronous or asynchronous. The default value is **synchronous**.|
...@@ -2963,7 +3108,7 @@ Obtains the call flag, which can be synchronous or asynchronous. ...@@ -2963,7 +3108,7 @@ Obtains the call flag, which can be synchronous or asynchronous.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number | Call mode obtained.| | number | Call mode obtained.|
...@@ -2977,7 +3122,7 @@ Sets the call flag, which can be synchronous or asynchronous. ...@@ -2977,7 +3122,7 @@ Sets the call flag, which can be synchronous or asynchronous.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| flags | number | Yes| Call flag to set.| | flags | number | Yes| Call flag to set.|
...@@ -2991,7 +3136,7 @@ Obtains the maximum wait time for this RPC call. ...@@ -2991,7 +3136,7 @@ Obtains the maximum wait time for this RPC call.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number | Maximum wait time obtained.| | number | Maximum wait time obtained.|
...@@ -3005,7 +3150,7 @@ Sets the maximum wait time for this RPC call. ...@@ -3005,7 +3150,7 @@ Sets the maximum wait time for this RPC call.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| waitTime | number | Yes| Maximum wait time to set.| | waitTime | number | Yes| Maximum wait time to set.|
...@@ -3024,12 +3169,12 @@ Obtains the system capability manager. ...@@ -3024,12 +3169,12 @@ Obtains the system capability manager.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| [IRemoteObject](#iremoteobject) | System capability manager obtained.| | [IRemoteObject](#iremoteobject) | System capability manager obtained.|
- Example **Example**
``` ```
let samgr = rpc.IPCSkeleton.getContextObject(); let samgr = rpc.IPCSkeleton.getContextObject();
...@@ -3045,12 +3190,12 @@ Obtains the PID of the caller. This method is invoked by the **RemoteObject** ob ...@@ -3045,12 +3190,12 @@ Obtains the PID of the caller. This method is invoked by the **RemoteObject** ob
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number | PID of the caller.| | number | PID of the caller.|
- Example **Example**
``` ```
class Stub extends rpc.RemoteObject { class Stub extends rpc.RemoteObject {
...@@ -3071,12 +3216,12 @@ Obtains the UID of the caller. This method is invoked by the **RemoteObject** ob ...@@ -3071,12 +3216,12 @@ Obtains the UID of the caller. This method is invoked by the **RemoteObject** ob
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number | UID of the caller.| | number | UID of the caller.|
- Example **Example**
``` ```
class Stub extends rpc.RemoteObject { class Stub extends rpc.RemoteObject {
...@@ -3088,7 +3233,7 @@ Obtains the UID of the caller. This method is invoked by the **RemoteObject** ob ...@@ -3088,7 +3233,7 @@ Obtains the UID of the caller. This method is invoked by the **RemoteObject** ob
} }
``` ```
### getCallingTokenId ### getCallingTokenId<sup>8+</sup>
static getCallingTokenId(): number; static getCallingTokenId(): number;
...@@ -3096,13 +3241,13 @@ Obtains the caller's token ID, which is used to verify the caller identity. ...@@ -3096,13 +3241,13 @@ Obtains the caller's token ID, which is used to verify the caller identity.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
Return value * Return value
| Type | Description | | Type | Description |
| ------ | --------------------- | | ------ | --------------------- |
| number | Token ID of the caller obtained.| | number | Token ID of the caller obtained.|
Example * Example
``` ```
class Stub extends rpc.RemoteObject { class Stub extends rpc.RemoteObject {
...@@ -3115,7 +3260,7 @@ Example ...@@ -3115,7 +3260,7 @@ Example
``` ```
### getCalligDeviceID ### getCallingDeviceID
static getCallingDeviceID(): string static getCallingDeviceID(): string
...@@ -3123,17 +3268,17 @@ Obtains the ID of the device hosting the caller's process. ...@@ -3123,17 +3268,17 @@ Obtains the ID of the device hosting the caller's process.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| string | Device ID obtained.| | string | Device ID obtained.|
- Example **Example**
``` ```
class Stub extends rpc.RemoteObject { class Stub extends rpc.RemoteObject {
onRemoteRequest(code, data, reply, option) { onRemoteRequest(code, data, reply, option) {
let callerDeviceID = rpc.IPCSkeleton.getCalligDeviceID(); let callerDeviceID = rpc.IPCSkeleton.getCallingDeviceID();
console.log("RpcServer: callerDeviceID is: " + callerDeviceID); console.log("RpcServer: callerDeviceID is: " + callerDeviceID);
return true; return true;
} }
...@@ -3149,12 +3294,12 @@ Obtains the local device ID. ...@@ -3149,12 +3294,12 @@ Obtains the local device ID.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| string | Local device ID obtained.| | string | Local device ID obtained.|
- Example **Example**
``` ```
class Stub extends rpc.RemoteObject { class Stub extends rpc.RemoteObject {
...@@ -3175,12 +3320,12 @@ Checks whether the remote process is a process of the local device. ...@@ -3175,12 +3320,12 @@ Checks whether the remote process is a process of the local device.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the local and remote processes are on the same device; returns **false** otherwise.| | boolean | Returns **true** if the local and remote processes are on the same device; returns **false** otherwise.|
- Example **Example**
``` ```
class Stub extends rpc.RemoteObject { class Stub extends rpc.RemoteObject {
...@@ -3201,21 +3346,40 @@ Flushes all suspended commands from the specified **RemoteProxy** to the corresp ...@@ -3201,21 +3346,40 @@ Flushes all suspended commands from the specified **RemoteProxy** to the corresp
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| object | [IRemoteObject](#iremoteobject) | Yes| **RemoteProxy** specified. | | object | [IRemoteObject](#iremoteobject) | Yes| **RemoteProxy** specified. |
- Return value **Return value**
| Type| Description| | 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.| | 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 **Example**
``` ```
let remoteObject = new rpc.RemoteObject("aaa", 3); class MyDeathRecipient {
onRemoteDied() {
console.log("server died");
}
}
class TestRemoteObject extends rpc.RemoteObject {
constructor(descriptor) {
super(descriptor);
}
addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
return true;
}
removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
return true;
}
isObjectDead(): boolean {
return false;
}
}
let remoteObject = new TestRemoteObject("aaa");
let ret = rpc.IPCSkeleton.flushCommands(remoteObject); let ret = rpc.IPCSkeleton.flushCommands(remoteObject);
console.log("RpcServer: flushCommands result: " + ret); console.log("RpcServer: flushCommands result: " + ret);
``` ```
...@@ -3229,12 +3393,12 @@ Changes the UID and PID of the remote user to the UID and PID of the local user. ...@@ -3229,12 +3393,12 @@ Changes the UID and PID of the remote user to the UID and PID of the local user.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| string | String containing the UID and PID of the remote user.| | string | String containing the UID and PID of the remote user.|
- Example **Example**
``` ```
class Stub extends rpc.RemoteObject { class Stub extends rpc.RemoteObject {
...@@ -3255,17 +3419,17 @@ Restores the UID and PID of the remote user. It is usually called when the UID a ...@@ -3255,17 +3419,17 @@ Restores the UID and PID of the remote user. It is usually called when the UID a
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| identity | string | Yes| String containing the remote user UID and PID, which are returned by **resetCallingIdentity**.| | identity | string | Yes| String containing the remote user UID and PID, which are returned by **resetCallingIdentity**.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
class Stub extends rpc.RemoteObject { class Stub extends rpc.RemoteObject {
...@@ -3297,23 +3461,24 @@ A constructor used to create a **RemoteObject** object. ...@@ -3297,23 +3461,24 @@ A constructor used to create a **RemoteObject** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| descriptor | string | Yes| Interface descriptor.| | descriptor | string | Yes| Interface descriptor.|
### sendRequest ### sendRequest<sup>(deprecated)</sup>
sendRequest(code : number, data : MessageParcel, reply : MessageParcel, options : MessageOption): boolean;<sup>7</sup> > **NOTE**<br/>
> This API is deprecated since API Version 8. You are advised to use [sendRequest<sup>8+</sup> ](#sendrequest8-4).
sendRequest(code : number, data : MessageParcel, reply : MessageParcel, options : MessageOption): Promise&lt;SendRequestResult&gt;<sup>8+</sup> 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 **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.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | 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.| | 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.|
...@@ -3321,19 +3486,33 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch ...@@ -3321,19 +3486,33 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch
| reply | [MessageParcel](#messageparcel) | Yes| **MessageParcel** object that receives the response.| | reply | [MessageParcel](#messageparcel) | Yes| **MessageParcel** object that receives the response.|
| options | [MessageOption](#messageoption) | Yes| Request sending mode, which can be synchronous (default) or asynchronous.| | options | [MessageOption](#messageoption) | Yes| Request sending mode, which can be synchronous (default) or asynchronous.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;number&gt;<sup>7</sup><br>Promise&lt;SendRequestResult&gt;<sup>8+</sup> | Promise used to return the result. The value **0** will be returned if the request is sent successfully. Otherwise, an error code will be returned.<sup>7</sup><br>Promise used to return the **sendRequestResult** object.<sup>8+</sup> | | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example<sup>7</sup> **Example**
``` ```
class MyDeathRecipient {
onRemoteDied() {
console.log("server died");
}
}
class TestRemoteObject extends rpc.RemoteObject { class TestRemoteObject extends rpc.RemoteObject {
constructor(descriptor) { constructor(descriptor) {
super(descriptor); super(descriptor);
} }
addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
return true;
}
removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
return true;
}
isObjectDead(): boolean {
return false;
}
} }
let testRemoteObject = new TestRemoteObject("testObject"); let testRemoteObject = new TestRemoteObject("testObject");
let option = new rpc.MessageOption(); let option = new rpc.MessageOption();
...@@ -3341,32 +3520,63 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch ...@@ -3341,32 +3520,63 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch
let reply = rpc.MessageParcel.create(); let reply = rpc.MessageParcel.create();
data.writeInt(1); data.writeInt(1);
data.writeString("hello"); data.writeString("hello");
testRemoteObject.sendRequest(1, data, reply, option) let ret: boolean = testRemoteObject.sendRequest(1, data, reply, option);
.then(function(errCode) { if (ret) {
if (errCode === 0) {
console.log("sendRequest got result"); console.log("sendRequest got result");
let msg = reply.readString(); let msg = reply.readString();
console.log("RPCTest: reply msg: " + msg); console.log("RPCTest: reply msg: " + msg);
} else { } else {
console.log("RPCTest: sendRequest failed, errCode: " + errCode); console.log("RPCTest: sendRequest failed");
} }
}).catch(function(e) {
console.log("RPCTest: sendRequest got exception: " + e.message);
}).finally (() => {
console.log("RPCTest: sendRequest ends, reclaim parcel"); console.log("RPCTest: sendRequest ends, reclaim parcel");
data.reclaim(); data.reclaim();
reply.reclaim(); reply.reclaim();
});
``` ```
- Example<sup>8+</sup> ### sendRequest<sup>8+</sup>
sendRequest(code : number, data : MessageParcel, reply : MessageParcel, options : MessageOption): Promise&lt;SendRequestResult&gt;
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.
**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](#messageparcel) | Yes| **MessageParcel** object holding the data to send.|
| reply | [MessageParcel](#messageparcel) | 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&lt;SendRequestResult&gt; | Promise used to return the **sendRequestResult** object.|
**Example**
``` ```
class MyDeathRecipient {
onRemoteDied() {
console.log("server died");
}
}
class TestRemoteObject extends rpc.RemoteObject { class TestRemoteObject extends rpc.RemoteObject {
constructor(descriptor) { constructor(descriptor) {
super(descriptor); super(descriptor);
} }
addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
return true;
}
removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
return true;
}
isObjectDead(): boolean {
return false;
}
} }
let testRemoteObject = new TestRemoteObject("testObject"); let testRemoteObject = new TestRemoteObject("testObject");
let option = new rpc.MessageOption(); let option = new rpc.MessageOption();
...@@ -3402,7 +3612,7 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch ...@@ -3402,7 +3612,7 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | 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.| | 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.|
...@@ -3412,13 +3622,27 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch ...@@ -3412,13 +3622,27 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch
| AsyncCallback | AsyncCallback&lt;SendRequestResult&gt; | Yes| Callback for receiving the sending result.| | AsyncCallback | AsyncCallback&lt;SendRequestResult&gt; | Yes| Callback for receiving the sending result.|
- Example **Example**
``` ```
class MyDeathRecipient {
onRemoteDied() {
console.log("server died");
}
}
class TestRemoteObject extends rpc.RemoteObject { class TestRemoteObject extends rpc.RemoteObject {
constructor(descriptor) { constructor(descriptor) {
super(descriptor); super(descriptor);
} }
addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
return true;
}
removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
return true;
}
isObjectDead(): boolean {
return false;
}
} }
function sendRequestCallback(result) { function sendRequestCallback(result) {
if (result.errCode === 0) { if (result.errCode === 0) {
...@@ -3451,7 +3675,7 @@ Provides a response to **sendRequest()**. The server processes the request and r ...@@ -3451,7 +3675,7 @@ Provides a response to **sendRequest()**. The server processes the request and r
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| code | number | Yes| Service request code sent by the remote end.| | code | number | Yes| Service request code sent by the remote end.|
...@@ -3459,19 +3683,33 @@ Provides a response to **sendRequest()**. The server processes the request and r ...@@ -3459,19 +3683,33 @@ Provides a response to **sendRequest()**. The server processes the request and r
| reply | [MessageParcel](#messageparcel) | Yes| **MessageParcel** object carrying the result.| | reply | [MessageParcel](#messageparcel) | Yes| **MessageParcel** object carrying the result.|
| option | [MessageOption](#messageoption) | Yes| Whether the operation is synchronous or asynchronous.| | option | [MessageOption](#messageoption) | Yes| Whether the operation is synchronous or asynchronous.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
class MyDeathRecipient {
onRemoteDied() {
console.log("server died");
}
}
class TestRemoteObject extends rpc.RemoteObject { class TestRemoteObject extends rpc.RemoteObject {
constructor(descriptor) { constructor(descriptor) {
super(descriptor); super(descriptor);
} }
addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
return true;
}
removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
return true;
}
isObjectDead(): boolean {
return false;
}
onRemoteRequest(code, data, reply, option) { onRemoteRequest(code, data, reply, option) {
if (code === 1) { if (code === 1) {
...@@ -3494,19 +3732,33 @@ Obtains the UID of the remote process. ...@@ -3494,19 +3732,33 @@ Obtains the UID of the remote process.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number | UID of the remote process obtained.| | number | UID of the remote process obtained.|
- Example **Example**
``` ```
class MyDeathRecipient {
onRemoteDied() {
console.log("server died");
}
}
class TestRemoteObject extends rpc.RemoteObject { class TestRemoteObject extends rpc.RemoteObject {
constructor(descriptor) { constructor(descriptor) {
super(descriptor); super(descriptor);
} }
addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
return true;
}
removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
return true;
}
isObjectDead(): boolean {
return false;
}
} }
let testRemoteObject = new TestRemoteObject("testObject"); let testRemoteObject = new TestRemoteObject("testObject");
console.log("RpcServer: getCallingUid: " + testRemoteObject.getCallingUid()); console.log("RpcServer: getCallingUid: " + testRemoteObject.getCallingUid());
...@@ -3521,19 +3773,33 @@ Obtains the PID of the remote process. ...@@ -3521,19 +3773,33 @@ Obtains the PID of the remote process.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number | PID of the remote process obtained.| | number | PID of the remote process obtained.|
- Example **Example**
``` ```
class MyDeathRecipient {
onRemoteDied() {
console.log("server died");
}
}
class TestRemoteObject extends rpc.RemoteObject { class TestRemoteObject extends rpc.RemoteObject {
constructor(descriptor) { constructor(descriptor) {
super(descriptor); super(descriptor);
} }
addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
return true;
}
removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
return true;
}
isObjectDead(): boolean {
return false;
}
} }
let testRemoteObject = new TestRemoteObject("testObject"); let testRemoteObject = new TestRemoteObject("testObject");
console.log("RpcServer: getCallingPid: " + testRemoteObject.getCallingPid()); console.log("RpcServer: getCallingPid: " + testRemoteObject.getCallingPid());
...@@ -3548,24 +3814,38 @@ Checks whether the remote object corresponding to the specified interface descri ...@@ -3548,24 +3814,38 @@ Checks whether the remote object corresponding to the specified interface descri
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| descriptor | string | Yes| Interface descriptor.| | descriptor | string | Yes| Interface descriptor.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| IRemoteBroker | Returns the remote object if a match is found; returns **Null** otherwise.| | IRemoteBroker | Returns the remote object if a match is found; returns **Null** otherwise.|
- Example **Example**
``` ```
class MyDeathRecipient {
onRemoteDied() {
console.log("server died");
}
}
class TestRemoteObject extends rpc.RemoteObject { class TestRemoteObject extends rpc.RemoteObject {
constructor(descriptor) { constructor(descriptor) {
super(descriptor); super(descriptor);
} }
addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
return true;
}
removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
return true;
}
isObjectDead(): boolean {
return false;
}
} }
let testRemoteObject = new TestRemoteObject("testObject"); let testRemoteObject = new TestRemoteObject("testObject");
let broker = testRemoteObject.queryLocalInterface("testObject"); let broker = testRemoteObject.queryLocalInterface("testObject");
...@@ -3580,19 +3860,33 @@ Obtains the interface descriptor. ...@@ -3580,19 +3860,33 @@ Obtains the interface descriptor.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| string | Interface descriptor obtained.| | string | Interface descriptor obtained.|
- Example **Example**
``` ```
class MyDeathRecipient {
onRemoteDied() {
console.log("server died");
}
}
class TestRemoteObject extends rpc.RemoteObject { class TestRemoteObject extends rpc.RemoteObject {
constructor(descriptor) { constructor(descriptor) {
super(descriptor); super(descriptor);
} }
addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
return true;
}
removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
return true;
}
isObjectDead(): boolean {
return false;
}
} }
let testRemoteObject = new TestRemoteObject("testObject"); let testRemoteObject = new TestRemoteObject("testObject");
let descriptor = testRemoteObject.getInterfaceDescriptor(); let descriptor = testRemoteObject.getInterfaceDescriptor();
...@@ -3608,21 +3902,38 @@ Binds an interface descriptor to an **IRemoteBroker** object. ...@@ -3608,21 +3902,38 @@ Binds an interface descriptor to an **IRemoteBroker** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| localInterface | IRemoteBroker | Yes| **IRemoteBroker** object.| | localInterface | IRemoteBroker | Yes| **IRemoteBroker** object.|
| descriptor | string | Yes| Interface descriptor.| | descriptor | string | Yes| Interface descriptor.|
- Example **Example**
``` ```
class MyDeathRecipient {
onRemoteDied() {
console.log("server died");
}
}
class TestRemoteObject extends rpc.RemoteObject { class TestRemoteObject extends rpc.RemoteObject {
constructor(descriptor) { constructor(descriptor) {
super(descriptor); super(descriptor);
this.attachLocalInterface(this, descriptor); this.attachLocalInterface(this, descriptor);
} }
addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
return true;
}
removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
return true;
}
isObjectDead(): boolean {
return false;
}
asObject(): rpc.IRemoteObject {
return this;
}
} }
let testRemoteObject = new TestRemoteObject("testObject"); let testRemoteObject = new TestRemoteObject("testObject");
``` ```
...@@ -3652,19 +3963,19 @@ Creates an **Ashmem** object with the specified name and size. ...@@ -3652,19 +3963,19 @@ Creates an **Ashmem** object with the specified name and size.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| name | string | Yes| Name of the **Ashmem** object to create.| | name | string | Yes| Name of the **Ashmem** object to create.|
| size | number | Yes| Size (in bytes) of the **Ashmem** object to create.| | size | number | Yes| Size (in bytes) of the **Ashmem** object to create.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Ashmem | Returns the **Ashmem** object if it is created successfully; returns null otherwise.| | Ashmem | Returns the **Ashmem** object if it is created successfully; returns null otherwise.|
- Example **Example**
``` ```
let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024); let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024);
...@@ -3681,18 +3992,18 @@ Creates an **Ashmem** object by copying the file descriptor (FD) of an existing ...@@ -3681,18 +3992,18 @@ Creates an **Ashmem** object by copying the file descriptor (FD) of an existing
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| ashmem | Ashmem | Yes| Existing **Ashmem** object.| | ashmem | Ashmem | Yes| Existing **Ashmem** object.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Ashmem | **Ashmem** object created.| | Ashmem | **Ashmem** object created.|
- Example **Example**
``` ```
let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024); let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024);
...@@ -3710,7 +4021,7 @@ Closes this **Ashmem** object. ...@@ -3710,7 +4021,7 @@ Closes this **Ashmem** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Example **Example**
``` ```
let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024); let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024);
...@@ -3726,7 +4037,7 @@ Deletes the mappings for the specified address range of this **Ashmem** object. ...@@ -3726,7 +4037,7 @@ Deletes the mappings for the specified address range of this **Ashmem** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Example **Example**
``` ```
let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024); let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024);
...@@ -3742,12 +4053,12 @@ Obtains the memory size of this **Ashmem** object. ...@@ -3742,12 +4053,12 @@ Obtains the memory size of this **Ashmem** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number | **Ashmem** size obtained.| | number | **Ashmem** size obtained.|
- Example **Example**
``` ```
let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024); let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024);
...@@ -3764,21 +4075,21 @@ Creates the shared file mapping on the virtual address space of this process. Th ...@@ -3764,21 +4075,21 @@ Creates the shared file mapping on the virtual address space of this process. Th
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| mapType | number | Yes| Protection level of the memory region to which the shared file is mapped.| | mapType | number | Yes| Protection level of the memory region to which the shared file is mapped.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024); let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024);
let mapReadAndWrite = ashmem.mapAshmem(rpc.Ashmem.PROT_READ | rpc.Ashmem.PROT_WRITE); let mapReadAndWrite = ashmem.mapAshmem(ashmem.PROT_READ | ashmem.PROT_WRITE);
console.log("RpcTest: map ashmem result is : " + mapReadAndWrite); console.log("RpcTest: map ashmem result is : " + mapReadAndWrite);
``` ```
...@@ -3791,12 +4102,12 @@ Maps the shared file to the readable and writable virtual address space of the p ...@@ -3791,12 +4102,12 @@ Maps the shared file to the readable and writable virtual address space of the p
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024); let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024);
...@@ -3813,12 +4124,12 @@ Maps the shared file to the read-only virtual address space of the process. ...@@ -3813,12 +4124,12 @@ Maps the shared file to the read-only virtual address space of the process.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024); let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024);
...@@ -3835,21 +4146,21 @@ Sets the protection level of the memory region to which the shared file is mappe ...@@ -3835,21 +4146,21 @@ Sets the protection level of the memory region to which the shared file is mappe
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| protectionType | number | Yes| Protection type to set.| | protectionType | number | Yes| Protection type to set.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024); let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024);
let result = ashmem.setProtection(rpc.Ashmem.PROT_READ); let result = ashmem.setProtection(ashmem.PROT_READ);
console.log("RpcTest: Ashmem setProtection result is : " + result); console.log("RpcTest: Ashmem setProtection result is : " + result);
``` ```
...@@ -3862,23 +4173,25 @@ Writes data to the shared file associated with this **Ashmem** object. ...@@ -3862,23 +4173,25 @@ Writes data to the shared file associated with this **Ashmem** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| buf | number[] | Yes| Data to write.| | buf | number[] | Yes| Data to write.|
| size | number | Yes| Size of the 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.| | offset | number | Yes| Start position of the data to write in the memory region associated with this **Ashmem** object.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** is the data is written successfully; returns **false** otherwise.| | boolean | Returns **true** is the data is written successfully; returns **false** otherwise.|
- Example **Example**
``` ```
let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024); let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024);
var ByteArrayVar = new Int8Array([1, 2, 3, 4, 5]); let mapResult = ashmem.mapReadAndWriteAshmem();
console.info("RpcTest map ashmem result is " + mapResult);
var ByteArrayVar = [1, 2, 3, 4, 5];
let writeResult = ashmem.writeToAshmem(ByteArrayVar, 5, 0); let writeResult = ashmem.writeToAshmem(ByteArrayVar, 5, 0);
console.log("RpcTest: write to Ashmem result is : " + writeResult); console.log("RpcTest: write to Ashmem result is : " + writeResult);
``` ```
...@@ -3892,23 +4205,25 @@ Reads data from the shared file associated with this **Ashmem** object. ...@@ -3892,23 +4205,25 @@ Reads data from the shared file associated with this **Ashmem** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| size | number | Yes| Size of the data to read.| | 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.| | offset | number | Yes| Start position of the data to read in the memory region associated with this **Ashmem** object.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number[] | Data read.| | number[] | Data read.|
- Example **Example**
``` ```
let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024); let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024);
var ByteArrayVar = new Int8Array([1, 2, 3, 4, 5]); let mapResult = ashmem.mapReadAndWriteAshmem();
console.info("RpcTest map ashmem result is " + mapResult);
var ByteArrayVar = [1, 2, 3, 4, 5];
let writeResult = ashmem.writeToAshmem(ByteArrayVar, 5, 0); let writeResult = ashmem.writeToAshmem(ByteArrayVar, 5, 0);
console.log("RpcTest: write to Ashmem result is : " + writeResult); console.log("RpcTest: write to Ashmem result is : " + writeResult);
let readResult = ashmem.readFromAshmem(5, 0); let readResult = ashmem.readFromAshmem(5, 0);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册