c++ 层实现binder服务样例

查看样例地址:https://github.com/langxianwen/binder-demo

研究了binder服务的实现,想写个binder样例。

在网上和书上都看到有这类似的样例,照着写后。发现都不是自己想要的,不太符合源代码的风格。
就从源代码的binder服务精简了一个。
遇到的问题:
1 、frameworks/native/include/binder/IInterface.h:50: error: undefined reference to 'android::RefBase::~RefBase()'
    原因:没有加入仅仅加入了libbinder 库。没加入libutils库,
2 、ITest.h TestService.h 头文件放在哪里,才干包括。


    一开是我是放在framework/av/include/media。


    引用时仅仅需#include <media/ITest.h>就可以。

    可是能不能放在自定义的随意文件夹能?如:./test/include/test/ITest.h 
    #include "ITest.h" 编译找不到头文件。还须要在Android.mk指定头文件路径 
    LOCAL_C_INCLUDES := $(LOCAL_PATH)/../include/test就可以。
3、我的样例里面打印log是用ALOGE等。有的代码库中是LOGE

写样例心得:虽然几行代码我也折腾来两三天。看会的,永远不一定就会了,动手才是应道理。

代码查看地址:https://github.com/langxianwen/binder-demo

git路径:git clone https://github.com/langxianwen/binder-demo.git


posted @ 2017-07-28 08:11  jzdwajue  阅读(499)  评论(0编辑  收藏  举报