binder经过interface_cast<ICameraService>转换,最终变成了BpCameraService类型
在IInterface.h文件中
template<typename INTERFACE>
inline sp<INTERFACE> interface_cast(const sp<IBinder>& obj)
{
return INTERFACE::asInterface(obj); //相当于return ICameraService::asInterface(obj);
}
然后来到ICameraService.h文件中,找到
DECLARE_META_INTERFACE(CameraService); //点击这里进入
截图部分代码被替换后,最终形式
类似接口
#define DECLARE_META_INTERFACE(CameraService)
static const android::String16 descriptor;
static android::sp<ICameraService> asInterface(
const android::sp<android::IBinder>& obj);
virtual const android::String16& getInterfaceDescriptor() const;
ICameraService();
virtual ~ICameraService();
类似接口的具体实现
#define IMPLEMENT_META_INTERFACE(CameraService, NAME)
const android::String16 ICameraService::descriptor(NAME);
const android::String16&
ICameraService::getInterfaceDescriptor() const {
return ICameraService::descriptor;
}
android::sp<ICameraService> ICameraService::asInterface(
const android::sp<android::IBinder>& obj)
{
android::sp<ICameraService> intr;
if (obj != NULL) {
intr = static_cast<ICameraService*>(
obj->queryLocalInterface(
ICameraService::descriptor).get());
if (intr == NULL) {
intr = new BpCameraService(obj);
}
}
return intr;
}
ICameraService::ICameraService() { }
ICameraService::~ICameraService() { }