首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >remote()的实现

remote()的实现
EN

Stack Overflow用户
提问于 2013-03-20 17:47:21
回答 1查看 2.7K关注 0票数 1

我正在尝试查找remote()的实现,如下所示:

代码语言:javascript
复制
remote()->transact(CODE, data, &reply);

你们知道它在哪吗?在谷歌上搜索结果是徒劳的。或者,如果你知道这个函数是做什么的,它会对我有很大的帮助。非常感谢

更新: remote()似乎会返回一个指向BBinder、IBinder、BpBinder或IPCThreadState类型的对象的指针,但我不确定是哪一个。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-03-20 20:09:06

remote的实现很简单:

代码语言:javascript
复制
class BpRefBase : public virtual RefBase
{
protected:
                            BpRefBase(const sp<IBinder>& o);
    virtual                 ~BpRefBase();
    virtual void            onFirstRef();
    virtual void            onLastStrongRef(const void* id);
    virtual bool            onIncStrongAttempted(uint32_t flags, const void* id);

    inline  IBinder*        remote()                { return mRemote; }
    inline  IBinder*        remote() const          { return mRemote; }

private:
                            BpRefBase(const BpRefBase& o);
    BpRefBase&              operator=(const BpRefBase& o);

    IBinder* const          mRemote;
    RefBase::weakref_type*  mRefs;
    volatile int32_t        mState;
};

ServiceManager将管理所有已注册的服务,有关其工作原理,请查看an existing answer。当您从ServiceManager执行getService操作时,它将返回一个表示该服务的IBinder对象,然后此IBinder对象将被放入BpInterface中。那是你的遥控器。然后,您可以使用该BpInterface启动具有实际service(BnInterface)的绑定器事务。

代码语言:javascript
复制
template<typename INTERFACE>
class BpInterface : public INTERFACE, public BpRefBase
{
public:
                                BpInterface(const sp<IBinder>& remote);

protected:
    virtual IBinder*            onAsBinder();
};

BpCamera一样熟悉的BpXXXBpCameraService都是从BpInterface扩展而来的。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15520098

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档