粗浅的 C Binder 服务和客户例子Word格式文档下载.docx
- 文档编号:22385941
- 上传时间:2023-02-03
- 格式:DOCX
- 页数:7
- 大小:15.10KB
粗浅的 C Binder 服务和客户例子Word格式文档下载.docx
《粗浅的 C Binder 服务和客户例子Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《粗浅的 C Binder 服务和客户例子Word格式文档下载.docx(7页珍藏版)》请在冰豆网上搜索。
├──Android.mk
└──test.cpp
IMyBinder.h
#include&
lt;
stdint.h&
gt;
sys/types.h&
utils/RefBase.h&
utils/Errors.h&
binder/IInterface.h&
namespaceandroid{
//----------------------------------------------------------------------------
classIMyBinder:
publicIInterface
{
public:
DECLARE_META_INTERFACE(MyBinder);
};
classBnMyBinder:
publicBnInterface&
IMyBinder&
virtualstatus_tonTransact(uint32_tcode,
constParcel&
amp;
data,
Parcel*reply,
uint32_tflags=0);
//namespaceandroid
IMyBinder.cpp
#defineLOG_TAG"
MyBinder"
binder/Parcel.h&
#include"
IMyBinder.h"
classBpMyBinder:
publicBpInterface&
BpMyBinder(constsp&
IBinder&
&
impl)
:
BpInterface&
(impl)
{
}
IMPLEMENT_META_INTERFACE(MyBinder,"
demo.IMyBinder"
);
status_tBnMyBinder:
:
onTransact(
uint32_tcode,constParcel&
data,Parcel*reply,uint32_tflags)
switch(code){
default:
returnBBinder:
onTransact(code,data,reply,flags);
}
MyBinder.h
binder/BinderService.h&
classMyBinder:
publicBinderService&
MyBinder&
publicBnMyBinder,
protectedThread
staticcharconst*getServiceName(){return"
demo.MyBinder"
;
MyBinder();
virtual~MyBinder();
virtualstatus_tonTransact(
data,Parcel*reply,uint32_tflags);
virtualboolthreadLoop();
MyBinder.cpp
MyBinder.h"
MyBinder:
MyBinder()
BnMyBinder(),Thread(false)
~MyBinder()
status_tMyBinder:
switch(code){
returnNO_ERROR;
boolMyBinder:
threadLoop()
returntrue;
main.cpp
usingnamespaceandroid;
intmain(intargc,char**argv){
MyBinder:
publishAndJoinThreadPool();
return0;
test.cpp
utils/Log.h&
binder/IServiceManager.h&
sp&
gMyBinder;
constsp&
getMyBinderService()
sp&
IServiceManager&
sm=defaultServiceManager();
binder;
do{
binder=sm-&
getService(String16("
));
if(binder!
=0)
break;
LOGW("
Servicenotpublished,waiting..."
usleep(500000);
//0.5s
}while(true);
/*if(mDeathNotifier==NULL){
mDeathNotifier=newDeathNotifier();
binder-&
linkToDeath(mDeathNotifier);
*/
gMyBinder=interface_cast&
(binder);
LOGE_IF(gMyBinder==0,"
noService!
?
"
returngMyBinder;
intmain()
getMyBinderService();
printf("
getinstance%p\n"
gMyBinder.get());
Android.mk贴server下的一个,其他类似修改
LOCAL_PATH:
=$(callmy-dir)include$(CLEAR_VARS)LOCAL_SRC_FILES:
=\
MyBinder.cpp\
main.cppLOCAL_SHARED_LIBRARIES:
libmybinderlibutilslibbinderLOCAL_C_INCLUDES:
=$(LOCAL_PATH)/../include\
frameworks/base/include/LOCAL_MODULE_TAGS:
=debugLOCAL_MODULE:
=mybinderinclude$(BUILD_EXECUTABLE)
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 粗浅的 Binder 服务和客户例子 粗浅 服务 客户 例子