返回介绍

3.1 Binder Native 的入口

发布于 2024-12-23 21:29:01 字数 1889 浏览 0 评论 0 收藏

IInterface.cpp 是 Binder 本地层入口,与 java 层的 android.os.IInterface 对应,提供 asBinder() 的实现,返回 IBinder 对象。在头文件中有两个类 BnInterface (Binder Native Interface)BpInterface (Binder Proxy Interface) , 对应于 java 层的 StubProxy

sp<IBinder> IInterface::asBinder(const IInterface* iface)
{
  if (iface == NULL) return NULL;
  return const_cast<IInterface*>(iface)->onAsBinder();
}
template<typename INTERFACE>
class BnInterface : public INTERFACE, public BBinder
{
public:
  virtual sp<IInterface>    queryLocalInterface(const String16& _descriptor);
  virtual const String16&   getInterfaceDescriptor() const;

protected:
  virtual IBinder*      onAsBinder();
};

// ----------------------------------------------------------------------

template<typename INTERFACE>
class BpInterface : public INTERFACE, public BpRefBase
{
public:
                BpInterface(const sp<IBinder>& remote);

protected:
  virtual IBinder*      onAsBinder();
};

其中 BnInterface 是实现 Stub 功能的模板,扩展 BBinder 的 onTransact() 方法实现 Binder 命令的解析和执行。 BpInterface 是实现 Proxy 功能的模板,BpRefBase 里有个 mRemote 对象指向一个 BpBinder 对象。

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。