1.bbinder binder实体对象
2.bpbinder binder引用对象
3.binder代理对象
4.ibinder bbinder 和bpbinder都继承与ibinder
注意:应用需要使用的是binder的代理对象,使用前需要将引用对象转换成代理对象。
ICameraService.Stub.asInterface(binder);
defaultServiceManager 拿到的是serviceManager 其实也是一个binder服务
getService()是拿到的普通binder服务
例子
class BpExampleService : public BpInterface<IExampleService>
{
virtual int get()
{
Parcel data,reply;
data.writeInterfaceToken(IexampleService::getInterfaceDescriptor());
remote()->transact(EXAMPLE_GET,data,&reply); //remote()函数得到Binder引用对象的指针,然后调用它的transcat() 此函数会调用IPCThread类的函数来向驱动传递数据
最后到了onTransact方法调用远程实体对象ExampleService 类对应的方法
return reply.readInt();
}
}
status_t BnExampleService::onTransact(...)
{
switch(code)
{
case EXAMPLE_GET:
CHECK_INTERFACE(IExampleService,data,reply);
reply->writeInt(get()); //调用get方法
break;
case EXAMPLE_SET:
CHECK_INTERFACE(IExampleService,data,reply);
set(data->readInt()); //调用set方法
break;
default:
return BBinder::onTransact(code,data,reply,flags);
}
}
图片参考此处http://www.cnblogs.com/winfu/p/6061296.html
新闻热点
疑难解答