Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
f01d0513
D
Docs
项目概览
OpenHarmony
/
Docs
大约 1 年 前同步成功
通知
159
Star
292
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
f01d0513
编写于
2月 09, 2023
作者:
Y
Yippo
提交者:
Gitee
2月 09, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
【IPC&RPC】代码示例优化和sendMessageRequest方法描述修改
Signed-off-by:
N
Yippo
<
liuyibo12@huawei.com
>
上级
4bc97424
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
122 addition
and
5 deletion
+122
-5
zh-cn/application-dev/reference/apis/js-apis-rpc.md
zh-cn/application-dev/reference/apis/js-apis-rpc.md
+122
-5
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-rpc.md
浏览文件 @
f01d0513
...
...
@@ -2391,6 +2391,8 @@ readException(): void
**示例:**
获取服务
```
ts
import
FA
from
"
@ohos.ability.featureAbility
"
;
let
proxy
;
...
...
@@ -2411,6 +2413,11 @@ readException(): void
"
abilityName
"
:
"
com.ohos.server.EntryAbility
"
,
};
FA
.
connectAbility
(
want
,
connect
);
```
上述onConnect回调函数中的proxy对象需要等等ability异步连接成功后才会被赋值,进而调用sendMessageRequest接口方法发送消息
```
ts
let
option
=
new
rpc
.
MessageOption
();
let
data
=
rpc
.
MessageSequence
.
create
();
let
reply
=
rpc
.
MessageSequence
.
create
();
...
...
@@ -4839,6 +4846,8 @@ readException(): void
**系统能力**
:SystemCapability.Communication.IPC.Core
**示例:**
获取服务
```
ts
import
FA
from
"
@ohos.ability.featureAbility
"
;
...
...
@@ -4860,6 +4869,11 @@ readException(): void
"
abilityName
"
:
"
com.ohos.server.EntryAbility
"
,
};
FA
.
connectAbility
(
want
,
connect
);
```
上述onConnect回调函数中的proxy对象需要等等ability异步连接成功后才会被赋值,进而调用sendMessageRequest接口方法发送消息
```
ts
let
option
=
new
rpc
.
MessageOption
();
let
data
=
rpc
.
MessageParcel
.
create
();
let
reply
=
rpc
.
MessageParcel
.
create
();
...
...
@@ -5640,6 +5654,8 @@ asObject(): IRemoteObject
**示例:**
获取服务
```
ts
import
FA
from
"
@ohos.ability.featureAbility
"
;
let
proxy
;
...
...
@@ -5660,7 +5676,11 @@ asObject(): IRemoteObject
"
abilityName
"
:
"
com.ohos.server.EntryAbility
"
,
};
FA
.
connectAbility
(
want
,
connect
);
```
上述onConnect回调函数中的proxy对象需要等等ability异步连接成功后才会被赋值,进而调用asObject接口方法获取代理或远端对象
```
ts
class
TestProxy
{
remote
:
rpc
.
RemoteObject
;
constructor
(
remote
)
{
...
...
@@ -5826,7 +5846,7 @@ sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: Me
sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence, options: MessageOption): Promise
<
RequestResult
>
以同步或异步方式向对端进程发送MessageSequence消息。如果为选项设置了异步模式,则
期约立即兑现,reply报文里没有内容
。如果为选项设置了同步模式,则期约将在sendMessageRequest返回时兑现,回复内容在reply报文里。
以同步或异步方式向对端进程发送MessageSequence消息。如果为选项设置了异步模式,则
立即收到回调,reply报文里没有内容,具体回复需要在callback回调中获取
。如果为选项设置了同步模式,则期约将在sendMessageRequest返回时兑现,回复内容在reply报文里。
**系统能力**
:SystemCapability.Communication.IPC.Core
...
...
@@ -5850,7 +5870,7 @@ sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence,
sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence, options: MessageOption, callback: AsyncCallback
<
RequestResult
>
): void
以同步或异步方式向对端进程发送MessageSequence消息。如果为选项设置了异步模式,则立即收到回调,reply报文里没有内容。如果为选项设置了同步模式,则将在sendRequest返回时收到回调,回复内容在reply报文里。
以同步或异步方式向对端进程发送MessageSequence消息。如果为选项设置了异步模式,则立即收到回调,reply报文里没有内容
,具体回复需要在callback回调中获取
。如果为选项设置了同步模式,则将在sendRequest返回时收到回调,回复内容在reply报文里。
**系统能力**
:SystemCapability.Communication.IPC.Core
...
...
@@ -6073,6 +6093,8 @@ sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: Me
**示例:**
获取服务
```
ts
import
FA
from
"
@ohos.ability.featureAbility
"
;
let
proxy
;
...
...
@@ -6093,6 +6115,11 @@ sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: Me
"
abilityName
"
:
"
com.ohos.server.EntryAbility
"
,
};
FA
.
connectAbility
(
want
,
connect
);
```
上述onConnect回调函数中的proxy对象需要等等ability异步连接成功后才会被赋值,进而调用sendMessageRequest接口方法发送消息
```
ts
let
option
=
new
rpc
.
MessageOption
();
let
data
=
rpc
.
MessageParcel
.
create
();
let
reply
=
rpc
.
MessageParcel
.
create
();
...
...
@@ -6136,6 +6163,8 @@ sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence,
**示例:**
获取服务
```
ts
import
FA
from
"
@ohos.ability.featureAbility
"
;
let
proxy
;
...
...
@@ -6156,6 +6185,11 @@ sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence,
"
abilityName
"
:
"
com.ohos.server.EntryAbility
"
,
};
FA
.
connectAbility
(
want
,
connect
);
```
上述onConnect回调函数中的proxy对象需要等等ability异步连接成功后才会被赋值,进而调用sendMessageRequest接口方法发送消息
```
ts
let
option
=
new
rpc
.
MessageOption
();
let
data
=
rpc
.
MessageSequence
.
create
();
let
reply
=
rpc
.
MessageSequence
.
create
();
...
...
@@ -6207,6 +6241,8 @@ sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: Me
**示例:**
获取服务
```
ts
import
FA
from
"
@ohos.ability.featureAbility
"
;
let
proxy
;
...
...
@@ -6227,6 +6263,11 @@ sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: Me
"
abilityName
"
:
"
com.ohos.server.EntryAbility
"
,
};
FA
.
connectAbility
(
want
,
connect
);
```
上述onConnect回调函数中的proxy对象需要等等ability异步连接成功后才会被赋值,进而调用sendMessageRequest接口方法发送消息
```
ts
let
option
=
new
rpc
.
MessageOption
();
let
data
=
rpc
.
MessageParcel
.
create
();
let
reply
=
rpc
.
MessageParcel
.
create
();
...
...
@@ -6270,6 +6311,8 @@ sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence,
| callback | AsyncCallback
<
RequestResult
>
| 是 | 接收发送结果的回调。 |
**示例:**
获取服务
```
ts
import
FA
from
"
@ohos.ability.featureAbility
"
;
...
...
@@ -6304,6 +6347,11 @@ sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence,
result
.
reply
.
reclaim
();
}
FA
.
connectAbility
(
want
,
connect
);
```
上述onConnect回调函数中的proxy对象需要等等ability异步连接成功后才会被赋值,进而调用sendMessageRequest接口方法发送消息
```
ts
let
option
=
new
rpc
.
MessageOption
();
let
data
=
rpc
.
MessageSequence
.
create
();
let
reply
=
rpc
.
MessageSequence
.
create
();
...
...
@@ -6339,6 +6387,8 @@ sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: Me
**示例:**
获取服务
```
ts
import
FA
from
"
@ohos.ability.featureAbility
"
;
let
proxy
;
...
...
@@ -6372,6 +6422,11 @@ sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: Me
result
.
reply
.
reclaim
();
}
FA
.
connectAbility
(
want
,
connect
);
```
上述onConnect回调函数中的proxy对象需要等等ability异步连接成功后才会被赋值,进而调用sendMessageRequest接口方法发送消息
```
ts
let
option
=
new
rpc
.
MessageOption
();
let
data
=
rpc
.
MessageParcel
.
create
();
let
reply
=
rpc
.
MessageParcel
.
create
();
...
...
@@ -6410,6 +6465,8 @@ getLocalInterface(interface: string): IRemoteBroker
**示例:**
获取服务
```
ts
import
FA
from
"
@ohos.ability.featureAbility
"
;
let
proxy
;
...
...
@@ -6430,6 +6487,11 @@ getLocalInterface(interface: string): IRemoteBroker
"
abilityName
"
:
"
com.ohos.server.EntryAbility
"
,
};
FA
.
connectAbility
(
want
,
connect
);
```
上述onConnect回调函数中的proxy对象需要等等ability异步连接成功后才会被赋值,进而调用getLocalInterface接口方法查询接口对象
```
ts
try
{
let
broker
=
proxy
.
getLocalInterface
(
"
testObject
"
);
console
.
log
(
"
RpcClient: getLocalInterface is
"
+
broker
);
...
...
@@ -6463,6 +6525,8 @@ queryLocalInterface(interface: string): IRemoteBroker
**示例:**
获取服务
```
ts
import
FA
from
"
@ohos.ability.featureAbility
"
;
let
proxy
;
...
...
@@ -6483,6 +6547,11 @@ queryLocalInterface(interface: string): IRemoteBroker
"
abilityName
"
:
"
com.ohos.server.EntryAbility
"
,
};
FA
.
connectAbility
(
want
,
connect
);
```
上述onConnect回调函数中的proxy对象需要等等ability异步连接成功后才会被赋值,进而调用queryLocalInterface接口获取接口对象
```
ts
let
broker
=
proxy
.
queryLocalInterface
(
"
testObject
"
);
console
.
log
(
"
RpcClient: queryLocalInterface is
"
+
broker
);
```
...
...
@@ -6512,6 +6581,8 @@ registerDeathRecipient(recipient: DeathRecipient, flags: number): void
**示例:**
获取服务
```
ts
import
FA
from
"
@ohos.ability.featureAbility
"
;
let
proxy
;
...
...
@@ -6532,6 +6603,11 @@ registerDeathRecipient(recipient: DeathRecipient, flags: number): void
"
abilityName
"
:
"
com.ohos.server.EntryAbility
"
,
};
FA
.
connectAbility
(
want
,
connect
);
```
上述onConnect回调函数中的proxy对象需要等等ability异步连接成功后才会被赋值,进而调用registerDeathRecipient接口注册死亡回调
```
ts
class
MyDeathRecipient
{
onRemoteDied
()
{
console
.
log
(
"
server died
"
);
...
...
@@ -6539,7 +6615,7 @@ registerDeathRecipient(recipient: DeathRecipient, flags: number): void
}
let
deathRecipient
=
new
MyDeathRecipient
();
try
{
proxy
.
registerDeathRecip
p
ient
(
deathRecipient
,
0
);
proxy
.
registerDeathRecipient
(
deathRecipient
,
0
);
}
catch
(
error
)
{
console
.
info
(
"
proxy register deathRecipient fail, errorCode
"
+
error
.
code
);
console
.
info
(
"
proxy register deathRecipient fail, errorMessage
"
+
error
.
message
);
...
...
@@ -6571,6 +6647,8 @@ addDeathRecipient(recipient: DeathRecipient, flags: number): boolean
**示例:**
获取服务
```
ts
import
FA
from
"
@ohos.ability.featureAbility
"
;
let
proxy
;
...
...
@@ -6591,13 +6669,18 @@ addDeathRecipient(recipient: DeathRecipient, flags: number): boolean
"
abilityName
"
:
"
com.ohos.server.EntryAbility
"
,
};
FA
.
connectAbility
(
want
,
connect
);
```
上述onConnect回调函数中的proxy对象需要等等ability异步连接成功后才会被赋值,进而调用addDeathRecipient接口方法新增死亡回调
```
ts
class
MyDeathRecipient
{
onRemoteDied
()
{
console
.
log
(
"
server died
"
);
}
}
let
deathRecipient
=
new
MyDeathRecipient
();
proxy
.
addDeathRecip
p
ient
(
deathRecipient
,
0
);
proxy
.
addDeathRecipient
(
deathRecipient
,
0
);
```
### unregisterDeathRecipient<sup>9+</sup>
...
...
@@ -6625,6 +6708,8 @@ unregisterDeathRecipient(recipient: DeathRecipient, flags: number): boolean
**示例:**
获取服务
```
ts
import
FA
from
"
@ohos.ability.featureAbility
"
;
let
proxy
;
...
...
@@ -6645,6 +6730,11 @@ unregisterDeathRecipient(recipient: DeathRecipient, flags: number): boolean
"
abilityName
"
:
"
com.ohos.server.EntryAbility
"
,
};
FA
.
connectAbility
(
want
,
connect
);
```
上述onConnect回调函数中的proxy对象需要等等ability异步连接成功后才会被赋值,进而调用unregisterDeathRecipient接口方法注销死亡回调
```
ts
class
MyDeathRecipient
{
onRemoteDied
()
{
console
.
log
(
"
server died
"
);
...
...
@@ -6685,6 +6775,8 @@ removeDeathRecipient(recipient: DeathRecipient, flags: number): boolean
**示例:**
获取服务
```
ts
import
FA
from
"
@ohos.ability.featureAbility
"
;
let
proxy
;
...
...
@@ -6705,6 +6797,11 @@ removeDeathRecipient(recipient: DeathRecipient, flags: number): boolean
"
abilityName
"
:
"
com.ohos.server.EntryAbility
"
,
};
FA
.
connectAbility
(
want
,
connect
);
```
上述onConnect回调函数中的proxy对象需要等等ability异步连接成功后才会被赋值,进而调用removeDeathRecipient接口方法去注册死亡回调
```
ts
class
MyDeathRecipient
{
onRemoteDied
()
{
console
.
log
(
"
server died
"
);
...
...
@@ -6740,6 +6837,8 @@ getDescriptor(): string
**示例:**
获取服务
```
ts
import
FA
from
"
@ohos.ability.featureAbility
"
;
let
proxy
;
...
...
@@ -6760,6 +6859,10 @@ getDescriptor(): string
"
abilityName
"
:
"
com.ohos.server.EntryAbility
"
,
};
FA
.
connectAbility
(
want
,
connect
);
```
上述onConnect回调函数中的proxy对象需要等等ability异步连接成功后才会被赋值,进而调用getDescriptor接口方法获取对象的接口描述符
```
ts
try
{
let
descriptor
=
proxy
.
getDescriptor
();
console
.
log
(
"
RpcClient: descriptor is
"
+
descriptor
);
...
...
@@ -6787,6 +6890,8 @@ getInterfaceDescriptor(): string
**示例:**
获取服务
```
ts
import
FA
from
"
@ohos.ability.featureAbility
"
;
let
proxy
;
...
...
@@ -6807,6 +6912,11 @@ getInterfaceDescriptor(): string
"
abilityName
"
:
"
com.ohos.server.EntryAbility
"
,
};
FA
.
connectAbility
(
want
,
connect
);
```
上述onConnect回调函数中的proxy对象需要等等ability异步连接成功后才会被赋值,进而调用getInterfaceDescriptor接口方法查询当前代理对象接口的描述符
```
ts
let
descriptor
=
proxy
.
getInterfaceDescriptor
();
console
.
log
(
"
RpcClient: descriptor is
"
+
descriptor
);
```
...
...
@@ -6827,6 +6937,8 @@ isObjectDead(): boolean
**示例:**
获取服务
```
ts
import
FA
from
"
@ohos.ability.featureAbility
"
;
let
proxy
;
...
...
@@ -6847,6 +6959,11 @@ isObjectDead(): boolean
"
abilityName
"
:
"
com.ohos.server.EntryAbility
"
,
};
FA
.
connectAbility
(
want
,
connect
);
```
上述onConnect回调函数中的proxy对象需要等等ability异步连接成功后才会被赋值,进而调用isObjectDead接口方法判断当前对象是否已经死亡
```
ts
let
isDead
=
proxy
.
isObjectDead
();
console
.
log
(
"
RpcClient: isObjectDead is
"
+
isDead
);
```
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录