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

 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

posted @ 2017-05-28 21:51  叶念西风  阅读(1384)  评论(0编辑  收藏  举报
叶念西风 - 个人博客 & 电脑Run - 维修帮助软件教程安装