未验证 提交 8ffa3457 编写于 作者: O openharmony_ci 提交者: Gitee

!14890 【IPC&RPC】部分代码示例和接口说明优化整改同步3.2beta5

Merge pull request !14890 from 张泊远yg/OpenHarmony-3.2-Beta5
...@@ -641,12 +641,12 @@ readShort(): number ...@@ -641,12 +641,12 @@ readShort(): number
console.info("rpc write short fail, errorMessage" + error.message); console.info("rpc write short fail, errorMessage" + error.message);
} }
try { try {
let ret = data.readShort(8); let ret = data.readShort();
console.log("RpcClient: readByte is: " + ret);
} catch(error) { } catch(error) {
console.info("rpc read short fail, errorCode " + error.code); console.info("rpc read short fail, errorCode " + error.code);
console.info("rpc read short fail, errorMessage" + error.message); console.info("rpc read short fail, errorMessage" + error.message);
} }
console.log("RpcClient: readByte is: " + ret);
``` ```
### writeInt ### writeInt
...@@ -2391,6 +2391,8 @@ readException(): void ...@@ -2391,6 +2391,8 @@ readException(): void
**示例:** **示例:**
获取服务
```ts ```ts
import FA from "@ohos.ability.featureAbility"; import FA from "@ohos.ability.featureAbility";
let proxy; let proxy;
...@@ -2411,6 +2413,11 @@ readException(): void ...@@ -2411,6 +2413,11 @@ readException(): void
"abilityName": "com.ohos.server.MainAbility", "abilityName": "com.ohos.server.MainAbility",
}; };
FA.connectAbility(want, connect); FA.connectAbility(want, connect);
```
上述onConnect回调函数中的proxy对象需要等ability异步连接成功后才会被赋值,然后才可调用proxy对象的sendMessageRequest接口方法发送消息
```ts
let option = new rpc.MessageOption(); let option = new rpc.MessageOption();
let data = rpc.MessageSequence.create(); let data = rpc.MessageSequence.create();
let reply = rpc.MessageSequence.create(); let reply = rpc.MessageSequence.create();
...@@ -4840,6 +4847,8 @@ readException(): void ...@@ -4840,6 +4847,8 @@ readException(): void
**示例:** **示例:**
获取服务
```ts ```ts
import FA from "@ohos.ability.featureAbility"; import FA from "@ohos.ability.featureAbility";
let proxy; let proxy;
...@@ -4860,6 +4869,11 @@ readException(): void ...@@ -4860,6 +4869,11 @@ readException(): void
"abilityName": "com.ohos.server.MainAbility", "abilityName": "com.ohos.server.MainAbility",
}; };
FA.connectAbility(want, connect); FA.connectAbility(want, connect);
```
上述onConnect回调函数中的proxy对象需要等ability异步连接成功后才会被赋值,然后才可调用proxy对象的sendMessageRequest接口方法发送消息
```ts
let option = new rpc.MessageOption(); let option = new rpc.MessageOption();
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
let reply = rpc.MessageParcel.create(); let reply = rpc.MessageParcel.create();
...@@ -5640,6 +5654,8 @@ asObject(): IRemoteObject ...@@ -5640,6 +5654,8 @@ asObject(): IRemoteObject
**示例:** **示例:**
获取服务
```ts ```ts
import FA from "@ohos.ability.featureAbility"; import FA from "@ohos.ability.featureAbility";
let proxy; let proxy;
...@@ -5660,7 +5676,11 @@ asObject(): IRemoteObject ...@@ -5660,7 +5676,11 @@ asObject(): IRemoteObject
"abilityName": "com.ohos.server.MainAbility", "abilityName": "com.ohos.server.MainAbility",
}; };
FA.connectAbility(want, connect); FA.connectAbility(want, connect);
```
上述onConnect回调函数中的proxy对象需要等ability异步连接成功后才会被赋值,然后才可调用proxy对象的asObject接口方法获取代理或远端对象
```ts
class TestProxy { class TestProxy {
remote: rpc.RemoteObject; remote: rpc.RemoteObject;
constructor(remote) { constructor(remote) {
...@@ -5802,7 +5822,7 @@ sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: Me ...@@ -5802,7 +5822,7 @@ sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: Me
sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption): Promise<SendRequestResult> sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption): Promise<SendRequestResult>
以同步或异步方式向对端进程发送MessageParcel消息。如果为选项设置了异步模式,则期约立即兑现,reply报文里没有内容。如果为选项设置了同步模式,则期约将在sendRequest返回时兑现,回复内容在reply报文里。 以同步或异步方式向对端进程发送MessageParcel消息。如果为选项设置了异步模式,则期约立即兑现,reply报文里没有内容,具体回复需要在业务侧的回调中获取。如果为选项设置了同步模式,则期约将在sendRequest返回时兑现,回复内容在reply报文里。
**系统能力**:SystemCapability.Communication.IPC.Core **系统能力**:SystemCapability.Communication.IPC.Core
...@@ -5826,7 +5846,7 @@ sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: Me ...@@ -5826,7 +5846,7 @@ sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: Me
sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence, options: MessageOption): Promise<RequestResult> sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence, options: MessageOption): Promise<RequestResult>
以同步或异步方式向对端进程发送MessageSequence消息。如果为选项设置了异步模式,则期约立即兑现,reply报文里没有内容。如果为选项设置了同步模式,则期约将在sendMessageRequest返回时兑现,回复内容在reply报文里。 以同步或异步方式向对端进程发送MessageSequence消息。如果为选项设置了异步模式,则期约立即兑现,reply报文里没有内容,具体回复需要在业务侧的回调中获取。如果为选项设置了同步模式,则期约将在sendMessageRequest返回时兑现,回复内容在reply报文里。
**系统能力**:SystemCapability.Communication.IPC.Core **系统能力**:SystemCapability.Communication.IPC.Core
...@@ -5850,7 +5870,7 @@ sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence, ...@@ -5850,7 +5870,7 @@ sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence,
sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence, options: MessageOption, callback: AsyncCallback<RequestResult>): void sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence, options: MessageOption, callback: AsyncCallback<RequestResult>): void
以同步或异步方式向对端进程发送MessageSequence消息。如果为选项设置了异步模式,则立即收到回调,reply报文里没有内容。如果为选项设置了同步模式,则将在sendRequest返回时收到回调,回复内容在reply报文里。 以同步或异步方式向对端进程发送MessageSequence消息。如果为选项设置了异步模式,则立即收到回调,reply报文里没有内容,具体回复需要在业务侧的回调中获取。如果为选项设置了同步模式,则将在sendRequest返回时收到回调,回复内容在reply报文里。
**系统能力**:SystemCapability.Communication.IPC.Core **系统能力**:SystemCapability.Communication.IPC.Core
...@@ -5870,7 +5890,7 @@ sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence, ...@@ -5870,7 +5890,7 @@ sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence,
sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption, callback: AsyncCallback<SendRequestResult>): void sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption, callback: AsyncCallback<SendRequestResult>): void
以同步或异步方式向对端进程发送MessageParcel消息。如果为选项设置了异步模式,则立即收到回调,reply报文里没有内容。如果为选项设置了同步模式,则将在sendRequest返回时收到回调,回复内容在reply报文里。 以同步或异步方式向对端进程发送MessageParcel消息。如果为选项设置了异步模式,则立即收到回调,reply报文里没有内容,具体回复需要在业务侧的回调中获取。如果为选项设置了同步模式,则将在sendRequest返回时收到回调,回复内容在reply报文里。
**系统能力**:SystemCapability.Communication.IPC.Core **系统能力**:SystemCapability.Communication.IPC.Core
...@@ -6052,7 +6072,7 @@ isObjectDead(): boolean ...@@ -6052,7 +6072,7 @@ isObjectDead(): boolean
sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption): boolean sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption): boolean
以同步或异步方式向对端进程发送MessageParcel消息。如果为选项设置了异步模式,则期约立即兑现,reply报文里没有内容。如果为选项设置了同步模式,则期约将在sendRequest返回时兑现,回复内容在reply报文里。 以同步或异步方式向对端进程发送MessageParcel消息。如果为选项设置了异步模式,则期约立即兑现,reply报文里没有内容,具体回复需要在业务侧的回调中获取。如果为选项设置了同步模式,则期约将在sendRequest返回时兑现,回复内容在reply报文里。
**系统能力**:SystemCapability.Communication.IPC.Core **系统能力**:SystemCapability.Communication.IPC.Core
...@@ -6073,6 +6093,8 @@ sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: Me ...@@ -6073,6 +6093,8 @@ sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: Me
**示例:** **示例:**
获取服务
```ts ```ts
import FA from "@ohos.ability.featureAbility"; import FA from "@ohos.ability.featureAbility";
let proxy; let proxy;
...@@ -6093,6 +6115,11 @@ sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: Me ...@@ -6093,6 +6115,11 @@ sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: Me
"abilityName": "com.ohos.server.MainAbility", "abilityName": "com.ohos.server.MainAbility",
}; };
FA.connectAbility(want, connect); FA.connectAbility(want, connect);
```
上述onConnect回调函数中的proxy对象需要等ability异步连接成功后才会被赋值,然后才可调用proxy对象的sendRequest接口方法发送消息
```ts
let option = new rpc.MessageOption(); let option = new rpc.MessageOption();
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
let reply = rpc.MessageParcel.create(); let reply = rpc.MessageParcel.create();
...@@ -6115,7 +6142,7 @@ sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: Me ...@@ -6115,7 +6142,7 @@ sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: Me
sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence, options: MessageOption): Promise<RequestResult> sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence, options: MessageOption): Promise<RequestResult>
以同步或异步方式向对端进程发送MessageSequence消息。如果为选项设置了异步模式,则期约立即兑现,reply报文里没有内容。如果为选项设置了同步模式,则期约将在sendMessageRequest返回时兑现,回复内容在reply报文里。 以同步或异步方式向对端进程发送MessageSequence消息。如果为选项设置了异步模式,则期约立即兑现,reply报文里没有内容,具体回复需要在业务侧的回调中获取。如果为选项设置了同步模式,则期约将在sendMessageRequest返回时兑现,回复内容在reply报文里。
**系统能力**:SystemCapability.Communication.IPC.Core **系统能力**:SystemCapability.Communication.IPC.Core
...@@ -6136,6 +6163,8 @@ sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence, ...@@ -6136,6 +6163,8 @@ sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence,
**示例:** **示例:**
获取服务
```ts ```ts
import FA from "@ohos.ability.featureAbility"; import FA from "@ohos.ability.featureAbility";
let proxy; let proxy;
...@@ -6156,6 +6185,11 @@ sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence, ...@@ -6156,6 +6185,11 @@ sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence,
"abilityName": "com.ohos.server.MainAbility", "abilityName": "com.ohos.server.MainAbility",
}; };
FA.connectAbility(want, connect); FA.connectAbility(want, connect);
```
上述onConnect回调函数中的proxy对象需要等ability异步连接成功后才会被赋值,然后才可调用proxy对象的sendMessageRequest接口方法发送消息
```ts
let option = new rpc.MessageOption(); let option = new rpc.MessageOption();
let data = rpc.MessageSequence.create(); let data = rpc.MessageSequence.create();
let reply = rpc.MessageSequence.create(); let reply = rpc.MessageSequence.create();
...@@ -6186,7 +6220,7 @@ sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence, ...@@ -6186,7 +6220,7 @@ sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence,
sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption): Promise<SendRequestResult> sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption): Promise<SendRequestResult>
以同步或异步方式向对端进程发送MessageParcel消息。如果为选项设置了异步模式,则期约立即兑现,reply报文里没有内容。如果为选项设置了同步模式,则期约将在sendRequest返回时兑现,回复内容在reply报文里。 以同步或异步方式向对端进程发送MessageParcel消息。如果为选项设置了异步模式,则期约立即兑现,reply报文里没有内容,具体回复需要在业务侧的回调中获取。如果为选项设置了同步模式,则期约将在sendRequest返回时兑现,回复内容在reply报文里。
**系统能力**:SystemCapability.Communication.IPC.Core **系统能力**:SystemCapability.Communication.IPC.Core
...@@ -6207,6 +6241,8 @@ sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: Me ...@@ -6207,6 +6241,8 @@ sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: Me
**示例:** **示例:**
获取服务
```ts ```ts
import FA from "@ohos.ability.featureAbility"; import FA from "@ohos.ability.featureAbility";
let proxy; let proxy;
...@@ -6227,6 +6263,11 @@ sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: Me ...@@ -6227,6 +6263,11 @@ sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: Me
"abilityName": "com.ohos.server.MainAbility", "abilityName": "com.ohos.server.MainAbility",
}; };
FA.connectAbility(want, connect); FA.connectAbility(want, connect);
```
上述onConnect回调函数中的proxy对象需要等ability异步连接成功后才会被赋值,然后才可调用proxy对象的sendRequest接口方法发送消息
```ts
let option = new rpc.MessageOption(); let option = new rpc.MessageOption();
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
let reply = rpc.MessageParcel.create(); let reply = rpc.MessageParcel.create();
...@@ -6255,7 +6296,7 @@ sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: Me ...@@ -6255,7 +6296,7 @@ sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: Me
sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence, options: MessageOption, callback: AsyncCallback<RequestResult>): void sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence, options: MessageOption, callback: AsyncCallback<RequestResult>): void
以同步或异步方式向对端进程发送MessageSequence消息。如果为选项设置了异步模式,则立即收到回调,reply报文里没有内容。如果为选项设置了同步模式,则将在sendMessageRequest返回后的某个时机执行回调,回复内容在RequestResult的reply报文里。 以同步或异步方式向对端进程发送MessageSequence消息。如果为选项设置了异步模式,则立即收到回调,reply报文里没有内容,具体回复需要在业务侧的回调中获取。如果为选项设置了同步模式,则将在sendMessageRequest返回后的某个时机执行回调,回复内容在RequestResult的reply报文里。
**系统能力**:SystemCapability.Communication.IPC.Core **系统能力**:SystemCapability.Communication.IPC.Core
...@@ -6271,6 +6312,8 @@ sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence, ...@@ -6271,6 +6312,8 @@ sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence,
**示例:** **示例:**
获取服务
```ts ```ts
import FA from "@ohos.ability.featureAbility"; import FA from "@ohos.ability.featureAbility";
let proxy; let proxy;
...@@ -6304,6 +6347,11 @@ sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence, ...@@ -6304,6 +6347,11 @@ sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence,
result.reply.reclaim(); result.reply.reclaim();
} }
FA.connectAbility(want, connect); FA.connectAbility(want, connect);
```
上述onConnect回调函数中的proxy对象需要等ability异步连接成功后才会被赋值,然后才可调用proxy对象的sendMessageRequest接口方法发送消息
```ts
let option = new rpc.MessageOption(); let option = new rpc.MessageOption();
let data = rpc.MessageSequence.create(); let data = rpc.MessageSequence.create();
let reply = rpc.MessageSequence.create(); let reply = rpc.MessageSequence.create();
...@@ -6323,7 +6371,7 @@ sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence, ...@@ -6323,7 +6371,7 @@ sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence,
sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption, callback: AsyncCallback<SendRequestResult>): void sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption, callback: AsyncCallback<SendRequestResult>): void
以同步或异步方式向对端进程发送MessageParcel消息。如果为选项设置了异步模式,则立即收到回调,reply报文里没有内容。如果为选项设置了同步模式,则将在sendRequest返回时收到回调,回复内容在reply报文里。 以同步或异步方式向对端进程发送MessageParcel消息。如果为选项设置了异步模式,则立即收到回调,reply报文里没有内容,具体回复需要在业务侧的回调中获取。如果为选项设置了同步模式,则将在sendRequest返回时收到回调,回复内容在reply报文里。
**系统能力**:SystemCapability.Communication.IPC.Core **系统能力**:SystemCapability.Communication.IPC.Core
...@@ -6339,6 +6387,8 @@ sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: Me ...@@ -6339,6 +6387,8 @@ sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: Me
**示例:** **示例:**
获取服务
```ts ```ts
import FA from "@ohos.ability.featureAbility"; import FA from "@ohos.ability.featureAbility";
let proxy; let proxy;
...@@ -6372,6 +6422,11 @@ sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: Me ...@@ -6372,6 +6422,11 @@ sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: Me
result.reply.reclaim(); result.reply.reclaim();
} }
FA.connectAbility(want, connect); FA.connectAbility(want, connect);
```
上述onConnect回调函数中的proxy对象需要等ability异步连接成功后才会被赋值,然后才可调用proxy对象的sendRequest接口方法发送消息
```ts
let option = new rpc.MessageOption(); let option = new rpc.MessageOption();
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
let reply = rpc.MessageParcel.create(); let reply = rpc.MessageParcel.create();
...@@ -6410,6 +6465,8 @@ getLocalInterface(interface: string): IRemoteBroker ...@@ -6410,6 +6465,8 @@ getLocalInterface(interface: string): IRemoteBroker
**示例:** **示例:**
获取服务
```ts ```ts
import FA from "@ohos.ability.featureAbility"; import FA from "@ohos.ability.featureAbility";
let proxy; let proxy;
...@@ -6430,6 +6487,11 @@ getLocalInterface(interface: string): IRemoteBroker ...@@ -6430,6 +6487,11 @@ getLocalInterface(interface: string): IRemoteBroker
"abilityName":"com.ohos.server.MainAbility", "abilityName":"com.ohos.server.MainAbility",
}; };
FA.connectAbility(want, connect); FA.connectAbility(want, connect);
```
上述onConnect回调函数中的proxy对象需要等ability异步连接成功后才会被赋值,然后才可调用proxy对象的getLocalInterface接口方法查询接口对象
```ts
try { try {
let broker = proxy.getLocalInterface("testObject"); let broker = proxy.getLocalInterface("testObject");
console.log("RpcClient: getLocalInterface is " + broker); console.log("RpcClient: getLocalInterface is " + broker);
...@@ -6463,6 +6525,8 @@ queryLocalInterface(interface: string): IRemoteBroker ...@@ -6463,6 +6525,8 @@ queryLocalInterface(interface: string): IRemoteBroker
**示例:** **示例:**
获取服务
```ts ```ts
import FA from "@ohos.ability.featureAbility"; import FA from "@ohos.ability.featureAbility";
let proxy; let proxy;
...@@ -6483,6 +6547,11 @@ queryLocalInterface(interface: string): IRemoteBroker ...@@ -6483,6 +6547,11 @@ queryLocalInterface(interface: string): IRemoteBroker
"abilityName":"com.ohos.server.MainAbility", "abilityName":"com.ohos.server.MainAbility",
}; };
FA.connectAbility(want, connect); FA.connectAbility(want, connect);
```
上述onConnect回调函数中的proxy对象需要等ability异步连接成功后才会被赋值,然后才可调用proxy对象的queryLocalInterface接口获取接口对象
```ts
let broker = proxy.queryLocalInterface("testObject"); let broker = proxy.queryLocalInterface("testObject");
console.log("RpcClient: queryLocalInterface is " + broker); console.log("RpcClient: queryLocalInterface is " + broker);
``` ```
...@@ -6512,6 +6581,8 @@ registerDeathRecipient(recipient: DeathRecipient, flags: number): void ...@@ -6512,6 +6581,8 @@ registerDeathRecipient(recipient: DeathRecipient, flags: number): void
**示例:** **示例:**
获取服务
```ts ```ts
import FA from "@ohos.ability.featureAbility"; import FA from "@ohos.ability.featureAbility";
let proxy; let proxy;
...@@ -6532,6 +6603,11 @@ registerDeathRecipient(recipient: DeathRecipient, flags: number): void ...@@ -6532,6 +6603,11 @@ registerDeathRecipient(recipient: DeathRecipient, flags: number): void
"abilityName": "com.ohos.server.MainAbility", "abilityName": "com.ohos.server.MainAbility",
}; };
FA.connectAbility(want, connect); FA.connectAbility(want, connect);
```
上述onConnect回调函数中的proxy对象需要等ability异步连接成功后才会被赋值,然后才可调用proxy对象的registerDeathRecipient接口注册死亡回调
```ts
class MyDeathRecipient { class MyDeathRecipient {
onRemoteDied() { onRemoteDied() {
console.log("server died"); console.log("server died");
...@@ -6539,7 +6615,7 @@ registerDeathRecipient(recipient: DeathRecipient, flags: number): void ...@@ -6539,7 +6615,7 @@ registerDeathRecipient(recipient: DeathRecipient, flags: number): void
} }
let deathRecipient = new MyDeathRecipient(); let deathRecipient = new MyDeathRecipient();
try { try {
proxy.registerDeathRecippient(deathRecipient, 0); proxy.registerDeathRecipient(deathRecipient, 0);
} catch(error) { } catch(error) {
console.info("proxy register deathRecipient fail, errorCode " + error.code); console.info("proxy register deathRecipient fail, errorCode " + error.code);
console.info("proxy register deathRecipient fail, errorMessage " + error.message); console.info("proxy register deathRecipient fail, errorMessage " + error.message);
...@@ -6571,6 +6647,8 @@ addDeathRecipient(recipient: DeathRecipient, flags: number): boolean ...@@ -6571,6 +6647,8 @@ addDeathRecipient(recipient: DeathRecipient, flags: number): boolean
**示例:** **示例:**
获取服务
```ts ```ts
import FA from "@ohos.ability.featureAbility"; import FA from "@ohos.ability.featureAbility";
let proxy; let proxy;
...@@ -6591,13 +6669,18 @@ addDeathRecipient(recipient: DeathRecipient, flags: number): boolean ...@@ -6591,13 +6669,18 @@ addDeathRecipient(recipient: DeathRecipient, flags: number): boolean
"abilityName": "com.ohos.server.MainAbility", "abilityName": "com.ohos.server.MainAbility",
}; };
FA.connectAbility(want, connect); FA.connectAbility(want, connect);
```
上述onConnect回调函数中的proxy对象需要等ability异步连接成功后才会被赋值,然后才可调用proxy对象的addDeathRecippient接口方法新增死亡回调
```ts
class MyDeathRecipient { class MyDeathRecipient {
onRemoteDied() { onRemoteDied() {
console.log("server died"); console.log("server died");
} }
} }
let deathRecipient = new MyDeathRecipient(); let deathRecipient = new MyDeathRecipient();
proxy.addDeathRecippient(deathRecipient, 0); proxy.addDeathRecipient(deathRecipient, 0);
``` ```
### unregisterDeathRecipient<sup>9+</sup> ### unregisterDeathRecipient<sup>9+</sup>
...@@ -6625,6 +6708,8 @@ unregisterDeathRecipient(recipient: DeathRecipient, flags: number): boolean ...@@ -6625,6 +6708,8 @@ unregisterDeathRecipient(recipient: DeathRecipient, flags: number): boolean
**示例:** **示例:**
获取服务
```ts ```ts
import FA from "@ohos.ability.featureAbility"; import FA from "@ohos.ability.featureAbility";
let proxy; let proxy;
...@@ -6645,6 +6730,11 @@ unregisterDeathRecipient(recipient: DeathRecipient, flags: number): boolean ...@@ -6645,6 +6730,11 @@ unregisterDeathRecipient(recipient: DeathRecipient, flags: number): boolean
"abilityName": "com.ohos.server.MainAbility", "abilityName": "com.ohos.server.MainAbility",
}; };
FA.connectAbility(want, connect); FA.connectAbility(want, connect);
```
上述onConnect回调函数中的proxy对象需要等ability异步连接成功后才会被赋值,然后才可调用proxy对象的addDeathRecippient接口方法新增死亡回调
```ts
class MyDeathRecipient { class MyDeathRecipient {
onRemoteDied() { onRemoteDied() {
console.log("server died"); console.log("server died");
...@@ -6685,6 +6775,8 @@ removeDeathRecipient(recipient: DeathRecipient, flags: number): boolean ...@@ -6685,6 +6775,8 @@ removeDeathRecipient(recipient: DeathRecipient, flags: number): boolean
**示例:** **示例:**
获取服务
```ts ```ts
import FA from "@ohos.ability.featureAbility"; import FA from "@ohos.ability.featureAbility";
let proxy; let proxy;
...@@ -6705,6 +6797,11 @@ removeDeathRecipient(recipient: DeathRecipient, flags: number): boolean ...@@ -6705,6 +6797,11 @@ removeDeathRecipient(recipient: DeathRecipient, flags: number): boolean
"abilityName": "com.ohos.server.MainAbility", "abilityName": "com.ohos.server.MainAbility",
}; };
FA.connectAbility(want, connect); FA.connectAbility(want, connect);
```
上述onConnect回调函数中的proxy对象需要等ability异步连接成功后才会被赋值,然后才可调用proxy对象的removeDeathRecipient接口方法去注册死亡回调
```ts
class MyDeathRecipient { class MyDeathRecipient {
onRemoteDied() { onRemoteDied() {
console.log("server died"); console.log("server died");
...@@ -6740,6 +6837,8 @@ getDescriptor(): string ...@@ -6740,6 +6837,8 @@ getDescriptor(): string
**示例:** **示例:**
获取服务
```ts ```ts
import FA from "@ohos.ability.featureAbility"; import FA from "@ohos.ability.featureAbility";
let proxy; let proxy;
...@@ -6760,6 +6859,10 @@ getDescriptor(): string ...@@ -6760,6 +6859,10 @@ getDescriptor(): string
"abilityName": "com.ohos.server.MainAbility", "abilityName": "com.ohos.server.MainAbility",
}; };
FA.connectAbility(want, connect); FA.connectAbility(want, connect);
```
上述onConnect回调函数中的proxy对象需要等ability异步连接成功后才会被赋值,然后才可调用proxy对象的getDescriptor接口方法获取对象的接口描述符
```ts
try { try {
let descriptor = proxy.getDescriptor(); let descriptor = proxy.getDescriptor();
console.log("RpcClient: descriptor is " + descriptor); console.log("RpcClient: descriptor is " + descriptor);
...@@ -6787,6 +6890,8 @@ getInterfaceDescriptor(): string ...@@ -6787,6 +6890,8 @@ getInterfaceDescriptor(): string
**示例:** **示例:**
获取服务
```ts ```ts
import FA from "@ohos.ability.featureAbility"; import FA from "@ohos.ability.featureAbility";
let proxy; let proxy;
...@@ -6807,6 +6912,11 @@ getInterfaceDescriptor(): string ...@@ -6807,6 +6912,11 @@ getInterfaceDescriptor(): string
"abilityName": "com.ohos.server.MainAbility", "abilityName": "com.ohos.server.MainAbility",
}; };
FA.connectAbility(want, connect); FA.connectAbility(want, connect);
```
上述onConnect回调函数中的proxy对象需要等ability异步连接成功后才会被赋值,然后才可调用proxy对象的getInterfaceDescriptor接口方法查询当前代理对象接口的描述符
```ts
let descriptor = proxy.getInterfaceDescriptor(); let descriptor = proxy.getInterfaceDescriptor();
console.log("RpcClient: descriptor is " + descriptor); console.log("RpcClient: descriptor is " + descriptor);
``` ```
...@@ -6827,6 +6937,8 @@ isObjectDead(): boolean ...@@ -6827,6 +6937,8 @@ isObjectDead(): boolean
**示例:** **示例:**
获取服务
```ts ```ts
import FA from "@ohos.ability.featureAbility"; import FA from "@ohos.ability.featureAbility";
let proxy; let proxy;
...@@ -6847,6 +6959,11 @@ isObjectDead(): boolean ...@@ -6847,6 +6959,11 @@ isObjectDead(): boolean
"abilityName": "com.ohos.server.MainAbility", "abilityName": "com.ohos.server.MainAbility",
}; };
FA.connectAbility(want, connect); FA.connectAbility(want, connect);
```
上述onConnect回调函数中的proxy对象需要等ability异步连接成功后才会被赋值,然后才可调用proxy对象的isObjectDead接口方法判断当前对象是否已经死亡
```ts
let isDead = proxy.isObjectDead(); let isDead = proxy.isObjectDead();
console.log("RpcClient: isObjectDead is " + isDead); console.log("RpcClient: isObjectDead is " + isDead);
``` ```
...@@ -7452,7 +7569,7 @@ RemoteObject构造函数。 ...@@ -7452,7 +7569,7 @@ RemoteObject构造函数。
sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption): boolean sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption): boolean
以同步或异步方式向对端进程发送MessageParcel消息。如果为选项设置了异步模式,则期约立即兑现,reply报文里没有内容。如果为选项设置了同步模式,则期约将在sendRequest返回时兑现,回复内容在reply报文里。 以同步或异步方式向对端进程发送MessageParcel消息。如果为选项设置了异步模式,则期约立即兑现,reply报文里没有内容,具体回复需要在业务侧的回调中获取。如果为选项设置了同步模式,则期约将在sendRequest返回时兑现,回复内容在reply报文里。
**系统能力**:SystemCapability.Communication.IPC.Core **系统能力**:SystemCapability.Communication.IPC.Core
...@@ -7518,7 +7635,7 @@ sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: Me ...@@ -7518,7 +7635,7 @@ sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: Me
sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption): Promise&lt;SendRequestResult&gt; sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption): Promise&lt;SendRequestResult&gt;
以同步或异步方式向对端进程发送MessageParcel消息。如果为选项设置了异步模式,则期约立即兑现,reply报文里没有内容。如果为选项设置了同步模式,则期约将在sendRequest返回时兑现,回复内容在reply报文里。 以同步或异步方式向对端进程发送MessageParcel消息。如果为选项设置了异步模式,则期约立即兑现,reply报文里没有内容,具体回复需要在业务侧的回调中获取。如果为选项设置了同步模式,则期约将在sendRequest返回时兑现,回复内容在reply报文里。
**系统能力**:SystemCapability.Communication.IPC.Core **系统能力**:SystemCapability.Communication.IPC.Core
...@@ -7588,7 +7705,7 @@ sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: Me ...@@ -7588,7 +7705,7 @@ sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: Me
sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence, options: MessageOption): Promise&lt;RequestResult&gt; sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence, options: MessageOption): Promise&lt;RequestResult&gt;
以同步或异步方式向对端进程发送MessageSequence消息。如果为选项设置了异步模式,则期约立即兑现,reply报文里没有内容。如果为选项设置了同步模式,则期约将在sendMessageRequest返回时兑现,回复内容在reply报文里。 以同步或异步方式向对端进程发送MessageSequence消息。如果为选项设置了异步模式,则期约立即兑现,reply报文里没有内容,具体回复需要在业务侧的回调中获取。如果为选项设置了同步模式,则期约将在sendMessageRequest返回时兑现,回复内容在reply报文里。
**系统能力**:SystemCapability.Communication.IPC.Core **系统能力**:SystemCapability.Communication.IPC.Core
...@@ -7644,7 +7761,7 @@ sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence, ...@@ -7644,7 +7761,7 @@ sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence,
sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence, options: MessageOption, callback: AsyncCallback&lt;RequestResult&gt;): void sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence, options: MessageOption, callback: AsyncCallback&lt;RequestResult&gt;): void
以同步或异步方式向对端进程发送MessageSequence消息。如果为选项设置了异步模式,则立即收到回调,reply报文里没有内容。如果为选项设置了同步模式,则将在sendMessageRequest返回时收到回调,回复内容在reply报文里。 以同步或异步方式向对端进程发送MessageSequence消息。如果为选项设置了异步模式,则立即收到回调,reply报文里没有内容,具体回复需要在业务侧的回调中获取。如果为选项设置了同步模式,则将在sendMessageRequest返回时收到回调,回复内容在reply报文里。
**系统能力**:SystemCapability.Communication.IPC.Core **系统能力**:SystemCapability.Communication.IPC.Core
...@@ -7694,7 +7811,7 @@ sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence, ...@@ -7694,7 +7811,7 @@ sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence,
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
以同步或异步方式向对端进程发送MessageParcel消息。如果为选项设置了异步模式,则立即收到回调,reply报文里没有内容。如果为选项设置了同步模式,则将在sendRequest返回时收到回调,回复内容在reply报文里。 以同步或异步方式向对端进程发送MessageParcel消息。如果为选项设置了异步模式,则立即收到回调,reply报文里没有内容,具体回复需要在业务侧的回调中获取。如果为选项设置了同步模式,则将在sendRequest返回时收到回调,回复内容在reply报文里。
**系统能力**:SystemCapability.Communication.IPC.Core **系统能力**:SystemCapability.Communication.IPC.Core
...@@ -8030,8 +8147,12 @@ getLocalInterface(descriptor: string): IRemoteBroker ...@@ -8030,8 +8147,12 @@ getLocalInterface(descriptor: string): IRemoteBroker
constructor(descriptor) { constructor(descriptor) {
super(descriptor); super(descriptor);
} }
registerDeathRecipient(recipient: MyDeathRecipient, flags: number); registerDeathRecipient(recipient: MyDeathRecipient, flags: number) {
unregisterDeathRecipient(recipient: MyDeathRecipient, flags: number); // 方法逻辑需开发者根据业务需要实现
}
unregisterDeathRecipient(recipient: MyDeathRecipient, flags: number) {
// 方法逻辑需开发者根据业务需要实现
}
isObjectDead(): boolean { isObjectDead(): boolean {
return false; return false;
} }
...@@ -8040,8 +8161,8 @@ getLocalInterface(descriptor: string): IRemoteBroker ...@@ -8040,8 +8161,8 @@ getLocalInterface(descriptor: string): IRemoteBroker
try { try {
let broker = testRemoteObject.getLocalInterface("testObject"); let broker = testRemoteObject.getLocalInterface("testObject");
} catch(error) { } catch(error) {
console.info(rpc get local interface fail, errorCode " + error.code); console.info("rpc get local interface fail, errorCode " + error.code);
console.info(rpc get local interface fail, errorMessage " + error.message); console.info("rpc get local interface fail, errorMessage " + error.message);
} }
``` ```
...@@ -8127,8 +8248,12 @@ getDescriptor(): string ...@@ -8127,8 +8248,12 @@ getDescriptor(): string
constructor(descriptor) { constructor(descriptor) {
super(descriptor); super(descriptor);
} }
addDeathRecipient(recipient: MyDeathRecipient, flags: number); registerDeathRecipient(recipient: MyDeathRecipient, flags: number) {
unregisterDeathRecipient(recipient: MyDeathRecipient, flags: number); // 方法逻辑需开发者根据业务需要实现
}
unregisterDeathRecipient(recipient: MyDeathRecipient, flags: number) {
// 方法逻辑需开发者根据业务需要实现
}
isObjectDead(): boolean { isObjectDead(): boolean {
return false; return false;
} }
...@@ -8137,8 +8262,8 @@ getDescriptor(): string ...@@ -8137,8 +8262,8 @@ getDescriptor(): string
try { try {
let descriptor = testRemoteObject.getDescriptor(); let descriptor = testRemoteObject.getDescriptor();
} catch(error) { } catch(error) {
console.info(rpc get local interface fail, errorCode " + error.code); console.info("rpc get local interface fail, errorCode " + error.code);
console.info(rpc get local interface fail, errorMessage " + error.message); console.info("rpc get local interface fail, errorMessage " + error.message);
} }
console.log("RpcServer: descriptor is: " + descriptor); console.log("RpcServer: descriptor is: " + descriptor);
``` ```
...@@ -8219,8 +8344,12 @@ modifyLocalInterface(localInterface: IRemoteBroker, descriptor: string): void ...@@ -8219,8 +8344,12 @@ modifyLocalInterface(localInterface: IRemoteBroker, descriptor: string): void
console.info(rpc attach local interface fail, errorMessage " + error.message); console.info(rpc attach local interface fail, errorMessage " + error.message);
} }
} }
registerDeathRecipient(recipient: MyDeathRecipient, flags: number); registerDeathRecipient(recipient: MyDeathRecipient, flags: number) {
unregisterDeathRecipient(recipient: MyDeathRecipient, flags: number); // 方法逻辑需开发者根据业务需要实现
}
unregisterDeathRecipient(recipient: MyDeathRecipient, flags: number) {
// 方法逻辑需开发者根据业务需要实现
}
isObjectDead(): boolean { isObjectDead(): boolean {
return false; return false;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册