您的位置:首页 > 运维架构 > Linux

Linux嵌入式学习-远程过程调用-Binder系统

2017-05-28 21:51 302 查看
Binder系统的C程序使用示例
IPC : Inter-Process Communication, 进程间通信
RPC : Remote Procedure Call, 远程过程调用

这里我们直接只用android系统中已经实现好的Bindrt系统。

具体源代码在 frameworks\native\cmds\servicemanager\目录下。

service_manager.c :
a. binder_open
b. binder_become_context_manager
c. binder_loop(bs, svcmgr_handler);
c.1 res = ioctl(bs->fd, BINDER_WRITE_READ, &bwr);
c.2 binder_parse
// 解析
// 处理 : svcmgr_handler
SVC_MGR_GET_SERVICE/SVC_MGR_CHECK_SERVICE : 获取服务
SVC_MGR_ADD_SERVICE : 注册服务
// 回复

bctest.c
注册服务的过程:
a. binder_open
b. binder_call(bs, &msg, &reply, 0, SVC_MGR_ADD_SERVICE)
// 含有服务的名字
// 它会含有servicemanager回复的数据
// 0表示servicemanager
// code: 表示要调用servicemanager中的"addservice函数"

获取服务的过程:
a. binder_open
b. binder_call(bs, &msg, &reply, target, SVC_MGR_CHECK_SERVICE)
// 含有服务的名字
// 它会含有servicemanager回复的数据, 表示提供服务的进程
// 0表示servicemanager
// code: 表示要调用servicemanager中的"getservice函数"

binder.c (封装好的C函数)

相关代码:https://github.com/qq2216691777/AndroidStudioProjects

版本 V10
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐