想了解更多关于开源的起学内容,请访问:
51CTO 开源基础软件社区
https://ost.51cto.com
1. 物理内存中开辟4096字节内存(1m-8k)
2. 物理内存与磁盘内存对应
3. mmu将mmap开辟的物理内存地址转换成虚拟地址
OpenBinder is a system for inter-process communication. It was developed at Be Inc. and then Palm, Inc. and was the basis for the Binder framework now used in the Android operating system developed by Google.
OpenBinder allows processes to present interfaces which may be called by other threads. Each process maintains a thread pool which may be used to service such requests. OpenBinder takes care of reference counting, recursion back into the original thread, and the inter-process communication itself. On the Linux version of OpenBinder, the communication is achieved using ioctls on a given file descriptor, communicating with a kernel driver.
The kernel-side component of the Linux version of OpenBinder was merged into the Linux kernel mainline in kernel version 3.19, which was released on February 8, 2015.
Binder是解决进程间通讯问题的框架
在OpenHarmony上表现的功能是:
在OpenHarmony里的限制是:
#define BINDER_WRITE_READ _IOWR('b', 1, struct binder_write_read)
#define BINDER_SET_IDLE_TIMEOUT _IOW('b', 3, __s64)
#define BINDER_SET_MAX_THREADS _IOW('b', 5, __u32)
#define BINDER_SET_IDLE_PRIORITY _IOW('b', 6, __s32)
#define BINDER_SET_CONTEXT_MGR _IOW('b', 7, __s32)
#define BINDER_THREAD_EXIT _IOW('b', 8, __s32)
#define BINDER_VERSION _IOWR('b', 9, struct binder_version)
#define BINDER_GET_NODE_DEBUG_INFO _IOWR('b', 11, struct binder_node_debug_info)
#define BINDER_FEATURE_SET _IOWR('b', 30, struct binder_feature_set)
#define BINDER_GET_ACCESS_TOKEN _IOWR('b', 31, struct access_token)
.
├── binder_alloc.c
├── binder_alloc.h
├── binder_alloc_selftest.c
├── binder.c
├── binder_trace.h
├── Kconfig
└── Makefile
角色说明
import rpc from "@ohos.rpc"
import featureAbility from "@ohos.ability.featureAbility"
sdk依赖:
external_deps = [
"ipc:ipc_core",
]
此外, IPC/RPC依赖的refbase实现在公共基础库下,请增加对utils的依赖:
external_deps = [
"c_utils:utils",
]
JS侧实现跨进程通信基本步骤:
获取代理
使用ohos.ability.featureAbility提供的connectAbility方法绑定Ability,在参数里指定要绑定的Ability所在应用的包名、组件名,如果是跨设备的情况,还需要指定所在设备的NetworkId。用户需要在服务端的onConnect方法里返回一个继承自ohos.rpc.RemoteObject的对象,此对象会在其onRemoteMessageRequest方法里接收到请求。
发送请求
客户端在connectAbility参数指定的回调函数接收到代理对象后,使用ohos.rpc模块提供的方法完成RPC通信,其中MessageParcel提供了读写各种类型数据的方法,IRemoteObject提供了发送请求的方法,RemoteObject提供了处理请求的方法onRemoteRequest,用户需要重写。
Native侧实现跨进程通信的基本步骤:
定义接口类
接口类继承IRemoteBroker,定义描述符、业务函数和消息码。
实现服务提供端(Stub)
Stub继承IRemoteStub(Native),除了接口类中未实现方法外,还需要实现AsObject方法及OnRemoteRequest方法。
实现服务请求端(Proxy)
Proxy继承IRemoteProxy(Native),封装业务函数,调用SendRequest将请求发送到Stub。
注册SA
服务提供方所在进程启动后,申请SA的唯一标识,将Stub注册到SAMgr。
通过SA的标识和设备NetworkId,从SAMgr获取Proxy,通过Proxy实现与Stub的跨进程通信。
想了解更多关于开源的内容,请访问:
51CTO 开源基础软件社区
https://ost.51cto.com
责任编辑:jianghua 来源: 51CTO 开源基础软件社区 BinderIPC工具(责任编辑:休闲)
大兴安岭农商行发布年度信息披露报告 资产总额同比增长10.71%
傲农生物(603363.SH):控股股东质押700万股 累计质押公司股份1.27亿股