Android IPC 通讯机制源码分析
2010-05-29 05:27:00 来源:WEB开发网template
inline sp
{
return INTERFACE::asInterface(obj);
}
将这个宏扩展后最终得到的是:
sp
{
sp
if (obj != NULL) {
intr = static_cast
obj->queryLocalInterface(
IServiceManager::descriptor).get());
if (intr == NULL) {
intr = new BpServiceManager(obj);
}
}
return intr;
}
返回一个BpServiceManager对象,这里obj就是前面我们创建的BpBInder对象。
client获取Service的远程IBinder接口
以CameraService为例(camera.cpp):
const sp
{
Mutex::Autolock _l(mLock);
if (mCameraService.get() == 0) {
sp
sp
do {
binder = sm->getService(String16("media.camera"));
if (binder != 0)
break;
LOGW("CameraService not published, waiting...");
usleep(500000); // 0.5 s
} while(true);
if (mDeathNotifier == NULL) {
mDeathNotifier = new DeathNotifier();
}
binder->linkToDeath(mDeathNotifier);
mCameraService = interface_cast
}
LOGE_IF(mCameraService==0, "no CameraService!?");
return mCameraService;
}
由前面的分析可知sm是BpCameraService对象://应该为BpServiceManager对象
virtual sp
更多精彩
赞助商链接