gpt4 book ai didi

android - 远程()的实现

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:57:13 24 4
gpt4 key购买 nike

我试图找到 remote() 的实现,如:

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

你们知道它在哪里吗?搜索谷歌结果是徒劳的。或者,如果您知道该功能的作用,那将对我有很大帮助。非常感谢

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

最佳答案

remote 的实现很简单:

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 .当你从ServiceManagergetService时,它会返回一个代表该服务的IBinder对象,那么这个IBinder对象将是放入 BpInterface。那是你的 Remote 。然后,您可以使用该 BpInterface 与实际的 service(BnInterface) 启动 Binder 事务。

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

protected:
virtual IBinder* onAsBinder();
};

所有熟悉的 BpXXX,例如 BpCameraBpCameraService 都继承自 BpInterface

关于android - 远程()的实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15520098/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com