Android深入浅出之Binder机制
2012-06-30 10:47:32 来源:WEB开发网核心提示:I##INTERFACE::I##INTERFACE() { } \I##INTERFACE::~I##INTERFACE(){ } \很麻烦吧?尤其是宏看着头疼,赶紧兑现下吧,An
I##INTERFACE::I##INTERFACE() { } \
I##INTERFACE::~I##INTERFACE(){ } \
很麻烦吧?尤其是宏看着头疼。赶紧兑现下吧。
const
android::String16IServiceManager::descriptor(“android.os.IServiceManager”);
constandroid::String16& IServiceManager::getInterfaceDescriptor() const
{ return IServiceManager::descriptor;//返回上面那个android.os.IServiceManager
} android::sp<IServiceManager> IServiceManager::asInterface(
constandroid::sp<android::IBinder>& obj)
{
android::sp<IServiceManager>intr;
if (obj != NULL) {
intr = static_cast<IServiceManager*>(
obj->queryLocalInterface(IServiceManager::descriptor).get());
if (intr == NULL) {
intr = new BpServiceManager(obj);
}
}
return intr;
}
IServiceManager::IServiceManager () {}
IServiceManager::~ IServiceManager() { }
哇塞,asInterface是这么搞的啊,赶紧分析下吧,还是不知道interface_cast怎么把BpBinder*转成了IServiceManager
我们刚才解析过的interface_cast<IServiceManager>(new BpBinder(0)),
原来就是调用asInterface(new BpBinder(0))
android::sp<IServiceManager>IServiceManager::asInterface(
constandroid::sp<android::IBinder>& obj)
{
android::sp<IServiceManager>intr;
if (obj != NULL) {
....
intr = new BpServiceManager(obj);
//神呐,终于看到和IServiceManager相关的东西了,看来
//实际返回的是BpServiceManager(new BpBinder(0));
}
}
I##INTERFACE::~I##INTERFACE(){ } \
很麻烦吧?尤其是宏看着头疼。赶紧兑现下吧。
const
android::String16IServiceManager::descriptor(“android.os.IServiceManager”);
constandroid::String16& IServiceManager::getInterfaceDescriptor() const
{ return IServiceManager::descriptor;//返回上面那个android.os.IServiceManager
} android::sp<IServiceManager> IServiceManager::asInterface(
constandroid::sp<android::IBinder>& obj)
{
android::sp<IServiceManager>intr;
if (obj != NULL) {
intr = static_cast<IServiceManager*>(
obj->queryLocalInterface(IServiceManager::descriptor).get());
if (intr == NULL) {
intr = new BpServiceManager(obj);
}
}
return intr;
}
IServiceManager::IServiceManager () {}
IServiceManager::~ IServiceManager() { }
哇塞,asInterface是这么搞的啊,赶紧分析下吧,还是不知道interface_cast怎么把BpBinder*转成了IServiceManager
我们刚才解析过的interface_cast<IServiceManager>(new BpBinder(0)),
原来就是调用asInterface(new BpBinder(0))
android::sp<IServiceManager>IServiceManager::asInterface(
constandroid::sp<android::IBinder>& obj)
{
android::sp<IServiceManager>intr;
if (obj != NULL) {
....
intr = new BpServiceManager(obj);
//神呐,终于看到和IServiceManager相关的东西了,看来
//实际返回的是BpServiceManager(new BpBinder(0));
}
}
更多精彩
赞助商链接