Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
2a7eff05
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看板
未验证
提交
2a7eff05
编写于
9月 05, 2023
作者:
O
openharmony_ci
提交者:
Gitee
9月 05, 2023
浏览文件
操作
浏览文件
下载
差异文件
!23861 ArkTS整改+格式修改
Merge pull request !23861 from Lixiaoying25/master
上级
bce252b8
449958d5
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
83 addition
and
74 deletion
+83
-74
zh-cn/application-dev/connectivity/ipc-rpc-development-guideline.md
...ication-dev/connectivity/ipc-rpc-development-guideline.md
+40
-30
zh-cn/application-dev/connectivity/subscribe-remote-state.md
zh-cn/application-dev/connectivity/subscribe-remote-state.md
+2
-3
zh-cn/application-dev/reference/apis/js-apis-rpc.md
zh-cn/application-dev/reference/apis/js-apis-rpc.md
+41
-41
未找到文件。
zh-cn/application-dev/connectivity/ipc-rpc-development-guideline.md
浏览文件 @
2a7eff05
...
...
@@ -231,8 +231,10 @@ IPC/RPC的主要工作是让运行在不同进程的Proxy和Stub互相通信,
import
Want
from
'
@ohos.app.ability.Want
'
;
import
common
from
'
@ohos.app.ability.common
'
;
import
deviceManager
from
'
@ohos.distributedHardware.deviceManager
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
proxy
:
rpc
.
RemoteProxy
;
let
dmInstance
:
deviceManager
.
DeviceManager
|
undefined
;
let
proxy
:
rpc
.
IRemoteObject
|
undefined
=
undefined
;
let
connectId
:
number
;
// 单个设备绑定Ability
...
...
@@ -242,7 +244,7 @@ IPC/RPC的主要工作是让运行在不同进程的Proxy和Stub互相通信,
abilityName
:
"
ohos.rpc.test.server.ServiceAbility
"
,
};
let
connect
:
common
.
ConnectOptions
=
{
onConnect
:
(
elementName
,
remote
:
rpc
.
RemoteProxy
)
=>
{
onConnect
:
(
elementName
,
remote
)
=>
{
proxy
=
remote
;
},
onDisconnect
:
(
elementName
)
=>
{
...
...
@@ -263,11 +265,17 @@ IPC/RPC的主要工作是让运行在不同进程的Proxy和Stub互相通信,
return
;
}
console
.
info
(
"
createDeviceManager success
"
);
let
dmInstance
=
data
;
dmInstance
=
data
;
}
try
{
deviceManager
.
createDeviceManager
(
"
ohos.rpc.test
"
,
deviceManagerCallback
);
}
catch
(
error
)
{
let
e
:
BusinessError
=
error
as
BusinessError
;
console
.
error
(
"
createDeviceManager errCode:
"
+
err
.
code
+
"
,errMessage:
"
+
err
.
message
);
}
// 使用deviceManager获取目标设备NetworkId
if
(
dmInstance
!=
undefined
)
{
let
deviceList
:
Array
<
deviceManager
.
DeviceInfo
>
=
dmInstance
.
getTrustedDeviceListSync
();
let
networkId
:
string
=
deviceList
[
0
].
networkId
;
let
want
:
Want
=
{
...
...
@@ -282,6 +290,7 @@ IPC/RPC的主要工作是让运行在不同进程的Proxy和Stub互相通信,
// 第一个参数是本应用的包名,第二个参数是接收deviceManager的回调函数
connectId
=
this
.
context
.
connectServiceExtensionAbility
(
want
,
connect
);
}
```
3.
服务端处理客户端请求
...
...
@@ -289,10 +298,6 @@ IPC/RPC的主要工作是让运行在不同进程的Proxy和Stub互相通信,
服务端被绑定的Ability在onConnect方法里返回继承自rpc.RemoteObject的对象,该对象需要实现onRemoteMessageRequest方法,处理客户端的请求。
```
ts
onConnect
(
want
:
Want
)
{
const
robj
:
rpc
.
RemoteObject
=
new
Stub
(
"
rpcTestAbility
"
);
return
robj
;
}
class
Stub
extends
rpc
.
RemoteObject
{
constructor
(
descriptor
:
string
)
{
super
(
descriptor
);
...
...
@@ -302,6 +307,10 @@ IPC/RPC的主要工作是让运行在不同进程的Proxy和Stub互相通信,
return
true
;
}
}
onConnect
(
want
:
Want
)
{
const
robj
:
rpc
.
RemoteObject
=
new
Stub
(
"
rpcTestAbility
"
);
return
robj
;
}
```
4.
客户端处理服务端响应
...
...
@@ -359,6 +368,7 @@ IPC/RPC的主要工作是让运行在不同进程的Proxy和Stub互相通信,
import
rpc
from
"
@ohos.rpc
"
;
// 仅FA模型需要导入@ohos.ability.featureAbility
// import featureAbility from "@ohos.ability.featureAbility";
function
disconnectCallback
()
{
console
.
info
(
"
disconnect ability done
"
);
}
...
...
zh-cn/application-dev/connectivity/subscribe-remote-state.md
浏览文件 @
2a7eff05
...
...
@@ -98,7 +98,6 @@ import Want from '@ohos.app.ability.Want';
import
AbilityConstant
from
'
@ohos.app.ability.AbilityConstant
'
;
import
window
from
'
@ohos.window
'
;
export
default
class
MainAbility
extends
UIAbility
{
onCreate
(
want
:
Want
,
launchParam
:
AbilityConstant
.
LaunchParam
)
{
console
.
log
(
"
[Demo] MainAbility onCreate
"
);
...
...
@@ -134,9 +133,9 @@ export default class MainAbility extends UIAbility {
import
Want
from
'
@ohos.app.ability.Want
'
;
import
common
from
'
@ohos.app.ability.common
'
;
let
proxy
:
rpc
.
RemoteProxy
;
let
proxy
:
rpc
.
IRemoteObject
|
undefined
=
undefined
;
let
connect
:
common
.
ConnectOptions
=
{
onConnect
:
(
elementName
,
remoteProxy
:
rpc
.
RemoteProxy
)
=>
{
onConnect
:
(
elementName
,
remoteProxy
)
=>
{
console
.
log
(
"
RpcClient: js onConnect called.
"
);
proxy
=
remoteProxy
;
},
...
...
zh-cn/application-dev/reference/apis/js-apis-rpc.md
浏览文件 @
2a7eff05
...
...
@@ -1289,8 +1289,8 @@ writeParcelable(val: Parcelable): void
import
{
BusinessError
}
from
'
@ohos.base
'
;
class
MyParcelable
implements
rpc
.
Parcelable
{
num
:
number
;
str
:
string
;
num
:
number
=
0
;
str
:
string
=
''
;
constructor
(
num
:
number
,
str
:
string
)
{
this
.
num
=
num
;
this
.
str
=
str
;
...
...
@@ -1346,8 +1346,8 @@ readParcelable(dataIn: Parcelable): void
import
{
BusinessError
}
from
'
@ohos.base
'
;
class
MyParcelable
implements
rpc
.
Parcelable
{
num
:
number
;
str
:
string
;
num
:
number
=
0
;
str
:
string
=
''
;
constructor
(
num
:
number
,
str
:
string
)
{
this
.
num
=
num
;
this
.
str
=
str
;
...
...
@@ -2595,7 +2595,7 @@ readException(): void
import
common
from
'
@ohos.app.ability.common
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
proxy
:
rpc
.
IRemoteo
bject
|
undefined
=
undefined
;
let
proxy
:
rpc
.
IRemoteO
bject
|
undefined
=
undefined
;
let
connect
:
common
.
ConnectOptions
=
{
onConnect
:
(
elementName
,
remoteProxy
)
=>
{
console
.
log
(
"
RpcClient: js onConnect called.
"
);
...
...
@@ -2680,8 +2680,8 @@ writeParcelableArray(parcelableArray: Parcelable[]): void
import
{
BusinessError
}
from
'
@ohos.base
'
;
class
MyParcelable
implements
rpc
.
Parcelable
{
num
:
number
;
str
:
string
;
num
:
number
=
0
;
str
:
string
=
''
;
constructor
(
num
:
number
,
str
:
string
)
{
this
.
num
=
num
;
this
.
str
=
str
;
...
...
@@ -2740,8 +2740,8 @@ readParcelableArray(parcelableArray: Parcelable[]): void
import
{
BusinessError
}
from
'
@ohos.base
'
;
class
MyParcelable
implements
rpc
.
Parcelable
{
num
:
number
;
str
:
string
;
num
:
number
=
0
;
str
:
string
=
''
;
constructor
(
num
:
number
,
str
:
string
)
{
this
.
num
=
num
;
this
.
str
=
str
;
...
...
@@ -4285,8 +4285,8 @@ writeSequenceable(val: Sequenceable): boolean
```
ts
class
MySequenceable
implements
rpc
.
Sequenceable
{
num
:
number
;
str
:
string
;
num
:
number
=
0
;
str
:
string
=
''
;
constructor
(
num
:
number
,
str
:
string
)
{
this
.
num
=
num
;
this
.
str
=
str
;
...
...
@@ -4332,8 +4332,8 @@ readSequenceable(dataIn: Sequenceable): boolean
```
ts
class
MySequenceable
implements
rpc
.
Sequenceable
{
num
:
number
;
str
:
string
;
num
:
number
=
0
;
str
:
string
=
''
;
constructor
(
num
:
number
,
str
:
string
)
{
this
.
num
=
num
;
this
.
str
=
str
;
...
...
@@ -5105,7 +5105,7 @@ readException(): void
import
Want
from
'
@ohos.app.ability.Want
'
;
import
common
from
'
@ohos.app.ability.common
'
;
let
proxy
:
rpc
.
IRemoteo
bject
|
undefined
=
undefined
;
let
proxy
:
rpc
.
IRemoteO
bject
|
undefined
=
undefined
;
let
connect
:
common
.
ConnectOptions
=
{
onConnect
:
(
elementName
,
remoteProxy
)
=>
{
console
.
log
(
"
RpcClient: js onConnect called.
"
);
...
...
@@ -5180,8 +5180,8 @@ writeSequenceableArray(sequenceableArray: Sequenceable[]): boolean
```
ts
class
MySequenceable
implements
rpc
.
Sequenceable
{
num
:
number
;
str
:
string
;
num
:
number
=
0
;
str
:
string
=
''
;
constructor
(
num
:
number
,
str
:
string
)
{
this
.
num
=
num
;
this
.
str
=
str
;
...
...
@@ -5224,8 +5224,8 @@ readSequenceableArray(sequenceableArray: Sequenceable[]): void
```
ts
class
MySequenceable
implements
rpc
.
Sequenceable
{
num
:
number
;
str
:
string
;
num
:
number
=
0
;
str
:
string
=
''
;
constructor
(
num
:
number
,
str
:
string
)
{
this
.
num
=
num
;
this
.
str
=
str
;
...
...
@@ -5706,8 +5706,8 @@ marshalling(dataOut: MessageSequence): boolean
```
ts
class
MyParcelable
implements
rpc
.
Parcelable
{
num
:
number
;
str
:
string
;
num
:
number
=
0
;
str
:
string
=
''
;
constructor
(
num
:
number
,
str
:
string
)
{
this
.
num
=
num
;
this
.
str
=
str
;
...
...
@@ -5756,8 +5756,8 @@ unmarshalling(dataIn: MessageSequence): boolean
```
ts
class
MyParcelable
implements
rpc
.
Parcelable
{
num
:
number
;
str
:
string
;
num
:
number
=
0
;
str
:
string
=
''
;
constructor
(
num
:
number
,
str
:
string
)
{
this
.
num
=
num
;
this
.
str
=
str
;
...
...
@@ -5812,8 +5812,8 @@ marshalling(dataOut: MessageParcel): boolean
```
ts
class
MySequenceable
implements
rpc
.
Sequenceable
{
num
:
number
;
str
:
string
;
num
:
number
=
0
;
str
:
string
=
''
;
constructor
(
num
:
number
,
str
:
string
)
{
this
.
num
=
num
;
this
.
str
=
str
;
...
...
@@ -5862,8 +5862,8 @@ unmarshalling(dataIn: MessageParcel): boolean
```
ts
class
MySequenceable
implements
rpc
.
Sequenceable
{
num
:
number
;
str
:
string
;
num
:
number
=
0
;
str
:
string
=
''
;
constructor
(
num
:
number
,
str
:
string
)
{
this
.
num
=
num
;
this
.
str
=
str
;
...
...
@@ -5928,7 +5928,7 @@ asObject(): IRemoteObject
import
Want
from
'
@ohos.app.ability.Want
'
;
import
common
from
'
@ohos.app.ability.common
'
;
let
proxy
:
rpc
.
IRemoteo
bject
|
undefined
=
undefined
;
let
proxy
:
rpc
.
IRemoteO
bject
|
undefined
=
undefined
;
let
connect
:
common
.
ConnectOptions
=
{
onConnect
:
(
elementName
,
remoteProxy
)
=>
{
console
.
log
(
"
RpcClient: js onConnect called.
"
);
...
...
@@ -6368,7 +6368,7 @@ sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: Me
import
Want
from
'
@ohos.app.ability.Want
'
;
import
common
from
'
@ohos.app.ability.common
'
;
let
proxy
:
rpc
.
IRemoteo
bject
|
undefined
=
undefined
;
let
proxy
:
rpc
.
IRemoteO
bject
|
undefined
=
undefined
;
let
connect
:
common
.
ConnectOptions
=
{
onConnect
:
(
elementName
,
remoteProxy
)
=>
{
console
.
log
(
"
RpcClient: js onConnect called.
"
);
...
...
@@ -6446,7 +6446,7 @@ sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence,
import
Want
from
'
@ohos.app.ability.Want
'
;
import
common
from
'
@ohos.app.ability.common
'
;
let
proxy
:
rpc
.
IRemoteo
bject
|
undefined
=
undefined
;
let
proxy
:
rpc
.
IRemoteO
bject
|
undefined
=
undefined
;
let
connect
:
common
.
ConnectOptions
=
{
onConnect
:
(
elementName
,
remoteProxy
)
=>
{
console
.
log
(
"
RpcClient: js onConnect called.
"
);
...
...
@@ -6532,7 +6532,7 @@ sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: Me
import
Want
from
'
@ohos.app.ability.Want
'
;
import
common
from
'
@ohos.app.ability.common
'
;
let
proxy
:
rpc
.
IRemoteo
bject
|
undefined
=
undefined
;
let
proxy
:
rpc
.
IRemoteO
bject
|
undefined
=
undefined
;
let
connect
:
common
.
ConnectOptions
=
{
onConnect
:
(
elementName
,
remoteProxy
)
=>
{
console
.
log
(
"
RpcClient: js onConnect called.
"
);
...
...
@@ -6612,7 +6612,7 @@ sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence,
import
common
from
'
@ohos.app.ability.common
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
proxy
:
rpc
.
IRemoteo
bject
|
undefined
=
undefined
;
let
proxy
:
rpc
.
IRemoteO
bject
|
undefined
=
undefined
;
let
connect
:
common
.
ConnectOptions
=
{
onConnect
:
(
elementName
,
remoteProxy
)
=>
{
console
.
log
(
"
RpcClient: js onConnect called.
"
);
...
...
@@ -6696,7 +6696,7 @@ sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: Me
import
Want
from
'
@ohos.app.ability.Want
'
;
import
common
from
'
@ohos.app.ability.common
'
;
let
proxy
:
rpc
.
IRemoteo
bject
|
undefined
=
undefined
;
let
proxy
:
rpc
.
IRemoteO
bject
|
undefined
=
undefined
;
let
connect
:
common
.
ConnectOptions
=
{
onConnect
:
(
elementName
,
remoteProxy
)
=>
{
console
.
log
(
"
RpcClient: js onConnect called.
"
);
...
...
@@ -6783,7 +6783,7 @@ getLocalInterface(interface: string): IRemoteBroker
import
common
from
'
@ohos.app.ability.common
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
proxy
:
rpc
.
IRemoteo
bject
|
undefined
=
undefined
;
let
proxy
:
rpc
.
IRemoteO
bject
|
undefined
=
undefined
;
let
connect
:
common
.
ConnectOptions
=
{
onConnect
:
(
elementName
,
remoteProxy
)
=>
{
console
.
log
(
"
RpcClient: js onConnect called.
"
);
...
...
@@ -6852,7 +6852,7 @@ queryLocalInterface(interface: string): IRemoteBroker
import
Want
from
'
@ohos.app.ability.Want
'
;
import
common
from
'
@ohos.app.ability.common
'
;
let
proxy
:
rpc
.
IRemoteo
bject
|
undefined
=
undefined
;
let
proxy
:
rpc
.
IRemoteO
bject
|
undefined
=
undefined
;
let
connect
:
common
.
ConnectOptions
=
{
onConnect
:
(
elementName
,
remoteProxy
)
=>
{
console
.
log
(
"
RpcClient: js onConnect called.
"
);
...
...
@@ -6917,7 +6917,7 @@ registerDeathRecipient(recipient: DeathRecipient, flags: number): void
import
common
from
'
@ohos.app.ability.common
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
proxy
:
rpc
.
IRemoteo
bject
|
undefined
=
undefined
;
let
proxy
:
rpc
.
IRemoteO
bject
|
undefined
=
undefined
;
let
connect
:
common
.
ConnectOptions
=
{
onConnect
:
(
elementName
,
remoteProxy
)
=>
{
console
.
log
(
"
RpcClient: js onConnect called.
"
);
...
...
@@ -6992,7 +6992,7 @@ addDeathRecipient(recipient: DeathRecipient, flags: number): boolean
import
Want
from
'
@ohos.app.ability.Want
'
;
import
common
from
'
@ohos.app.ability.common
'
;
let
proxy
:
rpc
.
IRemoteo
bject
|
undefined
=
undefined
;
let
proxy
:
rpc
.
IRemoteO
bject
|
undefined
=
undefined
;
let
connect
:
common
.
ConnectOptions
=
{
onConnect
:
(
elementName
,
remoteProxy
)
=>
{
console
.
log
(
"
RpcClient: js onConnect called.
"
);
...
...
@@ -7062,7 +7062,7 @@ unregisterDeathRecipient(recipient: DeathRecipient, flags: number): void
import
common
from
'
@ohos.app.ability.common
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
proxy
:
rpc
.
IRemoteo
bject
|
undefined
=
undefined
;
let
proxy
:
rpc
.
IRemoteO
bject
|
undefined
=
undefined
;
let
connect
:
common
.
ConnectOptions
=
{
onConnect
:
(
elementName
,
remoteProxy
)
=>
{
console
.
log
(
"
RpcClient: js onConnect called.
"
);
...
...
@@ -7138,7 +7138,7 @@ removeDeathRecipient(recipient: DeathRecipient, flags: number): boolean
import
Want
from
'
@ohos.app.ability.Want
'
;
import
common
from
'
@ohos.app.ability.common
'
;
let
proxy
:
rpc
.
IRemoteo
bject
|
undefined
=
undefined
;
let
proxy
:
rpc
.
IRemoteO
bject
|
undefined
=
undefined
;
let
connect
:
common
.
ConnectOptions
=
{
onConnect
:
(
elementName
,
remoteProxy
)
=>
{
console
.
log
(
"
RpcClient: js onConnect called.
"
);
...
...
@@ -7209,7 +7209,7 @@ getDescriptor(): string
import
common
from
'
@ohos.app.ability.common
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
proxy
:
rpc
.
IRemoteo
bject
|
undefined
=
undefined
;
let
proxy
:
rpc
.
IRemoteO
bject
|
undefined
=
undefined
;
let
connect
:
common
.
ConnectOptions
=
{
onConnect
:
(
elementName
,
remoteProxy
)
=>
{
console
.
log
(
"
RpcClient: js onConnect called.
"
);
...
...
@@ -7271,7 +7271,7 @@ getInterfaceDescriptor(): string
import
Want
from
'
@ohos.app.ability.Want
'
;
import
common
from
'
@ohos.app.ability.common
'
;
let
proxy
:
rpc
.
IRemote
o
bject
|
undefined
=
undefined
;
let
proxy
:
rpc
.
IRemote
O
bject
|
undefined
=
undefined
;
let
connect
:
common
.
ConnectOptions
=
{
onConnect
:
(
elementName
,
remoteProxy
)
=>
{
console
.
log
(
"
RpcClient: js onConnect called.
"
);
...
...
@@ -7326,7 +7326,7 @@ isObjectDead(): boolean
import
Want
from
'
@ohos.app.ability.Want
'
;
import
common
from
'
@ohos.app.ability.common
'
;
let
proxy
:
rpc
.
IRemoteo
bject
|
undefined
=
undefined
;
let
proxy
:
rpc
.
IRemoteO
bject
|
undefined
=
undefined
;
let
connect
:
common
.
ConnectOptions
=
{
onConnect
:
(
elementName
,
remoteProxy
)
=>
{
console
.
log
(
"
RpcClient: js onConnect called.
"
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录