Implementation of remote()

别等时光非礼了梦想. 提交于 2019-12-24 14:05:26

问题


I'm trying to find the implementation of remote(), as in:

remote()->transact(CODE, data, &reply);

Do you guys know where it is? Searching Google turned out futile. Or if you know what that function does, it would be a big help for me. Many thanks

Update: it seems remote() will return a pointer to an object of type BBinder, IBinder, BpBinder, or IPCThreadState but I'm not sure which one.


回答1:


The implementation of remote is simple:

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;
};

The ServiceManager will manage all the registered service, for how it works, check an existing answer. When you getService from ServiceManager, it will return an IBinder object represents that service, then this IBinder object will be put into a BpInterface. That is your remote. Then you can use that BpInterface to start binder transaction with the actual service(BnInterface).

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

protected:
    virtual IBinder*            onAsBinder();
};

All familiar BpXXX like BpCamera, BpCameraService extends from BpInterface.



来源:https://stackoverflow.com/questions/15520098/implementation-of-remote

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!